]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/augw.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / augw.m
1 ## Copyright (C) 2009, 2010   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn{Function File} {@var{P} =} augw (@var{G}, @var{W1}, @var{W2}, @var{W3})
20 ## Extend plant for stacked S/KS/T problem.  Subsequently, the robust control problem
21 ## can be solved by h2syn or hinfsyn.
22 ##
23 ## @strong{Inputs}
24 ## @table @var
25 ## @item G
26 ## LTI model of plant.
27 ## @item W1
28 ## LTI model of performance weight.  Bounds the largest singular values of sensitivity @var{S}.
29 ## Model must be empty @code{[]}, SISO or of appropriate size.
30 ## @item W2
31 ## LTI model to penalize large control inputs.  Bounds the largest singular values of @var{KS}.
32 ## Model must be empty @code{[]}, SISO or of appropriate size.
33 ## @item W3
34 ## LTI model of robustness and noise sensitivity weight.  Bounds the largest singular values of 
35 ## complementary sensitivity @var{T}.  Model must be empty @code{[]}, SISO or of appropriate size.
36 ## @end table
37 ##
38 ## All inputs must be proper/realizable.
39 ## Scalars, vectors and matrices are possible instead of LTI models.
40 ##
41 ## @strong{Outputs}
42 ## @table @var
43 ## @item P
44 ## State-space model of augmented plant.
45 ## @end table
46 ##
47 ## @strong{Block Diagram}
48 ## @example
49 ## @group
50 ##
51 ##     | W1 | -W1*G |     z1 = W1 r  -  W1 G u
52 ##     | 0  |  W2   |     z2 =          W2   u
53 ## P = | 0  |  W3*G |     z3 =          W3 G u
54 ##     |----+-------|
55 ##     | I  |    -G |     e  =    r  -     G u
56 ## @end group
57 ## @end example
58 ## @example
59 ## @group
60 ##                                                       +------+  z1
61 ##             +---------------------------------------->|  W1  |----->
62 ##             |                                         +------+
63 ##             |                                         +------+  z2
64 ##             |                 +---------------------->|  W2  |----->
65 ##             |                 |                       +------+
66 ##  r   +    e |   +--------+  u |   +--------+  y       +------+  z3
67 ## ----->(+)---+-->|  K(s)  |----+-->|  G(s)  |----+---->|  W3  |----->
68 ##        ^ -      +--------+        +--------+    |     +------+
69 ##        |                                        |
70 ##        +----------------------------------------+
71 ## @end group
72 ## @end example
73 ## @example
74 ## @group
75 ##                +--------+
76 ##                |        |-----> z1 (p1x1)          z1 = W1 e
77 ##  r (px1) ----->|  P(s)  |-----> z2 (p2x1)          z2 = W2 u
78 ##                |        |-----> z3 (p3x1)          z3 = W3 y
79 ##  u (mx1) ----->|        |-----> e (px1)            e = r - y
80 ##                +--------+
81 ## @end group
82 ## @end example
83 ## @example
84 ## @group
85 ##                +--------+  
86 ##        r ----->|        |-----> z
87 ##                |  P(s)  |
88 ##        u +---->|        |-----+ e
89 ##          |     +--------+     |
90 ##          |                    |
91 ##          |     +--------+     |
92 ##          +-----|  K(s)  |<----+
93 ##                +--------+
94 ## @end group
95 ## @end example
96 ## @example
97 ## @group
98 ## Reference:
99 ## Skogestad, S. and Postlethwaite I.
100 ## Multivariable Feedback Control: Analysis and Design
101 ## Second Edition
102 ## Wiley 2005
103 ## Chapter 3.8: General Control Problem Formulation
104 ## @end group
105 ## @end example
106 ## @seealso{h2syn, hinfsyn, mixsyn}
107 ## @end deftypefn
108
109 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
110 ## Created: December 2009
111 ## Version: 0.2
112
113 function P = augw (G, W1 = [], W2 = [], W3 = [])
114
115   if (nargin == 0 || nargin > 4)
116     print_usage ();
117   endif
118
119   G = ss (G);
120   [p, m] = size (G);
121
122   [W1, p1, m1] = __adjust_weighting__ (W1, p);
123   [W2, p2, m2] = __adjust_weighting__ (W2, m);
124   [W3, p3, m3] = __adjust_weighting__ (W3, p);
125
126   ## Pr = [1; 0; 0; 1];
127   ## Pu = [-1; 0; 1; -1]*G + [0; 1; 0; 0];
128
129   Pr = ss ([eye(m1,p)  ;
130             zeros(m2,p);
131             zeros(m3,p);
132             eye(p,p)   ]);
133
134   Pu1 = ss ([-eye(m1,p)  ;
135               zeros(m2,p);
136               eye(m3,p)  ;
137              -eye(p,p)   ]);
138
139   Pu2 = ss ([zeros(m1,m);
140              eye(m2,m)  ;
141              zeros(m3,m);
142              zeros(p,m) ]);
143
144   Pu = Pu1 * G  +  Pu2;
145
146   P = append (W1, W2, W3, eye (p, p)) * [Pr, Pu];
147
148 endfunction
149
150
151 function [W, p, m] = __adjust_weighting__ (W, s)
152
153   W = ss (W);
154   [p, m] = size (W);
155
156   if (m == 0 || m == s)               # model is empty or has s inputs
157     return;
158   elseif (m == 1)                     # model is SISO or SIMO
159     tmp = W;
160     for k = 2 : s
161       W = append (W, tmp);            # stack single-input model s times
162     endfor
163     [p, m] = size (W);                # weighting function now of correct size
164   else                                # model is MIMO or MISO
165     error ("augw: %s must have 1 or %d inputs", inputname (1), s);
166   endif 
167
168 endfunction