-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpwa_controller.m
156 lines (142 loc) · 6.12 KB
/
pwa_controller.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
146
147
148
149
150
151
152
153
154
155
156
function pwactrl = pwa_controller(pwasys, pwactrl, Param)
pwactrl.Lin2PWA = 1;
for i = pwasys.istar,
A{i} = pwasys.Abar{i}(1:pwasys.n,1:pwasys.n);
B{i} = pwasys.Bbar{i}(1:pwasys.n,:);
if isfield(Param,'Poles'),
K{i} = -acker(A{i},B{i},Param.Poles);
elseif isfield(Param,'KLin'),
K{i} = Param.KLin;
elseif isfield(Param,'QLin'),
K{i} = -lqr(A{i},B{i},Param.QLin,Param.RLin);
else
pwactrl.Lin2PWA = 0;
end
end
if ~isfield(Param,'alpha'),
Param.alpha=0;
end
if ~isfield(pwactrl,'Kbar'),
for i=1:pwasys.NR,
Kbar{i} = sdpvar(pwasys.m,pwasys.n+1,'full');
end
else,
if pwactrl.Lin2PWA,
Kbar = pwactrl.Kbar;
else,
for i=1:pwasys.NR,
Kbar{i} = sdpvar(pwasys.m,pwasys.n+1,'full');
assign(Kbar{i},pwactrl.Kbar{i})
end
end
end
if isfield(Param,'L2Gain'),
L2Gain = Param.L2Gain;
pwactrl.gammaSQ = sdpvar(1);
pwactrl.constraints=pwactrl.constraints+set(pwactrl.gammaSQ > Param.L2Gain^2,['gamma^2>' num2str(Param.L2Gain^2)]);
for i=1:pwasys.NR,
if ~iscell(pwasys.Czbar),
Czbar{i}=pwasys.Czbar;
end
if ~iscell(pwasys.Bwbar),
Bwbar{i}=pwasys.Bwbar;
end
if ~iscell(pwasys.Dzw),
Dzw{i}=pwasys.Dzw;
end
end
if ~isfield(pwasys,'Du'),
for i=1:pwasys.NR,
Dzu{i} = zeros(size(Czbar{i},1),pwasys.m);
end
end
for i=1:pwasys.NR,
Bw{i} = Bwbar{i}(1:end-1,:);
Cz{i} = Czbar{i}(:,1:end-1);
end
pwasys.Czbar = Czbar;
pwasys.Bwbar = Bwbar;
pwasys.Dzw = Dzw;
pwasys.Dzu = Dzu;
q = size(Bwbar{1},2); % Number of disturbance inputs
end
%%%%%%%%%%%%%%%%%%%%%%%% The center region %%%%%%%%%%%%%%%%%%%
I = eye(pwasys.n);
One = zeros(pwasys.n+1);
One(end,end)=1;
if pwactrl.Lin2PWA,
for i=pwasys.istar,
k = sdpvar(pwasys.m,1);
Kbar{i} = [K{i} k];
end
end
for i=pwasys.istar,
K{i} = Kbar{i}(:,1:pwasys.n);
for j=1:pwasys.NS,
try
% pwactrl.constraints=pwactrl.constraints+set( (pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})*[pwasys.xcl;1] == 0,'(Abar+Bbar*Kbar)*xclbar=0');
end
if exist('L2Gain'),
L2Mat11 = (pwasys.Abar{i}+pwasys.Bbar{i}*Kbar{i})'*pwactrl.Pbar{i}+0.5*(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})'*(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i});
L2Mat11 = L2Mat11(1:pwasys.n,1:pwasys.n);
L2Mat11 = L2Mat11+L2Mat11';
L2Mat12 = pwactrl.Pbar{i}*pwasys.Bwbar{i}+(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})'*pwasys.Dzw{i};
L2Mat22 = pwasys.Dzw{i}'*pwasys.Dzw{i}-25*eye(q);
pwactrl.constraints=pwactrl.constraints+set( [L2Mat11 L2Mat12(1:pwasys.n,:); L2Mat12(1:pwasys.n,:)' L2Mat22] < 0,['L2Mat' num2str(i) '<0']);
else,
if pwactrl.Lin2PWA,
DV{i,j} = pwactrl.Pbar{i}*(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})+(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})'*pwactrl.Pbar{i}; % Don't use alpha for the center region(s) if you already have the controller
else
DV{i,j} = pwactrl.Pbar{i}*(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})+(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})'*pwactrl.Pbar{i}+Param.alpha*pwactrl.Pbar{i};
end
pwactrl.constraints=pwactrl.constraints+set( DV{i,j}(1:pwasys.n,1:pwasys.n) < 0,['DV' num2str(i) ',' num2str(j) '<0']);
end
end
end
for i=1:pwasys.NR,
%%%%%%%%%%%%%%%%%%%%%%%% Inequality Constraints %%%%%%%%%%%%%%%%%%%
if ~isfield(pwactrl,'Kbar'),
if isfield(Param,'LimitK'),
if ~ismember(i,pwasys.istar) | ~pwactrl.Lin2PWA,
% pwactrl.constraints=pwactrl.constraints+set(Kbar{i}(:) < Param.LimitK,'Kbar<LimitK');
% pwactrl.constraints=pwactrl.constraints+set(Kbar{i}(:) > -Param.LimitK,'Kbar>-LimitK');
end
end %LimitK%
end
%%%%%%%%%%%%%%%%%%%%%%%%% Negative definite %%%%%%%%%%%%%%%%%%%%%%%%%
if i~=pwasys.istar,
if exist('L2Gain'),
% L{i} = sdpvar(pwasys.p+1,pwasys.p+1);
% pwactrl.constraints=pwactrl.constraints+set(0 < L{i}(:) < 1e5,['L{' num2str(i) '}(:)>0']);
% L2Mat{i} = [(pwasys.Abar{i}+pwasys.Bbar{i}*Kbar{i})'*pwactrl.Pbar{i}+pwactrl.Pbar{i}*(pwasys.Abar{i}+pwasys.Bbar{i}*Kbar{i})+(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})'*(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})+pwasys.Ebar{i}'*L{i}*pwasys.Ebar{i} pwactrl.Pbar{i}*pwasys.Bwbar{i}+(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})'*pwasys.Dzw{i}; (pwactrl.Pbar{i}*pwasys.Bwbar{i}+(pwasys.Czbar{i}+pwasys.Dzu{i}*Kbar{i})'*pwasys.Dzw{i})' pwasys.Dzw{i}'*pwasys.Dzw{i}-pwactrl.gammaSQ*eye(q)];
% pwactrl.constraints=pwactrl.constraints+set( L2Mat{i} < 0,['L2Mat' num2str(i) '<0']);
else
for j=1:pwasys.NS,
L{i,j} = sdpvar(pwasys.p+1,pwasys.p+1);
% S procedure
pwactrl.constraints=pwactrl.constraints+set(0 < L{i,j}(:) < 1e5,['L{' num2str(i) '}(:)>0']);
DV{i,j} = pwactrl.Pbar{i}*(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})+(pwasys.Abar{i,j}+pwasys.Bbar{i,j}*Kbar{i})'*pwactrl.Pbar{i}+Param.alpha*pwactrl.Pbar{i}+pwasys.Ebar{i}'*L{i,j}*pwasys.Ebar{i};
pwactrl.constraints=pwactrl.constraints+set( DV{i,j} < 0,['DV' num2str(i) '-' num2str(j) '<0']);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%% Continuity constraints %%%%%%%%%%%%%%%%%%%%%%%%
for j = i:pwasys.NR,
if ~isempty(pwasys.Fbar{i,j}),
% Continuity of the control input
try
% pwactrl.constraints=pwactrl.constraints+set((Kbar{i}-Kbar{j})*pwasys.Fbar{i,j}== 0,['Ki*F' num2str(i) '_' num2str(j) 's=Kis*F' num2str(i) '_' num2str(j) 's']);
end
end
end
end
if ~isfield(pwactrl,'Kbar'),
if pwactrl.Lin2PWA,
for i = 1:pwasys.NR,
if i~=pwasys.istar,
assign(Kbar{i}(:,1:end-1),Kbar{pwasys.istar(1)}(:,1:end-1));
end
end
end
end
pwactrl.Kbar = Kbar;