-
Notifications
You must be signed in to change notification settings - Fork 5
/
pwa_sliding.m
97 lines (80 loc) · 1.92 KB
/
pwa_sliding.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
function pwactrl = pwa_lin2pwa(pwasys, Param)
% pwasys
% xbarDot = Abar{i}*xbar + Bbar{i}*u
%
% pwasys.Abar = {Abar1, ..., Abarn}
% pwasys.Bbar = {Bbar1, ..., Bbarn}
%
% Polytopic region i: {x| Ebar{i}*x > 0 }
%
%
% Boundary information table:
% Boundary between Ri and Rj : {x| xbar=Fbar{i,j}*sbar }
%
xcl = pwasys.xcl;
xclbar = [xcl;1];
NR = length(pwasys.Abar); % Number of regions
n = size(pwasys.Abar{1},1)-1; % Number of state variables
m = size(pwasys.Bbar{1},2); % Number of inputs
Abar = pwasys.Abar;
Bbar = pwasys.Bbar;
Ebar = pwasys.Ebar;
Fbar = pwasys.Fbar;
istar = [];
for i=1:NR,
A{i} = Abar{i}(1:end-1,1:end-1);
a{i} = Abar{i}(1:end-1,end);
B{i} = Bbar{i}(1:end-1,:);
Echeck{i} = [zeros(1,n) 1; Ebar{i}];
xcl_is_inside_Ri = all(Ebar{i}*xclbar>=0);
if xcl_is_inside_Ri,
istar = union(istar,i);
end
end
Lin2PWA = 1;
if exist('Poles'),
for i = istar,
K{i} = -acker(A{i},B{i},Poles);
end
elseif exist('KLin'),
for i = istar,
K{i} = KLin;
end
elseif exist('QLin'),
for i = istar,
K{i} = -lqr(A{i},B{i},QLin,RLin);
end
else
Lin2PWA = 0;
end
if isfield(Param,'Sbar'),
Sbar = Param.Sbar;
else,
error('Sliding mode is not defined.');
end
if isfield(Param,'Sbar'),
Sbar = Param.Sbar;
else,
error('Sliding mode is not defined.');
end
if isfield(Param,'alpha'),
alpha=Param.alpha;
else
alpha = 5;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Sliding Mode Control %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:NR,
Kbar{i} = -(Sbar*Bbar{i})\(Sbar*Abar{i}+alpha*Sbar);
end
pwactrl.xcl = xcl;
pwactrl.istar = istar;
for i=1:NR,
pwactrl.Kbar{i} = double(Kbar{i});
end
pwactrl.Index = pwasys.Index;
pwactrl.X = pwasys.X;
pwactrl.T = pwasys.T;
pwactrl.xcl = pwasys.xcl;
pwactrl.Ebar = pwasys.Ebar;