-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
commands.sce
410 lines (342 loc) · 9.82 KB
/
commands.sce
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
/*
* Created Date: April 8th 2017
* Author: ky fung
*
* Copyright (c) 2017-2019 Craftweeks CNC Group
*/
global X Y Z z0 V sON XMAX YMAX isReset isDirectGo COM_NUM
X = %nan;
Y = %nan;
Z = %nan;
z0 = %nan;
V = 15;
SON = 1;
XMAX = 203.2;
YMAX = 152.4;
ZMAX = 60.5;
isReset = 0;
isDirectGo = 0; // get(handles.checkbox1, 'value');
COM_NUM = 4;
function home_callback()
//Write your callback for home here
if isReset == 0 then
reset_callback();
end
disp('home')
global X Y Z
X = 0.0; Y = 0.0; Z = 0.0+z0;
str_cmd = '^DF;!MC1;!PZ0,0;V15.0;Z0,0,0;!MC0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;';
send_cmd(str_cmd);
update_pos_show(X,Y,Z)
updateAxisXY(X,Y)
endfunction
function send_cmd(str_cmd)
global isReset
if isReset ==1 then
if (getos() == "Windows") then
fd = mopen(TMPDIR+'/text_mputl.txt','wt');
mputl(str_cmd,fd);
mclose(fd);
s = sprintf('type %s\\text_mputl.txt > com%d', TMPDIR, COM_NUM);
[output,bOK] = dos(s ,'-echo')
end
end
endfunction
function update_pos_show(x,y,z)
global X Y Z
X = x;
Y = y;
Z = z;
set(handles.editboxX, 'String', msprintf('%.3f',X));
set(handles.editboxY, 'String', msprintf('%.3f',Y));
set(handles.editboxZ, 'String', msprintf('%.3f',Z));
endfunction
function [sx, sy, sz] = scale(x,y,z)
ratio = 40;
sx = x*ratio;
sy = y*ratio;
sz = z*ratio;
endfunction
function new_cmd = make_cmd(sx,sy,sz)
global V SON
new_cmd = '^DF;!MC'+ msprintf('%d',SON) +';!PZ0,0;V'+ msprintf('%.1f',V) +';Z' + msprintf('%.3f',sx) + ',' + msprintf('%.3f',sy) + ','+ msprintf('%.3f',sz) + ';!MC0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;';
endfunction
function relative_move(dx,dy,dz)
global X Y Z
x1 = dx + X
y1 = dy + Y
z1 = dz + Z
if x1 > XMAX then
x1 = XMAX;
end
if y1 > YMAX then
y1 = YMAX;
end
if z1 > 0 - z0 then
z1 = 0 -z0;
end
if x1 < 0 then
x1 = 0;
end
if y1 < 0 then
y1 = 0;
end
if z1 < -ZMAX then
z1 = -ZMAX;
end
if (x1 == X & y1 == Y & z1 == Z) then
disp('Zero Displacement')
// set(handles.messagebox, 'String', 'Zero Displacement');
else
updateAxisXY(x1,y1);
update_pos_show(x1,y1,z1)
if get(handles.checkbox1, 'value') == 1 then
[sx,sy,sz] = scale(x1,y1,z1-z0);
new_cmd = make_cmd(sx,sy,sz);
disp(new_cmd)
send_cmd(new_cmd);
end
end
endfunction
function reset_callback()
//Write your callback for reset here
disp('Reset')
//set(handles.ZOpos, 'String', '')
global Z z0 isReset
Z = 0.0; z0 = 0.0;
str_cmd = ';;^IN;!MC0;^PA;!ZO0;;;^IN;!MC0;';
isReset = 1;
send_cmd(str_cmd);
update_pos_show(X,Y,Z)
set(handles.pushbuttonGO, 'Enable','on')
//zPostion = findobj("tag" , "ZPostion");
//set(handles.ZOpos, 'String', 'Z0 = ' + msprintf('%.3f',z0) +' mm');
endfunction
function left01mm_callback()
//Write your callback for left1mm here
disp('-x 0.1mm')
relative_move(-0.10, 0, 0);
endfunction
function right01mm_callback()
//Write your callback for right1mm here
disp('+x 0.1mm')
relative_move(0.10, 0, 0);
endfunction
function in01mm_callback()
//Write your callback for in1mm here
disp('-y 0.1mm')
relative_move(0, -0.1, 0);
endfunction
function out01mm_callback()
//Write your callback for out1mm here
disp('+y 0.1mm')
relative_move(0, 0.1, 0);
endfunction
function left1mm_callback()
//Write your callback for left1mm here
disp('-x 1mm')
relative_move(-1, 0, 0);
endfunction
function right1mm_callback()
//Write your callback for right1mm here
disp('+x 1mm')
relative_move(1, 0, 0);
endfunction
function in1mm_callback()
//Write your callback for in1mm here
disp('-y 1mm')
relative_move(0, -1, 0);
endfunction
function out1mm_callback()
//Write your callback for out1mm here
disp('+y 1mm')
relative_move(0, +1, 0);
endfunction
function left10mm_callback()
//Write your callback for left1mm here
disp('-x 10mm')
relative_move(-10, 0, 0);
endfunction
function right10mm_callback()
//Write your callback for right1mm here
disp('+x 10mm')
relative_move(10, 0, 0);
endfunction
function in10mm_callback()
//Write your callback for in1mm here
disp('-y 10mm')
relative_move(0, -10, 0);
endfunction
function out10mm_callback()
//Write your callback for out1mm here
disp('+y 10mm')
relative_move(0, +10, 0);
endfunction
function left1step_callback()
//Write your callback for left1mm here
disp('-x 1 step')
relative_move(-0.025, 0, 0);
endfunction
function right1step_callback()
//Write your callback for right1mm here
disp('+x 1 step')
relative_move(0.025, 0, 0);
endfunction
function in1step_callback()
//Write your callback for in1mm here
disp('-y 1 step')
relative_move(0, -0.025, 0);
endfunction
function out1step_callback()
//Write your callback for out1mm here
disp('+y 1 step')
relative_move(0, +0.025, 0);
endfunction
function up1step_callback()
//Write your callback for in1mm here
disp('+z 1 step')
relative_move(0, 0, 0.025);
endfunction
function down1step_callback()
//Write your callback for out1mm here
disp('-z 1 step')
relative_move(0, 0, -0.025);
endfunction
function up01mm_callback()
//Write your callback for in1mm here
disp('+z 0.1 mm')
relative_move(0, 0, 0.10);
endfunction
function down01mm_callback()
//Write your callback for out1mm here
disp('-z 0.1 mm')
relative_move(0, 0, -0.10);
endfunction
function up1mm_callback()
//Write your callback for in1mm here
disp('+z 1 mm')
relative_move(0, 0, 1);
endfunction
function down1mm_callback()
//Write your callback for out1mm here
disp('-y 1 mm')
relative_move(0, 0, -1);
endfunction
function up10mm_callback()
//Write your callback for in1mm here
disp('+z 10 mm')
relative_move(0, 0, 10);
endfunction
function down10mm_callback()
//Write your callback for out1mm here
disp('-z 10 mm')
relative_move(0, 0, -10);
endfunction
function setZO_callback()
//Write your callback for out1mm here
global z0
z0 = Z;
disp('Set new ZO')
//set(handles.messagebox, 'String', 'Set new Z0');
set(handles.TextZO, 'String', 'Z0 = ' + msprintf('%.3f',z0) +' mm');
[sx,sy,sz] = scale(X,Y,Z);
str_cmd = '^DF;!ZO' + msprintf('%.3f',sz) + ';;';
send_cmd(str_cmd);
endfunction
function directgo_callback()
//Write your callback for directgo here
global isDirectGo
isDirectGo = get(handles.checkbox1, 'value')
disp(isDirectGo)
endfunction
function go_callback()
//Write your callback for go here
[sx,sy,sz] = scale(X,Y,Z-z0);
new_cmd = make_cmd(sx,sy,sz);
disp(new_cmd)
send_cmd(new_cmd);
endfunction
function xminhome_callback()
relative_move(-XMAX, 0, 0);
endfunction
function xmaxhome_callback()
relative_move(XMAX, 0, 0);
endfunction
function yminhome_callback()
relative_move(0, -YMAX, 0);
endfunction
function ymaxhome_callback()
relative_move(0, YMAX, 0);
endfunction
function printer_callback()
[output,bOK,exitcode]=dos('rundll32.exe printui.dll,PrintUIEntry /o /n '"Roland MODELA MDX-20'"','-echo')
endfunction
function editboxX_callback()
global X;
X = strtod(get(handles.editbox1, 'String'));
endfunction
function editboxY_callback()
global Y;
Y = strtod(get(handles.editbox2, 'String'));
endfunction
function editboxZ_callback()
global Z;
Z = strtod(get(handles.editbox3, 'String'));
endfunction
function spooler_callback()
status = get(handles.pushbuttonSpooler, 'String')
if strindex(status, 'Stop')>=0 then
disp('net stop spooler')
[output,bOK]=dos("net stop spooler",'-echo');
set(handles.pushbuttonSpooler, 'String', 'Start Spool');
else
disp('net start spooler')
[output,bOK]=dos("net start spooler",'-echo');
set(handles.pushbuttonSpooler, 'String', 'Stop Spool');
end
endfunction
function changeport_callback()
global COM_NUM
COM_NUM = get(handles.popupmenu1, 'Value')
endfunction
function help_callback()
dos('start https://chriskyfung.github.io/modela_mdx-15_20_control_panel_scilab/')
endfunction
function setAsMDX15_callback()
global XMAX YMAX
XMAX = 152.4;
YMAX = 101.6;
updateAxisXY(0,0)
set(handles.radiobuttonMDX20, 'Enable','off')
endfunction
function setAsMDX20_callback()
global XMAX YMAX
XMAX = 203.2;
YMAX = 152.4;
updateAxisXY(0,0)
set(handles.radiobuttonMDX15, 'Enable','off')
endfunction
function velocity_callback()
global V
V = get(handles.hsliderV, 'Value');
endfunction
function checkboxSON_callback()
global SON
SON = get(handles.checkboxSON, 'Value');
endfunction
function updateAxisXY(x0,y0)
set(handles.frameXY, 'Position', [0, 80-round(y0*(80/YMAX)), 198, 132])
drawlater();
plot(handles.axisXY, x0, y0, 'b*')
isoview2(-2,XMAX, -2, YMAX);
drawnow();
endfunction
function isoview2(xmin, xmax, ymin, ymax)
version_numbers = getversion('scilab');
if version_numbers(1) >= 6 then
isoview on;
replot([xmin, ymin, xmax, ymax],handles.axisXY)
else
isoview(xmin, xmax, ymin, ymax);
end
endfunction