You are on page 1of 10

Lecture 8: From Analog to Digital Controllers, Design Approaches

PID Control Continuous−Time Process Model

Lecture 8
[IFAC PB Ch 6, Ch 8, RTCS Ch 10] Lectures 6,7,9

Discretized Process Model Control Design in Continuous Time

• Discrete-time approximation of continuous-time controllers


– State-space domain
Control Design in Discrete Time Discretized Controller
– Frequency domain
• The PID Controller
Difference Equation

Software Algorithm

1
2

Implementing a Continuous-Time Controller Methods:


Using a Computer • Differentiation and Tustin approximations
H ( z) ≈ G (s)
– State-space domain
u(t) {u ( kh )} { y ( kh )} y (t) – Frequency domain
A-D Algorithm D-A
• Step invariance (ZOH)
• Ramp invariance (FOH)
Clock
• Pole-zero matching

(Tustin and the three last methods are available in Matlab’s c2d command)
Want to find discrete-time Algorithm such that
A-D + Algorithm + D-A  Continuous Controller

3 4

Differentiation and Tustin Approximations State-Space Domain


Forward difference (Euler’s method): Assume that the controller is given in state-space form
dx(t) x(t + h) − x(t) q−1 dx
 = x(t) = Ax + Bu
dt h h dt
y = Cx + Du
Backward difference:
where x is the controller state, y is the controller output, and u
dx(t) x(t) − x(t − h) q−1
 = x(t) is the controller input.
dt h qh
Forward or backward approximation of the derivative
Tustin’s approximation (trapezoidal method, bilinear transforma-
tion):
ẋ(t + h) + ẋ(t) x(t + h) − x(t)

2 h

5 6
Forward difference Backward difference
dx(t) x( k + 1) − x( k) dx(t) x( k) − x( k − 1)
 
dt h dt h
leads to first gives
x( k + 1) − x( k) x( k) = ( I − hA)−1 x( k − h) + ( I − hA)−1 hBu( k)
= Ax( k) + Bu( k)
h
y( k) = Cx( k) + Du( k)
y( k) = Cx( k) + Du( k)

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


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

7 8

Frequency Domain Example: Discretization


Assume that the controller is given as a transfer function G (s) Assume that the following simple controller (filter) has been
designed in continuous-time:
The discrete-time approximation H ( z) is given by
1
U ( s) = E ( s)
H ( z) = G (s ) s+2

where Discretize this controller using Forward Euler approximation,


 z−1 i.e. replace s with z−h1 :
s = Forward difference
h
1
U ( z) = z−1
E( z)
z−1 +2
s = Backward difference h
zh h
U ( z) = E( z)
z − 1 + 2h
2 z−1
s = Tustin’s approximation ( z − 1 + 2h) U ( z) = hE( z)
h z+1
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 first:


du
Properties of the Approximation H ( z)  G (s)
+ 2u(t) = e(t)
dt Where do stable poles of G (s) get mapped?
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)

Step Response
Simulation 0.6
G(s)
(h = 0.1): 0.5
Hforward(z)

0.4 Forward differences Backward differences Tustin


Amplitude

0.3

0.2

0.1

0 11 12
0 0.5 1 1.5 2
Time (sec)
Frequency Distortion Frequency Distortion, Cont’d
Simple approximations such as Tustin introduce frequency If the continuous-time system affects signals at frequency ω  ,
distortion. the sampled system will instead affect signals at ω where
 
Important for controllers or filters designed to have certain 2 ωh
ω = tan
characteristics at a particular frequency, e.g., a band-pass filter h 2
or a notch (band-stop) filter. i.e.,
Tustin:    
2 ω h (ω  h)2
  ω= tan−1  ω 1 −
iω h
2 e −1 h 2 12
H ( eiω h )  G
h eiω h + 1
No distortion at ω = 0
The argument of G can be written as
  Distortion is small if ω h is small
2 eiω h − 1 2 eiω h/2 − e−iω h/2 2i ωh
ω
= ω ω
= tan
h e +1
i h he i h /2 +e− i h /2 h 2

13 14

Prewarping to Reduce Frequency Distortion Comparison of Approximations (1)


s z (s + 1)2 (s2 + 2s + 400)
G ( s) = , h = 0.03
e iω ′ (s + 5)2 (s2 + 2s + 100)(s2 + 3s + 2500)
iω ′
Approximation
Bode Diagram
−2
10
G(s)
H (z)
Magnitude (abs)

forward
−3 Hbackward(z)
10

−iω ′
e −iω ′ 10
−4

Choose one point ω 1 . Approximate using 10


−5

180
ω1 z−1
s = ⋅
tan(ω 1 h/2) z+1 90
Phase (deg)

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

−180
0 1 2 3
10 10 10 10
15 Frequency (rad/sec) 16

Comparison of Approximations (2) Sample and Hold-Based Approximations

10
−2
Bode Diagram Sample the controller in the same way as the physical plant
G(s)
Htustin(z)
model is sampled
Magnitude (abs)

10
−3 Hprewarp(50)(z)

• Zero-order hold or Step invariance method


• First-order hold or Ramp invariance method
−4
10

10
−5
For a controller, the assumption that the input is piece-wise
90
constant (ZOH) or piece-wise linear (FOH) does not hold!
45

However, the ramp invariance method normally gives good


Phase (deg)

−45
results with little frequency distortion
−90

−135

−180
0 1 2 3
10 10 10 10
Frequency (rad/sec)

17 18
Comparison of Approximations (3) Matlab
Bode Diagram
10
−2 SYSD = C2D(SYSC,TS,METHOD) converts the continuous
G(s)
H (z) system SYSC to a discrete-time system SYSD with
Magnitude (abs)

ZOH
10
−3 HFOH(z)
sample time TS. The string METHOD selects the
discretization method among the following:
−4
10
’zoh’ Zero-order hold on the inputs.
−5
’foh’ Linear interpolation of inputs
10
90 (triangle appx.)
’tustin’ Bilinear (Tustin) approximation.
0
’prewarp’ Tustin approximation with frequency
Phase (deg)

−90
prewarping.
−180 The critical frequency Wc is specified
last as in C2D(SysC,Ts,’prewarp’,Wc)
−270
10
0
10
1 2
10
3
10 ’matched’ Matched pole-zero method
Frequency (rad/sec)
(for SISO systems only).
19 20

Design Approaches: Which Way? Design Approaches: Which Way?


Continuous−Time Process Model Continuous−Time Process Model

Lecture 8 Lecture 8
Lectures 6,7,9 Lectures 6,7,9

Discretized Process Model Control Design in Continuous Time Discretized Process Model Control Design in Continuous Time

Control Design in Discrete Time Discretized Controller Control Design in Discrete Time Discretized Controller

Difference Equation Difference Equation

Software Algorithm Software Algorithm

Sampled-Control Design: Discretization of Continuous Design:


• When the plant model is already on discrete-time form • Empirical control design
– obtained from system identification – not model-based
• When the control design assumes a discrete-time model – e.g., PID control
– e.g., model-predictive control • Nonlinear continuous-time model
• When fast sampling not possible In most other cases it is mainly a matter of taste.
21 22

An Example: PID Control The Textbook Algorithm

 t de(t) 
• The oldest controller type u(t) = K e(t) + 1
e(τ )dτ + Td
Ti 0
dt
• The most widely used
– Pulp & Paper 86%
– Steel 93% K
U (s) = K E(s) + E(s) + K Td sE(s)
– Oil refineries 93% sTi
• Much to learn!

= P + I + D

23 24
Proportional Term Properties of P-Control

u Set point and measured variable


1.5
umax K=5

1
u0 K=2
0.5
K=1
umin 0
e 0 5 10 15 20
– e0 e0
6 Control variable
Proportional band 4 K=5

2
K=2
⎧ 0 K=1


⎪umax e > e0 −2

0 5 10 15 20
u = K e + u0 − e0 < e < e0



umin e < − e0
• Stationary error
• Increased K means faster speed, worse stability,
increased noise sensitivity
25 26

Error with P-control Integral Term

Control signal:
u = K e + u0 ( P)
u = K e + u0  
1
u = K e+ e(t)dt (PI)
Ti
Error: e
u − u0
e=
K

Error removed if: +

1. K = ∞ t

2. u0 = u

Solution: Automatic way to obtain u0 Stationary error present → e dt increases → u increases →
y increases → the error is not stationary

27 28

Automatic Reset Properties of PI-Control


Set point and measured variable
1 1.5
Ti=1
u0 1+sT i Ti=2
1
Ti=5
K e u 0.5
Σ Ti=∞

0
0 5 10 15 20
Control variable
1
U = KE+ U 2 Ti=1
1 + sTi Ti=2

  1
Ti=5
1 sTi
1− U= U = KE Ti=∞
1 + sTi 1 + sTi 0
0 5 10 15 20

 
1
U = K 1+ E • Removes stationary error
sTi
• Smaller Ti implies faster steady-state error removal,
worse stability
29 30
Prediction Derivative Part

Error
de(t)
A PI-controller contains no prediction e(t) + Td
dt

The same control signal is obtained for both these cases:


e(t)
e e e(t + Td)

Time
I I
P:
P P
u(t) = K e(t)
t Time t Time
PD:
 
de(t)
u(t) = K e(t) + Td  K e(t + Td )
dt

31
Td = Prediction horizon 32

Properties of PD-Control Alternative Forms


Set point and measured variable
Td=0.1 So far we have described the direct (position) version of the
1
Td=0.5 PID controller on parallel form
0.5
Td=2 Other forms:
0
0 5 10 15 20 • Series form
6 Control variable 1
Td=0.1 U = K  (1 + )(1 + sTd ) E
4 Td=0.5
Td=2
sTi
2 T 1
= K  (1 + d + + sTd ) E
0 Ti sTi
−2
0 5 10 15 20
Different parameter values

• Td too small, no influence


• Td too large, decreased performance

In industrial practice the D-term is often turned off. 33 34

• Incremental (velocity) form


Practical Modifications

1
U= ΔU Modifications are needed to make the PID controller practically
s
2 useful
1 s Td
Δ U = K (s + + )E
Ti 1 + sTd / N
• Limitations of derivative gain
Integration external to the algorithm (e.g. step motor) or • Derivative weighting
internal • Setpoint weighting
• Handle control signal limitations

35 36
Limitation of Derivative Gain Derivative Weighting

We do not want to apply derivation to high frequency measure- The setpoint is often constant for long periods of time
ment noise, therefore the following modification is used:
Setpoint often changed in steps → D-part becomes very large.
Derivative part applied on part of the setpoint or only on the
sTd measurement signal.
sTd 
1 + sTd / N

N = maximum derivative gain, often 10 − 20 sTd


D ( s) = (γ Ysp(s) − Y (s))
1 + sTd / N

Often, γ = 0 in process control (step reference changes),


γ = 1 in servo control (smooth reference trajectories)

37 38

Setpoint Weighting Setpoint Weighting

1.5 Set point and measured variable


An advantage to also use weighting on the setpoint. beta=1
1

beta=0.5
0.5 beta=0
u = K ( ysp − y)
0
replaced by 0 20 40 60

3 Control variable
u = K (β ysp − y)
2
beta=1
beta=0.5
0≤β ≤1 1
beta=0

A way of introducing feedforward from the reference signal 0


0 20 40 60
(position a closed loop zero)
Improved set-point responses.
39 40

Control Signal Limitations Anti-Reset Windup


All actuators saturate. Problems for controllers with integration.
Several solutions exist:
When the control signal saturates the integral part will continue
• controllers on velocity form (Δ u is set to 0 if u saturates)
to grow – integrator (reset) windup.
• limit the setpoint variations (saturation never reached)
When the control signal saturates the integral part will integrate
up to a very large value. This may cause large overshoots. • conditional integration (integration is switched off when the
control is far from the steady-state)
2 Output y and yref

1.5 • tracking (back-calculation)


1

0.5

0
0 10 20
Control variable u

0.2

−0.2
41 42
0 10 20
Tracking Tracking
–y
KTds

Actuator
• when the control signal saturates, the integral is recom- e = r− y v u
K Σ
puted so that its new value gives a control signal at the
saturation limit K – +
Σ 1 Σ
Ti
• to avoid resetting the integral due to, e.g., measurement
s

es
noise, the recomputation is done dynamically, i.e., through 1
a LP-filter with a time constant Tt (Tr ). Tt

–y
KT d s
Actuator
model Actuator
e = r− y
K Σ

K 1 – +
Ti
Σ Σ
s

1 es

43
Tt 44

Tracking Discretization

r
1

0.5
y

0
0 10 20 30
P-part:
0.15
u
0.05

−0.05
P( k) = K (β ysp( k) − y( k))
0 10 20 30

0
I
−0.4

−0.8
0 10 20 30

45 46

Discretization Discretization
I-part: D-part (assume γ = 0):
t sTd
K D=K (− Y (s))
I (t) = e(τ )dτ 1 + sTd / N
Ti
0 Td dD dy
+ D = − K Td
dI K N dt dt
= e
dt Ti
• Forward difference (unstable for small Td /large h)
• Forward difference • Backward difference
I (tk+1 ) − I (tk ) K Td D (tk ) − D (tk−1 ) y(tk ) − y(tk−1 )
= e(tk ) + D (tk ) = − K Td
h Ti N h h
I(k+1) := I(k) + (K*h/Ti)*e(k)
Td K Td N
The I-part can be precalculated in UpdateStates D (t k ) = D (tk−1 ) − ( y(tk ) − y(tk−1 ))
Td + N h Td + N h
• 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:

v := P + I + D; • empirically, rules of thumb, tuning charts


u := sat(v,umax,umin); • model-based tuning, e.g., pole-placement
I := I + (K*h/Ti)*e + (h/Tr)*(u - v);
• automatic tuning experiment
– Ziegler-Nichols method
∗ step response method
∗ ultimate sensitivity method
– relay method

49 50

Bumpless Transfer Bumpless Mode Changes

Avoid bumps in control signal when


Incremental Form:
• changing operating mode (manual - auto - manual)
+
• changing parameters –
MCU

• changing between different controllers M


A
1
s
u

y sp
Key Issue: Make sure that the controller states have the correct y
Inc PID

values, i.e., the same values before and after the change

51 52

Bumpless Mode Changes Bumpless Parameter Changes

Direct Position form: A change in a parameter when in stationarity should not result
1 in a bump in the control signal.
Σ
Tt +
– For example:
+ 1 1
− Tm
Σ s
v := P + I + D;
y sp I := I +(K*h/Ti)*e;
PD
y
M or
e K 1 u
Ti
Σ s Σ
A v := P + (K/Ti)*I + D;
– +
Σ I := I + h*e;
1
Tt The latter results in a bump in u if K or Ti are changed.

53 54
Bumpless Parameter Changes Switching Controllers

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

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
55
new controller to its correct value when switching (saves CPU)56

PID Code Class SimplePID


.

PID-controller with anti-reset windup and manual and auto public class SimplePID {
modes (γ = 0). private double u,e,v,y;
private double K,Ti,Td,Beta,Tr,N,h;
y = yIn.get(); private double ad,bd;
e = yref - y; private double D,I,yOld;
D = ad * D - bd * (y - yold);
v = K*(beta*yref - y) + I + D; public SimplePID(double nK, double nTi, double NTd,
if (mode == auto) { double nBeta, double nTr, double nN, double nh) {
u = sat(v,umax,umin)} updateParameters(nK,nTi,nTd,nBeta,nTr,nN,nh);
else u = sat(uman,umax,umin); }
uOut.put(u);
I = I + (K*h/Ti)*e + (h/Tr)*(u - v); public void updateParameters(double nK, double nTi, double NTd,
if (increment) double nBeta, double nTr, double nN, double nh) {
uinc = 1; K = nK;
else if (decrement) Ti = nTi;
uinc = -1; Td = nTd;
else uinc = 0; Beta = nBeta;
uman = uman + (h/Tm) * uinc + (h/Tr) * (u - uman) Tr = nTr
yold = y N = nN;
h = nh;
ad and bd are precalculated parameters given by the backward ad = Td / (Td + N*h);
bd = K*ad*N;
difference approximation of the D-term. 57
}
58

. .

Extract from Regul


public class Regul extends Thread {
public double calculateOutput(double yref, double newY) { private SimplePID pid;

y = newY; public Regul() {


e = yref - y; pid = new SimplePID(1,10,0,1,10,5,0.1);
D = ad*D - bd*(y - yOld); }
v = K*(Beta*yref - y) + I + D;
return v; public void run() {
} // Other stuff

public void updateState(double u) { while (true) {


y = getY();
I = I + (K*h/Ti)*e + (h/Tr)*(u - v); yref = getYref():
yOld = y; u = pid.calculateOutput(yref,y);
} u = limit(u);
setU(u);
} pid.updateState(u);
// Timing Code
}
}
}
59 60

You might also like