ECE785 ECE785 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
ECE785 Linear MPC Problem At time t: solve the following N-horizon optimal control problem: P N (x(t)) : V N (x(t)) = min u J(x(t),U ) J f (x N )+ N k= l(x k,u k ) subj. to: x k+ = Ax k + Bu k,k =,...,N A x x k b x,a u u k b u,k =,...,N A f x N b f, x = x(t) () Polyhedral state/control constraints: A x x k b x,a u u k b u,a f x N b f Cost functions J N (x(t), u): -norm, -norm, -norm -norm: x T N Q fx N + N k= ( x T k Qx k + u T k Ru k) / -norm: Q f x N p + N k= ( Qx k p + Ru k p ), p =,, Q, Q f,r are full column rank matrices Recall: x = i x i and x =max i x i Linear MPC Problem
ECE785 Batch Formulation of Linear MPC Vector form of prediction model over N horizon: x(t) x.. x N } {{ } X = I Ạ.. A N } {{ } S x x(t)+ B AB............... A N B B } {{ } S u u.. u N } {{ } U () Define X = S x x(t)+s u U -norm cost function becomes: J (x(),u )=X T QX +U T RU, Q diag{q,...,q,q f }, Q R diag{r,...,r}, R Batch Formulation of Linear MPC 3
ECE785 Substituting the expression of X : J N (x(t),u )=(S x x(t)+s u U ) T Q(S x x(t)+s u U )+U T RU = U T ((S u ) T QS u + R) U +x T (t)(s x ) T } {{ } H = U T HU +x T (t)fu + x T (t)yx(t) = [ U T,x(t) T ] H FT F Y U x(t) } {{ } F u QS U + x T (t)((s x ) T QS x ) x(t) } {{ } Y Polyhedral constraints can be reduced to: G U w + E x(t) where G,w,E,x(t) are known matrices/vectors at time t. Batch Formulation of Linear MPC 4
ECE785 P N (x(t)) boils down to a quadratic programming (QP) problem: V N (x(t)) = min U J N (x(t),u )= [ U T,x(t)T ] H F T F Y U x(t) (3) subj. to G U w + E x(t) QP with affine constraints is a special class of convex programs, which can be solved very efficiently Optimization variable is U ; 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
ECE785 Explicit Linear MPC Online solution: given x(t) at each time t compute a control action u by solving the QP (3) Offline solution (Explicit MPC): pre-compute the control law U (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 = U (x(t)) Simplest case: no state and control constraint U (x(t)) = H F T x(t) With polyhedral state and control constraints, explicit solution can be obtained through multiparametrix programming Explicit Linear MPC 6
ECE785 Multiparametric programming problem: J (x) = subj. to. min v J(x, v) Gv w + Sx (4) optimization variable is v R n v, 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) = argmin v {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 R n : v R n v s.t. Gv w + Sx} Assume (i) K is full dimensional polytope in R n ; (ii) S is full column rank Explicit Linear MPC 7
ECE785 Multiparametric Linear Programming (mp-lp) J (x) =min v {c T v : subj. to Gv w + Sx}; v (x) = argmin u {c T v : subj. to Gv w + Sx} Theorem (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
ECE785 Multiparametric Quadratic Programming (mp-qp): J (x) =min v {v T Hv : subj. to Gv w + Sx}; v (x) = argmin u {v T Hv : subj. to Gv w + Sx} Theorem (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
ECE785 Explicit MPC using multiparameteric programming: norm case: U (x(t)) = argmin U { U T HU + x(t) T FU : G U w + S x(t) } * can be transformed to standard mp-qp problem with v = U + H F T x(t). * explicit MPC law is of the form: U (x(t)) = F x(t)+f if H x(t) h.. (6) F M x(t)+f M if H M x(t) h M * can be solved efficiently using Multi-Parametric Toolbox Explicit Linear MPC
ECE785 ( -norm) case: U (x(t)) = argmin U {J N (x(t),u ):G U w + S x(t)}, where J N (x(t),u )= N ( Qx k + Ru k ) (7) * Note: min x{ x : h(x) } min x,ɛ {ɛ : ɛ x, ɛ x, h(x) } k= * introduce slack variables: ɛ x k Qx k ɛ u k Ru k ɛ x k [Qx k ] i, i =,...,n k =,...,N ɛ x k [Qx k] i i =,...,n k =,...,N ɛ u k [Ru k] i i =,...,m k =,...,N ɛ u k [Ru k] i i =,...,m k =,...,N Explicit Linear MPC
ECE785 * The problem reduces to an optimization problem of the following form: min ξ subj. to N k ɛ x k + ɛ u k Gξ W + Sx(t) where ξ = {ɛ x,...,ɛx N,ɛu,...,ɛu N,u,...,u N }. (8) * Therefore, the -norm linear MPC problem can be reformulated as an mp-lp problem * U (x) is also piecewise affine that can computed using the Multi-Parametric Toolbox -norm explicit MPC can also be formulated as an mp-lp problem See Borrelli s book for details. Explicit Linear MPC
ECE785 Examples for Linear MPC Example Compute R j (S), R+ j (S), O and C Consider the second order system x(t +)=α subject to the input and state constraints cos π 4 sin π 4 sin π 4 cos π 4 x(t)+ u(t) (9) X = x x(t), t U = {u 5 u(t) 5}, t The target set or initial set S is given as S = x 8 8 x(t) 8 8, t Examples for Linear MPC 3
ECE785 5 5 5 5 x R 4 - (S) R - (S) x S R 3 + (S) -5 S -5 X - - R 3 - (S) R - (S) -5 R + (S) X R + (S) R 4 + (S) -5-5 - -5 5 5 x - - -5 - -5 5 5 x Suppose α =in (), compute the j-step backward (and forward) reachable sets R j (S) (and R + j (S)), for j =,, 3, 4, respectively. >> [Xpre,XpreandX] = pre_function(sysstruct,x); >> [Rsets, Vsets] = mpt_reachsets(sysstruct, X, U, N); Examples for Linear MPC 4
ECE785 5 5 x O * -5 - S X -5 - -5 - -5 5 5 x Left: maximal control invariant set C can be obtained after 8 iterations (α =). >> [Cinf,iterations, Piter] = mpt_maxctrlset(sysstruct); Right: maximal positive invariant set O for α = >> [Oinf,tstar,fd,isemptypoly] = mpt_infset(a,x,tmax); Examples for Linear MPC 5
ECE785 Example Persistent feasibility problem Consider the double integrator system x(t +)= x(t)+ with J f (x N )=x T NPx N, l(x k,u k )=x T k Qx k + u T k Ru k, P = Q = X f = R, subject to the input constraints u(t) (), R =, N =3, p =and.5 u(k).5,k =,...,N () and the state constraints 5 5 x(k) 5 5,k =,...,N. () Examples for Linear MPC 6
ECE785 5 4 3 Set of initial feasible states X Maximal positive invariant set O * 5 4 3 x x - - - - -3-3 -4-4 -5-5 -4-3 - - 3 4 5 x -5-5 -4-3 - - 3 4 5 x X is not control invariant; state in X \O are not persistently feasible as shown in the right figure. >> ctrl = mpt_control(sysstruct,probstruct); >> invctrl = mpt_invariantset(ctrl); 3 >> [X,U,cost,trajectory]=mpt_plotTrajectory(ctrl); Examples for Linear MPC 7
ECE785 3 X X f 3 x x - - - - -3-5 -4-3 - - 3 4 5 x -3-5 -4-3 - - 3 4 5 x Choose X f as control invariant set (obtained through LQR) MPC problem is persistently feasible. >> [K,P,E] = dlqr(sysstruct.a,sysstruct.b,probstruct.q,probstruct.r); >> [Oinf,tstar,fd,isemptypoly] = mpt_infset(sysstruct.a-sysstruct.b*k,x,... tmax); 3 >> ctrl = mpt_control(sysstruct,probstruct); Examples for Linear MPC 8
ECE785 Example 3 Receding Horizon Control of Constrained Linear Systems: Consider the double integrator system () with the input constraints u(k),k =,...,N and the state constraints Let Q f = Q =, R = x(k),k =,...,N. We will consider both -norm and -norm case (see slide ) Examples for Linear MPC 9
ECE785 Case : p =,N =3, X f =, x.5.5 -.5 - -.5 Inputs States Evolution of states x x - 3 4 5 Evolution of control moves.4 u.3.. Outputs Dynamics.5.5 Evolution of outputs y -.5 3 4 5 Active dynamics.5.5 - -4-3 - - 3 4 x -. 3 4 5 3 4 5 probstruct.tconstraint = ; Xzero=polytope([eye();-eye()],[*sysStruct.xmax+e-5;*sysStruct.xmin... +e-5]); 3 probstruct.tset=xzero; 4 ctrl = mpt_control(sysstruct,probstruct); 5 plot(ctrl.pn); simplot(ctrl,x,nsteps); Examples for Linear MPC
ECE785 Case : p =,N =3, X f is LQR set,.5 Evolution of states Evolution of outputs x x y.5 States - Outputs - x.5 -.5 - -.5 - - 3 4 5 Evolution of control moves.3 u Inputs.. Dynamics - 3 4 5 Active dynamics.5.5 -.5-6 -4-4 6 x -. 3 4 5 3 4 5 * Feasible region X increased as we increase the terminal constraint set X f probstruct.tset=oinf; ctrl = mpt_control(sysstruct,probstruct); Examples for Linear MPC
ECE785 Value function over 7 regions Value of the control action U over 7 regions 8 7.5 J * (x) 6 5 4 3 U * (x) 4 x - -4 - -5 x 5 -.5 x - - -5 x 5 * Show the value function and control law mpt_plotj(ctrl); mpt_plotu(ctrl); 3 ctrl = mpt_lyapunov(ctrl, 'quad '); %% solve a quadratic Lyapunov... function. 4 ctrl.details.lyapunov 5 P=[3.847 4.8687; 4.8687 3.739}; Examples for Linear MPC
ECE785 Case 3: p =,N =5, X f = X, i.e, no terminal state constraints 3 Evolution of states Evolution of outputs States x x Outputs.5.5 y x - - Inputs - 3 4 5 Evolution of control moves.4 u.3.. Dynamics -.5 3 4 5 Active dynamics.5.5-3 -6-4 - 4 6 x -. 3 4 5 3 4 5 Choose X f = X leads to a larger initial feasible set X >> probstruct.tconstraint = ; Examples for Linear MPC 3
ECE785 Case 4: p =inf, N =5, X f = X, i.e, no terminal state constraints, 3 Evolution of states Evolution of outputs x y States x Outputs x - - Inputs - 3 4 5 Evolution of control moves.6 u.4. Dynamics - 3 4 5 Active dynamics.5.5-3 -6-4 - 4 6 x -. 3 4 5 3 4 5 * The size of feasible regions is independent of norm (Case 3 and Case 4). * Comparing feasible regions X : case 4 = case 3 > case > case Examples for Linear MPC 4
ECE785 Hybrid System Models Piecewise affine (PWA) systems x(t +)=A i(t) x(t)+b i(t) u(t)+f i(t) y(t) =C i(t) x(t)+d i(t) u(t)+g i(t) C 4 x-space C 3 H i(t) x(t)+j i(t) u(t) K i(t) C 7 state: x(t) R n control: u(t) R m C output: y(t) R p C C 6 C 5 mode: i(t) L {,...M} Hybrid System Models 5
ECE785 Discrete hybrid automaton (DHA) d E y v d u F v S... s x u d M 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 6
ECE785 Switched Affine System (SAS) x c (t +)=A i(t) x c (t)+b i(t) u c (t)+f i(t) y c (t) =C i(t) x c (t)+d i(t) u c (t)+g i(t) (3) * x c R n c, u c R m c, y c R p c, i(t) L {,...s} Event Generator (EG) Event generated by function of state and control input: h i (x c,u c )= where δ e (t) {, } n e. δ e (t) =h(x c (t),u c (t)) (4) if H i x c + J i u c + K i if H i x c + J i u c + K i > (5) Hybrid System Models 7
ECE785 Finite State Machine (FSM): binary state of the finite state machine evolves according to a Boolean state update function: x l (t +)=f l (x l (t),u l (t),δ e (t)) y l (t) =g l (x l (t),u l (t),δ e (t)) (6) where x l {, } n l is the binary state, u l {, } m l is the exogenous binary input, δ e (t) is the endogenous binary input coming from the EG Mode Selector (MS) i(t) =f M (x l (t),u l (t),δ e (t)) (7) where i(t) {, } n s, n M = log s. Hybrid System Models 8
ECE785 DHA Trajectories For a given initial condition x c() x l () R n c {, } n l, and inputs the state x(t) of the system evolves according to: δ e (t) =h(x c (t),u c (t),t) i(t) =f M (x l (t),u l (t),δ e (t)) y c (t) =C i(t) x c (t)+d i(t) u c (t)+g i(t) y l (t) =g l (x l (t),u l (t),δ e (t)) x c (t +)=A i(t) x c (t)+b i(t) u c (t)+f i(t) x l (t +)=f l (x l (t),u l (t),δ e (t)) u c(t) u l (t) R m c {, } m l, (8) Hybrid System Models 9
ECE785 Proposition: Any logic formula involving Boolean variables and linear combinations of continuous variables can be translated into a set of (mixed-)integer linear (in)equalities e.g.: X X = TRUE δ + δ,δ,δ {, } FSM and Mode selector: any logic statement f(x) =TRUE can be written m j= ( i Pj X i j Nj X i ) N j,p j {,...n} Event generator: [δ i e(t) =] [H i x c (t) W i ] Switched affine system: if [δ =]then z = a T x + bt u + f else z = a T x + bt u + f i P δ i + i N ( δ i ). i Pm δ i + i N m ( δ i ) H i x c (t) W i M( δe i) H i x c (t) W i >m i δe i (m M )δ + z a T x + b T u + f (m M )δ z a T x bt u f (m M )( δ)+z a T x + bt u + f (m M )( δ) z a T x bt u f Hybrid System Models 3
ECE785 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 +)=Ax(t)+B u(t)+b δ(t)+b 3 z(t)+b 5 y(t) =Cx(t)+D u(t)+d δ(t)+d 3 z(t)+d 5 (9) E δ(t)+e 3 z(t) E u(t)+e 4 x(t)+e 5 x R n c {, } n l, u R m c {, } m l, y R p c {, } p l, δ {, } r l, z R r c 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 appropriate for explicit MPC. Hybrid System Models 3
ECE785 HYSDEL Modeling Language: A modeling language describing DHA models SAS: x c(t) = x c (t)+u c (t), if i(t) =, x c (t), if i(t) =,, if i(t) =3, { δe (t) =[x c (t) ], EG: δ f (t) =[x c (t)+u c (t) ], [ ] δe (t), if δ f (t) =[ ], MS: i(t) =, if δ e (t) =, ] 3, if =[ ]. [ δe (t) δ f (t) SYSTEM sample { INTERFACE { STATE { REAL xr [-, ]; } INPUT { REAL ur [-, ]; } } IMPLEMENTATION { AUX { REAL z, z, z3; BOOL de, df, d, d, d3; } AD { de = xr >= ; df = xr + ur - >= ; } LOGIC { d = ~de & ~df; d = de; d3 = ~de & df; } DA { z = {IF d THEN xr + ur - }; z = {IF d THEN * xr }; z3 = {IF (~de & df) THEN }; } CONTINUOUS { xr = z + z + z3; } }} Hybrid System Models 3
ECE785 MPC of Hybrid Systems -norm case: min U J(x(t),U )=x T N Q fx N + ( N x T k Qx k + u T k Ru k) subj. to. MLD (9) k= () which can be reduced to min ξ subj. to ξ T Hξ +x(t) T Fξ+ x(t) T Yx(t) Gξ W + Sx(t) () where ξ = {u,...,u N,δ,...,δ N,z,...,z N }. This is Mixed Integer Quadratic Programming (MIQP) problem. MPC of Hybrid Systems 33
ECE785 -norm case: min U J(x(t),U )= N k= ( Qx k + Ru k ) subj. to. MLD (9) () introduce slack variables: ɛ x k Qx k ɛ u k Ru k ɛ x k [Qx k] i, i =,...,n k =,...,N ɛ x k [Qx k] i i =,...,n k =,...,N ɛ u k [Ru k] i i =,...,m k =,...,N ɛ u k [Ru k ] i i =,...,m k =,...,N The problem reduces to an optimization problem of the following form: min ξ subj. to N k ɛ x k + ɛ u k Gξ W + Sx(t) (3) where ξ = {ɛ x,...,ɛx N,ɛu,...,ɛu N,u,...,u N,δ,...,δ N,z,...,z N }. This is Mixed Integer Quadratic Programming (MILP) problem. MPC of Hybrid Systems 34
ECE785 Problems () and (3) 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 (x(t)) = F x(t)+g if x(t) partition. F M x(t)+g M In the -norm case, the partition may not be polyhedral if x(t) partition M MPC of Hybrid Systems 35
ECE785 Example 4 Example for Hybrid MPC Consider the following PWA system cos α(t) sinα(t) x(t +)=.8 sin α(t) cosα(t) y(t) = [ ] u(t) α(t) = π 3 if [ ] x(t) π 3 if [ ] x(t) < x(t)+ u(t) subject to the input and state constraints Let N =3, P = Q = 5 5 x(k) 5 5,k =,...,N (4) u(k),k =,...,N. (5), R =. MPC of Hybrid Systems 36
ECE785 Case : p =, X f = R, i.e, no terminal state constraints, 6 4 Evolution of states 4 Evolution of outputs x y 4 States x Outputs y - - x - -4 Inputs -4 3 4 5 Evolution of control moves u.8.6.4. Dynamics -4 3 4 5 Active dynamics 3.5.5-6 -6-4 - 4 6 x -. 3 4 5.5 3 4 5 The feasible region X is divided into 44 polytope regions. >>probstruct.norm = ; >>probstruct.n = 3; 3 >>probstruct.tconstraint = ; 4 >>ctrl= mpt_control(sysstruct, probstruct); 5 >>plot(ctrl.pn); 6 >>simplot(ctrl,x,nsteps); MPC of Hybrid Systems 37
ECE785 Case : p =inf, X f =[.,.] [.,.], 4 4 Evolution of states 4 Evolution of outputs x 3 - - -3-4 -5-4 -3 - - 3 4 5 x Inputs States - -4 3 4 5 Evolution of control moves u.8.6.4. -. 3 4 5 x x Outputs Dynamics - -4 3 4 5 3 Active dynamics y y 3 4 5 The feasible region X is divided into 84 polytope regions. >>probstruct.tconstraint = ; >>X_f=polytope([eye();-eye()],[.;.;.;.]); 3 >>probstruct.tset=x_f; 4 >>ctrl= mpt_control(sysstruct, probstruct); MPC of Hybrid Systems 38
ECE785 Case 3: p =, X f =[.,.] [.,.], x 4 3 - States 4 - Evolution of states -4 3 4 5 Evolution of control moves u x x Outputs 4 - Evolution of outputs y y -4 3 4 5 Active dynamics 3.5 - -3 Inputs.5 Dynamics.5.5-4 -5-4 -3 - - 3 4 5 x -.5 3 4 5 3 4 5 The feasible region X is divided into 9 polytope regions. >>ctrl= mpt_control(sysstruct, probstruct); >>plot(ctrl.pn); 3 >>simplot(ctrl,x,nsteps); MPC of Hybrid Systems 39
ECE785 Value function over 9 regions Value of the control action U over 9 regions 3 5.5 J * (x) 5 U * (x) -.5 5-4 x - -4-5 x 5 x - -4 - x 4 >>mpt_plotj(ctrl); >>mpt_plotu(ctrl); 3 >>[dq,dl,dc,feasible,drho]=mpt_getpwqlyapfct(ctrl); %compute a... piecewise quadratic Lyapunov function. MPC of Hybrid Systems 4