Linear Parameter Varying and Time-Varying Model Predictive Control Alberto Bemporad - Model Predictive Control course - Academic year 016/17 0-1
Linear Parameter-Varying (LPV) MPC LTI prediction model ( xk+1 = A(p(t))x k + B u (p(t))u k + B v (p(t))v k y k = C(p(t))x k + D v (p(t))v k Model depends on time t but does not change in prediction quadratic performance index NX 1 min kw y (y k r(t))k + kw u (u k u ref (t))k U k=0 QP min z 1 s.t. z0 H(p(t))z + 0 (t)f (p(t)) 0 z G(p(t))z apple W (p(t))+s(p(t)) (t) constraints ( umin apple u k apple u max y min apple y k apple y max All QP matrices are constructed on line LPV models can be obtained from linearization of nonlinear models or from black-box LPV system identification 0 -
Linear Time-Varying (LTV) MPC LTV prediction model ( xk+1 = A k (p(t))x k + B uk (p(t))u k + B vk (p(t))v k y k = C k (p(t))x k + D vk (p(t))v k Model depends on time t and prediction step k quadratic performance index NX 1 min kw y (y k r(t))k + kw u (u k u ref (t))k U k=0 QP min z 1 s.t. z0 H(p(t))z + 0 (t)f (p(t)) 0 z G(p(t))z apple W (p(t))+s(p(t)) (t) constraints ( umin apple u k apple u max y min apple y k apple y max LTV-MPC still leads to a convex QP LTV models can be obtained from linearizing NL models around time-varying reference trajectories (e.g.: previous optimal trajectory) 0 -
LTV-MPC example 1.4 Output 1. 1 0.8 0.6 0.4 0. mpcmoveadaptive mpcmovetimevarying mpcmove 0 0 5 10 15 0 5 0 5 40 45 50 Process model is LTV: LTV-MPC is quite good d y y dt +d dt +dy + (6 + sin(5t))y dt =5 du dt + (5 + cos(5 t))u LPV-MPC tries to catch-up with time-varying model LTI-MPC is not good (See demo TimeVaryingMPCControlOfATimeVaryingLinearSystemExample, MPC Toolbox) 0-4
LTV-MPC example Define LTV model Models = tf; ct = 1; for t = 0:0.1:10 Models(:,:,ct) = tf([5 5+*cos(.5*t)],[1 6+sin(5*t)]); ct = ct + 1; end Ts = 0.1; % sampling time Models = ss(cd(models,ts)); Design MPC controller sys = ss(cd(tf([5 5],[1 6]),Ts)); % average model time p = ; % prediction horizon m = ; % control horizon mpcobj = mpc(sys,ts,p,m); mpcobj.mv = struct('min',-,'max',); % input constraints mpcobj.weights = struct('mv',0,'mvrate',0.01,'output',1); 0-5
LTV-MPC example Simulate LTV system with LTI MPC controller for ct = 1:(Tstop/Ts+1) real_plant = Models(:,:,ct); % Get the current plant y = real_plant.c*x; u = mpcmove(mpcobj,xmpc,y,1); % Apply LTI MPC x = 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 plant y = real_plant.c*x; u = mpcmoveadaptive(mpcobj,xmpc,real_plant,nominal,y,1); x = real_plant.a*x + real_plant.b*u; end 0-6
LTV-MPC example Simulate LTV system with LTV MPC controller for ct = 1:(Tstop/Ts+1) real_plant = Models(:,:,ct); % Get the current plant y = 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 A B C Clock Zero-Order Hold t D U Y X DX Time Varying Predictive Model model mo ref Adaptive MPC mv t y u Time-Varying Plant ysim To Workspace1 mpc_timevarying.mdl 1 Reference Adaptive MPC Controller usim To Workspace 0-7
LTV-MPC example Simulink block need to provide D array of future models mpc_timevarying.mdl 0-8
Linearization and TIme-Discretization Assume model is nonlinear and continuous-time dx dt = f(x(t),u(t)) Linearize around a nominal state x(t) and input u(t), such as: - an equilibrium - a reference trajectory - the most updated value dx dt (t + ) ' @f @x x(t),ū(t) (x(t + ) + @f @u x(t),ū(t) (u(t + ) x(t)) ū(t)) + f(x(t),u(t)) Conversion to discrete-time linear prediction model discrete-time LPV model A(t)! @f x k+1 = I + T s x k + @x x(t),ū(t) B(t) f(t)! @f T s u k + f k @u x(t),ū(t) model matrices depend on current time t 0-9
Example: LPV-MPC of a nonlinear CSTR system MPC control of a diabatic continuous stirred tank reactor (CSTR) Process model is nonlinear: F Tf CAf dc A dt dt dt = F V (C Af C A ) C A k 0 e E RT = F V (T f T )+ UA C p V (T j T ) H C p C A k 0 e E RT T : temperature inside the reactor [K] (state) T Tj CA C A : concentration of the reagent in the reactor [kgmol/m ] (state) T j : jacket temperature [K] (input) T f : feedstream temperature [K] (measured disturbance) C Af : feedstream concentration [kgmol/m ] (measured disturbance) Objective: manipulate Tj to regulate CA on desired set-point >> edit ampccstr_linearization (MPC Toolbox) 0-10
Example: LPV-MPC of a nonlinear CSTR system Process model >> mpc_cstr_plant 1 CAi Ti Tc Feed Concentration Feed Temperature Coolant Temperature CSTR Reactor Temperature Reactor Concentration 1 T CA % Create operating point specification. plant_mdl = 'mpc_cstr_plant'; op = operspec(plant_mdl); op.inputs(1).u = 10; % Feed concentration known @initial condition op.inputs(1).known = true; op.inputs().u = 98.15; % Feed concentration known @initial condition op.inputs().known = true; op.inputs().u = 98.15; % Coolant temperature known @initial condition op.inputs().known = true; [op_point, op_report] = findop(plant_mdl,op); % Compute initial condition % Obtain nominal values of x, y and u. x0 = [op_report.states(1).x;op_report.states().x]; y0 = [op_report.outputs(1).y;op_report.outputs().y]; u0 = [op_report.inputs(1).u;op_report.inputs().u;op_report.inputs().u]; % Obtain linear plant model at the initial condition. sys = linearize(plant_mdl, op_point); sys = sys(:,:); % First plant input CAi dropped because not used by MPC 0-11
Example: LPV-MPC of a nonlinear CSTR system MPC design (1/) % Discretize the plant model Ts = 0.5; % hours plant = cd(sys,ts); % Design MPC Controller % Specify signal types used in MPC plant.inputgroup.measureddisturbances = 1; plant.inputgroup.manipulatedvariables = ; plant.outputgroup.measured = 1; plant.outputgroup.unmeasured = ; plant.inputname = {'Ti','Tc'}; plant.outputname = {'T','CA'}; % Create MPC controller with default prediction and control horizons mpcobj = mpc(plant); % Set nominal values in the controller mpcobj.model.nominal = struct('x', x0, 'U', u0(:), 'Y', y0, 'DX', [0 0]); 0-1
Example: LPV-MPC of a nonlinear CSTR system MPC design (/) % Set scale factors because plant input and output signals have different orders of magnitude Uscale = [0 50]; Yscale = [50 10]; mpcobj.dv(1).scalefactor = Uscale(1); mpcobj.mv(1).scalefactor = Uscale(); mpcobj.ov(1).scalefactor = Yscale(1); mpcobj.ov().scalefactor = Yscale(); % 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 = -; mpcobj.mv.ratemax = ; 0-1
Example: LPV-MPC of a nonlinear CSTR system Simulink diagram Measurement Noise u0(1) u0() Disturbance CAi Ti Tc plant model CSTR T CA Reactor Feed Temperature u0(1) [x] A T A [x] B B [x] C CA C [x] D D [x1] CAi U U [x1] Y Y Ti [x1] X X [x1] DX DX Tc [x1] poles Successive Linearizer [x] [x] [x] [x] [x1] [x1] [x1] [x1] Poles 8{4} [x1] Pole Concentration True Estimated Selector Coolant mv est.state Adaptive MPC model mo ref md Adaptive MPC Controller Reference 8{4} 0 CA Reference linearize + discretize Copyright 1990-014 The MathWorks, Inc. LPV-MPC >> ampc_cstr_linearization 0-14
Example: LPV-MPC of a nonlinear CSTR system Closed-loop results 0-15
Example: LTI-MPC of a nonlinear CSTR system Let us try with a fixed (LTI) MPC controller Noise u0(1) CAi CAi T Reactor u0() Ti Ti Tc CA Feed Disturbance CSTR Temperature Coolant mo LTI-MPC mv MPC ref md 0 CA Reference MPC Controller Reference Concentration True Copyright 1990-014 The MathWorks, Inc. Same tuning of MPC parameters 0-16
Example: LTI-MPC of a nonlinear CSTR system Closed-loop results very bad tracking! 0-17
Example: LTI-MPC of a nonlinear CSTR system Closed-loop results 0-18
Example: LTV-MPC for UAV navigation Goal: navigate two planar vehicles among obstacles to a target position The dynamical model of each vehicles is described by p(t) = 0 s + 0 s + 0 p c (t) p = [x,y] vehicle position pc = commanded position Vehicle dynamics converted to discrete-time by exact sampling Five square obstacles placed in workspace 0-19
LTV-MPC for obstacle avoidance Goal: Use linear time-varying (LTV) MPC to generate desired positions to stabilizing controller in real-time to avoid obstacles and other UAVs Problem: feasible space is non-convex! target position Main idea: get a convex inner approximation of the feasible space that is Polyhedral =linear constraints on predicted states in LTV-MPC problem Very simple to compute on-line initial position Can handle polytopic obstacles of arbitrary shape and dimension Alternative: non-convex feasible space modeled by mixed-integer constraints, guidance problem solved by (time-invariant) hybrid MPC (Bemporad, Rocchi, IFAC 011) 0-0
Fast greedy approximation algorithm (1/) Assume (for the moment) that vehicle and obstacles are points in space (Bemporad, Rocchi, CDC 011) p 0 R d = current vehicle position qm q 1,q,...,q M R d = obstacle positions p0 q Polyhedral approximation: q1 P = 8 >< >: p Rd : 6 4 (q 1 p 0 ) 0. (q M p 0 ) 0 7 5 p apple 6 4 (q 1 p 0 ) 0 q 1. (q M p 0 ) 0 q M 9 >= 7 5 >; p 0 6= q i, 8i =1,...,M P contains p0 and does not contain any of the obstacles q1, q,..., qm in its interior 0-1
Fast greedy approximation algorithm (/) Assume now polyhedral obstacles with shapes W1, W,... WM WM For each obstacle j define the scalar g j qm g j = min wr d (q j p 0 ) 0 w s.t. w W j p0 If the vertices of WM are available, simply g j = min h=1,...,s j A j cw jh (wjh = vertex of Wj) q W Polyhedral approximation: P = 8 >< >: p Rd : 6 4 (q 1 p 0 ) 0. (q M p 0 ) 0 7 5 p apple 6 4 (q 1 p 0 ) 0 q 1 + g 1. (q M p 0 ) 0 q M + g M 9 >= 7 5 >; q1 W1 If P is nonempty, then P contains p0 and does not contain any of the obstacles B j = {q j } in its interior W j 0 -
Fast greedy approximation algorithm (/) Assume polyhedral obstacles and polytopic UAV qm WM V, conv(p 0 + d 1,...,p 0 + d r ) V q W p0 q1 Polyhedral approximation: 8 >< (q 1 p 0 ) 0 P = >: p 6 Rd : 4. (q M p 0 ) 0 7 5 p apple 6 4 (q 1 p 0 ) 0 (q 1 d i )+g 1. (q M p 0 ) 0 (q M d i )+g M W1 9 >= 7 5, i =1,...,r >; If P is nonempty, then P contains V and does not contain any of the obstacles B j = {q j } in its interior W j 0 -
LTV-MPC guidance algorithm: prediction model Linear approximation of stabilized dynamics of UAV #i p i (t + 1) = A i p i (t)+b i p ci (t) p i (t) = Polytopic shape of UAV #i at time t p ci (t) = 4 x i(t) y i (t) z i (t) 4 x ci(t) y ci (t) z ci (t) 5 position of vehicle #i at time t 5 position commanded at time t V(t) ={p(t)} + conv(d 1 (t),...,d r (t)) p(t) V(t) Polyhedral shape of obstacle #j at time t B j (t) ={q j (t)} W j (t) qj(t) Bj(t) Note: other vehicles in formation are treated as polytopic obstacles (Bj = V ) 0-4
LTV-MPC guidance algorithm: optimization model At time t, select the desired position pc(t) for the UAV by solving the optimal control problem (=quadratic programming) prediction horizon min + N 1 X k=0 desired position kw y (p k p d (t))k + kw u (p c,k p c,k 1 )k s.t. bounds on p k+1 = Ap k + Bp c,k, k =0,...,N 1 input min apple p c,k p c,k 1 apple max, k =0,...,N u 1 increments A c,k p k apple b c,k + g k A c,k d h,k +1I k =0,...,N 1, h =1,...,r i p c,k = p c,nu 1, k = N u,...,n blocked moves UAV dynamics (soft)obstacl e avoidance constraints A c = 6 4 (q 1 p 0 ) 0. (q M p 0 ) 0 7 5, b c = 6 4 (q 1 p 0 ) 0 q 1. (q M p 0 ) 0 q M 7 5 0 -
Example: navigation demo Initial position #1 = (0,0) Target position #1 = (5,0) Initial position # = (5,-) Target position # = (0,0) ROBMPC project Robust Model Predictive Control (MPC) for Space Constrained Systems MPCSofT Toolbox for MATLAB (Bemporad, 010-011) 0-6
Example: navigation demo (cooperative MPC) Two vehicles avoiding each other and obstacles towards their targets vehicle dynamics #1 vehicle dynamics # MPC # MPC #1 previous optimal sequences are exchanged 0-7