Index exceeds the number of array elements (1) PID controller
1 view (last 30 days)
Show older comments
% set up motor with initial conditions and properties
motor.timeConstant = 5/60; % [min]
motor.gain = 0.2; % [rpm/V]
% transfer function for the motor
s = tf('s');
TFmotor_OL = motor.gain / (motor.timeConstant*s +1);
% set up PID
PID.Pgain = 4; % proportional gain
PID.Igain = 80; % internal gain
PID.Dgain = 1; % derivative gain
% create the controller
controller = pid(PID.Pgain, PID.Igain, PID.Dgain);
% connect the controller and motor
TFmotor_CL = feedback(controller*TFmotor_OL, 1);
% plot open-loop response
step(TFmotor_OL, 2)
% add time constant for derivative
tf = 0;
% plot closed-loop response
hold on % keep open-loop plot
step(TFmotor_CL, 2) % plot closed-loop response
legend('show') % show legend
It says the error is occuring in the line defining 's'. I have no idea why or how to solve it, any suggestions?
0 Comments
Answers (1)
Mathieu NOE
on 29 Oct 2020
hi
it works for me (R 2020a)
maybe you have an older matlab version
try the other syntax for tf :
% set up motor with initial conditions and properties
motor.timeConstant = 5/60; % [min]
motor.gain = 0.2; % [rpm/V]
% transfer function for the motor
% s = tf('s');
% TFmotor_OL = motor.gain / (motor.timeConstant*s +1);
% alternate method : sys = tf(numerator,denominator)
TFmotor_OL = tf([0 motor.gain],[motor.timeConstant 1]);
% set up PID
PID.Pgain = 4; % proportional gain
PID.Igain = 80; % internal gain
PID.Dgain = 1; % derivative gain
% create the controller
controller = pid(PID.Pgain, PID.Igain, PID.Dgain);
% connect the controller and motor
TFmotor_CL = feedback(controller*TFmotor_OL, 1);
% plot open-loop response
step(TFmotor_OL, 2)
% add time constant for derivative
tf = 0;
% plot closed-loop response
hold on % keep open-loop plot
step(TFmotor_CL, 2) % plot closed-loop response
legend('show') % show legend
See Also
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!