forked from flyfisher604/mpcnc_post_processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPCNC.cps
1848 lines (1598 loc) · 65.9 KB
/
MPCNC.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
/*
https://github.com/guffy1234/mpcnc_posts_processor
MPCNC posts processor for milling and laser/plasma cutting.
*/
description = "MPCNC Milling/Laser - Marlin 2.0, Grbl 1.1, RepRap";
vendor = "flyfisher604";
vendorUrl = "https://github.com/flyfisher604/mpcnc_post_processor";
// Internal properties
certificationLevel = 2;
extension = "gcode";
setCodePage("ascii");
capabilities = CAPABILITY_MILLING | CAPABILITY_JET;
machineMode = undefined; //TYPE_MILLING, TYPE_JET
var eFirmware = {
MARLIN: 0,
GRBL: 1,
REPRAP: 2,
prop: {
0: {name: "Marlin 2.x", value: 0},
1: {name: "Grbl 1.1", value: 1},
2: {name: "RepRap", value: 2}
}
};
var fw = eFirmware.MARLIN;
var eComment = {
Off: 0,
Important: 1,
Info: 2,
Debug: 3,
prop: {
0: {name: "Off", value: 0},
1: {name: "Important", value: 1},
2: {name: "Info", value: 2},
3: {name: "Debug", value: 3}
}
};
var eCoolant = {
Off: 0,
Flood: 1,
Mist: 2,
ThroughTool: 3,
Air: 4,
AirThroughTool: 5,
Suction: 6,
FloodMist: 7,
FloodThroughTool: 8,
prop: {
0: {name: "Off", value: 0},
1: {name: "Flood", value: 1},
2: {name: "Mist", value: 2},
3: {name: "ThroughTool", value: 3},
4: {name: "Air", value: 4},
5: {name: "AirThroughTool", value: 5},
6: {name: "Suction", value: 6},
7: {name: "Flood and Mist", value: 7},
8: {name: "Flood and ThroughTool", value: 8},
}
};
// user-defined properties
properties = {
job0_SelectedFirmware : fw, // Firmware to use in special cases
job1_SetOriginOnStart: true, // Set current position as 0,0,0 on start (G92)
job2_ManualSpindlePowerControl: true, // Spindle motor is controlled by manual switch
job3_CommentLevel: eComment.Info, // The level of comments included
job4_UseArcs: true, // Produce G2/G3 for arcs
job5_SequenceNumbers: false, // show sequence numbers
job6_SequenceNumberStart: 10, // first sequence number
job7_SequenceNumberIncrement: 1, // increment for sequence numbers
job8_SeparateWordsWithSpace: true, // specifies that the words should be separated with a white space
job9_GoOriginOnFinish: true, // Go X0 Y0 current Z at end
fr0_TravelSpeedXY: 2500, // High speed for travel movements X & Y (mm/min)
fr1_TravelSpeedZ: 300, // High speed for travel movements Z (mm/min)
fr2_EnforceFeedrate: true, // Add feedrate to each movement line
frA_ScaleFeedrate: false, // Will feedrated be scaled
frB_MaxCutSpeedXY: 900, // Max speed for cut movements X & Y (mm/min)
frC_MaxCutSpeedZ: 180, // Max speed for cut movements Z (mm/min)
frD_MaxCutSpeedXYZ: 1000, // Max feedrate after scaling
mapD_RestoreFirstRapids: false, // Map first G01 --> G00
mapE_RestoreRapids: false, // Map G01 --> G00 for SafeTravelsAboveZ
mapF_SafeZ: "Retract:15", // G01 mapped to G00 if Z is >= jobSafeZRapid
mapG_AllowRapidZ: false, // Allow G01 --> G00 for vertical retracts and Z descents above safe
toolChange0_Enabled: false, // Enable tool change code (bultin tool change requires LCD display)
toolChange1_X: 0, // X position for builtin tool change
toolChange2_Y: 0, // Y position for builtin tool change
toolChange3_Z: 40, // Z position for builtin tool change
toolChange4_DisableZStepper: false, // disable Z stepper when change a tool
probe1_OnStart: false, // Execute probe gcode to align tool
probe2_OnToolChange: false, // Z probe after tool change
probe3_Thickness: 0.8, // plate thickness
probe4_UseHomeZ: true, // use G28 or G38 for probing
probe5_G38Target: -10, // probing up to pos
probe6_G38Speed: 30, // probing with speed
gcodeStartFile: "", // File with custom Gcode for header/start (in nc folder)
gcodeStopFile: "", // File with custom Gcode for footer/end (in nc folder)
gcodeToolFile: "", // File with custom Gcode for tool change (in nc folder)
gcodeProbeFile: "", // File with custom Gcode for tool probe (in nc folder)
cutter1_OnVaporize: 100, // Percentage of power to turn on the laser/plasma cutter in vaporize mode
cutter2_OnThrough: 80, // Percentage of power to turn on the laser/plasma cutter in through mode
cutter3_OnEtch: 40, // Percentage of power to turn on the laser/plasma cutter in etch mode
cutter4_MarlinMode: 106, // Marlin mode laser/plasma cutter
cutter5_MarlinPin: 4, // Marlin laser/plasma cutter pin for M42
cutter6_GrblMode: 4, // GRBL mode laser/plasma cutter
cutter7_Coolant: eCoolant.Off, // Use this coolant. F360 doesn't define a coolant for cutters
cl0_coolantA_Mode: eCoolant.Off, // Enable issuing g-codes for control Coolant channel A
cl1_coolantB_Mode: eCoolant.Off, // Use issuing g-codes for control Coolant channel B
cl2_coolantAOn: "M42 P6 S255", // GCode command to turn on Coolant channel A
cl3_coolantAOff: "M42 P6 S0", // Gcode command to turn off Coolant channel A
cl4_coolantBOn: "M42 P11 S255", // GCode command to turn on Coolant channel B
cl5_coolantBOff: "M42 P11 S0", // Gcode command to turn off Coolant channel B
cl6_cust_coolantAOn: "", // Custom GCode command to turn on Coolant channel A
cl7_cust_coolantAOff: "", // Custom Gcode command to turn off Coolant channel A
cl8_cust_coolantBOn: "", // Custom GCode command to turn on Coolant channel B
cl9_cust_coolantBOff: "", // Custom Gcode command to turn off Coolant channel B
DuetMillingMode: "M453 P2 I0 R30000 F200", // GCode command to setup Duet3d milling mode
DuetLaserMode: "M452 P2 I0 R255 F200", // GCode command to setup Duet3d laser mode
};
propertyDefinitions = {
job0_SelectedFirmware: {
title: "Job: CNC Firmware", description: "Dialect of GCode to create", group: 1,
type: "integer", default_mm: eFirmware.MARLIN, default_in: eFirmware.MARLIN,
values: [
{ title: eFirmware.prop[eFirmware.MARLIN].name, id: eFirmware.MARLIN },
{ title: eFirmware.prop[eFirmware.GRBL].name, id: eFirmware.GRBL },
{ title: eFirmware.prop[eFirmware.REPRAP].name, id: eFirmware.REPRAP },
]
},
job1_SetOriginOnStart: {
title: "Job: Zero Starting Location (G92)", description: "On start set the current location as 0,0,0 (G92)", group: 1,
type: "boolean", default_mm: true, default_in: true
},
job2_ManualSpindlePowerControl: {
title: "Job: Manual Spindle On/Off", description: "Enable to manually turn spindle motor on/off", group: 1,
type: "boolean", default_mm: true, default_in: true
},
job3_CommentLevel: {
title: "Job: Comment Level", description: "Controls the comments include", group: 1,
type: "integer", default_mm: eComment.Info, default_in: eComment.Info,
values: [
{ title: eComment.prop[eComment.Off].name, id: eComment.Off },
{ title: eComment.prop[eComment.Important].name, id: eComment.Important },
{ title: eComment.prop[eComment.Info].name, id: eComment.Info },
{ title: eComment.prop[eComment.Debug].name, id: eComment.Debug },
]
},
job4_UseArcs: {
title: "Job: Use Arcs", description: "Use G2/G3 g-codes fo circular movements", group: 1,
type: "boolean", default_mm: true, default_in: true
},
job5_SequenceNumbers: {
title: "Job: Enable Line #s", description: "Show sequence numbers", group: 1,
type: "boolean", default_mm: false, default_in: false
},
job6_SequenceNumberStart: {
title: "Job: First Line #", description: "First sequence number", group: 1,
type: "integer", default_mm: 10, default_in: 10
},
job7_SequenceNumberIncrement: {
title: "Job: Line # Increment", description: "Sequence number increment", group: 1,
type: "integer", default_mm: 1, default_in: 1
},
job8_SeparateWordsWithSpace: {
title: "Job: Include Whitespace", description: "Includes whitespace seperation between text", group: 1,
type: "boolean", default_mm: true, default_in: true
},
job9_GoOriginOnFinish: {
title: "Job: At end go to 0,0", description: "Go to X0 Y0 at gcode end, Z remains unchanged", group: 1,
type: "boolean", default_mm: true, default_in: true
},
fr0_TravelSpeedXY: {
title: "Feed: Travel speed X/Y", description: "High speed for Rapid movements X & Y (mm/min; in/min)", group: 2,
type: "spatial", default_mm: 2500, default_in: 100
},
fr1_TravelSpeedZ: {
title: "Feed: Travel Speed Z", description: "High speed for Rapid movements z (mm/min; in/min)", group: 2,
type: "spatial", default_mm: 300, default_in: 12
},
fr2_EnforceFeedrate: {
title: "Feed: Enforce Feedrate", description: "Add feedrate to each movement g-code", group: 2,
type: "boolean", default_mm: true, default_in: true
},
frA_ScaleFeedrate: {
title: "Feed: Scale Feedrate", description: "Scale feedrate based on X, Y, Z axis maximums", group: 2,
type: "boolean", default_mm: false, default_in: false
},
frB_MaxCutSpeedXY: {
title: "Feed: Max XY Cut Speed", description: "Maximum X or Y axis cut speed (mm/min; in/min)", group: 2,
type: "spatial", default_mm: 900, default_in: 35.43
},
frC_MaxCutSpeedZ: {
title: "Feed: Max Z Cut Speed", description: "Maximum Z axis cut speed (mm/min; in/min)", group: 2,
type: "spatial", default_mm: 180, default_in: 7.08
},
frD_MaxCutSpeedXYZ: {
title: "Feed: Max Toolpath Speed", description: "Maximum scaled feedrate for toolpath (mm/min; in/min)", group: 2,
type: "spatial", default_mm: 1000, default_in: 39.37
},
mapD_RestoreFirstRapids: {
title: "Map: First G1 -> G0 Rapid", description: "Ensure move to start of a cut is with a G0 Rapid", group: 3,
type: "boolean", default_mm: false, default_in: false
},
mapE_RestoreRapids: {
title: "Map: G1s -> G0 Rapids", description: "Enable to convert G1s to G0 Rapids when safe", group: 3,
type: "boolean", default_mm: false, default_in: false
},
mapF_SafeZ: {
title: "Map: Safe Z to Rapid", description: "Must be above or equal to this value to map G1s --> G0s; constant or keyword (see docs)", group: 3,
type: "string", default_mm: "Retract:15", default_in: "Retract:15"
},
mapG_AllowRapidZ: {
title: "Map: Allow Rapid Z", description: "Enable to include vertical retracts and safe descents", group: 3,
type: "boolean", default_mm: false, default_in: false
},
toolChange0_Enabled: {
title: "Tool Change: Enable", description: "Include tool change code when tool changes (bultin tool change requires LCD display)", group: 4,
type: "boolean", default_mm: false, default_in: false
},
toolChange1_X: {
title: "Tool Change: X", description: "X location for tool change", group: 4,
type: "spatial", default_mm: 0, default_in: 0
},
toolChange2_Y: {
title: "Tool Change: Y", description: "Y location for tool change", group: 4,
type: "spatial", default_mm: 0, default_in: 0
},
toolChange3_Z: {
title: "Tool Change: Z ", description: "Z location for tool change", group: 4,
type: "spatial", default_mm: 40, default_in: 1.6
},
toolChange4_DisableZStepper: {
title: "Tool Change: Disable Z stepper", description: "Disable Z stepper after reaching tool change location", group: 4,
type: "boolean", default_mm: false, default_in: false
},
probe1_OnStart: {
title: "Probe: On job start", description: "Execute probe gcode on job start", group: 5,
type: "boolean", default_mm: false, default_in: false
},
probe2_OnToolChange: {
title: "Probe: After Tool Change", description: "After tool change, probe Z at the current location", group: 5,
type: "boolean", default_mm: false, default_in: false
},
probe3_Thickness: {
title: "Probe: Plate thickness", description: "Plate thickness", group: 5,
type: "spatial", default_mm: 0.8, default_in: 0.032
},
probe4_UseHomeZ: {
title: "Probe: Use Home Z (G28)", description: "Probe with G28 (Yes) or G38 (No)", group: 5,
type: "boolean", default_mm: true, default_in: true
},
probe5_G38Target: {
title: "Probe: G38 target", description: "G38 Probing's furthest Z position", group: 5,
type: "spatial", default_mm: -10, default_in: -0.5
},
probe6_G38Speed: {
title: "Probe: G38 speed", description: "G38 Probing's speed (mm/min; in/min)", group: 5,
type: "spatial", default_mm: 30, default_in: 1.2
},
cutter1_OnVaporize: {
title: "Laser: On - Vaporize", description: "Persent of power to turn on the laser/plasma cutter in vaporize mode", group: 6,
type: "number", default_mm: 100, default_in: 100
},
cutter2_OnThrough: {
title: "Laser: On - Through", description: "Persent of power to turn on the laser/plasma cutter in through mode", group: 6,
type: "number", default_mm: 80, default_in: 80
},
cutter3_OnEtch: {
title: "Laser: On - Etch", description: "Persent of power to on the laser/plasma cutter in etch mode", group: 6,
type: "number", default_mm: 40, default_in: 40
},
cutter4_MarlinMode: {
title: "Laser: Marlin/Reprap Mode", description: "Marlin/Reprap mode of the laser/plasma cutter", group: 6,
type: "integer", default_mm: 106, default_in: 106,
values: [
{ title: "Fan - M106 S{PWM}/M107", id: 106 },
{ title: "Spindle - M3 O{PWM}/M5", id: 3 },
{ title: "Pin - M42 P{pin} S{PWM}", id: 42 },
]
},
cutter5_MarlinPin: {
title: "Laser: Marlin M42 Pin", description: "Marlin custom pin number for the laser/plasma cutter", group: 6,
type: "integer", default_mm: 4, default_in: 4
},
cutter6_GrblMode: {
title: "Laser: GRBL Mode", description: "GRBL mode of the laser/plasma cutter", group: 6,
type: "integer", default_mm: 4, default_in: 4,
values: [
{ title: "M4 S{PWM}/M5 dynamic power", id: 4 },
{ title: "M3 S{PWM}/M5 static power", id: 3 },
]
},
cutter7_Coolant: {
title: "Laser: Coolant", description: "Force a coolant to be used", group: 6,
type: "integer", default_mm: eCoolant.Off, default_in: eCoolant.Off,
values: [
{ title: eCoolant.prop[eCoolant.Off].name, id: eCoolant.Off },
{ title: eCoolant.prop[eCoolant.Flood].name, id: eCoolant.Flood },
{ title: eCoolant.prop[eCoolant.Mist].name, id: eCoolant.Mist },
{ title: eCoolant.prop[eCoolant.ThroughTool].name, id: eCoolant.ThroughTool },
{ title: eCoolant.prop[eCoolant.Air].name, id: eCoolant.Air },
{ title: eCoolant.prop[eCoolant.AirThroughTool].name, id: eCoolant.AirThroughTool },
{ title: eCoolant.prop[eCoolant.Suction].name, id: eCoolant.Suction },
{ title: eCoolant.prop[eCoolant.FloodMist].name, id: eCoolant.FloodMist },
{ title: eCoolant.prop[eCoolant.FloodThroughTool].name, id: eCoolant.FloodThroughTool }
]
},
gcodeStartFile: {
title: "Extern: Start File", description: "File with custom Gcode for header/start (in nc folder)", group: 7,
type: "file", default_mm: "", default_in: ""
},
gcodeStopFile: {
title: "Extern: Stop File", description: "File with custom Gcode for footer/end (in nc folder)", group: 7,
type: "file", default_mm: "", default_in: ""
},
gcodeToolFile: {
title: "Extern: Tool File", description: "File with custom Gcode for tool change (in nc folder)", group: 7,
type: "file", default_mm: "", default_in: ""
},
gcodeProbeFile: {
title: "Extern: Probe File", description: "File with custom Gcode for tool probe (in nc folder)", group: 7,
type: "file", default_mm: "", default_in: ""
},
// Coolant
cl0_coolantA_Mode: {
title: "Coolant: A Mode", description: "Enable channel A when tool is set this coolant", group: 8,
type: "integer", default_mm: 0, default_in: 0,
values: [
{ title: eCoolant.prop[eCoolant.Off].name, id: eCoolant.Off },
{ title: eCoolant.prop[eCoolant.Flood].name, id: eCoolant.Flood },
{ title: eCoolant.prop[eCoolant.Mist].name, id: eCoolant.Mist },
{ title: eCoolant.prop[eCoolant.ThroughTool].name, id: eCoolant.ThroughTool },
{ title: eCoolant.prop[eCoolant.Air].name, id: eCoolant.Air },
{ title: eCoolant.prop[eCoolant.AirThroughTool].name, id: eCoolant.AirThroughTool },
{ title: eCoolant.prop[eCoolant.Suction].name, id: eCoolant.Suction },
{ title: eCoolant.prop[eCoolant.FloodMist].name, id: eCoolant.FloodMist },
{ title: eCoolant.prop[eCoolant.FloodThroughTool].name, id: eCoolant.FloodThroughTool }
]
},
cl1_coolantB_Mode: {
title: "Coolant: B Mode", description: "Enable channel B when tool is set this coolant", group: 8,
type: "integer", default_mm: 0, default_in: 0,
values: [
{ title: eCoolant.prop[eCoolant.Off].name, id: eCoolant.Off },
{ title: eCoolant.prop[eCoolant.Flood].name, id: eCoolant.Flood },
{ title: eCoolant.prop[eCoolant.Mist].name, id: eCoolant.Mist },
{ title: eCoolant.prop[eCoolant.ThroughTool].name, id: eCoolant.ThroughTool },
{ title: eCoolant.prop[eCoolant.Air].name, id: eCoolant.Air },
{ title: eCoolant.prop[eCoolant.AirThroughTool].name, id: eCoolant.AirThroughTool },
{ title: eCoolant.prop[eCoolant.Suction].name, id: eCoolant.Suction },
{ title: eCoolant.prop[eCoolant.FloodMist].name, id: eCoolant.FloodMist },
{ title: eCoolant.prop[eCoolant.FloodThroughTool].name, id: eCoolant.FloodThroughTool }
]
},
cl2_coolantAOn: {
title: "Coolant: A Enable", description: "GCode to turn On coolant channel A", group: 8,
type: "enum", default_mm: "M42 P6 S255", default_in: "M42 P6 S255",
values: [
{ title: "Mrln: M42 P6 S255", id: "M42 P6 S255" },
{ title: "Mrln: M42 P11 S255", id: "M42 P11 S255" },
{ title: "Grbl: M7 (mist)", id: "M7" },
{ title: "Grbl: M8 (flood)", id: "M8" },
{ title: "Use custom", id: "Use custom" }
]
},
cl3_coolantAOff: {
title: "Coolant: A Disable", description: "Gcode to turn Off coolant A", group: 8,
type: "enum", default_mm: "M42 P6 S0", default_in: "M42 P6 S0",
values: [
{ title: "Mrln: M42 P6 S0", id: "M42 P6 S0" },
{ title: "Mrln: M42 P11 S0", id: "M42 P11 S0" },
{ title: "Grbl: M9 (off)", id: "M9" },
{ title: "Use custom", id: "Use custom" }
]
},
cl4_coolantBOn: {
title: "Coolant: B Enable", description: "GCode to turn On coolant channel B", group: 8,
type: "enum", default_mm: "M42 P11 S255", default_in: "M42 P11 S255",
values: [
{ title: "Mrln: M42 P11 S255", id: "M42 P11 S255" },
{ title: "Mrln: M42 P6 S255", id: "M42 P6 S255" },
{ title: "Grbl: M7 (mist)", id: "M7" },
{ title: "Grbl: M8 (flood)", id: "M8" },
{ title: "Use custom", id: "Use custom" }
]
},
cl5_coolantBOff: {
title: "Coolant: B Disable", description: "Gcode to turn Off coolant B", group: 8,
type: "enum", default_mm: "M42 P11 S0", default_in: "M42 P11 S0",
values: [
{ title: "Mrln: M42 P11 S0", id: "M42 P11 S0" },
{ title: "Mrln: M42 P6 S0", id: "M42 P6 S0" },
{ title: "Grbl: M9 (off)", id: "M9" },
{ title: "Use custom", id: "Use custom" }
]
},
cl6_cust_coolantAOn: {
title: "Coolant: Custom A Enable", description: "Custom GCode to turn On coolant channel A", group: 8,
type: "string", default_mm: "", default_in: "",
},
cl7_cust_coolantAOff: {
title: "Coolant: Custom A Disable", description: "Custom Gcode to turn Off coolant A", group: 8,
type: "string", default_mm: "", default_in: "",
},
cl8_cust_coolantBOn: {
title: "Coolant: Custom B Enable", description: "Custom GCode to turn On coolant channel B", group: 8,
type: "string", default_mm: "", default_in: "",
},
cl9_cust_coolantBOff: {
title: "Coolant: Custom B Disable", description: "Custom Gcode to turn Off coolant B", group: 8,
type: "string", default_mm: "", default_in: "",
},
DuetMillingMode: {
title: "Duet: Milling mode", description: "GCode command to setup Duet3d milling mode", group: 9,
type: "string", default_mm: "M453 P2 I0 R30000 F200", default_in: "M453 P2 I0 R30000 F200"
},
DuetLaserMode: {
title: "Duet: Laser mode", description: "GCode command to setup Duet3d laser mode", group: 9,
type: "string", default_mm: "M452 P2 I0 R255 F200", default_in: "M452 P2 I0 R255 F200"
},
};
var sequenceNumber;
// 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 kFormat = createFormat({ prefix: "K", 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 feedFormat = createFormat({ decimals: (unit == MM ? 0 : 2) });
var fFormat = createFormat({ prefix: "F", decimals: (unit == MM ? 0 : 2) });
var toolFormat = createFormat({ decimals: 0 });
var tFormat = createFormat({ prefix: "T", 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({ force: false }, fFormat);
var sOutput = createVariable({ force: true }, sFormat);
// Circular outputs
var iOutput = createReferenceVariable({}, iFormat);
var jOutput = createReferenceVariable({}, jFormat);
var kOutput = createReferenceVariable({}, kFormat);
// Modals
var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
var gPlaneModal = createModal({ onchange: function () { gMotionModal.reset(); } }, gFormat); // modal group 2 // G17-19
var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94
var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21
// 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;
// Writes the specified block.
function writeBlock() {
if (properties.job5_SequenceNumbers) {
writeWords2("N" + sequenceNumber, arguments);
sequenceNumber += properties.job7_SequenceNumberIncrement;
} else {
writeWords(arguments);
}
}
function flushMotions() {
if (fw == eFirmware.GRBL) {
}
// Default
else {
writeBlock(mFormat.format(400));
}
}
//---------------- Safe Rapids ----------------
var eSafeZ = {
CONST: 0,
FEED: 1,
RETRACT: 2,
CLEARANCE: 3,
ERROR: 4,
prop: {
0: {name: "Const", regex: /^\d+\.?\d*$/, numRegEx: /^(\d+\.?\d*)$/, value: 0},
1: {name: "Feed", regex: /^Feed:/i, numRegEx: /:(\d+\.?\d*)$/, value: 1},
2: {name: "Retract", regex: /^Retract:/i, numRegEx: /:(\d+\.?\d*)$/, alue: 2},
3: {name: "Clearance", regex: /^Clearance:/i, numRegEx: /:(\d+\.?\d*)$/, value: 3},
4: {name: "Error", regex: /^$/, numRegEx: /^$/, value: 4}
}
};
var safeZMode = eSafeZ.CONST;
var safeZHeightDefault = 15;
var safeZHeight;
function parseSafeZProperty() {
var str = properties.mapF_SafeZ;
// Look for either a number by itself or 'Feed:', 'Retract:' or 'Clearance:'
for (safeZMode = eSafeZ.CONST; safeZMode < eSafeZ.ERROR; safeZMode++) {
if (str.search(eSafeZ.prop[safeZMode].regex) == 0) {
break;
}
}
// If it was not an error then get the number
if (safeZMode != eSafeZ.ERROR) {
safeZHeightDefault = str.match(eSafeZ.prop[safeZMode].numRegEx);
if ((safeZHeightDefault == null) || (safeZHeightDefault.length !=2)) {
writeComment(eComment.Debug, " parseSafeZProperty: " + safeZHeightDefault);
writeComment(eComment.Debug, " parseSafeZProperty.length: " + (safeZHeightDefault != null? safeZHeightDefault.length : "na"));
writeComment(eComment.Debug, " parseSafeZProperty: Couldn't find number");
safeZMode = eSafeZ.ERROR;
safeZHeightDefault = 15;
}
else {
safeZHeightDefault = safeZHeightDefault[1];
}
}
writeComment(eComment.Debug, " parseSafeZProperty: safeZMode = '" + eSafeZ.prop[safeZMode].name + "'");
writeComment(eComment.Debug, " parseSafeZProperty: safeZHeightDefault = " + safeZHeightDefault);
}
function safeZforSection(_section)
{
if (properties.mapE_RestoreRapids) {
switch (safeZMode) {
case eSafeZ.CONST:
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ using const: " + safeZHeight);
break;
case eSafeZ.FEED:
if (hasParameter("operation:feedHeight_value") && hasParameter("operation:feedHeight_absolute")) {
let feed = _section.getParameter("operation:feedHeight_value");
let abs = _section.getParameter("operation:feedHeight_absolute");
if (abs == 1) {
safeZHeight = feed;
writeComment(eComment.Info, " SafeZ feed level: " + safeZHeight);
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ feed level not abs: " + safeZHeight);
}
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ feed level not defined: " + safeZHeight);
}
break;
case eSafeZ.RETRACT:
if (hasParameter("operation:retractHeight_value") && hasParameter("operation:retractHeight_absolute")) {
let retract = _section.getParameter("operation:retractHeight_value");
let abs = _section.getParameter("operation:retractHeight_absolute");
if (abs == 1) {
safeZHeight = retract;
writeComment(eComment.Info, " SafeZ retract level: " + safeZHeight);
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ retract level not abs: " + safeZHeight);
}
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ: retract level not defined: " + safeZHeight);
}
break;
case eSafeZ.CLEARANCE:
if (hasParameter("operation:clearanceHeight_value") && hasParameter("operation:clearanceHeight_absolute")) {
var clearance = _section.getParameter("operation:clearanceHeight_value");
let abs = _section.getParameter("operation:clearanceHeight_absolute");
if (abs == 1) {
safeZHeight = clearance;
writeComment(eComment.Info, " SafeZ clearance level: " + safeZHeight);
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ clearance level not abs: " + safeZHeight);
}
}
else {
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " SafeZ clearance level not defined: " + safeZHeight);
}
break;
case eSafeZ.ERROR:
safeZHeight = safeZHeightDefault;
writeComment(eComment.Important, " >>> WARNING: " + propertyDefinitions.mapF_SafeZ.title + "format error: " + safeZHeight);
break;
}
}
}
Number.prototype.round = function(places) {
return +(Math.round(this + "e+" + places) + "e-" + places);
}
// Returns true if the rules to convert G1s to G0s are satisfied
function isSafeToRapid(x, y, z) {
if (properties.mapE_RestoreRapids) {
// Calculat a z to 3 decimal places for zSafe comparison, every where else use z to avoid mixing rounded with unrounded
var z_round = z.round(3);
writeComment(eComment.Debug, "isSafeToRapid z: " + z + " z_round: " + z_round);
let zSafe = (z_round >= safeZHeight);
writeComment(eComment.Debug, "isSafeToRapid zSafe: " + zSafe + " z_round: " + z_round + " safeZHeight: " + safeZHeight);
// Destination z must be in safe zone.
if (zSafe) {
let cur = getCurrentPosition();
let zConstant = (z == cur.z);
let zUp = (z > cur.z);
let xyConstant = ((x == cur.x) && (y == cur.y));
let curZSafe = (cur.z >= safeZHeight);
writeComment(eComment.Debug, "isSafeToRapid curZSafe: " + curZSafe + " cur.z: " + cur.z);
// Restore Rapids only when the target Z is safe and
// Case 1: Z is not changing, but XY are
// Case 2: Z is increasing, but XY constant
// Z is not changing and we know we are in the safe zone
if (zConstant) {
return true;
}
// We include moves of Z up as long as xy are constant
else if (properties.mapG_AllowRapidZ && zUp && xyConstant) {
return true;
}
// We include moves of Z down as long as xy are constant and z always remains safe
else if (properties.mapG_AllowRapidZ && (!zUp) && xyConstant && curZSafe) {
return true;
}
}
}
return false;
}
//---------------- Coolant ----------------
function CoolantA(on) {
var coolantText = on ? properties.cl2_coolantAOn : properties.cl3_coolantAOff;
if (coolantText == "Use custom") {
coolantText = on ? properties.cl6_cust_coolantAOn : properties.cl7_cust_coolantAOff;
}
writeBlock(coolantText);
}
function CoolantB(on) {
var coolantText = on ? properties.cl4_coolantBOn : properties.cl5_coolantBOff;
if (coolantText == "Use custom") {
coolantText = on ? properties.cl8_cust_coolantBOn : properties.cl9_cust_coolantBOff;
}
writeBlock(coolantText);
}
// Manage two channels of coolant by tracking which coolant is being using for
// a channel (0 = disabled). SetCoolant called with desired coolant to use or 0 to disable
var curCoolant = eCoolant.Off; // The coolant requested by the tool
var coolantChannelA = eCoolant.Off; // The coolant running in ChannelA
var coolantChannelB = eCoolant.Off; // The coolant running in ChannelB
function setCoolant(coolant) {
writeComment(eComment.Debug, " ---- Coolant: " + coolant + " cur: " + curCoolant + " A: " + coolantChannelA + " B: " + coolantChannelB);
// If the coolant for this tool is the same as the current coolant then there is nothing to do
if (curCoolant == coolant) {
return;
}
// We are changing coolant, so disable any active coolant channels
// before we switch to the other coolant
if (coolantChannelA != eCoolant.Off) {
writeComment((coolant == eCoolant.Off) ? eComment.Important: eComment.Info, " >>> Coolant Channel A: " + eCoolant.prop[eCoolant.Off].name);
coolantChannelA = eCoolant.Off;
CoolantA(false);
}
if (coolantChannelB != eCoolant.Off) {
writeComment((coolant == eCoolant.Off) ? eComment.Important: eComment.Info, " >>> Coolant Channel B: " + eCoolant.prop[eCoolant.Off].name);
coolantChannelB = eCoolant.Off;
CoolantB(false);
}
// At this point we know that all coolant is off so make that the current coolant
curCoolant = eCoolant.Off;
// As long as we are not disabling coolant (coolant = 0), then check if either coolant channel
// matches the coolant requested. If neither do then issue an warning
var warn = true;
if (coolant != eCoolant.Off) {
if (properties.cl0_coolantA_Mode == coolant) {
writeComment(eComment.Important, " >>> Coolant Channel A: " + eCoolant.prop[coolant].name);
coolantChannelA = coolant;
curCoolant = coolant;
warn = false;
CoolantA(true);
}
if (properties.cl1_coolantB_Mode == coolant) {
writeComment(eComment.Important, " >>> Coolant Channel B: " + eCoolant.prop[coolant].name);
coolantChannelB = coolant;
curCoolant = coolant;
warn = false;
CoolantB(true);
}
if (warn) {
writeComment(eComment.Important, " >>> WARNING: No matching Coolant channel : " + ((coolant <= eCoolant.FloodThroughTool) ? eCoolant.prop[coolant].name : "unknown") + " requested");
}
}
}
//---------------- Cutters - Waterjet/Laser/Plasma ----------------
var cutterOnCurrentPower;
function laserOn(power) {
// Firmware is Grbl
if (fw == eFirmware.GRBL) {
var laser_pwm = power * 10;
writeBlock(mFormat.format(properties.cutter6_GrblMode), sFormat.format(laser_pwm));
}
// Default firmware
else {
var laser_pwm = power / 100 * 255;
switch (properties.cutter4_MarlinMode) {
case 106:
writeBlock(mFormat.format(106), sFormat.format(laser_pwm));
break;
case 3:
if (fw == eFirmware.REPRAP) {
writeBlock(mFormat.format(3), sFormat.format(laser_pwm));
} else {
writeBlock(mFormat.format(3), oFormat.format(laser_pwm));
}
break;
case 42:
writeBlock(mFormat.format(42), pFormat.format(properties.cutter5_MarlinPin), sFormat.format(laser_pwm));
break;
}
}
}
function laserOff() {
// Firmware is Grbl
if (fw == eFirmware.GRBL) {
writeBlock(mFormat.format(5));
}
// Default
else {
switch (properties.cutter4_MarlinMode) {
case 106:
writeBlock(mFormat.format(107));
break;
case 3:
writeBlock(mFormat.format(5));
break;
case 42:
writeBlock(mFormat.format(42), pFormat.format(properties.cutter5_MarlinPin), sFormat.format(0));
break;
}
}
}
//---------------- on Entry Points ----------------
// Called in every new gcode file
function onOpen() {
fw = properties.job0_SelectedFirmware;
// Output anything special to start the GCode
if (fw == eFirmware.GRBL) {
writeln("%");
}
// Configure the GCode G commands
if (fw == eFirmware.GRBL) {
gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
}
else {
gMotionModal = createModal({ force: true }, gFormat); // modal group 1 // G0-G3, ...
}
// Configure how the feedrate is formatted
if (properties.fr2_EnforceFeedrate) {
fOutput = createVariable({ force: true }, fFormat);
}
// Set the starting sequence number for line numbering
sequenceNumber = properties.job6_SequenceNumberStart;
// Set the seperator used between text
if (!properties.job8_SeparateWordsWithSpace) {
setWordSeparator("");
}
// Determine the safeZHeight to do rapids
parseSafeZProperty();
}
// Called at end of gcode file
function onClose() {
writeComment(eComment.Important, " *** STOP begin ***");
flushMotions();
if (properties.gcodeStopFile == "") {
onCommand(COMMAND_COOLANT_OFF);
if (properties.job9_GoOriginOnFinish) {
rapidMovementsXY(0, 0);
}
onCommand(COMMAND_STOP_SPINDLE);
end(true);
writeComment(eComment.Important, " *** STOP end ***");
} else {
loadFile(properties.gcodeStopFile);
}
if (fw == eFirmware.GRBL) {
writeln("%");
}
}
var forceSectionToStartWithRapid = false;
function onSection() {
// Every section needs to start with a Rapid to get to the initial location.
// In the hobby version Rapids have been elliminated and the first command is
// a onLinear not a onRapid command. This results in not current position being
// that same as the cut to position which means wecan't determine the direction
// of the move. Without a direction vector we can't scale the feedrate or convert
// onLinear moves back into onRapids. By ensuring the first onLinear is treated as
// a onRapid we have a currentPosition that is correct.
forceSectionToStartWithRapid = true;
// Write Start gcode of the documment (after the "onParameters" with the global info)
if (isFirstSection()) {
writeFirstSection();
}
writeComment(eComment.Important, " *** SECTION begin ***");
// Print min/max boundaries for each section
vectorX = new Vector(1, 0, 0);
vectorY = new Vector(0, 1, 0);
writeComment(eComment.Info, " X Min: " + xyzFormat.format(currentSection.getGlobalRange(vectorX).getMinimum()) + " - X Max: " + xyzFormat.format(currentSection.getGlobalRange(vectorX).getMaximum()));
writeComment(eComment.Info, " Y Min: " + xyzFormat.format(currentSection.getGlobalRange(vectorY).getMinimum()) + " - Y Max: " + xyzFormat.format(currentSection.getGlobalRange(vectorY).getMaximum()));
writeComment(eComment.Info, " Z Min: " + xyzFormat.format(currentSection.getGlobalZRange().getMinimum()) + " - Z Max: " + xyzFormat.format(currentSection.getGlobalZRange().getMaximum()));
// Determine the Safe Z Height to map G1s to G0s
safeZforSection(currentSection);
// Do a tool change if tool changes are enabled and its not the first section and this section uses
// a different tool then the previous section
if (properties.toolChange0_Enabled && !isFirstSection() && tool.number != getPreviousSection().getTool().number) {
if (properties.gcodeToolFile == "") {
// Post Processor does the tool change
writeComment(eComment.Important, " --- Tool Change Start")
toolChange();
writeComment(eComment.Important, " --- Tool Change End")
} else {
// Users custom tool change gcode is used
loadFile(properties.gcodeToolFile);
}
}
// Machining type
if (currentSection.type == TYPE_MILLING) {
// Specific milling code
writeComment(eComment.Info, " " + sectionComment + " - Milling - Tool: " + tool.number + " - " + tool.comment + " " + getToolTypeName(tool.type));
}
else if (currentSection.type == TYPE_JET) {
var jetModeStr;
var warn = false;
// Cutter mode used for different cutting power in PWM laser
switch (currentSection.jetMode) {
case JET_MODE_THROUGH:
cutterOnCurrentPower = properties.cutter2_OnThrough;
jetModeStr = "Through"
break;
case JET_MODE_ETCHING:
cutterOnCurrentPower = properties.cutter3_OnEtch;
jetModeStr = "Etching"
break;
case JET_MODE_VAPORIZE:
jetModeStr = "Vaporize"
cutterOnCurrentPower = properties.cutter1_OnVaporize;
break;
default:
jetModeStr = "*** Unknown ***"
warn = true;
}
if (warn) {
writeComment(eComment.Info, " " + sectionComment + ", Laser/Plasma Cutting mode: " + getParameter("operation:cuttingMode") + ", jetMode: " + jetModeStr);
writeComment(eComment.Important, "Selected cutting mode " + currentSection.jetMode + " not mapped to power level");
}
else {
writeComment(eComment.Info, " " + sectionComment + ", Laser/Plasma Cutting mode: " + getParameter("operation:cuttingMode") + ", jetMode: " + jetModeStr + ", power: " + cutterOnCurrentPower);
}
}
// Adjust the mode
if (fw == eFirmware.REPRAP) {
if (machineMode != currentSection.type) {
switch (currentSection.type) {
case TYPE_MILLING:
writeBlock(properties.DuetMillingMode);
break;
case TYPE_JET:
writeBlock(properties.DuetLaserMode);
break;
}
}