3279
|
1 # Copyright (C) 1996 Auburn University. All Rights Reserved |
3213
|
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 |
3284
|
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3213
|
18 |
|
19 function bddemo() |
|
20 # Octave Controls toolbox demo: Block Diagram Manipulations demo |
|
21 # Written by David Clem August 15, 1994 |
|
22 # Modified by A S Hodel Summer-Fall 1996 |
|
23 |
|
24 str_sav = implicit_str_to_num_ok; |
|
25 sav_page = page_screen_output; |
|
26 implicit_str_to_num_ok = 1; |
|
27 page_screen_output = 1; |
|
28 |
|
29 while (1) |
|
30 clc |
|
31 k=0; |
|
32 while(k > 14 || k < 1) |
|
33 k = menu("Octave Block Diagram Manipulations Demo", ... |
|
34 "sysadd/syssub: F(s) = G(s) +/- H(s)", ... |
|
35 "sysappend: add new inputs/outputs", ... |
3228
|
36 "syssetsignals: change names of inputs, outputs, and/or states", ... |
3213
|
37 "sysconnect: connect specified system inputs/outputs", ... |
|
38 "syscont/sysdisc: extract the continuous (discrete) part of a system", ... |
|
39 "sysdup: duplicate specified inputs/outputs", ... |
|
40 "sysgroup: group two systems into a single system,", ... |
|
41 "sysmult: F(s) = G(s)*H(s) (series connection)", ... |
|
42 "sysprune: keep only specified inputs/outputs", ... |
|
43 "sysscale: scale inputs/outputs by specified gain matrices", ... |
|
44 "parallel: parallel connection of two systems", ... |
|
45 "buildssic: the combination of all", ... |
|
46 "Design examples:", ... |
|
47 "Return to main demo menu"); |
|
48 endwhile |
|
49 if (k == 1) |
|
50 clc |
|
51 disp("sysadd: add two systems together") |
|
52 disp("syssub: subtract F = G - H") |
|
53 prompt |
|
54 help sysadd |
|
55 prompt |
|
56 help syssub |
|
57 prompt |
|
58 disp('Example #1, \n') |
|
59 cmd = "sys1 = tf2sys([1 -1],[1 2 1]);"; |
|
60 run_cmd |
|
61 cmd = "sys2 = tf2sys([1 -1],[1 2 3]);"; |
|
62 run_cmd |
|
63 disp("sys1=") |
|
64 sysout(sys1); |
|
65 prompt |
|
66 disp("sys2=") |
|
67 sysout(sys2); |
|
68 cmd = "sys_sum1 = sysadd(sys1,sys1);"; |
|
69 run_cmd |
|
70 disp("This example adds sys1 to itself.") |
|
71 cmd = "sysout(sys_sum1)"; |
|
72 run_cmd |
|
73 disp("Notice that the numerator is twice what it used to be.") |
|
74 prompt |
|
75 disp("Example 2:") |
|
76 cmd = "sys_sub1 = syssub(sys1,sys2);"; |
|
77 run_cmd |
|
78 disp("Notice that sysadd (actually sysgroup, called by sysadd) lets you") |
|
79 disp("know that your two systems had identical names for their states,") |
|
80 disp("inputs and outputs. The warning message is perfectly harmless,") |
|
81 disp("and is provided for user information only.") |
|
82 disp("sys_sub1=") |
|
83 sysout(sys_sub1) |
|
84 disp("Notice that, since the two transfer functions had different") |
|
85 disp("denominators, syssub converted the primary system type to ") |
|
86 disp("state space. This is the typical behavior unless the") |
|
87 disp("the two systems are both SISO, they both have the same poles,") |
|
88 disp("and at least one of them has tf for its primary system type."); |
|
89 prompt |
|
90 elseif (k == 2) |
|
91 disp("sysappend: add new inputs and/or outputs to a system") |
|
92 help sysappend |
|
93 prompt |
|
94 disp("Consider a double-integrator system:") |
|
95 sys = tf2sys(1,[1 0 0]); |
|
96 sys=sysupdate(sys,"ss"); |
|
97 sysout(sys,"ss"); |
|
98 disp("We add a velocity disturbance input as follows:") |
|
99 cmd = "sys1=sysappend(sys,[1;0]);"; |
|
100 run_cmd |
|
101 sysout(sys1,"ss"); |
|
102 disp("Names of inputs can be included as follows:") |
|
103 cmd = "sys1=sysappend(sys,[1;0], [],[],[],\"Disturb\");"; |
|
104 run_cmd |
|
105 disp("Notice that empty matrices can be listed for the D matrix if") |
|
106 disp("all entries are zeros.") |
|
107 disp(" ") |
|
108 disp("sys1 is thus:") |
|
109 sysout(sys1); |
|
110 prompt |
|
111 elseif (k == 3) |
3228
|
112 disp("syssetsignals:") |
|
113 help syssetsignals |
3213
|
114 disp("Example system"); |
|
115 a = rand(3,3); |
|
116 b = rand(3,2); |
|
117 c = rand(2,3); |
|
118 sys = ss2sys(a,b,c); |
|
119 sysout(sys); |
|
120 prompt |
|
121 disp("Change state names to larry, moe, and curly as follows:") |
3228
|
122 cmd = "sys = syssetsignals(sys,\"st\",list(\"larry\",\"moe \" , \"curly\"));"; |
3213
|
123 run_cmd |
|
124 disp("Indicate that output 2 is discrete-time:") |
3228
|
125 cmd = "sys = syssetsignals(sys,\"yd\",1,2);"; |
|
126 run_cmd |
|
127 disp("Change output 2 name to \"Vir\""); |
|
128 cmd = "sys = syssetsignals(sys,\"out\",\"Vir\",2);"; |
3213
|
129 run_cmd |
|
130 disp("Resulting system is:") |
|
131 sysout(sys); |
|
132 prompt |
|
133 elseif (k == 4) |
|
134 help sysconnect |
|
135 prompt |
|
136 disp("********* N O T E *********") |
|
137 disp("sysconnect is demonstrated fully in the design examples (option 13)"); |
|
138 prompt |
|
139 elseif (k == 5) |
|
140 disp("syscont and sysdisc: ") |
|
141 disp("Example block diagram 1:") |
|
142 disp(" ------------------ ---------------------"); |
|
143 disp(" u_in ->| Discrete system |--->| Continuous system | ---> y_out"); |
|
144 disp(" ------------------ ---------------------"); |
|
145 sys1 = tf2sys([1 2],[1 2 1], 1,"u_in","y_disc"); |
|
146 sys2 = tf2sys([1 0],[1 -3 -2],0,"c_in","y_out"); |
|
147 sys = sysmult(sys2,sys1); |
|
148 disp("Consider the hybrid system") |
|
149 sysout(sys); |
|
150 prompt |
|
151 help syscont |
|
152 disp("The continuous part of the system can be extracted with syscont") |
|
153 cmd = "[csys,Acd,Ccd] = syscont(sys);"; |
|
154 run_cmd |
|
155 disp("The resulting csys is") |
|
156 sysout(csys); |
|
157 disp("Notice that B is 0; there is no purely continuous path from the") |
|
158 disp("input to the output"); |
|
159 prompt |
|
160 help sysdisc |
|
161 disp("The discrete part of the system can be extracted with sysdisc") |
|
162 cmd = "[dsys,Adc,Cdc] = sysdisc(sys)"; |
|
163 run_cmd |
|
164 disp("The resulting dsys is") |
|
165 sysout(dsys); |
|
166 disp("sysdisc returns dsys=empty since sys has no discrete outputs."); |
|
167 prompt |
|
168 disp("Example block diagram 2:") |
|
169 sys1 = tf2sys([1 2],[1 2 1], 1,"u_in","y_disc"); |
|
170 sys2 = tf2sys([1 0],[1 -3 -2],0,"c_in","y_out"); |
|
171 disp(" ---------------------") |
|
172 disp(" u_in -->o-->| Discrete system | --------> y_disc") |
|
173 disp(" ^ --------------------- |") |
|
174 disp(" | | "); |
|
175 disp(" -----------------------------|---") |
|
176 disp(" | |") |
|
177 disp(" ------------------------------ |") |
|
178 disp(" | |") |
|
179 disp(" v --------------------- |") |
|
180 disp(" c_in -->o-->| continuous system | --------> y_out") |
|
181 disp(" ---------------------") |
|
182 disp("repeat the above example with sys=") |
|
183 sys = sysgroup(sys1, sys2); |
|
184 sysout(sys) |
|
185 prompt |
|
186 sys = sysconnect(sys,[1 2],[2 1]); |
|
187 sysout(sys); |
|
188 cmd = "[csys,Acd,Bcd] = syscont(sys);"; |
|
189 run_cmd |
|
190 cmd = "[dsys,Acd,Bcd] = sysdisc(sys);"; |
|
191 run_cmd |
|
192 disp("csys is now") |
|
193 sysout(csys) |
|
194 disp("dsys is now") |
|
195 sysout(dsys); |
|
196 prompt |
|
197 elseif (k == 6) |
|
198 help sysdup |
|
199 prompt |
|
200 disp("********* N O T E *********") |
|
201 disp("sysdup is fully demonstrated in the design examples (option 13)") |
|
202 prompt |
|
203 elseif (k == 7) |
|
204 help sysgroup |
|
205 disp(" ") |
|
206 prompt |
|
207 disp("Example: combine two SISO systems together:") |
|
208 cmd = "sys_a=tf2sys([1 2],[3 4]);"; |
|
209 run_cmd |
|
210 cmd = "sys_b=tf2sys([5 6],[7 8],1);"; |
|
211 run_cmd |
|
212 cmd = "sys_g=sysgroup(sys_a,sys_b);"; |
|
213 run_cmd |
|
214 disp("Notice that sysgroup warns you when you join a purely continuous") |
|
215 disp("system to a purely discrete system. sysgroup also warns when") |
|
216 disp("you join two systems that have common state, input, or output names.") |
|
217 cmd = "sysout(sys_g)"; |
|
218 run_cmd |
|
219 disp("Since the grouped system is a multiple-input multiple-output system,") |
|
220 disp("the output system is by default in state-space format.") |
|
221 disp(" ") |
|
222 disp("********* N O T E *********") |
|
223 disp("sysgroup is further demonstrated in the design examples (option 13)") |
|
224 prompt |
|
225 elseif (k == 8) |
|
226 help sysmult |
|
227 disp("sysmult performs a series connection of two systems.") |
|
228 disp("Example 1") |
|
229 disp(" ") |
|
230 disp(" ---------- ----------") |
|
231 disp(" u --->| Bsys |---->| Asys |---> y") |
|
232 disp(" ---------- ----------") |
|
233 disp(" ") |
|
234 Asys = tf2sys(1,[1 2 1],0,"a_in","a_out"); |
|
235 Bsys = tf2sys([2 3],[1 3 2],0,"b_in","b_out"); |
|
236 disp("Asys=") |
|
237 sysout(Asys); |
|
238 disp("Bsys="); |
|
239 sysout(Bsys); |
|
240 cmd = "sys = sysmult(Asys,Bsys);"; |
|
241 run_cmd |
|
242 disp("sys =") |
|
243 sysout(sys); |
|
244 disp("Notice that sysmult automatically transforms to state space") |
|
245 disp("internal representation. This is to avoid numerical problems") |
|
246 disp("when multiplying polynomials"); |
|
247 prompt |
|
248 disp("Example 2: same system, except that Bsys is discrete-time"); |
|
249 Bsys = tf2sys([2 3],[1 3 2],1e-2,"b_in","b_out"); |
|
250 sysout(Bsys); |
|
251 cmd = "sys = sysmult(Asys,Bsys);"; |
|
252 run_cmd |
|
253 disp("sys =") |
|
254 sysout(sys); |
|
255 prompt |
|
256 elseif (k == 9) |
|
257 help sysprune |
|
258 prompt |
|
259 disp("********* N O T E *********") |
|
260 disp("sysprune is demonstrated in the design examples (option 13)"); |
|
261 prompt |
|
262 elseif (k == 10) |
|
263 help sysscale |
|
264 disp(" ") |
|
265 prompt |
|
266 disp("********* N O T E *********") |
|
267 disp("See the design examples (option 13) for use of sysscale.") |
|
268 prompt |
|
269 elseif ( k == 11) |
|
270 help parallel |
|
271 disp("parallel operates by making a call to sysgroup and sysscale.") |
|
272 disp("Example:") |
|
273 sys1 = tf2sys(1,[1 1],0,"in1","out1"); |
|
274 sys2 = tf2sys(2,[1 2],0,"in2","out2"); |
|
275 disp("sys1=") |
|
276 sysout(sys1); |
|
277 disp("sys2=") |
|
278 sysout(sys2); |
|
279 cmd = "sysp = parallel(sys1,sys2);"; |
|
280 run_cmd |
|
281 disp("sysp=") |
|
282 sysout(sysp); |
|
283 prompt |
|
284 disp("parallel can be used for multiple input systems as well:") |
|
285 |
3228
|
286 in1 = list("u1.1","u1.2"); |
|
287 in2 = list("u2.1","u2.2"); |
|
288 out1 = list("y1.1","y1.2"); |
|
289 out2 = list("y2.1","y2.2"); |
3213
|
290 |
|
291 sys1 = ss2sys([-1,0;0 -2],eye(2),eye(2),[]); |
|
292 sys2 = ss2sys([-2,0;0 -4],eye(2),eye(2),[]); |
|
293 |
3228
|
294 sys1 = syssetsignals(sys1,"in",in1); |
|
295 sys1 = syssetsignals(sys1,"out",out1); |
3213
|
296 |
3228
|
297 sys2 = syssetsignals(sys2,"in",in2); |
|
298 sys2 = syssetsignals(sys2,"out",out2); |
3213
|
299 |
|
300 disp("sys1=") |
|
301 sysout(sys1); |
|
302 disp("sys2=") |
|
303 sysout(sys2); |
|
304 cmd = "sysp = parallel(sys1,sys2);"; |
|
305 run_cmd |
|
306 disp("sysp=") |
|
307 sysout(sysp); |
|
308 prompt |
|
309 elseif (k == 12) |
|
310 # buildssic description |
|
311 disp(" ") |
|
312 disp(" ---------------------------------------") |
|
313 disp(" b u i l d s s i c") |
|
314 disp(" (BUILD State Space InterConnections)") |
|
315 disp(" ---------------------------------------") |
|
316 disp(" ") |
|
317 disp("buildssic builds a single system from up to 8 systems.") |
|
318 disp("It's primary pupose is the forming of interconnections") |
|
319 disp("for H2/H_inf designs and the building of closed loop") |
|
320 disp("systems.") |
|
321 disp("The interconnections may be of arbitrary complexity.") |
|
322 disp("The use of buildssic is an alternative to sysgroup,") |
|
323 disp("sysadd/syssub, sysappend, sysconnect, sysdup, sysmult") |
|
324 disp("sysprune, sysscale, parallel etc.") |
|
325 disp("In contrast to these functions buildssic does not") |
|
326 disp("handle mixed continuous and discrete systems. However,") |
|
327 disp("discrete systems can be connected as long as their") |
|
328 disp("sampling times are identical. Another drawback: the") |
|
329 disp("names of input/output and state variables are clobbered.") |
|
330 disp("Of course, buildsysic is useful in combination with sysgroup,") |
|
331 disp("sysmult etc.") |
|
332 prompt |
|
333 disp("********* N O T E *********") |
|
334 disp("buildssic is demonstrated in the design examples (option 13)"); |
|
335 prompt |
|
336 elseif (k == 13) |
|
337 disp("Design examples") |
|
338 disp("Packed system matrices may be connected and manipulated") |
|
339 disp("With the functions listed below:") |
|
340 disp(" sysdup: duplicate selected inputs/outputs") |
|
341 disp(" sysconnect: connect selected inputs/outputs") |
|
342 disp(" sysgroup: group two systems together") |
|
343 disp(" sysprune: prune a system to keep only selected inputs and outputs") |
|
344 disp(" sysscale:pre/post multiply a system by constant matrices") |
|
345 disp(" buildssic: connect systems with arbitrary complexity.") |
|
346 prompt |
|
347 disp("As a simple example, we will construct the system block ") |
|
348 disp("diagram shown below ") |
|
349 disp(" ") |
|
350 disp(" + -------- --------"); |
|
351 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
352 disp(" -^ -------- -------- |"); |
|
353 disp(" | |"); |
|
354 disp(" ------------------------------"); |
|
355 disp(" ") |
|
356 disp("where P(s) is the plant, K(s) is the controller.") |
|
357 prompt |
|
358 disp("Simple example: P(s) is a first order lag, K(s) is a PI ") |
|
359 disp("controller") |
|
360 nump = 1; |
|
361 denp = [1 1]; |
|
362 disp("P(s)=") |
|
363 tfout(nump,denp) |
|
364 numk = [1 1]; |
|
365 denk = [1 0]; |
|
366 disp("\nK(s)=") |
|
367 tfout(numk,denk); |
|
368 prompt |
|
369 disp("We'll show three approaches. ") |
|
370 P = tf2sys(nump,denp,0,"plant input","plant output"); |
|
371 K = tf2sys(numk, denk,0,"controller input","controller output"); |
|
372 |
|
373 meth = 0; |
|
374 while(meth != 5) |
|
375 disp("The first method consists of the following steps:") |
|
376 disp(" step 1: create systems P and K") |
|
377 disp(" step 2: group P and K together") |
|
378 disp(" step 3: create a summing junction") |
|
379 disp(" step 4: connect outputs to respective inputs") |
|
380 disp(" step 5: prune the desired i/o connections") |
|
381 disp("The second method is done as follows:") |
|
382 disp(" step 1: create systems P and K and a summing block S") |
|
383 disp(" step 2: connect P, K, and S in series") |
|
384 disp(" step 3: connect y to inverted summing connection") |
|
385 disp(" step 4: prune the desired i/o connections") |
|
386 disp("The third method uses buildssic:") |
|
387 disp(" step 1: GW = buildssic(...,K,P)") |
|
388 disp(" ") |
|
389 disp("Other design examples are in dgkfdemo (controldemo option 7)") |
|
390 disp(" ") |
|
391 meth = menu("Select design example method", ... |
|
392 "Method 1 ", ... |
|
393 "Method 1 (w/o algebraic loop warning)", ... |
|
394 "Method 2", ... |
|
395 "Method 3", ... |
|
396 "Exit design examples"); |
|
397 if(meth == 1) |
|
398 disp(" * * * Method 1 * * *") |
|
399 disp(" ") |
|
400 disp(" + -------- --------"); |
|
401 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
402 disp(" -^ -------- -------- |"); |
|
403 disp(" | |"); |
|
404 disp(" ------------------------------"); |
|
405 disp(" ") |
|
406 disp("Step 1: put plants in system format:"); |
|
407 nump |
|
408 denp |
|
409 cmd = "P = tf2sys(nump,denp,0,""plant input"",""plant output"");"; |
|
410 run_cmd |
|
411 disp("P=") |
|
412 sysout(P) |
|
413 prompt |
|
414 numk |
|
415 denk |
|
416 cmd = "K = tf2sys(numk, denk,0,""controller input"",""controller output"");"; |
|
417 run_cmd |
|
418 sysout(K) |
|
419 prompt |
|
420 disp("Step 2: group the systems together") |
|
421 cmd = "PK = sysgroup(P,K);"; |
|
422 run_cmd |
|
423 disp("PK=") |
|
424 sysout(PK); |
|
425 prompt |
|
426 disp(" ") |
|
427 disp(" y2 u1") |
|
428 disp(" + -------- --------"); |
|
429 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
430 disp(" u2 -^ -------- -------- | y1"); |
|
431 disp(" u3 | |"); |
|
432 disp(" --------------------------------"); |
|
433 disp(" ") |
|
434 disp("The controller has two inputs summed together, r(t)") |
|
435 disp("and the negative feedback of y(t)") |
|
436 disp("Step 3a: duplicate controller input: (input 2 of PK)") |
|
437 prompt |
|
438 cmd = "PK = sysdup(PK,[],2);"; |
|
439 run_cmd |
|
440 disp("PK=") |
|
441 sysout(PK); |
|
442 disp("Notice that PK now has three inputs (input 3 is a duplicate "); |
|
443 prompt("of input 2). Press return to go on") |
|
444 disp("Step 3b: scale input 3 by -1") |
|
445 cmd = "PK = sysscale(PK,[],diag([1,1,-1]));"; |
|
446 run_cmd |
|
447 disp("PK=") |
|
448 sysout(PK); |
|
449 prompt |
|
450 disp("Step 4: connect:") |
|
451 disp(" y(t) (output 1) to the negative sum junction (input 3)") |
|
452 disp(" u(t) (output 2) to plant input (input 1)") |
|
453 disp("and prune extraneous inputs/outputs (retain input 2, output 1)") |
|
454 prompt |
|
455 out_connect = [1 2] |
|
456 in_connect = [3 1] |
|
457 cmd = "PK0 = sysconnect(PK,out_connect,in_connect);"; |
|
458 run_cmd |
|
459 prompt |
|
460 disp("Notice that sysconnect detects the possibility of algebraic") |
|
461 disp("connections when connecting inputs. Option 2 (Method 1 ") |
|
462 disp("without algebraic loops) shows how to avoid this warning") |
|
463 disp("by performing connections one at a time.") |
|
464 prompt |
|
465 disp("PK0=") |
|
466 sysout(PK0); |
|
467 disp("Notice that the connected inputs now have stars on their") |
|
468 disp("names. This is how the Octave controls toolbox reminds you") |
|
469 disp("that the loop has been closed around these inputs.") |
|
470 prompt("Press return to prune extra inputs/outputs from system") |
|
471 disp("Only keep plant output (output 1) and r(t) (input 2)") |
|
472 cmd = "PK0 = sysprune(PK0,1,2);"; |
|
473 run_cmd |
|
474 disp("PK0=") |
|
475 sysout(PK0); |
|
476 prompt |
|
477 disp("The resulting closed-loop transfer function is obtained as follows:") |
|
478 cmd = "[num,den] = sys2tf(PK0);"; |
|
479 run_cmd |
|
480 prompt |
|
481 disp("Transfer function is now") |
|
482 tfout(num,den) |
|
483 disp("You can check this: Pk0=PK/(1+PK), as expected") |
|
484 prompt |
|
485 elseif(meth == 2) |
|
486 disp("Method 1 without algebraic loops") |
|
487 disp(" ") |
|
488 disp(" y2 u1") |
|
489 disp(" + -------- --------"); |
|
490 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
491 disp(" u2 -^ -------- -------- | y1"); |
|
492 disp(" u3 | |"); |
|
493 disp(" --------------------------------"); |
|
494 disp(" ") |
|
495 disp("Recall that sysconnect checks for algebraic loops. Although") |
|
496 disp("Design option 1 gets a warning message about a possible"); |
|
497 disp("algebraic loop, such a loop does not exist.") |
|
498 disp("This can be seen by performing the connections one at a time"); |
|
499 cmd = "PK = sysgroup(P,K);"; |
|
500 run_cmd |
|
501 disp("PK=") |
|
502 sysout(PK); |
|
503 disp("Create an additial inverted input to the controller.") |
|
504 cmd = "PK = sysdup(PK,[],2);"; |
|
505 run_cmd |
|
506 cmd = "PK = sysscale(PK,[],diag([1,1,-1]));"; |
|
507 run_cmd |
|
508 disp("PK=") |
|
509 sysout(PK); |
|
510 disp("Connect controller to plant:") |
|
511 cmd = "PK0 = sysconnect(PK,2,1);"; |
|
512 run_cmd |
|
513 disp("Plant output to negative control input") |
|
514 cmd = "PK0 = sysconnect(PK0,1,3);"; |
|
515 run_cmd |
|
516 disp("Only keep plant output (output 1) and r(t) (input 2)") |
|
517 cmd = "PK0 = sysprune(PK0,1,2);"; |
|
518 run_cmd |
|
519 disp("PK0=") |
|
520 sysout(PK0); |
|
521 prompt |
|
522 disp("The transfer function form of PK0 is:") |
|
523 sysout(PK0,"tf"); |
|
524 prompt |
|
525 elseif(meth == 3) |
|
526 disp(" * * * Method 2 * * *") |
|
527 disp(" ") |
|
528 disp(" + -------- --------"); |
|
529 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
530 disp(" -^ -------- -------- |"); |
|
531 disp(" | |"); |
|
532 disp(" ------------------------------"); |
|
533 disp(" ") |
|
534 disp("Step 1: We've already created systems P and K. Create a sum ") |
|
535 disp("block as follows:") |
|
536 implicit_str_to_num_ok = "warn"; |
3228
|
537 cmd = "S = ss2sys([],[],[],[1 -1],0,0,0,[],list(""r(t)"",""y(t)""),""e(t)"");"; |
3213
|
538 run_cmd |
|
539 implicit_str_to_num_ok = 1; |
|
540 disp("You may avoid the string conversion warning by setting the ") |
|
541 disp("Octave global variables implicit_str_to_num_ok = 1"); |
|
542 disp(" "); |
|
543 disp("(You may wish to look at help ss2sys to see what the above does)"); |
|
544 disp("S=") |
|
545 sysout(S) |
|
546 disp("notice that this is just a gain block that outputs e = r - y") |
|
547 prompt |
|
548 disp("Step 2: series connections of P, K, and S") |
|
549 cmd = "PKS = sysmult(P,sysmult(K,S));"; |
|
550 run_cmd |
|
551 disp("PKS=") |
|
552 sysout(PKS) |
|
553 disp("Step 3: connect y to inverted input") |
|
554 cmd = "PKcl = sysconnect(PKS,1,2);"; |
|
555 run_cmd |
|
556 disp("PKcl=") |
|
557 sysout(PKcl) |
|
558 disp("Step 4: prune desired inputs/outputs") |
|
559 cmd = "PKcl=sysprune(PKcl,1,1);"; |
|
560 run_cmd |
|
561 disp("PKcl=") |
|
562 sysout(PKcl) |
|
563 prompt |
|
564 elseif(meth == 4) |
|
565 disp(" * * * Method 3 * * *") |
|
566 disp(" ") |
|
567 disp(" + -------- --------"); |
|
568 disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); |
|
569 disp(" -^ -------- -------- |"); |
|
570 disp(" | |"); |
|
571 disp(" ------------------------------"); |
|
572 disp(" ") |
|
573 disp("Step 1: We've already created systems P and K.") |
|
574 disp(" Let us call buildssic:") |
|
575 disp(" PKcl = buildssic([1 2;2 -1],[],[1],[2],P,K)") |
|
576 disp(" ") |
|
577 disp(" ^ ^ ^ ^ ^ ^") |
|
578 disp(" | | | | | |") |
|
579 disp(" Connection list ----+ | | | | |") |
|
580 disp(" internal input list -----------+ | | | +-- controller") |
|
581 disp(" output list --------------+ | |") |
|
582 disp(" input list ------------------+ +---- plant") |
|
583 disp(" ") |
|
584 disp(" Connection list: connect input 1 (P) with output 2 (K)") |
|
585 disp(" connect input 2 (K) with neg. outp. 1 (P)") |
|
586 disp(" ") |
|
587 disp(" int. inp. list: do not append internal inputs") |
|
588 disp(" (e.g. the internal input of K (r-y))") |
|
589 disp(" ") |
|
590 disp(" output list: the only output is 1 (P), positive") |
|
591 disp(" ") |
|
592 disp(" input list: the only input is 2 (K), positive") |
|
593 disp(" ") |
|
594 cmd = "PKcl = buildssic([1 2;2 -1],[],[1],[2],P,K);" |
|
595 run_cmd |
|
596 sysout(PKcl) |
|
597 prompt |
|
598 disp("The transfer function form of PKcl is:") |
|
599 sysout(PKcl,"tf"); |
|
600 disp("You can check this: PKcl = PK / (1 + PK), as expected") |
|
601 prompt |
|
602 elseif(meth != 5) |
|
603 disp("Illegal selection") |
|
604 endif |
|
605 endwhile |
|
606 |
|
607 elseif (k == 14) |
|
608 return |
|
609 endif |
|
610 endwhile |
|
611 implict_str_to_num_ok = str_sav; |
|
612 page_screen_output = sav_page; |
|
613 endfunction |