You are on page 1of 57

Digital

Control Review 1

Paulo Garrido
Departamento de Eletrónica
Escola de Engenharia da Universidade do Minho

Creative Commons License Attribution Share-Alike 4.0


State space model in con7nuous 7me

•  If the dynamic operators of a model are integrators, one


aggregates the outputs of the integrators in the state vector x.
Together with the input vector u and the output vector y, one can
write the model in the general form:
dx
= f (x ,u ) state equation
dt
y = g(x ,u ) output quation

•  u, x and y can have dimensions 1, 2, 3, ...


•  dim(x) = n, dim(u) = m, dim(y) = o,

22/09/20 Digital control review 1


Linear state space model in con7nuous
7me
•  If the model is linear, then it can be written in the general form:

dx
= Ax + Bu
dt
y = Cx + Du

•  dim(A) = n×n, dim(B) = n×m, dim(C) = o×n, dim(D) = o×m,

22/09/20 Digital control review 2


Example: control of inverted
θ
pendulum on a cart
B – battery
E – electronics
SR1 – encoder to measure pendulum angle
with vertical, θ
SR2 – DC motor with encoder to measure
displacement x from reference position
SP1, SP2 – Proximity sensors to avoid
collisions F

F – fulcrum SR1
B
R – wheels SP2 E SP1

SR2M

Goal is to keep pendulum upright θ = 0, at R


the reference displacement x = 0. x

22/09/20 Digital control review 3


Inverted pendulum on cart linearized
model (valid for |θ| ≤ 0.1 rad)
⎡ 0 0 1 0 ⎤⎥ ⎡ 0 ⎤
⎢ ⎢ ⎥
⎡ x! ⎤ ⎢⎢ 0 0 0 1 ⎥⎥ ⎡ x ⎤ ⎢⎢ 0 ⎥

⎢ ⎥ ⎢ ⎥⎢ ⎢ ⎥ ⎢ ⎥
⎢ θ! ⎥ ⎢ (Lm )2 g θ ⎥ J + L 2
m
⎢ ⎥=⎢ 0 − 0 0 ⎥⎥ ⎢ ⎥ + ⎢⎢ ⎥( f + f )
⎥ m
⎢ v! ⎥ ⎢ J( M + m )+ L2 mM ⎥ ⎢⎢ v ⎥⎥ ⎢ J( M + m )+ L mM
2

e
⎢ ⎥ ⎢ ⎥⎢ ω ⎥ ⎢ ⎥
⎢ ω! ⎥ ⎢ Lmg( M + m ) Lm
⎣ ⎦
⎢ 0 0 0 ⎥⎥ ⎣ ⎦ ⎢ −



⎢⎣ J( M + m )+ L2 mM ⎥⎦ ⎢⎣ J( M + m )+ L2 mM ⎥⎦

θ – pendulum angle from vertical; ω –angular velocity


x – cart displacement from reference arbitrária; v – velocity
fm – translation force originated by motor; fe – external translation force (disturbance)
m – pendulum mass; M – cart mass; g –gravity;
L – distance from fulcrum to the pendulum center of mass;
J – pendulum moment of inércia referred to the center of mass; for uniform rod:
J = m(2L)2 / 12

22/09/20 Digital control review 4


Expression of the motor transla7on force

•  It turns out that the expression of the translation force


originated by the motor is :

Gr K m Gr2 K m2
fm = u− 2 v
Rr Ra Rr Ra
u – DC motor supply voltage; v – cart velocity
Gr – transmission ratio from the motor axis to the wheel axis
Rr – wheel radius
Ra – DC motor armature resistance
Km – gain from DC motor armature current to torque

22/09/20 Digital control review 5


The model with u as an input

•  The motor translation force is a (static) function of u


and v. To change the above model so that u is an input,
define the parameters:

(Lm)2 g J + L2 m
aa,θ =− ba, f =
J ( M + m) + L2 mM J ( M + m) + L2 mM
Lmg( M + m) Lm
aα ,θ = bα , f = −
J ( M + m) + L2 mM J ( M + m) + L2 mM
Gr K m Gr2 K m2
k f ,u = k f ,v =− 2
Rr Ra Rr Ra

22/09/20 Digital control review 6


•  Now the state equation becomes:

⎡ x! ⎤ ⎡⎢ 0 0 1 0 ⎤⎡
⎥⎢ x ⎤ ⎡⎢ 0 0 ⎤

⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎡ ⎤
⎢ θ! ⎥ ⎢ 0 0 0 1 ⎥⎢ θ ⎥ ⎢ 0 0 ⎥⎢ u ⎥
⎢ ⎥=⎢ ⎥⎢ ⎥+⎢ b k ⎥⎢ ⎥
⎢ v! ⎥ ⎢ 0 a a ,θ ba , f k f ,v 0 ⎥⎢ v ⎥ ⎢ a , f f ,u ba , f ⎥ ⎢⎣ f e ⎥⎦
⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥
⎢ ω! ⎥ ⎢ 0 a α,θ bα, f k f ,v 0 ⎥ ⎢⎣ ω ⎥⎦ ⎢ bα, f k f ,u bα, f ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
Exercise 1
a) (Easy) Check that the above state equation is correct,
given the expression for fm.
b) (Hard) Derive the expression for fm as a function of u
and v.
22/09/20 Digital control review 7
Declaring the model in Scilab – scalars
clear // To avoid errors in simula7on
//Nominal con7nuous 7me model

g=9.8; // Gravity
M=10; // Cart mass
m=0.25; // Pendulum mass
L=0.5; // Distance from the center of mass to the fulcrum
J=m*(2*L)^2/12 // Moment of iner7a referred to center of mass
fator=J*(M+m)+L^2*m*M

aa=-(L*m)^2*g/fator; aalfa=L*m*g*(M+m)/fator
ba=(J+L^2*m)/fator; balfa=-L*m/fator

G=50; Radius=0.05; Ra=2; Km=0.0025;


kfu=G*Km/(Radius*Ra); kfv=-G^2*Km^2/(Radius^2*Ra)
22/09/20 Digital control review 8
Declaring the model in Scilab – matrices
and system
//Con7nuous 7me state space model

A =[0 0 1 0 ; 0 0 0 1 ; 0 aa ba*kfv 0 ; 0 aalfa balfa*kfv 0 ];


Bu = [0 0 ba*kfu balfa*kfu] '; Bp=[0 0 ba balfa] '
B=[Bu Bp]
C = [1 0 0 0; 0 1 0 0]

sz=size(A);dimx=sz(1,1)
I=eye(dimx,dimx)
sz=size(C); dimy=sz(1,1)

pend_c=syslin('c',A,B,C);
disp(spec(A),"Nominal model poles in s:")

22/09/20 Digital control review 9


Matrix transfer func7on

X(s ) = (s I− A)−1 x(0)+(s I− A)−1 BU(s )

Y(s ) = H(s )U(s ) = (C(s I− A)−1 B + D )U(s )

•  dim(H) = o×m

22/09/20 Digital control review 10


Calcula7on of transfer func7on in pole-
zero form from model declared with syslin
Hpend=zpk(pend_c)
disp(Hpend,"Hpend:")





Exercise: iden7fy the input and output variables of
each scalar transfer func7on.
22/09/20 Digital control review 11
Conceptual model of digital control system
with periodic sampling of period h

•  The command variable in discrete time u(kh) is assumed to be set at the same
instants where the output variable y(t) is sampled to y(kh).
•  The D/A converter is assumed to work as a first-order hold: kh ≤ t < kh+h,
u(t) = u(kh). Then u(t) is a sequence of rectangular impulses.
•  Exercise: discuss how this general model fits the control of the inverted
pendulum on cart
22/09/20 Digital control review 12
General expression of the state evolu7on;
matrix transfer func7on

−1 −1
X(s ) = (s I− A) x(0)+(s I− A) BU(s )
t

x(t ) = e x(0)+ ∫ e
At A( t−τ )
Bu(τ )d τ
0

22/09/20 Digital control review 13


State space model discre7za7on with
periodic sampling of period h
•  Because the model is time invariant, one can take kh = 0 and kh + h = t, in the
solution of the state equation in continuous time to get:
kh+h

x(kh + h) = e A( kh+h−kh )x(kh)+ ∫ e A( kh+h−τ ')Bu(kh)d τ '


kh
h

= e Ah x(kh)+ ∫ e Aτ d τ Bu(kh)
0

= Φ(h)x(kh)+ Γ(h)u(kh)
⎧⎪x(k +1) = Φx(k)+ Γu(k)
•  Taking h implicitly, the model is written:
⎪⎨
⎪⎪⎩ y(k) = Cx(k)+ Du(k)

22/09/20 Digital control review 14


Empirical rule to choose h

•  Let |s|max be the greatest module of A eigenvalues:

⎡ 1 1 ⎤
h ∈ ⎢⎢ , ⎥

⎢⎣ 10 s max
4 s max ⎥⎦

22/09/20 Digital control review 15


Scilab code to calculate a discrete 7me
model for the inverted pedulum on a cart

•  Note that this model is exact for the external force


(disturbance) input being a step or impulses. While this
may not be the case, considering disturbances as steps
is a worst case condition.

//Number of samples by frequency inverse



Ns=10 //Number of samples by frequency inverse

22/09/20 Digital control review 16


//Sampling period

T=1/(max(abs(spec(A))))
h=round(1000*(T/Ns))/1000 //Ns samples in T
disp(h,"Sampling period:")

//Discrete 7me nominal model


pend_d=dscr(pend_c,h)
Fi=pend_d(2)
Gama=pend_d(3)
Gamau=Gama(:,1)
Gamap=Gama(:,2)
disp(Fi, 'Fi')
disp(Gama, 'Gama')
22/09/20 Digital control review 17
Pulse transfer operator of state space
model

q x(k) = Φx(k)+ Γu(k) ⎡ H (q) ! H (q)


⎢ 1,1 1,m


⎢ ⎥
H(q) = ⎢ ⎥
x(k) = (q I −Φ)−1 Γu(k) ⎢
" # "

⎢ H o,1(q) ! H o,m (q) ⎥
⎢⎣ ⎥⎦

y(k) = H(q)u(k)
= (C(q I−Φ)−1 Γ + D )u(k)

22/09/20 Digital control review 18


Z-transform of a state model

Z ⎡⎣ x(k +1)⎤⎦ = Z ⎡⎣Φx(k)+ Γu(k)⎤⎦


z ⎡⎣ X(z )− x(0)⎤⎦ = ΦX(z )+ ΓU(z )
(zI −Φ) X(z ) = zx(0)+ ΓU(z )

−1 −1
X(z ) = (zI −Φ) zx(0)+ (zI −Φ) ΓU(z )
−1 ⎡ −1 ⎤
Y(z ) = C (zI −Φ) zx(0)+ ⎢C (zI −Φ) Γ + D ⎥ U(z )
⎣ ⎦

22/09/20 Digital control review 19


Pulse transfer func7on

Y(z ) = H(z )U(z ) ⎡ H (z ) ! H (z ) ⎤


⎢ 1,1 1,m ⎥
⎡ −1 ⎤ ⎢ ⎥
= ⎢C (zI −Φ) Γ + D ⎥ U(z ) H(z ) = ⎢

" # " ⎥

⎣ ⎦ ⎢ H o,1(z ) ! H o,m (z ) ⎥
⎢⎣ ⎥⎦

•  The pulse transfer function and the pulse transfer operator can
be reciprocally obtained by substituting q for z or z for q:
H(z ) = H(q)|q is changed to z H(q) = H(z )|z is changed toq

•  The technical name for this is that they are isomorphic. They
have the same form, but different meaning.

22/09/20 Digital control review 20


Calcula7ng pulse transfers in Scilab
z=poly(0,"z")

Hpend_d=clean(C*inv(z*I-Fi)*Gamau)
disp(Hpend_d,"Hpend_d")

Hpend_dzpk=zpk(pend_d)
disp(Hpend_dzpk,"Hpend_dzpk")

22/09/20 Digital control review 21


The z = esh projec7on from the s to the z
plane
s = 0→z =1
s = −∞ → z = 0
s = jωs / 2 → z = −1 ωs = 2π / h

Res < 0 → z = 1
s = jω → z = 1
Res > 0 → z = 1

•  The projection is periodic along the jω axis with period ωs. All
the points s = σ+j(ω+kωs) project on the same z.

22/09/20 Digital control review 22


Stability criterion for linear discrete models

∀z i , z i <1 ← strictly stable

∃z i , z i >1
∨ ← unstable
∃z i , z i = 1∧ m(z i ) >1

Not the above ← marginally stable

22/09/20 Digital control review 23


Inverted pendulum on cart eigenvalues in z
plane for chosen h
p_d=spec(Fi)
disp(p_d,"Nominal model poles in z for h:")





Exercise: check that the con7nuous 7me and discrete
7me eigenvalues are related by zi = exp(si*h)
22/09/20 Digital control review 24
Full state feedback
•  Assume that one can measure all the state variables.
•  Calculate the command variable as

u(k) = −l 1 x 1(k)−l 2 x 2 (k)−...−l n x(k) = −Lx(k)

•  Exercise: discuss how you could calculate the command


variable for the inverted pendulum on a cart assuming
that the controller would be implemented with an STM
32 microcontroller.

22/09/20 Digital control review 25


Behavior under full state feedback
Plant state equation:
x(k +1) = Φx(k)+ Γu u(k) (1)
Processor generated command:
u(k) = −Lx(k) (2)
System behavior:
x(k +1) = Φx(k)−Γu Lx(k) (3)
x(k +1) = ⎡⎣Φ−Γu L ⎤⎦ x(k)
x(k +1) = Φ f x(k)

The system behavior depends on the eigenvalues of Φ f .


If the eigenvalues of Φ f are set to 0 the controller is said to be 'dead-beat'
and the free response goes to 0 in n sampling periods: Φnf = 0.

22/09/20 Digital control review 26


Controllability

•  Definition: a system is controllable if it is possible to drive it


from an arbitrary initial state x(0) to an arbitrary desired final
state xd = x(tf) by applying a finite sequence of commands U.

•  Criterion when the command variable is a scalar:


–  The controllability matrix Wc must W = ⎡ Γ ΦΓ ! Φn−1Γ ⎤
c ⎢⎣ ⎥⎦
have rank n. T
U = [u(n −1)… u(0)]

x(nh) = Φn x(0)+WcU
U = Wc−1 ⎡⎢ x(nh)−Φn x(0)⎤⎥
⎣ ⎦
22/09/20 Digital control review 27
Criterion to choose the eigenvalues of Φf

•  The plant closed loop poles must be chosen to achieve a proper


balance between speed of recovery from a disturbed state
x(0) ≠ 0 and the control effort.

K−1
•  Performance measures: J x = ∑ x (k)
2

–  State settling time, ts. k=0

–  Quadratic cost of state to Kh.


–  Maximum value of command, u(0). K−1

–  Quadratic cost of control to Kh. J u = ∑ u 2 (k)


k=0

22/09/20 Digital control review 28


Simula7on of inverted pendulum on cart
under a full state feedback in Scilab
//Choose closed loop poles in s plane

poles_s=[-2.0 -2.0 -2.0 -2.0]


disp(poles_s,'Closed loop poles in the s plane:')
poles_z=exp(poles_s*h); disp(poles_z,'Closed loop poles in the z plane:')

//Calculate gains with ppol
L=ppol(Fi,Gamau,poles_z)

disp(L,'Feedback gains for the chosen poles:')
disp(clean(spec(Fi-Gamau*L)),'Checking accuracy - eigenvalues of Fi-
Gamau*L:')

22/09/20 Digital control review 29


//Seong condi7ons for simula7on

p=8 //Final instant of simula7on


x0=[0 0.1 0 0]'//Ini7al state


p_amp=0 //Disturbance step amplitude


//Measurement error parameters


rand("normal") //Error probability distribu7on


rand("seed",0) //Ini7alize the random number generator to seed
kn=0.001 //Measurement error standard devia7on

//Command satura7on limits


satura7on_enable=0 //Enable simula7on of command satura7on


u_sat_plus=10; u_sat_minus=-10

22/09/20 Digital control review 30


// Simula7on

//Number of sample instants and vector of 7me instants


N=round(1000*(p/h))/1000+1
tk=0:h:(N-1)*h

//Ini7al values

xk=x0

//External inputs

p=p_amp*ones(1,N) //Disturbance

22/09/20 Digital control review 31


//Simula7on loop

for k=0:1:N-1

//Inputs calcula7on
pk=p(k+1)

//Measurement noise and measurement
nk=kn.*rand(dimx,1); xmk=xk+nk

//Calcula7on of command
uk=-L*xmk

if satura7on_enable==1 then
if uk>u_sat_plus then uk=u_sat_plus end
if uk<u_sat_minus then uk=u_sat_minus end
end

22/09/20 Digital control review 32
//Calcula7on of next state

xkplus1=Fi*xk+Gama*[uk pk]’

//Storing values
u(:,k+1)=uk;
x(:,k+1)=xk;
n(:,k+1)=nk

//Shit for next itera7on
xk=xkplus1;

end

22/09/20 Digital control review 33


// Ploong responses

scf(1); clf
UfScale=0.1
drawlater()
a=gca();
plot(tk', x', tk',(u*UfScale)')

//Color map 0 ou 1 preto 2 azul 3 verde
//4 ciano 5 vermelho 6 magenta 7 amarelo 8 branco

a.children.children.mark_mode='on' //Desenha pontos
a.children.children.mark_style=0 //Marca de ponto é círculo
a.children.children.mark_size=3 //Tamanho da marca de ponto

22/09/20 Digital control review 34


// Ploong responses
a.children.children(1).mark_foreground=6 //Cor da marca de ponto
a.children.children(1).mark_background=6 //Cor da marca de ponto
a.children.children(2).mark_foreground=4 //Cor da marca de ponto
a.children.children(2).mark_background=4 //Cor da marca de ponto
a.children.children(3).mark_foreground=3 //Cor da marca de ponto
a.children.children(3).mark_background=3 //Cor da marca de ponto
a.children.children(4).mark_foreground=5 //Cor da marca de ponto
a.children.children(4).mark_background=5 //Cor da marca de ponto
a.children.children(5).mark_foreground=2 //Cor da marca de ponto
a.children.children(5).mark_background=2 //Cor da marca de ponto
a.children.children(1).foreground=6
a.children.children(2).foreground=4
a.children.children(3).foreground=3
a.children.children(4).foreground=5
a.children.children(5).foreground=2
22/09/20 Digital control review 35

a.grid=[0 0];

7tle='Pendcart control, disturbance = '+ string(p_amp)+ ', noise std =
'+string(kn)
a.7tle.text=7tle
a.7tle.font_size=3;
a.x_label.text='t';
a.x_label.font_size=3;
a.y_label.font_size=3;
legend(['x','teta','v','omega','u/'+string(1/UfScale)],3)
drawnow()

22/09/20 Digital control review 36



// Performance measures

//Sum of squares of states

Jx=h*sum(x.*x,"c")
disp(Jx, "Jx: [ x teta v omega]")

//Sum of squares of command


Ju=h*sum(u.*u,"c")
disp(Ju, "Ju")

22/09/20 Digital control review 37


Some simula7on results

22/09/20 Digital control review 38


Week 1 Home exercises

•  The goal of these exercises is to get a good understanding of full
state feedback properties through playing with simulations.
1.  With noise std and disturbance set to 0, no actuator saturation
simulation, try different values for the closed loop eigenvalues
(CLE) in the situation of an impulse disturbance – initial state
different from 0. Note that as the CLE go to the left, the
command effort (maximum value, Ju) increases and the
regulation performance improves (settling time and Jx
decreases). The inverse happens if the CLE go to the right.
Tabulate the results: CLE, L gains, settling time, Jx, maximum
command value, Ju.

22/09/20 Digital control review 39


2.  For a given CLE, change the initial state values to mimick
different possible disturbed states, observe and register
differences in behavior.
3.  Enable actuator saturation simulation. Verify that it is possible
that the system becomes unstable for some combinations of
initial state and eigenvalues choice. For a given CLE, try to
determine a kind of “limit” initial state value above which the
system becomes unstable. Make the converse: for a giben initial
state value, try to determine a kind of “limit” CLE above which
the system becomes unstable. Finally, observe that saturation
increases settling time in relation to the ideal unsaturated
situation.

22/09/20 Digital control review 40


4.  Set noise std to a positive value, e.g. 0.005. Because one uses
the same value for all the supposed measurements, this means a
measurement error standard deviation of 0.005 m, 0.005 rad,
0.005 m/s and 0.005 rad/s.
Qualitatively, try to confirm or refute the hypothesys that
increasing CLE / gain values degrade system behavior. How
could you test the hypothesis quantitatively?
Comment the instruction rand("seed",0) to get different
noise values each time you run a simulation.
Simulate the situation where the initial state is 0 to check that
measurement noise produces unnecessary system behavior.
5.  With noise std set to 0, simulate the situation of applying an
external 1 N force on the cart (p_amp=1). Observe that while
the pendulum goes on equilibrated the cart deviates from the
null reference x position.
22/09/20 Digital control review 41
Control with state es7mates

•  Because it is not easy to measure all state variables, one can use estimates of
their values generated instead. How does performance degrade?

x(k +1) = Φx(k)+ Γu (−Lx̂(k))


= Φx(k)−Γu L ( x(k)−e(k))
= (Φ−Γu L ) x(k)+ Le(k)

•  Performance is degraded by the error “times” the gains.


•  If the error converges to 0, performance converges to the measurement case.

22/09/20 Digital control review 42


Es7ma7on of states with a full-state
observer

x̂(k +1) = Φx̂(k)+ Γu(k)+ K ⎡⎣ y(k)−Cx̂(k)⎤⎦

22/09/20 Digital control review 43


Full-state observer error
e(k +1) = x(k +1)− x̂(k +1) =
= Φx(k)+ Γu(k)−Φx̂(k)−Γu(k)− K ⎡⎣ y(k)−Cx̂(k)⎤⎦
= Φe(k)− K ⎡⎣Cx(k)−Cx̂(k)⎤⎦
= Φe(k)− KCe(k)
= (Φ− KC )e(k)
= Φe e(k)

•  The observer error evolution depends on the eigenvalues of the Φe


transition matrix.
•  If the eigenvalues of Φe are set to 0, the observer is said dead-beat on
error, and the error free response goes to 0 in n sampling periods: Φen= 0

22/09/20 Digital control review 44


Loop equa7ons with a full order observer
x(k +1) = Φx(k)+ Γ(−Lx̂(k))
= Φx(k)−ΓL ⎡⎣ x(k)− e(k)⎤⎦
= (Φ−ΓL ) x(k)+ ΓLe(k)

e(k +1) = (Φ− KC ) e(k)

•  The system has 2n poles.


•  The above equations imply the separation principle: it is possible
to choose the plant closed loop poles and the observer error
poles independently.

22/09/20 Digital control review 45


Observability

•  Definition: a system is observable if it is possible to derive the


value of an arbitrary initial state x(0) from a finite sequence of
output measurements Y.
Assume that u(k) = 0.
•  Criterion for the output ⎡ y(0) ⎤ ⎡ C ⎤
⎢ ⎥ ⎢ ⎥
measurements being a scalar: ⎢ ⎥ ⎢ CΦ ⎥
⎢ y(1) ⎥
Y =⎢ ⎥ Wo = ⎢⎢ ⎥

–  The observability matrix Wo ⎢ ! ⎥ ⎢ ! ⎥
⎢ ⎥ ⎢ CΦn−1 ⎥
must have rank n. ⎢⎣ y(n −1) ⎥⎦ ⎣ ⎦

Y = Wo x(0)
x(0) = Wo−1Y
22/09/20 Digital control review 46
Criterion to choose the eigenvalues of Φe

•  The eigenvalues of Φe must be chosen to achieve a


proper balance between speed of recovery from an
estimation error e(0) ≠ 0 and the sensitivity to
measurement noise or measurement errors.

22/09/20 Digital control review 47


Simula7ng the use of a full order observer
in the inverted pendulum on cart control
•  Create a new simulation program by changing the
above one. The following instructions are nececssary.

//Observer error poles in s plane
poles_so=[-8 -8 -8 -8]
disp(poles_so,'Observer error poles in the s plane:')

//Observer error poles
poles_zo=exp(poles_so*h)
disp(poles_zo,'Observer error poles in the z plane:')

22/09/20 Digital control review 48


//Observer gains

K=ppol(Fi',C',poles_zo)
K=K'
disp(K,'Observer feedback gains:')

disp(clean(spec(Fi-K*C)), 'Checking accuracy - eigenvalues of Fi-K*C:')



//Ini7al values

xk=x0
xok=zeros(dimx,1) //Es7mator ini7al state

22/09/20 Digital control review 49


•  Change the simulation loop as follows

//Calcula7on of command

uk=-L*xok

if satura7on_enable==1 then
if uk>u_sat_plus then uk=u_sat_plus end
if uk<u_sat_minus then uk=u_sat_minus end
end

//Calcula7on of next es7mate


nk=kn.*rand(dimy,1)
yk=C*xk+nk // measured y
yok=C*xok // es7mated y
xokplus1 = Fi*xok+Gamau*uk+K*(yk-yok) //es7mate for next k

22/09/20 Digital control review 50


//Calcula7on of next state

xkplus1=Fi*xk+Gama*[uk pk]'

//Storing values

u(:,k+1)=uk
x(:,k+1)=xk
xo(:,k+1)=xok
n(:,k+1)=nk

//Shit for next itera7on

xk=xkplus1
xok=xokplus1

22/09/20 Digital control review 51


//Ploong observa7on errors

scf(2)
clf

e=x-xo

drawlater()
b=gca();
plot(tk',clean(e)')

//Color map 0 ou 1 preto 2 azul 3 verde


//4 ciano 5 vermelho 6 magenta 7 amarelo 8 branco

b.children.children.mark_mode='on' //Desenha pontos


b.children.children.mark_style=0 //Marca de ponto é círculo
b.children.children.mark_size=3 //Tamanho da marca de ponto

22/09/20 Digital control review 52


b.children.children(1).mark_foreground=4 //Cor da marca de ponto
b.children.children(1).mark_background=4 //Cor da marca de ponto
b.children.children(1).foreground=4
b.children.children(2).mark_foreground=3 //Cor da marca de ponto
b.children.children(2).mark_background=3 //Cor da marca de ponto
b.children.children(2).foreground=3
b.children.children(3).mark_foreground=5 //Cor da marca de ponto
b.children.children(3).mark_background=5 //Cor da marca de ponto
b.children.children(3).foreground=5
b.children.children(4).mark_foreground=2 //Cor da marca de ponto
b.children.children(4).mark_background=2 //Cor da marca de ponto
b.children.children(4).foreground=2

22/09/20 Digital control review 53


b.grid=[0 0]; //visível a preto
b.7tle.text='Full order observer errors with noise std ='+string(kn)
b.7tle.font_size=3;
b.x_label.text='t';
b.x_label.font_size=3;
b.y_label.font_size=3;
legend(b,['ex','eteta','ev','eomega'],4)
drawnow()

// Performance measures

//Sum of squares of full observer errors

Je=h*sum(e.*e,"c")
disp(Je, "Je")

22/09/20 Digital control review 54


Some simula7on results

22/09/20 Digital control review 55


Weekly home exercises

22/09/20 Digital control review 56

You might also like