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?

Antworten (1)

Mathieu NOE
Mathieu NOE am 29 Okt. 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

Kategorien

Mehr zu Control System Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 29 Okt. 2020

Kommentiert:

am 29 Okt. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by