how to get PID output?

7 次查看(过去 30 天)
mohamed El Hamzawy
回答: mamal 2022-9-4
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?

回答(4 个)

Arkadiy Turevskiy
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 个评论
mohamed El Hamzawy
编辑:mohamed El Hamzawy 2014-7-8
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 2020-10-23
Hello,
I had the same question. Sorry for being too late, but did you manage to get the answer?

请先登录,再进行评论。


Komal Damodara
Komal Damodara 2019-4-4
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 2019-4-4
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 2022-9-4
How do you solve this problem?

类别

Help CenterFile Exchange 中查找有关 PID Controller Tuning 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by