Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)...

51
Model Predictive Control (MPC) Bo Bernhardsson and Karl Johan Åström Department of Automatic Control LTH, Lund University Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Transcript of Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)...

Page 1: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Model Predictive Control (MPC)

Bo Bernhardsson and Karl Johan Åström

Department of Automatic Control LTH,Lund University

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 2: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Model Predictive Control (MPC)

MPC Problem Setup and Parameters

Optimization Problem

MPC Tools

How to get Integral Action

Example - Quad Tank

Explicit MPC and CVXGEN

Material:Rawlings (2000), Tutorial overview of model predictive controlÅkesson (2006), Manual to MPC tools 1.0

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 3: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Basic Idea of MPC: Receding Horizon Control

1 At time k solve an open loop optimal control problem over apredefined horizon and apply the first input

2 At time k + 1 repeat the same procedure (the previous optimalsolution can be used as initial guess)

Bellman’s principle of optimalityBo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 4: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Model Predictive Control

Model Predictive Control (MPC)

Uses models explicitly to predict future plant behaviour

Constraints on inputs, outputs, and states are respected

Control sequence is determined by solving an (often convex)optimization problem each sample

Combined with state estimation

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 5: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC

Refineries (Shell in 1970s, "Dynamic Matrix Control")

(Bellman), Propoi (1963), Richalet, Prett, Morari, . . .

Main reasons for successSuitable for multivariable systemsRespects actuator limitations: no integrator wind-up, saturationproblems handled explicitlyProcess can be run close to constraints, which is oftencost-effective

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 6: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Optimization Criterion

Control changes ∆u(k + i) = u(k + i) − u(k + i − 1) areoptimization variables

J(k) =

Hp+Hw−1∑

i=Hw

||z(k + i|k) − r(k + i)||2Q +Hu−1∑

i=0

||∆u(k + i)||2R

Evaluated signals z = Czx + Dzu

Hw: system time-delay

Hu: cover typical closed loop time constant

Hp: somewhat larger than Hu

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 7: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Prediction Horizons (with Hw = 0)

y(k)

y(k)

r(k)

u(k)u(k)

k k + Hu k + Hp t

Large Hu and Hp give better performance but more computations andnumerical problems

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 8: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

∆u(k) vs u(k)

Why penalize ∆u(k) instead of u(k)?

Reference r 6= 0 requires u 6= 0 to avoid static errorNo need to guess and specify ur

Still possible to penalize u(k), just include u in z-vector

TAT: Do we get integral action by penalizing ∆u instead of u?Consider y = u + d, do we get y = r in stationarity if d 6= 0?

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 9: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Block Diagram (typical)

PLANTMPCy

y

u

ve

d

r+

v, d, e disturbances, v available for feedforwardr reference value

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 10: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Assumed Dynamics

xk+1 = Axk + Buuk + Bvvk + Bwwk

yk = Cxk + Dvvk + Dwwk

where vk is a measured disturbance and wk =

[

dk

ek

]

.

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 11: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Prediction Algorithms

Future trajectories starting at time k over the prediction horizon Hp

Assuming v is not known in advance

yk+Hp|k = C

AHpxk +

Hp−1∑

j=0

AHp−1B(uk−1 +j

i=0

∆ui)

+DvvHp

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 12: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Prediction Algorithms

All Hp predicted time steps can be summarized as

yk+1

yk+2

...yk+Hp

= Sxxk + Su−1uk−1 + Su

∆uk

∆uk+1

...∆uk+Hp−1

+ Hv

vk

vk+1

...vk+Hp

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 13: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Prediction Algorithms

...where

Sx =

CA

CA2

...CAHp

∈ RHpny×nx

Su−1 =

CBu

CABu + CBu∑Hp−1

j=0 CAjBu

∈ RHpnx×nu

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 14: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Prediction Algorithms

... and

Su =

CBu 0 . . . 0CBu + CABu CBu . . . 0

.... . .

...∑Hp−1

j=0 CAjBu

∑Hp−1j=0 CAjBu . . . CBu

∈ RHpny×Hpnu

Hv =

CBv D 0 . . . 0CABv CBv D 0

.... . .

...CAHp−1Bv CAHp−2Bv CAHp−3Bv . . . D

∈ RHpny×(Hp+1)nv

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 15: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Blocking Factors

At each step the following cost function is minimized

J(k) =

Hp−1∑

i=k

||y(k+i|k)−r(k+i|k)||2Q +Hu−1∑

i=k

||∆u(k+i|k)||2R

Blocking factors can be used to ease the computationalrequirements. This means that constraints and cost is onlyevaluated at certain time steps, contained in sets Ip and Iu.

J(k) =∑

i∈Ip

||y(k + i|k) − r(k + i|k)||2Q +∑

i∈Iu

||∆u(k + i|k)||2R

Move blocking restrictions can also be imposed on the controlsignal, so that ∆u = 0 at certain time steps

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 16: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Optimization Variables

Introduce the optimization variables, if we have reference controlsignals ur

k

eu =

uk

uk+1

...uk+Hp−1

urk

urk+1...

urk+Hp−1

,

and

e∆u =

∆uk

∆uk+1

...∆uk+Hu−1

, ey =

yk+1

yk+2

...yk+Hp

rk+1

rk+2

...rk+Hp

for control moves and reference tracking

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 17: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Optimization Variables

For unconstrained optimization, the cost function is

J(z) = eTu W 2

u eu + eT∆uW 2

∆ue∆u + eTy W 2

y ey

where the first term penalizes control signals, the second penalizescontrol moves and the last term penalizes tracking error.

Matrices Wu, W∆u, and Wy are design parameters.

Alternative notation (here without eu)

J(k) =

Hp−1∑

i=k

||y(k + i|k) − r(k + i|k)||2Q +Hu−1∑

i=k

||∆u(k + i|k)||2R

Matrices Q and R are (possibly time-varying) design parameters.

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 18: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Constraints

The MPC controller should respect the constraints

∆umin ≤ ∆u(k) ≤ ∆umax

umin ≤ u(k) ≤ umax

zmin ≤ zc(k) ≤ zmax

Some variables might be constrained, but have no reference values

If a constrained variable is not measured, the constraints will be put onan estimate instead

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 19: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Soft or Hard Constraints?

Always need to find a u. Problem if constraints unfeasible.

Replace hard constraints with soft constraints.

Minimize slack variable ǫ ≥ 0 so that

ymink+1

.

.

.

ymink+Hp

umink+1

.

.

.

umink+Hp

∆umink

.

.

.

∆umink+Hu−1

−ǫVmin

yk+1

.

.

.yk+Hp

uk

.

.

.uk+Hp−1

∆uk

.

.

.∆uk+Hu−1

ymaxk+1

.

.

.ymax

k+Hp

umaxk+1

.

.

.umax

k+Hp

∆umaxk

.

.

.∆umax

k+Hu−1

+ǫVmax

Relaxation vectors V min > 0, V max > 0 are user definedparameters. Larger V , more relaxed constraint

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 20: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Optimization Constraints

For the constrained case, a suitable MPC cost criterion to beminimized is

J(z, ǫ) = eTu W 2

u eu + eT∆uW 2

∆ue∆u + eTy W 2

y ey + ρǫǫ2

subject to dynamics and constraints

A large value of ρǫ penalizes constraint violation harder.

In practice, softening of output constraints is often a good idea.

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 21: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Design Parameters

Internal Dynamic Model

(State Estimation Parameters)

Prediction- and Control Horizons

Blocking factors

Weighting Matrices

Constraint Parameters

Sample rate

Integral action? alt. disturbance model

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 22: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Quadratic Optimization

The optimization problem is often posed as quadraticprogramming

minx12xT Hx + fT x

subject to Ax ≤ b

In MATLAB: ’quadprog’

Advantages with QP: Fast, reliable software

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 23: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Disturbance Models

When solving the optimization problem, predicted future values ofthe disturbances are needed

With some knowledge about the nature of the disturbances theprediction can be improved

Often Gaussian noise and Kalman filter is used

Can also formulate the prediction problem as a QP problem, e.g.maximizing log-likelihood of measurements

Optimization approach to estimation can e.g. give robustness tooutliers

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 24: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

State Estimation - Error Update

x0k|k

xdk|k

xmk|k

=

x0k|k−1

xdk|k−1

xmk|k−1

+ K (ymk − ym

k )

d : known disturbancem : reference model

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 25: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Internal Dynamic Model

x0k+1

xdk+1

xmk+1

=

A0 B0Cd 00 Ad 00 0 Am

x0k

xdk

xmk

+

Bu

00

uk

+

Bv

00

vk +

B0Dd 0 Bu Bv

Bd 0 0 00 Bm 0 0

wdk

wmk

wuk

wvk

ymk =

C0 Cd Cm

x0k

xdk

xmk

+

Dm D 0 0

wdk

wmk

wuk

wvk

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 26: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

State Estimation - Temporal Update

x0k+1|k

xdk+1|k

xmk+1|k

=

A0 B0Cd 00 Ad 00 0 Am

x0k|k−1

xdk|k−1

xvk|k−1

+

Bu

00

uk

+

Bv

00

vk +

B0Dd 0 Bu Bv

Bd 0 0 00 Bm 0 0

wdk

wmk

wuk

wvk

ymk =

C0 Cd Cm

x0k|k−1

xdk|k−1

xmk|k−1

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 27: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Software

MPCtools - Developed by Johan Åkesson, Automatic Control,Lund

Separates measured/constrained/controlled outputsIntegral action by means of disturbance estimationDifferent QP-solvers for the optimization problemUsed in Lab 3 i Predictive control

Mathworks - Model Predictive Control ToolboxGUI or text-based control designIntegrated observer design and basic disturbance modeling

MPT - Multi-Parametric Toolbox for Matlab from ETHSupports linear, nonlinear, and hybrid system descriptionsExplicit MPC

CVX+CVXGen: MPC code generator, runs typically on micro ormillisec for small size problems. Nice project!

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 28: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Toolbox

Model assumptions in MPC toolbox

x(k + 1) = Ax(k) + Bu(k)

y(k) = Cyx(k)

z(k) = Czx(k) + Dzu(k)

zc(k) = Ccx(k) + Dcu(k)

Measured outputs y

Controlled outputs z

Constrained outputs zc

(no known disturbances)

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 29: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPCTool - Control Problem

Cost function

J(k) =

Hp+Hw−1∑

i=Hw

‖z(k + i|k) − r(k + i|k)‖2

Q+Hu−1∑

i=0

‖∆u(k + i|k)‖2

R

(1)

Prediction Horizon, Hp

Control Horizon, Hu

First sample to be included, Hw

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 30: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Solving the Quadratic Program (QP)

One can rewrite the optimization criterion on the form

min J(k) = ∆UT H∆U − ∆UT G + ET QE

subject to Ω∆U ≤ ω

where ∆U , H, G, E , Q, Ω, ω are large vectors/matrices, used to stackup the equations above for all time indices.

Details are in the MPC toolbox manual, but will not be needed

Convex problem - efficient algorithms

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 31: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

State Estimation

Use a traditional Kalman filter, having the form

x(k + 1) = Ax(k) + Bu(k) + K(y(k) − Cyx(k)).

Gain matrix K obtained by solving a Riccati equation

(information about state constraints are not utilized in MPCTool)

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 32: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Error-free tracking - Integral Action 1

One option is to use a disturbance observer

A step disturbance is assumed to act on the input, the followingextended model is then used (when r = 0):

xk+1

vk+1

dk+1

=

A 0 B

0 I 00 0 I

xk

vk

dk

+

B

00

uk

z = yz =

Cz 0 0

xTk vT

k dTk

T

ya =

Ca I 0

xTk vT

k dTk

T

Using an observer with this model structure will introduce integralaction giving z = 0 in stationarity.

If more outputs than inputs, one must introduce constant outputdisturbances vk on the outputs ya that shouldn’t get integral action

If nr inputs = nr outputs one doesn’t need ya and vk

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 33: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Error-free tracking - Integral Action 2

Another option is to add integrator states in the model[

x(k + 1)xi(k + 1)

]

=

[

A 0−Cz I

]

x(k) +

[

B

0

]

u(k) +

[

0I

]

r(k)

y(k) =[

Cy 0]

z(k) =[

Cz 0]

A stabilizing feedback is calculated using the extended state. Note thatthe state xi need not be estimated, since it is known perfectly by thecontroller

Polynomial design interpretation to the two methods

A(q − 1)R′ + BS = AmAoB+

where either Ao (previous slide) or Am (this slide) has an increasedorder compared to the minimal order

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 34: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Linear Properties of the MPC Controller

The MPC controller is nonlinear, because of constraints on state andcontrol

However, if the constraints are not active, the controller is linear

The minimizing solutions of the unconstrained QP is then

∆U(k) = (ΘT QΘ + R)−1ΘT QE(k)

= . . .

= Ks

r(k)u(k − 1)

x(k)

for some vector Ks

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 35: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Linear Properties of the MPC Controller

This means the control law can be written

∆u(k) =[

Ksr Ksu Ksx

] [

rT (k) uT (k − 1) xT (k)]T

where[

Ksr Ksu Ksx

]

is given by the first m rows of Ks

This means that with

P (z) = Cy(zI − A)−1B

H(z) = −KsxHy(z)

Hy(z) = (zI − A + KCy)−1K

Hu(z) = (zI − A + KCy)−1B

we get the following figure

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 36: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Linear Properties of the MPC Controller

−Ksr

Ksu

−Ksx

Ksx

P (z)

Hu(z)

Hy(z)

r(k) ∆u(k) u(k) y(k)

z−1I

zz−1 I

Equivalent linear timeinvariant controller

K(z) =z

z − 1

[

I −1

z − 1Ksu −

z

z − 1KsxHu(z)

]−1

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 37: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Tools

MPC controller calculate ,simulate and evaluate in Matlab/Simulink

Good QP solver implementations with active set and interior pointmethods

Main commands: MPCInit (output: data-structure "md"), MPCSim,MPCController, MPCfrsp

Mode 0: State feedback.

Mode 1: State feedback with explicit integrators.

Mode 2: Observer-based output feedback.

Mode 3: Observer-based output feedback with explicitintegrators.

Mode 4: Observer-based output feedback with a disturbancemodel that gives error free tracking.

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 38: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Tools

Figure: A Simulink model where the MPC controller is used to control anonlinear plant.

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 39: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Example - Quad Tank

Tank 2Tank 1

Tank 3 Tank 4replacements

u1u2

γ1 γ2

1 − γ1 1 − γ2

Pump 1 Pump 2

Challenging MIMO process. Parameters γ1, γ2 control the flowstructure to the upper and lower tanks respectively

Non-minimum phase dynamics if e.g. γ1 = γ2 = 0.3

See e.g. MPCTools manual for a modelBo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 40: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

MPC Controller Parameters

Parameter Valueh sampling rate = 3 secHp 30Hw 1Hu 10Ip blocking factor 2Iu blocking factor 2Q diag(4, 1)R diag(0.01, 0.01)W diag(1, 1, 1, 1)/diag(1, 1, 1, 1, 1, 1)V diag(0.01, 0.01)

Constraints: 0 ≤ x ≤ 19.8 cm on all tanks0 ≤ u ≤ 10 V on both pumps

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 41: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Typical Code

% Some initialisation of matrices left out here

Hp = 30; % Prediction horizon

Hu = 10; % Horizon for varying input signal

Hw = 1; % First penalty sample

zblk=2;

ublk=2;

Q = diag([4 1]);

R = 0.01*diag([1 1]);

W = diag([1 1 1 1]);

V = diag(0.01*ones(1,2));

md = MPCInit(Ad,Bd,Cyd,Czd,Dzd,Ccd,Dcd,Hp,Hw,zblk,Hu,ublk, ...

du_max,du_min,u_max,u_min,z_max, ...

z_min,Q,R,W,V,h,2,’qp_as’);

MPCfrsp(md,10);

[x,u,y,z,zp,up] = MPCSim(md,s,d);

% Plotting left out here

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 42: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Results, simulation on linearized plant

0 200 400 600 800 1000 12002

4

6

8

10

12

h 3 [cm

]

0 200 400 600 800 1000 12002

4

6

8

10

h 4 [cm

]

0 200 400 600 800 1000 12006

8

10

12

14

16

h 1 [cm

]

0 200 400 600 800 1000 120018

18.5

19

19.5

20

h 2 [cm

]

0 200 400 600 800 1000 12000

1

2

3

4

u 1 [V]

t [s]0 200 400 600 800 1000 1200

2

4

6

8

u 2 [V]

t [s]

Dashed: Kalman filter, no integral actionSolid: Kalman filter with disturbance observer

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 43: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Results, simulation on nonlinear plant

0 200 400 600 800 1000 12002

4

6

8

10

12

14

h 3 [cm

]

0 200 400 600 800 1000 12002

4

6

8

10

h 4 [cm

]

0 200 400 600 800 1000 12006

8

10

12

14

16

h 1 [cm

]

0 200 400 600 800 1000 1200

18

18.5

19

19.5

20

h 2 [cm

]

0 200 400 600 800 1000 12000

1

2

3

4

u 1 [V]

t [s]0 200 400 600 800 1000 1200

2

4

6

8

u 2 [V]

t [s]

Works wellBo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 44: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Results, MPC linear behavior

Without the contraints, the MPC controller gives the following gaincurves. The plots show singular values for the 2 × 2 system.

10-2

100

-30

-20

-10

0

10

Closed Loop

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-30

-20

-10

0

10

Sensitivity Function

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-30

-20

-10

0

10

Complimentary Sensitivity

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-20

-10

0

10

20

Control Sensitivity to Noise

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-2

100

-30

-20

-10

0

10

Closed Loop

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-80

-60

-40

-20

0

20

Sensitivity Function

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-15

-10

-5

0

5

10

Complimentary Sensitivity

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

10-4

10-2

100

-20

-10

0

10

20

30

Control Sensitivity to Noise

Frequency (rad/s)

Sin

gula

r V

alue

s (d

B)

Left: Without integral action Right: With integral action

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 45: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Explicit MPC

For applications where very short sample times are required,there may not be time to solve the optimization problem at eachtime step.

Explicit MPC calculates a state feedback law that is equivalent toMPC in a specific region of the state-space

As constraints are activated, the feedback law changes indifferent parts of the state-space

Certainty equivalance used u = −K(x)x

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 46: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Explicit MPC Example

For the plant

Y (s) =1

s + 1U(s)

with constraints

−3 ≤ y(t) ≤ 3

−0.1 ≤ u(t) ≤ 0.1

−0.05 ≤ ∆u(t) ≤ 0.05

the regions might look like...

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 47: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

Explicit MPC Example

−3 −2 −1 0 1 2 3

−0.1

−0.05

0

0.05

0.1

x

u

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 48: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

CVXGEN

Developed at Stanford

CVXGEN generates fast custom code for small, QP-representableconvex optimization problems, using an online interface with nosoftware installation. With minimal effort, turn a mathematical problemdescription into a high speed solver.

See http://cvxgen.com/

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 49: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

CVXGEN

Describe your small, quadratic program (QP) representableproblem with a simple, powerful language.

CVXGEN automatically creates library-free C code for a custom,high-speed solver. This can be downloaded and usedimmediately, and requires nothing but a C compiler. CVXGENalso supplies a Matlab function that, with one command,downloads and builds a custom Matlab mex solver.

CVXGEN performs most transformations and optimizationsoffline, to make online solution as fast as possible. Codegeneration takes a few seconds or minutes, producing solversthat work in microseconds or milliseconds. Compared withgeneric code (CVX), solution times are typically at least 20 timesfaster, with the smallest problems showing speedup as large as10,000x

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 50: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

CVXGEN: MPC Example

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)

Page 51: Model Predictive Control (MPC) Bernhardsson and Karl Johan Åström Model Predictive Control (MPC) ... Supports linear, nonlinear, and hybrid system descriptions Explicit MPC (() +()

CVXGEN: MPC Example - Input Code

Bo Bernhardsson and Karl Johan Åström Model Predictive Control (MPC)