summaryrefslogtreecommitdiff
path: root/3432/CH6/EX6.14/Ex6_14.sce
blob: 4ccf15583ca63add1d179b48c4762e8af58acc3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Example 6.14 
//Lead compensation for DC motor.

xdel(winsid())//close all graphics Windows
clear;
clc;
//------------------------------------------------------------------
//System transfer function 
s=poly(0,'s');
g=1/s/(s+1);
K=10; //DC gain
KGs=syslin('c',K*g);

//Lead compensator
numD=s/2+1;
denD=s/10+1;
D=numD/denD;
Ds=syslin('c',D);

KGDs=Ds*KGs; //compensated system
//------------------------------------------------------------------
//(a) The bode plot of the system
bode([KGs;KGDs],0.1/2/%pi,100/2/%pi,['KG(s)';'D(s)G(s)'],"rad");
exec .\fig_settings.sci; //custom script for setting figure properties
title('Frequency response of lead compensation design','fontsize',3)

//root locus
figure(1)
evans(KGDs/K)
xset("font size", 3);
xstring(-10,4,"$KD(s)=\frac{s/2+1}{s/10+1}$",0,0)
xstring(-10,2,"$G(s)=\frac{1}{s(s+1)}$",0,0)

//Title, labels and grid to the figure
exec .\fig_settings.sci; // custom script for setting figure properties
title('Root locus for lead compensation design','fontsize',3)
zoom_rect([-14 -8 4 8])
f=gca();
f.x_location = "origin";
f.y_location = "origin";
h=legend('');
h.visible = "off"
//------------------------------------------------------------------
//(b) digital version of lead compensator
//Discretize the system using sampling time Ts=0.05 and Bilinear Transform
Ts=0.05;        //in book its 0.005, which may not give expected responses
D=tf2ss(KGDs/K/g);
sysD=cls2dls(D,Ts);

//Pulse transfer function
Ddz=ss2tf(sysD)
disp(Ddz,"Ddz=")

//------------------------------------------------------------------
//(c) Compare step and ramp responses.
//step response switch sw=1 and for ramp response sw=0
//------------------------------------------------------------------

//step response
sw=1; 
importXcosDiagram(".\Ex6_14_model.xcos")

xcos_simulate(scs_m,4);
scs_m.props.context
figure,
a1=newaxes(); 
a1.axes_bounds=[0,0,1.0,0.5];
plot(time_resp.time,time_resp.values)

xlabel('time');
ylabel('y');
title(["Lead-compensation design (a) step Response...
 (b) ramp response"],'fontsize',3)
exec .\fig_settings.sci; //custom script for setting figure properties
legend("continuous controller","digital controller",4)
//------------------------------------------------------------------
//ramp response
sw=0; 
importXcosDiagram(".\Ex6_14_model.xcos")

xcos_simulate(scs_m,4);
scs_m.props.context

a2=newaxes(); 
a2.axes_bounds=[0,0.5,1.0,0.5];
plot(time_resp.time,time_resp.values)

xlabel('time');
ylabel('y');
title("(b)",'fontsize',3)
exec .\fig_settings.sci; //custom script for setting figure properties
legend("continuous controller","digital controller",4)
//------------------------------------------------------------------