diff options
author | Siddharth Agarwal | 2019-09-03 18:27:40 +0530 |
---|---|---|
committer | Siddharth Agarwal | 2019-09-03 18:27:40 +0530 |
commit | 8ac15bc5efafa2afc053c293152605b0e6ae60ff (patch) | |
tree | e1bc17aae137922b1ee990f17aae4a6cb15b7d87 /Working_Examples/3432/CH7/EX7.18 | |
parent | 52a477ec613900885e29c4a0b02806a415b4f83a (diff) | |
download | Xcos_block_examples-8ac15bc5efafa2afc053c293152605b0e6ae60ff.tar.gz Xcos_block_examples-8ac15bc5efafa2afc053c293152605b0e6ae60ff.tar.bz2 Xcos_block_examples-8ac15bc5efafa2afc053c293152605b0e6ae60ff.zip |
Diffstat (limited to 'Working_Examples/3432/CH7/EX7.18')
-rwxr-xr-x | Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/acker_dk.sci | 73 | ||||
-rwxr-xr-x | Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/fig_settings.sci | 9 | ||||
-rwxr-xr-x | Working_Examples/3432/CH7/EX7.18/Ex7_18.sce | 56 | ||||
-rwxr-xr-x | Working_Examples/3432/CH7/EX7.18/Ex7_18_f0.pdf | bin | 0 -> 20736 bytes |
4 files changed, 138 insertions, 0 deletions
diff --git a/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/acker_dk.sci b/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/acker_dk.sci new file mode 100755 index 0000000..3391d24 --- /dev/null +++ b/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/acker_dk.sci @@ -0,0 +1,73 @@ +//------------------------------------------------------------------ +//------------------------------------------------------------------ +//A function written by Deepti Khimani. +//Usage:- +//[K, lambda]=acker_dk(a, b, pl) +//K=acker_dk(a, b, pl) +//a:- System matrix. +//b:- input matrix. +//p:- Desired poles. +//K:-State feedback gain for the control law u=-Kx. +//lambda:- Eigen values of (a-b*k) +//------------------------------------------------------------------ +//------------------------------------------------------------------ + +function [K, lambda]=acker_dk(a, b, pl) + [lhs,rhs]=argn(0) + + if rhs == 0 then + disp(["K=acker_dk(a, b, pl)";"[K, lambda]=acker_dk(a, b, pl)"]); + disp(["a:- System matrix";"b:- input matrix";"p:- Desired poles"]); + disp(["K:-State feedback gain for the control law u=-Kx";... + "lambda:- Eigen values of (a-b*k)"]); + return; + end +[ra ca]=size(a); +[rb cb]=size(b); +l=length(pl); + +CO=cont_mat(a,b); + +if ra~=l then + error(["Dimension error:";"number of desired poles must equal... + to order of the system"]); +elseif ra~=ca then + error(["Dimension error:";"system matrix should be... + a sqaure matrix"]); +elseif rb~=ra then + error (["Dimension error:","Input matrix should have... + as many rows as a system matrix."]); +elseif rank(CO)<ra then + error("system is not controllable"); +end +//------------------------------------------------------------------ +//controllable canonical form +[Ac,Bc,T,ind]=canon(a,b); + +//CO=zeros(ra,cb); +for i=1:ra + CO(:,ra+1-i)=Ac^(i-1)*Bc; +end +//------------------------------------------------------------------ +chr_eq=poly(pl,'s'); +des_chr_coeff=coeff(chr_eq); + +des_chr_coeff=des_chr_coeff(1:ra); +alpha_c=Ac^ra; + +for k=1:ra + alpha_c=alpha_c + des_chr_coeff(k)*Ac^(k-1) +end +//------------------------------------------------------------------ +//State feedback gain +temp=zeros(1,ra); +temp(1)=1; +K=temp*inv(CO)*alpha_c; +K=K/T; +lambda=spec(a-b*K); +endfunction +//------------------------------------------------------------------ + + + + diff --git a/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/fig_settings.sci b/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/fig_settings.sci new file mode 100755 index 0000000..5d5e7d4 --- /dev/null +++ b/Working_Examples/3432/CH7/EX7.18/DEPENDENCIES/fig_settings.sci @@ -0,0 +1,9 @@ +//------------------------------------------------------------------
+//figure handel settings
+f=get("current_figure"); //Current figure handle
+f.background=8; //make the figure window background white
+l=f.children(1);
+l.background=8 ;//make the text background white
+id=color('grey');
+xgrid(id);
+//------------------------------------------------------------------
diff --git a/Working_Examples/3432/CH7/EX7.18/Ex7_18.sce b/Working_Examples/3432/CH7/EX7.18/Ex7_18.sce new file mode 100755 index 0000000..5be65a2 --- /dev/null +++ b/Working_Examples/3432/CH7/EX7.18/Ex7_18.sce @@ -0,0 +1,56 @@ +//Example 7.18 +//Introducing the reference input. + +xdel(winsid())//close all graphics Windows +clear; +clc; +//------------------------------------------------------------------ +//Pendulum state model; +w0=1; + +F=[0 1;-w0^2 0]; +G=[0 1]'; +H=[1 0]; //representing x1 and x2 states as outputs +J=0; +n=sqrt(length(F)); + +//computing state feedback matrix to place poles at [-2 -2] +exec('./acker_dk.sci', -1); +K=acker_dk(F,G,[-2, -2]); +//------------------------------------------------------------------ +//augmented matrix for tracking the reference +A=[F G;H J]; +N=A\[zeros(1,n) 1]'; +Nx=N(1:n); +Nu=N(n+1); + +//feedforward gain (input weight) +Ntilde=Nu+K*Nx; + +//------------------------------------ +//Alternately, it can be computed as / +Ntilde1=-inv(H*inv(F-G*K)*G); // / +//------------------------------------ + +//Closed loop system and step response +syscl=syslin('c',(F-G*K),G*Ntilde,H,J); //closed loop system + +t=0:0.1:7; +[y x]=csim('step',t,syscl); //closed loop response +plot(t',x'); + +u=-K*x+Ntilde; +plot(t',u'/4,'r--'); //control law u plot (scaled to 1/4 in figure); +legend("x1","x2","u/4"); +xset('font size',3); +xstring(5,0.93,"$x_{ss}$") +xstring(5,0.25,"$u_{ss}$") + +//Title, labels and grid to the figure +exec .\fig_settings.sci; //custom script for setting figure properties +title('Step response of undamped oscillator to reference input',... +'fontsize',3); +xlabel('Time t (sec.)','fontsize',2); +ylabel('Amplitude','fontsize',2); + +//------------------------------------------------------------------ diff --git a/Working_Examples/3432/CH7/EX7.18/Ex7_18_f0.pdf b/Working_Examples/3432/CH7/EX7.18/Ex7_18_f0.pdf Binary files differnew file mode 100755 index 0000000..18e8af6 --- /dev/null +++ b/Working_Examples/3432/CH7/EX7.18/Ex7_18_f0.pdf |