Simulink PID Controller not behaving Properly

117 vues (au cours des 30 derniers jours)
Nick
Nick le 2 Mar 2023
Modifié(e) : Sam Chak le 4 Mar 2023
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.

Réponses (1)

Sam Chak
Sam Chak le 3 Mar 2023
Modifié(e) : Sam Chak le 4 Mar 2023
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)
Gp = 0.01 --------------------------- 0.005 s^2 + 0.06 s + 0.1001 Continuous-time transfer function.
dcgain(Gp)
ans = 0.0999
step(voltage*Gp, 4)
% My Controller
kp1 = 15.5;
ki1 = 30;
kd1 = 0.21;
Tf1 = 1/12;
Gc1 = pid(kp1, ki1, kd1, Tf1)
Gc1 = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = 15.5, Ki = 30, Kd = 0.21, Tf = 0.0833 Continuous-time PIDF controller in parallel form.
Gcl1 = minreal(feedback(Gc1*Gp, 1))
Gcl1 = 36.04 s^2 + 432 s + 720 ---------------------------------------- s^4 + 24 s^3 + 200.1 s^2 + 672.2 s + 720 Continuous-time transfer function.
step(voltage*Gcl1, 4)
S1 = stepinfo(Gcl1)
S1 = struct with fields:
RiseTime: 0.5604 TransientTime: 0.9754 SettlingTime: 0.9754 SettlingMin: 0.9009 SettlingMax: 1.0000 Overshoot: 0 Undershoot: 0 Peak: 1.0000 PeakTime: 2.3733
% 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)
Gc2 = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = 60, Ki = 180, Kd = 4.5, Tf = 0.01 Continuous-time PIDF controller in parallel form.
Gcl2 = minreal(feedback(Gc2*Gp, 1))
Gcl2 = 1020 s^2 + 12360 s + 36000 ---------------------------------------------- s^4 + 112 s^3 + 2240 s^2 + 1.436e04 s + 3.6e04 Continuous-time transfer function.
step(voltage*Gcl2, 4)
S2 = stepinfo(Gcl2)
S2 = struct with fields:
RiseTime: 0.1637 TransientTime: 0.8502 SettlingTime: 0.8502 SettlingMin: 0.9002 SettlingMax: 1.0682 Overshoot: 6.8183 Undershoot: 0 Peak: 1.0682 PeakTime: 0.4425
  4 commentaires
Nick
Nick le 4 Mar 2023
Modifié(e) : Nick le 4 Mar 2023
Right!? Here are both the simulink model and my code files.
Worth noting that lowering the value of N seemd to offer an improvement, but another project requirement is that the controller output shouldnt exceed 25V, but im seeting 200-300v overshoot. any ideas there?
Sam Chak
Sam Chak le 4 Mar 2023
Modifié(e) : Sam Chak le 4 Mar 2023
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! 🙏

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by