Telechargé par Karel Peuskens

Voorbeeld verslag Blok X: Regeltechniek Oplossingen

publicité
Voorbeeld verslag Blok X
March 12, 2026
1
Deel A
ẋ =
R3
0
ẋ1
−1
=
ẋ2
−1
−1
.
x
(1)
1
x1
−2
+
u.
−1 x2
−3
(2)
x2 dx
Z 5
x3 dx,
0
1.1
Oplossingen Part 1A
1a
Als b=0 heb je geen wrijving (geen energieverlies) en is de angular acceleration groot. Wanneer
b positief is en groter wordt heb je te maken met wrijving waardoor energie verloren wordt en de
angular acceleration daalt.
1b
J Ω̇r (t) + b Ωr (t) = ∆τ (t)
Set ∆τ (t) = 0:
J Ω̇r (t) + b Ωr (t) = 0
Assume
Ωr (t) = c1 eλt
⇒
Ω̇r (t) = c1 λeλt
Substitute:
J(c1 λeλt ) + b(c1 eλt ) = 0
c1 eλt (Jλ + b) = 0 ⇒ Jλ + b = 0 ⇒ λ = −
b
J
So,
b
Ωr (t) = c1 e− J t
With Ωr (0) = Ω0 :
c1 = Ω0
Final answer:
b
Ωr (t) = Ω0 e− J t
1c
ẋ = f (x, u) =
y=x
1
u − bx
J
(3)
(4)
Figure 1: Plot
1d
1e
Ω̄r =
∆τ̄
b
(5)
1f
Uit vraag 1c weten we dat:
1.
f (x, u) =
u − bx
J
(6)
2.
h(x, u) = x
(7)
Nu lineariseren we de functies:
f (x, u) ≈ f (xe , ue ) +
=
∂f (xe , ue )
∂f (xe , ue )
(x − xe ) +
(u − ue )
∂x
∂u
ue − bxe
b
1
− (x − xe ) + (u − ue )
J
J
J
u − bx
=
J
en
h(x, u) ≈ h(xe , ue ) +
∂h(xe , ue )
∂h(xe , ue )
(x − xe ) +
(u − ue )
∂x
∂u
= xe + (x − xe ) + 0
=x
(8)
(9)
(10)
(11)
(12)
(13)
Met, niet te vergeten:
(xe , ue ) = (Ω̄r , ∆τ̄ ) = (
∆τ̄
, ∆τ̄ )
b
als resultaat voor het equilibrium punt uit vraag 1e.
De systeem matrix A is in dit geval een 1x1 matrix met een constant element:
A=−
b
J
(14)
In dit geval wordt de stabiliteit bepaald door het teken van de constante. Gegeven is dat b en J
beide positief zijn, het teken van de constante is dus negatief. Hieruit kunnen we concluderen dat
het systeem asymptotisch stabiel is. Het equilibrium punt was niet nodig voor het vinden van de
state-space matrices omdat de vergelijkingen al lineair waren.
2
1g
Figure 2: Code
Figure 3: Plot
1h
De unit step kan fysisch bijvoorbeeld betekenen dat er op tijdstip t=0 een plotselinge koppel van
1Nm wordt uitgeoefend. Praktisch reageert het systeem niet zo snel al een unit step. Wat er gebeurt
in dit voorbeeld is dat de koppel het systeem versnelt en terwijl de snelheid stijgt, groeit de kracht
bω.
Uiteindelijk geldt: bω = 1, er is geen versnelling meer. De step response laat dus zien: hoe snel het
systeem reageert, hoe sterk de demping is, en naar welke stationaire waarde het systeem convergeert
(in geval van een stabiel systeem).
3
1.2
Oplossingen Part 2A
2a
Figure 4: sketch 2A
2b
State vector:

  
θs
θs



x = Ωr = θ̇r 
Ωg
θ̇g
Input vector:
u=
τr
τg
Output vector:
Ωr
y=
Ωg
System dynamics
The nonlinear state-space model is given by

Ωr − Ω g
θ̇s
 −ks θs − bs (Ωr − Ωg ) + τr 




ẋ = f (x, u) = Ω̇r = 

J
 ks θs + bs (Ωrr − Ωg ) − τg 
Ω̇g
Jg



Output equation
y = h(x, u) =
4
Ωr
Ωg
2c
Figure 5: Blokdiagram 2C
2d
State vector:


θs
x(t) = Ωr 
Ωg
Input vector:
u(t) =
τr
τg
Output vector:
y(t) =
Ωr
Ωg
The system in linear state-space form is:
ẋ(t) = Ax(t) + Bu(t)
y(t) = Cx(t) + Du(t)
where
0
 ks
−
A =  Jr
 ks
Jg

1
bs
−
Jr
bs
Jg

0
1

B =  Jr

0
0

−1
bs 

Jr 
bs 
−
Jg


0 

1
−
Jg
0 1 0
C=
0 0 1
0 0
D=
0 0
5
2e
The eigenvalues are: [(-1.238+24.885j), (-1.238-24.885j), 0j]. The real parts of the eigenvalues are
strictly negative and zero meaning that we have a Neutral stability.
2f
The state vector remains the same, and the rotor torque τr becomes the only external input,
u = τr
The updated nonlinear system ẋ = f (x, u) becomes:


Ωr − Ω g
 −ks θs − bs (Ωr − Ωg ) + τr 




Jr


2
 ks θs + bs (Ωr − Ωg ) − KΩg 
Jg
Since all states are measured, the output becomes the same as the state and is:
 
θs
y =  Ωr 
Ωg
2g
Figure 6: Blockdiagram 2g
2h
The equilibrium state vector is:
τ̄r 
   r
ks 
θ̄s

τ̄r 


x̄ = Ω̄r  = ±

 rK 
Ω̄g

τ̄r 
±
K

6
2i
The closed-loop dynamics (with τg = KΩ2g ), state x = [θs , Ωr , Ωg ]⊤ and input u = τr are


Ωr − Ω g


 −ks θs − bs (Ωr − Ωg ) + τr 


.
ẋ = f (x, u) = 
Jr



2
 ks θs + bs (Ωr − Ωg ) − KΩg 
Jg
The output measures all states:


θs
y = h(x, u) = Ωr  .
Ωg
State matrix Af b

0
 k
 s
−
Af b =  Jr

 ks
Jg
1
−1
bs
Jr
bs
Jg

bs


.
Jr

bs + 2K Ω̄g 
−
Jg
−

Input matrix Bf b

0
1

Bf b = 
 Jr  .

0
Output matrix Cf b and feed-through Df b
Since y = x,

1
Cf b = I3 = 0
0
0
1
0

0
0 ,
1
 
0
Df b = 0 .
0
Observations
Compared to the open-loop (or the earlier linear model without the nonlinear torque feedback), the
feedback controller changes the linearized dynamics by modifying the (3, 3) entry of A:
−
bs
bs + 2K Ω̄g
−→ −
.
Jg
Jg
Additionally, the number of independent inputs is reduced to one (u = τr ), so Bf b is a 3 × 1 matrix,
and the output has been changed to measure all states (Cf b = I3 ).
7
2j
Figure 7: graph of results
2k
State Transformation to Human-Readable Units
The original state vector is


θs (t)
x(t) = Ωr (t)
Ωg (t)
with units (rad, rad/s, rad/s).
We define a new state vector

θs◦ (t)
(t)
z(t) = Ωrpm
r
rpm
Ωg (t)

with units (deg, rpm, rpm).
State Transformation Matrix
Using the unit conversions
1 rad =
180
deg,
π
1 rad/s =
8
60
30
=
rpm,
2π
π
the state transformation z = T x is defined by
 180
0
π
30
π
T = 0
0

0
0  ∈ R3×3 .
0
30
π
 π
0
The inverse transformation is
180
T −1 =  0
0
π
30
0

0
0 .
π
30
Transformed State-Space System
Given the original system
ẋ(t) = Af b x(t) + Bf b u(t),
y(t) = Cf b x(t) + Df b u(t),
and using x = T
−1
z, we obtain
ż(t) = T Af b T −1 z(t) + T Bf b u(t).
Thus, the transformed system matrices are
Ãf b = T Af b T −1 ,
C̃f b = Cf b T
−1
,
B̃f b = T Bf b ,
D̃f b = Df b .
2l
Figure 8: graph 2L
2m
Eigenvalues of Af b : [(-4.738+24.443j), (-4.738-24.443j), (-0.127+0j)]
Eigenvalues of Af b,t : [(-4.738+24.443j), (-4.738-24.443j), (-0.127+0j)]
The eigenvalues for Af b and Af b,t are the same. All real parts of the eigenvalues are negative
indicating that the system is asymptotically stable.
9
2n
Figure 9: graph 2n
Eigenvalues of A: [-8.878, -0.569, -0.156]
Reducing the shaft torsional spring constant ks by a factor of 100 makes the drivetrain
significantly more compliant. After the step at t = 10 s, the system requires more time to adjust to
the new operating condition. The rotor and generator speeds separate more noticeably for a short
period, and the shaft twist angle becomes larger compared to the previous case. This indicates
that the drivetrain behaves less rigidly and exhibits a more pronounced temporary mismatch
between rotor and generator before settling to steady operation.
The eigenvalues move closer to the imaginary axis, meaning that their real parts decrease in
magnitude. This implies a slower response of the system and a longer adjustment phase after the
step input.
2o

0
 s
AV =  −b
Jr
−1
1
∂τr
∂Ωr
− Jbsr + Jr
ks
Jg

bs

Jr
(−bs −2KΩg )
Jg
bs
Jg


1
∂τr
 s
∂Ωr 
BV =  −b
J + J 
r
CV = 0
bs
Jg
1
DV = 0
1.3
Oplossing Part 3A
3a
10

r
0
Figure 10: Sketch system part 3
3b
 
θ̇
θ

x = 
q̇  ,
q
u = F,
y =
θ
.
q
Define the temporary constants
k := I + mt l2 ,
M := mc + mt ,
c := mt l.
For small motions, the dynamics are
k θ̈ + cg θ = −c q̈,
M q̈ + b q̇ + c θ̈ = F.
11
(15)
(16)
Rewrite (15) as
k θ̈ + c q̈ = −cg θ.
From this,
θ̈ =
−cg θ − c q̈
.
k
Substitute into (16):
−cg θ − c q̈
=F
k
c2
c2 g
M q̈ − q̈ + b q̇ −
θ=F
k k
c2
c2 g
M−
q̈ = F − b q̇ +
θ
k
k
M q̈ + b q̇ + c
2
q̈ =
F − b q̇ + ckg θ
2
M − ck
.
Now compute θ̈ using (15) and the expression for q̈:
θ̈ =
−cg θ − c q̈
k
2
F − b q̇ + ckg θ
cg
c
=− θ−
k
k
!
.
2
M − ck
This gives us:


2
F −b q̇+ c kg θ
cg
c
− θ− k
2
M − ck

 k




θ̇
ẋ = 

2


F −b q̇+ c kg θ


2
c
M− k
q̇
θ
y=
q
State definitions:
x1 = θ̇,
x2 = θ,
x3 = q̇,
x4 = q.
ẋ2 = x1 ,
ẋ3 = q̈,
Then
ẋ1 = θ̈,
So the state-space form ẋ = Ax + Bu is

c2 g
cg
c ( k )
c
b
  0 − −
2
c

k
k (M − k ) k (M − ck2 )
ẋ1

ẋ2  1
0
0
 =
ẋ3  
c2 g

b
k
0
−
ẋ4
2
c2

(M − k )
(M − ck )
0
0
1
ẋ4 = x3 .



1
c
−
0    k
2
(M − ck ) 
 x1




0
x2  


0
  + 
 u.
 x3  

1




0 x4
c2

(M − k ) 

0
0
θ
For the output y =
,
q
y = Cx + Du,
y=
0
C=
0
1
0
0
0
0
,
1
θ
0
=
q
0
1
0
0
0
0
x
1
12
0
D=
.
0
3c
The eigenvalues of the system are [0j, (-0.045+0.376j), (-0.045-0.376j), (-0.15+0j)]. These eigenvalues are zero or negative, and two of the eigenvalues have complex parts. This means the system
has a neutral stability. When applying a step input, we first expect the system to be damped with
oscillations (because of the complex part) and then the system will stay within the same distance of
the stability value without converging or diverging from it.
3d
Figure 11: Impulse and Step response
In practice, the step function represents a sudden input of constant force, and the response shows
you how the system responds. With the impulse function, you suddenly apply a very short and big
force and see how the system responds. Theta and q are probably so small because the system is
initially positioned at the equilibrium state, meaning the turbine is hanging still at the start of the
experiment. Another reason is that the step response is a very small force for a system of this size,
and the impulse response has too short a time to really make the system move much.
3e
For the linear time-invariant system
ẋ(t) = Ax(t) + Bu(t),
y(t) = Cx(t) + Du(t),
the reachability (controllability) matrix is defined as
Wr = B AB A2 B · · ·
An−1 B .
The highest power of A appearing in Wr is An−1 , where n is the order (number of states) of the
system. Higher powers are not needed due to the Cayley–Hamilton theorem.
If A ∈ Rn×n and B ∈ Rn×m , then
Wr ∈ Rn×nm .
For a single-input system (m = 1), Wr is a square matrix of dimension n × n. Since the order of
the system is equal to its amount of states, the order n = 4, and thus the highest power of A is 3.
The dimensions of Wr is 4x4.
3f
The rank of the matrix is equal to the order of the matrix. Therefore the system is reachable,
meaning that you can reach any wanted output when giving the right input. In other words, you
can fully control the system by giving the right input to get a wanted output.
3g
When setting B=0, the reachablility matrix would be a 4x4 matrix with only zeros. The rank will
thus become zero. In theory this means that the system is not reachable as the rank is 0 while the
order is 4. In practice this means that it is not possible to reach a wanted output.
3h
13
Figure 12: Block Diagram
Ac = A − BK, Bc = Bkf , Cc = C − DK, Dc = Dkf
(17)
Figure 13: Eigenvalue Graph
De eigenvalues van de closed loop liggen allemaal in het linker half en het systeem is dus stabiel.
Voor de eigenvalues van de open loop ligt er een eigenvalue op de oorsprong. Het systeem is dus
neurtraal stabiel. In opgave 3d konden we dan ook het effect daarvan zien, bij de step response bleef
de q maar stijgen. Er was geen demping dat de cart liet stoppen. Nu met het closed loop system
is het wel stabiel en zien we bij de step response dat de cart uiteindelijk tot stilstand komt. (NOG
NIET VOLLEDIG, KIJK TERUG NAAR DE VRAAG IN VOCAREUM)
Figure 14: Closed Loop
14
Figure 15: Open Loop 3d
3i
Calculation of the reference gain kf To compute the reference gain kf , first the closed-loop
system with state feedback u = −Kx + kf r was considered. The closed-loop dynamics become
ẋ = (A − BK)x + Bkf r. For a constant reference, the steady-state condition ẋ = 0 was used to
solve for the steady-state state vector. By imposing the requirement that the crane position output
equals the reference (y = r), the reference gain was obtained as
kf = −
1
.
Cr (A − BK)−1 B
This gain ensures that the system output reaches the desired reference value in steady state.
Why only the crane position is selected from C Only the crane position is selected from
the output matrix C because the reference signal r represents the desired crane position q. The
other output, such as the sway angle θ, should not track the reference but instead converge to zero.
Therefore, the row of C corresponding to the crane position is used to form Cr , ensuring that the
reference gain is calculated for the correct output.
Conclusion from the new step response The new step response shows that the crane position
now correctly tracks the reference and reaches the desired steady-state value. Compared to the
previous exercise, the overall shape of the response (oscillation and settling behavior) remains similar,
but the final value is now correct. This is expected for a linear system, since the state-feedback gain
K determines the system dynamics, while the reference gain kf only scales the input to achieve
correct steady-state tracking.
3j
In desired cl eigenvalues, the dominant eigenvalue pair is -0.1223 (+ or -) 0.1362j because their real
part lies closest to the imaginary axis. These eigenvalues decay most slowly and therefore dominate
the transient response.
15
Figure 16: Eigen values
Figure 17: Step Responses
Let’s discuss what we see here. ζ controls the angle and ω0 controls the distance from the origin.
To get a faster response, we scaled the ω0 while keeping the damping ratio the same. In the step
response, we see the system reacting faster than the nominal (blue) one.
For the underdamped system, we did the opposite keeping the natural frequency the same but scaling the damping ratio down. In the step response (green) we see overshoots above the nominal
system (blue), showing signs of not enough damping.
For the overdamped system, the damping ratio becomes larger than 1, and we get only real eigenvalues. In the step response (red), we can see that the function has lower peaks and overall a smaller
amplitude, showing sign of too much damping. Lastly, for the critically damped system, the damping ratio is equal to 1. This should be the fastest response and show no overshoot, something we
can see in the step response as well.
The position of the eigenvalues controls the input signals the controller produces as well. Poles
closer to the imaginary axis provide smaller feedback gains K, the input signal changes slowly, and
there’s a lower control effort. Poles further left in the complex plane, on the contrary provides larger
feedback gains, the controller produces larger and sharper inputs, and there’s a stronger actuation
to force the system to move quickly.
To answer the question of possible drawbacks of a faster design, there are a few: the control effort
becomes larger, and the sensitivity to noise is higher because it gets amplified more, and the system
becomes more sensitive to modelling errors.
16
3k
Augmented system with integral action To include integral action, the state vector is augmented with the integral state
Z
z(t) = (q − r) dt,
ż = q − r.
The augmented state vector is defined as
xa = θ̇
θ
q̇
q
z
⊤
.
Starting from the open-loop system
ẋ = Ax + Bu,
y = Cx + Du,
and using ż = q − r, where q is selected from the second output, the augmented system becomes
ẋa = Aa xa + Ba u + Br r,
The augmented matrices are
A
Aa =
Cr
0
,
0
Ba =
Ca = C
0 ,
y = Ca xa + Da u.
B
,
0
Br =
0
,
−1
Da = D,
where Cr is the row of C corresponding to the crane position q.
This augmentation allows the controller to use the integrated position error, which removes
steady-state tracking error for a constant reference.
3l
Effect of the integrator eigenvalue When the integrator eigenvalue is moved further to the
left, the response becomes faster at first. However, beyond a certain magnitude, the system does
not get noticeably faster anymore. This happens approximately when the integrator pole is already
sufficiently faster than the dominant closed-loop poles found in 3h. From that point on, the overall
response is no longer limited by the integrator state, but by the other closed-loop poles of the system.
How to make the overall system faster To make the full system behave faster, the dominant
closed-loop poles of the original system must also be moved further to the left. So it is not enough
to only place the integrator pole further left; the state-feedback pole locations must be redesigned
as well.
Positive integrator eigenvalue If the integrator eigenvalue is chosen positive, the corresponding
pole lies in the right-half plane. This makes the closed-loop system unstable. The integral state
will grow instead of decay, which causes the control input and output to diverge. Therefore, the
integrator eigenvalue must be chosen negative.
3m
Effect of reintroducing the reference gain When the reference gain kf is added, the transient
shape of the response stays largely the same, but the output is scaled so that the crane position tracks
the reference more accurately. In other words, kf mainly affects how strongly the reference enters
the system, while the integral action still ensures zero steady-state error for a constant reference.
Effect of changing kf
Changing kf changes the scaling and sign of the reference input:
• For kf = 0.5 kf , the reference input is weaker, so the response initially moves less strongly
toward the reference.
• For kf = 2 kf , the reference input is stronger, so the response initially moves more aggressively.
• For kf = −1 kf , the sign of the reference input is reversed, so the system initially moves in the
wrong direction.
Because integral action is present, the system can still remove steady-state error for a constant
reference, but the transient behavior changes significantly depending on the value and sign of kf .
17
Effect on the eigenvalues Changing kf does not change the eigenvalues of the closed-loop system. The eigenvalues are determined by the matrix
Acl = Aa − Ba Ka ,
and kf only changes how the reference signal enters through the input matrix. Therefore, kf affects
the response amplitude and transient excitation, but not the pole locations or internal stability of
the closed-loop system.
1.4
Oplossingen Part 4A
4a

C
 CA 


2 
Wo = 
 CA 
 ... 
CAn−1

Dim(W0 )=pn x n,
with n (=4), the number of state variables, and p (=2), the number of outputs.
The observability matrix then becomes:


C
 CA 

Wo = 
CA2 
CA3
The observability and reachability are dual to each other. The observability of a system described
by (A,C) is equivalent to the reachability of the dual system described by (AT , C T ). Similarly, the
reachability of a system described by (A,B) is equivalent to the observability of the dual system
described by (AT , B T ).
4b
The rank of the observability matrix is equal to 4 and is equal to the number of states thetad , theta, qd , q.
This means that the system is observable. In practice this means that we can determine the states
knowing the input and output.
4c
When only measuring the angle θ or the position q, the output matrix C changes.
When only measuring the position q, the output matrix becomes:
Cq = 0
0
0
1
The observability matrix then becomes:

Cq
 Cq A 

Wo,q = 
Cq A2 
Cq A3

When only measuring the angle θ, the output matrix becomes:
Cθ = 0
1
0
0
And the observability matrix becomes:


Cθ
 Cθ A 

Wo,θ = 
Cθ A2 
Cθ A3
The rank of the observability matrix for only measuring the crane position, q, becomes 4 while
measuring only the tower angle, theta, has an observability matrix with rank 3. There are in total
4 states, the system is observable when using the crane position q as a measurement, meaning that
knowing q and the input u, we can reconstruct all states in a give time period. For the case of
18
measuring theta, we get an observability matrix that has a lower rank then the amount of states.
This means that it is not possible to reconstruct the full state based on the single measurement,
theta, because you don’t have enough equation for the amount of unknowns.
4d
Figure 18: Blockdiagram 4d
Augmented state-space model of the plant and observer
Consider the uncontrolled plant
ẋ = Ax + Bu,
(18)
y = Cx,
(19)
where D = 0.
The corresponding observer is given by
x̂˙ = Ax̂ + Bu + L (y − C x̂) ,
(20)
where L is the observer gain and x̂ is the estimated state.
Substituting the plant output y = Cx into the observer equation gives
x̂˙ = Ax̂ + Bu + L(Cx − C x̂)
(21)
= Ax̂ + Bu + LCx − LC x̂
(22)
= LCx + (A − LC)x̂ + Bu.
(23)
Now define the augmented state vector as
xe =
x
.
x̂
(24)
Its time derivative is
ẋ
Ax + Bu
ẋe = ˙ =
.
LCx + (A − LC)x̂ + Bu
x̂
19
(25)
This can be written in the standard state-space form
ẋe = Ae xe + Be u
(26)
with
A
Ae =
LC
0
,
A − LC
B
Be =
.
B
(27)
If the output of the augmented system is chosen as the measured plant output y, then
ye = Ce xe + De u
(28)
with
Ce = C
0 ,
De = 0.
Hence, the augmented plant-observer system is
A
0
B
ẋe =
x +
u,
LC A − LC e
B
ye = C 0 xe .
(29)
(30)
(31)
4e
The observer gain matrix L has dimension
L ∈ Rn×p ,
since the correction term L(y − C x̂) must produce an n × 1 vector from the output error (y − C x̂) ∈
Rp×1 . For this system, n = 4 states and p = 2 measured outputs (q, θ), hence
L ∈ R4×2 .
Because the augmented state vector is defined as
x
xe =
∈ R2n ,
x̂
the augmented state-space model
ẋe = Ae xe + Be u,
y = Ce x e + D e u
has matrices with dimensions
Ae ∈ R2n×2n ,
Be ∈ R2n×q ,
Ce ∈ Rp×2n ,
De ∈ Rp×q .
For the given system (n = 4, p = 2, q = 1):
Ae ∈ R8×8 ,
Be ∈ R8×1 ,
Ce ∈ R2×8 ,
4f
import numpy as np
import matplotlib . pyplot as plt
import control as ct
n = A . shape [0]
# Input signal : + F1 for T seconds , then - F1
F1 = 1.0 e5
T_switch = 20.0
dt = 0.01
t = np . arange (0 , 2* T_switch + dt , dt )
u = np . zeros_like ( t )
u [ t < T_switch ] = F1
20
De ∈ R2×1 .
u [ t >= T_switch ] = - F1
# Observer poles
cl_poles = de si re d_c l_ ei ge nva lu es
obs_poles_fast = 8 * cl_poles
obs_poles_slow = 3 * cl_poles
# Observer gains
L_fast = ct . place ( A .T , C .T , obs_poles_fast ) . T
L_slow = ct . place ( A .T , C .T , obs_poles_slow ) . T
def s imulate_observer (A , B , C , u , t , L , x0 , xhat0 ) :
dt = t [1] - t [0]
n = A . shape [0]
p = C . shape [0]
x = np . zeros (( n , len ( t ) ) )
xhat = np . zeros (( n , len ( t ) ) )
y = np . zeros (( p , len ( t ) ) )
yhat = np . zeros (( p , len ( t ) ) )
x [: ,0] = x0 . flatten ()
xhat [: ,0] = xhat0 . flatten ()
for k in range ( len ( t ) -1) :
uk = np . array ([[ u [ k ]]])
# true system
xdot = A @ x [: ,[ k ]] + B @ uk
x [: ,[ k +1]] = x [: ,[ k ]] + dt * xdot
# outputs
y [: ,[ k ]] = C @ x [: ,[ k ]]
yhat [: ,[ k ]] = C @ xhat [: ,[ k ]]
# observer
xhat_dot = A @ xhat [: ,[ k ]] + B @ uk + L@ ( y [: ,[ k ]] - C@xhat [: ,[ k ]])
xhat [: ,[ k +1]] = xhat [: ,[ k ]] + dt * xhat_dot
return x , xhat
The initial conditions used in this case are:
x0 = np.array([[0.0], [0.0], [0.0], [0.0]])
xhat0 = np.array([[0.03], [0.02], [0.2], [1.0]])
21
Figure 19: graph 4f
22
4g
[H]
Figure 20: graph 4g
Zero-mean Gaussian noise was added to the measured outputs θ(t) and q(t). The velocity
estimates θ̇(t) and q̇(t) were then obtained using a backward-difference approximation. The resulting
plots show that numerical differentiation strongly amplifies measurement noise, which makes the
estimated velocities much noisier than the true simulated velocity states. Numerical differentiation
amplifies measurement noise because the derivative is computed as a difference between successive
samples divided by the time step,
ẋ(tk ) ≈
x(tk ) − x(tk−1 )
.
∆t
If the measurements contain noise, these noise components are also subtracted and divided by
the small time step ∆t. Since noise typically contains high-frequency variations, the differencing
operation emphasizes these rapid changes, causing the estimated derivative to become very noisy.
As a result, numerical differentiation significantly amplifies measurement noise, making velocity
estimates unreliable when based on noisy position measurements.
4h
23
Figure 21: code1
Figure 22: code2
Figure 23: Plots
Two LQR controller designs were implemented, each with different weightings on the state and
input penalization matrices Qx and Qu, demonstrating the trade-off between aggressive state regulation and control effort.
The weighting matrices were chosen as Qx = diag([50, 0, 1, 0]) and Qu = diag([1]). The large
weight on the crane position q (50) reflects the primary control objective of bringing the cart to the
reference position accurately. The swing angle theta is penalized moderately (1), while the velocity
states are left unpenalized, allowing the controller to accept transient velocity deviations in exchange
24
for smoother control effort. The resulting step response shows the crane position converging to 1
m within approximately 8 seconds, with limited oscillation in the swing angle. The controller input
remains moderate throughout the maneuver.
For the second design, Qx was reduced and Qu increased, penalizing control effort more heavily.
This results in a slower response but lower actuator demand. The crane position still converges to 1
m, but with a longer settling time. This design is preferable in scenarios where actuator saturation
is a concern.
Increasing the state penalty relative to the input penalty produces a more aggressive controller that
settles faster but demands higher control input. Conversely, raising Qu yields a more conservative
controller with slower but smoother behavior. The closed-loop eigenvalues shift further into the
left-half plane as state penalties increase, confirming improved transient performance at the cost of
higher input effort.
2
AI Acknowledgement
For this report, we used AI for several tasks. AI was used to understand questions and the provided
code at a deeper level. We also used it for more tedious tasks like putting matrices in Overleaf
where AI generated the code for a given matrix. Lastly AI was used to check our answers. If the
language model provided the same reasoning for an answer, our answer has a bigger probability of
being correct. If not, then we would have to look at the exercise again and improve our errors.
25
Téléchargement