pid controller simulation

11
Basic simulation of digital standard-PID-controller Yoshihiko Takase and George Ibrahim Department of Mechatronics Engineering, Faculty of Mechanical and Electrical Engineering, Tishreen University, Lattakia, Syria Abstract Minimum essentia ls of simula tion of the PID controller to carry out a ser ies of experiment s related to the DC motor motion con trol were prepare d. The eect of PID parame ters to process va riable was examine d step by step. The result was consistent with Ziegler-Nichols and others method. The P cont roller show ed a big improvemen t of the step response, while it never eliminated steady -state error. The PI controller showed every good feature of P controlle r and in addition elimina ted the steady-state error. The PID cont roller show ed every good feature of PI controll er and in additio n sta ble contr ol capabi lit y. However, the noise problem appeared by the dig ita l dieren tiation. Practi cal PID controllers to elimina te the noise problem was discuss ed. 1 Introdu ct ion A proportional-integral-derivative controller (PID controller) is a common feedback loop component in industrial control systems. It is widely used in industries to improve the control system instead of simple On-Ocontroller. The main disadvantage of the On-Ocontroller is that a persistent oscillation of the process variable occurs.[1] In the absence of knowledge of the underlying process, a PID controller is the best controller.[2],[3] The practice project to understand the base of the process control plainly was planned for the student who studies the mechat ronic s engineering. The project consists of: 1. Characteristics of PIC PWM con- troller measured by USB based data acquisition system,[4] 2. Basic simulation of digital standard-PID- con trolle r,[5] 3. DC-mo tor speed con trol by PIC-ba sed digital PID-controller, 4. DC-mo tor simulatio n and verication of the result by experiment, 5. Locked anti-phase PWM PID-control of DC-motor speed, and 6. DC-mo tor p ositio n PID-c ontrol by simulati on and experimen t. The purpose of this study is to prepare minimum essentials of software of the PID controller to carry out a series of experiments related to the DC motor motio n control. The study process is to prepare a basic simulation system of the digital standard-PID-controller, to examine the eect of PID parameters (proportional gain, integral time and derivative time) to the process variable, and to discuss the optimum behavior by comparing it with the Ziegler-Nichols and others method. 2 Theoreti cal basi s Block diagram of traditional PID controller is shown in Figure 1.[3] Manipulated variable M V (t) as a function of time t, the output from the controller (i.e. the input to the process) is given by MV (t) = P OUT + I OUT + D OUT (1) where P OUT , I OUT and D OUT are the contributions to the output from the PID controller, each of which is dened below. 1

Upload: keitabando

Post on 08-Apr-2018

251 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 1/11

Basic simulation of digital standard-PID-controller

Yoshihiko Takase and George Ibrahim

Department of Mechatronics Engineering, Faculty of Mechanical and Electrical Engineering, Tishreen 

University, Lattakia, Syria 

Abstract

Minimum essentials of simulation of the PID controller to carry out a series of experimentsrelated to the DC motor motion control were prepared. The effect of PID parameters to process

variable was examined step by step. The result was consistent with Ziegler-Nichols and othersmethod. The P controller showed a big improvement of the step response, while it never eliminatedsteady-state error. The PI controller showed every good feature of P controller and in additioneliminated the steady-state error. The PID controller showed every good feature of PI controllerand in addition stable control capability. However, the noise problem appeared by the digitaldifferentiation. Practical PID controllers to eliminate the noise problem was discussed.

1 Introduction

A proportional-integral-derivative controller (PID controller) is a common feedback loop component inindustrial control systems. It is widely used in industries to improve the control system instead of simpleOn-Off controller. The main disadvantage of the On-Off controller is that a persistent oscillation of the

process variable occurs.[1] In the absence of knowledge of the underlying process, a PID controller is thebest controller.[2],[3]The practice project to understand the base of the process control plainly was planned for the student

who studies the mechatronics engineering. The project consists of: 1. Characteristics of PIC PWM con-troller measured by USB based data acquisition system,[4] 2. Basic simulation of digital standard-PID-controller,[5] 3. DC-motor speed control by PIC-based digital PID-controller, 4. DC-motor simulationand verification of the result by experiment, 5. Locked anti-phase PWM PID-control of DC-motor speed,and 6. DC-motor position PID-control by simulation and experiment.

The purpose of this study is to prepare minimum essentials of software of the PID controller to carryout a series of experiments related to the DC motor motion control. The study process is to prepare abasic simulation system of the digital standard-PID-controller, to examine the effect of PID parameters(proportional gain, integral time and derivative time) to the process variable, and to discuss the optimumbehavior by comparing it with the Ziegler-Nichols and others method.

2 Theoretical basis

Block diagram of traditional PID controller is shown in Figure 1.[3]Manipulated variable MV (t) as a function of time t, the output from the controller (i.e. the input to

the process) is given by

MV (t) = P OUT + I OUT + DOUT  (1)

where P OUT , I OUT and DOUT are the contributions to the output from the PID controller, each of which is defined below.

1

Page 2: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 2/11

Process

Measurement(Sensor)

PID Controller 

)(t e

  )(t PV 

  )(t MV 

++

+

+

  )(t eK PPOUT 

=

  ∫ =t 

I OUT d eK I 

0)( ττ

 dt 

deK D

DOUT =

 PS 

Fig. 1 Block diagram of PID controller and process

P OUT = K P e(t), (2)

I OUT = K I 

∫ t

0

e(τ )dτ, (3)

DOUT = K Dde

dt, (4)

where

e(t) = SP −PV (t) (5)

is the error, SP the setpoint and PV (t) the process variable. Proportional gain K P , integral gainK I and derivative gain K D are constants that are used to tune the PID control loop. Normally K I isexpressed as being related to K P by introducing integral time T I which is a time where I OUT is equalto P OUT against e(t) being changed as a step function with amplitude e0:

K I 

∫ T I

0

e0dτ = K P e0. (6)

From equation 6, K I is given by

K I = K P /T I . (7)

Similarly K D is replaced by a derivative time T D which is a time where DOUT is equal to P OUT againsta linear function of e(t) = αt where α is the slope:

αK D = αK P T D. (8)

From equation 8, K D is given by

K D = K P T D. (9)

As a result MV (t) is expressed in terms of K P , T I and T D as follows:

MV (t) = K P 

(e(t) +

1

T I 

∫ t

0

e(τ )dτ + T Dde

dt

). (10)

This form of PID controller is referred to as the standard form and is more common in industry. In

this form, T I and T D relate only to dynamics of the process, and K P relates to the gain of the process.

2

Page 3: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 3/11

For a digital implementation of a PID controller, the standard form of the PID controller has to bediscretised. Approximations for first-order derivatives are made by backward finite differences. Thus,

the discretised PID controller is obtained as:

MV n = K P 

en +

1

T I ∆t

n∑i=0

ei +T D∆t

(en −en−1)

, (11)

where ∆t is the sampling time and n the sampling number corresponds the present time. Equation 11is referred to as the positional algorithm.[1],[6]

The previous value of MV n is

MV n−1 = K P 

en−1 +

1

T I ∆t

n−1∑i=0

ei +T D∆t

(en−1 −en−2)

. (12)

Difference of the present MV n is obtained by subtracting equation 12 from equation 11.

∆MV n = K P 

(en −en−1 +

∆t

T I en +

T D∆t

(en −2en−1 + en−2)

)(13)

MV n = MV n−1 + ∆MV n (14)

Equations 13 and 14 are referred to as the velocity algorithm.[1],[6]

3 Standard PID controller program

The standard PID velocity-algorithm was implemented by the C while loop as follows. For the purpose

of displaying the results graphically the Windows API were used.

SP = 200.0; PV = MV = 0.0; en_1 = en_2 = 0.0; DT = 0.1;

// Processing loop of the standard PID controller of velocity algorithm

while (true) {

// Equation (5)

e = SP - PV;

// Equation (13)

dMV = Kp*(e - en_1) + Kp*DT/Ti*e + Kp*Td/DT*(e - 2*en_1 + en_2);

// Equation (14)

MV = MVn_1 + dMV;

// inport from measurement

PV = inport(PV, MV);// Update previous value to current value

MVn_1 = MV;

// Update previous value to current value

en_2 = en_1;

// Update previous value to current value

en_1 = e;

}

The inport(PV, MV) function in the program returns the process variable. The process model and itsC program is described in the discussion section.

3

Page 4: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 4/11

4 Step response of the process under PID controlFirst, the step response of the process under the P control was examined by changing K P and settingintegral and derivative contributions zero. The step responses at K P = 0.1, 1.0, 1.5 and 2.5 are shownin Figures 2, 3, 4 and 5, respectively. Two variables, PV and MV , are shown. Middle thin line indicatesthe setpoint SP .

Fig. 2 Step response under P control at K P = 0.1 Fig. 3 Step response under P control at K P = 1.0

Fig. 4 Step response under P control at K P = 1.5 Fig. 5 Step response under P control at K P = 2.5

Second, effect of K P on the step response under the PI control was examined by changing K P andsetting T I constant and T D zero. Values of K P , T I and T D are listed in Table 1. The step responsesare shown in Figures 6, 7, 8 and 9. Five variables, PV , MV , P OUT , I OUT and DOUT , are shown. Themiddle thin line indicates SP .

Third, effect of T I on the step response under the PI control was examined by changing T I and settingK P constant and T D zero. Values of K P , T I and T D are listed in Table 2. The step responses are shownin Figures 10, 11, 12 and 13. Five variables are shown as same as the above examination. The middlethin line indicates SP .

Forth, effect of T D on the step response under the PID control was examined by changing T D and

setting K P and T I constant. Values of K P , T I and T D are listed in Table 3. The step responses are

4

Page 5: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 5/11

K P  T I  T D1 0.1 3.0 0.02 1.0 3.0 0.03 1.5 3.0 0.04 2.0 3.0 0.0

Table. 1 Examined values of K P , T I and T D under PI control

Fig. 6 Step response under PI control at K P = 0.1 Fig. 7 Step response under PI control at K P = 1.0

Fig. 8 Step response under PI control at K P = 1.5 Fig. 9 Step response under PI control at K P = 2.5

K P  T I  T D1 1.2 5.0 0.02 1.2 3.0 0.03 1.2 1.5 0.04 1.2 0.7 0.0

Table. 2 Examined values of K P , T I and T D under PI control

5

Page 6: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 6/11

Fig. 10 Step response under PI control at T I = 5.0 Fig. 11 Step response under PI control at T I = 3.0

Fig. 12 Step response under PI control at T I = 1.5 Fig. 13 Step response under PI control at T I = 0.7

shown in Figures 14, 15, 16 and 17. Five variables are shown as same as the PI controller. The middlethin line indicates SP .

K P  T I  T D1 1.2 3.0 0.01

2 1.2 3.0 0.053 1.2 3.0 0.104 1.2 3.0 0.15

Table. 3 Examined values of K P , T I and T D under PID control

5 Discussion

A first-order-plus-dead-time (FOPDT) process model is often used to represent the step responsecharacteristics of simple systems.[1] The transfer function of the model is expressed by the followingequation.[2],[6]

6

Page 7: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 7/11

Fig. 14 Step response under PID control at T D = 0.01 Fig. 15 Step response under PID control at T D = 0.05

Fig. 16 Step response under PID control at T D = 0.10 Fig. 17 Step response under PID control at T D = 0.15

GP (s) = K 1

1 + T P · se−LP ·s, (15)

where K is the equivalent gain, T P the equivalent time constant and LP the equivalent dead time of the process. Changing the transfer function to differential equation the following relation is obtained.

yn + T P yn −yn−1

∆t= Kxn−l, (16)

where x and y are input and output of the process, respectively, and l is integer given by

LP = l∆t. (17)

From equation 16 the following formula is obtained.

yn =T P 

∆t + T P yn−1 +

∆t ·K 

∆t + T P xn−l (18)

Equation 18 was calculated by the following C function. The dead time was expressed by a first-in

first-out type buffer.

7

Page 8: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 8/11

// pv: process variable

double inport(double pv, double x)

{int i;

// y: output of the process

double y;

// l: integer index of the dead time

static double buff[l];

// x: input of the process in equation (18)

buff[l-1] = x;

y = T / (DT + T) * pv + buff[0] * DT * K / (DT + T);

// shift left of the buffer element

for (i = 0; i < l - 1; i++) {

buff[i] = buff[i+1];

}

return y;

}

The step response of this program against unit step input is shown in Figure 18 at K = 5.0, T P = 3.0,l = 3 and DT = 0.1. Gray dotted line is the step function and black dotted line is the response. Thinlines indicate the gain K and the time constant T P .

Fig. 18 Step response of a process

There are some important proposals to determine the PID parameters as listed in Table 4.

K P  T I  T D Test pointZiegler&Nichols 1.2T/(KL) 2.0L 0.5L Decay ratio 25%

CHR Case 1 0.95T/(KL) 2.4L 0.4L No overshootCHR Case 1 1.2T/(KL) 2L 0.42L Overshoot 20 %CHR Case 2 0.6T/(KL) T 0.5L No overshootCHR Case 2 0.95T/(KL) 1.35T 0.47L Overshoot 20%

CHR: Chein, Hrones and Reswick methodCase 1: Most suitable to external disturbanceCase 2: Most suitable to follow the set point

Table. 4 Proposals to determine the parameters of PID controller [3], [6]

In the present case of K = 5.0, T P = 3.0 and LP = 0.3, the values of K P , T I and T D become as shown

8

Page 9: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 9/11

in Table 5.

K P  T I  T D Test pointZiegler&Nichols 2.4 0.60 0.15 Decay ratio 25%

CHR Case 1 1.9 0.72 0.12 No overshootCHR Case 1 2.4 0.60 0.13 Overshoot 20%CHR Case 2 1.2 3.0 0.15 No overshootCHR Case 2 1.9 4.0 0.14 Overshoot 20 %

Table. 5 Determined PID parameters

The step response under the P control, Figures 2 - 5, indicates that the time constant at rising edgebecomes small as K P increases. Figure 3 shows a good step response, however, certain amount of error,e(t) = SP − PV (t), remains even after the steady state. This is the well known steady-state errorproblem of the P controller.[7] The error still exists even for K P = 2.5 where the response curve becomes

oscillatory. P controller is useful for simple and qualitative control.The step response under the PI control, Figures 6 - 9, indicates that the response is similar to that of 

the P controller except the steady-state error problem. The steady-state error, e(t), is now almost zero.This is the most significant effect of the integral term. The best curve among the four simulation resultsis Figure 7 where K P = 1.0, T I = 3.0 and T D = 0.0. These values are close to the CHR case 2 on noovershoot condition in Table 5. The improvement is significant when this result is compared with theinsufficient control result in Figure 6.

The step response under the PI control, Figures 10 - 13, indicates that the integral contributiondecreases the error as T I decreases. For smaller value of T I than 0.7, however, the curve begins tooscillate.

The step response under the PID control, Figures 14 - 17, indicates that DOUT affects as negativefeedback especially in initial time region. As a result initial overshoot is suppressed and becomes stable

in all time region as can be seen by comparing Figure 11 (PI controller) and Figures 14 and 15 (PIDcontroller). The best curve among the four simulation results is Figure 15 where K P = 1.2, T I = 3.0 andT D = 0.05. These values are close to the CHR case 2 on no overshoot condition in Table 5. Applicationof exact value, however, of the CHR case 2, K P = 1.2, T I = 3.0 and T D = 0.15 in Table 5, revealednoise problem as shown in Figure 17. The PID controller has every good feature of PI controller and inaddition stable control capability. On the other hand, Figure 17 exhibits a noise problem of the digitalPID controller.

The digital noise problem of the standard PID controller is examined by a step response of MV (t),P OUT , I OUT and DOUT against step functional change of the error e(t). The result is shown in Figure19.

Fig. 19 Step response against step functional change of the error e(t).

9

Page 10: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 10/11

P OUT is proportional to the step function and becomes constant. I OUT becomes a straight line witha slope. DOUT shows a sharp spike at the rising edge. For the purpose of constructing practical PID

controller at industrial use it is important to eliminate this kind of digital noise problem.Hiroi and Miyata[6] have summarized the practical PID controller with derivative contribution havingthe first order lag as follows.

Type 1 practical PID controller:Block diagram of this type is shown in Figure 20. This type of controller has low pass filter in front of 

the derivative contribution.

P

I

D

sT 

sT 

D

D

⋅+

η1

)(t e

  )(t PV 

  )(t MV 

++

+

+sT I ⋅

1

 PK  )(sGp PS 

Fig. 20 Block diagram of Type 1 practical PID controller and process

Type 2 practical PID controller:The Type 1 still has ability to generate spike against steep change of SP . The derivative contribution

is the most effective to the steep change of SP . In order to reduce this effect, the term (en − en−1) isreplaced by (PV n−1 −PV n). Block diagram of this type is shown in Figure 21.

P

I

D

sT 

sT 

D

D

⋅+

η1

)(t e

  )(t PV 

  )(t MV 

− −

++

+

sT I ⋅

1

 PK  )(sGp PS 

Fig. 21 Block diagram of Type 2 practical PID controller and process

Type 3 practical PID controller:The proportional contribution is the second effective part to the steep change of SP . In order to

reduce further this effect, all of the terms (en−en−1) are replaced by (PV n−1−PV n). Block diagram of this type is shown in Figure 22.

Examination of some practical PID controllers will be presented later including both simulation andexperiment.

6 Conclusion

Minimum essentials of simulation of the PID controller to carry out a series of experiments related to the

DC motor motion control were prepared. The effect of PID parameters to process variable was examined

10

Page 11: PID Controller Simulation

8/7/2019 PID Controller Simulation

http://slidepdf.com/reader/full/pid-controller-simulation 11/11

P

I

D

sT 

sT 

D

D

⋅+

η1

)(t e

  )(t PV 

  )(t MV 

− −

+ +

sT I ⋅

1

 PK  )(sGp PS 

Fig. 22 Block diagram of Type 3 practical PID controller and process

step by step. The result was consistent with Ziegler-Nichols and others method. The P controller showeda big improvement of the step response, while it never eliminated steady-state error. The PI controllershowed every good feature of P controller and in addition eliminated the steady-state error. The PIDcontroller showed every good feature of PI controller and in addition stable control capability. However,the noise problem appeared by the digital differentiation. Practical PID controllers to eliminate the noiseproblem was discussed.

References

[1] A. Visioli: Practical PID control, p.3, Springer-Verlag London Limited (2006).[2] M. Araki: CONTROL SYSTEMS, ROBOTICS, AND AUTOMATION - Vol. II - PID Control,

Encyclopedia of Life Support Systems (Copyright 2002-2010).

[3] Wikipedia: PID controller (last modified on 6 November 2010), http://en.wikipedia.org/wiki/PID controller.

[4] Y. Takase and George Ibrahim: Characteristics of PIC PWM Controller Measured by USB BasedData Acquisition System, The Forth Report of Senior Volunteer of JICA (April 16, 2008).

[5] Y. Takase and George Ibrahim: Basic simulation of digital standard-PID-controller, The Forth Reportof Senior Volunteer of JICA (April 16, 2008).

[6] K. Hiroi and A. Miyata: Introduction to Control Engineering using Simulation System (in Japanese),CQ Publishing Co., Ltd. (October 2004).

[7] University of Michigan: Control Tutorials for Matlab, PID Tutorial (August 1997), http://www.

engin.umich.edu/group/ctm/PID/PID.html.

11