Index in position 1 is invalid PID Controller
Afficher commentaires plus anciens
Hi,
I think I'm having a syntax error for my tf, it's not working for some reason when I run it.
% set up motor with initial conditions and properties
motor.timeConstant = 5/60; % [min]
motor.gain = 0.2; % [rpm/V]
% transfer function for the motor
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
I've also tried using this and it still doesn't work.
% transfer function for the motor
s = tf('s');
TFmotor_OL = motor.gain / (motor.timeConstant*s +1);
if you could help that would be great :)
1 commentaire
Tom Hart
le 7 Déc 2020
Réponses (1)
When you run this the first time you first call the inbuilt function tf and then later you create a variable, which is named tf also:
TFmotor_OL = tf([0 motor.gain],[motor.timeConstant 1]);
.
.
.
tf = 0;
Since you not clear the workspace, the next time you run the function the call of tf with brackets will be interpreted as the indexed call of the variable tf, not the function that you want to call.
To avoid this you should rename your variable. It is never a good idea to name variables or scripts like inbuilt functions.
Catégories
En savoir plus sur PID Controller Tuning dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!