You are on page 1of 125

Model Predictive Control

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

©2018 A. Bemporad - "Model Predictive Control" 2/120


Model Predictive Control: Basic Concepts
Model Predictive Control (MPC)
optimization
prediction model
algorithm

model-based optimizer
process

set-points inputs outputs

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

©2018 A. Bemporad - "Model Predictive Control" 3/120


Model Predictive Control (MPC)
• Goal: find the best control sequence over a future horizon of N steps
past future r(t)

N −1 yk
min
y
∥W (yk −
2
r(t))∥2
u
+ ∥W (uk −
2
ur (t))∥2 predicted outputs
k=0 uk
s.t. xk+1 = f (xk , uk ) prediction model manipulated inputs
yk = g(xk , uk ) t t+k t+N

umin ≤ uk ≤ umax constraints


ymin ≤ yk ≤ ymax

x0 = x(t) state feedback

optimization problem t+1 t+1+k t+N+1

• 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

©2018 A. Bemporad - "Model Predictive Control" 4/120


Daily-life examples of MPC
• MPC is like playing chess !

• On-line (event-based) re-planning used in GPS navigation

• You use MPC too when you drive !

©2018 A. Bemporad - "Model Predictive Control" 5/120


MPC in industry
• The MPC concept for process control dates back to the 60’s

(Rafal, Stevens, AiChE Journal, 1968)

• MPC used in the process industries since the 80’s


(Qin, Badgewell, 2003) (Bauer, Craig, 2008)

MPC is the standard for advanced control in the process industry

• Research in MPC is still very active !

©2018 A. Bemporad - "Model Predictive Control" 6/120


MPC in industry
(Qin, Badgewell, 2003)
S.J. Qin, T.A. Badgwell / Control Engineering Practice 11 (2003) 733–764 745

• 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

Area Aspen Honeywell Adersab Invensys SGSc Total


Technology Hi-Spec

Refining 1200 480 280 25 1985


Petrochemicals 450 80 — 20 550
Chemicals 100 20 3 21 144
Pulp and paper 18 50 — — 68
Air & Gas — 10 — — 10
Utility — 10 — 4 14
Mining/Metallurgy 8 6 7 16 37
Food Processing — — 41 10 51
Polymer 17 — — — 17
Furnaces — — 42 3 45
Aerospace/Defense — — 13 — 13
Automotive — — 7 — 7
Unclassified 40 40 1045 26 450 1601
Total 1833 696 1438 125 450 4542
First App. DMC:1985 PCT:1984 IDCOM:1973
IDCOM-M:1987 RMPCT:1991 HIECON:1986 1984 1985
OPC:1987
Largest App. 603 ( 283 225 ( 85 — 31 ( 12 —
a
The numbers reflect a snapshot survey conducted in mid-1999 and should not be read as static. A recent update by one vendor showed 80%
increase in the number of applications.
b
Adersa applications through January 1, 1996 are reported here. Since there are many embedded Adersa applications, it is difficult to accurately
Estimates based
report their number on vendor
or distribution. survey
Adersa’s product literature indicates over 1000 applications of PFC alone by January 1, 1996.
c
The number of applications of SMOC includes in-house applications by Shell, which are unclassified. Therefore, only a total number is estimated
here.

©2018 A. Bemporad - "Model Predictive Control"


Nonlinear The PFC algorithm can be used with several different7/120
model types. The most general of these is a discrete-time
MPC in industry
M. Bauer, I.K. Craig / Journal of Process Control 18 (2008) 2–18 5
(Bauer, Craig, 2008)
• EconomicM.assessment
Petrochemical
of Advanced
North America
Process Control (APC) 5
Bauer, I.K. Craig / Journal of Process Control 18 (2008) 2–18

Chemicals Petrochemical North America


Africa
leum refining Chemicals Africa
Europe
Petroleum refining
alsprocessing Europe
Asia Pacific
Mineralsprocessing
Oil & Gas Asia Pacific
South America
Oil & Gas
wer & utilities South America
Power & utilities 0% 10% 20% 30%
Pulp & paper 0% M. Bauer,
10% 20%I.K. 30%
Craig / Journal of Process Control 18 (2008) 2–18
Pulp & paper M. Bauer, I.K. Craig / Journal of Process Control 18 (2008) 2–18
dustrial gases
Industrial gases
Coal products Suppliers Model predictive control Standard
Coal products Suppliers Model predictive control Standard
& wastewater Users Constraint control Frequently
Water & wastewater Users Constraint control Frequently
Other Split-range controlcontrol Rarely
Rarely
Other Split-range
Linear programming (LP) (LP) Never
Never
0% 20%0% 40%
20% 60%
40% 80%
60% 100%
80% 100%
Linear programming
Don't
Don'tknow
know
Nonlinear control control
Nonlinear algorithms or models
algorithms or models
ofParticipants
APC survey by industry
of APC andindustry
survey by by continent
and by (total: 66 (total:
continent participants). Several Several
66 participants). answersanswers
were allowed for industry
were allowed sectors.
for industry sectors.
participants of APC survey by industry (worldwide) Dead-time compensation
Dead-time compensation
entify the respondent
espondent and captureandthe
capture thethe
size of size of the the estimation
the estimation of qualitative,
of qualitative, non-monetary
non-monetary
Statistical
Statistical process benefits
controlcontrolbenefits
process
well
use asof the use oftechnology
control control technology
within thewithin (15%)
the as (15%)
well asaswell
rulesasof rules of thumb
thumb [47], such ascontrol
that a new
con-con-
Neural [47],
Neuralsuch
networksnetworks
basedascontrol
that
based a new
on.
ird The thirdqueries
section sectionthe
queries the APC
use of use of APC trol scheme
trol scheme will increase
will increase the throughput
the throughput bybaseda by
fixeda fixed percent-
Expert Expert system
system based control controlpercent-
y. and tools.four
Sections Sections four
to six aretokey
six to
arethe
key to age ageFor
the (7%). (7%). theFor the water
water and
and waste-water waste-water industries,
industries, LantLant
Fuzzy logic control
assessment process. While Section four covers and Steffens [48] provide a qualitative self-assessment form
Fuzzy logic control
process. While Section four covers and Steffens [48] provide a qualitative self-assessment form
erial process by asking about reporting, decision to establish how goodInternal Internal model
the process controlcontrolis.(IMC)
The disadvan-
ss by asking about reporting, decision to establish how good the process model
controlcontrol is.(IMC)
The disadvan-
nd budgeting, Section five is concerned with the tage of such a table is that Adaptive it is industry
/ selftuningrelated
control and has to
g, Section five is concerned with the
g process and the estimation of cost and benefits.
tage of besuch a table is that Adaptive
it is industry
updated with the development / selftuning
of
related
new
and has to
controltechnologies.
Directsynthesis (DS)
nd the estimation
x requests of cost and
the respondents opinion about be
benefits. theupdated The with the development
questionnaire of new
resultsDirectsynthesis
support technologies.
the(DS)industry–univer-
the respondents
mportance opinionwith
and satisfaction about the
the current esti-The sity
questionnaire
study by Marlin results andsupport the industry–univer-
co-workers [49], which 0% 20%
high- 40% 60% 80% 100%
and satisfaction withasthe current esti- 0% 20% 40% 60% 80% 100%
ocess in place as well about future trends.sity study by the
lighted Marlin and co-workers
importance of determining [49], which
the
Fig. 4. Industrial
high-
base
use ofcase
APC methods: survey results.
ce as well as about future trends. lighted operation
the importance of determining
through in-depth analysis the base
use ofcase
of historical
Fig. 4. Industrial plant
APC methods: survey results.
ork – the engineering process operationdata.through
An important in-depth
Industrial useanalysis
consideration
of APC methods: of historical
for thesurvey
base resultsplant
case identi-
data.point
An closer
fication to then
is
important a limitthe by Dl, see
xLselection
consideration ofFig.
for the5,
the [43].case
appropriate
base The identi-
reduc-
process mance that is expected from the new
ngineering process
estimate of the performance that will result point tionvariables
closer
fication
from in
tovariance
is a limit
then from
the xisLselection
often
by Dl,
which assumed
see
theofFig. to5,be
variance
the aisfixed
[43].
appropriate The percentage.
reduc-
estimated. Latour
process Pb after
mance av .that
This is
improvement can be the
expected from expresse
new
©2018 A. Bemporad - "Model Predictivetion Control"Several industrial andtheacademicto beauthors assume reduc- b after
avariables: computed from the variance reduction8/120 a
process control requires
the performance process
that will insight
result in
as variance
fromas wellvariables [19]from is often
whichassumed
recommends the analysis
variance ofaisfixed
the percentage.
following
estimated. Latour P av . This improvement can be expresse
anding of the control technology. Seven steps Severalof tion of the and
industrial standard deviation
academic authors by 50% assume [19,61–63]
a reduc- or by computed
system and froma minimum achievable
the variance reductionvaria
a
d 23 stantial benefits in each of several (or discovery), we still have noth-
MPC in industry
ding
y of
industry sectors; adoption by
ma ny companies in different sec-
ing that compares with PID! It’s also
concerning that the “crown jewels”
with, tors; standard practice in industry. of control theory appear near the bot-
(Samad, IEEE CS Magazine, 2017)
y; all » High single-industry impact: Sub- tom of the list. However, the fact that
y in- stantial benefits in one industry all the technologies had at least some
e re- sector; adoption by many compa- positive assessments suggests that the

stry,
Impact of advanced control technologies in industry
gov-
ence TABLE 1 A list of the survey results in order of industry impact as perceived by
ctors the committee members.
ence
Rank and Technology High-Impact Ratings Low- or No-Impact Ratings
pace,
cals, PID control 100% 0%
dical, Model predictive control 78% 9%
geo- System identification 61% 9%
with Process data analytics 61% 17%
d all Soft sensing 52% 22%
f the
Fault detection and 50% 18%
C na- identification
ech-
Decentralized and/or 48% 30%
coordinated control
, the
Intelligent control 35% 30%
nter-
Discrete-event systems 23% 32%
any
ease Nonlinear control 22% 35%
.org. Adaptive control 17% 43%
Robust control 13% 43%
Hybrid dynamical systems 13% 43%

©2018 A. Bemporad - "Model Predictive Control" 9/120


FEBRUARY 2017 « IEEE CONTROL SYSTEMS MAGAZINE 17
Typical use of MPC
static optimizer
Steady-state •(economic) set-point
optimization optimization

•static I/O model

output set points and


corresponding optimal actuator set points

dynamic optimizer
•coordinate multiple inputs
r(t) MPC •performance optim.
predicted outputs
uk
manipulated inputs •constraints handling
t t+k t+N

measurements set points to actuators

regulators
•fast-sampling
low-level controllers
•single-loop

©2018 A. Bemporad - "Model Predictive Control" 10/120


Automotive applications of MPC
(Bemporad, Bernardini, Borrelli, Cimini, Di Cairano, Esen, Giorgetti, Graf-Plessen, Hrovat, Kolmanovsky
Levijoki, Ripaccioli, Trimboli, Tseng, Yanakiev, ... (2001-present))

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

Model predictive control toolset 1 / 8

suspension deflection

suspension tire
deflection
deflection

tire deflection

 4

Most automotive OEMs are looking into MPC solutions today


4

©2018 A. Bemporad - "Model Predictive Control" 11/120


MPC for autonomous driving

• Coordinate torque request and steering to achieve safe and


comfortable autonomous driving with no collisions

• MPC combines path planning, path tracking, and obstacle


avoidance

• Stochastic prediction models are used to account for uncertainty


and driver’s behavior

©2018 A. Bemporad - "Model Predictive Control" 12/120


MPC of gasoline turbocharged engines
• Control throttle, wastegate, intake & exhaust cams to make engine torque
track set-points, with max efficiency and satisfying constraints
MPC Engine

Desired Actuators Achieved


torque commands Torque

Measurements

QP solved in real-time on ECU

(Bemporad, Bernardini, Long, Verdejo, 2018)

engine operating at low pressure (66 kPa)


©2018 A. Bemporad - "Model Predictive Control" 13/120
Supervisory MPC of powertrain with CVT

• Coordinate engine torque request and continuously variable transmission


(CVT) ratio to improve fuel economy and drivability

• 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)

©2018 A. Bemporad - "Model Predictive Control" 14/120


MPC is in automotive production right now !
The MPC developed by General Motors and ODYS for torque tracking
in turbocharged gasoline engines is in production since fall 2018.

• Multivariable system, 4 inputs, 4 outputs.


QP solved in real time on ECU
(Bemporad, Bernardini, Long, Verdejo, 2018)

• Supervisory MPC for powertrain control


also scheduled for production
(Bemporad, Bernardini, Livshiz, Pattipati, 2018)

First known mass production of MPC in the automotive industry

http://www.odys.it/odys-and-gm-bring-online-mpc-to-production

©2018 A. Bemporad - "Model Predictive Control" 15/120


Model predictive control toolset 1 / 8

Aerospace applications of MPC


• MPC capabilities explored in new space applications

cooperating UAVs powered descent planetary rover

  
(Bemporad, Rocchi, 2011) (Pascucci, Bennani, Bemporad, 2016) (Krenn et. al., 2012)

©2018 A. Bemporad - "Model Predictive Control" 16/120


MPC In Aeronautic Industry

http://www.pw.utc.com/Press/Story/20100527-0100/2010

©2018 A. Bemporad - "Model Predictive Control" 17/120


MPC for Smart Electricity Grids
(Patrinos, Trimboli, Bemporad, 2011)
transmission grid

coal 1 ? ?
photovoltaic
coal 2

? ? ? hydro-storage

? ? ?
demand
natural gas

? ? ? wind farm

Dispatch power in smart distribution grids, trade energy on energy markets

Challenges: account for dynamics, network topology, physical constraints,


and stochasticity (of renewable energy, demand, electricity prices)
FP7-ICT project “E-PRICE - Price-based Control of Electrical Power Systems”
(2010-2013)
©2018 A. Bemporad - "Model Predictive Control" 18/120
MPC of drinking water networks
(Sampathirao, Sopasakis, Bemporad, Patrinos, 2017)

Drinking water
network of
Barcelona:

63 tanks
114 controlled flows
17 mixing nodes

• ≈5% savings on energy costs w.r.t. current practice


• Demand and minimum pressure requirements met, smooth control actions
• Computation time: ≈20 s on NVIDIA Tesla 2075 CUDA (sample time = 1 hr)
FP7-ICT project “EFFINET - Efficient Integrated Real-time Monitoring and Control of Drinking Water Networks”
(2012-2015)
©2018 A. Bemporad - "Model Predictive Control" 19/120
MPC for dynamic hedging of financial options
(Bemporad, Bellucci, Gabbriellini, Quantitative Finance, 2014)

• Goal: find a dynamic hedging policy of a portfolio replicating a synthetic


option, so to minimize risk that payoff̸=portfolio wealth at expiration date

• A simple linear stochastic model describes the dynamics of portfolio wealth

• Stochastic MPC results:


Portfolio wealth vs. payoff at expiration Portfolio wealth vs. payoff at expiration
100 0.2

80
0.15

Final wealth in portfolio


60
0.1

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 )

European call Napoleon cliquet


©2018 A. Bemporad - "Model Predictive Control" 20/120
MPC research is driven by applications

• Process control → linear MPC (some nonlinear too) 1970-2000

• Automotive control → explicit, hybrid MPC 2001-2010

• Aerospace systems and UAVs → linear time-varying MPC >2005

• Information and Communication Technologies (ICT)


(wireless nets, cloud) → distributed/decentralized MPC >2005

• Energy, finance, automotive, water → stochastic MPC >2010

• Industrial production → embedded optimization solvers for MPC today

©2018 A. Bemporad - "Model Predictive Control" 21/120


MPC design flow
High-fidelity simulation model performance index
(simplified) control-oriented
prediction model & constraints
u y
G(z)

closed-loop simulation MPC


design
physical modeling +
parameter estimation

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

©2018 A. Bemporad - "Model Predictive Control" 22/120


MPC toolboxes

• MPC Toolbox (The Mathworks, Inc.): (Bemporad, Ricker, Morari, 1998-today)

– Part of Mathworks’ official toolbox distribution


– Great for education and research

• Hybrid Toolbox: (Bemporad, 2003-today) 7200 downloads


– Free download: http://cse.lab.imtlucca.it/~bemporad/hybrid/toolbox 1.5 downloads/day
– Great for research and education

• ODYS MPC Toolbox: (Bemporad, Bernardini, Cimini 2013-present)

– Flexible and customized MPC design and seamless integration


in production systems
– Real-time MPC code and QP solver written in plain C
– Supports (multiple) linear and linear time-varying models Model predictive control toolset 1 / 8

– Designed for industrial production

©2018 A. Bemporad - "Model Predictive Control" 23/120


Pros and cons of MPC

N −1
y 2
• Extremely flexible control design approach: min ∥W (yk − r(t))∥2
k=0
+∥W u (uk − ur (t))∥22
 Prediction model: multivariable, w/delays,
s.t. xk+1 = f (xk , uk )
time-varying, uncertain, stochastic, nonlinear, …
yk = g(xk , uk
 Handles constraints on inputs and outputs h(uk , xk , yk ) ≤ 0
 Can exploit preview on future references
and measured disturbances
 Tuning similar to LQR (Linear Quadratic Regulator)
 Mature offline design tools and real-time code are available

• 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

©2018 A. Bemporad - "Model Predictive Control" 24/120


Basics of Constrained Optimization
Mathematical programming
minx f (x)
s.t. g(x) ≤ 0 f(x)

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 )

In general, the problem is difficult to solve use software tools

©2018 A. Bemporad - "Model Predictive Control" 25/120


Optimization software
• Comparison on benchmark problems:
http://plato.la.asu.edu/bench.html

• Taxonomy of many solvers for different classes of optimization problems:


http://www.neos-guide.org

• NEOS server for remotely solving optimization problems:

http://www.neos-server.org

• Good open-source optimization software:

http://www.coin-or.org/

• GitHub , MATLAB Central , Google , ...

©2018 A. Bemporad - "Model Predictive Control" 26/120


Convex sets
Definition
A set S ⊆ Rn is convex if for all x1 , x2 ∈ S

λx1 + (1 − λ)x2 ∈ S, ∀λ ∈ [0, 1]

convex set
nonconvex set

S S

©2018 A. Bemporad - "Model Predictive Control" 27/120


Convex functions
Definition
f : S → R is a convex function if S is convex and
f (λx1 + (1 − λ)x2 ) ≤ λf (x1 ) + (1 − λ)f (x2 )
Jensen’s inequality
∀x1 , x2 ∈ S, λ ∈ [0, 1]

©2018 A. Bemporad - "Model Predictive Control" 28/120


Convex optimization problem
The optimization problem
min f (x)
s.t. x ∈ S

is a convex optimization problem if S is a convex set S


and f : S → R is a convex function

• Often S is defined by linear equality constraints Ax = b and convex


inequality constraints g(x) ≤ 0, g : Rn → Rm convex

• Every local solution is also a global one (we will see this later)

• Efficient solution algorithms exist

• Often occurring in many problems in engineering, economics, and science

Excellent textbook: “Convex Optimization” (Boyd, Vandenberghe, 2002)

©2018 A. Bemporad - "Model Predictive Control" 29/120


Polyhedra
Definition
Convex polyhedron = intersection of a finite set of half-spaces of Rn
Convex polytope = bounded convex polyhedron
v3
b 2
x=
A2
• Hyperplane (H-)representation: v2 A
A2 1

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

• Conversion to standard form by introducing slack variables


 n  n
 ∑  ∑
 aij xj ≤ bi  aij xj + si = bi

 j=1
  j=1

xj ≥ 0 si , xj ≥ 0

• Nonnegative variables by splitting positive and negative part of x


 n  n
 ∑  ∑
 aij xj = bi  + −
aij (xj − xj ) = bi



j=1  j=1
 + −
xj free x j , xj ≥ 0
©2018 A. Bemporad - "Model Predictive Control" 31/120
Linear programming (LP)
• Converting maximization to minimization

max c′ x = −(min −c′ x)


x x

• Equalities to double inequalities (not recommended)


{ ∑
∑n n
aij xj ≤ bi
aij xj = bi ⇒ ∑j=1
n
j=1 j=1 aij xj ≥ bi

• Change direction of an inequality



n ∑
n
aij xj ≥ bi ⇒ −aij xj ≤ −bi
j=1 j=1

An LP can be always formulated using “min” and “≤”

©2018 A. Bemporad - "Model Predictive Control" 32/120


Quadratic programming (QP)

• Quadratic programming (QP) problem:


1 ′
min x Qx + c′ x
2 Ax  b
s.t. Ax ≤ b, x ∈ Rn
x*

1 x0 Qx + c0 x = constant
2

• Convex optimization problem if Q ≽ 0 (Q = positive semidefinite matrix) 1

• Hard problem if Q ̸≽ 0 (Q = indefinite matrix)

1 A matrix P ∈ Rn×n is positive semidefinite (P ≽ 0) if x′ P x ≥ 0 for all x.

It is positive definite (P ≻ 0) if in addition x′ P x > 0 for all x ̸= 0.


It is negative (semi)definite (P ≺ 0, P ≼ 0) if −P is positive (semi)definite.
It is indefinite otherwise.

©2018 A. Bemporad - "Model Predictive Control" 33/120


Mixed-integer programming (MIP)
1 ′
min c′ x min x Qx + c′ x
2
s.t. Ax ≤ b, x = [ xxcb ] s.t. Ax ≤ b, x = [ xxcb ]
xc ∈ Rnc , xb ∈ {0, 1}nb xc ∈ Rnc , xb ∈ {0, 1}nb
mixed-integer linear program (MILP) mixed-integer quadratic program (MIQP)

• Some variables are real, some are binary (0/1)

• A N P-hard problem, in general

• Many good solvers are available (CPLEX, Gurobi, GLPK, Xpress-MP, CBC, ...)
For comparisons see http://plato.la.asu.edu/bench.html

©2018 A. Bemporad - "Model Predictive Control" 34/120


Modeling languages for optimization problems
• AMPL (A Modeling Language for Mathematical Programming) most used
modeling language, supports several solvers

• OPL (Optimization Programming Language), associated with commercial


package IBM-CPLEX

• MOSEL associated with commercial package FICO Xpress

• GAMS (General Algebraic Modeling System) is one of the first modeling


languages

• LINGO modeling language of Lindo Systems Inc.

• GNU MathProg a subset of AMPL associated with the free package GLPK
(GNU Linear Programming Kit)

• FLOPC++ open source modeling language (C++ class library)

©2018 A. Bemporad - "Model Predictive Control" 35/120


Modeling languages for optimization problems

• YALMIP MATLAB-based modeling language

• CVX (CVXPY) Modeling language for convex problems in MATLAB ( )

• PYOMO -based modeling language

• PICOS A interface to conic optimization solvers

• PuLP An linear programming modeler for

• JuMP A modeling language for linear, quadratic, and nonlinear constrained


optimization problems embedded in

©2018 A. Bemporad - "Model Predictive Control" 36/120


Linear MPC
Linear MPC - Unconstrained case
• Linear prediction model

{ 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

©2018 A. Bemporad - "Model Predictive Control" 37/120


Computation of cost function

z }| {
 x1
′   x1

Q 0 0 ... 0
 x2   0 Q 0 ... 0  x2 
    
′  .   . . . .  . 
J(z, x0 ) = x0 Qx0 + 
 . 


 . .
.
. . . 
 . 

 .   . . . . .  . 
x   0 ... 0 Q 0
 x 
N −1 N −1
xN 0 0 ... 0 P xN
 u0
  u0

R 0 ... 0
 u1  0 R ... 0  u1 
   
+
 .  .
 . . .   . 
.   
. . .
  . . .
. . . .  . 
uN − 1 0 ... 0 R uN − 1
| {z }

    
x1 B 0 ... 0  u0
 A
 x2   AB B ... 0  u1   A2 
      
 .      . 
 .  =  . . . . 
. 
. +  x0
 .   .
.
.
.
.
. .  .
.  
 .
. 

xN AN −1 B A N −2 B ... B uN − 1 AN
| {z }| {z } | {z }
S̄ z T̄

′ ′ ′
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

©2018 A. Bemporad - "Model Predictive Control" 38/120


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

• The optimum is obtained by zeroing the gradient

∇z J(z, x0 ) = Hz + F x0 = 0
 u∗

0
u∗
 1 
and hence z ∗ =  ..  = −H −1 F x0 (“batch” solution)

.
uN −1

• Alternative #1: find z ∗ via dynamic programming (Riccati iterations)


• Alternative #2: keep also x1 , . . . , xN as optimization variables and the
equality constraints xk+1 = Axk + Buk (non-condensed form)

©2018 A. Bemporad - "Model Predictive Control" 39/120


Unconstrained linear MPC algorithm
@ each sampling step t: past future r(t)
yk
predicted outputs
uk
manipulated inputs

t t+k t+N

• Minimize quadratic function, no constraints


 u0 
u1
1
min f (z) = z ′ Hz + x′ (t)F ′ z z= .. 
z 2 .
uN −1

• solution: ∇f (z) = Hz + F x′ (t) = 0 ⇒ z ∗ = −H −1 F x′ (t)


[ ]
u(t) = − I 0 . . . 0 H −1 F x(t) = Kx(t)

Unconstrained linear MPC = linear state-feedback!


©2018 A. Bemporad - "Model Predictive Control" 40/120
Constrained Linear MPC
{ 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

• Constrained optimal control problem (quadratic performance index):



N −1
min x′N P xN + x′k Qxk + u′k Ruk  u0 
z R = R′ ≻0
k=0 u1
Q = Q′ ≽0 z= .. 
′ .
s.t. umin ≤ uk ≤ umax , k = 0, . . . , N − 1 P = P ≽0 uN −1

ymin ≤ yk ≤ ymax , k = 1, . . . , N

©2018 A. Bemporad - "Model Predictive Control" 41/120


Constrained Linear MPC

k−1
• Linear prediction model: xk = Ak x0 + Ai Buk−1−i
i=0
• Optimization problem (condensed form):
V (x0 ) = 12 x′0 Y x0 + min 1 ′
2 z Hz + x′0 F ′ z (quadratic objective)
z

s.t. Gz ≤ W + Sx0 (linear constraints)

convex Quadratic Program (QP)


 u0  Az  b
u1 <latexit sha1_base64="c1miaOCnyb2pfxh2eiSZ6uIMPIE=">AAABUHicZY09T8MwEIYv5auYrwAjS0U6MKDI7tK1LQtjkUhboaDIcY/KqmOH2EHQqv+CFX4UG/+EDQpkgT7LPXrvdG+aK2kdpe9ebW19Y3Orvk12dvf2D/zDo4E1ZSEwEkaZYpRyi0pqjJx0Ckd5gTxLFQ7T6cX3fviAhZVGX7unHG8zPtHyTgrultFNszuLFd430mbiBzSkPzRWhVUSQEU/8Vk8NqLMUDuhuLVzq+QY7YLEpcWciymf4LzbSxw+5kZqtyBk2cH+f1yVQStkNGRXraBzXrXV4QRO4QwYtKEDl9CHCARoeIYXeIU3+IBPz/s9rVUTjuEPHvkCC7JRgA==</latexit>
sha1_base64="vBgm2mW7JCiG5B7aFaREhioGqZU=">AAABUHicZY27TsMwFIZPyq2EW7hsLBXpwICiuAtrCgtjkUhboaDIdg+VVcc2sYOAqm/BCg/FxpuwQWm7QL/lfPrP0fmZkcK6OP70aiura+sb9U1/a3tndy/YP+haXZUcU66lLvuMWpRCYeqEk9g3JdKCSeyx0eXvvveIpRVa3bhng3cFHSpxLzh10+i22X7JJD40WDMPwjiKZzSWhSwkTI5gRicPSDbQvCpQOS6ptWMrxQDtxM8qi4byER3iuH2RO3wyWig38f1pB/n/cVm6rYjEEbluhcnZvAzqcAwncAoEziGBK+hAChwUvMIbvMMHfMG3581Pa4sJh/AHz/8BSPpR1A==</latexit>

• z= ..  ∈ RN m is the optimization vector z*

. 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

• H = H ′ ≻ 0, and H, F, Y, G, W, S depend on weights Q, R, P upper and


lower bounds umin , umax , ymin , ymax and model matrices A, B, C.

©2018 A. Bemporad - "Model Predictive Control" 42/120


Computation of constraint matrices
• Input constraints umin ≤ uk ≤ umax , k = 0, . . . , N − 1
   
1 0 ... 0 umax
 0 0   
 1 ...   umax 
     
 .. .. ..   .. 
 . . .   .  u0
{      
≤  0 1     u1 
uk umax  ... 0   umax 
 z ≤   z=
 .. 

−uk ≤ −umin  −1 0 ... 0   −umin   
    .
 0 −1 ... 0   −umin 
    uN −1
 . ..   . 
 . ..  .. 
 . . .   
0 ... 0 −1 −umin


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

©2018 A. Bemporad - "Model Predictive Control" 43/120


Linear MPC algorithm
past future r(t)
yk
@ each sampling step t: predicted outputs
uk
manipulated inputs

t t+k t+N

• Measure (or estimate) the current state x(t)



  
 feedback
z }| {
u∗ 

0
u∗ 
 1 ′
+ x′ (t)F ′ z
 1   min 2 z Hz
• 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

©2018 A. Bemporad - "Model Predictive Control" 44/120


Double integrator example
∫∫ 2
• System: y(t) = u(τ )dτ (or equivalently ddt2y = u)
{
x(t + 1) = [ 10 11 ] x(t) + [ 01 ] u(t)
• Sampling with period Ts = 1 s:
y(t) = [ 1 0 ] x(t)

• 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

©2018 A. Bemporad - "Model Predictive Control" 45/120


Double integrator example
x1
x2

u x2

x1

go to demo linear/doubleint.m (Hybrid Toolbox)


(see also mpcdoubleint.m in MPC Toolbox)

©2018 A. Bemporad - "Model Predictive Control" 46/120


Double integrator example

• Add constraint on second state at prediction time t + 1:

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

©2018 A. Bemporad - "Model Predictive Control" 47/120


Double integrator example

x1
x2

u x2

x1

©2018 A. Bemporad - "Model Predictive Control" 48/120


Linear MPC - Tracking
• Objective: make the output y(t) track a reference signal r(t)
• Let us parameterize the problem using the input increments

∆u(t) = u(t) − u(t − 1)

• 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)

©2018 A. Bemporad - "Model Predictive Control" 49/120


Linear MPC - Tracking
• Optimal control problem (quadratic performance index):

N −1
min ∥W y (yk+1 − r(t))∥22 + ∥W ∆u ∆uk ∥22    
z ∆u0 u0
k=0
   
[∆uk , uk − uk−1 ], u−1 = u(t − 1)  ∆u1   u1 
z=
 ..  or z = 
  .. 

s.t. umin ≤ uk ≤ umax , k = 0, . . . , N − 1  .   . 
ymin ≤ yk ≤ ymax , k = 1, . . . , N ∆uN −1 uN −1
∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , N − 1

weight W = diagonal matrix (more generally, Cholesky factor of Q = W ′ W )

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

©2018 A. Bemporad - "Model Predictive Control" 50/120


Linear MPC tracking example
1.6

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)

go to demo linear/example3.m (Hybrid Toolbox)

©2018 A. Bemporad - "Model Predictive Control" 51/120


Linear MPC tracking example
• Performance index:

9 input

min (yk+1 − r(t))2 + 0.04∆u2k tf(1,[1 .4 1])

LTI System
k=0 output

Step
Linear Constrained
Controller

• Closed-loop MPC results:


u(t) y(t)

©2018 A. Bemporad - "Model Predictive Control" 52/120


Linear MPC tracking example
• Impose constraint 0.8 ≤ u(t) ≤ 1.2 (amplitude)

u(t) y(t)

• Impose instead constraint −0.2 ≤ ∆u(t) ≤ 0.2 (slew-rate)

u(t) y(t)

©2018 A. Bemporad - "Model Predictive Control" 53/120


Measured disturbances
• Measured disturbance v(t) = input that is measured but not manipulated
{
xk+1 = Axk + Buk + Bv v(t) manipulated
u(t) variables
yk = Cxk + Dv v(t)
outputs
process
y(t)
measured
v(t) disturbances

k−1
xk = Ak x0 + Aj Buk−1−j + Aj Bv v(t) state
j=0 x(t)

• Same performance index, same constraints. We still have a QP:


min J(z, x(t)) = 12 z ′ Hz + [x′ (t) r′ (t) u′ (t − 1) v ′ (t)]F ′ z
z  
x(t)
 r(t) 
 
s.t. Gz ≤ W + S  
 u(t − 1) 
v(t)

©2018 A. Bemporad - "Model Predictive Control" 54/120


Anticipative action (a.k.a. "preview")

N −1
min ∥W y (yk+1 − rk+1 )∥22 + ∥W ∆u ∆u(k)∥22
∆U
k=0

• Reference not known in advance • Future refs (partially) known in


(causal): advance (anticipative action):
rk ≡ r(t), ∀k = 0, . . . , N − 1 rk = r(t + k), ∀k = 0, . . . , N − 1

use r(t)
use r(t) use r(t+k)
use r(t+k)

go to demo mpcpreview.m (MPC Toolbox)


• Same idea also applies for preview of measured disturbances
©2018 A. Bemporad - "Model Predictive Control" 55/120
Soft constraints
• Relax output constraints to prevent QP infeasibility

N −1
min ∥W y (yk+1 − r(t))∥22 + ∥W ∆u ∆uk ∥22 + ρϵ ϵ2
z
k=0  ∆u(0)

..
subj. to xk+1 = Axk + Buk , k = 0, . . . , N − 1 z= .

∆u(N −1)
umin ≤ uk ≤ umax , k = 0, . . . , N − 1 ϵ

∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , N − 1


ymin − ϵVmin ≤ yk ≤ ymax + ϵVmax , k = 1, . . . , N

• ϵ = “panic” variable, with weight ρϵ ≫ W y , W ∆u


• Vmin , Vmax = vectors with entries ≥ 0. The larger the i-th entry of vector V ,
the relatively softer the corresponding i-th constraint

• Infeasibility can be due to:


– modeling errors
– disturbances
– wrong MPC setup (e.g., prediction horizon is too short)
©2018 A. Bemporad - "Model Predictive Control" 56/120
Delays - Method #1
• Linear model with delays x(t + 1) = Ax(t) + Bu(t − τ )
y(t) = Cx(t)

u(t 1) ... u(t ⌧) y(t)


u(t) x(t)
A, B C

• Map delays to poles in z = 0:


xk (t) , u(t − k) ⇒ xk (t1 ) = xk−1 (t), k = 1, . . . , τ
 x   A B 0 0 ... 0   x   0 
xτ 0 0 Im 0 ... 0 xτ 0
 xτ −1   0 0 0 Im ... 0   xτ −1   0 
 .  (t + 1) =  . . . . . .   .  (t) +  .  u(t)
.. .. .. .. . . .. .. .. ..
x 1 0 0 x0 I
0 ... 0 1 m

• Apply MPC to the extended system

• Note: the prediction horizon N ≥ τ , otherwise u0 , . . . , uN −1 have no effect


on the output!
©2018 A. Bemporad - "Model Predictive Control" 57/120
Delays - Method #2
{
x(t + 1) = Ax(t) + Bu(t − τ )
• Linear model with delays:
y(t) = Cx(t)
{
x̄(t + 1) = Ax̄(t) + Bu(t)
• Delay-free model: x̄(t) , x(t + τ )
ȳ(t) = C x̄(t)
• Design MPC for delay-free model, u(t) = fMPC (x̄(t))
• Compute the predicted state


τ −1
x̄(t) = x̂(t + τ ) = Aτ x(t) + Aj B u(t − 1 − j)
| {z }
j=1
past inputs!

• Compute the MPC control move u(t) = fMPC (x̂(t + τ ))


• For better closed-loop performance, x̂(t + τ ) can be computed by a more
complex model than (A, B, C)

©2018 A. Bemporad - "Model Predictive Control" 58/120


Good models for (MPC) control
• Computation complexity and theoretical properties (e.g., stability) depend on
chosen model/performance index/constraints
• Good models for MPC must be
– Descriptive enough to capture the most significant dynamics of the system

D E OFF
TRA
– Simple enough for solving the optimization problem

“Things should be made as simple as possible, but not any simpler.”

Albert Einstein
(1879–1955)

©2018 A. Bemporad - "Model Predictive Control" 59/120


MPC theory
• After the industrial success of MPC, a lot of research done:

– linear MPC ⇒ linear prediction model


– nonlinear MPC ⇒ nonlinear prediction model
– robust MPC ⇒ uncertain (linear) prediction model
– stochastic MPC ⇒ stochastic prediction model
– distributed/decentralized MPC⇒ multiple MPCs cooperating together
– economic MPC ⇒ MPC based on arbitrary (economic) performance indices
– hybrid MPC ⇒ prediction model integrating logic and dynamics
– explicit MPC ⇒ off-line (exact/approximate) computation of MPC
– solvers for MPC ⇒ on-line numerical algorithms for solving MPC problems

• Main theoretical issues: feasibility, stability, solution algorithms (Mayne, 2014)

Research on solution algorithms with guaranteed theoretical properties has


the most impact in industrial practice.
©2018 A. Bemporad - "Model Predictive Control" 60/120
Feasibility

N −1
min ∥W y (yk+1 − r(t))∥2 + ∥W ∆u ∆uk ∥2
z
k=0
subj. to umin ≤ uk ≤ umax , k = 0, . . . , N − 1 QP problem
ymin ≤ yk ≤ ymax , k = 1, . . . , N
∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , N − 1

• Feasibility: Will the QP problem be feasible at all sampling instants t?

• Input constraints only: always feasible if u/∆u constraints are consistent

• Hard output constraints:


– When N < ∞ there is no guarantee that the QP problem will remain feasible at
all future time steps t
– N = ∞ ⇒ infinite number of constraints!
– Maximum output admissible set theory: N < ∞ is enough (Gutman, Ckwikel, 1987)
(Gilbert, Tan, 1991) (Chmielewski, Manousiouthakis, 1996) (Kerrigan, Maciejowski, 2000)

©2018 A. Bemporad - "Model Predictive Control" 61/120


Predicted and actual trajectories
• Consider predicted and actual trajectories

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

• This follows by Bellman’s principle of optimality: 0 k N

“Given the optimal sequence u∗ (0), . . . , u∗ (N − 1) and the


corresponding optimal trajectory x( 0), . . . , x∗ (N ), the sub-
sequence u∗ (k), . . . , u∗ (N −1) is optimal for the problem on
the horizon [k, N ], starting from the optimal state x∗ (k).”

``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

an optimal policy.'' (Bellman, 1957) (1920–1984)

©2018 A. Bemporad - "Model Predictive Control" 63/120


Convergence and stability

N −1
min x′N P xN + x′k Qxk + u′k Ruk
z
k=0
QP problem
s.t. umin ≤ uk ≤ umax , k = 0, . . . , N − 1
ymin ≤ Cxk ≤ ymax , k = 1, . . . , N

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 can be imposed over
the prediction horizon to ensure stability of MPC

©2018 A. Bemporad - "Model Predictive Control" 64/120


Basic convergence properties
Theorem
Consider the linear system x(t + 1) = Ax(t) + Bu(t). Let the MPC law be
based on

N −1
V ∗ (x(t)) = min x′k Qxk + u′k Ruk
k=0
s.t. xk+1 = Axk + Buk
umin ≤ uk ≤ umax
ymin ≤ Cxk ≤ ymax
xN = 0 ← “terminal constraint”

with R, Q ≻ 0, umin < 0 < umax , ymin < 0 < ymax .


If the optimization problem is feasible at time t = 0 then

lim x(t) = 0, lim u(t) = 0


t→∞ t→∞

and the constraints are satisfied at all time t ≥ 0, for all R, Q ≻ 0.

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

• Let zt = optimal control sequence at time t, zt = [ut0 . . . utN −1 ]′

• By construction z̄t+1 = [ut1 . . . utN −1 0]′ is a feasible sequence at time t + 1

• The cost of z̄t+1 is V ∗ (x(t)) − x′ (t)Qx(t) − u′ (t)Ru(t) ≥ V ∗ (x(t + 1))

• V ∗ (x(t)) is monotonically decreasing and ≥ 0, so ∃ limt→∞ V ∗ (x(t)) , V∞

• Hence
0 ≤ x′ (t)Qx(t) + u′ (t)Ru(t) ≤ V ∗ (x(t)) − V ∗ (x(t + 1)) → 0 for t → ∞

• Since R, Q ≻ 0, limt→∞ x(t) = 0, limt→∞ u(t) = 0

Reaching the global optimum is not needed to prove convergence!

©2018 A. Bemporad - "Model Predictive Control" 66/120


A little more general converge result
Theorem (Keerthi, Gilbert, 1988) (Bemporad, Chisci, Mosca, 1994)
Consider again the linear system described by (A, B, C) and the MPC control
law based on optimizing

N −1
V ∗ (x(t)) = min yk′ Qy yk + u′k Ruk
k=0
s.t. xk+1 = Axk + Buk
umin ≤ uk ≤ umax
ymin ≤ yk ≤ ymax

If the optimization problem is feasible at time t = 0 then for either N = ∞ or


xN = 0 and for all R ≻ 0, Qy ≽ 0

lim y(t) = 0, lim u(t) = 0


t→∞ t→∞

and the constraints are satisfied at all time t ≥ 0. Moreover, if (LC, A) is a


detectable pair, Qy = L′ L (Cholesky factorization), then limt→∞ x(t) = 0.

©2018 A. Bemporad - "Model Predictive Control" 67/120


Convergence proof
Proof:

• 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

V ∗ (x(t)) − y ′ (t)Qy y(t) − u′ (t)Ru(t) ≥ V ∗ (x(t + 1))

• Therefore, by convergence of V ∗ (x(t)), we have that

0 ≤ y ′ (t)Qy y(t) + u′ (t)Ru(t) ≤ V ∗ (x(t)) − V ∗ (x(t + 1)) → 0

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

©2018 A. Bemporad - "Model Predictive Control" 68/120


Convergence proof (cont'd)

• As u(t) → 0, also LCAk x(t) → 0, and hence Θx(t) → 0, where Θ is the


observability matrix of (LC, A)

• If (LC, A) is observable then Θ is nonsingular and hence limt→∞ x(t) = 0

• If (LC, A) is only detectable, a canonical observability decomposition shows


that the unobservable modes go to zero spontaneously since u(t) → 0.

©2018 A. Bemporad - "Model Predictive Control" 69/120


Stability constraints

1. No stability constraint, infinite prediction horizon N →∞


(Keerthi, Gilbert, 1988) (Rawlings, Muske, 1993) (Bemporad, Chisci, Mosca, 1994)

2. End-point constraint xN = 0
(Kwon, Pearson, 1977) (Keerthi, Gilbert, 1988) (Bemporad, Chisci, Mosca, 1994)

3. Relaxed terminal constraint xN ∈ Ω


(Scokaert, Rawlings, 1996)

4. Contraction constraint ∥xk+1 ∥ ≤ α∥x(t)∥, α < 1


(Polak, Yang, 1993) (Bemporad, 1998)

All the proofs in (1,2,3) use the value function V ∗ (x(t)) = minz J(z, x(t)) as a
Lyapunov function.

©2018 A. Bemporad - "Model Predictive Control" 70/120


Control and constraint horizons

N −1
min ∥W y (yk − r(t))∥22 + ∥W ∆u ∆uk ∥22 + ρϵ ϵ2
z
k=0

subj. to umin ≤ uk ≤ umax , k = 0, . . . , N − 1


∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , N − 1
∆uk = 0, k = Nu , . . . , N − 1
ymin − ϵVmin ≤ yk ≤ ymax + ϵVmax , k = 1, . . . , Nc

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

• The constraint horizon Nc limits the number of constraints


– Higher chance of violating output constraints
– Reduced computation time

©2018 A. Bemporad - "Model Predictive Control" 71/120


MPC and Linear Quadratic Regulation (LQR)
∑N −1
• Special case: J(z, x0 ) = minz x′N P xN + k=0 x′k Qxk + u′k Ruk , Nu = N ,
with matrix P solving the Algebraic Riccati Equation

P = A′ P A − A′ P B(B ′ P B + R)−1 B ′ P A + Q
Jacopo Francesco Riccati
(1676–1754)

(unconstrained) MPC = LQR for any choice of the prediction horizon N

Proof: : Easily follows from Bellman’s principle of optimality (dynamic


programming): x′N P xN = optimal “cost-to-go” from time N to ∞.

©2018 A. Bemporad - "Model Predictive Control" 72/120


MPC and Linear Quadratic Regulation (LQR)
• Consider again the constrained MPC law based on minimizing

N −1
min x′N P xN + x′k Qxk + u′k Ruk
z
k=0
s.t. umin ≤ uk ≤ umax , k = 0, . . . , N − 1
ymin ≤ yk ≤ ymax , k = 1, . . . , N
uk = Kxk , k = Nu , . . . , N − 1
• Choose matrix P and terminal gain K by solving the LQR problem
K = −(R + B ′ P B)−1 B ′ P A
P = (A + BK)′ P (A + BK) + K ′ RK + Q

• In a polyhedral region around the origin, constrained MPC = constrained LQR


for any choice of the prediction and control horizons N , Nu
(Sznaier, Damborg, 1987) (Chmielewski, Manousiouthakis, 1996) (Scokaert, Rawlings, 1998)
(Bemporad, Morari, Dua Pistikopoulos, 2002)
• The larger the horizon N , the larger the region where MPC=LQR
©2018 A. Bemporad - "Model Predictive Control" 73/120
Double integrator example
{
∫∫ x(t + 1) = [ 10 11 ] x(t) + [ 01 ] u(t)
• y(t) = u(τ )dτ
y(t) = [ 1 0 ] x(t)
• Constraints: −1 ≤ u(t) ≤ 1
• Objective:

∑ uk = Kxk , ∀k ≥ Nu , K = LQR gain
1 2
min yk2 + u
10 k Nu = N = 2
k=0
(∑ )
+ x′2
1 1 2
yk2 +
[ 2.1429 1.2246 ]
10 uk x2
k=0
|1.2246{z1.3996}
solution of algebraic
Riccati equation
• QP matrices (cost function normalized by max singular value of H)
0.8365 0.3603 ] , F = [ 0.4624 1.2852 ]
H = [ 0.3603
[ 1 0 0.2059
] [ 1 ] 0.1682 [0.5285
00
]
−1 0
G = 0 1 , W = 11 , S = 00 00
0 −1 1 00

©2018 A. Bemporad - "Model Predictive Control" 74/120


Example: AFTI-F16 aircraft

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) !+''

• Constraints: ±25◦ on both angles /0'$%+1


2+130*"#01)'4)50,

• Open-loop unstable, poles are 6$%*07)'4)50,


2)*$%)'4)50,
−7.6636, −0.0075 ± 0.0556j, 5.4530
go to demo linear/afti16.m (Hybrid Toolbox)
see also afti16.m (MPC Toolbox)
©2018 A. Bemporad - "Model Predictive Control" 75/120
Wednesday, June 2, 2010
Example: AFTI-F16 aircraft
• Prediction horizon N = 10, control horizon Nu = 2

• Input weights W ∆u = [ 0.1 0 u


0 0.1 ], W = 0
[ ◦]
• Input constraints umin = −umax = 25 25◦
30
20
20
15
10

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

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

©2018 A. Bemporad - "Model Predictive Control" 76/120


Example: AFTI-F16 aircraft

• Add output constraints y1,min = −y1,max = 0.5◦


30
20
20
15
10

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

©2018 A. Bemporad - "Model Predictive Control" 77/120


Example: AFTI-F16 aircraft
• Linear control (=unconstrained MPC) + input clipping
4 30
10

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!

Saturation needs to be considered in the control design!

©2018 A. Bemporad - "Model Predictive Control" 78/120


Saturation
• Saturation is dangerous because it breaks the control loop

v(t)=Kx(t)+Hr(t)
saturation
r(t)
linear u(t) x(t)
controller plant

• MPC takes it into account automatically (and optimally)

v(t)=f(x(t),r(t))=u(t)
saturation
r(t)
MPC u(t) x(t)
controller plant

©2018 A. Bemporad - "Model Predictive Control" 79/120


Tuning guidelines

N −1
min ∥W y (yk+1 − r(t))∥22 + ∥W ∆u ∆uk ∥22 + ρϵ ϵ2
∆U
k=0

subj. to ∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , Nu − 1


∆uk = 0, k = Nu , . . . , N − 1
umin ≤ uk ≤ umax , k = 0, . . . , Nu − 1
ymin − ϵVmin ≤ yk ≤ ymax + ϵVmax , k = 1, . . . , Nc

• 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

Always try to set Nu as small as possible!

©2018 A. Bemporad - "Model Predictive Control" 80/120


Scaling

• Humans think infinite precision …computers do not !

• Numerical difficulties may arise if variables assume very small/large values

• Example:

y1 ∈ [−1e − 4, 1e − 4] [V] y1 ∈ [−0.1, 0.1] [mV]


y2 ∈ [−1e4, 1e4] [Pa] y2 ∈ [−10, 10] [kPa]

• Ideally all variables should be in [−1, 1]. For example, one can replace y with
y/ymax

• Scaling also possible after formulating the QP problem (=preconditioning)

©2018 A. Bemporad - "Model Predictive Control" 81/120


Observer design for MPC
r(t) u(t) y(t)
Optimizer Process measured
reference x(t) outputs

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)

We need to use a state observer

• Example: Luenberger observer x̂(t + 1) = Ax̂(t) + Bu(t) + L(y(t) − C x̂(t))

©2018 A. Bemporad - "Model Predictive Control" 82/120


Extended model for observer design
MVs (Manipulated Variables)
u(t)
yu(t)
v(t) MDs (Measured Disturbances) Plant CVs (Controlled Variables) Unmeasured
Outputs

nd(t) Unmeasured d(t) model


disturbance
model UMDs
white noise (Unmeasured
innovations Disturbances)

zm(t)
nm(t) Measurement m(t) + + ym(t)
noise
white noise model MOs
innovations (Measured Outputs)

unmeasured disturbance model measurement noise model


{ {
xd (t + 1) = Āxd (t) + B̄nd (t) xm (t + 1) = Ãxm (t) + B̃nm (t)
d(t) = C̄xd (t) + D̄nd (t) m(t) = C̃xm (t) + D̃nm (t)

• Note: the measurement noise model is not needed during optimization

©2018 A. Bemporad - "Model Predictive Control" 83/120


Kalman filter design
• Plant model
{
x(t + 1) = Ax(t) + Bu u(t) + Bv v(t) + Bd d(t)
y(t) = Cx(t) + Dv v(t) + Dd d(t)
Rudolf Emil Kalman
• Full model for designing Kalman filter (1930–2016)

[ 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)

] 0

ym (t) = [ Cm Ddm C̄ C̃ ] x( t) + Dvm v(k) + D̄m nd (t) + D̃m nm (t)


xm (t)

• nd (k) = source of modeling errors


• nm (k) = source of measurement noise
• nu (k) = white noise on input u (added to compute the Kalman gain)

©2018 A. Bemporad - "Model Predictive Control" 84/120


Observer implementation
• Measurement update
ym (t|t − 1) = Cm x(t|t − 1)

x(t|t) = x(t|t − 1) + M (ym (t) − ym (t|t − 1))

• Time update

x(t + 1|t) = Ax(t|t − 1) + Bu(t) + L(ym (t) − ym (t|t − 1))

• Note that the separation principle holds (under certain assumptions)


(Muske, Meadows, Rawlings, 1994)

©2018 A. Bemporad - "Model Predictive Control" 85/120


I/O feedthrough
• We always assumed no feedthrough from u to y

yk = Cxk + Duk + Dv vk + Dd dk , D=0

• This avoids static loops between state observer (x(t|t) depends on u(t)) and
MPC (u(t) depends on x(t|t))

• Often D = 0 is not a limiting assumption as


– often actuator dynamics must be considered (u is the set-point to a low-level
controller of the actuators)
– most physical models described by ordinary differential equations are strictly
causal, and so is the discrete-time version of the model

• In case D ̸= 0, we can assume a delay in executing the commanded u


yk
yk = Cxk + Duk−1 yk-1 uk
uk-1
and treat u(t − 1) as an extra state. t
(k-1)Ts kTs (k+1)Ts
©2018 A. Bemporad - "Model Predictive Control" 86/120
Integral action in MPC
Output integrators
MVs (Manipulated Variables)
u(t) Unmeasured Outputs
yu(t)
v(t) MDs (Measured Disturbances) Plant
nd(t) Unmeasured d(t) model +
zm(t)
disturbance
UMDs
+
white noise model
(Unmeasured
innovations Disturbances)

ni(t) Output
white noise Integrators
innovations

nm(t) Measurement m(t) + + ym(t)


noise
white noise model MOs
innovations (Measured Outputs)

• Introduce output integrators as additional disturbance models


• Under certain conditions, observer + controller provide zero offset in
steady-state

©2018 A. Bemporad - "Model Predictive Control" 87/120


Output integrators and offset-free tracking
• Add constant unknown disturbances on measured outputs:


 xk+1 = Axk + Buk
dk+1 = dk

 yk = Cxk + dk

• 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)

• Why we get offset-free tracking in steady-state (intuitively):


ˆ → y(t)
– the observer makes C x̂(t) + d(t) (estimation error)
ˆ → r(t)
– the MPC controller makes C x̂(t) + d(t) (predicted tracking error)
– the combination of the two makes y(t) → r(t) (actual tracking error)

ˆ compensates for model mismatch


• In steady state, the term d(t)

©2018 A. Bemporad - "Model Predictive Control" 88/120


Output integrators and offset-free tracking
(Pannocchia, Rawlings, 2003)

• More general result: consider the disturbance model




 xk+1 = Axk + Buk + Bd dk
dk+1 = dk special case: output integrators

 Bd = 0, Dd = I
yk = Cxk + Dd dk

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

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.
©2018 A. Bemporad - "Model Predictive Control" 89/120
Disturbance model example

[ 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

• We cannot add an output integrator since the pair ([ A0 10 ] , [ C 1 ]) is not


observable

[ 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)

©2018 A. Bemporad - "Model Predictive Control" 90/120


Error feedback
(Kwakernaak, Sivan, 1972)

• Idea: add the integral of the tracking error as an additional state (original idea
developed for integral action in state-feedback control)

• Extended prediction model:




 x(t + 1) = Ax(t) + Bu u(t) + 0 · r(t) ← r(t) is seen as a meas. disturbance

 q(t + 1) = q(t) + Cx(t) − r(t) ← integral action
| {z }

 tracking error


y(t) = Cx(t)

• ∥W i q∥22 is penalized in the cost function, otherwise it is useless. W i is a new


tuning knob

• Intuitively, if the MPC closed-loop is asymptotically stable then q(t) converges


to a constant, and hence y(t) − r(t) converges to zero.
©2018 A. Bemporad - "Model Predictive Control" 91/120
Reference / Command Governor
(Bemporad, Mosca, 1994) (Gilbert, Kolmanovsky, Tan, 1994) (Garone, Di Cairano, Kolmanovsky, 2016)
actual control
reference input
constrained
r(t) w(t) u(k) variables
Local c(t)
desired
reference Feedback y(t) ¼ r(t)
Reference Plant
Governor controlled outputs

Primal System
x(t)
estimated plant + controller states

• MPC manipulates set-points to a linear feedback loop to enforce constraints


• Separation of problems:
– Local feedback guarantees offset-free tracking in steady-state in the absence of
constraints
– Actual reference w(t) generated by MPC to take care of constraints

• Advantages: small-signal properties preserved, fewer variables to optimize


w(t) = arg minw ∥w − r(t)∥22
s.t. ct+k ∈ C

©2018 A. Bemporad - "Model Predictive Control" 92/120


Model Predictive Control Toolbox
(Bemporad, Ricker, Morari, 1998-present)

• Several linear MPC design features available:


– explicit MPC

– time-varying/adaptive models, weights, constraints

– stability/frequency analysis of closed-loop (inactive constraints)

– …
• 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)

©2018 A. Bemporad - "Model Predictive Control" 93/120


MPC Simulink Library

>> mpclib

©2018 A. Bemporad - "Model Predictive Control" 94/120


MPC Simulink block

©2018 A. Bemporad - "Model Predictive Control" 95/120


MPC Simulink block

©2018 A. Bemporad - "Model Predictive Control" 96/120


MPC Simulink block

©2018 A. Bemporad - "Model Predictive Control" 97/120


MPC Graphical User Interface

>> mpcDesigner (old version: >> mpctool)

See video on Mathworks’ web site (link)

©2018 A. Bemporad - "Model Predictive Control" 98/120


Example: MPC of a DC servomotor
R
µM Tr
V e µ
JM s T µL
bM r JL
bL

Symbol Value (MKS) Meaning >> mpcmotor


LS 1.0 shaft length
dS 0.02 shaft diameter
JS negligible shaft inertia
JM 0.5 motor inertia
βM 0.1 motor viscous friction coefficient
R 20 resistance of armature see also
kT 10 motor constant linear/dcmotor.m
ρ 20 gear ratio
kθ 1280.2 torsional rigidity (Hybrid Toolbox)
JL 50JM nominal load inertia
βL 25 load viscous friction coefficient
Ts 0.1 sampling time

©2018 A. Bemporad - "Model Predictive Control" 99/120


DC servomotor model

 
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

0 − ρ2kJθ − RJM
[ ρJM ] M JM
θL = 1 0 0 0 x [θ ]
y= T
L

[ ]
T = kθ 0 − kρθ 0 x

>> [plant, tau] = mpcmotormodel;


>> plant = setmpcsignals(plant,'MV',1,'MO',1,'UO',2);

©2018 A. Bemporad - "Model Predictive Control" 100/120


DC servomotor constraints

• The input DC voltage V is bounded withing the range

|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;

©2018 A. Bemporad - "Model Predictive Control" 101/120


DC servomotor - MPC setup


p−1
min ∥W y (yk+1 − r(t))∥2 + ∥W ∆u ∆uk ∥2 + ρϵ ϵ2
∆U
k=0

subj. to ∆umin ≤ ∆uk ≤ ∆umax , k = 0, . . . , m − 1


∆uk = 0, k = m, . . . , p − 1
umin ≤ uk ≤ umax , k = 0, . . . , m − 1
ymin − ϵVmin ≤ yk ≤ ymax + ϵVmax , k = 1, . . . , p

>> Weights = struct('MV',0,'MVRate',0.1,'OV',[0.1 0]);


>> p = 10;
>> m = 2;
>> mpcobj = mpc(plant,Ts,p,m,Weights,MV,OV);

©2018 A. Bemporad - "Model Predictive Control" 102/120


DC servomotor - Closed-loop simulation

R
µM Tr
V e µ
JM s T µL
bM r JL
bL

Closed-loop simulation using


the sim command

>> Tstop = 8; % seconds


>> Tf = round(Tstop/Ts); % simulation iterations
>> r = [pi*ones(Tf,1) zeros(Tf,1)];
>> [y1,t1,u1] = sim(mpcobj,Tf,r);

©2018 A. Bemporad - "Model Predictive Control" 103/120


DC servomotor - Closed-loop simulation

Closed-loop
simulation in
Simulink

>> mdl = 'mpc_motor';


>> open_system(mdl)
>> sim(mdl)

©2018 A. Bemporad - "Model Predictive Control" 104/120


DC servomotor - Closed-loop simulation
θL (t) T (t) V (t)
4 100 400

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

• same MPC tuning parameters

• setpoint r(t) = π sin(0.4t) deg

©2018 A. Bemporad - "Model Predictive Control" 105/120


Example: MPC of active suspensions
θ
Lf Lr
z
We consider the suspension demo uf ur
h
sldemo_suspn in MATLAB

Ff ront = 2Kf (Lf θ − (z + h)) + 2Cf (Lf θ̇ − ż) + uf


Ff ront , Frear = upward force on body from front/rear suspension
Kf , Kr = front and rear suspension spring constant
Cf , Cr = front and rear suspension damping rate
Lf , Lr = horizontal distance from c.g. to front/rear suspension
θ, θ̇ = pitch (rotational) angle and its rate of change
z, ż = bounce (vertical) distance and its rate of change

• for control purposes we add external forces uf , ur as manipulated variables


• the system has 4 states: θ, θ̇, z, ż

©2018 A. Bemporad - "Model Predictive Control" 106/120


Example: MPC of active suspensions

• Step #1: get a linear discrete-time model (4 inputs, 3 outputs, 4 states)

>> plant_mdl = 'suspension_model';


>> op = operspec(plant_mdl);
>> [op_point, op_report] = findop(plant_mdl,op);
>> sys = linearize(plant_mdl, op_point);
>> Ts = 0.025; % sample time (s)
>> plant = c2d(sys,Ts);

>> plant = setmpcsignals(plant,'MV',[1 2],'MD',...


[3 4],'MO',[1 2],'UO',3);

©2018 A. Bemporad - "Model Predictive Control" 107/120


Example: MPC of active suspensions

• Step #2: design the MPC controller

>> dfmax = .1/.1; % [kN/s]


>> MV = struct('RateMin',-Ts*dfmax, Ts*dfmax,...
'RateMax',Ts*dfmax,Ts*dfmax);
>> OV = [];
>> Weights = struct('MV',[0 0], 'MVRate',[.01 .01],...
'OV',[.01 0 10]);

>> p = 50; % Prediction horizon


>> m = 5; % Control horizon

>> mpcobj = mpc(plant,Ts,p,m,Weights,MV,OV);

©2018 A. Bemporad - "Model Predictive Control" 108/120


Example: MPC of active suspensions
Vehicle Suspension Model ?

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

FrontForce RearForce signal2 signal2

Front Suspension Rear Suspension h


Road Height

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

MPC Controller Gain1 Copyright 1990-2015 The MathWorks, Inc.

©2018 A. Bemporad - "Model Predictive Control" 109/120


Example: MPC of active suspensions
-3 3_ (rad/s) z_ (cm/s)
• Closed-loop MPC results 6
#10

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

MPC Front Force uf (N) MPC Rear Force ur (N)


150 20

0
100

-20
50
-40

0
-60

-50 -80
0 2 4 6 8 10 0 2 4 6 8 10

My (Nm) h, Z+h (cm)


100 5
road height h
80 relative displacement Z+h
0

60
-5
40

-10
20

0 -15
0 2 4 6 8 10 0 2 4 6 8 10

©2018 A. Bemporad - "Model Predictive Control" 110/120


Frequency analysis of MPC (for small signals)
• Unconstrained MPC gain + linear observer = linear dynamical system
• Closed-loop MPC analysis can be performed using standard
frequency-domain tools (e.g., Bode plots for sensitivity analysis)

u(t) Plant ym(t)


x(t)

MPC
^
x(t) r(t)

>> sys=ss(mpcobj) returns the LTI object of the MPC controller


>> sys=tf(mpcobj) (when constraints are inactive)

©2018 A. Bemporad - "Model Predictive Control" 111/120


Controller matching
(Di Cairano, Bemporad, 2010)

• Given a desired linear controller u = Kd x, find a set of weights Q, R, P


defining an MPC problem such that
[ ]
− I 0 . . . 0 H −1 F = Kd

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

• The above inverse optimality problem can be cast as a convex problem


(Di Cairano, Bemporad, 2010)

©2018 A. Bemporad - "Model Predictive Control" 112/120


Controller matching - Example

• Open-loop process: y(t) = 1.8y(t − 1) + 1.2y(t − 2) + u(t − 1)

• Constraints: −24 ≤ u(t) ≤ 24, y(t) ≥ −5

• Desired controller = PID with gains KI = 0.248, KP = 0.752, KD = 2.237


( ) [ y(t−1) ]
u(t) = − KI I(t) + KP y(t) + KTD (y(t) − y(t − 1)) y(t−2)
s x(t) = I(t−1)
I(t) = I(t − 1) + Ts y(t) u(t−1)

• Matching result (using inverse LQR):


[ 6.401 0.064 −0.001 0.020 ] [ 422.7 241.7 50.39 201.4 ]
∗ 0.064 6.605 0.006 0.080 ∗ ∗ 241.7 151.0 32.13 120.4
Q = −0.001 0.006 6.647 −0.020 , R = 1, P = 50.39 32.13 19.85 26.75
0.019 0.080 −0.020 6.378 201.4 120.4 26.75 106.6

©2018 A. Bemporad - "Model Predictive Control" 113/120


Controller matching - Example
20

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

what PID would apply 20


0
−20

y2
−40
−60
−80

• Note: This is not trivially a −100


0 2 4 6 8 10
t
12 14 16 18 20

saturation of a PID controller. 50

25
In this case saturating the PID
u2

output leads to closed-loop −25

−50
instability! 0 2 4 6 8 10
t
12 14 16 18 20

©2018 A. Bemporad - "Model Predictive Control" 114/120


Linear MPC based on linear programming
Linear MPC based on LP
(Propoi, 1963) (Bemporad, Borrelli, Morari, 2003)

{ 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

• Constrained optimal control problem (∞-norms): ∥v∥∞ , max |vi |


i=1,...,n


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

©2018 A. Bemporad - "Model Predictive Control" 115/120


Linear MPC based on LP

• Basic trick: introduce slack variables (Qi = i-th row of Q)

ϵ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

©2018 A. Bemporad - "Model Predictive Control" 116/120


Linear MPC based on LP

k−1
• Linear prediction model: xk = Ak x0 + Ai Buk−1−i
i=0

• Optimization problem:
V (x0 ) = min [1 . . . 1 0 . . . 0]z (linear objective)
z

s.t. Gz ≤ W + Sx0 (linear constraints)

Linear Program (LP)


• optimization vector: z , [ϵu0 . . . ϵuN −1 ϵx1 . . . ϵxN u′0 , . . . , u′N −1 ]′ ∈ RN (nu +2)

• G, W , S are obtained from weights Q, R, P , and model matrices A, B, C


• Q, R, P can be selected to guarantee closed-loop stability
(Bemporad, Borrelli, Morari, 2003)

©2018 A. Bemporad - "Model Predictive Control" 117/120


Extension to arbitrary convex PWA functions
a04x + b4
Result `(x)
a01x + b1
Every convex piecewise affine function
ℓ : Rn → R can be represented as the a03x + b3

max of affine functions, and vice versa


(Schechter, 1987)
x
a02x + b2
Example: ℓ(x) = |x| = max{x, −x}
ℓ(x) = max {a′1 x + b1 , . . . , a′4 x + b4 }

• Constrained optimal control problem

−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

©2018 A. Bemporad - "Model Predictive Control" 118/120


Convex PWA optimization problems and LP
• Minimization of a convex PWA function ℓ(x):

ϵ minϵ,x ϵ

 ϵ ≥ a′1 x + b1

 ϵ ≥ a′ x + b
2 2
s.t. ′

 ϵ ≥ a x + b


3 3
x ϵ ≥ a′4 x + b4

• By construction ϵ ≥ max{a′1 x + b1 , a′2 x + b2 , a′3 x + b3 , a′4 x + b4 }


• By contradiction it is easy to show that at the optimum we have that

ϵ = max{a′1 x + b1 , a′2 x + b2 , a′3 x + b3 , a′4 x + b4 }

• Convex PWA constraints ℓ(x) ≤ 0 can be handled similarly by imposing


a′i x + bi ≤ 0, ∀i = 1, 2, 3, 4

©2018 A. Bemporad - "Model Predictive Control" 119/120


LP-based vs QP-based MPC
• QP- and LP-based share the same set of feasible inputs (Gz ≤ W + Sx)

• When constraints dominate over performance there is little difference


between them (e.g., during transients)

• 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

©2018 A. Bemporad - "Model Predictive Control" 120/120

You might also like