annotate scripts/control/dhinfdemo.m @ 3284:f7e4a95916f2

[project @ 1999-10-13 21:37:04 by jwe]
author jwe
date Wed, 13 Oct 1999 21:37:40 +0000
parents 98e15955107e
children 69b167451491
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3236
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
1 # Copyright (C) 1996,1998 Kai Mueller
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
2 #
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
3 # This file is part of Octave.
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
4 #
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
6 # under the terms of the GNU General Public License as published by the
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
8 # later version.
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
9 #
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
13 # for more details.
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
14 #
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
15 # You should have received a copy of the GNU General Public License
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
3284
f7e4a95916f2 [project @ 1999-10-13 21:37:04 by jwe]
jwe
parents: 3236
diff changeset
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
3236
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
18
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
19 # ------------------------------------------------------------
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
20 # dhinfdemo Design of a discrete H_infinity controller.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
21 # This is not a true discrete design. The design
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
22 # is carried out in continuous time while the
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
23 # effect of sampling is described by a bilinear
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
24 # transformation of the sampled system.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
25 # This method works quite well if the sampling
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
26 # period is "small" compared to the plant time
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
27 # constants.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
28 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
29 # This is a script file for OCTAVE.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
30 # ------------------------------------------------------------
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
31 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
32 # continuous plant:
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
33 # 1
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
34 # G(s) = --------------
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
35 # (s + 2)(s + 1)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
36 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
37 # discretised plant with ZOH (Sampling period = Ts = 1 second)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
38 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
39 # 0.39958z + 0.14700
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
40 # G(s) = --------------------------
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
41 # (z - 0.36788)(z - 0.13533)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
42 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
43 # +----+
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
44 # -------------------->| W1 |---> v1
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
45 # z | +----+
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
46 # ----|-------------+ || T || => min.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
47 # | | vz infty
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
48 # | +---+ v +----+
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
49 # *--->| G |--->O--*-->| W2 |---> v2
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
50 # | +---+ | +----+
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
51 # | |
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
52 # | +---+ |
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
53 # -----| K |<-------
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
54 # +---+
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
55 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
56 # W1 and W2 are the robustness and performancs weighting
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
57 # functions
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
58
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
59 # K. Mueller, <mueller@ifr.ing.tu-bs.de>
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
60 # Technical University of Braunschweig, IfR
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
61
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
62 echo off
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
63 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
64 disp(" --------------------------------------------------");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
65 disp(" Discrete H_infinity optimal control for the plant:");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
66 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
67 disp(" 0.39958z + 0.14700");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
68 disp(" G(s) = --------------------------");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
69 disp(" (z - 0.36788)(z - 0.13533)");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
70 disp(" --------------------------------------------------");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
71 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
72
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
73 disp("sampling time:")
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
74 cmd = "Ts = 1.0;";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
75 disp(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
76 eval(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
77 disp("weighting on actuator value u");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
78 cmd = "W1 = wgt1o(0.1, 200.0, 50.0);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
79 disp(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
80 eval(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
81 disp("weighting on controlled variable y");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
82 cmd = "W2 = wgt1o(350.0, 0.05, 0.0002);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
83 disp(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
84 eval(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
85 # omega axis (column vector)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
86 ww = vec(logspace(-4.99, 3.99, 100));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
87
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
88 disp("Create ZOH equivalent model of a continuous plant");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
89 cmd = "G = tf2sys(2,[1 3 2]); Gd = c2d(G, Ts);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
90 run_cmd
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
91
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
92 # w-plane (continuous representation of the sampled system)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
93 disp("W-plane transform of discrete time system:");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
94 cmd = "Gw = d2c(Gd, \"bi\");";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
95 run_cmd
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
96
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
97 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
98 disp(" o building P...");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
99 # need One as the pseudo transfer function One = 1
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
100 cmd = "One = ugain(1);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
101 disp(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
102 eval(cmd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
103 cmd = " psys = buildssic([1 4;2 4;3 1],[3],[2 3 5],[3 4],Gw,W1,W2,One);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
104 run_cmd;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
105 disp(" o controller design...");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
106 cmd = "[K, gfin, GWC] = hinfsyn(psys, 1, 1, 0.1, 10.0, 0.02);";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
107 run_cmd
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
108
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
109 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
110 fig_n = 1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
111 yn = input(" * Plot magnitudes of W1KS and W2S? [n]: ","S");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
112 if (length(yn) >= 1)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
113 if ((yn(1) == "y") || (yn(1) == 'Y'))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
114 disp(" o magnitudes of W1KS and W2S...");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
115 gwx = sysprune(GWC, 1, 1);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
116 mag1 = bode(gwx, ww);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
117 if (columns(mag1) > 1); mag1 = mag1'; endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
118 gwx = sysprune(GWC, 2, 1);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
119 mag2 = bode(gwx, ww);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
120 if (columns(mag2) > 1); mag2 = mag2'; endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
121 figure(fig_n)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
122 fig_n = fig_n + 1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
123 gset grid
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
124 loglog(ww, [mag1 mag2]);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
125 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
126 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
127
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
128 Kd = c2d(K, "bi", Ts);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
129 GG = buildssic([1 2; 2 1], [], [1 2], [-2], Gd, Kd);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
130 disp(" o closed loop poles...");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
131 damp(GG);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
132
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
133 disp(" ");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
134 yn = input(" * Plot closed loop step responses? [n]: ","S");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
135 if (length(yn) >= 1)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
136 if ((yn(1) == "y") || (yn(1) == 'Y'))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
137 disp(" o step responses of T and KS...");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
138 figure(fig_n)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
139 step(GG, 1, 10);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
140 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
141 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
142
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
143 # --------- End of dhinfdemo/kpm