3381
|
1 ## Copyright (C) 1996 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. |
3213
|
18 |
|
19 page_screen_output = 1; |
|
20 opt = 0; |
|
21 QUITOPT = 7; |
|
22 while (opt != QUITOPT) |
|
23 opt = menu("Marsyas interface update demo:", ... |
|
24 "run Marsyas on the magnetically suspended ball example", ... |
|
25 "load continuous time marsyas example system", ... |
|
26 "load discrete-time marsyas example system", ... |
|
27 "bode plot of loaded system (MIMO)", ... |
|
28 "bode plot of loaded system (SISO)", ... |
|
29 "Design example", ... |
|
30 "Quit"); |
|
31 |
|
32 if(opt == 1) |
|
33 cmd = "system(""marsyas mag1d.mar"")"; |
|
34 run_cmd |
|
35 cmd = "system(""marplot -i"")"; |
|
36 run_cmd |
|
37 elseif(opt == 2) |
|
38 cmd = "ballsys = margetsys();"; |
|
39 run_cmd; |
|
40 cmd = "sysout(ballsys);" |
|
41 run_cmd |
|
42 elseif(opt == 3) |
|
43 cmd = "ballsys = margetsys(""disc"");"; |
|
44 run_cmd |
|
45 cmd = "sysout(ballsys);" |
|
46 run_cmd |
|
47 elseif(opt == 4) |
|
48 cmd = "bode(ballsys);"; |
|
49 run_cmd |
|
50 elseif(opt == 5) |
|
51 cmd = "bode(ballsys,[],1,1);"; |
|
52 run_cmd |
|
53 elseif(opt == 6) |
|
54 if(!exist("ballsys")) |
|
55 warning("You didn't load a system yet (option 2 or 3)"); |
|
56 else |
|
57 disp("Design LQG controller"); |
|
58 cmd = "sysout(ballsys)"; |
|
59 run_cmd |
|
60 disp("add noise inputs to system...") |
|
61 if(ballsys.n) |
|
62 disp("continuous system:") |
|
63 cmd = "ballsys1 = sysappend(ballsys,eye(ballsys.n));"; |
|
64 else |
|
65 disp("discrete system:") |
|
66 cmd = "ballsys1 = sysappend(ballsys,eye(ballsys.nz));"; |
|
67 endif |
|
68 run_cmd |
|
69 cmd = "sysout(ballsys1)"; |
|
70 run_cmd |
|
71 disp("Notice the two additional inputs, u_2, and u_3. These are the "); |
|
72 disp("""entry points"" for the gaussian noise disturbance."); |
|
73 disp(" "); |
|
74 disp("We'll design the controller to use only position feedback:") |
|
75 cmd = "ballsys1=sysprune(ballsys1,1,[]);"; |
|
76 run_cmd |
|
77 cmd = "sysout(ballsys1)"; |
|
78 run_cmd |
|
79 disp("Now design an LQG controller: Sigw: input noise") |
|
80 Sigw = eye(2) |
|
81 disp("Now design an LQG controller: Sigv: measurement noise") |
|
82 Sigv = eye(rows(ballsys1.c)) |
|
83 disp("State and input penalties:") |
|
84 Q = eye(2) |
|
85 R = 1 |
|
86 disp("Controlled input is input 1"); |
|
87 cmd="Ksys = lqg(ballsys1,Sigw,Sigv,Q,R,1);"; |
|
88 run_cmd |
|
89 disp("sysout(Ksys);"); |
|
90 sysout(Ksys); |
|
91 |
|
92 disp("marsyas conversion: output in scalar form:") |
|
93 cmd = "maroutsys(Ksys, ""ball_controller"",""scalar"");"; |
|
94 run_cmd |
|
95 disp("here's the output file:") |
|
96 prompt |
|
97 system("more ball_controller.mar"); |
|
98 |
|
99 disp("marsyas conversion: output in state space form: (default option;") |
|
100 disp("the ""ss"" in the command below is not needed)") |
|
101 cmd = "maroutsys(Ksys, ""ball_controller_ss"",""ss"");"; |
|
102 run_cmd |
|
103 disp("here's the output file:") |
|
104 prompt |
|
105 system("more ball_controller_ss.mar"); |
|
106 |
|
107 disp("marsyas conversion: output in transfer function form:") |
|
108 cmd = "maroutsys(Ksys, ""ball_controller_tf"",""tf"")" |
|
109 run_cmd |
|
110 disp("here's the output file:") |
|
111 prompt |
|
112 system("more ball_controller_tf.mar"); |
|
113 |
|
114 endif |
|
115 endif |
|
116 endwhile |