Lecture 8
[IFAC PB Ch 6, Ch 8, RTCS Ch 10] Lectures 6,7,9
Software Algorithm
1
2
(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
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)
7 8
Step Response
Simulation 0.6
G(s)
(h = 0.1): 0.5
Hforward(z)
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
forward
−3 Hbackward(z)
10
−iω ′
e −iω ′ 10
−4
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
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)
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
−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
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
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
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
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
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
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
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
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
37 38
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
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:
49 50
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
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
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
. .