Num 1 Den (1 20 30) Plant TF (Num, Den) Step (Plant,'r') Xlabel ('Amplitude - ') Ylabel ('Time - ') Title ('Plant Function Response')
Num 1 Den (1 20 30) Plant TF (Num, Den) Step (Plant,'r') Xlabel ('Amplitude - ') Ylabel ('Time - ') Title ('Plant Function Response')
Theory:
A PID controller consists of a Proportional element, an Integral element and a Derivative element, all
three connected in parallel. All of them take the error as input. Kp, Ki, Kd are the gains of P, I and D
elements respectively.
The best way to understand something is by simulating it. So I simulated a PID controller in matlab. The
matlab code is provided at the end of this article.
Let me assume a suitable mathematical model for the plant and then go ahead with designing the
controller.
The step response of a system is the output of the system when the input to the system is a unit step.
The open loop step response of the above plant is
num=1;
den=[1 20 30];
Plant = tf(num,den);
step(Plant,r);
xlabel('Amplitude---->');
ylabel('time----->');
title('Plant Function Response');
It can be seen that the step response output is close to 0.035. The steady state error = 1-0.035 = 0.965.
Thats quite high! Also observe that the settling time is around 3 sec.
Now lets see what is the effect of PID controller on the system response.
Lets see the effect of proportional element on the system output.
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=10;
P_Sys = tf(Kp,1);
OpenLoop=series(P_Sys,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(P Controller Response');
The output is now 0.25. Much better than the open loop response! (The curve in red shows the open
loop step response of the plant)
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=100;
P_Sys = tf(Kp,1);
OpenLoop=series(P_Sys,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(P Controller Response');
The output is now 0.77. So its clear now that increasing Kp will reduce the steady state error.
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=200;
P_Sys = tf(Kp,1);
OpenLoop=series(P_Sys,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(P Controller Response');
The output is around 0.87. Also observe that the ripples have started appearing in the output. If Kp is
increased further it will only lead to increase in ripples or overshoot. The rise time also has decreased.
Also observe that there is a small steady state error (1 0.87 = 0.13).
Conclusion
Increasing Kp will reduce the steady state error.
After certain limit, increasing Kp will only increase overshoot.
Kp reduces rise time.
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=200;
P_Sys = tf(Kp,1);
Ki=10;
den2=[1 0];
I_Sys=tf(Ki,den2);
PI=parallel(P_Sys,I_Sys);
OpenLoop=series(PI,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(PI Controller Response');
Fig 5: PI Controller Unit Step Response
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=200;
P_Sys = tf(Kp,1);
Ki=300;
den2=[1 0];
I_Sys=tf(Ki,den2);
PI=parallel(P_Sys,I_Sys);
OpenLoop=series(PI,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(PI Controller Response');
The output is now close to 0.99. Thats very close to the setpoint. But observe that settling time has
increased.
num=1;
den=[1 20 30];
Plant = tf(num,den);
Kp=200;
P_Sys = tf(Kp,1);
Ki=200;
den2=[1 0];
I_Sys=tf(Ki,den2);
PI=parallel(P_Sys,I_Sys);
OpenLoop=series(PI,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
xlabel('Amplitude---->');
ylabel('time----->');
title(PI Controller Response');
Fig 7: Final PI Controller Reduced Settling Time and Steady State Error.
Observe that rise time has now reduced and steady state error is very small.
num=1;
den=[1 20 30];
Plant = tf(num,den);
step(Plant,r);
hold on;
Kp=200;
P_Sys = tf(Kp,1);
Ki=300;
den2=[1 0];
I_Sys=tf(Ki,den2);
Kd=0;
num3=[Kd 0];
D_Sys=tf(num3,1);
PI=parallel(P_Sys,I_Sys);
PID=parallel(PI,D_Sys);
OpenLoop=series(PID,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
Observe that steady state error is close to 0 now. But increasing Ki has resulted in overshoot.
num=1;
den=[1 20 30];
Plant = tf(num,den);
step(Plant,r);
hold on;
Kp=200;
P_Sys = tf(Kp,1);
Ki=300;
den2=[1 0];
I_Sys=tf(Ki,den2);
Kd=10;
num3=[Kd 0];
D_Sys=tf(num3,1);
PI=parallel(P_Sys,I_Sys);
PID=parallel(PI,D_Sys);
OpenLoop=series(PID,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);
Wow! What a response! Where is the overshoot? It has disappeared. There is a reduction in settling
time as well.
So the ideal PID values for our plant is Kp = 200, Ki = 300 and Kd = 10.
num=1;
den=[1 20 30];
Plant = tf(num,den);
step(Plant,r);
hold on;
Kp=200;
P_Sys = tf(Kp,1);
Ki=300;
den2=[1 0];
I_Sys=tf(Ki,den2);
Kd=10;
num3=[Kd 0];
D_Sys=tf(num3,1);
PI=parallel(P_Sys,I_Sys);
PID=parallel(PI,D_Sys);
OpenLoop=series(PID,Plant);
ClsdLoop = feedback(OpenLoop,[1]);
step(ClsdLoop,b);