Professional Documents
Culture Documents
Karl-Erik rzen The basic algorithm Algorithm modications Discretization Mode handling Code
PID Control
PID Algorithm
Textbook Algorithm: The oldest controller type The most widely used
Pulp & Paper 86% Steel 93% Oil reneries 93% U (s) = K ( E(s) + u(t)
K ( e(t)
1 TI
e( )d +
TD de(t) ) dt
1 sTI
E(s)
+ TD sE(s))
Much to learn!! =
3
D
4
Proportional Term u
umax u0 umin e0 e0 e
1.5 1
Properties of P-Control
Set point and measured variable Kc=5
Proportionalband
umax u = K e + u0 umin
e > e0
0 2 0 5 10
e0 < e < e0
e < e0
15
20
stationary error increased K means faster speed, increased noise sensitivity, worse stability
5 6
Integral Term
u = K e + u0 u=K
e
e+
1 Ti
e(t)dt
(PI)
Stationary error present edt increases u increases y increases the error is not stationary
7 8
Automatic Reset
ub Kc e 1 1+sT i
1.5 1 0.5 0 0
Properties of PI-Control
Set point and measured variable Ti=1 Ti=2 Ti=5
U = KE+
2 Ti=2 1
Ti=1
Ti=5 Ti= 5 10 15 20
0 0
Prediction
Derivative Part
Reglerfel e(t) + Td 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)
tid
P:
I P t tid t I P tid
PD:
Td = Prediction horizon
11 12
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
Outline
The basic algorithm
10
15
20
TD too small, no inuence TD too large, decreased performance In industrial practice the D-term is often turned off.
13 14
Algorithm Modications
Modications are needed to make the controller practically useful Limitations of derivative gain Derivative weighting Setpoint weighting
We do not want to apply derivation to high frequency measurement noise, therefore the following modication is used:
sTD sTD 1 + sTD / N
15
16
Derivative weighting
Setpoint weighting
An advantage to also use weighting on the setpoint.
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.
D (s) = sTD ( Ysp(s) Y (s)) 1 + sTD / N
u = K ( ysp y)
replaced by
0 1
u = K ( ysp y)
A way of introducing feedforward from the reference signal (position a closed loop zero) Improved set-point responses.
18
Setpoint weighting
1.5 Set point and measured variable beta=1 1 0.5 0 0 3 Control variable 2 1 beta=0 0 0 20 40 60 beta=0.5 beta=0
1 TI
20
40
60
PID
GP
beta=1 beta=0.5
Feedforward + Feedback
19
20
Two-degree-of-freedom controller
disturbance rejection
closed loop poles feedback
Gff
ysp
+
A better algorithm
Gfb
GP
U (s) = K ( yr y +
Modications: Setpoint weighting ( ) in the proportional term improves set-point response Limitation of the derivative gain (low-pass lter) to avoid derivation of measurement noise Derivative action only on y to avoid bumps for step changes in the reference signal
21 22
Anti-Reset Windup
Several solutions exist: controllers on velocity form (not discussed here)) 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)
23
24
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 re-computation is done dynamically, i.e., through a LP-lter with a time constant 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
25
26
Tracking
1 0.5 0 0.15 0.05 0.05 0 10 20 30
Outline
The basic algorithm Algorithm modications Discretization Mode handling Code
10
20
30
0 0.4 0.8 0 10 20 30
27
28
Discretization
I-part:
Discretization
I ( t) = K TI
t
e( )d ,
0
dI K = e dt TI
Forward difference
I (t k+1 ) I (t k) K = e(t k) h TI
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)) Others
29 30
Discretization
D-part (assume = 0): sTD D=K ( Y (s)) 1 + sTD / N TD dD dy + D = K TD N dt dt
Discretization, cont.
D-part:
Backward difference
TD D (t k) D (t k1 ) + D (t k) N h y(t k) y(t k1 ) h TD D (t k1 ) D (t k) = TD + Nh K TD N ( y(tk) y(tk1 )) TD + Nh
= K TD
31
32
Discretization
The basic algorithm
Tracking:
Outline
33
34
Bumpless Transfers
Avoid bumps in control signal when changing operating mode (manual - auto - manual) changing parameters changing between different controllers
Changing operating mode
+
y sp y
1 s PD M 1 s
Key Issue: Make sure that the controller states have the correct values, i.e., the same values before and after the change
K Ti
u A
1 Tt
35
36
More involved situation when setpoint weighting is used. The quantity P + I should be invariant to parameter changes.
Inew = Iold + K old ( old ysp y) K new( new ysp y)
38
Changing Controllers
Controller1 Process Controller2 Switch
Outline
The basic algorithm Algorithm modications Discretization
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 CPUtime)
39
40
PID code
PID-controller with anti-reset windup
y = yIn.get(); // A-D conversion e = yref - y; D = ad * D - bd * (y - yold); v = K*(beta*yref - y) + I + D; u = sat(v,umax,umin)} uOut.put(u); // D-A conversion I = I + (K*h/Ti)*e + (h/Tr)*(u - v); yold = y
ad and bd are precalculated parameters given by the backward difference approximation of the D-term.
42
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; }
43
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; } }
44