36
PID Controller By MATLAB Automatic Control Course By : Mahmoud Taha; Demonstrator. Benha Faculty of Engineering Benha University April., 2015 1

PID Controller By Matlab

Embed Size (px)

DESCRIPTION

Discuss PID Controller by using Matlab M-files and Simulink

Citation preview

Page 1: PID Controller By Matlab

PID Controller By MATLAB

Automatic Control Course By :Mahmoud Taha; Demonstrator.

Benha Faculty of EngineeringBenha University

April., 20151

Page 2: PID Controller By Matlab

Outlines:• PID Controller Overview

• The Character istics of P, I, and D Controllers

• Effect of Add P,PD,PI,PID controller to Mechanical system

Represent it in MATLAB M_Files

• Effect of Adding PID controller to Armature Controlled DC motor & Represent

it in MATLAB Simulink using 3 methods to model DC motor

Represent Diff Equation using Integrator

Using Transfer Function Consept

Using State Space Representation Method

• References

Page 3: PID Controller By Matlab

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.TAHA1

Page 4: PID Controller By Matlab

The output of a PID controller, equal to the control input to the

plant, in the time-domain is as follows:

( ) * ( ) * ( ) * deGc t Kp e t Ki e t dt Kddt

= + +∫

Gc(s) G(s)

Instructor ENG / M.TAHA2

Page 5: PID Controller By Matlab

• 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.

Instructor ENG / M.TAHA3

Page 6: PID Controller By Matlab

• The effects of each of controller parameters, Kp, Ki, and Kd on a closed-loop system are summarized in the table below:

Steady state error

Settling timeOver shootRisetime

ClosedLoop

ResponseDecreaseSmall changeIncreaseDecreaseKp

EliminateIncreaseIncreaseDecreaseKi

Nochange

DecreaseDecreaseSmall change

Kd

Instructor ENG / M.TAHA4

Page 7: PID Controller By Matlab

• 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.TAHA5

Page 8: PID Controller By Matlab

• Suppose Mass spring with Damper mechanical systemas shown:

It's modeling equation :

where X ..... output and F..... Input

* * *M x b x K x F+ + =

Instructor ENG / M.TAHA6

Page 9: PID Controller By Matlab

• transfer function between the displacement X(s) and the input F(s) then becomes:

Let M= 1 kg & b = 10 N.s/m & K= 20 N/m and F= 1 N

2

( ) 1( ) * *

X sF s M s b s K

=+ +

2

1( )10 20

G ss s

=+ +

Instructor ENG / M.TAHA7

Page 10: PID Controller By Matlab

Instructor ENG / M.TAHA8

Page 11: PID Controller By Matlab

Instructor ENG / M.TAHA9

Page 12: PID Controller By Matlab

Instructor ENG / M.TAHA10

Page 13: PID Controller By Matlab

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.

Instructor ENG / M.TAHA11

Page 14: PID Controller By Matlab

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.

Instructor ENG / M.TAHA12

Page 15: PID Controller By Matlab

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-input-single-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

Instructor ENG / M.TAHA13

Page 16: PID Controller By Matlab

Instructor ENG / M.TAHA14

Page 17: PID Controller By Matlab

Suppose an armature controlled DC motor as Shown :where :

Motor parameterRa= 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;

Instructor ENG / M.TAHA15

Page 18: PID Controller By Matlab

Model of armature controlled DC motor:

Electrical Equation:

Mechanical Equation:

Block Diagram :

* * *diaVa ia Ra La Kb wdt

= + +

* * *LdwKt ia T J B wdt

− = +

Va Kt1*Ra La s+

ia

TL

1*J s B+

Kb

wTe+ +

-

-

Instructor ENG / M.TAHA16

Page 19: PID Controller By Matlab

DC motor Model can be represented by 3 methods 1st method Represent Diff equation By integrator :

&* *dia Va Ra Kbia wdt La La La

= − −* *LTdw Kt ia B w

dt J J J= − −

Instructor ENG / M.TAHA17

Page 20: PID Controller By Matlab

DC motor Model where there are 2 Diff equation:

&* *dia Va Ra Kbia w

dt La La La= − − * *LTdw Kt ia B w

dt J J J= − −

Instructor ENG / M.TAHA18

Page 21: PID Controller By Matlab

Where DC motor Model

Instructor ENG / M.TAHA19

Page 22: PID Controller By Matlab

Where Closed Loop System shown and we make subsystem and mask to DC motor Model

Instructor ENG / M.TAHA20

Page 23: PID Controller By Matlab

Where PID controller Model

Instructor ENG / M.TAHA21

Page 24: PID Controller By Matlab

Instructor ENG / M.TAHA22

Page 25: PID Controller By Matlab

Actual speed & Ref speed

Instructor ENG / M.TAHA23

Page 26: PID Controller By Matlab

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 Kt1//

Las Ra La+

ia1/

/J

s B J+

Kb

wTe+

-

24

Page 27: PID Controller By Matlab

Instructor ENG / M.TAHA

• T.F of Armature Controlled DC Motor

(2nd order system)

/( )( ) ( / )( / ) /

t a

a a b t a

K L Jw sVa s s R L s B J K K L J

=+ + +

2

212 20.02s s

=+ +

25

Page 28: PID Controller By Matlab

Instructor ENG / M.TAHA

• Armature Controlled DC Motor

26

Page 29: PID Controller By Matlab

Instructor ENG / M.TAHA

• Armature Controlled DC Motor

27

Page 30: PID Controller By Matlab

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

• From the Diff Equation :

&

x Ax Buy Cx Du= += +

* *dia Va Ra Kbia wdt La La La

= − −* *LTdw Kt ia B w

dt J J J= − −

2* 2* 0.02*Ia Va ia w= − − 100 10*Lw ia T w= − −

28

Page 31: PID Controller By Matlab

Instructor ENG / M.TAHA

• We can implement Model of DC motor By an other Method BY state space

Representation

2 0.02 2 01 10 0 100 L

VaIa IaTw w

− − = + − −

)( )(01 00L

Vaiaw

Tw

= +

29

Page 32: PID Controller By Matlab

Instructor ENG / M.TAHA

• We can implement Model of DC motor By an other Method BY state space

Representation and using PID Block

30

Page 33: PID Controller By Matlab

Instructor ENG / M.TAHA

• Using PID Block

31

Page 34: PID Controller By Matlab

Instructor ENG / M.TAHA

• Using PID Block

32

Page 35: PID Controller By Matlab

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&section=Con

trolPID

• http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed&section=Sim

ulinkModeling

• http://ctms.engin.umich.edu/CTMS/index.php?example=AircraftPitch&section=Sim

ulinkModeling

Page 36: PID Controller By Matlab