Lecture 8: From Analog To Digital Controllers, PID Control Design Approaches

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Lecture 8: From Analog to Digital Controllers, PID Control

[IFAC PB Ch 6, Ch 8, RTCS Ch 10]

Design Approaches
ContinuousTime Process Model Lectures 6,7,9 Lecture 8

Discretized Process Model

Control Design in Continuous Time

Discrete-time approximation of continuous-time controllers


State-space domain Frequency domain
Control Design in Discrete Time Discretized Controller

The PID Controller


Difference Equation Software Algorithm

1 2

Implementing a Continuous-Time Controller Using a Computer


H ( z) G (s) u(t) A-D

Methods: Differentiation and Tustin approximations


State-space domain Frequency domain

{u ( kh )}

Algorithm

{ y ( kh )}

y (t) D-A

Step invariance (ZOH)


Clock

Ramp invariance (FOH) Pole-zero matching


(Tustin and the three last methods are available in Matlabs c2d command)

Want to nd discrete-time Algorithm such that


A-D + Algorithm + D-A Continuous Controller

Differentiation and Tustin Approximations


Forward difference (Eulers method):
dx(t) dt x(t + h) x(t) q1 x(t) = h h

State-Space Domain
Assume that the controller is given in state-space form
dx = Ax + Bu dt y = Cx + Du

Backward difference:
dx(t) dt x(t) x(t h) q1 x(t) = h qh

where x is the controller state, y is the controller output, and u is the controller input. Forward or backward approximation of the derivative

Tustins approximation (trapezoidal method, bilinear transformation):


x ( t + h) + x (t) 2 x(t + h) x(t) h

Forward difference
dx(t) dt x( k + 1) x( k) h

Backward difference
dx(t) dt x( k) x( k 1) h

leads to
x( k + 1) x( k) = Ax( k) + Bu( k) h y( k) = Cx( k) + Du( k)

rst gives
x( k) = ( I hA)1 x( k h) + ( I hA)1 hBu( k) y( k) = Cx( k) + Du( k)

which gives
x( k + 1) = ( I + hA) x( k) + hBu( k) y( k) = Cx( k) + Du( k)

which after a variable shift x ( k) = x( k h) gives


x ( k + 1) = ( I hA)1 x ( k) + ( I hA)1 hBu( k) y( k) = C( I hA)1 x ( k) + ( C( I hA)1 hB + D )u( k)

Frequency Domain
Assume that the controller is given as a transfer function G (s) The discrete-time approximation H ( z) is given by
H ( z) = G (s )

Example: Discretization
Assume that the following simple controller (lter) has been designed in continuous-time:
U ( s) = 1 E ( s) s+2

where
z1 s = h s = z1 zh Forward difference Backward difference Tustins approximation

Discretize this controller using Forward Euler approximation, 1 i.e. replace s with z : h
U ( z) = U ( z) =
z1 h

1 E( z) +2

2 z1 s = h z+1

h E( z) z 1 + 2h ( z 1 + 2h) U ( z) = hE( z) u( k + 1) (1 2h)u( k) = he( k) u( k) = (1 2h)u( k 1) + he( k 1)


9 10

Alternative: Write as differential equation rst:


du + 2u(t) = e(t) dt u( k + 1) u( k) + 2u( k) = e( k) h u( k + 1) u( k) + 2hu( k) = he( k) u( k) = (1 2h)u( k 1) + he( k 1)

Properties of the Approximation H ( z)


Where do stable poles of G (s) get mapped?

G (s)

Simulation (h = 0.1):
Amplitude

Step Response 0.6 G(s) Hforward(z)

0.5

0.4

Forward differences

Backward differences

Tustin

0.3

0.2

0.1

0.5

1 Time (sec)

1.5

11

12

Frequency Distortion
Simple approximations such as Tustin introduce frequency distortion. Important for controllers or lters designed to have certain characteristics at a particular frequency, e.g., a band-pass lter or a notch (band-stop) lter. Tustin:
H ( ei h ) G 2 e 1 h ei h + 1
i h

Frequency Distortion, Contd


If the continuous-time system affects signals at frequency , the sampled system will instead affect signals at where
=
2 h tan h 2

i.e.,
=
2 tan1 h

h
2

( h)2 12

The argument of G can be written as


2 ei h 1 2 ei h/2 ei h/2 2i h tan = = h ei h + 1 h ei h/2 + ei h/2 h 2

No distortion at = 0 Distortion is small if h is small

13

14

Prewarping to Reduce Frequency Distortion


s i z

Comparison of Approximations (1)


G ( s) =

e i
Approximation

(s + 1)2 (s2 + 2s + 400) , (s + 5)2 (s2 + 2s + 100)(s2 + 3s + 2500)


Bode Diagram
2

h = 0.03

10 Magnitude (abs)

10

G(s) H (z) forward Hbackward(z)

e i

10

Choose one point 1 . Approximate using


Phase (deg)

10

s =

tan( 1 h/2)

z1 z+1

180 90 0 90 180
15

This implies that H ei 1 h = G (i 1 ). Plain Tustin is obtained 1h 1h for small . for 1 = 0 since tan 2 2

10

10 Frequency (rad/sec)

10

10

16

Comparison of Approximations (2)


Bode Diagram 10 Magnitude (abs)
2

Sample and Hold-Based Approximations


Sample the controller in the same way as the physical plant model is sampled Zero-order hold or Step invariance method First-order hold or Ramp invariance method For a controller, the assumption that the input is piece-wise constant (ZOH) or piece-wise linear (FOH) does not hold! However, the ramp invariance method normally gives good results with little frequency distortion

10

G(s) Htustin(z) Hprewarp(50)(z)

10

10

90 45 Phase (deg) 0 45 90 135 180 10


0

10 Frequency (rad/sec)

10

10

17

18

Comparison of Approximations (3)


Bode Diagram 10 Magnitude (abs)
2

Matlab
SYSD = C2D(SYSC,TS,METHOD) converts the continuous system SYSC to a discrete-time system SYSD with sample time TS. The string METHOD selects the discretization method among the following: zoh Zero-order hold on the inputs. foh Linear interpolation of inputs (triangle appx.) tustin Bilinear (Tustin) approximation. prewarp Tustin approximation with frequency prewarping. The critical frequency Wc is specified last as in C2D(SysC,Ts,prewarp,Wc) matched Matched pole-zero method (for SISO systems only).
19 20

10

G(s) H (z) ZOH HFOH(z)

10

10

90 0 90 180 270

Phase (deg)

10

10 Frequency (rad/sec)

10

10

Design Approaches: Which Way?


ContinuousTime Process Model Lectures 6,7,9 Lecture 8 Discretized Process Model Control Design in Continuous Time

Design Approaches: Which Way?


ContinuousTime Process Model Lectures 6,7,9 Lecture 8 Discretized Process Model Control Design in Continuous Time

Control Design in Discrete Time

Discretized Controller

Control Design in Discrete Time

Discretized Controller

Difference Equation Software Algorithm

Difference Equation Software Algorithm

Sampled-Control Design: When the plant model is already on discrete-time form


obtained from system identication

Discretization of Continuous Design: Empirical control design


not model-based e.g., PID control

When the control design assumes a discrete-time model


e.g., model-predictive control

Nonlinear continuous-time model

When fast sampling not possible


21

In most other cases it is mainly a matter of taste.


22

An Example: PID Control

The Textbook Algorithm


de(t) dt

The oldest controller type The most widely used


Pulp & Paper 86% Steel 93% Oil reneries 93%

u(t)

= K e(t) +

1 Ti

t 0

e( )d +

Td

U (s) =

K E(s) +

K E(s) sTi

+ K Td sE(s)

Much to learn! =
P

23

24

Proportional Term
u umax u0 umin e0 e0 e
1.5 1

Properties of P-Control
Set point and measured variable K=5

K=2 0.5 0 0 6 Control variable 4 2 K=5 K=2 K=1 K=1 5 10 15 20

Proportional band

umax u = K e + u0 umin

e > e0

0 2 0 5 10

e0 < e < e0
e < e0

15

20

Stationary error
25

Increased K means faster speed, worse stability, increased noise sensitivity

26

Error with P-control


Control signal:
u = K e + u0

Integral Term
u = K e + u0 u=K
e

( P)
e(t)dt

Error:
e= u u0 K

1 e+ Ti

(PI)

Error removed if: 1. K = 2. u0 = u Solution: Automatic way to obtain u0


27

+
t

Stationary error present e dt increases u increases y increases the error is not stationary
28

Automatic Reset
u0 K e 1 1+sT i
1.5 1

Properties of PI-Control
Set point and measured variable Ti=1 Ti=2 Ti=5

U = KE+ 1 1 + sTi U=K 1 U 1 + sTi

0.5 0 0 Control variable 2 Ti=2 1 Ti=5 Ti= 5 10 Ti=1

Ti= 5 10 15 20

U=

sTi U = KE 1 + sTi 1 sTi

0 0

15

20

1+

Removes stationary error Smaller Ti implies faster steady-state error removal, worse stability

29

30

Prediction
Error

Derivative Part
de(t) dt

A PI-controller contains no prediction The same control signal is obtained for both these cases:
e e
e ( t)

e(t) + Td

e(t + Td)

Time

I P t Time

I P t Time

P:
u(t) = K e(t)

PD:
u(t) = K
31

e(t) + Td

de(t) dt

K e(t + Td )
32

Td = Prediction horizon

Properties of PD-Control
Set point and measured variable Td=0.1 1 0.5 0 0 6 Control variable Td=0.1 Td=0.5 4 Td=2 2 0 2 0 5 10 15 20 Td=0.5 Td=2

Alternative Forms
So far we have described the direct (position) version of the PID controller on parallel form Other forms: Series form
U = K (1 + 1 )(1 + sTd ) E sTi Td 1 = K (1 + + + sTd ) E Ti sTi

10

15

20

Different parameter values

Td too small, no inuence Td too large, decreased performance In industrial practice the D-term is often turned off.
33 34

Incremental (velocity) form


U= 1 U s 1 s Td + )E Ti 1 + sTd / N
2

Practical Modications
Modications are needed to make the PID controller practically useful Limitations of derivative gain Derivative weighting Setpoint weighting Handle control signal limitations

U = K (s +

Integration external to the algorithm (e.g. step motor) or internal

35

36

Limitation of Derivative Gain


We do not want to apply derivation to high frequency measurement noise, therefore the following modication is used:
sTd 1 + sTd / N

Derivative Weighting
The setpoint is often constant for long periods of time Setpoint often changed in steps D-part becomes very large. Derivative part applied on part of the setpoint or only on the measurement signal.
sTd ( Ysp(s) Y (s)) 1 + sTd / N

sTd

N = maximum derivative gain, often 10 20

D ( s) =

Often, = 0 in process control (step reference changes), = 1 in servo control (smooth reference trajectories)
37 38

Setpoint Weighting
An advantage to also use weighting on the setpoint.
u = K ( ysp y)

Setpoint Weighting
1.5 Set point and measured variable beta=1 1 0.5 0 0 beta=0.5 beta=0

replaced by
u = K ( ysp y)

20

40

60

3 Control variable 2 1 beta=0 0 0 20 40 60

0 1

beta=1 beta=0.5

A way of introducing feedforward from the reference signal (position a closed loop zero) Improved set-point responses.
39

40

Control Signal Limitations


All actuators saturate. Problems for controllers with integration. When the control signal saturates the integral part will continue to grow integrator (reset) windup. When the control signal saturates the integral part will integrate up to a very large value. This may cause large overshoots.
2 Output y and yref 1.5 1 0.5 0 0 Control variable u 0.2 0 0.2
41

Anti-Reset Windup
Several solutions exist: controllers on velocity form ( u is set to 0 if u saturates) limit the setpoint variations (saturation never reached) conditional integration (integration is switched off when the control is far from the steady-state) tracking (back-calculation)

10

20

42

10

20

Tracking
y

Tracking
KTds Actuator e = r y K

when the control signal saturates, the integral is recomputed so that its new value gives a control signal at the saturation limit to avoid resetting the integral due to, e.g., measurement noise, the recomputation is done dynamically, i.e., through a LP-lter with a time constant Tt (Tr ).

1 s 1 Tt

K Ti

es

KT d s

Actuator model

Actuator

e = r y

K K Ti 1 s 1 Tt

+
es
44

43

Tracking
1 0.5 0 0.15 0.05 0.05 0

Discretization

r y
10 20 30

P-part:

u P( k) = K ( ysp( k) y( k))
0 10 20 30

0 0.4 0.8 0

I
10 20 30

45

46

Discretization
I-part:
I (t) = K Ti
t

Discretization
D-part (assume = 0):
sTd ( Y (s)) 1 + sTd / N Td dD dy + D = K Td N dt dt D=K

e( )d
0

dI K = e dt Ti

Forward difference
I (tk+1 ) I (tk ) K = e(tk ) h Ti

Forward difference (unstable for small Td /large h) Backward difference


Td D (tk ) D (tk1 ) y(tk ) y(tk1 ) + D (tk ) = K Td N h h D (t k ) = Td K Td N D (tk1 ) ( y(tk ) y(tk1 )) Td + N h Td + N h

I(k+1) := I(k) + (K*h/Ti)*e(k) The I-part can be precalculated in UpdateStates Backward difference The I-part cannot be precalculated, i(k) = f(e(k))
47

48

Discretization

Tuning
Parameters: K , Ti , Td , N , , , Tr

Tracking:

Methods: empirically, rules of thumb, tuning charts model-based tuning, e.g., pole-placement automatic tuning experiment
Ziegler-Nichols method

v := P + I + D; u := sat(v,umax,umin); I := I + (K*h/Ti)*e + (h/Tr)*(u - v);

step response method ultimate sensitivity method


relay method
49 50

Bumpless Transfer
Avoid bumps in control signal when changing operating mode (manual - auto - manual) changing parameters changing between different controllers Key Issue: Make sure that the controller states have the correct values, i.e., the same values before and after the change
y sp y

Bumpless Mode Changes


Incremental Form:
+
MCU M A Inc PID 1 s u

51

52

Bumpless Mode Changes


Direct Position form:
1 Tt
+

Bumpless Parameter Changes


A change in a parameter when in stationarity should not result in a bump in the control signal.

1 Tm

y sp y

1 s PD M 1 s

For example: v := P + I + D; I := I +(K*h/Ti)*e;

K Ti

u A

or v := P + (K/Ti)*I + D; I := I + h*e; The latter results in a bump in u if K or Ti are changed.


53 54

1 Tt

Bumpless Parameter Changes

Switching Controllers

Controller1

More involved situation when setpoint weighting is used. The quantity P + I should be invariant to parameter changes.
Controller2 Switch

Process

Inew = Iold + K old ( old ysp y) K new( new ysp y)

Similar to changing between manual and auto Let the controllers run in parallel Let the controller that is not active track the one that is active. Alternatively, execute only the active controller and initialize the new controller to its correct value when switching (saves CPU)56

55

PID Code
PID-controller with anti-reset windup and manual and auto modes ( = 0).
y = yIn.get(); e = yref - y; D = ad * D - bd * (y - yold); v = K*(beta*yref - y) + I + D; if (mode == auto) { u = sat(v,umax,umin)} else u = sat(uman,umax,umin); uOut.put(u); I = I + (K*h/Ti)*e + (h/Tr)*(u - v); if (increment) uinc = 1; else if (decrement) uinc = -1; else uinc = 0; uman = uman + (h/Tm) * uinc + (h/Tr) * (u - uman) yold = y

Class SimplePID
public class SimplePID { private double u,e,v,y; private double K,Ti,Td,Beta,Tr,N,h; private double ad,bd; private double D,I,yOld; public SimplePID(double nK, double nTi, double NTd, double nBeta, double nTr, double nN, double nh) { updateParameters(nK,nTi,nTd,nBeta,nTr,nN,nh); } public void updateParameters(double nK, double nTi, double NTd, double nBeta, double nTr, double nN, double nh) { K = nK; Ti = nTi; Td = nTd; Beta = nBeta; Tr = nTr N = nN; h = nh; ad = Td / (Td + N*h); bd = K*ad*N; }

ad and bd are precalculated parameters given by the backward difference approximation of the D-term.

57

58

Extract from Regul


public class Regul extends Thread { private SimplePID pid; public Regul() { pid = new SimplePID(1,10,0,1,10,5,0.1); } public void run() { // Other stuff while (true) { y = getY(); yref = getYref(): u = pid.calculateOutput(yref,y); u = limit(u); setU(u); pid.updateState(u); // Timing Code } } }

public double calculateOutput(double yref, double newY) { y = newY; e = yref - y; D = ad*D - bd*(y - yOld); v = K*(Beta*yref - y) + I + D; return v; } public void updateState(double u) { I = I + (K*h/Ti)*e + (h/Tr)*(u - v); yOld = y; } }

59

60

You might also like