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