forked from rutup1595/gui-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_final.sci
419 lines (364 loc) · 15.4 KB
/
gui_final.sci
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// sys=1/(s+2+s^3)
// sys=((s+3)*(s))/(s+2+s^4)
// sys=(s+4)/(s^2+8*s+9)
global margin_x margin_y;
global frame_w frame_h plot_w plot_h;
// Window Parameters initialization
frame_w = 200; frame_h = 550;// Frame width and height
plot_w = 150; plot_h = frame_h;// Plot width and heigh
margin_x = 150; margin_y = 15;// Horizontal and vertical margin
//for elements
defaultfont = "arial"; // Default Font
axes_w = 2*margin_x + frame_w + plot_w;// axes width
axes_h = 2*margin_y + frame_h; // axes height (100 =>
//toolbar height)
demo_lhy = scf(100001);// Create window with id=100001 and make
//it the current one
// Background and text
demo_lhy.background = -2;
demo_lhy.figure_position = [100 100];
demo_lhy.figure_name = gettext("Control System");
// Change dimensions of the figure
demo_lhy.axes_size = [axes_w axes_h];
// Remove Scilab graphics menus & toolbar
delmenu(demo_lhy.figure_id,gettext("&File"));
delmenu(demo_lhy.figure_id,gettext("&Tools"));
delmenu(demo_lhy.figure_id,gettext("&Edit"));
delmenu(demo_lhy.figure_id,gettext("&?"));
toolbar(demo_lhy.figure_id,"off");
// New menu
h1 = uimenu("parent",demo_lhy, "label",gettext("File"));
h2 = uimenu("parent",demo_lhy, "label",gettext("About"));
h3 = uimenu("parent",demo_lhy, "label",gettext("Response"));
h4 = uimenu("parent",demo_lhy, "label",gettext("Parameters"));
// Populate menu: file
uimenu(h1, "label",gettext("Close"), 'callback',"demo_lhy=get_figure_handle(100001);delete(demo_lhy);");
// Populate menu: about
uimenu(h2, "label",gettext("About"),"callback","About();");
popul1=uimenu(h3, "label",gettext("Plots"),"callback","plt();");
popul2=uimenu(h3, "label",gettext("Margin"),"callback","mrgin();");
popul3=uimenu(h4,"label",gettext("PZdata"),"callback","PZdata();");
popul3=uimenu(h4,"label",gettext("Systemdata"),"callback","Systemdata();");
// Sleep to guarantee a better display (avoiding to see a
//sequential display)
sleep(500);
my_frame = uicontrol("parent",demo_lhy, "relief","groove","style","frame", "units","pixels","position",[margin_x margin_y frame_w+100 frame_h],"horizontalalignment","center", "background",[1 1 1],"tag","frame_control");
my_frame_title = uicontrol("parent",demo_lhy, "style","text","string","System", "units","pixels","position",[70+margin_x margin_y+frame_h-10 frame_w-60 20],"fontname",defaultfont, "fontunits","points","fontsize",16, "horizontalalignment","center","background",[1 1 1], "tag","title_frame_control");
textsys = uicontrol("parent",demo_lhy,"relief","groove","style","edit","units","pixels","position",[margin_x+60 500 frame_w-10 20],"tag","nter");
enter1 = uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+70 400 frame_w-50 40],"string","ENTER","callback","enter();");
dispplay=uicontrol("parent",demo_lhy,"relief","groove","style","text","units","pixels","position",[margin_x+50 250 frame_w-10 100],"tag","disp");
//handles.obj=newaxes();handles.obj.margin=[0 0 0 0];handles.obj.axes_bounds=[1/3,0,2/3,1]
function enter()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
// disp(typeof(sys1))
textsys = findobj("tag","disp");textsys.string=string(syst);
endfunction
////c=enter();
function plt()
tag1 = findobj("tag","p1");
tag1.visible="off"
tag1 = findobj("tag","p2");
tag1.visible="off"
tag1 = findobj("tag","p3");
tag1.visible="off"
tag1 = findobj("tag","p4");
tag1.visible="off"
tag2 = findobj("tag","margin1");
tag2.visible="off"
tag2 = findobj("tag","margin2");
tag2.visible="off"
tag1 = findobj("tag","p5");
tag1.visible="off"
tag1 = findobj("tag","p6");
tag1.visible="off"
tag1 = findobj("tag","p7");
tag1.visible="off"
impls=uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 20 frame_w-10 40],"tag","impuls","string","impulse","callback","impuls();");
inital=uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 80 frame_w-10 40],"tag","impuls1","string","Sigma","callback","sig();");
iop= uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 140 frame_w-10 40],"tag","impuls2","string","iopzplot","callback","iopz();");
endfunction
function mrgin()
tag1 = findobj("tag","impuls");
tag1.visible="off"
tag1 = findobj("tag","impuls1");
tag1.visible="off"
tag2 = findobj("tag","impuls2");
tag2.visible="off"
tag1 = findobj("tag","p1");
tag1.visible="off"
tag1 = findobj("tag","p2");
tag1.visible="off"
tag1 = findobj("tag","p3");
tag1.visible="off"
tag1 = findobj("tag","p4");
tag1.visible="off"
tag1 = findobj("tag","p5");
tag1.visible="off"
tag1 = findobj("tag","p6");
tag1.visible="off"
tag1 = findobj("tag","p7");
tag1.visible="off"
show_mrg=uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 20 frame_w-10 40],"tag","margin1","string","Margin","callback","mgin();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 80 frame_w-10 40],"tag","bode1","string","Bode","callback","bde();");
endfunction
function impuls()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
demo_lhy1 = scf(100002);
demo_lhy1.background = -2;
demo_lhy1.figure_position = [50 50];
demo_lhy1.axes_size = [axes_w axes_h];
demo_lhy1.figure_name = gettext("IMPULSE PLOT");
impulse(sys);
hh=gca();
hh.auto_clear="on"
endfunction
function sig()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
// set(gca(),"auto clear","on")
demo_lhy1 = scf(100002);
demo_lhy1.background = -2;
demo_lhy1.figure_position = [50 50];
demo_lhy1.axes_size = [axes_w axes_h];
demo_lhy1.figure_name = gettext("SIGMA");
sigma(sys);
hh=gca();
hh.auto_clear="on"
endfunction
function iopz()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
// set(gca(),"auto clear","on")
demo_lhy1 = scf(100002);
demo_lhy1.background = -2;
demo_lhy1.figure_position = [50 50];
demo_lhy1.axes_size = [axes_w axes_h];
demo_lhy1.figure_name = gettext("IOPZPLOT");
iopzplot(sys);
hh=gca();
hh.auto_clear="on"
endfunction
function mgin()
// if ~isempty(handles.obj.children); then
// delete(handles.obj.children)
// end
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
demo_lhy1 = scf(100002);
demo_lhy1.background = -2;
demo_lhy1.figure_position = [50 50];
demo_lhy1.axes_size = [axes_w axes_h];
demo_lhy1.figure_name = gettext("MARGIN");
margin(sys)
endfunction
function bde()
// if ~isempty(handles.obj.children); then
// delete(handles.obj.children)
// end
impls.children.visible="off"
iop.children.visible="off"
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
demo_lhy1 = scf(100002);
demo_lhy1.background = -2;
demo_lhy1.figure_position = [50 50];
demo_lhy1.axes_size = [axes_w axes_h];
demo_lhy1.figure_name = gettext("BODE");
bode(sys)
endfunction
//------------------------------------------------------------------///-------------------------------------------------------------------------------------
function PZdata()
tag1 = findobj("tag","impuls");
tag1.visible="off"
tag1 = findobj("tag","impuls1");
tag1.visible="off"
tag1 = findobj("tag","impuls2");
tag1.visible="off"
tag2 = findobj("tag","margin1");
tag2.visible="off"
tag2 = findobj("tag","margin2");
tag2.visible="off"
tag1 = findobj("tag","p4");
tag1.visible="off"
tag1 = findobj("tag","p5");
tag1.visible="off"
tag1 = findobj("tag","p6");
tag1.visible="off"
tag1 = findobj("tag","p7");
tag1.visible="off"
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 20 frame_w-10 40],"tag","p1","string","Pole","callback","pol();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 80 frame_w-10 40],"tag","p2","string","Zero","callback","zer();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 140 frame_w-10 40],"tag","p3","string","ZPK","callback","zpkdat();");
////// uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 100 frame_w-10 40],"tag","zpkdata1","string","AllMargin","callback","allmargi();");
////// uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 140 frame_w-10 40],"tag","tfdata1","string","StepInfo","callback","stepinf();");
endfunction
function pol()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
poles=cell2mat(pole(sys))
//disp(poles) ;
len = size(poles,1) ;
//disp(len)
page = list() ;
page($+1)=list(list([1 len+1],'frame','Poles'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(poles(i))));
//disp('hello')
end
guimaker(page,list('Parameters')) ;
endfunction
function zer()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
zeroes = (zero(sys)) ;
//disp(poles) ;
len = size(zeroes,1) ;
//disp(len)
page = list() ;
page($+1)=list(list([1 len+1],'frame','Zeroes'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(zeroes(i))));
//disp('hello')
end
guimaker(page,list('Parameters')) ;
endfunction
function zpkdat()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
[a,b,c] = zpkdata(sys) ;
[num, den] = tfdata(sys) ;
page = list() ;
page($+1)=list(list([1 2],'frame','Gain Matrix'));
page($+1)=list(list('text','Gain'),list('edit',string(c)));
len = length(num) ;
page($+1)=list(list([1 len+1],'frame','Numerator'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(num(i))));
//disp('hello')
end
len = length(den) ;
page($+1)=list(list([1 len+1],'frame','Denominator'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(den(i))));
//disp('hello')
end
guimaker(page,list('Parameters')) ;
endfunction
function Systemdata()
tag1 = findobj("tag","impuls");
tag1.visible="off"
tag1 = findobj("tag","impuls1");
tag1.visible="off"
tag1 = findobj("tag","impuls2");
tag1.visible="off"
tag2 = findobj("tag","margin1");
tag2.visible="off"
tag2 = findobj("tag","margin2");
tag2.visible="off"
tag1 = findobj("tag","p1");
tag1.visible="off"
tag1 = findobj("tag","p2");
tag1.visible="off"
tag1 = findobj("tag","p3");
tag1.visible="off"
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 20 frame_w-10 40],"tag","p4","string","TFdata","callback","tfdat();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 80 frame_w-10 40],"tag","p5","string","Bandwidth","callback","bandwid();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 140 frame_w-10 40],"tag","p6","string","AllMargin","callback","allmargi();");
uicontrol("parent",demo_lhy,"relief","groove","style","pushbutton","units","pixels","position",[margin_x+50 200 frame_w-10 40],"tag","p7","string","StepInfo","callback","stepinf();");
endfunction
function bandwid()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
band = bandwidth(sys) ;
page = list() ;
page($+1)=list(list([1 2],'frame','Bandwidth'));
page($+1)=list(list('text','Bandwidth'),list('edit',string(band)));
guimaker(page,list('Parameters')) ;
endfunction
function tfdat()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
[num, den] = tfdata(sys) ;
page = list() ;
len = length(num) ;
page($+1)=list(list([1 len+1],'frame','Numerator'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(num(i))));
//disp('hello')
end
len = length(den) ;
page($+1)=list(list([1 len+1],'frame','Denominator'));
for i =1:len
page($+1)=list(list('text',string(i)),list('edit',string(den(i))));
//disp('hello')
end
guimaker(page,list('Parameters')) ;
endfunction
function stepinf()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
[x1 x2 x3 x4 x5 x6 x7 x8] = stepinfo(sys) ;
page = list() ;
page($+1)=list(list([1 8],'frame','Step Info'));
page($+1)=list(list('text','Rise Time'),list('edit',string(x1)));
page($+1)=list(list('text','Settling Time'),list('edit',string(x2)));
page($+1)=list(list('text','Settling Minimum'),list('edit',string(x3)));
page($+1)=list(list('text','Settling Maximum'),list('edit',string(x4)));
page($+1)=list(list('text','Overshoot'),list('edit',string(x5)));
page($+1)=list(list('text','Undershoot'),list('edit',string(x6)));
page($+1)=list(list('text','Peak'),list('edit',string(x7)));
page($+1)=list(list('text','Peak Time'),list('edit',string(x8)));
guimaker(page,list('Parameters')) ;
endfunction
function allmargi()
editsys = findobj("tag","nter");syst =(editsys.string);
s=%s;
sys=evstr(syst);
sys=syslin('c',sys);
a = allmargin(sys) ;
x1 = a.GMF ;
x2 = a.GM ;
x3 = a.PMF ;
x4 = a.PM ;
x5 = a.DM ;
x6 = a.DMF ;
x7 =a.stable ;
page = list() ;
page($+1)=list(list([1 7],'frame','All Margin'));
page($+1)=list(list('text','Gain Margin Frequency [rad/s]'),list('edit',string(x1)));
page($+1)=list(list('text','Gain Margin [db]'),list('edit',string(x2)));
page($+1)=list(list('text','Phase Margin Frequency [rad/s]'),list('edit',string(x3)));
page($+1)=list(list('text','Phase Margin'),list('edit',string(x4)));
page($+1)=list(list('text','Delay Margin'),list('edit',string(x5)));
page($+1)=list(list('text','Delay Margin Frequency [rad/s]'),list('edit',string(x6)));
page($+1)=list(list('text','Stable'),list('edit',string(x7)));
guimaker(page,list('Parameters')) ;
endfunction
//--------------------------------------------------///--------------------------------------------------------------------------------------------------------
//