how to get PID output?

14 visualizzazioni (ultimi 30 giorni)
mohamed El Hamzawy
mohamed El Hamzawy il 3 Lug 2014
Risposto: mamal il 4 Set 2022
hello i am currently doin my bachelor thesis ,, the project is ball on beam. i am using PID function for matlab to control a servo motor . the code is as follows:
s = tf('s');
P_ball = 0.48/s^2;
Kp =2;
Kd =1;
Ki=.75;
C = pid(Kp,Ki,Kd);
sys_cl=feedback(P_ball,1);
t=0:0.01:5;
step(0.25*sys_cl)
disp(sys_cl);
The problem is extracting the output value from the PID function. the output of PID function is supposed to be the angle of the servo motor,, now i dont know how to get this angle in order to give it to the servo motor continuously. can anyone help?

Risposte (4)

Arkadiy Turevskiy
Arkadiy Turevskiy il 7 Lug 2014
Your code, as written does not make much sense. You define controller C, but then do not use it, and instead just use unity gain when computing closed-loop response. I am also not sure why you are mutiplying sys_cl by 0.25 when computing the step reponse.
The more meaningful code would be:
s = tf('s');
P_ball = 0.48/s^2;
Kp =2;
Kd =1;
Ki=.75;
C = pid(Kp,Ki,Kd);
sys_cl=feedback(C*P_ball,1);
t=0:0.01:5;
step(sys_cl)
what you see then is the angle of the motor (the variable you control). The output of the PID would be something like a voltage request to the motor. Another issue is that typically a motor transfer function is not a double integrator, like your plant transfer function, but that's for you to figure out.
  2 Commenti
mohamed El Hamzawy
mohamed El Hamzawy il 8 Lug 2014
Modificato: mohamed El Hamzawy il 8 Lug 2014
First of all thanks for answering.
Second of all, in the code C controller is used in the feed back function "sys_cl=feedback(C*P_ball,1);". The transfer function is not for the motor too, it is for the system of ball on beam. its is a relation between the output which is the position of the ball, and the input which is the angle of the servo. The problem is i am using arduino connections with matlab to control the servo motor as follows:
" a.servoAttach(9);
a.servoWrite(9,Outputpid); "
the Problem is i am trying to get the output of pid function as an integer for each time the pid calculates a new output.
parag patil
parag patil il 23 Ott 2020
Hello,
I had the same question. Sorry for being too late, but did you manage to get the answer?

Accedi per commentare.


Komal Damodara
Komal Damodara il 4 Apr 2019
s = tf('s');
P_ball = 0.48/s^2;
Kp =2;
Kd =1;
Ki=.75;
C = pid(Kp,Ki,Kd);
sys_cl=feedback(C*P_ball,1);
t=0:0.01:5;
step(sys_cl)

Komal Damodara
Komal Damodara il 4 Apr 2019
s = tf('s');
P_ball = 0.48/s^2;
Kp =2;
Kd =1;
Ki=.75;
C = pid(Kp,Ki,Kd);
sys_cl=feedback(C*P_ball,1);
t=0:0.01:5;
step(sys_cl)

mamal
mamal il 4 Set 2022
How do you solve this problem?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by