Study of P, PD, Pi, Pid Controllers Using Mat Lab
Study of P, PD, Pi, Pid Controllers Using Mat Lab
AIM:
To study the effect of P, PD, PI, PID controllers using Mat lab.
The output of a PID controller, equal to the control input to the plant (u), in the time-domain is as
follows:
( ) ( ) ∫ ( ) (1)
Working of PID controller in a closed-loop system
The variable ( ) represents the tracking error, the difference between the desired input value ( )
and the actual output ( ). This error signal ( ) will be sent to the PID controller, and the controller
computes both the derivative and the integral of this error signal. The control signal ( ) to the
plant is equal to the proportional gain ( ) times the magnitude of the error plus the integral gain
( ) times the integral of the error plus the derivative gain ( ) times the derivative of the error.
This control signal ( ) is sent to the plant, and the new output ( ) is obtained. The new output ( )
is then fed back and compared to the reference to find the new error signal ( ). The controller
takes this new error signal and computes its derivative and its integral again, ad infinitum.
The transfer function of a PID controller is found by taking the Laplace transform of (1).
Kp = 1; Ki = 1; Kd = 1;
sys = tf('sys');
C = Kp + Ki/s + Kd*s
C=
s^2 + s + 1
-----------
C = pid (Kp,Ki,Kd)
C=
Kp + Ki * --- + Kd * s
with Kp = 1, Ki = 1, Kd = 1
Converting the pid object to a transfer function using the command tf(C)
ans =
s^2 + s + 1
----------------
The transfer function between the displacement and the input then becomes
Let
M = 1 kg
b = 10 N s/m
k = 20 N/m
F=1N
The goal of this problem is to show how each of , and contributes to obtain
Step (P)
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to a unit
step input. This corresponds to the steady-state error of 0.95, quite large indeed. Furthermore, the
rise time is about one second, and the settling time is about 1.5 seconds. Let's design a controller
that will reduce the rise time, reduce the settling time, and eliminate the steady-state error.
P CONTROLLER
The closed-loop transfer function of the above system with a proportional controller is:
kp
----------------
s^2 + 10 s + 20+kp
Kp = 300;
C = pid(Kp)
T = feedback(C*P,1);
t = 0:0.01:2;
step(T,t)
C =
Kp = 300
T =
300
----------------
s^2 + 10 s + 320
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec)
Proportional controller (Kp) reduces the rise time, increases the overshoot, and reduces the
steady-state error.
PD CONTROLLER
The closed-loop transfer function of the given system with a PD controller is:
kd s + kp
----------------
kp=300;
kd=10;
num=[kd kp];
sys=tf(num,den)
t=0:.01:2;
step(num,den,t)
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec)
The derivative controller (Kd) reduces both the overshoot and the settling time.
PI CONTROLLER
Kp s + ki
------------------------
kp=30;
ki=70;
num=[kp ki];
sys=tf(num,den)
t=0:.01:2;
step(num,den,t)
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec)
An integral controller (Ki) decreases the rise time, increases both the overshoot and the settling
time, and eliminates the steady-state error.
PID CONTROLLER
The closed-loop transfer function of the given system with a PID controller is:
kd s^2 + kp s + ki
--------------------------
kp=350;
ki=300;
kd=50;
num=[kd kp ki];
sys=tf(num,den)
t=0:.01:2;
step(num,den,t)
Step Response
1
0.9
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec)
Adjust each of Kp, Ki, and Kd until a desired overall response is obtained.
Lastly, please keep in mind that all three controllers (proportional, derivative, and integral) may
not be implemented into a single system. For example, if a PI controller gives a good enough
response, then don't need to implement a derivative controller on the system. Keep the controller
as simple as possible.
Let's explore these automated tools by first generating a proportional controller for the mass-
spring-damper system by entering the following commands:
The pidtool GUI window, like that shown below, should appear.
Notice that the step response shown is slower than the proportional controller we designed by
hand. Now click on the Show Parameters button on the top right. As expected the proportional
gain constant, Kp, is lower than the one we used, Kp = 94.85 < 300.
We can now interactively tune the controller parameters and immediately see the resulting
response in the GUI window. Try dragging the response time slider to the right to 0.14s, as shown
in the figure below. The response does indeed speed up, and we can see Kp is now closer to the
manual value. We can also see all the other performance and robustness parameters for the
system. Note that the phase margin is 60 degrees, the default for pidtool and generally a good
balance of robustness and performance.
Now let's try designing a PID controller for our system. By specifying the previously designed or
(baseline) controller, C, as the second parameter, pidtool will design another PID controller
(instead of P or PI) and will compare the response of the system with the automated controller
with that of the baseline.
Pidtool (P,C)
We see in the output window that the automated controller responds slower and exhibits more
overshoot than the baseline. Now choose the Design Mode: Extended option at the top, which
reveals more tuning parameters.
Now type in Bandwidth: 32 rad/s and Phase Margin: 90 deg to generate a controller similar in
performance to the baseline. Keep in mind that a higher bandwidth (0 dB crossover of the open-
loop) results in a faster rise time, and a higher phase margin reduces the overshoot and improves
the system stability.
Finally we note that we can generate the same controller using the command line
tool pidtune instead of the pidtool GUI
opts = pidtuneOptions('CrossoverFrequency',32,'PhaseMargin',90);
[C, info] = pidtune(P, 'pid', opts)
C=
Kp + Ki * --- + Kd * s
s
with Kp = 320, Ki = 169, Kd = 31.5 Continuous-time PID controller in parallel form.
info =
Stable: 1
CrossoverFrequency: 32
PhaseMargin: 90