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