Index in position 1 is invalid PID Controller

조회 수: 1 (최근 30일)
Tom Hart
Tom Hart 2020년 12월 6일
편집: Stephan 2020년 12월 7일
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
Tom Hart
Tom Hart 2020년 12월 7일
Update on this. If I close Matlab and run the script it works, but then when i try to run it a second time it wont work.
Anyone know why?

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephan
Stephan 2020년 12월 7일
편집: Stephan 2020년 12월 7일
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.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by