From 8ac15bc5efafa2afc053c293152605b0e6ae60ff Mon Sep 17 00:00:00 2001
From: Siddharth Agarwal
Date: Tue, 3 Sep 2019 18:27:40 +0530
Subject: Xcos examples from textbooks and for blocks
---
.../3432/CH8/EX8.1/DEPENDENCIES/fig_settings.sci | 9 +++
Working_Examples/3432/CH8/EX8.1/Ex8_1.sce | 56 ++++++++++++++++++
Working_Examples/3432/CH8/EX8.1/Ex8_1_f0.pdf | Bin 0 -> 27021 bytes
Working_Examples/3432/CH8/EX8.1/Ex8_1_f1.pdf | Bin 0 -> 28141 bytes
Working_Examples/3432/CH8/EX8.1/Ex8_1_model.xcos | 1 +
.../3432/CH8/EX8.2/DEPENDENCIES/fig_settings.sci | 9 +++
Working_Examples/3432/CH8/EX8.2/Ex8_2.sce | 65 +++++++++++++++++++++
Working_Examples/3432/CH8/EX8.2/Ex8_2_f0.pdf | Bin 0 -> 17544 bytes
Working_Examples/3432/CH8/EX8.2/Ex8_2_f1.pdf | Bin 0 -> 37047 bytes
Working_Examples/3432/CH8/EX8.2/Ex8_2_model.xcos | 1 +
10 files changed, 141 insertions(+)
create mode 100755 Working_Examples/3432/CH8/EX8.1/DEPENDENCIES/fig_settings.sci
create mode 100755 Working_Examples/3432/CH8/EX8.1/Ex8_1.sce
create mode 100755 Working_Examples/3432/CH8/EX8.1/Ex8_1_f0.pdf
create mode 100755 Working_Examples/3432/CH8/EX8.1/Ex8_1_f1.pdf
create mode 100755 Working_Examples/3432/CH8/EX8.1/Ex8_1_model.xcos
create mode 100755 Working_Examples/3432/CH8/EX8.2/DEPENDENCIES/fig_settings.sci
create mode 100755 Working_Examples/3432/CH8/EX8.2/Ex8_2.sce
create mode 100755 Working_Examples/3432/CH8/EX8.2/Ex8_2_f0.pdf
create mode 100755 Working_Examples/3432/CH8/EX8.2/Ex8_2_f1.pdf
create mode 100755 Working_Examples/3432/CH8/EX8.2/Ex8_2_model.xcos
(limited to 'Working_Examples/3432/CH8')
diff --git a/Working_Examples/3432/CH8/EX8.1/DEPENDENCIES/fig_settings.sci b/Working_Examples/3432/CH8/EX8.1/DEPENDENCIES/fig_settings.sci
new file mode 100755
index 0000000..5d5e7d4
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.1/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/CH8/EX8.1/Ex8_1.sce b/Working_Examples/3432/CH8/EX8.1/Ex8_1.sce
new file mode 100755
index 0000000..015f648
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.1/Ex8_1.sce
@@ -0,0 +1,56 @@
+///Example 8.1
+// Digital Controller using tustin approximation.
+
+xdel(winsid())//close all graphics Windows
+clear;
+clc;
+//------------------------------------------------------------------
+//Cntroller
+s=poly(0,'s');
+numD=s/2+1;
+denD=s/10+1;
+D=10*numD/denD;
+Ds=syslin('c',D);
+//sampling freq. = 25 times bandwidth
+Wbw=10;
+Ws=25*Wbw;
+fs=Ws/2/%pi;
+T=1/fs; //sampling time
+a=1;b=-1;
+c=1;d=1;
+//Digital controller
+z=poly(0,'z');
+Dz=horner(Ds,2/T*(a*z+b)/(c*z+d));
+disp(Dz,'Digital Controller : ')
+
+//------------------------------------------------------------------
+//step response and control efforts.
+figure(0);
+importXcosDiagram(".\Ex8_1_model.xcos")
+ //The diagram data structure
+xcos_simulate(scs_m,4);
+scs_m.props.context
+plot(yt.time,yt.values(:,1),'r--')
+plot(yt.time,yt.values(:,2),2)
+
+xlabel('Time (sec.)');
+ylabel('Position, y');
+title(["Comparison between digital and continuous controller step...
+ response";"with a sample rate 25 times bandwidth";"(a) Position "],...
+ 'fontsize',3);
+exec .\fig_settings.sci; // custom script for setting figure properties
+
+//control effort
+
+figure(1);
+plot(ut.time,ut.values(:,1),'r--')
+plot2d2(ut.time,ut.values(:,2),2)
+
+xlabel('Time (sec.)');
+ylabel('Control, u');
+title(["Comparison between digital and continuous controller step...
+ response";"with a sample rate 25 times bandwidth";"(b) Control "],...
+ 'fontsize',3);
+exec .\fig_settings.sci; // custom script for setting figure properties
+//------------------------------------------------------------------
+
diff --git a/Working_Examples/3432/CH8/EX8.1/Ex8_1_f0.pdf b/Working_Examples/3432/CH8/EX8.1/Ex8_1_f0.pdf
new file mode 100755
index 0000000..18b8139
Binary files /dev/null and b/Working_Examples/3432/CH8/EX8.1/Ex8_1_f0.pdf differ
diff --git a/Working_Examples/3432/CH8/EX8.1/Ex8_1_f1.pdf b/Working_Examples/3432/CH8/EX8.1/Ex8_1_f1.pdf
new file mode 100755
index 0000000..ab9cb8c
Binary files /dev/null and b/Working_Examples/3432/CH8/EX8.1/Ex8_1_f1.pdf differ
diff --git a/Working_Examples/3432/CH8/EX8.1/Ex8_1_model.xcos b/Working_Examples/3432/CH8/EX8.1/Ex8_1_model.xcos
new file mode 100755
index 0000000..ece7753
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.1/Ex8_1_model.xcos
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Working_Examples/3432/CH8/EX8.2/DEPENDENCIES/fig_settings.sci b/Working_Examples/3432/CH8/EX8.2/DEPENDENCIES/fig_settings.sci
new file mode 100755
index 0000000..5d5e7d4
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.2/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/CH8/EX8.2/Ex8_2.sce b/Working_Examples/3432/CH8/EX8.2/Ex8_2.sce
new file mode 100755
index 0000000..d5b2152
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.2/Ex8_2.sce
@@ -0,0 +1,65 @@
+//Example 8.2
+// Design of a Space Station Attitude Digital Controller using
+// Discrete Equivalents
+
+xdel(winsid())//close all graphics Windows
+clear;
+clc;
+//------------------------------------------------------------------
+// State space representation of continuous time system
+s=poly(0,'s');
+num=1;
+den=(s^2);
+Gs=syslin('c',num/den);
+Ds=0.81*(s+0.2)/(s+2);
+Ds=syslin('c',Ds);
+sysc=Gs*Ds;
+
+//Root locus
+evans(sysc)
+zoom_rect([-2 -0.4 0.5 0.4])
+f=gca();
+f.x_location = "origin"
+f.y_location = "origin"
+h=legend('');
+h.visible = "off"
+exec .\fig_settings.sci; //custom script for setting figure properties
+title('s-plane locus with respect to K','fontsize',3)
+//------------------------------------------------------------------
+//Contonuous time response of the system
+figure,
+tc=0:0.1:30;
+syscl=sysc/(1+sysc)
+yc=csim("step",tc,syscl);
+plot(tc,yc,'b')
+//------------------------------------------------------------------
+// Discretization of the system at
+z=poly(0,'z')
+// sampling time Ts=1 sec
+Ts=1;
+Dz1=horner(Ds,2/Ts*(z-1)/(z+1))
+disp(Dz1,"Dz1=","Discrete-time controller with Ts=1 sec.")
+
+// sampling time Ts=0.5 sec
+Ts2=0.5;
+Dz2=horner(Ds,2/Ts2*(z-1)/(z+1))
+disp(Dz2,"Dz2=","Discrete-time controller with Ts=0.5 sec.")
+
+//discrete-time response of the system.
+
+importXcosDiagram(".\Ex8_2_model.xcos")
+ //The diagram data structure
+xcos_simulate(scs_m,4);
+//scs_m.props.context
+plot(yt1.time,yt1.values,'m-.') //with Ts=1sec.
+plot(yt2.time,yt2.values,'r--') //with Ts=0.5 sec.
+//------------------------------------------------------------------------------
+
+title('step responses of continous and digital implementations','fontsize',3)
+
+exec .\fig_settings.sci; // custom script for setting figure properties
+xlabel('Time (sec)','fontsize',2)
+ylabel('Plant output','fontsize',2)
+legend("Continuous design","Discrete equivalent design, T=1 sec."...
+,"Discrete equivalent design, T=0.5 sec.",4)
+//------------------------------------------------------------------------------
diff --git a/Working_Examples/3432/CH8/EX8.2/Ex8_2_f0.pdf b/Working_Examples/3432/CH8/EX8.2/Ex8_2_f0.pdf
new file mode 100755
index 0000000..58a1e2d
Binary files /dev/null and b/Working_Examples/3432/CH8/EX8.2/Ex8_2_f0.pdf differ
diff --git a/Working_Examples/3432/CH8/EX8.2/Ex8_2_f1.pdf b/Working_Examples/3432/CH8/EX8.2/Ex8_2_f1.pdf
new file mode 100755
index 0000000..614471a
Binary files /dev/null and b/Working_Examples/3432/CH8/EX8.2/Ex8_2_f1.pdf differ
diff --git a/Working_Examples/3432/CH8/EX8.2/Ex8_2_model.xcos b/Working_Examples/3432/CH8/EX8.2/Ex8_2_model.xcos
new file mode 100755
index 0000000..b97f107
--- /dev/null
+++ b/Working_Examples/3432/CH8/EX8.2/Ex8_2_model.xcos
@@ -0,0 +1 @@
+
\ No newline at end of file
--
cgit