7017
|
1 ## Copyright (C) 1996, 2000, 2002, 2004, 2005, 2007 |
|
2 ## Auburn University. All rights reserved. |
3421
|
3 ## |
3426
|
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. |
3421
|
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. |
3426
|
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/>. |
3421
|
19 |
|
20 ## O B S O L E T E * * * D O N O T U S E! |
|
21 ## |
|
22 ## Use lqg instead. |
|
23 ## |
|
24 ## function [K,Q,P,Ee,Er] = dlqg(A,B,C,G,Sigw,Sigv,Q,R) |
|
25 ## function [K,Q,P,Ee,Er] = dlqg(Sys,Sigw,Sigv,Q,R) |
3426
|
26 ## |
3421
|
27 ## design a discrete-time linear quadratic gaussian optimal controller |
|
28 ## for the system |
|
29 ## |
|
30 ## x(k+1) = A x(k) + B u(k) + G w(k) [w]=N(0,[Sigw 0 ]) |
|
31 ## y(k) = C x(k) + v(k) [v] ( 0 Sigv ]) |
|
32 ## |
|
33 ## Outputs: |
|
34 ## K: system data structure format LQG optimal controller |
|
35 ## P: Solution of control (state feedback) algebraic Riccati equation |
|
36 ## Q: Solution of estimation algebraic Riccati equation |
|
37 ## Ee: estimator poles |
|
38 ## Es: controller poles |
|
39 ## inputs: |
3426
|
40 ## A,B,C,G, or Sys: state space representation of system. |
|
41 ## Sigw, Sigv: covariance matrices of independent Gaussian noise processes |
3421
|
42 ## (as above) |
3426
|
43 ## Q, R: state, control weighting matrices for dlqr call respectively. |
3421
|
44 ## |
|
45 ## See also: lqg, dlqe, dlqr |
|
46 |
|
47 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
48 ## Created: August 1995 |
|
49 |
|
50 function [K, Q, P, Ee, Er] = dlqg (A, B, C, G, Sigw, Sigv, Q, R) |
|
51 |
|
52 warning("dlqg: obsolete. use lqg instead (system data structure format)"); |
|
53 |
|
54 if (nargin == 5) |
|
55 ## system data structure format |
|
56 |
|
57 ## check that it really is system data structure |
4030
|
58 if(! isstruct(A) ) |
3421
|
59 error("dlqg: 5 arguments, first argument is not a system data structure structure") |
|
60 endif |
|
61 |
|
62 sys = sysupdate(sys,"ss"); # make sure in proper form |
|
63 [ncstates,ndstates,nin,nout] = sysdimensions(sys); |
|
64 if(ndstates == -1) |
|
65 error("this message should never appear: bad system dimensions"); |
|
66 endif |
|
67 |
|
68 if(ncstates) |
|
69 error("dlqg: system has continuous-time states (try lqg?)") |
|
70 elseif(ndstates < 1) |
|
71 error("dlqg: system has no discrete time states") |
|
72 elseif(nin <= columns(Sigw)) |
|
73 error(["dlqg: ",num2str(nin)," inputs provided, noise dimension is ", ... |
3426
|
74 num2str(columns(Sigw))]) |
3421
|
75 elseif(nout != columns(Sigv)) |
|
76 error(["dlqg: number of outputs (",num2str(nout),") incompatible with ", ... |
3426
|
77 "dimension of Sigv (",num2str(columns(Sigv)),")"]) |
3421
|
78 endif |
|
79 |
|
80 ## put parameters into correct variables |
|
81 R = Sigw; |
|
82 Q = G; |
|
83 Sigv = C; |
|
84 Sigw = B; |
|
85 [A,B,C,D] = sys2ss(Sys) |
|
86 [n,m] = size(B) |
|
87 m1 = columns(Sigw); |
|
88 m2 = m1+1; |
|
89 G = B(:,1:m1); |
|
90 B = B(:,m2:m); |
|
91 |
|
92 elseif (nargin == 8) |
|
93 ## state-space format |
|
94 m = columns(B); |
|
95 m1 = columns(G); |
|
96 p = rows(C); |
|
97 n = abcddim(A,B,C,zeros(p,m)); |
|
98 n1 = abcddim(A,G,C,zeros(p,m1)); |
|
99 if( (n == -1) || (n1 == -1)) |
|
100 error("dlqg: A,B,C,G incompatibly dimensioned"); |
|
101 elseif(p != columns(Sigv)) |
|
102 error("dlqg: C, Sigv incompatibly dimensioned"); |
|
103 elseif(m1 != columns(Sigw)) |
|
104 error("dlqg: G, Sigw incompatibly dimensioned"); |
|
105 endif |
|
106 else |
3427
|
107 error ("dlqg: invalid number of arguments") |
3421
|
108 endif |
|
109 |
4030
|
110 if (! (issquare(Sigw) && issquare(Sigv) ) ) |
3421
|
111 error("dlqg: Sigw, Sigv must be square"); |
|
112 endif |
|
113 |
|
114 ## now we can just do the design; call dlqr and dlqe, since all matrices |
|
115 ## are not given in Cholesky factor form (as in h2syn case) |
|
116 [Ks, P, Er] = dlqr(A,B,Q,R); |
|
117 [Ke, Q, jnk, Ee] = dlqe(A,G,C,Sigw,Sigv); |
|
118 Ac = A - Ke*C - B*Ks; |
|
119 Bc = Ke; |
|
120 Cc = -Ks; |
|
121 Dc = zeros(rows(Cc),columns(Bc)); |
4771
|
122 K = ss(Ac,Bc,Cc,Dc,1); |
3421
|
123 disp("HODEL: need to add names to this guy!") |
|
124 |
|
125 endfunction |