-
Notifications
You must be signed in to change notification settings - Fork 25
/
Mach3_4X_Y.gpp
591 lines (466 loc) · 10.4 KB
/
Mach3_4X_Y.gpp
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
;
; Mach3 post for SolidCam
; -----
; Setup: standard 3 axis mill. A axis rotary, along Y.
; Latest Revision:
@init_post
; Non GPPL variables
num_user_procs = 1
line_labels = TRUE ; Jump to N...
; GPPL variables
;pre_processor = 'Mach3 - 4 axis Y'
numeric_def_f = '5.3'
integer_def_f = '5.0(p)'
gcode_f = '2.0(p)'
mcode_f = '2.0(p)'
xpos_f = '5.3'
ypos_f = '5.3'
zpos_f = '5.3'
feed_f = '4.3(p)'
; tool_diameter_f = '5.3/1'
apos_f = '5.3'
blknum_f = '5.0(p)'
blknum_gen = false
blknum_exist = true
blknum_letter = 'N'
end_block_text = ''
blknum = 5
blknum_delta = 5
blknum_max = 999995
global logical use_sc_feeds
use_sc_feeds = FALSE
input 'Trace Level'trace_level
trace 'all':trace_level
endp
;-------------------
@start_of_file
{'%'}
{nl, 'O'program_number, ' (', part_name,')'}
if rotate_used then
gcode = 69
{nb, 'G'gcode}
endif
if mirror_used then
{nb, 'G50.1 X0 Y0'}
endif
endp
;-------------------
@start_program
{nb, '( --- Initialisation --- )'}
{nb, 'G0 G53 X0 Y0 A0'} ; TODO REMOVE !!! ;eliminate "Z0" tool crash
{nb, 'G0 G40 G49 G80'}
if inch_system then
{' G20'}
else
{' G21'}
endif
;{nb, '( --- Go To Machine Origin --- )'}
;{nb, 'G0 G53 Z0'}
;{nb, 'G0 G53 X0 Y0 A0'}
endp
;-------------------
@end_program
{nb, 'M9 M5'}
{nb, 'G0 Z'tool_z_level}
{nb, 'G0 X0 Y0 A0'}
{nl, 'M30'}
endp
;-------------------
@end_of_file
label = first_user_proc
{nl, '%'}
endp
;-------------------
@relative_mode
gcode = 91
{nb, 'G'gcode, ' '}
skipline = FALSE
endp
;-------------------
@absolute_mode
gcode = 90
{nb, 'G'gcode, ' '}
skipline = FALSE
endp
;-------------------
@machine_plane
gcode = 17 ; XY default
if machine_plane eq YZ
gcode = 19
endif
if machine_plane eq ZX
gcode = 18
endif
{nb, 'G'gcode}
endp
;-------------------
@call_proc
{[' ('message, ')']}
;if active(parm1) then
; gcode = 65
; {nb, 'G'gcode, ' P'label, ' A'parm1, [' B'parm2], [' C'parm3]}
;else
{nb, 'M98 P'label}
;endif
if proc_count gt 1 then
{' L'proc_count}
endif
endp
;-------------------
@proc
{nl, ':'label}
endp
;-------------------
@end_proc
{nb, 'M99'}
endp
;----------------
@loop
; TODO
;local integer var_num
;var_num = loop_level + 20
;{nb, '#', var_num, ' = 0'}
;{nb, 'WHILE [#', var_num, ' LT ', loop_count, '] DO ', loop_level}
endp
;----------------
@end_loop
; TODO
;local integer var_num
;var_num = loop_level + 20
;{nb, '#', var_num, ' = #', var_num, ' + 1'}
;{nb, 'END ', loop_level}
endp
;----------------
@def_tool
; {nb, '(G10 L1 P', (tool_number+1), ' R'tool_offset, ')'}
endp
;-------------------
@rapid_move
gcode = 0
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos] }
endp
;-------------------
@line
gcode = 1
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' F'feed] }
endp
;-------------------
@move_4x
gcode = 0
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], ' A'cpos }
endp
;-------------------
@line_4x
gcode = 1
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' A'cpos], [' F'feed] }
endp
;-------------------
@move_5x
gcode = 0
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' A'apos] }
endp
;-------------------
@line_5x
gcode = 1
if use_sc_feeds then
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' A'apos], [' F'feed] }
else
if original_feed > 0 then
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' A'apos], [' F'original_feed] }
else
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos], [' A'apos], [' F'feed] }
endif
endif
endp
;-------------------
@arc
if arc_direction eq CCW then
gcode = 3
else ; CW
gcode = 2
endif
{nb, ['G'gcode], [' X'xpos], [' Y'ypos], [' Z'zpos] }
if arc_size eq 360 then
{' I'xcenter_rel, ' J'ycenter_rel}
else
if arc_size gt 180 then
radius = -radius
endif
{' R'radius}
endif
{[' F'feed]}
endp
;-------------------
@compensation
if side eq COMP_LEFT then
gcode = 41
endif
if side eq COMP_RIGHT then
gcode = 42
endif
if side eq COMP_OFF then
gcode = 40
endif
{nb, 'G'gcode,' '}
if side ne COMP_OFF
{'D'(offset_number), ' '}
endif
skipline = FALSE
endp
;-------------------
@change_ref_point
; TODO
; Given in absolute mode
gcode = 10
{nb, 'G'gcode, 'L2 P'home_number ' X'xhome, ' Y'yhome, ' Z'zhome}
{nb, 'G90'}
endp
;-------------------
@home_number
gcode = 53 + home_number
{nb, 'G'gcode}
;{' A'(-angle_4x_around_x):'5.3(p)'}
endp
;-------------------
@rotate
if rotate_cancel then
gcode = 69
{nb, 'G'gcode}
else
gcode = 68
{nb, 'G'gcode, ' X0 Y0 G91 R'angle}
{nb, 'G90'}
endif
endp
;-------------------
@rotate_to_plane
;anext
;need_change_plane
{nb, 'G0 Z'tool_z_level}
{nb, 'G0 A'first_axis_angle}
endp
;-------------------
@fourth_axis
gcode = 0
{nb, 'G'gcode, ' A'first_axis_angle}
endp
@transform_info
{nb, 'G0 A'angle}
endp
;-------------------
@change_tool
local logical save_blknum_gen
if machine_plane eq XY
gcode = 17
endif
if machine_plane eq ZX
gcode = 18
endif
{nb, '(Tool # 'tool_number,' - Diameter 'tool_diameter,' D'tool_number,' H'tool_number, ')'}
mcode = 6
{nb, 'T'tool_number,' M' mcode' D'tool_number ' H'tool_number}
call @start_tool
call @home_number
endp
;-------------------
;TODO - check mach drill cicles. g83 in particular
@drill
change(apos) = FALSE ; So
call @move_5x
gcode = 98 ; default value
if drill_type eq G81 then
gcode = 81
endif
if drill_type eq G82 then
gcode = 82
endif
if drill_type eq G83 then
gcode = 83
endif
if drill_type eq G84 then
gcode = 84
endif
{nb, 'G'gcode, ' Z'drill_lower_z, ' R'drill_upper_z}
if drill_type eq G83 then
;{' Q'stepdown}
{' Q'down_step}
{' P'dwell:'7.0(*1000P)'}
endif
if drill_type eq G82 then
{' P'dwell:'7.0(*1000P)'}
endif
;if drill_type eq G84 then
; feed = spin * pitch
;endif
{' F'feed}
;{nb, ' ', ' X'xpos, ' Y'ypos, ' Z'zpos}
endp
;-------------------
@drill_point
;{nl, '('first_drill')'}
if not first_drill then
call @drill
;else
; {nb, ' ', ' X'xpos, ' Y'ypos, ' Z'zpos}
endif
endp
;-------------------
@drill4x_pnt
if not first_drill then
call @drill
endif
endp
;-------------------
@mirror
if mirror_type eq MIRROR_OFF then
{nb, 'G50.1 X0 Y0'}
else
{nb, 'G51.1 '}
if mirror_type eq MIRROR_X then
{'X1 Y0'}
endif
if mirror_type eq MIRROR_Y then
{'X0 Y1'}
endif
if mirror_type eq MIRROR_XY then
{'X1 Y1'}
endif
endif
endp
;-------------------
@end_drill
gcode = 80
{nb, 'G'gcode}
endp
;-------------------
@halt_program
{' M0'}
endp
;--------------------
@round_comp
; NOP
endp
;--------------------
@start_of_job
;{nb, '( ---- Start of 'job_name' ---- )'}
if msg ne ''
{nb, '('msg, ')'}
endif
if active(use_solidcam_feeds) then
;{nb, '( active use_solidcam_feeds ', use_solidcam_feeds, ' )'}
use_sc_feeds = use_solidcam_feeds
else
;{nb, '( active use_solidcam_feeds FALSE', use_solidcam_feeds, ' )'}
use_sc_feeds = FALSE
endif
; if fourth_axis_used eq false and rotate_used eq false then
; {nb, 'G0 Z'(tool_z_level):'5.3(p)', ' ; move up to tool_z_level'}
; ;{nb, 'G0 Z'clearance_level, '; clearance_level'}
; ;{nb, 'G0 G53 Z0'}
; ;{nb, 'G0 G53 A'(angle_4x_around_y):'5.3(p)'}
; endif
endp
;--------------------
@end_of_job
{nb, '( ---- End of 'job_name' ---- )'}
endp
;--------------------
@delay
gcode = 4
{nb, 'G'gcode, ' P'delay_period:integer_def_f}
endp
;-------------------
@dwell
delay_period = dwell_time
call @delay
endp
;--------------------
@cool_mist
if mist_coolant then
{nb, 'M7'}
else
{nb, 'M9'}
endif
endp
;--------------------
@cool_flood
if flood_coolant then
{nb, 'M8'}
else
{nb, 'M9'}
endif
endp
;--------------------
@message
if not instr(message, '-----') then
{nb, '( ', message, ' )'}
endif
endp
;-------------------
@mco_message
call @message
endp
;--------------------
@machine_opt_stop
if optional_stop then
if MCO_New_Line then
{nb}
endif
{' M1'}
endif
endp
;--------------------
@move_object
local string machine_coords
local numeric xpos, ypos, zpos, apos
machine_coords = ' G53' ; abs coords by default
if MCO_CoordSysType eq 1 then ; machine / abs coordinates
machine_coords = ' G53'
xpos = move_axis_x
ypos = move_axis_y
zpos = move_axis_z
apos = move_axis_a
else ; part coordinates
machine_coords = ''
xpos = xh_move
ypos = yh_move
zpos = zh_move
apos = ah_move
endif
if is_rapid_move then
{nb, 'G0', machine_coords, ' X'xpos, ' Y'ypos, ' Z'zpos, [' A'apos] }
else
{nb, 'G1', machine_coords, ' X'xpos, ' Y'ypos, ' Z'zpos, [' A'apos], [' F'feed_move] }
endif
endp
;--------------------
@assign_axis
; TODO
endp
;-------------------
; =======================
; USER DEFINED PROCEDURES
; =======================
@call_simple_proc
active(message) = FALSE
active(parm1) = FALSE
active(parm2) = FALSE
active(parm3) = FALSE
proc_count = 1
call @call_proc
endp
;-------------------
@start_tool
if tool_direction eq CW then
mcode = 3
else ; CCW
mcode = 4
endif
{nb, 'S'spin:integer_def_f, ' M'mcode}
{nb, 'M8'}
endp
;-------------------
@stop_tool
{nb, ' M5'}
endp
;-------------------