Index exceeds the number of array elements (1) PID controller

% 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?

답변 (1개)

Mathieu NOE
Mathieu NOE 2020년 10월 29일
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

카테고리

도움말 센터File Exchange에서 Control System Toolbox에 대해 자세히 알아보기

질문:

2020년 10월 29일

댓글:

2020년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by