Wiki

Clone wiki

mup / cli

MUP and CLI

r20160523 [Home] [changelog]

wiki20160215.1

This page briefly explain how to use MUP in MATLAB Command Line Interface (CLI).

Presentation about MUP Toolbox and CLI can be downloaded here [How2use_mup.pdf] .

We will consider the case study of robust MPC design based on the RMPC_OPTIMIZER (designed by YALMIP/OPTIMIZER) with enabled feasibility check.

In general, the robust MPC design problem can be expanded into the following steps:

step 1: define uncertain system,

step 2: robust MPC setup,

step 3: SDP formulation,

step 4: RMPC_OPTIMIZER design,

step 5: closed-loop control performance,

step 6: process the results.

Step 1: Define uncertain system

Consider the following vertex representation of discrete-time state-space system with interval parametric uncertainties:

%% Step 1:Define Uncertain System

%% Vertex No.1
A{1,1} = [0.93, 0.51; 0.38, 0.83];
B{1,1} = [-1.45; -0.70];
C{1,1} = [2, 0; 0, 2];
%% Vertex No.2
A{2,1} = [0.06, 0.26; 1.80, 0.87];
B{2,1} = [-1.45; -0.70];
C{2,1} = [2, 0; 0, 2];

Note, the system vertices are defined using MATLAB class cell-array. Some method requires to design RMPC using the nominal system. We define also the nominal system as the last vertex. The nominal system is considered as the mean values of the interval parametric uncertainties.

%% Nominal System
A{3,1} = [0.50, 0.39; 1.10, 0.85];
B{3,1} = [-1.45; -0.70];
C{3,1} = [1, 0; 0, 1];

We define the sampling time of the linear discrete-time system:

%% Sampling Time
Ts = 1;

We define the uncertain system initial conditions of the state vector:

%% System Initial Conditions
x0 = [3;0];

Step 2: Robust MPC Setup

Consider the symmetric constraints on the system inputs and states. The constraints are set as the vector of the maximal admissible values of the elements.

%% Step 2: Robust MPC Setup

%% Input and State Constraints
u_max = [10];
x_max = [10;10];

Next we set the quadratic quality criterion weighting matrices of system states and inputs, respectively:

%% Cost Function Weight Matrices
Wx = eye(2);
Wu = eye(1);

We considered the diagonal matrices with entries 1 on principal diagonal.

Alternatively, except of previous commands in Stpes 1 and 2, you can load the benchmark system, e.g., one of the Cuzzola et al. (2002):

benchmark_cuzzola % Load benchmark system
mup_expand_rmpc_block_ws % Expand its variables

We enable the feasibility check using the variable chk_feas:

chk_feas = 'on'; % Enable Feasibility Chcek
% chk_feas = 'off'; % DIsable Feasibility Chcek

Next we need to select the required RMPC design method. We use the function for user-friendly selection in MATLAB CLI:

%% Select RMPC method Using CLI
[rmpc_method,rmpc_kwd] = mup_cli_rmpc_method;

Alternatively, the advanced users can directly define the variables rmpc_method and rmc_kwd. We can display the list of available methods by typing:

[rmpc_list, rmpc_kwds] = mup_get_rmpclist
that returns MATLAB cell-arrays:

rmpc_list = 

    'Cao et al. (2005)'
    'Cuzzola et al. (2002)'
    'Ding et al. (2007)'
    'Huang et al. (2011)'
    'Kothare et al. (1996)'
    'Li et al. (2008)'
    'Mao (2003)'
    'Mao et Cao (2015)'
    'Mao et Huang (2015)'
    'Wan et al. (2003)'
    'Wan et Cao (2015)'
    'Wan et Huang (2015)'
    'Wan et Zhang (2015)'
    'Zhang et al. (2013)'

rmpc_kwds = 

    'cao'
    'cuzzola'
    'ding'
    'huang'
    'kothare'
    'li'
    'mao'
    'mao_cao'
    'mao_huang'
    'wan'
    'wan_cao'
    'wan_huang'
    'wan_zhang'
    'zhang'

Then we choose the required method. For example Kothre et al. (1996) is placed on the 5th position:

position = 5;
rmpc_method = rmpc_list{position};
rmpc_kwd = rmpc_kwd{position};

or we can directly type:

rmpc_method = 'Kothare et al. (1996)';
rmpc_kwd = 'kothare';

Step 3: SDP Formulation

In the next step we define the complex optimization problem in the form of SDP by simply typing:

%% Step 3: SDP Formulation
mup_sdp

Step 4: RMPC_OPTIMIZER Design

In this step we need to construct the gain matrix of the closed-loop control law. The designed controller will be used to evaluate the state feedback control law in each control step. In this step we construct the controller RMPC_OPTMIZER based on the function YALMIP/OPTMIZER by typing:

%% Step 4: RMPC_OPTIMIZER Design

% Construct the RMPC_OPTMIZER and Store Data into structures DESIGN, MODEL, PROBLEM, SETUP, RMPC_BLOCK_WS[GLOBAL]
mup_rmpc_opt

Step 5: Closed-loop Control Performance

In this step we manage the closed-loop control setup.

We consider the 10 control steps, i.e. nk=10 and we want to evaluate the control performance. We initialize the cycle FOR for all the vertex systems in cyckle, i.e. vtx = 1 : nv:

%% Step 5: Closed-loop Control Performance

%% Number of Control Steps
nk = 10;
%
for vtx = 1 : nv

Next we initialize the matrix of the system-state vector evaluation in time using the system initial conditions:

%% Initialization
disp(sprintf('\n Vertex processing: %d of %d',vtx,nv))
x(:,1) = x0;

We initialize the cycle FOR for each control step:

for k = 1 : nk

We evaluate current system-states measurement (initialized by the initial conditions x0):

%% Current State Measure
xk = x(:,k);

We compute the optimal control action u(:,k) in the k-th control step, gain matrix of the state-feedback control law F{k} in k-th control step, and the auxiliary vector vct_opt for the feasibility check:

%% Closed-Loop RMPC using YALMIP/Optimizer
[u(:,k),F{k},vct_opt] = mup_rmpc(xk,design);

Then we evaluate the feasibility check, when required:

%% Feasibility Check
if(isequal(setup.chk_feas,'on'));
    mup_opt_feas
end % if
%% Verbose
disp(sprintf(' %d/%d',k,nk))

We implement the additional control input saturation, since various RMPC methods require the additional saturation:

%% Saturation of the Control Inputs 
if(isempty(u_max) == 1)
    u_sat(:,k) = sign(u(:,k));
else
    sgn = sign(u(:,k));
    for cnt_u = 1 : nu
        u_sat(cnt_u,k) = sgn(cnt_u)*min(abs(u(cnt_u,k)),u_max(cnt_u));
    end % for cnt_u
end % if

Then we implement the computed control action into the uncertain linear discrete-time state-space system:

%% System Behaviour
x(:,k+1) = A{vtx}*x(:,k) + B{vtx}*u_sat(:,k);

We compute the current value of quadratic quality criterion:

%% Quadratic Quality Criterion
cost(k,1) = get_J(x(:,1:k),u(:,1:k),Wx,Wu);

We close the cycle of the vtx-th vertex evaluation after nk-th control steps.

end % for k

We store the obtained simulation results of the vtx-th vertex into the structure DATA:

%% Save Vertex-Results
if(exist('data','var') ~= 1)
    data = []; % Default value for DATA
end % if
data = mup_results2data(x,u,cost,vtx,data);

We close the cycle of the RMPC for each vertex:

end % for vtx

We can export the generated closed-loop results stored in structure DATA into the file RESULTS_$DATESTR:

%% Store the Obtained Results
filename = ['results_',datestr(now,30)];
save(filename,'data','-v6')

Finally, we can plot the obtained simulation results:

%% Plot the Obtained Results
temp = rmpc_plot(data);

The whole DEMO can be find next, or can be simply downloaded [download]:

%% Step 1: Define Uncertain System

% 1st Vertex
A{1,1} = [0.93, 0.51; 0.38, 0.83];
B{1,1} = [-1.45; -0.70];
C{1,1} = [2, 0; 0, 2];
% 2nd Vertex
A{2,1} = [0.06, 0.26; 1.80, 0.87];
B{2,1} = [-1.45; -0.70];
C{2,1} = [2, 0; 0, 2];
% Nominal System
A{3,1} = [0.50, 0.39; 1.10, 0.85];
B{3,1} = [-1.45; -0.70];
C{3,1} = [1, 0; 0, 1];
% Sampling Time
Ts = 1;

%% Step 2: Robust MPC Setup

%% System Initial Conditions
x0 = [3;0];

%% Input and State Constraints
u_max = [10];
x_max = [10;10];

%% Cost Function Weight Matrices
Wx = eye(2);
Wu = eye(1);

%% Alternatively, except of Stpes 1,2, you can load the benchmark system here
% benchmark_cuzzola % Load benchmark system
% mup_expand_rmpc_block_ws % Expand its variables

%% on/off Feasibility Chcek
chk_feas = 'on'; % Enable Feasibility Chcek
% chk_feas = 'off'; % Disable Feasibility Chcek

%% Select RMPC method Using CLI
[rmpc_method,rmpc_kwd] = mup_cli_rmpc_method;

%% Additional RMPC Tunning Parameter
if( (isequal(rmpc_method,'Huang et al. (2011)')) | (isequal(rmpc_method,'Wan et Huang ((2015))')) | (isequal(rmpc_method,'Mao et Huang (2015)')) )
    beta=1e3;
end % if


%% Step 3: SDP Formulation
mup_sdp


%% Step 4: RMPC_OPTIMIZER Design

% Construct the RMPC_OPTMIZER and Store Data into structures DESIGN, MODEL, PROBLEM, SETUP, RMPC_BLOCK_WS[GLOBAL]
mup_rmpc_opt


%% Step 5: Closed-loop Control Performance

%% Number of Control Steps
nk = 300;
%
for vtx = 1 : 1% nv

%% Initialization
disp(sprintf('\n Vertex processing: %d of %d',vtx,nv))
x(:,1) = x0;

for k = 1 : nk

%% Current State Measure
xk = x(:,k);

%% Closed-Loop RMPC using YALMIP/Optimizer
[u(:,k),F{k},vct_opt] = mup_rmpc(xk,design);

%% Feasibility Check
if(isequal(setup.chk_feas,'on'));
    mup_opt_feas
end % if

%% Verbose
disp(sprintf(' %d/%d',k,nk))

%% Saturation of the Control Inputs 
if(isempty(u_max) == 1)
    u_sat(:,k) = sign(u(:,k));
else
    sgn = sign(u(:,k));
    for cnt_u = 1 : nu
        u_sat(cnt_u,k) = sgn(cnt_u)*min(abs(u(cnt_u,k)),u_max(cnt_u));
    end % for cnt_u
end % if

%% System Behaviour
x(:,k+1) = A{vtx}*x(:,k) + B{vtx}*u_sat(:,k);

%% Quadratic Quality Criterion
cost(k,1) = get_J(x(:,1:k),u(:,1:k),Wx,Wu);

end % for k

%% Save Vertex-Results
if(exist('data','var') ~= 1)
    data = []; % Default value for DATA
end % if
data = mup_results2data(x,u,cost,vtx,data);

end % for vtx

%% Store the Obtained Results
filename = ['results_',datestr(now,30)];
save(filename,'data','-v6')

%% Plot the Obtained Results
temp = rmpc_plot(data);

Updated