Professional Documents
Culture Documents
Alberto Bemporad
http://cse.lab.imtlucca.it/~bemporad
Course structure
• Linear model predictive control (MPC)
• Linear time-varying and nonlinear MPC
• MPC computations: quadratic programming (QP), explicit MPC
• Hybrid MPC
• Stochastic MPC
• Data-driven MPC
MATLAB Toolboxes:
– MPC Toolbox (linear/explicit/parameter-varying MPC)
– Hybrid Toolbox (explicit MPC, hybrid systems)
Course page:
http://cse.lab.imtlucca.it/~bemporad/mpc_course.html
model-based optimizer
process
c x0
+
x
r(t) y(t)
Ax Q
b
u(t)
2 x0
1
in
m
s.t.
measurements
simplified likely
Use a dynamical model of the process to predict its future
evolution and choose --------------------
the “best” control action
a good
• At each time t:
– get new measurements to update the estimate of the current state x(t)
– solve the optimization problem with respect to {u0 , . . . , uN −1 }
– apply only the first optimal move u(t) = u∗0 , discard the remaining samples
• Industrial
Table 6
survey of MPC applications conducted in mid 1999
Summary of linear MPC applications by areas (estimates based on vendor survey; estimates do not include applications by companies who have
licensed vendor technology)a
dynamic optimizer
•coordinate multiple inputs
r(t) MPC •performance optim.
predicted outputs
uk
manipulated inputs •constraints handling
t t+k t+N
regulators
•fast-sampling
low-level controllers
•single-loop
Powertrain
Ford Motor Company
engine control, magnetic actuators, robotized gearbox, Jaguar
power MGT in HEVs, cabin heat control, electrical motors
DENSO Automotive
FCA
Vehicle dynamics General Motors
traction control, active steering, semiactive suspensions,
autonomous driving
suspension deflection
suspension tire
deflection
deflection
tire deflection
4
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
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 flows
17 mixing nodes
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 )
se tup real-time
system PC
e M code
identification r evis
/* 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
• Price to pay:
Requires a (simple) model (experiments + system identification, linearization, …)
Many design/calibration knobs (weights, horizon, constraints, …)
Requires real-time computations to solve the optimization problem
x ∈ Rn , f : Rn → R, g : Rn → Rm
( )
g(x) 0
x
maxx f (x)
s.t. g(x) ≤ 0
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 S
• Every local solution is also a global one (we will see this later)
P = {x ∈ R : Ax ≤ b} n
v3
v1 A
1 x=
b1
A3x=b3 A3
• Vertex (V-)representation:
∑
q ∑
p Convex hull = transformation
P = {x ∈ Rn : x = αi vi + βj rj } from V- to H-representation
i=1 i=1
Vertex enumeration =
∑ q
αi , βj ≥ 0, αi = 1, vi , rj ∈ R n
transformation from H- to
i=1
V-representation
when q = 0 the polyhedron is a cone
vi = vertex, rj = extreme ray
©2018 A. Bemporad - "Model Predictive Control" 30/120
Linear programming
• Linear programming (LP) problem: -f
min c′ x Ax b
x*
s.t. Ax ≤ b, x ∈ Rn
George Dantzig
(1914–2005)
′ c0x = constant
• LP in standard form: min cx
s.t. Ax = b
x ≥ 0, x ∈ Rn
1 x0 Qx + c0 x = constant
2
• Many good solvers are available (CPLEX, Gurobi, GLPK, Xpress-MP, 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)
{ x ∈ Rn Notation:
xk+1 = Axk + Buk x0 = x(t)
u ∈ Rm
yk = Cxk xk = x(t + k|t)
y ∈ Rp
uk = u(t + k|t)
∑
k−1
• Relation between input and states: xk = Ak x0 + Aj Buk−1−j
j=0
• Performance index
u0
N∑−1 R = R′ ≻0 u1
J(z, x0 ) = ′
xN P x N + x′k Qxk +u′k Ruk Q = Q′ ≽0 z= ..
′ .
k=0 P = P ≽0 uN −1
• Goal: find 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 + x0 Qx0
1 ′ ′ ′ ′ 1 ′ ′
= z 2(R̄ + S̄ Q̄S̄) z + x0 2T̄ Q̄S̄ z + x0 2(Q + T̄ Q̄T̄ ) x0
2 | {z } | {z } 2 | {z }
H F′ Y
∇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
. 1 x0 Hx + x0 F 0 z = constant
uN −1 <latexit sha1_base64="b7JBH2VbNQDHy5RJb0IpdUH5nqY=">AAABanicZY3LSsNAFIZP6q3GS2NdSTelDURQQqYbV0JVkC4r2MuiEibT0zJ0MhMyU4mG7H0at/oqvoMPYdVstN/q4/znnD9KBNcmCD6sysbm1vZOddfe2z84rDlH9aFWy5ThgCmh0nFENQoucWC4EThOUqRxJHAULW6+89EjpporeW+eEnyI6VzyGWfUrEah03Ins5SynBR5p8i8XnaWebfes9u8bDIltaHShE478IMfmutCSmlDST90yGSq2DJGaZigWuda8Cnqwp4sNSaULegc86vr0GCWKC5NYdurDvL/47oMOz4JfHLXaXfPy7YqNKAFp0DgArrQgz4MgMELvMIbvMOnVbdOrMbvasUqb47hD5b7BbdWWQo=</latexit>
sha1_base64="hD002KlkFC0iEVl8Of2x4ceQYJM=">AAABanicZY3LTsJAFIZP8Yb1VtGNYUNoE0w0TYeNKxPUxLDERC4LTDMdDmTCMNN0pqbadO/TuNVX8R18CBHYKN/qy/nPOX8UC65NEHxZpY3Nre2d8q69t39weOQcV3papQnDLlNCJYOIahRcYtdwI3AQJ0hnkcB+NL37zfvPmGiu5KN5ifFpRieSjzmjZj4Knbo3HCeU5aTIm0XWaGcXWeO+8erVrmtMSW2oNKHjBn6woLYuZCVu6xQWdEKHDEeKpTOUhgmqda4FH6Eu7GGqMaZsSieY39yGBrNYcWkK2553kP8f16XX9Engk4em27pclkEZqlCHcyBwBS1oQwe6wOAN3uEDPuHbqlhnVnW5WrJWNyfwB8v7AfSeWV4=</latexit>
2
∑
k−1
• Output constraints yk = CA x0 + k
CAi Buk−1−i ≤ ymax , k = 1, . . . , N
i=0
CB 0 ... 0 ymax CA
CAB CB ... 0 ymax CA2
z ≤ . − . x0
.. .. . .
. . . .
CAN −1 B ... CAB CB ymax CAN
t t+k t+N
• Constraints: −1 ≤ u(t) ≤ 1
(∑ )
+ x′2 [ 10 01 ] x2
1 2 1 2
• Performance index: min k=0 yk + 10 uk
• QP matrices:
H = [ 4.2 2 26
2 2.2 ] , F = [ 0 2 ]
1 ′ [ 1 0 ]
cost: 2 z Hz + x′ (t)F ′ z + 12 x′ (t)Y x(t) 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)
[ ] [ ]
x(t+1)
[ A0 BI ] xx(t)
= + [ BI ] ∆u(t)
xu (t+1) [ u (t)]
y(t) = [ C 0 ] xx(t)
u (t)
• Again a linear system with states x(t), xu (t) and input ∆u(t)
1 ′
min J(z, x(t)) = + [x′ (t) r′ (t) u′ (t − 1)]F ′ z
z Hz
z 2
convex
x(t) Quadratic
s.t. Gz ≤ W + S r(t)
u(t − 1)
Program
• 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
2
d y
(or equivalently dt2 + 0.4 dy
dt + y = u) 0.8
0.6
0.4
• Sampling
{ with period Ts = 0.5 s: 0.2
[ 1.597 −0.8187 ] 0.5
x(t + 1) = 1 0 x(t) + [ 0 ] u(t) 00 10 20 30
y(t) = [ 0.2294 0.2145 ] x(t)
LTI System
k=0 output
Step
Linear Constrained
Controller
u(t) y(t)
u(t) y(t)
use r(t)
use r(t) use r(t+k)
use r(t+k)
∑
τ −1
x̄(t) = x̂(t + τ ) = Aτ x(t) + Aj B u(t − 1 − j)
| {z }
j=1
past inputs!
D E OFF
TRA
– Simple enough for solving the optimization problem
Albert Einstein
(1879–1955)
x(t)
x*(t+2|t)
x*(t+1|t)=x(t+1)
0 t t+N
x(t)
x*(t+2|t)
x*(t+1|t)=x(t+1)
0 t
©2018 A. Bemporad - "Model Predictive Control" t+N 62/120
Predicted and actual trajectories
optimal state x (k)
• Special case: when the horizon is infinite, open-loop
trajectories and closed-loop trajectories coincide.
time
x(t) 0 k N
optimal input u (k)
x*(t+2|t)=x*(t+2|t+1)=x(t+2)
x*(t+1|t)=x(t+1)
0 t +1 time
``An optimal policy has the property that, regardless of the decisions taken to enter
a particular state, the remaining decisions made for leaving that stage must constitute Richard Bellman
Q = Q′ ≽ 0, R = R′ ≻ 0, P = P ′ ≽ 0
• Stability constraints and weights on the terminal state can be imposed over
the prediction horizon to ensure stability of MPC
For general stability results see (Lazar, Heemels, Weiland, Bemporad, 2006)
©2018 A. Bemporad - "Model Predictive Control" 65/120
Convergence proof
Proof: Main idea: use the value function V ∗ (x(t)) as a Lyapunov function
• 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
for t → ∞
• Since R, Qy ≻ 0, also limt→∞ y(t) = 0, limt→∞ u(t) = 0
• For all k = 0, . . . , n − 1 we have that
∑
k−1
0 = lim y ′ (t+k)Qy y(t+k) = lim ∥LC(Ak x(t)+ Aj Bu(t+k −1−j))∥22
t→∞ t→∞
j=0
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.
ymax
• The input horizon Nu limits the number
of free variables yk
– Reduced performance
uk
– Reduced computation time
typically Nu = 1 ÷ 5 t t+Nu t+Nc t+N
P = A′ P A − A′ P B(B ′ P B + R)−1 B ′ P A + Q
Jacopo Francesco Riccati
(1676–1754)
Linearized model:
[ ] [ ]
−0.0151 −60.5651 −32.174 −2.516 −13.136
0
−0.0001 −1.3411 0.9929 −0.1689 −0.2514
ẋ = 0
x+ u
0.00018 43.2541 −0.86939 0 −17.251 −1.5766
0 0 1 0 0 0
[0 1 0 0]
y = 0001 x
:); 80*79
/0'$%+1
• Inputs: elevator and flaperon (=flap+aileron) angles
!"##$%
• Outputs: attack and pitch angles -').,
&'$()*+%,
• Sampling time: Ts = 0.05 sec (+ ZOH) !+''
y(t) 10
u(t) 0
W y = [ 10 01 ]
-10
5
-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
y(t) 10
u(t) 0
W y = [ 100 0
0 1]
5 -10
-20
0
y(t) 10
u(t) 0
W y = [ 10 01 ]
5
-10
0
-20
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
20
3
10
W y = [ 10 01 ]
2
y(t) u(t) 0
-10
1
-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!
v(t)=Kx(t)+Hr(t)
saturation
r(t)
linear u(t) x(t)
controller plant
v(t)=f(x(t),r(t))=u(t)
saturation
r(t)
MPC u(t) x(t)
controller plant
• 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 satisfied
• 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 filtered 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 identification)
zm(t)
nm(t) Measurement m(t) + + ym(t)
noise
white noise model MOs
innovations (Measured Outputs)
[ x(t+1)
] [ ][ x(t)
] [B ] [B ]
ABd C̄ 0 u v
x( t+1) = 0 Ā 0 x( t) + 0 u(t) + 0 v(t)+
xm (t+1) [ 0 ] 0 Ã xm (t)
[0]
0
[B ]
0
Bd D̄ u
B̄ nd (t) + 0 nm (t) + 0 nu (t)
0 [ x(t)
B̃
] 0
• Time update
• This avoids static loops between state observer (x(t|t) depends on u(t)) and
MPC (u(t) depends on x(t|t))
ni(t) Output
white noise Integrators
innovations
• Use the extended model to design a state observer (e.g., Kalman filter) 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 + ny
C Dd
[ 1 −1 −2
1 ] [1]
0 −2 3 2
• Open-loop system: A = 0 2 −1 −1 , B = 01 , Cm = [ 1 1 0 0 ]
0 2 0 −2 1
[ A Bd
]
• Add an input integrator: Bd = B, Dd = 0, rank Cm 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
– …
• Prediction models can be generated by the Identification Toolbox or
automatically linearized from Simulink
• Fast command-line MPC functions
(compiled EML-code)
• Graphical User Interface
• Simulink library (compiled EML-code)
>> mpclib
0 1 0 0
− kθ 0
JL − βJL
L kθ
0 [ θL ]
ρJL
0
ẋ = 0 0 0 1 x + V θ̇L
0 x= θM
kT θ̇M
2
βM +kT /R
kθ
0 − ρ2kJθ − RJM
[ ρJM ] M JM
θL = 1 0 0 0 x [θ ]
y= T
L
[ ]
T = kθ 0 − kρθ 0 x
|V | ≤ 220 V
• Finite shear strength τadm = 50N/mm2 requires that the torsional torque T
satisfies 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;
∑
p−1
min ∥W y (yk+1 − r(t))∥2 + ∥W ∆u ∆uk ∥2 + ρϵ ϵ2
∆U
k=0
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
signal1 signal1
-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 signal1 100
mo
Theta
Gain2
Gain4 uf
1/1000
ur mv MPC ref y0
1000
reference Gain5
Gain3 signal1
md
signal2 100
Open-loop
2
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
MPC
^
x(t) r(t)
i.e., the MPC controller 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 AB B ... 0 A2
. . . . . 0 R ... 0
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
−10
−20
0 2 4 6 8 10 12 14 16 18 20
t
50 matched MPC
25
u1
−25
−50
0 2 4 6 8 10 12 14 16 18 20
t
y2
−40
−60
−80
25
In this case saturating the PID
u2
−50
instability! 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
∑
N −1
min ∥P xN ∥∞ + ∥Qxk ∥∞ + ∥Ruk ∥∞ u0
z
u1
k=0 R, Q, P
z= ..
full rank .
s.t. umin ≤ uk ≤ umax , k = 0, . . . , N − 1 uN −1
ymin ≤ yk ≤ ymax , k = 1, . . . , N
ϵxk ≥ Qi xk i = 1, . . . , n
ϵxk ≥ −Qi xk k = 0, . . . , N − 1
ϵxk ≥ ∥Qxk ∥∞
ϵuk ≥ Ri 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
−1
ℓk , ℓN , gk , gN are arbitrary
∑
N
min ℓN (xN ) + ℓk (xk , uk ) convex piecewise affine (PWA)
U
k=0 functions
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 x + b
3 3
x ϵ ≥ a′4 x + b4
• 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