forked from swarfer/GRBL-Post-Processor
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathOpenbuildsFusion360PostGrblX32-4thaxis-beta.cps
2711 lines (2515 loc) · 89.8 KB
/
OpenbuildsFusion360PostGrblX32-4thaxis-beta.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
/**
Original sample post:
Copyright (C) 2012-2022 by Autodesk, Inc.
All rights reserved.
RS-274D Multi-axis post processor configuration.
The above post sample forms the basis for this post.
$Revision: 44023 7d0062d6193198b074b1bb174154c949e72cb2df $
$Date: 2022-11-04 21:33:14 $
$Id$
FORKID {2EECF092-D7C3-4ACA-BFE6-377B72950FE9}
This post:
Additions based on the OpenBuildsFusion360PostGRBL.cps
Custom Post-Processor for grblHAL based Openbuilds-style CNC machines
For BlackboxX32 based on ESP32 for grblHAL with 4th axis
DOES NOT DO LASER AND PLASMA - ONLY MILLING
Made possible by
Swarfer https://github.com/swarfer/GRBL-Post-Processor
Sharmstr https://github.com/sharmstr/GRBL-Post-Processor
Strooom https://github.com/Strooom/GRBL-Post-Processor
This post-Processor should work on GRBLhal-based machines
Changelog
xx/Dec/2022 - V0.0.1 : Initial version (Swarfer)
Jan 2024 - V0.0.3b : machine simulation
MAr 2024 - V0.0.4 : remove alert() calls
*/
obversion = 'V0.0.3_beta';
debugMode = false;
description = "OB BBx32 Multi-axis Post Processor Milling Only";
vendor = "Openbuilds";
vendorUrl = "http://www.openbuilds.com";
machineControl = "grblHAL 1.1 ESP32 / BlackBox X32 XYZA",
legal = "Copyright (C) 2012-2023 by Autodesk, Inc. and OpenBuilds.com 2024";
model = "grblHAL";
certificationLevel = 2;
minimumRevision = 45892;
longDescription = "MultiAxis post for Blackbox X32 with single rotary axis A or plain XYZ - MILLING ONLY.";
extension = "gcode";
setCodePage("ascii");
var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,=_-*/\\:";
capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION;
tolerance = spatial(0.002, MM);
minimumChordLength = spatial(0.25, MM);
minimumCircularRadius = spatial(0.125, MM); // 0.125
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.1);
maximumCircularSweep = toRad(180);
allowHelicalMoves = true;
allowSpiralMoves = false;
allowedCircularPlanes = (1 << PLANE_XY); // allow only XY plane
// if you need vertical arcs then uncomment the line below
allowedCircularPlanes = (1 << PLANE_XY) | (1 << PLANE_ZX) | (1 << PLANE_YZ); // allow all planes, recentering arcs solves YZ/XZ arcs
// if you allow vertical arcs then be aware that ObCONTROL will not display the gcode correctly, but it WILL cut correctly.
/*
useMultiAxisFeatures: { // DTS remove this and make always false
title : "Use G68.2",
description: "Enable to output G68.2 blocks for 3+2 operations, disable to output rotary angles.",
group : "multiAxis",
scope : ["machine", "post"],
type : "boolean",
value : false
},
*/
var showSequenceNumbers = false; // DTS - never want line numbers
var preloadTool = false; // DTS - never want to preload
var forceCyclesOff = true; // DTS - wait until CONTROL can display cycles before enabling this
// user-defined properties
properties =
{
optionalStop: {
title: "Optional stop",
description: "Outputs optional stop code when necessary in the code.",
group: "preferences",
type: "boolean",
value: true,
scope: "post"
},
useToolChange: { // replaces generateMultiple
title: "Use Toolchange M6",
description: "Use tool change codes (true) or use , file per tool output (false).",
group: "preferences",
type: "boolean",
value: false,
scope: "post"
},
routerType: {
group: "spindle",
title: "SPINDLE Router type",
description: "Select the type of spindle you have.",
type: "enum",
value: "other",
values: [
{ title: "Other", id: "other" },
{ title: "Router11", id: "Router11" },
{ title: "Makita RT0701", id: "Makita" },
{ title: "Dewalt 611", id: "Dewalt" }
]
},
spindleOnOffDelay: {
group: "spindle",
title: "SPINDLE on/off delay",
description: "Time (in seconds) the spindle needs to get up to speed or stop",
type: "number",
value: 1.5
},
/*
preloadTool: {
title : "Preload tool",
description: "Preloads the next tool at a tool change (if any).",
group : "preferences",
type : "boolean",
value : true,
scope : "post"
},
*/
safePositionMethod: {
title: "Safe Retracts",
description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.",
group: "startEndPos",
type: "enum",
values: [
//{title:"G28", id:"G28"},
{ title: "G53", id: "G53" },
{ title: "Clearance Height", id: "clearanceHeight" }
],
value: "G53",
scope: "post"
},
gotoMCSatend: {
group: "startEndPos",
title: "EndPos: Use Machine Coordinates (G53) at end of job?",
description: "Yes will do G53 G0 x{machinehomeX} y(machinehomeY) (Machine Coordinates), No will do G0 x(machinehomeX) y(machinehomeY) (Work Coordinates) at end of program",
type: "boolean",
scope: "post",
value: false
},
machineHomeX: {
group: "startEndPos",
title: "EndPos: End of job X position (MM).",
description: "(G53 or G54) X position to move to in Millimeters",
type: "spatial",
scope: "post",
value: toPreciseUnit(-10, MM)
},
machineHomeY: {
group: "startEndPos",
title: "EndPos: End of job Y position (MM).",
description: "(G53 or G54) Y position to move to in Millimeters.",
type: "spatial",
scope: "post",
value: toPreciseUnit(-10, MM)
},
machineHomeZ: {
group: "startEndPos",
title: "startEndPos: START and End of job Z position (MCS Only) (MM)",
description: "G53 Z position to move to in Millimeters, normally negative. Moves to this distance below Z home.",
type: "spatial",
scope: "post",
value: toPreciseUnit(-10, MM)
},
safeRetractDistance: {
title: "Safe retract distance for rewinds",
description: "Specifies the distance to add to retract distance when rewinding rotary axes.",
group: "multiAxis",
type: "spatial",
value: 0,
scope: "post"
},
useABCPrepositioning: {
title: "Preposition rotaries",
description: "Enable to preposition rotary axes prior to G68.2 blocks.",
group: "multiAxis",
scope: ["machine", "post"],
type: "boolean",
value: true
},
/*
showSequenceNumbers: {
title : "Use sequence numbers",
description: "'Yes' outputs sequence numbers on each block, 'Only on tool change' outputs sequence numbers on tool change blocks only, and 'No' disables the output of sequence numbers.",
group : "formats",
type : "enum",
values : [
{title:"Yes", id:"true"},
{title:"No", id:"false"},
{title:"Only on tool change", id:"toolChange"}
],
value: "false",
scope: "post"
},
sequenceNumberStart: {
title : "Start sequence number",
description: "The number at which to start the sequence numbers.",
group : "formats",
type : "integer",
value : 10,
scope : "post"
},
sequenceNumberIncrement: {
title : "Sequence number increment",
description: "The amount by which the sequence number is incremented by in each block.",
group : "formats",
type : "integer",
value : 5,
scope : "post"
},
*/
separateWordsWithSpace: {
title: "Separate words with space",
description: "Adds spaces between words if 'yes' is selected.",
group: "formats",
type: "boolean",
value: true,
scope: "post"
},
showNotes: {
title: "Show notes",
description: "Writes setup and operation notes as comments in the output code.",
group: "formats",
type: "boolean",
value: true,
scope: "post"
},
writeMachine: {
title: "Write machine",
description: "Output the machine settings in the header of the code.",
group: "formats",
type: "boolean",
value: true,
scope: "post"
},
writeTools: {
title: "Write tool list",
description: "Output a tool list in the header of the code.",
group: "formats",
type: "boolean",
value: true,
scope: "post"
}
};
// define the order of display
groupDefinitions =
{
spindle: { title:"Spindle Options", description:"Options for spindle control", collapsed: false, order: 5},
startEndPos: { title:"Start and End positions", description:"Set options for start and end safety positioning", collapsed: false, order: 7},
}
var numberOfToolSlots = 9999;
var numberOfSections = 0;
var wcsDefinitions =
{
useZeroOffset: false, // set to 'true' to allow for workoffset 0, 'false' treats 0 as 1
wcs: [
{ name: "Standard", format: "G", range: [54, 59] }, // standard WCS, output as G54-G59
{ name: "Extended", format: "G59.#", range: [1, 3] } // extended WCS, output as G59.7, etc.
// {name:"Extended", format:"G54 P#", range:[1, 64]} // extended WCS, output as G54 P7, etc.
]
};
var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines
// samples:
// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89}
// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]}
// {id: COOLANT_THROUGH_TOOL, on: "M88 P3 (myComment)", off: "M89"}
var coolants = [
{ id: COOLANT_FLOOD, on: 8 },
{ id: COOLANT_MIST }, // not supported by X32
{ id: COOLANT_THROUGH_TOOL },
{ id: COOLANT_AIR },
{ id: COOLANT_AIR_THROUGH_TOOL },
{ id: COOLANT_SUCTION },
{ id: COOLANT_FLOOD_MIST },
{ id: COOLANT_FLOOD_THROUGH_TOOL },
{ id: COOLANT_OFF, off: 9 }
];
var gFormat = createFormat({ prefix: "G", decimals: 1 });
var mFormat = createFormat({ prefix: "M", decimals: 0 });
var hFormat = createFormat({ prefix: "H", decimals: 0 });
var dFormat = createFormat({ prefix: "D", decimals: 0 });
var xyzFormat = createFormat({ decimals: (unit == MM ? 3 : 4), type: FORMAT_REAL, minDigitsRight: 1 });
//var abcFormat = createFormat({decimals:3, type:FORMAT_REAL, scale:DEG});
var abcFormat = createFormat({ decimals: 3, type: FORMAT_REAL, scale: DEG, minDigitsRight: 1 });
var feedFormat = createFormat({ decimals: (unit == MM ? 1 : 2) });
var inverseTimeFormat = createFormat({ decimals: 3, type: FORMAT_REAL });
var toolFormat = createFormat({ decimals: 0 });
var rpmFormat = createFormat({ decimals: 0 });
var secFormat = createFormat({ decimals: 3, type: FORMAT_REAL }); // seconds - range 0.001-1000
var taperFormat = createFormat({ decimals: 1, scale: DEG });
var xOutput = createOutputVariable({ prefix: "X" }, xyzFormat);
var yOutput = createOutputVariable({ prefix: "Y" }, xyzFormat);
var zOutput = createOutputVariable({ onchange: function ()
{
retracted = false;
}, prefix: "Z"
}, xyzFormat);
var aOutput = createOutputVariable({ prefix: "A" }, abcFormat);
var bOutput = createOutputVariable({ prefix: "B" }, abcFormat);
var cOutput = createOutputVariable({ prefix: "C" }, abcFormat);
var feedOutput = createOutputVariable({ prefix: "F" }, feedFormat);
var inverseTimeOutput = createOutputVariable({ prefix: "F", control: CONTROL_FORCE }, inverseTimeFormat);
var sOutput = createOutputVariable({ prefix: "S", control: CONTROL_FORCE }, rpmFormat);
var dOutput = createOutputVariable({}, dFormat);
// circular output
var iOutput = createOutputVariable({ prefix: "I", control: CONTROL_FORCE }, xyzFormat);
var jOutput = createOutputVariable({ prefix: "J", control: CONTROL_FORCE }, xyzFormat);
var kOutput = createOutputVariable({ prefix: "K", control: CONTROL_FORCE }, xyzFormat);
var gMotionModal = createOutputVariable({}, gFormat); // modal group 1 // G0-G3, ...
var gPlaneModal = createOutputVariable({ onchange: function ()
{
gMotionModal.reset();
}
}, gFormat); // modal group 2 // G17-19
var gAbsIncModal = createOutputVariable({}, gFormat); // modal group 3 // G90-91
var gFeedModeModal = createOutputVariable({}, gFormat); // modal group 5 // G93-94
var gUnitModal = createOutputVariable({}, gFormat); // modal group 6 // G20-21
var gCycleModal = createOutputVariable({}, gFormat); // modal group 9 // G81, ...
var gRetractModal = createOutputVariable({}, gFormat); // modal group 10 // G98-99
var gRotationModal = createOutputVariable({}, gFormat); // modal group 16 // G68-G69
// settings
var WARNING_WORK_OFFSET = 0;
// collected state
var fileSequenceNumber = 1; // DTS multifile naming
var currentworkOffset = 54; // the current WCS in use, so we can retract Z between sections if needed
var NsequenceNumber;
var retracted = false; // specifies that the tool has been retracted to the safe plane
var firstNote = true; // handles output of notes from multiple setups
var forceSpindleSpeed = false;
// from BB post - multifile output variables
var filesToGenerate = 1; //used to figure out how many files will be generated so we can diplay in header
var fileIndexFormat = createFormat({ width: 2, zeropad: true, decimals: 0 });
var isNewfile = false; // set true when a new file has just been started
var numberOfSections = 0;
var isLaser = false; // todo - laser and plasma
var isPlasma = false;
var haveRapid = false; // assume no rapid moves
var linmove = 1; // linear move mode
var retractHeight = 1; // will be set by onParameter and used in onLinear to detect rapids
var linearizeSmallArcs = false; // arcs with radius < toolRadius have radius errors, linearize instead?
var toolRadius = toPreciseUnit(1, MM);
var lengthCompensated = false; // true if length compensation is on
/**
Writes the specified block.
*/
function writeBlock()
{
if (!formatWords(arguments))
{
return;
}
if (showSequenceNumbers == true)
{
writeWords2("N" + NsequenceNumber, arguments);
NsequenceNumber += getProperty("sequenceNumberIncrement", 1);
}
else
{
writeWords(arguments);
}
}
function formatComment(text, indent )
{
indent = String(indent);
//return "(" + String(text).replace(/[()]/g, "") + ")";
return ("(" + indent + filterText(String(text), permittedCommentChars) + ")");
}
/**
Writes the specified block - used for tool changes only.
*/
function writeToolBlock()
{
if (getProperty("useToolChange", false))
{
writeComment("writeToolBock");
//var show = getProperty("showSequenceNumbers",false);
//setProperty("showSequenceNumbers", (show == "true" || show == "toolChange") ? "true" : "false");
//todo - DTS - make tool calls optional
writeBlock(arguments);
//setProperty("showSequenceNumbers", show);
}
else
{
writeComment("Tool change avoided, see other file");
}
}
/**
Output a comment.
DTS - use multilines if needed
*/
function writeComment(text)
{
// split the line so no comment is longer than 70 chars
text = filterText(text.trim(), permittedCommentChars);
var indent = '';
if (text.length > 70)
{
//text = String(text).replace( /[^a-zA-Z\d:=,.]+/g, " "); // remove illegal chars
var bits = text.split(" "); // get all the words
var out = '';
for (i = 0; i < bits.length; i++)
{
out += bits[i] + " "; // additional space after first line
if (out.length > 60) // a long word on the end can take us to 80 chars!
{
writeln(formatComment(out.trim(), indent));
out = "";
indent = ' ';
}
}
if (out.length > 0)
writeln(formatComment(out.trim(),indent));
}
else
writeln(formatComment(text,''));
}
// Start of machine configuration logic
var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads
var useMultiAxisFeatures = false; // not for grblHAL, enable to use control enabled tilted plane, can be overridden with a property
var useABCPrepositioning = false; // enable to preposition rotary axes prior to tilted plane output, can be overridden with a property
var forceMultiAxisIndexing = false; // force multi-axis indexing for 3D programs
var eulerConvention = EULER_ZXZ_R; // euler angle convention for 3+2 operations
// internal variables, do not change
var receivedMachineConfiguration;
var operationSupportsTCP;
var multiAxisFeedrate;
/**
Activates the machine configuration (both from CAM and hardcoded)
*/
function activateMachine()
{
if (debugMode) writeComment("DEBUG activateMachine");
// disable unsupported rotary axes output
if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined"))
{
if (debugMode) writeComment("DEBUG activateMachine A disable");
aOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined"))
{
if (debugMode) writeComment("DEBUG activateMachine B disable");
bOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined"))
{
if (debugMode) writeComment("DEBUG activateMachine C disable");
cOutput.disable();
}
// setup usage of multiAxisFeatures
useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") :
(typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false);
useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") :
(typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false);
if (debugMode) writeComment("DEBUG useMultiAxisFeatures " + useMultiAxisFeatures);
if (debugMode) writeComment("DEBUG useABCPrepositioning " + useABCPrepositioning);
// don't need to modify any settings if 3-axis machine
if (!machineConfiguration.isMultiAxisConfiguration())
{
return;
}
// save multi-axis feedrate settings from machine configuration
var mode = machineConfiguration.getMultiAxisFeedrateMode();
var type = mode == FEED_INVERSE_TIME ? machineConfiguration.getMultiAxisFeedrateInverseTimeUnits() :
(mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateDPMType() : DPM_STANDARD);
multiAxisFeedrate =
{
mode: mode,
maximum: machineConfiguration.getMultiAxisFeedrateMaximum(),
type: type,
tolerance: mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateOutputTolerance() : 0,
bpwRatio : mode == FEED_DPM ? machineConfiguration.getMultiAxisFeedrateBpwRatio() : 1
};
// setup of retract/reconfigure TAG: Only needed until post kernel supports these machine config settings
if (receivedMachineConfiguration && machineConfiguration.performRewinds())
{
safeRetractDistance = machineConfiguration.getSafeRetractDistance();
safePlungeFeed = machineConfiguration.getSafePlungeFeedrate();
safeRetractFeed = machineConfiguration.getSafeRetractFeedrate();
}
if (typeof safeRetractDistance == "number" && getProperty("safeRetractDistance") != undefined && getProperty("safeRetractDistance") != 0)
{
safeRetractDistance = getProperty("safeRetractDistance");
}
// setup for head configurations
if (machineConfiguration.isHeadConfiguration())
{
compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength;
}
// calculate the ABC angles and adjust the points for multi-axis operations
// rotary heads may require the tool length be added to the pivot length
// so we need to optimize each section individually
if (machineConfiguration.isHeadConfiguration() && compensateToolLength)
{
writeComment('compensating') ;
for (var i = 0; i < getNumberOfSections(); ++i)
{
var section = getSection(i);
if (section.isMultiAxis())
{
machineConfiguration.setToolLength(section.getTool().overallLength); // define the tool length for head adjustments
section.optimizeMachineAnglesByMachine(machineConfiguration, OPTIMIZE_AXIS);
}
}
}
else // tables and rotary heads with TCP support can be optimized with a single call
{
if (debugMode) writeComment('optimizing machine angles') ;
optimizeMachineAngles2(OPTIMIZE_AXIS);
}
}
/**
Defines a hardcoded machine configuration
*/
function defineMachine()
{
if (debugMode) writeComment("DEBUG defineMachine");
if (!receivedMachineConfiguration) // CAM provided machine configuration takes precedence
{
writeComment("Using hardcoded machine XYZ - if you want A-axis then define a suitable machine in Fusion360");
// if (true) { // hardcoded machine configuration takes precedence
// define machine kinematics
var useTCP = false;
// todo - allow user to choose axis direction
//var aAxis = createAxis({coordinate:X, table:true, axis:[1, 0, 0], offset:[0, 0, 0], range:[0,360], cyclic:true, preference:-1, tcp:useTCP});
//machineConfiguration = new MachineConfiguration(aAxis);
machineConfiguration = new MachineConfiguration();
machineConfiguration.setVendor("OpenBuilds");
machineConfiguration.setModel("BBx32");
machineConfiguration.setDescription(description);
// multiaxis settings
if (machineConfiguration.isHeadConfiguration())
{
machineConfiguration.setVirtualTooltip(false); // translate the pivot point to the virtual tool tip for nonTCP rotary heads
}
// retract / reconfigure
var performRewinds = false; // set to true to enable the retract/reconfigure logic
if (performRewinds)
{
machineConfiguration.enableMachineRewinds(); // enables the retract/reconfigure logic
safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock, can be overridden with a property
safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate
safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate
machineConfiguration.setSafeRetractDistance(safeRetractDistance);
machineConfiguration.setSafeRetractFeedrate(safeRetractFeed);
machineConfiguration.setSafePlungeFeedrate(safePlungeFeed);
var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values
machineConfiguration.setRewindStockExpansion(stockExpansion);
}
// multi-axis feedrates
if (machineConfiguration.isMultiAxisConfiguration())
{
machineConfiguration.setMultiAxisFeedrate(
useTCP ? FEED_FPM : getProperty("useDPMFeeds") ? FEED_DPM : FEED_INVERSE_TIME,
9999.99, // maximum output value for inverse time feed rates
getProperty("useDPMFeeds") ? DPM_COMBINATION : INVERSE_MINUTES, // INVERSE_MINUTES/INVERSE_SECONDS or DPM_COMBINATION/DPM_STANDARD
0.5, // tolerance to determine when the DPM feed has changed
1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations
);
}
/* home positions */
// machineConfiguration.setHomePositionX(toPreciseUnit(0, IN));
// machineConfiguration.setHomePositionY(toPreciseUnit(0, IN));
// machineConfiguration.setRetractPlane(toPreciseUnit(0, IN));
// define the machine configuration
setMachineConfiguration(machineConfiguration); // inform post kernel of hardcoded machine configuration
if (receivedMachineConfiguration)
{
warning(localize("The provided CAM machine configuration is overwritten by the postprocessor."));
receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten
}
}
}
// End of machine configuration logic
function onOpen()
{
if (debugMode)
{
warning("debugMode is true");
}
//setWriteInvocations(debugMode);
// define and enable machine configuration
receivedMachineConfiguration = machineConfiguration.isReceived();
if (typeof defineMachine == "function")
{
defineMachine(); // hardcoded machine configuration
}
activateMachine(); // enable the machine optimizations and settings
gRotationModal.format(69); // Default to G69 Rotation Off
if (!getProperty("separateWordsWithSpace"))
{
setWordSeparator("");
}
showSequenceNumbers = getProperty("showSequenceNumbers", false);
NsequenceNumber = getProperty("sequenceNumberStart", 1);
preloadTool = getProperty("preloadTool", false);
numberOfSections = getNumberOfSections();
numberOfSections = getNumberOfSections();
checkforDuplicatetools(); // sets filesToGenerate
writeHeader(0);
if (programName)
{
writeComment(programName);
}
if (programComment)
{
writeComment(programComment);
}
// dump machine configuration
var vendor = machineConfiguration.getVendor();
var model = machineConfiguration.getModel();
var description = machineConfiguration.getDescription();
if (getProperty("writeMachine") && (vendor || model || description))
{
writeComment(localize("Machine"));
if (vendor)
{
writeComment(" " + localize("vendor") + ": " + vendor);
}
if (model)
{
writeComment(" " + localize("model") + ": " + model);
}
if (description)
{
writeComment(" " + localize("description") + ": " + description);
}
}
// dump tool information
if (getProperty("writeTools"))
{
var zRanges = {};
if (is3D())
{
var numberOfSections = getNumberOfSections();
for (var i = 0; i < numberOfSections; ++i)
{
var section = getSection(i);
var zRange = section.getGlobalZRange();
var tool = section.getTool();
if (zRanges[tool.number])
{
zRanges[tool.number].expandToRange(zRange);
}
else
{
zRanges[tool.number] = zRange;
}
}
}
var tools = getToolTable();
if (tools.getNumberOfTools() > 0)
{
for (var i = 0; i < tools.getNumberOfTools(); ++i)
{
var tool = tools.getTool(i);
var comment = "T" + toolFormat.format(tool.number) + " " +
"D=" + xyzFormat.format(tool.diameter) + " " +
localize("CR") + "=" + xyzFormat.format(tool.cornerRadius);
if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI))
{
comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg");
}
if (zRanges[tool.number])
{
comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum());
}
comment += " - " + getToolTypeName(tool.type);
writeComment(comment);
}
}
}
// output setup notes
if (getProperty("showNotes"))
{
writeSetupNotes();
}
if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0))
{
for (var i = 0; i < getNumberOfSections(); ++i)
{
if (getSection(i).workOffset > 0)
{
error(localize("Using multiple work offsets is not possible if the initial work offset is 0."));
return;
}
}
}
// absolute coordinates and feed per min
//writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gFeedModeModal.format(49));
writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), writeBlock(gPlaneModal.format(17)) );
switch (unit)
{
case IN:
writeBlock(gUnitModal.format(20));
break;
case MM:
writeBlock(gUnitModal.format(21));
break;
}
}
function onComment(message)
{
writeComment(message);
}
/** Force output of X, Y, and Z. */
function forceXYZ()
{
xOutput.reset();
yOutput.reset();
zOutput.reset();
}
/** Force output of A, B, and C. */
function forceABC()
{
aOutput.reset();
bOutput.reset();
cOutput.reset();
}
/** Force output of X, Y, Z, A, B, C, and F on next output. */
function forceAny()
{
forceXYZ();
forceABC();
feedOutput.reset();
}
var lengthCompensationActive = false;
/** Disables length compensation if currently active or if forced. */
function disableLengthCompensation(force)
{
if (lengthCompensationActive || force)
{
if (debugMode) writeComment('DEBUG disableLengthCompensation');
validate(retracted, "Cannot cancel length compensation if the machine is not fully retracted.");
writeBlock(gFormat.format(49));
lengthCompensationActive = false;
}
}
var currentWorkPlaneABC = undefined;
function forceWorkPlane()
{
currentWorkPlaneABC = undefined;
}
function defineWorkPlane(_section, _setWorkPlane)
{
var abc = new Vector(0, 0, 0);
if (forceMultiAxisIndexing || !is3D() || machineConfiguration.isMultiAxisConfiguration()) // use 5-axis indexing for multi-axis mode
{
// set working plane after datum shift
if (_section.isMultiAxis())
{
cancelTransformation();
if (_setWorkPlane)
{
forceWorkPlane();
}
if (machineConfiguration.isMultiAxisConfiguration())
{
abc = _section.getInitialToolAxisABC();
if (_setWorkPlane)
{
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
positionABC(abc, true);
}
}
else
{
if (_setWorkPlane)
{
var d = _section.getGlobalInitialToolAxis();
// position
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
"I" + xyzFormat.format(d.x), "J" + xyzFormat.format(d.y), "K" + xyzFormat.format(d.z)
);
}
}
}
else
{
if (useMultiAxisFeatures)
{
abc = _section.workPlane.getEuler2(eulerConvention);
cancelTransformation();
}
else
{
abc = getWorkPlaneMachineABC(_section.workPlane, true);
}
if (_setWorkPlane)
{
setWorkPlane(abc);
}
}
}
else // pure 3D
{
var remaining = _section.workPlane;
if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)))
{
error(localize("Tool orientation is not supported."));
return abc;
}
setRotation(remaining);
}
if (currentSection && (currentSection.getId() == _section.getId()))
{
operationSupportsTCP = (_section.isMultiAxis() || !useMultiAxisFeatures) && _section.getOptimizedTCPMode() == OPTIMIZE_NONE;
}
return abc;
}
function cancelWorkPlane()
{
writeBlock(gRotationModal.format(69)); // cancel frame
forceWorkPlane();
}
function setWorkPlane(abc)
{
if (is3D() && !machineConfiguration.isMultiAxisConfiguration())
{
return; // ignore
}
if (!((currentWorkPlaneABC == undefined) ||
abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) ||
abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) ||
abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z)))
{
return; // no change
}
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
if (!retracted)
{
writeRetract(Z);
}
if (useMultiAxisFeatures)
{
cancelWorkPlane();
if (machineConfiguration.isMultiAxisConfiguration())
{
var machineABC = abc.isNonZero() ? getWorkPlaneMachineABC(currentSection.workPlane, false) : abc;
if (useABCPrepositioning || abc.isZero())
{
positionABC(machineABC, true);
}
setCurrentABC(machineABC); // required for machine simulation
}
if (abc.isNonZero())
{
gRotationModal.reset();
writeBlock(gRotationModal.format(68.2), "X" + xyzFormat.format(0), "Y" + xyzFormat.format(0), "Z" + xyzFormat.format(0), "I" + abcFormat.format(abc.x), "J" + abcFormat.format(abc.y), "K" + abcFormat.format(abc.z)); // set frame
writeBlock(gFormat.format(53.1)); // turn machine
}
}
else
{
positionABC(abc, true);
}
onCommand(COMMAND_LOCK_MULTI_AXIS);
currentWorkPlaneABC = abc;
}
function getWorkPlaneMachineABC(workPlane, rotate)
{
var W = workPlane; // map to global frame
var currentABC = isFirstSection() ? new Vector(0, 0, 0) : getCurrentDirection();
var abc = machineConfiguration.getABCByPreference(W, currentABC, ABC, PREFER_PREFERENCE, ENABLE_ALL);
var direction = machineConfiguration.getDirection(abc);
if (!isSameDirection(direction, W.forward))
{
error(localize("Orientation not supported."));
}
if (rotate && !currentSection.isOptimizedForMachine())
{
machineConfiguration.setToolLength(compensateToolLength ? currentSection.getTool().overallLength : 0); // define the tool length for head adjustments
currentSection.optimize3DPositionsByMachine(machineConfiguration, abc, OPTIMIZE_AXIS);
}
return abc;
}
function positionABC(abc, force)
{
if (typeof unwindABC == "function")
{
unwindABC(abc, false);
}
if (force)
{
forceABC();
}
var a = aOutput.format(abc.x);
var b = bOutput.format(abc.y);
var c = cOutput.format(abc.z);
if (a || b || c)
{
if (!retracted)
{
if (typeof moveToSafeRetractPosition == "function")
{
moveToSafeRetractPosition();
}
else
{
writeRetract(Z);
}
}
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
gMotionModal.reset();
writeBlock(gMotionModal.format(0), a, b, c);
setCurrentABC(abc); // required for machine simulation
}
}
function onPassThrough(text)
{
writeNotes(text);
}
function onParameter(name, value)
{
switch (name)
{
case "job-notes": // write setup notes when multiple setups are used
if (!firstNote)
{