32
Model Predictive Control Linear time-varying and nonlinear MPC Alberto Bemporad http://cse.lab.imtlucca.it/~bemporad ©2019 A. Bemporad - "Model Predictive Control" 1/30

ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Model Predictive ControlLinear time-varying and nonlinear MPC

Alberto Bemporad

http://cse.lab.imtlucca.it/~bemporad

©2019 A. Bemporad - "Model Predictive Control" 1/30

Page 2: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

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

©2019 A. Bemporad - "Model Predictive Control" 2/30

Page 3: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Linear Time-Varying Model Predictive Control

Page 4: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LPV models

• Linear Parameter-Varying (LPV)model{xk+1 = A(p(t))xk +B(p(t))uk +Bv(p(t))vk

yk = C(p(t))xk +Dv(p(t))vk

that depends on a vector p(t) of parameters

• The weights in the quadratic performance index can also be LPV

• The resulting optimization problem is still a QP

minz

1

2z′H(p(t))z +

[x(t)r(t)

u(t−1)

]′F (p(t))′z

s.t. G(p(t))z ≤ W (p(t)) + S(p(t))

[x(t)r(t)

u(t−1)

]

• The QP matrices must be constructed online, contrarily to the LTI case

©2019 A. Bemporad - "Model Predictive Control" 3/30

Page 5: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Linearizing a nonlinear model: LPV case

• An LPV model can be obtained by linearizing the nonlinear model{xc(t) = f(xc(t), uc(t), pc(t))

yc(t) = g(xc(t), pc(t))

• pc ∈ Rnp = a vector of exogenous signals (e.g., ambient conditions)• At time t, consider nominal values xc(t), uc(t), pc(t) and linearize

d

dτ(xc(t+ τ)− xc(t)) =

d

dτ(xc(t+ τ)) ≃ ∂f

∂x

∣∣∣∣xc(t),uc(t),pc(t)︸ ︷︷ ︸

Ac(t)

(xc(t+ τ)− xc(t)) +

∂f

∂u

∣∣∣∣xc(t),uc(t),pc(t)︸ ︷︷ ︸

Bc(t)

(uc(t+ τ)− uc(t)) + f(xc(t), uc(t), pc(t))︸ ︷︷ ︸Bvc(t)

·1

• Convert (Ac, [Bc Bvc]) to discrete-time and get prediction model (A, [B Bv])

• Same thing for the output equation to get matricesC andDv

©2019 A. Bemporad - "Model Predictive Control" 4/30

Page 6: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV models

• Linear Time-Varying (LTV)model{xk+1 = Ak(t)xk +Bk(t)uk

yk = Ck(t)xk

• At each time t the model can also change over the prediction horizon k

• The measured disturbance is embedded in the model

• The resulting optimization problem is still a QP

minz

1

2z′H(t)z +

[x(t)r(t)

u(t−1)

]′F (t)′z

s.t. G(t)z ≤ W (t) + S(t)

[x(t)r(t)

u(t−1)

]• As for LPV-MPC, the QP matrices must be constructed online

©2019 A. Bemporad - "Model Predictive Control" 5/30

Page 7: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Linearizing a nonlinear model: LTV case• LPV/LTV models can be obtained by linearizing nonlinear models{

xc(t) = f(xc(t), uc(t), pc(t))

yc(t) = g(xc(t), pc(t))

• At time t, consider nominal trajectories

U = {uc(t), uc(t+ Ts), . . . , uc(t+ (N − 1)Ts)}(example: U = shifted previous optimal sequence or input ref. trajectory)

P = {pc(t), pc(t+ Ts), . . . , pc(t+ (N − 1)Ts)}(no preview: pc(t+ k) ≡ pc(t))

• Integrate the model and get nominal state/output trajectories

X = {xc(t), xc(t+ Ts), . . . , xc(t+ (N − 1)Ts)}Y = {yc(t), yc(t+ Ts), . . . , yc(t+ (N − 1)Ts)}

• Examples: xc(t) = current xc(t); xc(t) = equilibrium; xc(t) = reference

©2019 A. Bemporad - "Model Predictive Control" 6/30

Page 8: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Linearizing a nonlinear model: LTV case

• While integrating, also compute the sensitivities

Ak(t) =∂xc(t+ (k + 1)Ts)

xc(t+ kTs)

Bk(t) =∂xc(t+ (k + 1)Ts)

uc(t+ kTs)

Ck(t) =∂yc(t+ kTs)

xc(t+ kTs)

• Approximate the NL model as the LTV modelxk+1︷ ︸︸ ︷

xc(k + 1)− xc(k + 1) = Ak(t)

xk︷ ︸︸ ︷(xc(k)− xc(k))+Bk(t)

uk︷ ︸︸ ︷(uc(k)− uc(k))

yc(k)− yc(k)︸ ︷︷ ︸yk

= Ck(t) (xc(k)− xc(k))︸ ︷︷ ︸xk

©2019 A. Bemporad - "Model Predictive Control" 7/30

Page 9: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV-MPC example• Process model is LTV

d3y

dt3+ 3

d2y

dt2+ 2

dy

dt+ (6 + sin(5t))y = 5

du

dt+

(5 + 2 cos

(5

2t

))u

• LTI-MPC cannot track the setpoint, LPV-MPC tries to catch-up withtime-varying model, LTV-MPC has preview on future model values

(See demo TimeVaryingMPCControlOfATimeVaryingLinearSystemExample in MPC Toolbox)

©2019 A. Bemporad - "Model Predictive Control" 8/30

Page 10: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV-MPC example• Define LTV model

Models = tf; ct = 1;for t = 0:0.1:10

Models(:,:,ct) = tf([5 5+2*cos(2.5*t)],[1 3 2 6+sin(5*t)]);ct = ct + 1;

end

Ts = 0.1; % sampling timeModels = ss(c2d(Models,Ts));

• Design MPC controller

sys = ss(c2d(tf([5 5],[1 3 2 6]),Ts)); % average model timep = 3; % prediction horizonm = 3; % control horizonmpcobj = mpc(sys,Ts,p,m);

mpcobj.MV = struct('Min',-2,'Max',2); % input constraintsmpcobj.Weights = struct('MV',0,'MVRate',0.01,'Output',1);

©2019 A. Bemporad - "Model Predictive Control" 9/30

Page 11: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV-MPC example

• Simulate LTV system with LTI-MPC controller

for ct = 1:(Tstop/Ts+1)real_plant = Models(:,:,ct); % Get the current planty = real_plant.C*x;u = mpcmove(mpcobj,xmpc,y,1); % Apply LTI MPCx = real_plant.A*x + real_plant.B*u;

end

• Simulate LTV system with LPV-MPC controller

for ct = 1:(Tstop/Ts+1)real_plant = Models(:,:,ct); % Get the current planty = real_plant.C*x;u = mpcmoveAdaptive(mpcobj,xmpc,real_plant,nominal,y,1);x = real_plant.A*x + real_plant.B*u;

end

©2019 A. Bemporad - "Model Predictive Control" 10/30

Page 12: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

t

uy

Time-Varying Plant

AdaptiveMPC mv

model

mo

ref

Adaptive MPC Controller

t

A

B

C

D

U

Y

X

DX

Time Varying Predictive Model

Clock

usim

To Workspace

ysim

To Workspace1

Zero-OrderHold

1

Reference

LTV-MPC example• Simulate LTV system with LTV-MPC controller

for ct = 1:(Tstop/Ts+1)real_plant = Models(:,:,ct); % Get the current planty = real_plant.C*x;u = mpcmoveAdaptive(mpcobj,xmpc,Models(:,:,ct:ct+p),Nominals,y,1);x = real_plant.A*x + real_plant.B*u;

end

• Simulate in Simulink

mpc_timevarying.mdl

©2019 A. Bemporad - "Model Predictive Control" 11/30

Page 13: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV-MPC example• Simulink block

need to provide 3D arrayof future models

mpc_timevarying.mdl

©2019 A. Bemporad - "Model Predictive Control" 12/30

Page 14: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Tj

Tf

CAf

CAT

F

A�� B

Example: LPV-MPC of a nonlinear CSTR system

• MPC control of a diabatic continuous stirred tank reactor (CSTR)

• Process model is nonlinear

dCA

dt=

F

V(CAf − CA)− CAk0e

−∆ERT

dT

dt=

F

V(Tf − T ) +

UA

ρCpV(Tj − T )−

∆H

ρCpCAk0e

−∆ERT

– T : temperature inside the reactor [K] (state)

– CA : concentration of the reactant in the reactor [kgmol/m3] (state)

– Tj : jacket temperature [K] (input)

– Tf : feedstream temperature [K] (measured disturbance)

– CAf : feedstream concentration [kgmol/m3] (measured disturbance)

• Objective: manipulate Tj to regulate CA on desired setpoint

>> edit ampccstr_linearization (MPC Toolbox)

©2019 A. Bemporad - "Model Predictive Control" 13/30

Page 15: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

2CA

1T

Feed Concentration

Feed Temperature

Coolant Temperature

Reactor Temperature

Reactor Concentration

CSTR

3Tc

2Ti

1CAi

Example: LPV-MPC of a nonlinear CSTR systemProcess model:>> mpc_cstr_plant

% Create operating point specification.plant_mdl = 'mpc_cstr_plant';op = operspec(plant_mdl);

op.Inputs(1).u = 10; % Feed concentration known @initial conditionop.Inputs(1).Known = true;op.Inputs(2).u = 298.15; % Feed concentration known @initial conditionop.Inputs(2).Known = true;op.Inputs(3).u = 298.15; % Coolant temperature known @initial conditionop.Inputs(3).Known = true;

[op_point, op_report] = findop(plant_mdl,op); % Compute initial condition

x0 = [op_report.States(1).x;op_report.States(2).x];y0 = [op_report.Outputs(1).y;op_report.Outputs(2).y];u0 = [op_report.Inputs(1).u;op_report.Inputs(2).u;op_report.Inputs(3).u];

% Obtain linear plant model at the initial condition.sys = linearize(plant_mdl, op_point);sys = sys(:,2:3); % First plant input CAi dropped because not used by MPC

©2019 A. Bemporad - "Model Predictive Control" 14/30

Page 16: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LPV-MPC of a nonlinear CSTR system

• MPC design

% Discretize the plant modelTs = 0.5; % hoursplant = c2d(sys,Ts);

% Design MPC Controller

% Specify signal types used in MPCplant.InputGroup.MeasuredDisturbances = 1;plant.InputGroup.ManipulatedVariables = 2;plant.OutputGroup.Measured = 1;plant.OutputGroup.Unmeasured = 2;plant.InputName = 'Ti','Tc';plant.OutputName = 'T','CA';

% Create MPC controller with default prediction and control horizonsmpcobj = mpc(plant);

% Set nominal values in the controllermpcobj.Model.Nominal = struct('X', x0, 'U', u0(2:3), 'Y', y0, 'DX', [0 0]);

©2019 A. Bemporad - "Model Predictive Control" 15/30

Page 17: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LPV-MPC of a nonlinear CSTR system

• MPC design (cont’d)

% Set scale factors because plant input and output signals have different% orders of magnitudeUscale = [30 50];Yscale = [50 10];mpcobj.DV(1).ScaleFactor = Uscale(1);mpcobj.MV(1).ScaleFactor = Uscale(2);mpcobj.OV(1).ScaleFactor = Yscale(1);mpcobj.OV(2).ScaleFactor = Yscale(2);

% Let reactor temperature T float (i.e. with no setpoint tracking error% penalty), because the objective is to control reactor concentration CA% and only one manipulated variable (coolant temperature Tc) is available.mpcobj.Weights.OV = [0 1];

% Due to the physical constraint of coolant jacket, Tc rate of change is% bounded by degrees per minute.mpcobj.MV.RateMin = -2;mpcobj.MV.RateMax = 2;

©2019 A. Bemporad - "Model Predictive Control" 16/30

Page 18: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LPV-MPC of a nonlinear CSTR system• Simulink diagram

Copyright 1990-2014 The MathWorks, Inc.

Concentration

33

Temperature3

3

MeasurementNoise

33

CA Reference

2

0

u0(1)

Selector

3

u0(2)

Disturbance

T

CA

CAi

Ti

Tc

A

B

C

D

U

Y

X

DX

poles

Successive Linearizer

[2x1]

[2x1]

[2x1]

[2x1]

[2x1]

[2x2]

[2x2]

[2x2]

[2x2] 8{24}

[2x1]

[2x1]

[2x1]

[2x1]

[2x2]

[2x2]

[2x2]

[2x2]

22

32

2

u0(1)

CAi

Ti

Tc

T

CA

CSTR

Pole[2x1]

AdaptiveMPC

mvmodel

mo

ref

mdest.state

Adaptive MPC Controller

3

2

8{24}

Reference

Feed

Coolant

Reactor

Estimated

A

B

C

D

U

Y

X

DX

True

Poles

plant model

LPV-MPC

linearize + discretize

>> edit ampc_cstr_linearization

©2019 A. Bemporad - "Model Predictive Control" 17/30

Page 19: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LPV-MPC of a nonlinear CSTR system

• Closed-loop results

©2019 A. Bemporad - "Model Predictive Control" 18/30

Page 20: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LTI-MPC of a nonlinear CSTR system

• Closed-loop results with LTI-MPC, same tuning

Copyright 1990-2014 The MathWorks, Inc.Concentration

22

Temperature3

3

Noise

33

CA Reference

2

0

u0(1)

CAi

CAi

Ti

Tc

T

CA

CSTR

u0(2)

Ti

Disturbance

MPCmv

mo

ref

md

MPC Controller

2

Reference

Feed

Coolant

Reactor

True

LTI-MPC

©2019 A. Bemporad - "Model Predictive Control" 19/30

Page 21: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Example: LTI-MPC of a nonlinear CSTR system

• Closed-loop results

©2019 A. Bemporad - "Model Predictive Control" 20/30

Page 22: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV Kalman filter

• Process model = LTV model with noise

x(k + 1) = A(k)x(k) +B(k)u(k)+G(k)ξ(k)

y(k) = C(k)x(k) + ζ(k)

• ξ(k) ∈ Rq = zero-mean white process noisewith covarianceQ(k) ≽ 0

• ζ(k) ∈ Rp = zero-mean whitemeasurement noisewith covarianceR(k) ≻ 0

• measurement update:

M(k) = P (k|k − 1)C(k)′[C(k)P (k|k − 1)C(k)′ +R(k)]−1

x(k|k) = x(k|k − 1) +M(k) (y(k)− C(k)x(k|k − 1))

P (k|k) = (I −M(k)C(k))P (k|k − 1)

• time update:

x(k + 1|k) = A(k)x(k|k) +B(k)u(k)

P (k + 1|k) = A(k)P (k|k)A(k)′ +G(k)Q(k)G(k)′

©2019 A. Bemporad - "Model Predictive Control" 21/30

Page 23: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Extended Kalman filter• Process model = nonlinear model with noise

x(k + 1) = f(x(k), u(k), ξ(k))

y(k) = g(x(k), u(k)) + ζ(k)

• measurement update:

C(k) =∂g

∂x(xk|k−1, u(k))

M(k) = P (k|k − 1)C(k)′[C(k)P (k|k − 1)C(k)′ +R(k)]−1

x(k|k) = x(k|k − 1) +M(k) (y(k)− g(x(k|k − 1), u(k)))

P (k|k) = (I −M(k)C(k))P (k|k − 1)

• time update:

x(k + 1|k) = f(x(k|k), u(k))

A(k) =∂f

∂x(xk|k, u(k), E[ξ(k)]), G(k) =

∂f

∂ξ(xk|k, u(k), E[ξ(k)])

P (k + 1|k) = A(k)P (k|k)A(k)′ +G(k)Q(k)G(k)′

©2019 A. Bemporad - "Model Predictive Control" 22/30

Page 24: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Nonlinear Model Predictive Control

Page 25: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Nonlinear MPC(Mayne, Rawlings, Diehl, 2017)

• Nonlinear prediction model{xk+1 = f(xk, uk)

yk = g(xk, uk)

• Nonlinear constraints h(xk, uk) ≤ 0

• Nonlinear performance indexmin ℓN (xN ) +

N−1∑k=0

ℓ(xk, uk)

• Optimization problem: nonlinear programming problem (NLP)

minz F (z, x(t))

s.t. G(z, x(t)) ≤ 0

H(z, x(t)) = 0

z =

u0

...uN−1x1

...xN

©2019 A. Bemporad - "Model Predictive Control" 23/30

Page 26: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Nonlinear optimization

(Nocedal,Wright, 2006)

• (Nonconvex) NLP is harder to solve than QP

• Convergence to a global optimummay not be guaranteed

• Several NLP solvers exist (such as Sequential Quadratic Programming (SQP))

• NL-MPC is not used in practice so often, except for dealing with strongdynamical nonlinearities and slow processes (such as chemical processes)

©2019 A. Bemporad - "Model Predictive Control" 24/30

Page 27: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Fast nonlinear MPC(Lopez-Negrete, D’Amato, Biegler, Kumar, 2013)

• Fast MPC: exploit sensitivity analysis to compensate for the computationaldelay caused by solving the NLP

• Key idea: pre-solve the NLP between time t− 1 and t based on the predictedstate x∗(t) = f(x(t− 1), u(t− 1)) in background

• Get u∗(t) and sensitivity∂u∗

∂x

∣∣∣∣x∗(t)

within sample interval [(t− 1)Ts, tTs)

• At time t, get x(t) and compute

u(t) = u∗(t) +∂u∗

∂x(x(t)− x∗(t))

• Note that still one NLP must be solved within the sample interval

©2019 A. Bemporad - "Model Predictive Control" 25/30

Page 28: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

From LTV-MPC to NL-MPC

• Key idea: Solve a sequence of LTV-MPC problems at the same time t

• Given the current state x(t) and reference {r(t+ k), ur(t+ k)}, initial guessU0 = {u0

0, . . . , u0N−1} and corresponding state trajectoryX0 = {x0

0, . . . , x0N}

• A good initial guess U0, X0 is the previous (shifted) optimal solution

• At a generic iteration i, linearize the NL model around Ui, Xi:{xk+1 = f(xk, uk)

yk = g(xk)

Ai =∂f(xi

0, ui0)

∂x, Bi =

∂f(xi0, u

i0)

∂u, Ci =

∂g(xi0, u

i0)

∂x

©2019 A. Bemporad - "Model Predictive Control" 26/30

Page 29: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Nonlinear MPC

For h = 0 to hmax − 1 do:1. Simulate from x(t)with inputs Uh, parameter sequence P and get state

trajectoryXh and output trajectory Yh

2. Linearize around (Xh, Uh, P ) and discretize in time with sample time Ts

3. Let U∗h+1 be the solution of the QP problem corresponding to LTV-MPC

4. Find optimal step size αh ∈ (0, 1];5. Set Uh+1 = (1− αh)Uh + αhU

∗h+1;

Return solution Uhmax

• The method above is a Gauss-Newton method to solve the NL-MPC problem

• Special case: just solve one iteration with α = 1 (a.k.a. Real-Time Iteration)(Diehl, Bock, Schloder, Findeisen, Nagy, Allgower, 2002)

©2019 A. Bemporad - "Model Predictive Control" 27/30

Page 30: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Nonlinear MPC(Gros, Zanon, Quirynen, Bemporad, Diehl, 2016)

• Example8

2 4 6 8 10 12 14 16 18 20-5

0

5

10

x1

2 4 6 8 10 12 14 16 18 20-2

0

2

4

x2

2 4 6 8 10 12 14 16 18 20

-0.4

-0.2

0

0.2

u1

time

Linear MPC

RTI

Fully converged

Linear MPC

RTI

Fully converged

Linear MPCRTIConverged

Fig. 7. Illustration of the RTI solution vs. the linear MPC solutions at thediscrete time instant i = 2, with state noise.

0 5 10 15 20 25 30

0

1

2

3

4

x1

0 5 10 15 20 25 30

0

1

2

3

4

x2

0 5 10 15 20 25 30

-0.4

-0.2

0

0.2

u1

time

Linear MPCRTIConverged

Fig. 8. Illustration of the RTI solution vs. the linear MPC solutions inclosed-loop simulations, without state noise.

0 5 10 15 20 25 30-1

0

1

2

3

4

x1

0 5 10 15 20 25 30-1

0

1

2

3

4

x20 5 10 15 20 25 30

-0.4

-0.2

0

0.2

u1

time

Linear MPCRTIConverged

Fig. 9. Illustration of the RTI solution vs. the linear MPC solutions inclosed-loop simulations, with state noise of covariance 0.1.

the system is readily described as a discrete dynamic system,such as when the model is identified from input/output data,computing f (x,u) and — f (x,u) is straightforward. However,in many applications, the system dynamics are available in acontinuous form, typically as an Ordinary Differential Equa-tion (ODE) of the form:

x(t) = F (x(t),u(t)) . (23)

In this section, we will present a family of numerical meth-ods for simulation and sensitivity generation. It is importantto stress that the well-known matrix exponential can alsobe considered as such a method for numerical simulation.However, depending on the system considered, other methodsmight be more accurate and less computationally intensive.We also want to stress the fact that several integration stepscan be taken inside each control interval in order to increasethe accuracy of the simulation. We will also sketch how thesensitivities can be propagated in case multiple integrationsteps are taken.

For the sake of simplicity we consider here an explicitODE having time-invariant dynamics, though the followingdevelopments can be easily extended to the time-varying caseand to implicit ODE or Differential Algebraic Equation (DAE)systems.

Let us consider a piecewise constant discretization of the

©2019 A. Bemporad - "Model Predictive Control" 28/30

Page 31: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

Learning nonlinear models for MPC(Masti, Bemporad, CDC 2018)

• Idea: use autoencoders and artificial neural networks to learn a nonlinearstate-space model of desired order from input/output data

(Hinton, Salakhutdinov, 2006)

dead-beat observer

output map

state map

Ok = [y′k . . . y′

k−m]′

Ik = [y′k . . . y′

k−na+1 u′k . . . u′

k−nb+1]′

©2019 A. Bemporad - "Model Predictive Control" 29/30

Page 32: ModelPredictiveControlcse.lab.imtlucca.it/~bemporad/teaching/mpc/imt/2-ltv_nl... · 2019-04-02 · • Simulink block needtoprovide3Darray offuturemodels mpc_timevarying.mdl ©2019A.Bemporad-"ModelPredictiveControl"

LTV MPC

● The performance achieved with the derivative-based controller suggests that an LTV-MPC formulation might also works well. We also assess its robustness using a model achieving 61% BFR in open loop

ODYS CONFIDENTIAL

Computation time per step: ~40ms

LTV-MPC results

Learning nonlinear models for MPC - An example(Masti, Bemporad, CDC 2018)

• System generating the data = nonlinear 2-tank benchmark

www.mathworks.com

x1(k + 1) = x1(k)− k1

√x1(k) + k2(u(k) + w(k))

x2(k + 1) = x2(k) + k3√

x1(k)− k4√

x2(k)

y(k) = x2(k) + v(k)

Model is totally unknown to learning algorithm

• Artificial neural network (ANN): 3 hidden layers60 exponential linear unit (ELU) neurons

• For given number of model parameters,autoencoder approach is superior to NNARX

• Jacobians directly obtained from ANN structurefor Kalman filtering & MPC problem construction

©2019 A. Bemporad - "Model Predictive Control" 30/30