Professional Documents
Culture Documents
1 Linear MPC
1 Linear MPC
Alberto Bemporad
imt.lu/ab
• Hybrid MPC
• Stochastic MPC
• Learning-based MPC
• Numerical examples:
– Linear Systems:
http://cse.lab.imtlucca.it/~bemporad/intro_control_course.html
– Numerical Optimization:
http://cse.lab.imtlucca.it/~bemporad/optimization_course.html
– Machine Learning:
http://cse.lab.imtlucca.it/~bemporad/ml.html
model-based optimizer
process
measurements
simplified likely
Use a dynamical model of the process to predict its future
---------
evolution and choose the “best” control action
a good
(Propoi, 1963)
• MPC used in the process industries since the 80’s
(Qin, Badgewell, 2003) (Bauer, Craig, 2008)
©SimulateLive.com
"As can be observed, MPC is clearly considered more impactful, and likely to be more impactful,
vis-à-vis other control technologies, especially those that can be considered the "crown jewels" of
control theory - robust control, adaptive control, and nonlinear control."
€
reference
state (static I/O models)
optimization
• Reference trajectory
generator
reference-signal r(t)
tactical planner
dynamic optimizer
• optimize transient response
MPC • ensure reference tracking
• handle constraints
• coordinate multiple inputs
suspension deflection
tire deflection
suspension deflection
tire deflection
4
Employ stochastic
• "Stochastic MPC
prediction to take
models into
are account
used uncertainty
to account and
for uncertainty
driver9s behavior
and driver’s behavior
Measurements
• Real-time MPC is able to take into account coupled dynamics and constraints,
optimizing performance also during transients
Engine
torque
request
Desired
axle torque
Engine Control
nowcar.com
MPC
CVT US06 Double Hill driving cycle
ratio
request CVT Control (Bemporad, Bernardini, Livshiz, Pattipati, 2018)
http://www.odys.it/odys-and-gm-bring-online-mpc-to-production
(Bemporad, Rocchi, 2011) (Pascucci, Bennani, Bemporad, 2016) (Krenn et. al., 2012)
http://www.pw.utc.com/Press/Story/20100527-0100/2010
coal 1 ? ?
photovoltaic
coal 2
? ? ? hydro-storage
? ? ?
demand
natural gas
? ? ? wind farm
Drinking water
network of
Barcelona:
63 tanks
114 controlled 昀氀ows
17 mixing nodes
(2012-2015)
80
0.15
40
0.05
20
0
0
−20 −0.05
0 50 100 150 200 −0.05 0 0.05 0.1 0.15 0.2
Stock price at expiration Payoff
( )
x(ti ) − x(ti−1 )
p(T ) = max{w(T ) − K, 0} p(T ) = max 0, C + min
i∈{1,...,Nfix } x(ti−1 )
closed-loop simulation
MPC
design
physical modeling +
parameter estimation
real-time
system code
identification
/* z=A*x0; */
for (i=0;i<m;i++) {
z[i]=A[i]*x[0];
for (j=1;j<n;j++) {
z[i]+=A[i+m*j]*x[j];
}
}
experiments
physical process
"Model Predictive Control" - © 2023 A. Bemporad. All rights reserved. 24/132
MPC toolboxes
• MPC Toolbox (The Mathworks, Inc.): (Bemporad, Ricker, Morari, 1998-today)
odys.it/embedded-mpc
• ODYS Embedded MPC Toolset: (ODYS, 2013-today)
x ∈ Rn , f : Rn → R, g : Rn → Rm
g(x) ≤ 0
x
x1 g1 (x1 , x2 , . . . , xn )
. ..
.. ,
x= f (x) = f (x1 , x2 , . . . , xn ), g(x) =
.
xn gm (x1 , x2 , . . . , xn )
http://www.neos-server.org
http://www.coin-or.org/
convex set
nonconvex set
S x1 x2
x1 x2
• Every local solution is also a global one (we will see this later)
n
P = {x ∈ R : Ax ≤ b} v3
v1 A
1 x=
b1
A3x=b3 A3
• Vertex (V-)representation:
q
X p
X Convex hull = transformation
P = {x ∈ Rn : x = αi vi + β j rj } from V- to H-representation
i=1 j=1
Vertex enumeration =
∑ q
αi , βj ≥ 0, αi = 1, vi , rj ∈ Rn transformation from H- to
i=1
V-representation
when q = 0 the polyhedron is a cone
vi = vertex, rj = extreme ray
• LP in standard form:
′
min cx
s.t. Ax = b
x ≥ 0, x ∈ Rn
• Conversion to standard form:
1. introduce slack variables
n
X n
X
aij xj ≤ bi ⇒ aij xj + si = bi , si ≥ 0
j=1 j=1
• Many good solvers are available (CPLEX, Gurobi, GLPK, FICO Xpress, CBC, ...)
For comparisons see http://plato.la.asu.edu/bench.html
• GNU MathProg a subset of AMPL associated with the free package GLPK
(GNU Linear Programming Kit)
k−1
X
• Relation between input and states: xk = Ak x0 + Aj Buk−1−j
j=0
• Performance index
u0
N
X −1 R = R′ ≻0 u1
J(z, x0 ) = x′N P xN + x′k Qxk +u′k Ruk Q = Q′ ⪰0 z= ..
.
k=0 P = P ′ ⪰0 uN −1
• Goal: 昀椀nd the sequence z ∗ that minimizes J(z, x0 ), i.e., that steers the state x
to the origin optimally
′ ′
J(z, x0 ) = (S̄z + T̄ x0 ) Q̄(S̄z + T̄ x0 ) + z R̄z + x′0 Qx0
1 ′ 1
= z 2(R̄ + S̄ ′ Q̄S̄) z + x′0 2T̄ ′ Q̄S̄ z + x′0 2(Q + T̄ ′ Q̄T̄ ) x0
2 | {z } | {z } 2 | {z }
H F′ Y
"Model Predictive Control" - © 2023 A. Bemporad. All rights reserved. 40/132
Linear MPC - Unconstrained case
u0
u1
1 1 condensed
J(z, x0 ) = z ′ Hz+x′0 F ′ z+ x′0 Y x0 z= ..
2 2 . form of MPC
uN −1
∇z J(z, x0 ) = Hz + F x0 = 0
u∗
0
u∗
1
and hence z ∗ = .. = −H −1 F x0 (“batch” solution)
∗
.
uN −1
t t+k t+N
ymin ≤ yk ≤ ymax , k = 1, . . . , N
.
uN −1
t t+k t+N
u∗
feedback
0 z }| {
1 ′
u∗
1 min
2 z Hz + x′ (t)F ′ z
• Get the solution z ∗ = .. of the QP z
∗
.
uN −1
s.t. Gz ≤ W + S x(t)
|{z}
feedback
• Apply only u(t) = u∗0 , discarding the remaining optimal inputs u∗1 , . . . , u∗N −1
• Sample time: Ts = 1 s
(
x(t + 1) = [ 10 11 ] x(t) + [ 01 ] u(t)
• State-space realization:
y(t) = [ 1 0 ] x(t)
• Constraints: −1 ≤ u(t) ≤ 1
P
1 1 2
• Performance index: min k=0 yk2 + 10 uk + x′2 [ 10 01 ] x2 (N = 2)
• QP matrices:
H = [ 4.2 2 26
2 2.2 ] , F = [ 0 2 ]
1 ′
+ x′ (t)F ′ z + 12 x′ (t)Y x(t)
1 0
cost: 2 z Hz 6 ] , G = −1 0
Y = [ 46 12 0 1
1 0 00 −1
constraints: Gz ≤ W + Sx(t)
W = 11 , S = 00 00
1 00
u x2
x1
x2,k ≥ −1, k = 1
• New QP matrices:
H = [ 4.2 2 26 4 6
2 2.2 ] , F = [ 0 2 ] , Y = [ 6 12 ]
" −1 0 # "1# "0 1#
1 0 1 0 0
G= −1 0 ,W = 1 ,S= 0 0
0 1 1 0 0
0 −1 1 0 0
x1
x2
u x2
x1
• As u(t) = u(t − 1) + ∆u(t) we need to extend the system with a new state
xu (t) = u(t − 1)
(
x(t + 1) = Ax(t) + Bu(t − 1) + B∆u(t)
xu (t + 1) = xu (t) + ∆u(t)
h i h i
x(t+1) x(t)
xu (t+1) = [ A0 BI ] xu (t) + [ BI ] ∆u(t)
h i
x(t)
y(t) = [ C 0 ] xu (t)
• Again a linear system with states x(t), xu (t) and input ∆u(t)
• Add the extra penalty ∥W u (uk − uref (t))∥22 to track input references
• Constraints may depend on r(t), such as emin ≤ yk − r(t) ≤ emax
1.4
1.2
1
• System: y(t) = s2 +0.4s+1 u(t) 1
0.8
d2 y
(or equivalently dt2 + 0.4 dy
dt + y = u) 0.6
0.4
0.2
LTI System
k=0 output
Step
Linear Constrained
Controller
u(t) y(t)
u(t) y(t)
v(t)
• Note that MPC naturally provides feedforward action on v(t) and r(t)
input input
process #1 process #2
u1(t)
r1(t) r2(t)
MPC #1 MPC #2
u1 (t), u1(t+1), …, u1(t+N-1)
• Commands generated by MPC #1 are measured dist. in MPC#2, and vice versa
• Vmin , Vmax = vectors with entries > 0. The larger the i-th entry of vector V , the
relatively softer the corresponding i-th constraint
Albert Einstein
(1879–1955)
x(t) x(t)
x*(t+2|t) x*(t+2|t)
x*(t+1|t)=x(t+1) x*(t+1|t)=x(t+1)
0 t t+N 0 t t+N
x*(t+2|t) x*(t+2|t)
x*(t+1|t)=x(t+1) x*(t+1|t)=x(t+1)
0 t t+N 0 t t+N
x*(t+1|t)=x(t+1)
0 t +1 time
Q = Q′ ⪰ 0, R = R′ ≻ 0, P = P ′ ⪰ 0
• Stability is a complex function of the model (A, B, C) and the MPC parameters
N, Q, R, P, umin , umax , ymin , ymax
• Stability constraints and weights on the terminal state xN can be imposed over
the prediction horizon to ensure stability of MPC
• Hence
0 ≤ x′ (t)Qx(t) + u′ (t)Ru(t) ≤ V ∗ (x(t)) − V ∗ (x(t + 1)) → 0 for t → ∞
• The shifted optimal sequence z̄t+1 = [ut1 . . . utN −1 0]′ (or z̄t+1 = [ut1 ut2 . . .]′ in
case N = ∞) is feasible sequence at time t + 1 and has cost
• As u(t) → 0, also LCAk x(t) → 0, and since L is nonsingular CAk x(t) → 0 too,
for all k = 0, . . . , n − 1
xr = Axr + Bur
(equilibrium state/input)
r = Cxr
• Formulate the MPC problem (assume umin < ur < umax , ymin < r < ymax )
∑
N −1
min (yk − r)′ Qy (yk − r) + (uk − ur )′ R(uk − ur )
k=0
s.t. xk+1 = Axk + Buk
umin ≤ uk ≤ umax , ymin ≤ Cxk ≤ ymax
xN = xr
• Drawback: the approach only works well in nominal conditions, as the input
reference ur depends on A, B, C (inverse static model)
2. End-point constraint xN = 0
(Kwon, Pearson, 1977) (Keerthi, Gilbert, 1988) (Bemporad, Chisci, Mosca, 1994)
All the proofs in (1,2,3) use the value function V ∗ (x(t)) = minz J(z, x(t)) as a
Lyapunov function.
P = A′ P A − A′ P B(B ′ P B + R)−1 B ′ P A + Q
Jacopo Francesco Riccati
(1676–1754)
that is the maximum output admissible set for the closed-loop system
(A + BK, B, C) and constraints umin ≤ Kx ≤ umax , ymin ≤ Cx ≤ ymax
• This makes MPC ≡ constrained LQR where the MPC problem is feasible
• Recursive feasibility in ensured by the terminal constraint for all x(0) such that
the MPC problem is feasible @t = 0
Linearized model:
" # " #
−0.0151 −60.5651 0 −32.174 −2.516 −13.136
−0.0001 −1.3411 0.9929 0 −0.1689 −0.2514
ẋ = 0.00018 43.2541 −0.86939 0 x+ −17.251 −1.5766 u
0 0 1 0 0 0
0 1 0 0
y = 0001 x (Kapasouris, Athans, Stein, 1988)
:); 80*79
• Inputs: elevator and 昀氀aperon (=昀氀ap+aileron) angles /0'$%+1
!"##$%
• Outputs: attack and pitch angles -').,
&'$()*+%,
• Sampling time: Ts = 0.05 sec (+ ZOH) !+''
25◦
• Input constraints umin = −umax = 25◦
30
20
20
15
10
y1 (t) 10
u(t) 0
W y = [ 10 01 ]
y2 (t) 5
-10
-20
0
-30
0 0.5 1 1.5 2 2.5 3 3.5 4 0 0.5 1 1.5 2 2.5 3 3.5 4
30
20
20
15
10
y1 (t) 10
u(t) 0
W y = [ 100 0
0 1]
y2 (t) 5 -10
-20
0
min ρϵ ϵ 2
s.t. y1,min − ϵV1,min ≤ y1 ≤ y1,max − ϵV1,max
20
3
10
y1 (t) 2
u(t) 0
W y = [ 10 01 ]
y2 (t) 1
-10
-20
0
-30
0 0.5 1 1.5 2 2.5 3 3.5 4 0 0.5 1 1.5 2 2.5 3 3.5 4
unstable!
saturation
r(t) ua(t)
linear x(t)
controller process
• MPC takes saturation into account and handles it automatically (and optimally)
saturation
r(t) ua(t)
MPC x(t)
controller process
• weights: the larger the ratio W y /W ∆u the more aggressive the controller
• input horizon: the larger Nu , the more “optimal” but more complex the controller
• prediction horizon: the smaller N , the more aggressive the controller
• constraints horizon: the smaller Nc , the simpler the controller
• limits: controller less aggressive if ∆umin , ∆umax are small
• penalty ρϵ : pick up smallest ρϵ that keeps soft constraints reasonably satis昀椀ed
0
0 1 2 3 4 5 6
time (s)
du
• Slew-rate constraints u̇min ≤ dt ≤ u̇max on actuators are related to Ts by
∆u ∆umax
du uk − uk−1 z }|min{ z }| {
u̇ ≜ ≈ Ts u̇min ≤ ∆uk ≤ Ts u̇max
dt Ts
• Hence, when changing the sampling time from T1 to T2 , can can keep the same
MPC cost function by leaving W y , W u unchanged and simply rescaling
W u̇ T1 W u̇ T1 ∆u ρϵ T 1 ρϵ T1
W2∆u = = = W1 ρϵ2 = = = ρϵ1
T2 T2 T1 T2 T2 T2 T1 T2
• Example:
• Ideally all variables should be in [−1, 1]. For example, one can replace y with
y/ymax
x(t)
Observer
state estimate
• Full state x(t) of process may not be available, only outputs y(t)
• Even if x(t) is available, noise should be 昀椀ltered out
• Prediction and process models may be quite different
• The state x(t) may not have any physical meaning
(e.g., in case of model reduction or subspace identi昀椀cation)
zm(t)
nm(t) m(t) + +
measurement ym(t)
white noise noise model measured
outputs
• Note: the measurement noise model is not used for optimization, as we want
zm to go to its reference, not ym
[ ] [ ][ ]
x(t+1) ABd C̄ 0 x(t) [B ] [B ]
u v
xd (t+1) = 0 Ā 0 xd (t) + 0 u(t) + 0 v(t)+
xm (t+1) xm (t) 0 0
[ 0 ] 0 Ã [0]
Bd D̄
[B ]
u
B̄ nd (t) + 0 nm (t) + 0 nu (t)
0
0 [ B̃ ]
x(t)
ym (t) = [ Cm Ddm C̄ C̃ ] xd (t) + Dvm v(k) + D̄m nd (t) + D̃m nm (t)
xm (t)
• Time update
yk-1 uk
and treat u(t − 1) as an extra state uk-1
ni(t) output
• Use the extended model to design a state observer (e.g., Kalman 昀椀lter) that
ˆ from y(t)
estimates both the state x̂(t) and disturbance d(t)
Theorem
Let the number nd of disturbances be equal to the number ny of measured outputs.
Then all pairs (Bd , Dd ) satisfying
" #
I − A −Bd
rank = nx + n y
C Dd
guarantee zero offset in steady-state (y = r), provided that constraints are not
active in steady-state and the closed-loop system is asymptotically stable.
observable
A Bd
• Add an input integrator: Bd = B , Dd = 0, rank C m Dd = 5 = nx + ny
x(t + 1) =
Ax(t) + B(u(t) + d(t))
d(t + 1) = d(t)
y(t) = Cx(t) + 0 · d(t)
• Idea: add the integral of the tracking error as an additional state (original idea
developed for integral action in state-feedback control)
primal system
x(t)
estimated plant + controller states
B(z)
u(t) = y(t), B(1) ̸= 0
(z − 1)A(z)
• One may think that the ∆u-formulation of MPC provides integral action ...
... is it true ?
• Example: we want to regulate the output y(t) to zero of the scalar system
• Since x(t) = y(t) and u(t) = u(t − 1) + ∆u(t) we get the linear controller
ρβα
1+ρβ 2 z
u(t) = − 1 y(t) No pole in z = 1
z − 1+ρβ 2
• Reason: MPC gives a feedback gain on both x(t) and u(t − 1), not just on x(t)
ans = 0.9000
ans = -6.4185e-16
xr (t + 1) = Ar xr (t)
r(t) = Cr xr (t)
• Design
h i a state observer
h i(e.g., via pole-placement) to estimate x(t), x (t) from
r
y(t) C 0
x(t)
r(t)
= 0 Cr xr (t)
xk
• Design an MPC controller with output ek = yk − rk = [ C −Cr ] xrk
input
2
-1
A= 1 0 0
-3
0 5 10 15 20 25 30 35 40 45 50
h 0.50i 0.125 0
B= 0
0
observer poles placed in
C = [ 0.1349 0.0159 −0.1933 ]
{0.3, 0.4, 0.5, 0.6, 0.7}
Ar =
1.7552 −1 sample time Ts = 0.5 s
1 0
Cr = [ .2448 .2448 ] input saturation −2 ≤ u(t) ≤ 2
– …
• Prediction models can be generated by the Identi昀椀cation Toolbox or
automatically linearized from Simulink
>> mpclib
0 1 0 0
− kθ kθ 0
JL − βJL
L
ρJL
0
0 [ θL ]
ẋ = 0 0 0 1 x + V
θ̇L
0 x= θM
kT θ̇M
2
kθ βM +kT /R
ρJM
0 − ρ2kJθ − JM
RJM
[ ] M
θL = 1 0 0 0 x y=
[θ ]
L
T
[ ]
T = kθ 0 − kρθ 0 x
|V | ≤ 220 V
• Finite shear strength τadm = 50N/mm2 requires that the torsional torque T
satis昀椀es the constraint
|T | ≤ 78.5398 N m
• Sampling time of model/controller: Ts = 0.1s
>> MV = struct('Min',-220,'Max',220);
>> OV = struct('Min',{-Inf,-78.5398},'Max',{Inf,78.5398});
>> Ts = 0.1;
R
µM Tr
V e µ
JM s T µL
bM r JL
bL
closed-loop
simulation in
Simulink
3 300
2 50 200
1 100
0 0 0
-1 -100
-2 -50 -200
-3 -300
-4 -100 -400
0 5 10 15 20 0 5 10 15 20 0 5 10 15 20
1/Iyy 1 1 Theta
My s Thetadot s Theta
1/(Body Inertia) THETAdot THETA
Pitch moment
induced by
vehicle acceleration Thetadot
al1 sign
-Front Pitch Moment Rear Pitch Moment
1/Mb 1 1 Z+h
s Zdot s Z Z+h
1/(Body Mass) Zdot Z
-9.81
Zdot
acceleration Zdot
due to gravity
cm
1000 al1 100
mo
Theta
Gain4 Gain2
uf
1/1000
ur mv MPC ref y0
1000
reference Gain5
Gain3 al1
md al2 100
Open-loop
2
z_ (cm/s)
Closed-loop
4 0
2 -2
0 -4
Open-loop
Closed-loop
-2 -6
0 2 4 6 8 10 0 2 4 6 8 10
0
100
-20
50
-40
0
-60
-50 -80
0 2 4 6 8 10 0 2 4 6 8 10
60
-5
40
-10
20
0 -15
0 2 4 6 8 10 0 2 4 6 8 10
u(t)
MPC
^
x(t) r(t)
i.e., the MPC law coincides with Kd when the constraints are inactive
• Recall that the QP matrices are H = 2(R̄ + S̄ ′ Q̄S̄), F = 2S̄ ′ Q̄T̄ , where
Q 0 0 ... 0
R 0 ... 0 B 0 ... 0
A
0 Q 0 ... 0
0 R ... 0 AB B ... 0 A2
. . . . . .. ..
Q̄ = . . . . . , R̄ = .. .. . . .. , S̄ = . . .. , T̄ = ..
. . . . . . . . . . . . . .
0 ... 0 Q 0 0 ... 0 R AN −1 B AN −2 B ... B AN
0 0 ... 0 P
10
0
y
210
220
0 2 4 6 8 10 12 14 16 18 20
t
50 matched MPC
25
u1
225
250
0 2 4 6 8 10 12 14 16 18 20
t
y2
240
260
instability! 250
0 2 4 6 8 10
t
12 14 16 18 20
( x ∈ Rn
xk+1 = Axk + Buk
• Linear prediction model: u ∈ Rm
yk = Cxk
y ∈ Rp
• Constraints to enforce:
(
umin ≤ u(t) ≤ umax
ymin ≤ y(t) ≤ ymax
ymin ≤ yk ≤ ymax , k = 1, . . . , N
ϵxk ≥ Qi xk i = 1, . . . , n
ϵxk ≥ −Qi xk k = 0, . . . , N − 1
ϵxk ≥ ∥Qxk ∥∞
ϵuk ≥ R i uk i = 1, . . . , m
ϵuk ≥ ∥Ruk ∥∞
ϵuk ≥ −Ri uk k = 0, . . . , N − 1
ϵxN ≥ ∥P xk ∥∞
ϵxN ≥ P i xN i = 1, . . . , n
ϵxN ≥ −P i xN
• Example:
minx |x| → minx,ϵ ϵ
s.t. ϵ ≥ x
ϵ ≥ −x
• Optimization problem:
V (x0 ) = min [1 . . . 1 0 . . . 0]z (linear objective)
z
• optimization vector: z ≜ [ϵu0 . . . ϵuN −1 ϵx1 . . . ϵxN u′0 , . . . , u′N −1 ]′ ∈ RN (nu +2)
s.t. gk (xk , uk ) ≤ 0, k = 0, . . . , N − 1
gN (xN ) ≤ 0
÷
minϵ,x ϵ
ϵ ≥ a′1 x + b1
ϵ ≥ a′ x + b
2 2
s.t.
ϵ ≥ a′3 x + b3
ϵ ≥ a′4 x + b4
x
• Small-signal response, however, is usually less smooth with LP than with QP,
because in LP an optimal point is always on a vertex
LP optimizer QP optimizer
always on a same feasible set may lie
vertex anywhere
( )
Gz ≤ W + Sx
z: {z : Gz ≤ W + Sx}
Ḡz + Ēϵ ≤ W̄ + S̄x
ϵ = additional slack variables introduced
to represent convex PWA costs