-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmup_rmpc_demo.m
145 lines (110 loc) · 2.9 KB
/
mup_rmpc_demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
% MUP_RMPC_SOFT_CON_DEMO
%
% M-file MUP_RMPC_DEMO demonstrates the basic features of inline robust
% MPC design by MUP toolbox.
%
%
%% 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
%% Soft-Constraints Params
%
u_sl = 0.4;
y_sl = [1;0.5];
Wsu = Wu*1e4;
Wsy = Wx*1e2;
Esu = eye(1);
Esy = eye(2);
%
param.u_sl = u_sl;
param.y_sl = y_sl;
param.Wsu = Wsu;
param.Wsy = Wsy;
param.Esu = Esu;
param.Esy = Esy;
%% 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,'PDLF and ACIS')) | (isequal(rmpc_method,'PDLF and WACIS')) )
beta=1e3;
elseif ( (isequal(rmpc_method,'Shi et al. (2013)')) )
N = 3; % Predictin horizon
param = N;
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 = 10;
%
for vtx = 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);