forked from martindb/mpcnc_posts_processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPCNC_Marlin20.cps
1350 lines (1215 loc) · 38.2 KB
/
MPCNC_Marlin20.cps
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable no-undef */
/*
https://github.com/kovyrin/mpcnc_posts_processor
MPCNC posts processor for milling and laser/plasma cutting.
*/
description = "MPCNC - Marlin 2.0";
vendor = "Oleksiy Kovyrin";
vendorUrl = "https://github.com/kovyrin/mpcnc_posts_processor";
certificationLevel = 2;
longDescription = "MPCNC post based on the DIYCNC post by martindb.";
extension = "gcode";
setCodePage("ascii");
capabilities = CAPABILITY_MILLING | CAPABILITY_JET;
// Arc support variables
minimumChordLength = spatial(0.01, MM);
minimumCircularRadius = spatial(0.01, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
maximumCircularSweep = toRad(180);
allowHelicalMoves = false;
allowedCircularPlanes = undefined;
//-------------------------------------------------------------------------------------------------
// user-defined properties
properties = {
jobMarlinEnforceFeedrate: {
title: "Job: Enforce Feedrate",
description: "Add feedrate to each movement g-code",
group: 1,
type: "boolean",
value: false,
},
jobTravelSpeedXY: {
title: "Job: Travel speed X/Y",
description: "High speed for travel movements X & Y (mm/min)",
group: 1,
type: "spatial",
value: 2500,
},
jobTravelSpeedZ: {
title: "Job: Travel Speed Z",
description: "High speed for travel movements z (mm/min)",
group: 1,
type: "spatial",
value: 300,
},
jobManualSpindlePowerControl: {
title: "Job: Manual Spindle On/Off",
description:
"Set Yes when your spindle motor is controlled by manual switch",
group: 1,
type: "boolean",
value: false,
},
jobUseArcs: {
title: "Job: Use Arcs",
description: "Use G2/G3 g-codes fo circular movements",
group: 1,
type: "boolean",
value: true,
},
jobSetOriginOnStart: {
title: "Job: Reset on start (G92)",
description: "Set origin when gcode start (G92)",
group: 1,
type: "boolean",
value: false,
},
jobGoOriginOnFinish: {
title: "Job: Goto 0 at end",
description: "Go X0 Y0 at gcode end",
group: 1,
type: "boolean",
value: true,
},
jobSequenceNumbers: {
title: "Job: Line numbers",
description: "Show sequence numbers",
group: 1,
type: "boolean",
value: false,
},
jobSequenceNumberStart: {
title: "Job: Line start",
description: "First sequence number",
group: 1,
type: "integer",
value: 10,
},
jobSequenceNumberIncrement: {
title: "Job: Line increment",
description: "Increment for sequence numbers",
group: 1,
type: "integer",
value: 1,
},
jobSeparateWordsWithSpace: {
title: "Job: Separate words",
description:
"Specifies that the words should be separated with a white space",
group: 1,
type: "boolean",
value: true,
},
toolChangeEnabled: {
title: "Change: Enabled",
description:
"Enable tool change code (bultin tool change requires LCD display)",
group: 2,
type: "boolean",
value: false,
},
toolChangeX: {
title: "Change: X",
description: "X position for builtin tool change",
group: 2,
type: "spatial",
value: 0,
},
toolChangeY: {
title: "Change: Y",
description: "Y position for builtin tool change",
group: 2,
type: "spatial",
value: 0,
},
toolChangeZ: {
title: "Change: Z ",
description: "Z position for builtin tool change",
group: 2,
type: "spatial",
value: 40,
},
toolChangeZProbe: {
title: "Change: Make Z Probe",
description: "Z probe after tool change",
group: 2,
type: "boolean",
value: true,
},
toolChangeDisableZStepper: {
title: "Change: Disable Z stepper",
description: "Disable Z stepper when change a tool",
group: 2,
type: "boolean",
value: false,
},
probeOnStart: {
title: "Probe: On job start",
description: "Execute probe gcode on job start",
group: 3,
type: "boolean",
value: false,
},
probeThickness: {
title: "Probe: Plate thickness",
description: "Plate thickness (mm)",
group: 3,
type: "spatial",
value: 0.8,
},
probeUseHomeZ: {
title: "Probe: Use Home Z",
description: "Use G28 for probing instead off G38",
group: 3,
type: "boolean",
value: true,
},
probeG38Target: {
title: "Probe: G38 target",
description: "Probing up to Z position (mm)",
group: 3,
type: "spatial",
value: -10,
},
probeG38Speed: {
title: "Probe: G38 speed",
description: "Probing with speed (mm/min)",
group: 3,
type: "spatial",
value: 30,
},
cutterOnVaporize: {
title: "Laser: On - Vaporize",
description:
"Persent of power to turn on the laser/plasma cutter in vaporize mode",
group: 4,
type: "number",
value: 100,
},
cutterOnThrough: {
title: "Laser: On - Through",
description:
"Persent of power to turn on the laser/plasma cutter in through mode",
group: 4,
type: "number",
value: 80,
},
cutterOnEtch: {
title: "Laser: On - Etch",
description: "Persent of power to on the laser/plasma cutter in etch mode",
group: 4,
type: "number",
value: 40,
},
cutterMarlinMode: {
title: "Laser: Marlin/Reprap mode",
description: "Marlin/Reprar mode of the laser/plasma cutter",
group: 4,
type: "integer",
value: 106,
values: [
{ title: "M106 S{PWM}/M107", id: 106 },
{ title: "M3 O{PWM}/M5", id: 3 },
{ title: "M42 P{pin} S{PWM}", id: 42 },
],
},
cutterMarlinPin: {
title: "Laser: Marlin M42 pin",
description: "Marlin custom pin number for the laser/plasma cutter",
group: 4,
type: "integer",
value: 4,
},
gcodeStartFile: {
title: "Extern: Start File",
description: "File with custom Gcode for header/start (in nc folder)",
group: 5,
type: "file",
value: "",
},
gcodeStopFile: {
title: "Extern: Stop File",
description: "File with custom Gcode for footer/end (in nc folder)",
group: 5,
type: "file",
value: "",
},
gcodeToolFile: {
title: "Extern: Tool File",
description: "File with custom Gcode for tool change (in nc folder)",
group: 5,
type: "file",
value: "",
},
gcodeProbeFile: {
title: "Extern: Probe File",
description: "File with custom Gcode for tool probe (in nc folder)",
group: 5,
type: "file",
value: "",
},
coolantA_Mode: {
title: "Coolant: A Mode",
description: "Enable issuing g-codes for control Coolant channel A",
group: 6,
type: "integer",
value: 0,
values: [
{ title: "off", id: 0 },
{ title: "flood", id: 1 },
{ title: "mist", id: 2 },
{ title: "throughTool", id: 3 },
{ title: "air", id: 4 },
{ title: "airThroughTool", id: 5 },
{ title: "suction", id: 6 },
{ title: "floodMist", id: 7 },
{ title: "floodThroughTool", id: 8 },
],
},
coolantAMarlinOn: {
title: "Coolant: A On command",
description: "GCode command to turn on Coolant channel A",
group: 6,
type: "string",
value: "M42 P11 S255",
},
coolantAMarlinOff: {
title: "Coolant: A Off command",
description: "Gcode command to turn off Coolant A",
group: 6,
type: "string",
value: "M42 P11 S0",
},
coolantB_Mode: {
title: "Coolant: B Mode",
description: "Enable issuing g-codes for control Coolant channel B",
group: 6,
type: "integer",
value: 0,
values: [
{ title: "off", id: 0 },
{ title: "flood", id: 1 },
{ title: "mist", id: 2 },
{ title: "throughTool", id: 3 },
{ title: "air", id: 4 },
{ title: "airThroughTool", id: 5 },
{ title: "suction", id: 6 },
{ title: "floodMist", id: 7 },
{ title: "floodThroughTool", id: 8 },
],
},
coolantBMarlinOn: {
title: "Coolant: B On command",
description: "GCode command to turn on Coolant channel B",
group: 6,
type: "string",
value: "M42 P6 S255",
},
coolantBMarlinOff: {
title: "Coolant: B Off command",
description: "Gcode command to turn off Coolant channel B",
group: 6,
type: "string",
value: "M42 P6 S0",
},
commentWriteTools: {
title: "Comment: Write Tools",
description: "Write table of used tools in job header",
group: 7,
type: "boolean",
value: true,
},
commentActivities: {
title: "Comment: Activities",
description:
"Write comments which somehow helps to understand current piece of g-code",
group: 7,
type: "boolean",
value: true,
},
commentSections: {
title: "Comment: Sections",
description: "Write header of every section",
group: 7,
type: "boolean",
value: true,
},
commentCommands: {
title: "Comment: Trace Commands",
description: "Write stringified commands called by CAM",
group: 7,
type: "boolean",
value: true,
},
commentMovements: {
title: "Comment: Trace Movements",
description: "Write stringified movements called by CAM",
group: 7,
type: "boolean",
value: true,
},
};
//-------------------------------------------------------------------------------------------------
// Formats
var gFormat = createFormat({ prefix: "G", decimals: 1 });
var mFormat = createFormat({ prefix: "M", decimals: 0 });
var xyzFormat = createFormat({ decimals: unit == MM ? 3 : 4 });
var xFormat = createFormat({ prefix: "X", decimals: unit == MM ? 3 : 4 });
var yFormat = createFormat({ prefix: "Y", decimals: unit == MM ? 3 : 4 });
var zFormat = createFormat({ prefix: "Z", decimals: unit == MM ? 3 : 4 });
var iFormat = createFormat({ prefix: "I", decimals: unit == MM ? 3 : 4 });
var jFormat = createFormat({ prefix: "J", decimals: unit == MM ? 3 : 4 });
var speedFormat = createFormat({ decimals: 0 });
var sFormat = createFormat({ prefix: "S", decimals: 0 });
var pFormat = createFormat({ prefix: "P", decimals: 0 });
var oFormat = createFormat({ prefix: "O", decimals: 0 });
var fFormat = createFormat({ prefix: "F", decimals: unit == MM ? 0 : 2 });
var toolFormat = createFormat({ decimals: 0 });
var taperFormat = createFormat({ decimals: 1, scale: DEG });
var secFormat = createFormat({ decimals: 3, forceDecimal: true }); // seconds - range 0.001-1000
// Linear outputs
var xOutput = createVariable({}, xFormat);
var yOutput = createVariable({}, yFormat);
var zOutput = createVariable({}, zFormat);
var fOutput = createVariable({}, fFormat);
// var sOutput = createVariable({ force: true }, sFormat);
// Circular outputs
var iOutput = createReferenceVariable({}, iFormat);
var jOutput = createReferenceVariable({}, jFormat);
// Modals
var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21
// Copied from the class init
gMotionModal = createModal({ force: true }, gFormat); // modal group 1 // G0-G3, ...
if (getProperty("jobMarlinEnforceFeedrate")) {
fOutput = createVariable({ force: true }, fFormat);
}
//-------------------------------------------------------------------------------------------------
// collected state
var sequenceNumber;
var spindleEnabled = false;
var cutterOnCurrentPower;
var pendingRadiusCompensation = RADIUS_COMPENSATION_OFF;
var currentSpindleSpeed = 0;
var currentCoolantMode = 0;
// Called on waterjet/plasma/laser cuts
var powerState = false;
//-------------------------------------------------------------------------------------------------
var permittedCommentChars =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,=_-*";
//-------------------------------------------------------------------------------------------------
// Writes the specified block.
function writeBlock() {
if (getProperty("jobSequenceNumbers")) {
writeWords2("N" + sequenceNumber, arguments);
sequenceNumber += getProperty("jobSequenceNumberIncrement");
} else {
writeWords(arguments);
}
}
//-------------------------------------------------------------------------------------------------
// Called in every new gcode file
// eslint-disable-next-line no-unused-vars
function onOpen() {
sequenceNumber = getProperty("jobSequenceNumberStart");
if (!getProperty("jobSeparateWordsWithSpace")) {
setWordSeparator("");
}
}
//-------------------------------------------------------------------------------------------------
// Called at end of gcode file
// eslint-disable-next-line no-unused-vars
function onClose() {
writeActivityComment(" *** STOP begin ***");
flushMotions();
if (getProperty("gcodeStopFile") == "") {
onCommand(COMMAND_COOLANT_OFF);
if (getProperty("jobGoOriginOnFinish")) {
rapidMovementsXY(0, 0);
}
onCommand(COMMAND_STOP_SPINDLE);
end();
writeActivityComment(" *** STOP end ***");
} else {
loadFile(getProperty("gcodeStopFile"));
}
close();
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onSection() {
// Write Start gcode of the documment (after the "onParameters" with the global info)
if (isFirstSection()) {
writeFirstSection();
}
writeActivityComment(" *** SECTION begin ***");
// Tool change
if (
getProperty("toolChangeEnabled") &&
!isFirstSection() &&
tool.number != getPreviousSection().getTool().number
) {
if (getProperty("gcodeToolFile") == "") {
// Builtin tool change gcode
writeActivityComment(" --- CHANGE TOOL begin ---");
toolChange();
writeActivityComment(" --- CHANGE TOOL end ---");
} else {
// Custom tool change gcode
loadFile(getProperty("gcodeToolFile"));
}
}
if (getProperty("commentSections")) {
// Machining type
if (currentSection.type == TYPE_MILLING) {
// Specific milling code
writeComment(
sectionComment +
" - Milling - Tool: " +
tool.number +
" - " +
tool.comment +
" " +
getToolTypeName(tool.type)
);
}
if (currentSection.type == TYPE_JET) {
// Cutter mode used for different cutting power in PWM laser
switch (currentSection.jetMode) {
case JET_MODE_THROUGH:
cutterOnCurrentPower = getProperty("cutterOnThrough");
break;
case JET_MODE_ETCHING:
cutterOnCurrentPower = getProperty("cutterOnEtch");
break;
case JET_MODE_VAPORIZE:
cutterOnCurrentPower = getProperty("cutterOnVaporize");
break;
default:
error("Cutting mode is not supported.");
}
writeComment(
sectionComment +
" - Laser/Plasma - Cutting mode: " +
getParameter("operation:cuttingMode")
);
}
// Print min/max boundaries for each section
vectorX = new Vector(1, 0, 0);
vectorY = new Vector(0, 1, 0);
writeComment(
" X Min: " +
xyzFormat.format(currentSection.getGlobalRange(vectorX).getMinimum()) +
" - X Max: " +
xyzFormat.format(currentSection.getGlobalRange(vectorX).getMaximum())
);
writeComment(
" Y Min: " +
xyzFormat.format(currentSection.getGlobalRange(vectorY).getMinimum()) +
" - Y Max: " +
xyzFormat.format(currentSection.getGlobalRange(vectorY).getMaximum())
);
writeComment(
" Z Min: " +
xyzFormat.format(currentSection.getGlobalZRange().getMinimum()) +
" - Z Max: " +
xyzFormat.format(currentSection.getGlobalZRange().getMaximum())
);
}
onCommand(COMMAND_START_SPINDLE);
onCommand(COMMAND_COOLANT_ON);
// Display section name in LCD
display_text(" " + sectionComment);
}
//-------------------------------------------------------------------------------------------------
function resetAll() {
xOutput.reset();
yOutput.reset();
zOutput.reset();
fOutput.reset();
}
//-------------------------------------------------------------------------------------------------
// Called in every section end
// eslint-disable-next-line no-unused-vars
function onSectionEnd() {
resetAll();
writeActivityComment(" *** SECTION end ***");
writeln("");
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onComment(message) {
writeComment(message);
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onRadiusCompensation() {
pendingRadiusCompensation = radiusCompensation;
}
//-------------------------------------------------------------------------------------------------
// Rapid movements
// eslint-disable-next-line no-unused-vars
function onRapid(x, y, z) {
rapidMovements(x, y, z);
}
//-------------------------------------------------------------------------------------------------
// Feed movements
// eslint-disable-next-line no-unused-vars
function onLinear(x, y, z, feed) {
linearMovements(x, y, z, feed);
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onRapid5D(_x, _y, _z, _a, _b, _c) {
error(localize("Multi-axis motion is not supported."));
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onLinear5D(_x, _y, _z, _a, _b, _c, _feed) {
error(localize("Multi-axis motion is not supported."));
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
if (pendingRadiusCompensation != RADIUS_COMPENSATION_OFF) {
error(
localize(
"Radius compensation cannot be activated/deactivated for a circular move."
)
);
return;
}
circular(clockwise, cx, cy, cz, x, y, z, feed);
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onPower(power) {
if (power != powerState) {
if (power) {
writeActivityComment(" >>> LASER Power ON");
laserOn(cutterOnCurrentPower);
} else {
writeActivityComment(" >>> LASER Power OFF");
laserOff();
}
powerState = power;
}
}
//-------------------------------------------------------------------------------------------------
// Called on Dwell Manual NC invocation
// eslint-disable-next-line no-unused-vars
function onDwell(seconds) {
if (seconds > 99999.999) {
warning(localize("Dwelling time is out of range."));
}
writeActivityComment(" >>> Dwell");
dwell(seconds);
}
//-------------------------------------------------------------------------------------------------
// Called with every parameter in the documment/section
// eslint-disable-next-line no-unused-vars
function onParameter(name, value) {
// Write gcode initial info
// Product version
if (name == "generated-by") {
writeComment(value);
writeComment(
" Posts processor: " + FileSystem.getFilename(getConfigurationPath())
);
}
// Date
if (name == "generated-at")
writeComment(" Gcode generated: " + value + " GMT");
// Document
if (name == "document-path") writeComment(" Document: " + value);
// Setup
if (name == "job-description") writeComment(" Setup: " + value);
// Get section comment
if (name == "operation-comment") sectionComment = value;
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onMovement(movement) {
if (getProperty("commentMovements")) {
var jet = tool.isJetTool && tool.isJetTool();
var id;
switch (movement) {
case MOVEMENT_RAPID:
id = "MOVEMENT_RAPID";
break;
case MOVEMENT_LEAD_IN:
id = "MOVEMENT_LEAD_IN";
break;
case MOVEMENT_CUTTING:
id = "MOVEMENT_CUTTING";
break;
case MOVEMENT_LEAD_OUT:
id = "MOVEMENT_LEAD_OUT";
break;
case MOVEMENT_LINK_TRANSITION:
id = jet ? "MOVEMENT_BRIDGING" : "MOVEMENT_LINK_TRANSITION";
break;
case MOVEMENT_LINK_DIRECT:
id = "MOVEMENT_LINK_DIRECT";
break;
case MOVEMENT_RAMP_HELIX:
id = jet ? "MOVEMENT_PIERCE_CIRCULAR" : "MOVEMENT_RAMP_HELIX";
break;
case MOVEMENT_RAMP_PROFILE:
id = jet ? "MOVEMENT_PIERCE_PROFILE" : "MOVEMENT_RAMP_PROFILE";
break;
case MOVEMENT_RAMP_ZIG_ZAG:
id = jet ? "MOVEMENT_PIERCE_LINEAR" : "MOVEMENT_RAMP_ZIG_ZAG";
break;
case MOVEMENT_RAMP:
id = "MOVEMENT_RAMP";
break;
case MOVEMENT_PLUNGE:
id = jet ? "MOVEMENT_PIERCE" : "MOVEMENT_PLUNGE";
break;
case MOVEMENT_PREDRILL:
id = "MOVEMENT_PREDRILL";
break;
case MOVEMENT_EXTENDED:
id = "MOVEMENT_EXTENDED";
break;
case MOVEMENT_REDUCED:
id = "MOVEMENT_REDUCED";
break;
case MOVEMENT_HIGH_FEED:
id = "MOVEMENT_HIGH_FEED";
break;
case MOVEMENT_FINISH_CUTTING:
id = "MOVEMENT_FINISH_CUTTING";
break;
}
if (id == undefined) {
id = String(movement);
}
writeComment(" " + id);
}
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onSpindleSpeed(spindleSpeed) {
setSpindeSpeed(spindleSpeed, tool.clockwise);
}
//-------------------------------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
function onCommand(command) {
if (getProperty("commentActivities")) {
var stringId = getCommandStringId(command);
writeComment(" " + stringId);
}
switch (command) {
case COMMAND_START_SPINDLE:
onCommand(
tool.clockwise
? COMMAND_SPINDLE_CLOCKWISE
: COMMAND_SPINDLE_COUNTERCLOCKWISE
);
return;
case COMMAND_SPINDLE_CLOCKWISE:
if (tool.jetTool) return;
setSpindeSpeed(spindleSpeed, true);
return;
case COMMAND_SPINDLE_COUNTERCLOCKWISE:
if (tool.jetTool) return;
setSpindeSpeed(spindleSpeed, false);
return;
case COMMAND_STOP_SPINDLE:
if (tool.jetTool) return;
setSpindeSpeed(0, true);
return;
case COMMAND_COOLANT_ON:
setCoolant(tool.coolant);
return;
case COMMAND_COOLANT_OFF:
setCoolant(0); //COOLANT_DISABLED
return;
case COMMAND_LOCK_MULTI_AXIS:
return;
case COMMAND_UNLOCK_MULTI_AXIS:
return;
case COMMAND_BREAK_CONTROL:
return;
case COMMAND_TOOL_MEASURE:
if (tool.jetTool) return;
probeTool();
return;
case COMMAND_STOP:
writeBlock(mFormat.format(0));
return;
}
}
//-------------------------------------------------------------------------------------------------
function setSpindeSpeed(_spindleSpeed, _clockwise) {
if (currentSpindleSpeed != _spindleSpeed) {
if (_spindleSpeed > 0) {
spindleOn(_spindleSpeed, _clockwise);
} else {
spindleOff();
}
currentSpindleSpeed = _spindleSpeed;
}
}
//-------------------------------------------------------------------------------------------------
function handleMinMax(pair, range) {
var rmin = range.getMinimum();
var rmax = range.getMaximum();
if (pair.min == undefined || pair.min > rmin) {
pair.min = rmin;
}
if (pair.max == undefined || pair.max < rmax) {
pair.max = rmax;
}
}
//-------------------------------------------------------------------------------------------------
function writeFirstSection() {
var i, tool;
// dump tool information
var toolZRanges = {};
var vectorX = new Vector(1, 0, 0);
var vectorY = new Vector(0, 1, 0);
var ranges = {
x: { min: undefined, max: undefined },
y: { min: undefined, max: undefined },
z: { min: undefined, max: undefined },
};
var numberOfSections = getNumberOfSections();
for (i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
tool = section.getTool();
var zRange = section.getGlobalZRange();
var xRange = section.getGlobalRange(vectorX);
var yRange = section.getGlobalRange(vectorY);
handleMinMax(ranges.x, xRange);
handleMinMax(ranges.y, yRange);
handleMinMax(ranges.z, zRange);
if (is3D() && getProperty("commentWriteTools")) {
if (toolZRanges[tool.number]) {
toolZRanges[tool.number].expandToRange(zRange);
} else {
toolZRanges[tool.number] = zRange;
}
}
}
writeComment(" ");
writeComment(" Ranges table:");
writeComment(
" X: Min=" +
xyzFormat.format(ranges.x.min) +
" Max=" +
xyzFormat.format(ranges.x.max) +
" Size=" +
xyzFormat.format(ranges.x.max - ranges.x.min)
);
writeComment(
" Y: Min=" +
xyzFormat.format(ranges.y.min) +
" Max=" +
xyzFormat.format(ranges.y.max) +
" Size=" +
xyzFormat.format(ranges.y.max - ranges.y.min)
);
writeComment(
" Z: Min=" +
xyzFormat.format(ranges.z.min) +
" Max=" +
xyzFormat.format(ranges.z.max) +
" Size=" +
xyzFormat.format(ranges.z.max - ranges.z.min)
);
if (getProperty("commentWriteTools")) {
writeComment(" ");
writeComment(" Tools table:");
var tools = getToolTable();
if (tools.getNumberOfTools() > 0) {
for (i = 0; i < tools.getNumberOfTools(); ++i) {
tool = tools.getTool(i);
var comment =
" T" +
toolFormat.format(tool.number) +
" D=" +
xyzFormat.format(tool.diameter) +
" CR=" +
xyzFormat.format(tool.cornerRadius);
if (tool.taperAngle > 0 && tool.taperAngle < Math.PI) {
comment += " TAPER=" + taperFormat.format(tool.taperAngle) + "deg";
}
if (toolZRanges[tool.number]) {
comment +=
" - ZMIN=" +
xyzFormat.format(toolZRanges[tool.number].getMinimum());
}
comment += " - " + getToolTypeName(tool.type) + " " + tool.comment;
writeComment(comment);
}
}
}
writeln("");
writeActivityComment(" *** START begin ***");
if (getProperty("gcodeStartFile") == "") {
start();
} else {
loadFile(getProperty("gcodeStartFile"));
}
writeActivityComment(" *** START end ***");
writeln("");
}
//-------------------------------------------------------------------------------------------------
// Formats text as a gcode comment
function formatComment(text) {
return ";" + filterText(String(text), permittedCommentChars);
}
// Output a comment
function writeComment(text) {
writeln(formatComment(text));
}
//-------------------------------------------------------------------------------------------------
// Rapid movements with G1 and differentiated travel speeds for XY and Z
function rapidMovementsXY(_x, _y) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
if (x || y) {
if (pendingRadiusCompensation != RADIUS_COMPENSATION_OFF) {
error(
localize(
"Radius compensation mode cannot be changed at rapid traversal."
)
);
return;
}
f = fOutput.format(propertyMmToUnit(getProperty("jobTravelSpeedXY")));
writeBlock(gMotionModal.format(0), x, y, f);
}
}
//-------------------------------------------------------------------------------------------------
function rapidMovementsZ(_z) {
var z = zOutput.format(_z);
if (z) {
if (pendingRadiusCompensation != RADIUS_COMPENSATION_OFF) {
error(
localize(
"Radius compensation mode cannot be changed at rapid traversal."
)
);