📄 bddemo.m
字号:
sysout(sys2); cmd = "sysp = parallel(sys1,sys2);"; run_cmd disp("sysp=") sysout(sysp); prompt elseif (k == 12) ## buildssic description disp(" ") disp(" ---------------------------------------") disp(" b u i l d s s i c") disp(" (BUILD State Space InterConnections)") disp(" ---------------------------------------") disp(" ") disp("buildssic builds a single system from up to 8 systems.") disp("It's primary pupose is the forming of interconnections") disp("for H2/H_inf designs and the building of closed loop") disp("systems.") disp("The interconnections may be of arbitrary complexity.") disp("The use of buildssic is an alternative to sysgroup,") disp("sysadd/syssub, sysappend, sysconnect, sysdup, sysmult") disp("sysprune, sysscale, parallel etc.") disp("In contrast to these functions buildssic does not") disp("handle mixed continuous and discrete systems. However,") disp("discrete systems can be connected as long as their") disp("sampling times are identical. Another drawback: the") disp("names of input/output and state variables are clobbered.") disp("Of course, buildsysic is useful in combination with sysgroup,") disp("sysmult etc.") prompt disp("********* N O T E *********") disp("buildssic is demonstrated in the design examples (option 13)"); prompt elseif (k == 13) disp("Design examples") disp("Packed system matrices may be connected and manipulated") disp("With the functions listed below:") disp(" sysdup: duplicate selected inputs/outputs") disp(" sysconnect: connect selected inputs/outputs") disp(" sysgroup: group two systems together") disp(" sysprune: prune a system to keep only selected inputs and outputs") disp(" sysscale:pre/post multiply a system by constant matrices") disp(" buildssic: connect systems with arbitrary complexity.") prompt disp("As a simple example, we will construct the system block ") disp("diagram shown below ") disp(" ") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" -^ -------- -------- |"); disp(" | |"); disp(" ------------------------------"); disp(" ") disp("where P(s) is the plant, K(s) is the controller.") prompt disp("Simple example: P(s) is a first order lag, K(s) is a PI ") disp("controller") nump = 1; denp = [1, 1]; disp("P(s)=") tfout(nump,denp) numk = [1, 1]; denk = [1, 0]; disp("\nK(s)=") tfout(numk,denk); prompt disp("We'll show three approaches. ") P = tf(nump,denp,0,"plant input","plant output"); K = tf(numk, denk,0,"controller input","controller output"); meth = 0; while(meth != 5) disp("The first method consists of the following steps:") disp(" step 1: create systems P and K") disp(" step 2: group P and K together") disp(" step 3: create a summing junction") disp(" step 4: connect outputs to respective inputs") disp(" step 5: prune the desired i/o connections") disp("The second method is done as follows:") disp(" step 1: create systems P and K and a summing block S") disp(" step 2: connect P, K, and S in series") disp(" step 3: connect y to inverted summing connection") disp(" step 4: prune the desired i/o connections") disp("The third method uses buildssic:") disp(" step 1: GW = buildssic(...,K,P)") disp(" ") disp("Other design examples are in dgkfdemo (controldemo option 7)") disp(" ") meth = menu("Select design example method", ... "Method 1 ", ... "Method 1 (w/o algebraic loop warning)", ... "Method 2", ... "Method 3", ... "Exit design examples"); if(meth == 1) disp(" * * * Method 1 * * *") disp(" ") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" -^ -------- -------- |"); disp(" | |"); disp(" ------------------------------"); disp(" ") disp("Step 1: put plants in system format:"); nump denp cmd = "P = tf(nump,denp,0,""plant input"",""plant output"");"; run_cmd disp("P=") sysout(P) prompt numk denk cmd = "K = tf(numk, denk,0,""controller input"",""controller output"");"; run_cmd sysout(K) prompt disp("Step 2: group the systems together") cmd = "PK = sysgroup(P,K);"; run_cmd disp("PK=") sysout(PK); prompt disp(" ") disp(" y2 u1") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" u2 -^ -------- -------- | y1"); disp(" u3 | |"); disp(" --------------------------------"); disp(" ") disp("The controller has two inputs summed together, r(t)") disp("and the negative feedback of y(t)") disp("Step 3a: duplicate controller input: (input 2 of PK)") prompt cmd = "PK = sysdup(PK,[],2);"; run_cmd disp("PK=") sysout(PK); disp("Notice that PK now has three inputs (input 3 is a duplicate "); prompt("of input 2). Press return to go on") disp("Step 3b: scale input 3 by -1") cmd = "PK = sysscale(PK,[],diag([1, 1, -1]));"; run_cmd disp("PK=") sysout(PK); prompt disp("Step 4: connect:") disp(" y(t) (output 1) to the negative sum junction (input 3)") disp(" u(t) (output 2) to plant input (input 1)") disp("and prune extraneous inputs/outputs (retain input 2, output 1)") prompt out_connect = [1, 2] in_connect = [3, 1] cmd = "PK0 = sysconnect(PK,out_connect,in_connect);"; run_cmd prompt disp("Notice that sysconnect detects the possibility of algebraic") disp("connections when connecting inputs. Option 2 (Method 1 ") disp("without algebraic loops) shows how to avoid this warning") disp("by performing connections one at a time.") prompt disp("PK0=") sysout(PK0); disp("Notice that the connected inputs now have stars on their") disp("names. This is how the Octave controls toolbox reminds you") disp("that the loop has been closed around these inputs.") prompt("Press return to prune extra inputs/outputs from system") disp("Only keep plant output (output 1) and r(t) (input 2)") cmd = "PK0 = sysprune(PK0,1,2);"; run_cmd disp("PK0=") sysout(PK0); prompt disp("The resulting closed-loop transfer function is obtained as follows:") cmd = "[num,den] = sys2tf(PK0);"; run_cmd prompt disp("Transfer function is now") tfout(num,den) disp("You can check this: Pk0=PK/(1+PK), as expected") prompt elseif(meth == 2) disp("Method 1 without algebraic loops") disp(" ") disp(" y2 u1") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" u2 -^ -------- -------- | y1"); disp(" u3 | |"); disp(" --------------------------------"); disp(" ") disp("Recall that sysconnect checks for algebraic loops. Although") disp("Design option 1 gets a warning message about a possible"); disp("algebraic loop, such a loop does not exist.") disp("This can be seen by performing the connections one at a time"); cmd = "PK = sysgroup(P,K);"; run_cmd disp("PK=") sysout(PK); disp("Create an additial inverted input to the controller.") cmd = "PK = sysdup(PK,[],2);"; run_cmd cmd = "PK = sysscale(PK,[],diag([1,1,-1]));"; run_cmd disp("PK=") sysout(PK); disp("Connect controller to plant:") cmd = "PK0 = sysconnect(PK,2,1);"; run_cmd disp("Plant output to negative control input") cmd = "PK0 = sysconnect(PK0,1,3);"; run_cmd disp("Only keep plant output (output 1) and r(t) (input 2)") cmd = "PK0 = sysprune(PK0,1,2);"; run_cmd disp("PK0=") sysout(PK0); prompt disp("The transfer function form of PK0 is:") sysout(PK0,"tf"); prompt elseif(meth == 3) disp(" * * * Method 2 * * *") disp(" ") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" -^ -------- -------- |"); disp(" | |"); disp(" ------------------------------"); disp(" ") disp("Step 1: We've already created systems P and K. Create a sum ") disp("block as follows:") cmd = 'S = ss([],[],[],[1, -1],0,0,0,[],{"r(t)", "y(t)"},"e(t)");'; run_cmd disp("(You may wish to look at help ss to see what the above does)"); disp("S=") sysout(S) disp("notice that this is just a gain block that outputs e = r - y") prompt disp("Step 2: series connections of P, K, and S") cmd = "PKS = sysmult(P,sysmult(K,S));"; run_cmd disp("PKS=") sysout(PKS) disp("Step 3: connect y to inverted input") cmd = "PKcl = sysconnect(PKS,1,2);"; run_cmd disp("PKcl=") sysout(PKcl) disp("Step 4: prune desired inputs/outputs") cmd = "PKcl=sysprune(PKcl,1,1);"; run_cmd disp("PKcl=") sysout(PKcl) prompt elseif(meth == 4) disp(" * * * Method 3 * * *") disp(" ") disp(" + -------- --------"); disp(" r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)"); disp(" -^ -------- -------- |"); disp(" | |"); disp(" ------------------------------"); disp(" ") disp("Step 1: We've already created systems P and K.") disp(" Let us call buildssic:") disp(" PKcl = buildssic([1, 2; 2, -1],[],[1],[2],P,K)") disp(" ") disp(" ^ ^ ^ ^ ^ ^") disp(" | | | | | |") disp(" Connection list ----+ | | | | |") disp(" internal input list -----------+ | | | +-- controller") disp(" output list --------------+ | |") disp(" input list ------------------+ +---- plant") disp(" ") disp(" Connection list: connect input 1 (P) with output 2 (K)") disp(" connect input 2 (K) with neg. outp. 1 (P)") disp(" ") disp(" int. inp. list: do not append internal inputs") disp(" (e.g. the internal input of K (r-y))") disp(" ") disp(" output list: the only output is 1 (P), positive") disp(" ") disp(" input list: the only input is 2 (K), positive") disp(" ") cmd = "PKcl = buildssic([1, 2; 2, -1],[],[1],[2],P,K);" run_cmd sysout(PKcl) prompt disp("The transfer function form of PKcl is:") sysout(PKcl,"tf"); disp("You can check this: PKcl = PK / (1 + PK), as expected") prompt elseif(meth != 5) disp("invalid selection") endif endwhile elseif (k == 14) return endif endwhile implict_str_to_num_ok = str_sav; page_screen_output (sav_page);endfunction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -