40
ECE7850 Wei Zhang ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model Predictive Control for Constrained Linear Systems Online Solution to Linear MPC Multiparametric Programming Explicit Linear MPC Examples • MPC for Discrete Time Hybrid Systems Discrete Time Hybrid System Models: General Modeling Framework, Piecewise Affine System, Mixed Logical Dynamical System Online Solution to Hybrid MPC Explicit Hybrid MPC Hybrid MPC Examples 1

ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

ECE7850 Lecture 9

Model Predictive Control: Computational Aspects

• Model Predictive Control for Constrained Linear Systems

– Online Solution to Linear MPC

– Multiparametric Programming

– Explicit Linear MPC

– Examples

• MPC for Discrete Time Hybrid Systems

– Discrete Time Hybrid System Models: General Modeling Framework, Piecewise AffineSystem, Mixed Logical Dynamical System

– Online Solution to Hybrid MPC

– Explicit Hybrid MPC

– Hybrid MPC Examples

1

Page 2: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

Linear MPC Problem

• At time t: solve the following N -horizon optimal control problem:

PN(x(t)) : VN(x(t)) =

⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

minu J(x(t), U0) � Jf(xN) + ∑N−1k=0 l(xk, uk)

subj. to: xk+1 = Axk + Buk, k = 0, . . . , N − 1Axxk ≤ bx, Auuk ≤ bu, k = 0, . . . , N − 1AfxN ≤ bf, x0 = x(t)

(1)

• Polyhedral state/control constraints: Axxk ≤ bx, Auuk ≤ bu, AfxN ≤ bf

• Cost functions JN(x(t), u): 2-norm, 1-norm, ∞-norm

– 2-norm: xTNQfxN + ∑N−1

k=0(xT

k Qxk + uTk Ruk

)

– 1/∞-norm: ‖QfxN‖p + ∑N−1k=0 (‖Qxk‖p + ‖Ruk‖p), p = 1, ∞, Q, Qf, R are full column rank

matrices

– Recall: ‖x‖1 = ∑i

|xi| and ‖x‖∞ = maxi |xi|

Linear MPC Problem 2

Page 3: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

Batch Formulation of Linear MPC

• Vector form of prediction model over N horizon:⎡⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣

x(t)x1......

xN

⎤⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎦

︸ ︷︷ ︸X

=

⎡⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣

I

A......

AN

⎤⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎦

︸ ︷︷ ︸Sx

x(t) +

⎡⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣

0 · · · · · · 0B 0 · · · 0

AB . . . . . . ...... . . . . . . ...

AN−1B · · · · · · B

⎤⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎦

︸ ︷︷ ︸Su

⎡⎢⎢⎢⎢⎢⎢⎢⎢⎣

u0......

uN−1

⎤⎥⎥⎥⎥⎥⎥⎥⎥⎦

︸ ︷︷ ︸U0

(2)

• Define X = Sxx(t) + SuU0

• 2-norm cost function becomes: J0(x(0), U0) = X T Q̄X +U0T R̄U0,

– Q̄ � diag{Q, . . . , Q, Qf}, Q̄ � 0

– R̄ � diag{R, . . . , R}, R̄ � 0

Batch Formulation of Linear MPC 3

Page 4: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Substituting the expression of X ⇒:

JN(x(t), U0) = (Sxx(t) + SuU0)T Q̄(Sxx(t) + SuU0) + U0T R̄U0

= U0T ((Su)T Q̄Su + R̄)︸ ︷︷ ︸

H

U0 + 2xT (t)(Sx)T Q̄Su

︸ ︷︷ ︸F

U0 + xT (t)((Sx)T Q̄Sx)︸ ︷︷ ︸Y

x(t)

= U0T HU0 + 2xT (t)FU0 + xT (t)Y x(t)

=[UT

0 , x(t)T] ⎡

⎢⎣ H F T

F Y

⎤⎥⎦

⎡⎢⎣ U0

x(t)

⎤⎥⎦

• Polyhedral constraints can be reduced to:

G0U0 ≤ w + E0x(t)

where G0, w0, E0, x(t) are known matrices/vectors at time t.

Batch Formulation of Linear MPC 4

Page 5: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• PN(x(t)) boils down to a quadratic programming (QP) problem:

VN(x(t)) =

⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

minU0 JN(x(t), U0) =[UT

0 , x(t)T] ⎡

⎢⎢⎣H F T

F Y

⎤⎥⎥⎦

⎡⎢⎢⎣

U0

x(t)

⎤⎥⎥⎦

subj. to G0U0 ≤ w0 + E0x(t)(3)

– QP with affine constraints is a special class of convex programs, which can be solved

very efficiently

– Optimization variable is U0; all parameters are known and constant;

– x(t) is the measured state at each time t, which is also known before solving the QP.

– MATLAB quadratic programming function: quadprog

Batch Formulation of Linear MPC 5

Page 6: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

Explicit Linear MPC

• Online solution: given x(t) at each time t compute a control action u∗0 by solving the QP (3)

• Offline solution (Explicit MPC): pre-compute the control law U ∗0 (z) for all possible state

location x(t) = z. The online implementation of the controller only involves evaluating the

law at a given state u∗0 = U∗

0 (x(t))

• Simplest case: no state and control constraint ⇒U ∗0 (x(t)) = −H−1F Tx(t)

• With polyhedral state and control constraints, explicit solution can be obtained through mul-

tiparametrix programming

Explicit Linear MPC 6

Page 7: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Multiparametric programming problem:

J∗(x) =⎧⎪⎪⎨⎪⎪⎩

minv J(x, v)subj. to. Gv ≤ w + Sx

(4)

• optimization variable is v ∈ Rnv, while x ∈ R

n is viewed as a parameter of the problem

• Minimum cost J ∗(x) is also called a value function, the minimizer function is parameter

dependent:

v∗(x) = argminv{J(x, v) : Gv ≤ w + Sx} (5)

• multiparametric programming studies properties of the value function J ∗(x) and minimizer

function v∗(x) w.r.t. parameter x

• region of feasible parameters: K = {x ∈ Rn : ∃v ∈ R

nv s.t. Gv ≤ w + Sx}

• Assume (i) K is full dimensional polytope in Rn; (ii) S is full column rank

Explicit Linear MPC 7

Page 8: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Multiparametric Linear Programming (mp-LP)

– J∗(x) = minv{cT v : subj. to Gv ≤ w + Sx};

– v∗(x) = argminu{cT v : subj. to Gv ≤ w + Sx}

– Theorem 1 (mp-LP): There exists a polyhedral partition of K such that

* J∗(x) is affine in each partition

* There exists a minimizer function v∗(x) that is affine in each partition

* J∗(x) is convex on K

Explicit Linear MPC 8

Page 9: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Multiparametric Quadratic Programming (mp-QP):

– J∗(x) = minv{vT Hv : subj. to Gv ≤ w + Sx};

– v∗(x) = argminu{vTHv : subj. to Gv ≤ w + Sx}

– Theorem 2 (mp-LP): There exists a polyhedral partition of K such that

* J∗(x) is continuous, convex, and piecewise quadratic

* v∗(x) is continuous and piecewise affine

Explicit Linear MPC 9

Page 10: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Explicit MPC using multiparameteric programming:

– 2 norm case: U ∗0 (x(t)) = argminU0

{UT

0 HU0 + x(t)TFU0 : G0U0 ≤ w0 + S0x(t)}

* can be transformed to standard mp-QP problem with v = U0 + H−1F Tx(t).

* ⇒ explicit MPC law is of the form:

U∗0 (x(t)) =

⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

F1x(t) + f1 if H1x(t) ≤ h1... ...

FMx(t) + fM if HMx(t) ≤ hM

(6)

* can be solved efficiently using Multi-Parametric Toolbox

Explicit Linear MPC 10

Page 11: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– (∞-norm) case: U ∗0 (x(t)) = argminU0{JN(x(t), U0) : G0U0 ≤ w0 + S0x(t)}, where

JN(x(t), U0) =N−1∑k=0

(‖Qxk‖∞ + ‖Ruk‖∞) (7)

* Note: minx{|x| : h(x) ≤ 0} ⇔ minx,ε{ε : ε ≥ x, ε ≥ −x, h(x) ≤ 0}

* introduce slack variables:

⎧⎪⎪⎨⎪⎪⎩εx

k ≥ ‖Qxk‖∞εu

k ≥ ‖Ruk‖∞⇒

⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

εxk ≥ [Qxk]i, i = 1, . . . , n k = 1, . . . , N − 1

εxk ≥ −[Qxk]i i = 1, . . . , n k = 1, . . . , N − 1

εuk ≥ [Ruk]i i = 1, . . . , m k = 1, . . . , N − 1

εuk ≥ −[Ruk]i i = 1, . . . , m k = 1, . . . , N − 1

Explicit Linear MPC 11

Page 12: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

* The problem reduces to an optimization problem of the following form:⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩min

ξ

N−1∑k

εxk + εu

k

subj. to Gξ ≤ W + Sx(t)(8)

where ξ = {εx1, . . . , εx

N−1, εu0, . . . , εu

N−1, u0, . . . , uN−1}.

* Therefore, the ∞-norm linear MPC problem can be reformulated as an mp-LP problem

* U∗0 (x) is also piecewise affine that can computed using the Multi-Parametric Toolbox

– 1-norm explicit MPC can also be formulated as an mp-LP problem

– See Borrelli’s book for details.

Explicit Linear MPC 12

Page 13: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

Examples for Linear MPC

• Example 1 Compute R−j (S), R+

j (S), O∗ and C∗

Consider the second order system

x(t + 1) = α

⎡⎢⎣ cos π

4 − sin π4

sin π4 cos π

4

⎤⎥⎦ x(t) +

⎡⎢⎣ 1

0

⎤⎥⎦ u(t) (9)

subject to the input and state constraints

X =⎧⎪⎨⎪⎩x|

⎡⎢⎣ −10

−10

⎤⎥⎦ ≤ x(t) ≤

⎡⎢⎣ 10

10

⎤⎥⎦

⎫⎪⎬⎪⎭ , ∀t ≥ 0

U = {u| − 5 ≤ u(t) ≤ 5}, ∀t ≥ 0

The target set or initial set S is given as

S =⎧⎪⎨⎪⎩x|

⎡⎢⎣ −8

−8

⎤⎥⎦ ≤ x(t) ≤

⎡⎢⎣ 8

8

⎤⎥⎦

⎫⎪⎬⎪⎭ , ∀t ≥ 0

Examples for Linear MPC 13

Page 14: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-15 -10 -5 0 5 10 15-15

-10

-5

0

5

10

15

x1

x 2 R4- (S)

S

X

R3- (S) R2

- (S)

R1- (S)

-200 -150 -100 -50 0 50 100 150 200-200

-150

-100

-50

0

50

100

150

200

x1

x 2 R3+(S)

R1+(S) X

R2+(S)

R4+(S)

S

Suppose α = 2 in (1), compute the j-step backward (and forward) reachable sets R−j (S)

(and R+j (S)), for j = 1, 2, 3, 4, respectively.

>> [Xpre,XpreandX] = pre_function(sysStruct,X);

>> [Rsets, Vsets] = mpt_reachSets(sysStruct, X0, U0, N);

Examples for Linear MPC 14

Page 15: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-20 -15 -10 -5 0 5 10 15 20-15

-10

-5

0

5

10

15

x1

x 2

XS

O*

– Left: maximal control invariant set C∗ can be obtained after 28 iterations (α = 2).

>> [Cinf,iterations, Piter] = mpt_maxCtrlSet(sysStruct);

– Right: maximal positive invariant set O∗ for α = 1

>> [Oinf,tstar,fd,isemptypoly] = mpt_infset(A,X,tmax);

Examples for Linear MPC 15

Page 16: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Example 2 Persistent feasibility problem

Consider the double integrator system

x(t + 1) =⎡⎢⎣ 1 1

0 1

⎤⎥⎦ x(t) +

⎡⎢⎣ 0

1

⎤⎥⎦ u(t) (10)

with Jf(xN) = xTNP xN , l(xk, uk) = xT

k Qxk + uTk Ruk, P = Q =

⎡⎢⎣ 1 0

0 1

⎤⎥⎦, R = 10, N = 3, p = 2 and

Xf = R2, subject to the input constraints

−0.5 ≤ u(k) ≤ 0.5, k = 0, . . . , N − 1 (11)

and the state constraints

⎡⎢⎣ −5

−5

⎤⎥⎦ ≤ x(k) ≤

⎡⎢⎣ 5

5

⎤⎥⎦ , k = 0, . . . , N − 1. (12)

Examples for Linear MPC 16

Page 17: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-5 -4 -3 -2 -1 0 1 2 3 4 5-5

-4

-3

-2

-1

0

1

2

3

4

5

x1

x 2

Set of initial feasible states X0

Maximal positive invariant set O*

-5 -4 -3 -2 -1 0 1 2 3 4 5-5

-4

-3

-2

-1

0

1

2

3

4

5

x1

x 2

– X0 is not control invariant;

– state in X0 \ O∗ are not persistently feasible as shown in the right figure.

1 >> ctrl = mpt_control(sysStruct , probStruct);2 >> invCtrl = mpt_invariantSet(ctrl);3 >> [X,U,cost , trajectory]= mpt_plotTrajectory(ctrl);

Examples for Linear MPC 17

Page 18: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-5 -4 -3 -2 -1 0 1 2 3 4 5-3

-2

-1

0

1

2

3

x1

x 2

X0Xf

-5 -4 -3 -2 -1 0 1 2 3 4 5-3

-2

-1

0

1

2

3

x1

x 2

– Choose Xf as control invariant set (obtained through LQR)

– MPC problem is persistently feasible.

1 >> [K,P,E] = dlqr(sysStruct.A, sysStruct.B, probStruct.Q, probStruct.R);2 >> [Oinf ,tstar ,fd ,isemptypoly] = mpt_infset(sysStruct.A- sysStruct.B*K,X,...

tmax);3 >> ctrl = mpt_control(sysStruct , probStruct);

Examples for Linear MPC 18

Page 19: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Example 3 Receding Horizon Control of Constrained Linear Systems:

Consider the double integrator system (10) with the input constraints

−1 ≤ u(k) ≤ 1, k = 0, . . . , N − 1

and the state constraints

⎡⎢⎣ −10

−10

⎤⎥⎦ ≤ x(k) ≤

⎡⎢⎣ 10

10

⎤⎥⎦ , k = 0, . . . , N − 1.

– Let Qf = Q =⎡⎢⎣ 1 0

0 1

⎤⎥⎦, R = 10

– We will consider both 2-norm and ∞-norm case (see slide 2)

Examples for Linear MPC 19

Page 20: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 1: p = 2, N = 3, Xf = 0,

-4 -3 -2 -1 0 1 2 3 4-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x1

x 2

0 10 20 30 40 50-1

0

1

2Evolution of states

Sampling Instances

Sta

tes

x1x2

0 10 20 30 40 50-0.5

0

0.5

1

1.5

2Evolution of outputs

Sampling Instances

Out

puts

y1

0 10 20 30 40 50-0.1

0

0.1

0.2

0.3

0.4Evolution of control moves

Sampling Instances

Inpu

ts

u1

0 10 20 30 40 500

0.5

1

1.5

2Active dynamics

Sampling Instances

Dyn

amic

s

1 probStruct. Tconstraint = 2;2 Xzero= polytope([eye (2);-eye (2) ] ,[0*sysStruct.xmax+1e -5;0* sysStruct.xmin...

+1e -5]);3 probStruct.Tset=Xzero;4 ctrl = mpt_control(sysStruct , probStruct);5 plot(ctrl.Pn); simplot(ctrl ,x0 ,Nsteps);

Examples for Linear MPC 20

Page 21: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 2: p = 2, N = 3, Xf is LQR set,

-6 -4 -2 0 2 4 6-2.5

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

2.5

x1

x 2

0 10 20 30 40 50-2

-1

0

1

2Evolution of states

Sampling Instances

Sta

tes

x1x2

0 10 20 30 40 50-2

-1

0

1

2Evolution of outputs

Sampling Instances

Out

puts

y1

0 10 20 30 40 50-0.1

0

0.1

0.2

0.3Evolution of control moves

Sampling Instances

Inpu

ts

u1

0 10 20 30 40 500

0.5

1

1.5

2Active dynamics

Sampling Instances

Dyn

amic

s

* Feasible region X0 increased as we increase the terminal constraint set Xf

1 probStruct.Tset=Oinf;2 ctrl = mpt_control(sysStruct , probStruct);

Examples for Linear MPC 21

Page 22: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-10-5

05

-4-2

02

40

10

20

30

40

50

60

70

80

x1

Value function over 7 regions

x2

J* (x)

-5

0

5

-2-1

01

2-0.5

0

0.5

x1

Value of the control action U1 over 7 regions

x2

U* 1(x

)

* Show the value function and control law

1 mpt_plotJ(ctrl);2 mpt_plotU(ctrl);3 ctrl1 = mpt_lyapunov(ctrl , 'quad '); %% solve a quadratic Lyapunov ...

function.4 ctrl1. details.lyapunov5 P =[3.8147 4.8687; 4.8687 13.7039};

Examples for Linear MPC 22

Page 23: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 3: p = 2, N = 5, Xf = X, i.e, no terminal state constraints

-6 -4 -2 0 2 4 6-3

-2

-1

0

1

2

3

x1

x 2

0 10 20 30 40 50-1

0

1

2Evolution of states

Sampling Instances

Sta

tes

x1x2

0 10 20 30 40 50-0.5

0

0.5

1

1.5

2Evolution of outputs

Sampling Instances

Out

puts

y1

0 10 20 30 40 50-0.1

0

0.1

0.2

0.3

0.4Evolution of control moves

Sampling Instances

Inpu

ts

u1

0 10 20 30 40 500

0.5

1

1.5

2Active dynamics

Sampling Instances

Dyn

amic

s

– Choose Xf = X leads to a larger initial feasible set X0

>> probStruct.Tconstraint = 0;

Examples for Linear MPC 23

Page 24: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 4: p = inf, N = 5, Xf = X, i.e, no terminal state constraints,

-6 -4 -2 0 2 4 6-3

-2

-1

0

1

2

3

x1

x 2

0 10 20 30 40 50-1

0

1

2Evolution of states

Sampling Instances

Sta

tes

x1x2

0 10 20 30 40 50-1

0

1

2Evolution of outputs

Sampling Instances

Out

puts

y1

0 10 20 30 40 50-0.2

0

0.2

0.4

0.6Evolution of control moves

Sampling Instances

Inpu

ts

u1

0 10 20 30 40 500

0.5

1

1.5

2Active dynamics

Sampling Instances

Dyn

amic

s

* The size of feasible regions is independent of norm (Case 3 and Case 4).

* Comparing feasible regions X0: case 4 = case 3 > case 2 > case 1

Examples for Linear MPC 24

Page 25: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

Hybrid System Models

• Piecewise affine (PWA) systems⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

x(t + 1) = Ai(t)x(t) + Bi(t)u(t) + fi(t)

y(t) = Ci(t)x(t) + Di(t)u(t) + gi(t)

Hi(t)x(t) + Ji(t)u(t) ≤ Ki(t)

– state: x(t) ∈ Rn

– control: u(t) ∈ Rm

– output: y(t) ∈ Rp

– mode: i(t) ∈ L � {1, . . . M}

C7

C4

C2

C1

C3

C6

C5

x-space

Hybrid System Models 25

Page 26: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Discrete hybrid automaton (DHA)

E

1

s

y

vd

Fd

u v

S

Mx

u

d

i

...

– connection of a finite state machine (FSM) and a switched affine system (SAS), through

a mode selector (MS) and an event generator (EG).

Hybrid System Models 26

Page 27: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Switched Affine System (SAS)

⎧⎪⎪⎨⎪⎪⎩xc(t + 1) = Ai(t)xc(t) + Bi(t)uc(t) + fi(t)

yc(t) = Ci(t)xc(t) + Di(t)uc(t) + gi(t) (13)

* xc ∈ Rnc, uc ∈ R

mc, yc ∈ Rpc, i(t) ∈ L � {1, . . . s}

– Event Generator (EG)

Event generated by function of state and control input:

δe(t) = h(xc(t), uc(t)) (14)

hi(xc, uc) =⎧⎪⎪⎨⎪⎪⎩1 if Hixc + Jiuc + Ki ≤ 00 if Hixc + Jiuc + Ki > 0

(15)

where δe(t) ∈ {0, 1}ne.

Hybrid System Models 27

Page 28: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Finite State Machine (FSM): binary state of the finite state machine evolves according to

a Boolean state update function:

⎧⎪⎪⎨⎪⎪⎩xl(t + 1) = fl(xl(t), ul(t), δe(t))yl(t) = gl(xl(t), ul(t), δe(t))

(16)

where xl ∈ {0, 1}nl is the binary state, ul ∈ {0, 1}ml is the exogenous binary input, δe(t) is

the endogenous binary input coming from the EG

– Mode Selector (MS)

i(t) = fM(xl(t), ul(t), δe(t)) (17)

where i(t) ∈ {0, 1}ns, nM = �log2 s�.

Hybrid System Models 28

Page 29: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– DHA Trajectories

For a given initial condition⎡⎢⎣ xc(0)

xl(0)

⎤⎥⎦ ∈ R

nc × {0, 1}nl, and inputs⎡⎢⎣ uc(t)

ul(t)

⎤⎥⎦ ∈ R

mc × {0, 1}ml,

the state x(t) of the system evolves according to:⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

δe(t) = h(xc(t), uc(t), t)i(t) = fM(xl(t), ul(t), δe(t))yc(t) = Ci(t)xc(t) + Di(t)uc(t) + gi(t)

yl(t) = gl(xl(t), ul(t), δe(t))xc(t + 1) = Ai(t)xc(t) + Bi(t)uc(t) + fi(t)

xl(t + 1) = fl(xl(t), ul(t), δe(t))

(18)

Hybrid System Models 29

Page 30: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Proposition: Any logic formula involving Boolean variables and linear combinations of con-

tinuous variables can be translated into a set of (mixed-)integer linear (in)equalities

– e.g.: X1 ∨ X2 = TRUE ⇒ δ1 + δ2 ≥ 1, δ1, δ2 ∈ {0, 1}

– FSM and Mode selector: any logic statement f(X) = TRUE can be written

⎧⎪⎪⎪⎨⎪⎪⎪⎩

m∧j=1

(∨i∈Pj

Xi ∨j∈Nj¬Xi

)

Nj, Pj ⊆ {1, . . . n}⇒

⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

∑i∈P1 δi + ∑

i∈N1(1 − δi) ≥ 1...∑

i∈Pm δi + ∑i∈Nm(1 − δi) ≥ 1

– Event generator: [δie(t) = 1] ↔ [Hixc(t) ≤ W i] ⇒

⎧⎪⎪⎨⎪⎪⎩Hixc(t) − W i ≤ M(1 − δi

e)Hixc(t) − W i > miδi

e

– Switched affine system:

⎧⎪⎪⎨⎪⎪⎩

if [δ = 1] then z = aT1 x + bT

1 u + f1

else z = aT2 x + bT

2 u + f2⇒

⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

(m2 − M1)δ + z ≤ aT2 x + bT

2 u + f2

(m1 − M2)δ − z ≤ −aT2 x − bT

2 u − f2

(m1 − M2)(1 − δ) + z ≤ aT1 x + bT

1 u + f1

(m2 − M1)(1 − δ) − z ≤ −aT1 x − bT

1 u − f1

Hybrid System Models 30

Page 31: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• All DHA blocks can be translated into (mixed)integer linear equalities and inequalities

• This leads to the so-called Mixed Logical Dynamical (MLD) System⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

x(t + 1) = Ax(t) + B1u(t) + B2δ(t) + B3z(t) + B5

y(t) = Cx(t) + D1u(t) + D2δ(t) + D3z(t) + D5

E2δ(t) + E3z(t) ≤ E1u(t) + E4x(t) + E5

(19)

x ∈ Rnc × {0, 1}nl, u ∈ R

mc × {0, 1}ml, y ∈ Rpc × {0, 1}pl, δ ∈ {0, 1}rl, z ∈ R

rc

• Theorem 3 MLD and PWA are equivalent in the sense that given a MLD (resp. PWA), one

can always find a corresponding PWA (resp. MLD) model which produces the same output

under the same initial state and control inputs.

• For MPC problems, MLD is better suited for online optimization while PWA is more appro-

priate for explicit MPC.

Hybrid System Models 31

Page 32: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• HYSDEL Modeling Language: A modeling language describing DHA models

SAS: x′c(t) =

⎧⎨⎩

xc(t) + uc(t)− 1, if i(t) = 1,2xc(t), if i(t) = 2,2, if i(t) = 3,

EG:

{δe(t) = [xc(t) ≥ 0],δf (t) = [xc(t) + uc(t)− 1 ≥ 0],

MS: i(t) =

⎧⎪⎪⎨⎪⎪⎩

1, if[

δe(t)δf (t)

]= [ 00 ] ,

2, if δe(t) = 1,

3, if[

δe(t)δf (t)

]= [ 01 ] .

SYSTEM sample {INTERFACE {STATE {

REAL xr [-10, 10]; }INPUT {

REAL ur [-2, 2]; }}IMPLEMENTATION {AUX {

REAL z1, z2, z3;BOOL de, df, d1, d2, d3; }

AD {de = xr >= 0;df = xr + ur - 1 >= 0; }

LOGIC {d1 = ~de & ~df;d2 = de;d3 = ~de & df; }

DA {z1 = {IF d1 THEN xr + ur - 1 };z2 = {IF d2 THEN 2 * xr };z3 = {IF (~de & df) THEN 2 }; }

CONTINUOUS {xr = z1 + z2 + z3; }

}}

Hybrid System Models 32

Page 33: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

MPC of Hybrid Systems

• 2-norm case:

⎧⎪⎪⎨⎪⎪⎩minU0 J(x(t), U0) = xT

NQfxN + ∑N−1k=0

(xT

k Qxk + uTk Ruk

)

subj. to. MLD (19)(20)

which can be reduced to⎧⎪⎪⎪⎨⎪⎪⎪⎩min

ξξT Hξ + 2x(t)TFξ + x(t)TY x(t)

subj. to Gξ ≤ W + Sx(t)(21)

where ξ = {u0, . . . , uN−1, δ0, . . . , δN−1, z0, . . . , zN−1}. This is Mixed Integer Quadratic Pro-

gramming (MIQP) problem.

MPC of Hybrid Systems 33

Page 34: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• ∞-norm case:

⎧⎪⎪⎨⎪⎪⎩minU0 J(x(t), U0) = ∑N−1

k=0 (‖Qxk‖∞ + ‖Ruk‖∞)subj. to. MLD (19)

(22)

– introduce slack variables:

⎧⎪⎪⎨⎪⎪⎩εx

k ≥ ‖Qxk‖∞εu

k ≥ ‖Ruk‖∞⇒

⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

εxk ≥ [Qxk]i, i = 1, . . . , n k = 1, . . . , N − 1

εxk ≥ −[Qxk]i i = 1, . . . , n k = 1, . . . , N − 1

εuk ≥ [Ruk]i i = 1, . . . , m k = 1, . . . , N − 1

εuk ≥ −[Ruk]i i = 1, . . . , m k = 1, . . . , N − 1

– The problem reduces to an optimization problem of the following form:⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩min

ξ

N−1∑k

εxk + εu

k

subj. to Gξ ≤ W + Sx(t)(23)

where ξ = {εx1, . . . , εx

N−1, εu0, . . . , εu

N−1, u0, . . . , uN−1, δ0, . . . , δN−1, z0, . . . , zN−1}.

– This is Mixed Integer Quadratic Programming (MILP) problem.

MPC of Hybrid Systems 34

Page 35: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Problems (21) and (23) can be solved online using MIQP and MILP solvers.

• Explicit MPC solutions can also be computed offline using multiparametric MIQP (mp-MIQP)

and multiparametric MILP (mp-MILP).

• Explicit Hybrid MPC: The hybrid MPC controller is piecewise affine

U∗0 (x(t)) =

⎧⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎩

F1x(t) + g1 if x(t) ∈ partition 1...

FMx(t) + gM if x(t) ∈ partition M

In the 2-norm case, the partition may not be polyhedral

MPC of Hybrid Systems 35

Page 36: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

• Example 4 Example for Hybrid MPC Consider the following PWA system⎧⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩

x(t + 1) = 0.8⎡⎢⎢⎣

cos α(t) − sin α(t)sin α(t) cos α(t)

⎤⎥⎥⎦ x(t) +

⎡⎢⎢⎣

01

⎤⎥⎥⎦ u(t)

y(t) =[

0 1]u(t)

α(t) =

⎧⎪⎪⎪⎨⎪⎪⎪⎩

π3 if

[1 0

]x(t) ≥ 0

−π3 if

[1 0

]x(t) < 0

subject to the input and state constraints

⎡⎢⎣ −5

−5

⎤⎥⎦ ≤ x(k) ≤

⎡⎢⎣ 5

5

⎤⎥⎦ , k = 0, . . . , N − 1 (24)

−1 ≤ u(k) ≤ 1, k = 0, . . . , N − 1. (25)

– Let N = 3, P = Q =⎡⎢⎣ 1 0

0 1

⎤⎥⎦, R = 1.

MPC of Hybrid Systems 36

Page 37: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 1: p = 2, Xf = R2, i.e, no terminal state constraints,

-6 -4 -2 0 2 4 6-6

-4

-2

0

2

4

6

x1

x 2

0 10 20 30 40 50-4

-2

0

2

4Evolution of states

Sampling Instances

Sta

tes

x1

x2

0 10 20 30 40 50-4

-2

0

2

4Evolution of outputs

Sampling Instances

Out

puts

y1

y2

0 10 20 30 40 50-0.2

0

0.2

0.4

0.6

0.8

1Evolution of control moves

Sampling Instances

Inpu

ts

u

0 10 20 30 40 500

0.5

1

1.5

2

2.5

3Active dynamics

Sampling Instances

Dyn

amic

s

– The feasible region X0 is divided into 44 polytope regions.

1 >>probStruct.norm = 2;2 >>probStruct.N = 3;3 >>probStruct. Tconstraint = 0;4 >>ctrl= mpt_control(sysStruct , probStruct);5 >>plot(ctrl.Pn);6 >>simplot(ctrl ,x0 ,NSteps);

MPC of Hybrid Systems 37

Page 38: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 2: p = inf, Xf = [−0.01, 0.01] × [−0.01, 0.01],

-5 -4 -3 -2 -1 0 1 2 3 4 5-4

-3

-2

-1

0

1

2

3

4

x1

x 2

0 10 20 30 40 50-4

-2

0

2

4Evolution of states

Sampling Instances

Sta

tes

x1

x2

0 10 20 30 40 50-4

-2

0

2

4Evolution of outputs

Sampling Instances

Out

puts

y1

y2

0 10 20 30 40 50-0.2

0

0.2

0.4

0.6

0.8

1Evolution of control moves

Sampling Instances

Inpu

ts

u

0 10 20 30 40 500

1

2

3Active dynamics

Sampling Instances

Dyn

amic

s

– The feasible region X0 is divided into 84 polytope regions.

1 >>probStruct. Tconstraint = 2;2 >>X_f= polytope([eye (2);-eye (2) ] ,[0.01;0.01;0.01;0.01]);3 >>probStruct.Tset=X_f;4 >>ctrl= mpt_control(sysStruct , probStruct);

MPC of Hybrid Systems 38

Page 39: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

– Case 3: p = 2, Xf = [−0.01, 0.01] × [−0.01, 0.01],

-5 -4 -3 -2 -1 0 1 2 3 4 5-4

-3

-2

-1

0

1

2

3

4

x1

x 2

0 10 20 30 40 50-4

-2

0

2

4Evolution of states

Sampling Instances

Sta

tes

x1

x2

0 10 20 30 40 50-4

-2

0

2

4Evolution of outputs

Sampling Instances

Out

puts

y1y2

0 10 20 30 40 50-0.5

0

0.5

1Evolution of control moves

Sampling Instances

Inpu

ts

u1

0 10 20 30 40 500

0.5

1

1.5

2

2.5

3Active dynamics

Sampling Instances

Dyn

amic

s

– The feasible region X0 is divided into 92 polytope regions.

1 >>ctrl= mpt_control(sysStruct , probStruct);2 >>plot(ctrl.Pn);3 >>simplot(ctrl ,x0 ,NSteps);

MPC of Hybrid Systems 39

Page 40: ECE7850 Lecture 9 Model Predictive Control: Computational ...zhang/teaching/hybridsystem/lecture notes/LN9...ECE7850 Lecture 9 Model Predictive Control: Computational Aspects • Model

ECE7850 Wei Zhang

-5

0

5

-4

-2

0

2

40

5

10

15

20

25

30

x1

Value function over 92 regions

x2

J* (x)

-4-2

02

4

-2

0

2

-1

-0.5

0

0.5

1

x1

Value of the control action U1 over 92 regions

x2

U* 1(x

)1 >>mpt_plotJ(ctrl);2 >>mpt_plotU(ctrl);3 >>[dQ1 ,dL1 ,dC1 ,feasible ,drho]= mpt_getPWQLyapFct(ctrl); % compute a ...

piecewise quadratic Lyapunov function.

MPC of Hybrid Systems 40