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