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