Professional Documents
Culture Documents
Lecture 4
State feedback (continued), optimal control
1. Reference feed-forward
2. Integral effect
3. Optimal Control
4. Lunar lander
1. Reference feed-forward
2. Integral effect
3. Optimal Control
4. Lunar lander
State feedback
Consider the system:
ẋ = Ax + Bu
y = Cx
ẋ = (A − BK)x
if the system is controllable, we can choose K to make the closed-loop system stable. Then, x will
converge towards x∞ = 0, and y towards y∞ = 0.
Reference
Sometimes we want the system output y to converge to a non-zero reference r. But we still want
the benefits of the state feedback. How?
Implementation
u= Kr r − Kx
|{z} |{z}
Reference feedforward State Feedback
Equilibrium conditions
Assuming that feedback results in a stable equilibrium yields the steady-state condition:
Finding Kr
Inversion gives the correct feedforward gain:
Note that the number of references must be the same as the number of outputs.
1
The elements in y are the variables we wish to control, not the measurement per sé. In state feedback all states are assumed
known.
TTK4115 (MOA) Lecture 4 5 / 43
Reference feed-forward
A common mistake
If C = I, so y = x, one might be tempted to use pure error feedback:
u = K(r − x)
x̂(s)
⇒ = (sI − [A − BK])−1 BK
r̂(s)
Assume that the reference is constant r̂(s) = r0 /s. The final-value theorem yields (in general):
x̂(s) r0
x(∞) = lim s = −(A − BK)−1 BKr0 6= r0
s→0 r̂(s) s
Correct approach
Suppose now that state feedback + reference feedforward is used instead (now for any C):
ŷ(s) x̂(s)
⇒ =C = C(sI − [A − BK])−1 B[C(BK − A)−1 B]−1
r̂(s) r̂(s)
Assume that the reference is constant r̂(s) = r0 /s. The final-value theorem yields:
ŷ(s) r0
y(∞) = lim s = C(A − BK)−1 B[C(A − BK)−1 B]−1 r0 = r0
s→0 r̂(s) s
The reference feed-forward moves the equilibrium point of the closed-loop system so y = r in
the equilibrium point.
This lets us separate the issue of following the reference (feed-forward), from the issue of the
system’s convergence properties (state feedback).
Note that the value of Kr depends on the value of K.
1. Reference feed-forward
2. Integral effect
3. Optimal Control
4. Lunar lander
Problem
What if we don’t know our system perfectly? (We never do)
What about disturbances: w?
Solution
Use integral effect!
Plant2
Disturbance
z}|{
ẋ = Ax + Bu + Bw
y = Cx
Augmented system
ẋ A 0 x B B 0
= + u+ w+ r
ẋa −C 0 xa 0 0 I
2
The disturbance w is assumed to act in a way that can be cancelled by the input.
TTK4115 (MOA) Lecture 4 11 / 43
Integral effect
Augmented system
ẋ A 0 x B B 0
= + u+ w+ r
ẋa −C 0 xa 0 0 I
State feedback
As before state feedback + reference feedforward is used:
x
u = − K Ka + Kr r
xa
ẋa = 0 ⇒ Cx∞ = r0
If the feedforward is implemented as shown earlier (Kr = [C(BK − A)−1 B]−1 ) we have:
Ka xa,∞ = w0
ẋa = 0 ⇒ Cx∞ = r0
The integral action now performs double duty and compensates for the disturbance as well as
setting the correct bias3 :
Ka xa,∞ = −Kr r0 + w0
3
But only asymptotically..
TTK4115 (MOA) Lecture 4 14 / 43
Example
Cruise control
Car model:
mv̇ = −dv + u + w, y =v
Matrices:
d 1
A = −m , B= m
, C=1
State feedback
Control:
u = −kv + kr r
Feedforward gain:
kr = [C(BK − A)−1 B]−1 = d + k
Closed loop dynamics:
mv̇ = (d + k )(r − v ) + w, y =v
Stable equilibrium at y = r if w = 0.
State feedback
Control:
u = −kv − ka xa + kr r
Closed loop dynamics:
− d+k − kma kr 1
v̇ v
= m + m r+ m w
ẋa −1 0 xa 1 0
State feedback
Control:
u = −kv − ka xa + kr r
Closed loop dynamics:
− d+k − kma kr 1
v̇ v
= m + m r+ m w
ẋa −1 0 xa 1 0
Transfer functions
r.ff.
z }| {
(d + k)s −ka s
ŷ (s) = r̂ (s) + ŵ(s)
ms2 + (d + k)s − ka ms2 + (d + k)s − ka
Retaining reference feedforward may yield faster reference tracking.
1. Reference feed-forward
2. Integral effect
3. Optimal Control
4. Lunar lander
Optimal control
Optimal control is concerned with finding an input u(t) that minimizes a cost function over some
interval of time, subject to system dynamics.
LQR
The Linear Quadratic Regulator is a special case where the plant is Linear and the cost function is
Quadratic. The time interval is infinite.
ẋ = Ax + Bu
y = Cx
This form weights the outputs y(t). We can choose to weight the state values x(t) instead.
Note:
It is an ordinary state feedback - just with a new way of choosing K.
The J function is separate from the state equation - but its value depends on it.
For J to have a finite value, the system must converge towards its equilibrium in origo.
The system must therefore be controllable...
... and the value of K that optimizes J must stabilize the system.
Scalar case
In a scalar system, the object function can be written as follows:
Z ∞
J= qx(t)2 + ru(t)2 dt, q > 0 and r > 0
0
The feedback gain k that optimizes J depends on the relative sizes of q and r , and these serve to
prioritize:
either fast convergence of x(t), using a large q/r
or low use of the input u(t), using a small q/r .
Multivariable case
Z ∞
J= yT (t)Qy(t) + uT (t)Ru(t)dt
0
In the multivariable case:
The Q matrix lets us weight fast convergence in each individual output (in the diagonal
elements) and in products of pairs of outputs (in the off-diagonal elements). We often use
nonzero values on the diagonal only.
The R matrix lets us weight the inputs (in the diagonal elements). We typically use nonzero
values on the diagonal only.
Finding a minimum
Finding an analytical solution that minimizes the objective function is in general not trivial.
Discretizing the dynamics and finding the optimum numerically over a finite horizon is a viable
method (MPC,NMPC).
Linear model with a quadratic cost function is a ”lucky” case: we can find an analytical
solution that covers all all initial values.
Output energy
yT (t)Qy(t)
Making this function smaller requires more input energy.
Control energy
uT (t)Ru(t)
Making this function smaller requires less input energy which leads to higher output energy.
Finding a minimum
We want to find the minimum of:
Z ∞
J= yT (t)Qy(t) + uT (t)Ru(t)dt
0
where:
H(x(·), u(·)) is not affected by the input, directly or indirectly.
Λ(x(t), u(t)) has an obvious minimum in terms of u(t).
The functionala H(x(·), u(·)) above can be described as a feedback invariant. The functional takes
the system inputs and states as arguments, but its value depends only on the initial condition x(0).
It is not affected by the input, directly or indirectly.
a
A functional takes functions as arguments and returns a scalar.
Feedback invariance
The functional: Z ∞ d h T i
H(x(·), u(·)) , − x (t)Sx(t) dt
0 dt
happens to be feedback invariant as long as x(t) → 0 as t → ∞:
Z ∞
d h T i h i∞
x (t)Sx(t) dt = − xT (t)Sx(t) = xT (0)Sx(0) − (
xT (∞)Sx(∞)
(
− (((
0 dt 0
d h T i
x Sx(t) = ẋT Sx + xT Sẋ = xT S[Ax + Bu] + [Ax + Bu]T Sx
dt
"Z #
∞
T T
J = H(x, u) + y (t)Qy(t) + u (t)Ru(t)dt − H(x(·), u(·))
0
Z ∞
= H(x, u) + xT CT QCx + uT Ru + (Ax + Bu)T Sx + xT S(Ax + Bu)dt
0
Z ∞
xT (AT S + SA + CT QC)x + uT Ru + 2uT BT Sx dt
= H(x, u) +
0 | {z }
Λ(x,u)
Z ∞
J = H(x(·), u(·)) + Λ(x(t), u(t))dt
0
Z ∞
H(x(·), u(·)) = − [Ax(t) + Bu(t)]T Sx(t) + xT (t)S[Ax(t) + Bu(t)]dt
0
Λ(x, u) = xT (AT S + SA + CT QC)x + uT Ru + 2uT BT Sx
Z ∞
J = H(x(·), u(·)) + Λ(x(t), u(t))dt
0
Z ∞
H(x(·), u(·)) = − [Ax(t) + Bu(t)]T Sx(t) + xT (t)S[Ax(t) + Bu(t)]dt
0
Λ(x, u) = xT (AT S + SA + CT QC − SBR−1 BT S)x + (u + R−1 BT Sx)T R(u + R−1 BT Sx)
How to minimize J
We already established that H(x(·), u(·)) is feedback invariant for any choice of S, so we can
ignore it in the optimization.
We can choose S so the first quadratic expression becomes 0. The equation has the form of
the continuous-time Ricatti equation (CARE)
After choosing S, we just need to minimize the second term (to 0) by the right choice of u
Z ∞
J = H(x(·), u(·)) + Λ(x(t), u(t))dt
0
Z ∞
H(x(·), u(·)) = − [Ax(t) + Bu(t)]T Sx(t) + xT (t)S[Ax(t) + Bu(t)]dt
0
Λ(x, u) = xT (AT S + SA + CT QC − SBR−1 BT S)x + (u + R−1 BT Sx)T R(u + R−1 BT Sx)
Minimization step 1:
Solve CARE:
AT S + SA + CT QC − SBR−1 BT S = 0
Minimization step 2:
Choose:
u = −R−1 BT Sx
is a linear feedback:
u(t) = −Kx(t)
where:
K = R−1 BT S
leading to the closed loop system:
p2
−2λp + q − =0
r
The solutions are: q
p = −λr ± qr + λ2 r 2 : Pick the positive solution
The feedback matrix becomes:
r !
p q
u(t) = −kx(t) = − x(t) = λ− + λ2 x(t)
r r
Input: !
r
p q
u(t) = −kx(t) = − x(t) = λ− + λ2 x(t)
r r
Note:
There is a direct tradeoff between q and r .
1
Qii =
maximum acceptable value of xi2
1
Rjj =
maximum acceptable value of uj2
Matlab commands
”SYS = ss(A,B,C,D)”
”[K,S,E] = lqr(SYS,Q,R,N)”
”[K,S,E] = lqry(SYS,Q,R,N)”
Remarks
{A, B} must be controllable.
If weighing the outputs, all unstable modes must show up in the output.
1. Reference feed-forward
2. Integral effect
3. Optimal Control
4. Lunar lander
fs
y
f
fs
y
f
Nonlinear model
m 0 0 ẍ sin(θ) cos(θ) 0
f
0 m 0 ÿ = cos(θ) − sin(θ) − mg
fs
0 0 j θ̈ 0 r 0
Nonlinear model
m 0 0 ẍ sin(θ) cos(θ) 0
f
0 m 0 ÿ = cos(θ) − sin(θ) − mg
fs
0 0 j θ̈ 0 r 0
Inputs
u1 = f − mg u2 = fs
Linearized model
m 0 0 ẍ 0 1 θ
u 1
0 m 0 ÿ = 1 0 + mg 0
u2
0 0 j θ̈ 0 r 0
Linearized model
m 0 0 ẍ 0 1 θ
u1
0 m 0 ÿ = 1 0 + mg 0
u2
0 0 j θ̈ 0 r 0
State equation
0 0
ẋ
0 0 0 1 0 0 x
ẏ 0 0 0 0 1 0 y 0 0
0 0 u1
θ̇
= 0 0 0 0 0 1 θ +
0 1
ẍ
0 0 g 0 0 0 ẋ 1
u2
m
ÿ 0 0 0 0 0 0
ẏ 0
m
0 0 0 0 0 0 r
θ̈ θ̇ 0 j
State equation
0 0
ẋ
0 0 0 1 0 0 x
ẏ 0 0 0 0 1 0 y 0 0
0 0 u1
θ̇
= 0 0 0 0 0 1 θ
+
1
ẍ 0 0 g 0 0 0 ẋ 0 u2
m
1
ÿ 0 0 0 0 0 0 ẏ
m
0
0 0 0 0 0 0 r
θ̈ θ̇ 0 j
Controllability Matrix
1 gr
0 0 0 0 0 0 0 0 0 0
m j
1
0 0 m
0 0 0 0 0 0 0 0 0
r
0 0 0 j
0 0 0 0 0 0 0 0
C=
1 gr
0 0 0 0 0 0 0 0 0 0
m j
1
m
0 0 0 0 0 0 0 0 0 0 0
r
0 j
0 0 0 0 0 0 0 0 0 0
State equation
0 0
ẋ
0 0 0 1 0 0 x
ẏ 0 0 0 0 1 0 y 0 0
0 0 u1
θ̇
= 0 0 0 0 0 1 θ
+
1
ẍ 0 0 g 0 0 0 ẋ 0 u2
m
1
ÿ 0 0 0 0 0 0 ẏ
m
0
0 0 0 0 0 0 r
θ̈ θ̇ 0 j
Output
x
y
1 0 0 0 0 0
θ
y = Cx = 0 1 0 0 0 0
ẋ
0 0 1 0 0 0
ẏ
θ̇
Simulink model
A Simulink model for the lunar lander with accompanying Matlab script is available on Blackboard.
Nonlinearities
The true system is not linear!
Actuator saturation
Thrusters are limited. In this example to: