7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
5016
|
21 ## @deftypefn {Function File} {[@var{K}, @var{gain}, @var{kc}, @var{kf}, @var{pc}, @var{pf}] = } h2syn (@var{asys}, @var{nu}, @var{ny}, @var{tol}) |
|
22 ## Design |
|
23 ## @iftex |
|
24 ## @tex |
|
25 ## $ { \cal H }_2 $ |
|
26 ## @end tex |
|
27 ## @end iftex |
|
28 ## @ifinfo |
|
29 ## H-2 |
|
30 ## @end ifinfo |
|
31 ## optimal controller per procedure in |
|
32 ## Doyle, Glover, Khargonekar, Francis, @cite{State-Space Solutions to Standard} |
|
33 ## @iftex |
|
34 ## @tex |
|
35 ## $ { \cal H }_2 $ @cite{and} $ { \cal H }_\infty $ |
|
36 ## @end tex |
|
37 ## @end iftex |
|
38 ## @ifinfo |
|
39 ## @cite{H-2 and H-infinity} |
|
40 ## @end ifinfo |
|
41 ## @cite{Control Problems}, @acronym{IEEE} @acronym{TAC} August 1989. |
3430
|
42 ## |
5016
|
43 ## Discrete-time control per Zhou, Doyle, and Glover, @cite{Robust and optimal control}, Prentice-Hall, 1996. |
3430
|
44 ## |
5016
|
45 ## @strong{Inputs} |
3430
|
46 ## @table @var |
3502
|
47 ## @item asys |
4771
|
48 ## system data structure (see ss, sys2ss) |
3430
|
49 ## @itemize @bullet |
|
50 ## @item controller is implemented for continuous time systems |
5016
|
51 ## @item controller is @strong{not} implemented for discrete time systems |
3430
|
52 ## @end itemize |
|
53 ## @item nu |
|
54 ## number of controlled inputs |
|
55 ## @item ny |
|
56 ## number of measured outputs |
|
57 ## @item tol |
5016
|
58 ## threshold for 0. Default: 200*@code{eps} |
3430
|
59 ## @end table |
|
60 ## |
|
61 ## @strong{Outputs} |
|
62 ## @table @var |
3502
|
63 ## @item k |
3430
|
64 ## system controller |
|
65 ## @item gain |
|
66 ## optimal closed loop gain |
3502
|
67 ## @item kc |
3430
|
68 ## full information control (packed) |
3502
|
69 ## @item kf |
3430
|
70 ## state estimator (packed) |
3502
|
71 ## @item pc |
5016
|
72 ## @acronym{ARE} solution matrix for regulator subproblem |
3502
|
73 ## @item pf |
5016
|
74 ## @acronym{ARE} solution matrix for filter subproblem |
3430
|
75 ## @end table |
|
76 ## @end deftypefn |
|
77 |
|
78 ## Updated for System structure December 1996 by John Ingram |
|
79 |
|
80 function [K, gain, Kc, Kf, Pc, Pf] = h2syn (Asys, nu, ny, tol) |
|
81 |
7131
|
82 if (nargin < 3 || nargin > 4) |
6046
|
83 print_usage (); |
7131
|
84 elseif (nargin == 3) |
|
85 [chkdgkf, dgs] = is_dgkf (Asys, nu, ny); |
|
86 elseif (nargin == 4) |
|
87 [chkdgkf, dgs] = is_dgkf (Asys, nu, ny, tol); |
3430
|
88 endif |
|
89 |
7131
|
90 if (! chkdgkf) |
|
91 error ("h2syn: system does not meet required assumptions") |
3430
|
92 endif |
|
93 |
|
94 ## extract dgs information |
7131
|
95 nw = dgs.nw; |
|
96 nu = dgs.nu; |
|
97 nz = dgs.nz; |
|
98 ny = dgs.ny; |
|
99 |
|
100 A = dgs.A; |
|
101 |
|
102 Bw = dgs.Bw; |
|
103 Bu = dgs.Bu; |
|
104 |
|
105 Cz = dgs.Cz; |
|
106 Cy = dgs.Cy; |
|
107 |
|
108 Dzw = dgs.Dzw; |
|
109 Dzu = dgs.Dzu; |
|
110 |
|
111 Dyw = dgs.Dyw; |
|
112 Dyu = dgs.Dyu; |
|
113 |
3430
|
114 d22nz = dgs.Dyu_nz; |
7131
|
115 |
3430
|
116 dflg = dgs.dflg; |
|
117 |
7131
|
118 if (norm (Dzw, Inf) > norm ([Dzw, Dzu; Dyw, Dyu], Inf)*1e-12) |
|
119 warning ("h2syn: Dzw nonzero; feedforward not implemented") |
3430
|
120 Dzw |
|
121 D = [Dzw, Dzu ; Dyw, Dyu] |
|
122 endif |
|
123 |
|
124 ## recover i/o transformations |
7131
|
125 Ru = dgs.Ru; |
|
126 Ry = dgs.Ry; |
3430
|
127 |
7131
|
128 [ncstates, ndstates, nout, nin] = sysdimensions (Asys); |
|
129 Atsam = sysgettsam (Asys); |
|
130 [Ast, Ain, Aout] = sysgetsignals (Asys); |
|
131 |
|
132 if (dgs.dflg == 0) |
|
133 Pc = are (A, Bu*Bu', Cz'*Cz); # solve control, filtering ARE's |
|
134 Pf = are(A', Cy'*Cy, Bw*Bw'); |
3430
|
135 F2 = -Bu'*Pc; # calculate feedback gains |
|
136 L2 = -Pf*Cy'; |
|
137 |
|
138 AF2 = A + Bu*F2; |
|
139 AL2 = A + L2*Cy; |
|
140 CzF2 = Cz + (Dzu/Ru)*F2; |
|
141 BwL2 = Bw+L2*(Ry\Dyw); |
|
142 |
|
143 else |
|
144 ## discrete time solution |
7131
|
145 error ("h2syn: discrete-time case not yet implemented") |
|
146 Pc = dare (A, Bu*Bu', Cz'*Cz); |
|
147 Pf = dare (A', Cy'*Cy, Bw*Bw'); |
3430
|
148 endif |
|
149 |
|
150 nn = ncstates + ndstates; |
7131
|
151 In = eye (nn); |
3430
|
152 KA = A + Bu*F2 + L2*Cy; |
7131
|
153 Kc1 = ss (AF2, Bw, CzF2, zeros (nz, nw)); |
|
154 Kf1 = ss (AL2, BwL2, F2, zeros (nu, nw)); |
3430
|
155 |
7131
|
156 g1 = h2norm (Kc1); |
|
157 g2 = h2norm (Kf1); |
3430
|
158 |
|
159 ## compute optimal closed loop gain |
7131
|
160 gain = sqrt (g1*g1 + g2*g2); |
3430
|
161 |
7131
|
162 if (nargout) |
|
163 Kst = strappend (Ast, "_K"); |
|
164 Kin = strappend (Aout((nout-ny+1):(nout)), "_K"); |
|
165 Kout = strappend (Ain((nin-nu+1):(nin)), "_K"); |
3430
|
166 |
|
167 ## compute systems for return |
7131
|
168 K = ss (KA, -L2/Ru, Ry\F2, zeros(nu,ny), Atsam, ncstates, |
|
169 ndstates, Kst, Kin, Kout); |
3430
|
170 endif |
|
171 |
|
172 if (nargout > 2) |
|
173 ## system full information control state names |
7131
|
174 stname2 = strappend (Ast, "_FI"); |
3430
|
175 |
|
176 ## system full information control input names |
7131
|
177 inname2 = strappend (Ast, "_FI_in"); |
3430
|
178 |
|
179 ## system full information control output names |
7131
|
180 outname2 = strappend (Aout(1:(nout-ny)), "_FI_out"); |
3430
|
181 |
|
182 nz = rows (Cz); |
|
183 nw = columns (Bw); |
|
184 |
7131
|
185 Kc = ss (AF2, In, CzF2, zeros(nz,nn), Atsam, |
|
186 ncstates, ndstates, stname2, inname2, outname2); |
3430
|
187 endif |
|
188 |
|
189 if (nargout >3) |
|
190 ## fix system state estimator state names |
7131
|
191 stname3 = strappend (Ast, "_Kf"); |
3430
|
192 |
|
193 ## fix system state estimator input names |
7131
|
194 inname3 = strappend (Ast, "_Kf_noise"); |
3430
|
195 |
|
196 ## fix system state estimator output names |
7131
|
197 outname3 = strappend (Ast, "_est"); |
3430
|
198 |
7131
|
199 Kf = ss (AL2, BwL2, In, zeros(nn,nw),Atsam, |
|
200 ncstates, ndstates, stname3, inname3, outname3); |
3430
|
201 endif |
|
202 |
|
203 endfunction |