6 Digital Controller Design

You are on page 1of 23

6 Digital Controller Design

6 Dig
• Digital signals
• The concept of Z transfer function
• Equivalent Design
• Simulation study
• Your Lab work
 Design and simulation of digital PI and PID
controllers for different sampling rates

6 Dig 1
Digital control (computer-based control)

Classical Control:
Analogue controller
Morden Control:
Digital controller
State space approach

Easy to learn digital control from digital PID controllers


(equivalent design), an easy transition from analogue to digital.

6 Dig 2
Digital control block diagram
DSP D/A

Control algorithm
A/D

Digital controller

A/D Embedded Systems


Applications Projects
D/A
Digital control (control algorithm)
6 Dig 3
Signal sampling in digital systems

Signal distortion
after D/A and A/D

6 Dig 4
Signal into a DSP and comes out from a D/A

G(z)
E(z) U(z)
ZOH r (t )  r (kT )
U ( z ) cnum( z )
Gc ( z )   kT  t  ( k  1)T
E ( z ) cden( z )
k  2 (or any integer)
" change s to z " (1  e  sT
)
G0 ( s )  r (t )  r (2T )
s 2T  t  3T
Gc(z) used for simulation :
U ( z) 0.37 z  0.26  z 2 U ( z) 0.37 z 1  0.26 z 2 
Gc ( z )   2    2  Gc ( z )   
 z 1
E ( z ) 1  1.4 z  0.37 z  2 
E ( z ) z  1.4 z  0.37 
For digital algorithm
6 Dig 5
Equivalent design

G(s) G(z)
Outputs with different T and
G(z) (after sampling)

Conceptually
If T → 0, G(z) → G(s)
“continuous sampling”

6 Dig 6
Find equivalent G(z) for G(s): MATLAB commands

Gc here NOT G p
Use T  0.05
for your case Digital PID controller equivalent design
1 N
PI D ( N  100)
s 1
1 N
s
= Gp(z) In a form of cnum / cden
( P  D  N )s 2  ( P  N  I )s  I  N
Gc ( s ) 
s 2  sN  0
6 Dig 7
A digital control system: simulation

no change
T T

In which Simulink group ?


• Browsing
Simulink/Discrete
• Search (type the name)
Simulink Extras/Additional Discrete 6 Dig 8
Engineering practice: decide the sampling period T
T  0  continuous
T  0  fast processor
T too large ??

90%
tr
T Your design task:
nr • Digital PID controllers: equivalent
10  nr  20 design for PI and PID (not P)
• Investigating different T, starting
with T = 0.05, then … next slide
10%
tr

6 Dig 9
Guidance on selecting sampling period T
• compromise between “good” equivalent design and the CPU
load
• Try a T and a 2T (T could be arbitrary, here T=0.05 ).
 If Out_T is much better than Out_2T, next try 0.5T ……
 If Out_T “The same as” Out_2T, next try 4T ……
• Sampling is an intermittent feedback, between two sampling
instances, the signal is assumed unchanged (ZOH). Therefore
if signal changes fast: need a short T.

Better response, but increased CPU load

0 0.5T T 2T
Next try of T: increase ? decrease ? stop try ?
(suggest to start with T = 0.05 sec. )
6 Dig 10
Digital PI and PID control with different T
In simulation, if you
change T, not only in
ZOH

Gc ( z ) _(T 0.05) 
Gc ( z ) _(T 0.1)

but also need to


change Gc(z)
• Sampling is an intermittent feedback,
between two sampling instances, the
signal is assumed unchanged (ZOH).
Therefore if signal changes fast: need
a short T. 6 Dig 11
What do we check: some numerical results
• Your plant transfer function, Kcr, Pcr
• The results of running a *.m file below
Find_PID_Parameters_from_Kcr_P_cr.m (Re: file 5,
slides 12 and 13)
• Gc(z), when Gc(s) is the PID in your simulation and T=0.05

Aimed at work
independently in a company
6 Dig 12
*.m file (Matlab script file, widely used)
Run a *.m file below first -K-
nu m (s)
d e n(s)
r(t) te st_ k Scop e

num = [ …… ];
P l a nt to be con t rol l e d

den = [ ....... ];
test_k = 1

If you are still not clear what is and how to use *.m files after
review your Year 1 module. Ask me in the Lab

Good engineering practice:


• separate variable name with its value in a model
• Using *.m files for designs (calculations)
Find_PID_Parameters_from_Kcr_P_cr.m (Re: file 5, slides 12 and 13)
Design controllers …… for different sampling rates
Make a file: Num_Den_of_Digital_PID.m (to be used with different T)
6 Dig 13
By the end of this week, you need
to complete the basic work
specified up to the last slide.
Average time a student spend
on a 15 credit module: 10-12
hours per week
“Don’t work”: help provided
outside timetabled Lab time
6 Dig 14
Further topic: comparing continuous/discrete equivalent design time
responses

Continuous design
Clock
T i me t vari able
P_out

pl ot (t, P_out)

num(s)
PID(s)
den(s)
r(t) P Control l er Scope
Plant to b e control led

PI_out

Discrete design 1
PID(s)
num(s)
plot (t, PI_out)

den(s)
r(t)1 PI Controll er Scope1
Pl ant to be control l ed1

PID_out

pl ot (t, PID_out)

num(s)
PID(s)
den(s)

Discrete design 2
r(t)2 PID Controll er Pl ant to be control l ed2
Scope2

How to do the above,


Learn next week
This does not work !
6 Dig 15
Step by step and Debug
(Also applicable to *.m files) In another file
Cl o ck

P ID (s)
T im e
t

t va r i a b l e

nu m ( s)
p lo t
P_ o u t

(t , P _ o ut )
(window):
A
d en ( s)
r (t) P C o nt ro l l er Sco p e
Pl an t to be co n tr ol l e d

PI_ o u t
t
p lo t (t, P I_ o ut )
C l o ck Ti m e t var i a b l e
nu m ( s) P _o u t
P ID (s)
d en ( s)
r( t)1 pl o t (t, P _o u t)
PI Co n tro l l e r P la n t to be co nt ro l l e d1 S co pe 1

B
nu m (s)
PI D( s)
de n (s)
r( t) P Co n tr ol l e r S cop e
P la n t t o be co nt ro l l e d

P ID _o u t

p lo t (t , PI D_ o u t)

nu m ( s) P I_ ou t
P ID (s)
d en ( s)
r( t)2 p l o t ( t, PI _o u t)
P ID C o nt ro l l e r S co pe 2
P la n t to be co nt ro l l e d2
nu m (s)
PI D( s)
de n (s)
r(t )1 PI C on tr ol l e r Sco p e 1
P l a nt to be con t ro l l ed 1

PID _ o ut

p lo t (t, P ID _o u t)

t
nu m (s)
PI D( s)
de n (s)
r(t )2 P ID C on t ro l l er Sco p e 2
P l a nt to be con t ro l l ed 2

A
Cl ock

OK
T i me t vari abl e
P_out

pl ot (t, P_out)

r(t)
PID(s)

P Control l er
num(s)
den(s)
Pl ant to be control l ed
Scope

Cl o ck T im e
t

t va r i a b l e

p lo t
P_ o u t

(t , P _ o ut )
OK
nu m ( s)
P ID (s)
d en ( s)
r (t) P C o nt ro l l er Sco p e
Pl an t to be co n tr ol l e d

PI_out p lo t
PI_ o u t

(t, P I_ o ut )

nu m ( s)
P ID (s)
d en ( s)
r( t)1 PI Co n tro l l e r S co pe 1
P la n t to be co nt ro l l e d1

pl ot (t, PI_out)
t

P ID _o u t Cl o ck T im e t va ri ab l e
P_ o u t
p lo t (t , PI D_ o u t)
p lo t (t , P _ ou t )

num(s)
nu m ( s)

C
P ID (s) n um (s)
d en ( s) P ID (s)

PID(s)
r( t)2 P ID C o nt ro l l e r S co pe 2 d en ( s)
P la n t to be co nt ro l l e d2

=
r(t ) P C on tr o l l er Sco p e
Pl a n t to be co n tr ol l e d

den(s)

B
+
PI_ o u t

r(t)1 PI Control l er Scope1 p lo t (t , P I_ o u t)

Plant to be control l ed1 r( t) 1


P ID (s)
n um (s)

d en ( s)
S cop e 1
P I C o nt ro l l e r P la n t to be co n tro l l e d 1

P ID _o u t

p l ot (t , PI D_ o u t)

n um (s)
P ID (s)
d en ( s)
r( t) 2 PID C o n tro l l e r S cop e 2
P la n t to be co n tro l l e d 2

C l ock Ti m e t va ri a b l e
P _ o ut

PID_out
p lo t (t, P _ ou t)

nu m ( s)
P ID (s)
d en ( s)
r (t) P Co n tr o l l e r S co p e
Pl a n t to be co n tr ol l e d

pl ot (t, PID_out)

Copy + Paste OK
P I_ o u t

p lo t (t, P I_ o ut )

nu m ( s)
P ID (s)
d en ( s)

num(s)
r( t)1 PI C on t ro l l er S cop e 1
P l a nt to be co nt ro l l e d1

PID(s)
den(s)
P ID_ o u t

p lo t (t , PID _ o ut )

r(t)2
nu m ( s)

Scope2
P ID (s)

PID Control l er
d en ( s)

Plant to be control l ed2


r( t)2 P ID C o nt ro l l e r S cop e 2
P l a nt to be co nt ro l l e d2

C
OK

File 5 slide 18 … Conflict in Variable names


does not work ? and Dimensions ? ( ….. t )
6 Dig 16
Compare two or more design methods → plot two (or more)
outputs in a graph − when it can work, when it cannot ?
plot( t, P_out, 'r-.', t, PI_out, 'b:', t, PID_out, 'k-')

t
Cl ock T i m e t vari abl e
P_out

pl ot (t, P_out)

To
num(s)
PID(s)
den(s)
r(t) P Control l er Scope
Pl ant to be control l ed

PID(s)
num(s)
PI_out

pl ot (t, PI_out) work


den(s)

need
r(t)1 PI Control l er Scope1
Plant to be control l ed1

PID_out

r(t)2
PID(s)

PID Control l er
num(s)
den(s)
Plant to be control l ed2
pl ot (t, PID_out)

Scope2
same
size
6 Dig 17
Note of good practice: detailed working record
Analogy PID controller file *.slx, rising time * sec.
Digital PID controller file *.slx
Make a file: Num_Den_of_Digital_PID.m (to be used with different T)
T NUM (z) DEN (z) note
0.05
……
……

Only for a few cases: If up till here all you have done has no error, but
your system under digital PID control is unstable, read below
Analysis and interpretation:
• Equivalent design results always worth than analogue controllers.
The original analogue PID response is too oscillatory. Therefore ……
• …… (further investigation)
High mark: can deal with challenge.
6 Dig 18
What we will do in next week’s lecture (week 5)

File 8 Two reports and Plots in


reports, and part of file 7
Face-to-face discussions (feedback)
on your Week 8 report
• 3 students in a small group in my office, each group 20
minutes, at Weeks 10 and 11 Mon. and Tue. PM, detailed
“group time table” will be made late by a lottery draw.
• Make your own groups and let me know by Week 6,
otherwise I will assign groups.
• No Monday lectures in weeks 10 and 11.

6 Dig 19
Marking your work
Assessment Criterion (Reference pack page 82)
OPEN, FAIR, and JUSTIFIBLE
Overall average 60% for every module
with normal (Gaussian) distributions
means that half students get 2-1 or above

60%
Compare your report with “the class average” (between 60-65%) → your mark
6 Dig 20
Don’t worry you will (or have made) mistakes, you
learn from your mistakes. An experienced
researcher also makes mistakes, he/she just not
repeats the mistakes he/she made before.
Appendix: Find_PID_Parameters_from_Kcr_P_cr.m (Re: 5 PID 12 13)
K_cr=4.0 % From Kp Ti Td of P PI PID controllers
P_cr=1.8
% of form 1 to find P I D parameters
% Find parameters Kp Ti Td for P % of form 2 P PI PID controllers (step 3)
PI PID controllers
% based on Ziegler–Nichols P_P=P_Kp
Tuning Rule
PI_P=PI_Kp
P_Kp=0.5*K_cr
PI_I=PI_Kp/PI_Ti
PI_Kp=0.45*K_cr
PI_Ti=P_cr/1.2 PID_P=PID_Kp
PID_Kp=0.6*K_cr PID_I=PID_Kp/PID_Ti
PID_Ti=0.5*P_cr PID_D=PID_Kp*PID_Td
PID_Td=0.125*P_cr
6 Dig 21
G(z) ↔ difference equations ↔ Iterative Algorithm
U ( z) 0.37 z 1  0.26 z 2
Gc ( z )   U ( z )  u (kT ) E ( z )  e(kT )
E ( z ) 1  1.4 z 1  0.37 z  2

Z-domain and
(1  1.4 z 1  0.37 z 2 )U ( z )  (0.37 z 1  0.26 z 2 ) E ( z )
U ( z )  (1.4 z 1  0.37 z 2 )U ( z )  (0.37 z 1  0.26 z 2 ) E ( z )

Time domain
z 1 means shift time back a sampling peorid
u( kT )  1.4u( kT  T )  0.37u (kT  2T )
 0.37e( kT  T )  0.26e( kT  2T )
Q: in LT s means
…… ?

E(z) U(z)

6 Dig 22
Difference equations → Iterative Algorithm
u (kT )  1.4 u (kT  T )  0.37 u (kT  2T )  0.37 e(kT  T )  0.26 e(kT  2T )

Z-domain and
u(kT )  (current control at sampling instance kT )
1.4  u( kT  T ) (the previous control at kT  T stored in memory)
 0.37  u( kT  2T ) (the previous control at kT  2T stored in memory)

Time domain
 0.37 e(k  T ) (the previous error at kT  T stored in memory)
 0.26 e( k  2T ) (the previous error at kT  2T stored in memory)

6 Dig 23

You might also like