Simulink PID Controller not behaving Properly
63 views (last 30 days)
Show older comments
Hi All, having some issues with a PID controller project I'm working on using the simulink PID block.
I've been trying to tune the controller manually, but the behavior I'm seeing from the simulink output does not match both the basic step response graph as well as the PID Tuner app.
J = 0.01;
b = 0.1;
K = 0.01;
R = 1;
L = 0.5;
voltage = 10;
stoptime = 10;
timestep= 0.05;
simIn = Simulink.SimulationInput("proj1sim");
simIn = setModelParameter(simIn,'StopTime',stoptime);
simIn = setModelParameter(simIn,'TimeStep',timestep);
%Setup Transfer Function
num = [K];
denom = [J*L R*J+b*L b*R+K^2];
G = tf(num,denom);
%step(G);
%1st Controller
%PID Parameters
Kp = 60;
Ki = 180;
Kd = 4.5;
out = sim("proj1sim.slx");
output = out.simout;
controller = out.controller;
figure(1);
plot(output);
title('Plant Output');
ylabel('Voltage');
figure(2);
plot(controller);
title('Controller Output');
ylabel('Voltage');
The main problem I'm seeing is that when I put any value other than zero for the derivative gain, the system completely breaks down.
As shown in the images, when I use the values given by PID Tuner, the graph makes no sense. But when I sed Kd to zero and change nothing else, it sort of works suddenly.
PID tuner:
Output with PID tuner Values:
Output with Kd=0:
Simulink Model:
Any help would be grealty appreciated.
0 Comments
Answers (1)
Sam Chak
on 3 Mar 2023
Edited: Sam Chak
on 4 Mar 2023
Hi @Nick
Update: The reason behind the instablity is caused by the Fixed-step size solver.
If you want to let (by default), then readjust the following
timestep = 0.05/10;
so that the new timestep sec is smaller than the time constant of the derivative filter sec. In short, make sure that
.
3 Mar 2023: Not sure what went wrong, but your manually tuned PID gains in Simulink produced the same (stable) results as shown in MATLAB. I have also tested with my tuned PID gains. The closed-loop is also stable.
I suspect that some values in the transfer function block of the Plant are probably incorrectly entered. Cannot confirm without seeing how the values are entered in the Block Parameters.
J = 0.01;
b = 0.1;
K = 0.01;
R = 1;
L = 0.5;
voltage = 10;
stoptime = 10;
timestep= 0.05;
% Setup Transfer Function
num = [K];
den = [J*L R*J+b*L b*R+K^2];
Gp = tf(num, den)
dcgain(Gp)
step(voltage*Gp, 4)
% My Controller
kp1 = 15.5;
ki1 = 30;
kd1 = 0.21;
Tf1 = 1/12;
Gc1 = pid(kp1, ki1, kd1, Tf1)
Gcl1 = minreal(feedback(Gc1*Gp, 1))
step(voltage*Gcl1, 4)
S1 = stepinfo(Gcl1)
% Your Controller
kp2 = 60;
ki2 = 180;
kd2 = 4.5;
N = 100; % assuming the default value in the PID block
Tf2 = 1/N;
Gc2 = pid(kp2, ki2, kd2, Tf2)
Gcl2 = minreal(feedback(Gc2*Gp, 1))
step(voltage*Gcl2, 4)
S2 = stepinfo(Gcl2)
4 Comments
Sam Chak
on 4 Mar 2023
Edited: Sam Chak
on 4 Mar 2023
Hi @Nick
Found out that the reason behind the instablity is caused by the Fixed-step size solver.
Because you let N = 100 (untuned), which is equivalent to sec, the time constant of the 1st-order derivative filter is smaller than the selected 0.05 sec time-step in the solver, it cannot accurately produce the output of the derivative action, and thus causing the instability.
In my original PID controller above, the time constant of the 1st-order derivative filter is sec. If you set , and because the timestep , then it will produce a stable response.
Nevertheless, if you want to let (by default value), then readjust the following
timestep = 0.05/10;
so that the new timestep sec is smaller than sec.
If the proposed solution works, please consider accepting ✔ and voting 👍 the Answer. Thanks a bunch! 🙏
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!