Implicit Tube MPC design - holaza/mptplus GitHub Wiki

MPTplus enables also the implicit tube MPC design according to: Rakovic, Automatica (2023): The implicit rigid tube model predictive control. The implicit formulation of tube MPC design enables handling of the large-scale systems, in contrast to the widely-used set-based rigid tube MPC design according to: Mayne et al., Automatica (2005): Robust model predictive control of constrained linear systems with bounded disturbances, for details consult Tube MPC design.

Construction and evaluation of implicit Tube MPC controller

Example on how to construct and evaluate implicit tube MPC controller:

Note: If the value of the parameter TubeType is set to implicit, then implicit tube MPC is designed. Otherwise, by default, if the value of the parameter TubeType is set to explicit, then explicit tube MPC is designed.

Note: Although MPTplus supports the construction of explicit/multiparametric controller from implicit tube MPC controller using a function toExplicit, it does not make much sense to do so. Instead, we recommend designing non-implicit (explicit) tube MPC to be transformed into explicit/multiparametric form, when applicable. Therefore, call the function toExplicit for implicit tube MPC design only if you really want to.

Demo:

%% TUBE MPC DESIGN
% LTI system
model = ULTISystem('A', [1, 1; 0, 1], 'B', [0.5; 1], 'E', [1, 0; 0, 1]);
model.u.min = [-1];
model.u.max = [ 1];
model.x.min = [-200; -2]; 
model.x.max = [ 200;  2];
model.d.min = [-0.1; -0.1]; 
model.d.max = [ 0.1;  0.1];
% Penalty functions
model.x.penalty = QuadFunction(diag([1, 1]));
model.u.penalty = QuadFunction(diag([0.01]));
% Prediction horizon
N = 9;
option = {'TubeType','implicit','soltype',1,'LQRstability',1}
implicit_MPC = TMPCController(model,N,option)
% TMPC evaluation
x0 = [ -5; -2 ]; % Initial condition
u_implicit = implicit_MPC.evaluate(x0) % Implicit MPC evaluation
[ u, feasible ] = implicit_MPC.evaluate(x0) % Feasibility check

Note: If the value of the parameter LQRstability is set to 0, then no terminal penalty and terminal set are automatically computed. The user is expected to set their own terminal penalty and terminal set or remain empty.

How to evaluate the closed-loop simulation of control

For the given uncertain LTI model and prediction horizon N, the closed-loop simulation of the implicit tube MPC controller is evaluated by:

% Closed-loop simulation
% Note, function ".simulate" works only for solType == 1
Nsim = 12; % Number of simulation steps
% Closed-loop data of implicit Tube MPC 
ClosedLoopData = implicit_MPC.simulate(x0, Nsim)
% Closed-loop data of implicit Tube MPC for any model
implicit_loop = ClosedLoop(implicit_MPC, model) 
ClosedLoopData = implicit_loop.simulate(x0, Nsim) 
% Show results
figure(1),hold on, box on, grid on, xlabel('Control steps k'), ylabel('System states x(k)')
stairs([0,Nsim],[0;0],'k--')
stairs([0:Nsim],ClosedLoopData.X(1,:))
stairs([0:Nsim],ClosedLoopData.X(2,:))
figure(2),hold on, box on, grid on, xlabel('Control steps k'), ylabel('Control inputs u(k)')
stairs([0:Nsim-1],ClosedLoopData.U(1,:))

Note, the returned output of function/method simulate is not supported for the case of the expanded vector of the control inputs (u_opt,x_opt) determined by the value of option solType - {0/1}.

How to get the associated parameters

For the given uncertain LTI model and prediction horizon N, get the associated parameters:

option = {'TubeType','implicit','solType',1,'LQRstability',1}
implicit_MPC = TMPCController(model,N,option);
% number of iterations for construction of implicit tube: Ns
Ns = implicit_MPC.TMPCparams.Ns
% shrinking factor of implicit tube: alpha
alpha = implicit_MPC.TMPCparams.alpha
% tolerance for evaluation of alpha: alpha_tol
alpha_tol = implicit_MPC.TMPCparams.alpha_tol

How to set the auxiliary terminal ingredients

To set the auxiliary terminal ingredients Pz and Kz, extend the options:

% Options extended by auxiliary terminal ingredients "Pz" and "Kz":
[Kz,Pz] = dlqr(model.A,model.B,model.x.penalty.weight*10, model.u.penalty.weight);
option = {'TubeType','implicit','LQRstability',1,'Nz', 3, 'Pz', Pz, 'Kz', -Kz};
% Compute the Tube MPC object
TMPC = TMPCController(model,N,option);
% Perform simulation
x0 = [-5;-2]; % initial condition
Nsim = 15;    % number of simulation steps
data = TMPC.simulate(x0,Nsim);
figure, plot(data.X')

How to return the particular variables of the feedback control law

For given feedback control law: u(0) = u_opt + K*( x(0) - x_opt ) , switch between returning the compact control input u(0) and the vector of the particular variables u_opt and x_opt using the option solType - {0/1}. For the given uncertain LTI model and prediction horizon N, evaluate the vector of the particular variables u_opt and x_opt:

% Setup for expanded control input 
option = {'TubeType','implicit','solType',0}
% TMPC controller construction
implicit_MPC = TMPCController(model,N,option)
% TMPC evaluation of expanded control input
x0 = [-5; -2]; % Initial condition
[ ux_implicit, feasible, implicit_openloop ] = implicit_MPC.evaluate(x0) % Enriched output

Evaluation of the compact control input u(0):

% Setup for compact control input 
option = {'TubeType','implicit','solType',1}
% TMPC controller construction
implicit_MPC = TMPCController(model,N,option)
% TMPC evaluation of compact control input
x0 = [-5; -2]; % Initial condition
ux_implicit = implicit_MPC.evaluate(x0) % Implicit MPC evaluation

Closed-loop Tube MPC control using the particular variables of the feedback control law

Example on how to construct and evaluate Tube MPC controller using the particular variables of the feedback control law:

% Closed-loop simulation for solType == 0
% LTI system
model = ULTISystem('A', [1, 1; 0, 1], 'B', [0.5; 1], 'E', [1, 0; 0, 1]);
model.u.min = [-1];
model.u.max = [ 1];
model.x.min = [-200; -2]; 
model.x.max = [ 200;  2];
model.d.min = [-0.1; -0.1]; 
model.d.max = [ 0.1;  0.1];
% Penalty functions
model.x.penalty = QuadFunction(diag([1, 1]));
model.u.penalty = QuadFunction(diag([0.01]));
% Prediction horizon
N = 9;
% Include the LQR-based terminal penalty and set for compact control law
option = {'TubeType','implicit', 'LQRstability',1, 'solType',0};
% Construct Tube MPC controller
implicit_MPC_expanded = TMPCController(model,N,option)
% TMPC evaluation
x0 = [ -5; -2 ]; % Initial condition
Nsim = 12; % Number of simulation steps
implicit_loop = ClosedLoop(implicit_MPC_expanded, model)
ClosedLoopData = implicit_MPC_expanded.simulate(x0, Nsim) % Implicit Tube MPC
% ClosedLoopData = eMPC_expanded.simulate(x0, Nsim) % Explicit Tube MPC
for k = 1 : Nsim, w(:,k) = implicit_MPC_expanded.TMPCparams.Pw.randomPoint; end % Fixed sequence of disturbances
ClosedLoopData = implicit_MPC_expanded.simulate(x0, Nsim, w) % Implicit Tube MPC
% ClosedLoopData = eMPC_expanded.simulate(x0, Nsim, w) % Explicit Tube MPC
figure(1),hold on, box on, grid on, xlabel('k'), ylabel('System states x(k)')
stairs([0:Nsim],ClosedLoopData.X(1,:))
stairs([0:Nsim],ClosedLoopData.X(2,:))
stairs([0,Nsim],[0;0],'k--')
figure(2),hold on, box on, grid on, xlabel('k'), ylabel('Control inputs u(k)')
stairs([0:Nsim-1],ClosedLoopData.U(1,:))