PID Controller By
MATLAB
Automatic Control Course By :
Mahmoud Taha; Demonstrator.
Benha Faculty of Engineering
Benha University
April., 2015
1
Outlines:
PID Contr oller Over view
The Char acter istics of P, I, and D Contr oller s
Effect of Add P,PD,PI,PID contr oller to Mechanical system
Repr esent it in MATLAB M_Files
Effect of Adding PID contr oller to Ar matur e Contr olled DC motor & Repr esent
it in MATLAB Simulink using 3 methods to model DC motor
Repr esent Diff Equation using Integr ator
Using Tr ansfer Function Consept
Using State Space Repr esentation Method
Refer ences
We will discuss the effect of each of the PID parameters on the
closed-loop dynamics and demonstrate how to use a PID
controller to improve the system performance.
Instructor ENG / M.TAHA
Gc(s)
G(s)
The output of a PID controller, equal to the control input to the
plant, in the time-domain is as follows:
de
Gc (t ) =
Kp * e (t ) + Ki * e (t )dt + Kd *
dt
Instructor ENG / M.TAHA
A proportional controller (Kp) will have the effect of
reducing the rise time and will reduce but never eliminate
the steady-state error.
An integral control (Ki/s) will have the effect of
eliminating the steady-state error for a constant or step
input, but it may make the transient response slower.
A derivative control (Kd*s) will have the effect of
increasing the stability of the system, reducing the
overshoot, and improving the transient response.
3
Instructor ENG / M.TAHA
The effects of each of controller parameters, Kp, Ki, and
Kd on a closed-loop system are summarized in the table
below:
Closed
Loop
Response
Kp
Rise
time
Decrease
Increase
Small change
Steady
state
error
Decrease
Ki
Decrease
Increase
Increase
Eliminate
Kd
Small
change
Decrease
Decrease
No
change
Over shoot Settling time
Instructor ENG / M.TAHA
Note that these correlations may not be exactly accurate,
because Kp, Ki, and Kd are dependent on each other.
In fact, changing one of these variables can change the
effect of the other two. For this reason, the table should
only be used as a reference when you are determining
the values for Ki, Kp and Kd.
Instructor ENG / M.TAHA
Suppose Mass spring with Damper mechanical system
as shown:
It's modeling equation :
M * x + b * x + K * x =
F
where X ..... output and F..... Input
6
Instructor ENG / M.TAHA
transfer function between the displacement X(s) and the
input F(s) then becomes:
X (s )
1
=
F (s ) M * s 2 + b * s + K
Let M= 1 kg & b = 10 N.s/m & K= 20 N/m and F= 1 N
1
G (s ) = 2
s + 10s + 20
7
Instructor ENG / M.TAHA
Instructor ENG / M.TAHA
Instructor ENG / M.TAHA
10
Instructor ENG / M.TAHA
When you are designing a PID controller for a given system, follow
the steps shown below to obtain a desired response.
Obtain an open-loop response and determine what needs to be
improved
Add a proportional control to improve the rise time
Add a derivative control to improve the overshoot
Add an integral control to eliminate the steady-state error
Adjust each of Kp, Ki, and Kd until you obtain a desired overall response.
You can always refer to the table shown in this "PID Tutorial" page to
find out which controller controls what characteristics.
11
Instructor ENG / M.TAHA
Lastly, please keep in mind that you do not need to implement all
three controllers (proportional, derivative, and integral) into a single
system, if not necessary. For example, if a PI controller gives a good
enough response (like the above example), then you don't need to
implement a derivative controller on the system. Keep the controller
as simple as possible.
12
Instructor ENG / M.TAHA
MATLAB provides tools for automatically choosing optimal PID gains which
makes the trial and error process described above unnecessary. You can
access the tuning algorithm directly using pidtool command to open PID
(GUI).
pidtool(SYS,TYPE) designs a PID controller for plant SYS. SYS is a single-inputsingle-output LTI system
TYPE defines controller type, and can be one of the following strings:
'P'
Proportional only control
'I'
Integral only control
'PI'
PI control
'PD' PD control
'PDF' PD control with first order derivative filter
'PID' PID control
'PIDF' PID control with first order derivative filter
13
Instructor ENG / M.TAHA
14
Instructor ENG / M.TAHA
Suppose an armature controlled DC motor as Shown :
where :
Motor parameter
Ra= 1 ohm;
La= 0.5 H;
J=0.01 kg.m^2;
B=0.1 N.m.s;
Kb=0.01 V/rad/sec;
Kt=0.01 N.m/Amp;
15
Instructor ENG / M.TAHA
Model of armature controlled DC motor:
Electrical Equation:
dia
V a =ia * Ra + La *
+ Kb *w
dt
Mechanical Equation:
dw
Kt * ia T=
J*
+ B *w
L
dt
TL
Block Diagram :
+
Va
1
Ra + La * s
ia
Kt
Te
w
1
J *s + B
Kb
16
Instructor ENG / M.TAHA
DC motor Model can be represented by 3 methods
1st method Represent Diff equation By integrator :
dia V a Ra
Kb
=
* ia
*w
dt
La La
La
17
&
dw Kt * ia T L B
=
*w
dt
J
J J
Instructor ENG / M.TAHA
DC motor Model where there are 2 Diff equation:
dia V a Ra
Kb
* ia
*w
=
dt
La La
La
18
&
dw Kt * ia T L B
=
*w
dt
J
J J
Instructor ENG / M.TAHA
Where DC motor Model
19
Instructor ENG / M.TAHA
Where Closed Loop System shown and we make subsystem and mask to DC
motor Model
20
Instructor ENG / M.TAHA
Where PID controller Model
21
Instructor ENG / M.TAHA
22
Instructor ENG / M.TAHA
Actual speed & Ref speed
23
Instructor ENG / M.TAHA
We can implement Model of DC motor By an other Method By using Transfer
Function Block Directly
At this case there are two T.F as the system Multi input single output
There are 2 inputs Va & TL and 1 output W
So One T.F bet W and Va and another one bet W and TL
We assume that TL=0 .. No Load
So we will work By one T.F
+
Va
1/ La
s + Ra / La
ia
Kt
Te
1/ J
s +B /J
Kb
24
Instructor ENG / M.TAHA
T.F of Armature Controlled DC Motor
K t / La J
w (s )
=
V a (s ) (s + R a / La )(s + B / J ) + K b K t / La J
(2nd order system)
2
= 2
s + 12s + 20.02
25
Instructor ENG / M.TAHA
26
Armature Controlled DC Motor
Instructor ENG / M.TAHA
27
Armature Controlled DC Motor
Instructor ENG / M.TAHA
We can implement Model of DC motor By an other Method BY state space
Representation
At this case the system is Multi input single output
There are 2 inputs Va & TL and 1 output W
=
x Ax + Bu
=
y Cx + Du
From the Diff Equation :
dia V a Ra
Kb
=
* ia
*w
dt
La La
La
Ia = 2*V a 2* ia 0.02*w
28
&
dw Kt * ia T L B
=
*w
dt
J
J J
w =
ia 100T L 10*w
Instructor ENG / M.TAHA
We can implement Model of DC motor By an other Method BY state space
Representation
0 V a
Ia 2 0.02 Ia 2
+
T
10 w 0 100 L
w 1
29
V a
ia
( 01) w + ( 0 0 ) T
L
Instructor ENG / M.TAHA
We can implement Model of DC motor By an other Method BY state space
Representation and using PID Block
30
Instructor ENG / M.TAHA
Using PID Block
31
Instructor ENG / M.TAHA
Using PID Block
32
Instructor ENG / M.TAHA
References
http://en.wikipedia.org/wiki/PID_controller#/media/File:PID_en_updated_feedbac
k.svg
http://www.mathworks.com/help/control/examples/dc-motor-control.html
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=Con
trolPID
http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed§ion=Sim
ulinkModeling
http://ctms.engin.umich.edu/CTMS/index.php?example=AircraftPitch§ion=Sim
ulinkModeling