-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBodgery Special_2.cps
More file actions
1990 lines (1852 loc) · 76.2 KB
/
Bodgery Special_2.cps
File metadata and controls
1990 lines (1852 loc) · 76.2 KB
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
/**
Copyright (C) 2012-2023 by Autodesk, Inc.
All rights reserved.
Techno CNC post processor configuration.
$Revision: 44084 50de7c95bb70e9c4ee23870e4732db9f8459a22e $
$Date: 2023-08-14 15:40:23 $
FORKID {65C1DFDD-C0F7-4854-9202-01CBC4D0CC50}
*/
/*
This Post file has been modified to suit use for the TechnoCNC LC series
CNC router at the Bodgery in Madison Wisconsin. It's not intended for use
with any other machine - anywhere! Search on the word "Bodgery" to see all
changes made for this environment.
Changes made by Mike Litzkow, mlitzkow@wisc.edu,
*/
description = "Techno CNC router";
vendor = "Techno CNC";
vendorUrl = "http://www.technocnc.com";
legal = "Copyright (C) 2012-2023 by Autodesk, Inc.";
certificationLevel = 2;
minimumRevision = 45917;
longDescription = "Generic post for Techno CNC HD/HD2/HDS routers. You can select your machine model using the properties.";
extension = "nc";
programNameIsInteger = false;
setCodePage("ascii");
capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION;
tolerance = spatial(0.002, MM);
minimumChordLength = spatial(0.25, MM);
minimumCircularRadius = spatial(0.01, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
maximumCircularSweep = toRad(180);
allowHelicalMoves = false;
allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only
// user-defined properties
properties = {
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: "true",
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 : 10,
scope : "post"
},
optionalStop: {
title : "Optional stop",
description: "Outputs optional stop code during when necessary in the code.",
group : "preferences",
type : "boolean",
value : false,
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"
},
useRadius: {
title : "Radius arcs",
description: "If yes is selected, arcs are outputted using radius values rather than IJK.",
group : "preferences",
type : "boolean",
value : false,
scope : "post"
},
showNotes: {
title : "Show notes",
description: "Writes operation notes as comments in the outputted code.",
group : "formats",
type : "boolean",
value : false,
scope : "post"
},
machineModel: {
title : "Machine type",
description: "Sets the machine type.",
group : "configuration",
type : "enum",
values : [
/*
Change machine type to only allow "lc" at the Bodgery. It's the only
TechnoCNC machine we have.
{title:"HD Series", id:"hd"},
{title:"HD2 Series", id:"hd2"},
{title:"HDS Series", id:"hds"},
*/
{title:"LC Series", id:"lc"}
],
// value: "hds",
value: "lc",
scope: ["machine", "post"]
},
useToolCall: {
title : "Use tool changer",
description: "Specifies that a tool changer is available.",
group : "preferences",
type : "boolean",
// The Bodgery's TechnoCNC router doesn't have a tool changer
//value : true,
value : false,
scope : "post"
}
};
var gFormat = createFormat({prefix:"G", width:2, zeropad:true, decimals:1});
var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1});
var hFormat = createFormat({prefix:"H", width:2, zeropad:true, decimals:1});
var diameterOffsetFormat = createFormat({prefix:"D", width:2, zeropad:true, decimals:1});
var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
var ijkFormat = createFormat({decimals:6, forceDecimal:true}); // unitless
var rFormat = xyzFormat; // radius
var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG});
var feedFormat = createFormat({decimals:(unit == MM ? 0 : 1), forceDecimal:true});
var inverseTimeFormat = createFormat({decimals:5, forceDecimal:true});
var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
var toolFormat = createFormat({decimals:0});
var rpmFormat = createFormat({decimals:0});
var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999
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 toolVectorOutputI = createOutputVariable({prefix:"I", control:CONTROL_FORCE}, ijkFormat);
var toolVectorOutputJ = createOutputVariable({prefix:"J", control:CONTROL_FORCE}, ijkFormat);
var toolVectorOutputK = createOutputVariable({prefix:"K", control:CONTROL_FORCE}, ijkFormat);
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 pitchOutput = createOutputVariable({prefix:"K", control:CONTROL_FORCE}, pitchFormat);
var sOutput = createOutputVariable({prefix:"S", control:CONTROL_FORCE}, rpmFormat);
// 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({control:CONTROL_FORCE}, 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 // G94-95
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
var settings = {
coolant: {
// 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"}
coolants: [
{id:COOLANT_FLOOD, on:8},
{id:COOLANT_MIST, on:70, off:71},
{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}
],
singleLineCoolant: false, // specifies to output multiple coolant codes in one line rather than in separate lines
},
retract: {
cancelRotationOnRetracting: false, // specifies that rotations (G68) need to be canceled prior to retracting
methodXY : undefined, // special condition, overwrite retract behavior per axis
methodZ : undefined, // special condition, overwrite retract behavior per axis
useZeroValues : ["G28", "G30"] // enter property value id(s) for using "0" value instead of machineConfiguration axes home position values (ie G30 Z0)
},
machineAngles: { // refer to https://cam.autodesk.com/posts/reference/classMachineConfiguration.html#a14bcc7550639c482492b4ad05b1580c8
controllingAxis: ABC,
type : PREFER_PREFERENCE,
options : ENABLE_ALL
},
workPlaneMethod: {
useTiltedWorkplane : true, // specifies that tilted workplanes should be used (ie. G68.2, G254, PLANE SPATIAL, CYCLE800), can be overwritten by property
eulerConvention : EULER_ZXZ_R, // specifies the euler convention (ie EULER_XYZ_R), set to undefined to use machine angles for TWP commands ('undefined' requires machine configuration)
eulerCalculationMethod: "standard", // ('standard' / 'machine') 'machine' adjusts euler angles to match the machines ABC orientation, machine configuration required
cancelTiltFirst : true, // cancel tilted workplane prior to WCS (G54-G59) blocks
useABCPrepositioning : false, // position ABC axes prior to tilted workplane blocks
forceMultiAxisIndexing: false, // force multi-axis indexing for 3D programs
optimizeType : OPTIMIZE_AXIS // can be set to OPTIMIZE_NONE, OPTIMIZE_BOTH, OPTIMIZE_TABLES, OPTIMIZE_HEADS, OPTIMIZE_AXIS. 'undefined' uses legacy rotations
},
comments: {
permittedCommentChars: " abcdefghijklmnopqrstuvwxyz0123456789.,=_-", // letters are not case sensitive, use option 'outputFormat' below. Set to 'undefined' to allow any character
prefix : ";(", // specifies the prefix for the comment
suffix : ")", // specifies the suffix for the comment
outputFormat : "upperCase", // can be set to "upperCase", "lowerCase" and "ignoreCase". Set to "ignoreCase" to write comments without upper/lower case formatting
maximumLineLength : 80 // the maximum number of characters allowed in a line, set to 0 to disable comment output
},
maximumSequenceNumber : undefined, // the maximum sequence number (Nxxx), use 'undefined' for unlimited
supportsToolVectorOutput : true, // specifies if the control does support tool axis vector output for multi axis toolpath
supportsRadiusCompensation: true, // specifies if radius compensation is supported on the control
outputToolDiameterOffset : false, // specifies if tool diameter offset code should be output for tool radius compensation (Dxx)
supportsTCP : false // specifies if the postprocessor does support TCP
};
var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads
function defineMachine() {
var useTCP = true;
if (receivedMachineConfiguration) {
if (machineConfiguration.isMultiAxisConfiguration() && getProperty("machineModel") != "hds" &&
getProperty("machineModel") != "hd2") {
error(localize("Multi-axis machine configurations are only supported by the HDS and HD2 models"));
return;
}
}
if (false) { // note: setup your machine here
var bAxis = createAxis({coordinate:1, table:false, axis:[0, -1, 0], range:[-90 - 0.0001, 90 + 0.0001], preference:0, tcp:useTCP});
machineConfiguration = new MachineConfiguration(bAxis);
setMachineConfiguration(machineConfiguration);
if (receivedMachineConfiguration) {
warning(localize("The provided CAM machine configuration is overwritten by the postprocessor."));
receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten
}
}
if (!receivedMachineConfiguration) {
// 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 rewind/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()) {
var useDPMFeeds = false;
machineConfiguration.setMultiAxisFeedrate(
useTCP ? FEED_FPM : useDPMFeeds ? FEED_FPM : FEED_INVERSE_TIME,
9999.99999, // maximum output value for inverse time feed rates
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
);
setMachineConfiguration(machineConfiguration);
}
/* home positions */
// machineConfiguration.setHomePositionX(toPreciseUnit(-29.0, IN));
// machineConfiguration.setHomePositionY(toPreciseUnit(-8, IN));
// machineConfiguration.setRetractPlane(toPreciseUnit(2.5, IN));
}
}
// End of machine configuration logic
function onOpen() {
/*
Make certain these properties are set up appropriately for the Bodgery,
regardless what the user has configured.
*/
setProperty("useToolCall", false);
setProperty("machineModel", "lc" );
receivedMachineConfiguration = machineConfiguration.isReceived();
if (typeof defineMachine == "function") {
defineMachine(); // hardcoded machine configuration
}
activateMachine(); // enable the machine optimizations and settings
if (getProperty("machineModel") == "lc") {
// settings.comments.maximumLineLength = 0;
gPlaneModal.disable();
}
if (getProperty("machineModel") == "hd") {
settings.supportsRadiusCompensation = false;
unit = IN;
}
if (getProperty("machineModel") == "hds") {
hFormat = createFormat({prefix:"h", decimals:0});
settings.workPlaneMethod.useTiltedWorkplane = !machineConfiguration.isMultiAxisConfiguration();
settings.supportsTCP = true;
tcp.isSupportedByControl = true;
}
if (getProperty("useRadius")) {
maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC
}
gRotationModal.format(69); // Default to G69 Rotation Off
if (!getProperty("separateWordsWithSpace")) {
setWordSeparator("");
}
if (getProperty("machineModel") == "hd" || getProperty("machineModel") == "lc") {
writeln("%");
}
writeComment(programName);
writeComment(programComment);
writeProgramHeader();
// absolute coordinates and feed per min
if (getProperty("machineModel") == "hd2") {
writeBlock(gAbsIncModal.format(90), gFormat.format(40), gFormat.format(80));
writeBlock(gPlaneModal.format(17), gFormat.format(49));
} else if (getProperty("machineModel") == "hds") {
writeBlock(gAbsIncModal.format(90));
writeBlock(gFormat.format(40));
writeBlock(gFormat.format(80));
writeBlock(gPlaneModal.format(17));
writeBlock(gFormat.format(27));
} else {
writeBlock(gAbsIncModal.format(90));
}
switch (unit) {
case IN:
if (getProperty("machineModel") != "hd" && getProperty("machineModel") != "lc") {
writeBlock(gUnitModal.format(70));
}
break;
case MM:
if (getProperty("machineModel") == "hd") {
error(localize("Unit MM is not supported by HD Series."));
return;
}
if (getProperty("machineModel") != "lc") {
writeBlock(gUnitModal.format(71));
}
break;
}
writeBlock(conditional(getProperty("machineModel") == "hds", gFormat.format(600)));
validateCommonParameters();
}
var lengthCompensationActive = false;
/** Disables length compensation if currently active or if forced. */
function disableLengthCompensation(force) {
if (lengthCompensationActive || force) {
validate(retracted, "Cannot cancel length compensation if the machine is not fully retracted.");
if (getProperty("machineModel") == "hd2") {
writeBlock(gFormat.format(49));
} else if (getProperty("machineModel") == "hds" && tcp.isSupportedByMachine) {
writeBlock("(TCP)");
}
lengthCompensationActive = false;
}
}
function writeInitialPositioning(initialPosition, isRequired) {
var gOffset = getSetting("outputToolLengthCompensation", true) ? getOffsetCode() : "";
var hOffset = getSetting("outputToolLengthOffset", true) ? hFormat.format(tool.lengthOffset) : "";
forceModals(gMotionModal);
writeStartBlocks(isRequired, function() {
if (typeof disableLengthCompensation == "function") {
disableLengthCompensation(false); // cancel tool length compensation prior to enabling it, required when switching G43/G43.4 modes
}
if (machineConfiguration.isHeadConfiguration()) {
if (getProperty("machineModel") == "hds") {
writeBlock(hOffset);
writeBlock(gOffset);
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y),
zOutput.format(initialPosition.z)
);
} else {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
gOffset,
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y),
zOutput.format(initialPosition.z), conditional(getProperty("machineModel") == "hd2", hOffset)
);
}
} else {
if (gOffset != undefined) {
if (getProperty("machineModel") == "hd2") {
writeBlock(gOffset, hOffset);
lengthCompensationActive = true;
} else if (getProperty("machineModel") == "hds") {
writeBlock(hOffset);
writeBlock(gOffset);
lengthCompensationActive = true;
}
}
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y)
);
}
lengthCompensationActive = true;
forceModals(gMotionModal);
});
if (getProperty("machineModel") == "hd2") {
validate(lengthCompensationActive, "Length compensation is not active.");
}
if (!isRequired) { // simple positioning
if (!retracted && xyzFormat.getResultingValue(getCurrentPosition().z) < xyzFormat.getResultingValue(initialPosition.z)) {
writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z));
}
forceXYZ();
writeBlock(
gAbsIncModal.format(90), gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y));
}
}
function onSection() {
var forceSectionRestart = optionalSection && !currentSection.isOptional();
optionalSection = currentSection.isOptional();
var insertToolCall = isToolChangeNeeded("number") || forceSectionRestart;
var newWorkOffset = isNewWorkOffset() || forceSectionRestart;
var newWorkPlane = isNewWorkPlane() || forceSectionRestart;
operationNeedsSafeStart = getProperty("safeStartAllOperations") && !isFirstSection();
if (insertToolCall || newWorkOffset || newWorkPlane) {
if (insertToolCall && !isFirstSection()) {
onCommand(COMMAND_STOP_SPINDLE); // stop spindle before retract during tool change
}
writeRetract(Z); // retract
forceXYZ();
}
// wcs
if (insertToolCall) { // force work offset when changing tool
currentWorkOffset = undefined;
}
var workOffset = currentSection.workOffset;
if (workOffset == 0) {
warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET);
workOffset = 1;
}
if (workOffset != currentWorkOffset) {
if (settings.workPlaneMethod.cancelTiltFirst) {
cancelWorkPlane();
}
forceWorkPlane();
}
if ((workOffset > 0) && (getProperty("machineModel") != "hd" && getProperty("machineModel") != "lc")) {
if (getProperty("machineModel") == "hds") {
if (machineConfiguration.isMultiAxisConfiguration()) { // cancel TCP prior to wcs change
if (!retracted) {
writeRetract(Z);
}
disableLengthCompensation(true);
}
writeBlock("(UAO," + workOffset + ")");
} else {
if (workOffset > 6) {
var p = workOffset - 6; // 1->...
if (p > 300) {
error(localize("Work offset out of range."));
return;
} else {
if (workOffset != currentWorkOffset) {
writeBlock(gFormat.format(54.1), "P" + p); // G54.1P
currentWorkOffset = workOffset;
}
}
} else {
if (workOffset != currentWorkOffset) {
writeBlock(gFormat.format(53 + workOffset)); // G54->G59
currentWorkOffset = workOffset;
}
}
}
}
writeln("");
writeComment(getParameter("operation-comment", ""));
if (getProperty("showNotes")) {
writeSectionNotes();
}
// tool change
writeToolCall(tool, insertToolCall);
startSpindle(tool, insertToolCall);
// output modals here
if (getProperty("machineModel") == "hds") {
writeBlock(gAbsIncModal.format(90));
writeBlock(gPlaneModal.format(17));
writeBlock(gFeedModeModal.format(94));
} else {
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gFeedModeModal.format(94));
}
if (insertToolCall && (getProperty("machineModel") == "hds")) {
writeBlock(gFormat.format(27));
}
forceXYZ();
var abc = defineWorkPlane(currentSection, true);
if (getProperty("machineModel") != "hds") {
setCoolant(tool.coolant); // writes the required coolant codes
}
forceAny();
var initialPosition = getFramePosition(currentSection.getInitialPosition());
var isRequired = (getProperty("machineModel") == "hd2" || (getProperty("machineModel") == "hds" && tcp.isSupportedByOperation)) &&
(insertToolCall || !lengthCompensationActive || retracted || (!isFirstSection() && getPreviousSection().isMultiAxis()));
writeInitialPositioning(initialPosition, isRequired);
retracted = false;
}
function onDwell(seconds) {
if (seconds > 99999.999) {
warning(localize("Dwelling time is out of range."));
}
writeBlock("DWT=" + secFormat.format(seconds));
writeBlock(gFormat.format(4));
}
function onSpindleSpeed(spindleSpeed) {
writeBlock(sOutput.format(spindleSpeed));
}
function onCycle() {
writeBlock(gPlaneModal.format(17));
}
function getCommonCycle(r1, r2, z) {
forceXYZ(); // force xyz on first drill hole of any cycle
return ["R" + xyzFormat.format(r1), "R" + xyzFormat.format(r2), zOutput.format(z)];
}
function onCyclePoint(x, y, z) {
if (!isSameDirection(machineConfiguration.getSpindleAxis(), getForwardDirection(currentSection))) {
expandCyclePoint(x, y, z);
return;
}
var F = cycle.feedrate;
if (isFirstCyclePoint()) {
// return to initial Z which is clearance plane and set absolute mode
repositionToCycleClearance(cycle, x, y, z);
var P = !cycle.dwell ? 0 : clamp(0, cycle.dwell, 99999); // in seconds
switch (cycleType) {
/*
The G81 drilling cycles don't seem to work properly at the Bodgery. Here
we force those functions to the default case. This will cause the gcode
processor engine to "expand" the drilling cycle. That means it will generate
individual G0 and G1 commands along the Z axis to accomplish the necessary
pecking actions.
case "drilling":
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(81),
getCommonCycle(cycle.retract, cycle.clearance, z),
feedOutput.format(F)
);
break;
*/
case "counter-boring":
writeBlock(conditional(P > 0, "DWT=" + secFormat.format(P)));
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(82), conditional(P > 0, gFormat.format(4)),
getCommonCycle(cycle.retract, cycle.clearance, z),
feedOutput.format(F)
);
break;
/*
The G83 drilling cycles don't seem to work properly at the Bodgery. Here
we force those functions to the default case. This will cause the gcode
processor engine to "expand" the drilling cycle. That means it will generate
individual G0 and G1 commands along the Z axis to accomplish the necessary
pecking actions.
case "chip-breaking":
if (cycle.accumulatedDepth < cycle.depth) {
expandCyclePoint(x, y, z);
} else {
var isSimpleChipBreaking = cycle.chipBreakDistance == 0 && cycle.incrementalDepthReduction == 0;
var reductionFactor = (1 - (cycle.incrementalDepthReduction / cycle.incrementalDepth)); // factor
if (reductionFactor < 0 && !isSimpleChipBreaking) {
error(localize("Pecking depth reduction value exceeds the pecking depth."));
return;
}
writeBlock(conditional(P > 0, "DWT=" + secFormat.format(P)));
writeBlock(conditional(!isSimpleChipBreaking, "DRP=" + xyzFormat.format(cycle.chipBreakDistance)));
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(83), conditional(P > 0, gFormat.format(4)),
getCommonCycle(cycle.retract, cycle.clearance, z),
"I" + xyzFormat.format(cycle.incrementalDepth),
conditional(!isSimpleChipBreaking, "J" + xyzFormat.format(Math.min(cycle.minimumIncrementalDepth, cycle.incrementalDepth))), // make sure that J is below/ equal to I always
conditional(!isSimpleChipBreaking, "K" + xyzFormat.format(reductionFactor)),
feedOutput.format(F)
);
}
break;
case "deep-drilling":
var reductionFactor = (1 - (cycle.incrementalDepthReduction / cycle.incrementalDepth)); // factor
if (reductionFactor < 0) {
error(localize("Pecking depth reduction value exceeds the pecking depth."));
return;
}
writeBlock(conditional(P > 0, "DWT=" + secFormat.format(P)));
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(83), conditional(P > 0, gFormat.format(4)),
getCommonCycle(cycle.retract, cycle.clearance, z),
"I" + xyzFormat.format(cycle.incrementalDepth),
"J" + xyzFormat.format(Math.min(cycle.minimumIncrementalDepth, cycle.incrementalDepth)), // make sure that J is below/ equal to I always
"K" + xyzFormat.format(reductionFactor),
feedOutput.format(F)
);
break;
*/
case "tapping":
case "left-tapping":
case "right-tapping":
/*
We can't get a spindle speed nearly low enough for tapping at the Bodgery
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(84),
getCommonCycle(cycle.retract, cycle.clearance, z),
pitchOutput.format(tool.threadPitch)
);
*/
error(localize("Tapping is not supported."));
return;
break;
case "tapping-with-chip-breaking":
case "left-tapping-with-chip-breaking":
case "right-tapping-with-chip-breaking":
error(localize("Tapping with chip breaking is not supported."));
return;
case "fine-boring":
error(localize("Fine boring is not supported."));
return;
case "back-boring":
error(localize("Back boring is not supported."));
return;
case "reaming":
if (feedFormat.getResultingValue(cycle.feedrate) != feedFormat.getResultingValue(cycle.retractFeedrate)) {
expandCyclePoint(x, y, z);
break;
}
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(85),
getCommonCycle(cycle.retract, cycle.clearance, z),
feedOutput.format(F)
);
break;
case "stop-boring":
expandCyclePoint(x, y, z);
break;
case "boring":
if (feedFormat.getResultingValue(cycle.feedrate) != feedFormat.getResultingValue(cycle.retractFeedrate)) {
expandCyclePoint(x, y, z);
break;
}
writeBlock(conditional(P > 0, "DWT=" + secFormat.format(P)));
writeBlock(
gAbsIncModal.format(90), gCycleModal.format(89), conditional(P > 0, gFormat.format(4)),
getCommonCycle(cycle.retract, cycle.clearance, z),
feedOutput.format(F)
);
break;
default:
expandCyclePoint(x, y, z);
}
if (!cycleExpanded) {
switch (cycleType) {
case "tapping":
case "left-tapping":
case "right-tapping":
break;
default:
feedOutput.reset();
writeBlock(xOutput.format(x), yOutput.format(y), feedOutput.format(F));
break;
}
}
} else {
if (isProbeOperation()) {
// do nothing
} else if (cycleExpanded) {
expandCyclePoint(x, y, z);
} else {
switch (cycleType) {
case "tapping":
case "left-tapping":
case "right-tapping":
pitchOutput.reset();
F = pitchOutput.format(tool.threadPitch);
break;
default:
feedOutput.reset();
F = feedOutput.format(cycle.feedrate);
break;
}
writeBlock(xOutput.format(x), yOutput.format(y), F);
}
}
}
function onCycleEnd() {
if (!cycleExpanded) {
writeBlock(gCycleModal.format(80));
zOutput.reset();
}
}
function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation cannot be activated/deactivated for a circular move."));
return;
}
var start = getCurrentPosition();
var i = iOutput.format((getProperty("machineModel") != "hds") ? (cx - start.x) : (cx));
var j = jOutput.format((getProperty("machineModel") != "hds") ? (cy - start.y) : (cy));
var k = kOutput.format((getProperty("machineModel") != "hds") ? (cz - start.z) : (cz));
xOutput.reset();
yOutput.reset();
if (isFullCircle()) {
if (getProperty("useRadius") || isHelical()) { // radius mode does not support full arcs
linearize(tolerance);
return;
}
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), i, j, getFeed(feed));
break;
case PLANE_ZX:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), i, k, getFeed(feed));
break;
case PLANE_YZ:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), j, k, getFeed(feed));
break;
default:
linearize(tolerance);
}
} else if (!getProperty("useRadius")) {
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), i, j, getFeed(feed));
break;
case PLANE_ZX:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), i, k, getFeed(feed));
break;
case PLANE_YZ:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), j, k, getFeed(feed));
break;
default:
linearize(tolerance);
}
} else { // use radius mode
var r = getCircularRadius();
if (toDeg(getCircularSweep()) > (180 + 1e-9)) {
r = -r; // allow up to <360 deg arcs
}
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
break;
case PLANE_ZX:
writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
break;
case PLANE_YZ:
writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
break;
default:
linearize(tolerance);
}
}
}
var mapCommand = {
COMMAND_END : 2,
COMMAND_STOP_SPINDLE : 5,
COMMAND_ORIENTATE_SPINDLE: 19
};
function onCommand(command) {
switch (command) {
case COMMAND_COOLANT_OFF:
setCoolant(COOLANT_OFF);
return;
case COMMAND_COOLANT_ON:
if (getProperty("machineModel") != "hds") {
setCoolant(tool.coolant);
}
return;
case COMMAND_STOP:
writeBlock(mFormat.format(0));
forceSpindleSpeed = true;
forceCoolant = true;
return;
case COMMAND_OPTIONAL_STOP:
writeBlock(mFormat.format(1));
forceSpindleSpeed = true;
forceCoolant = true;
return;
case COMMAND_START_SPINDLE:
forceSpindleSpeed = false;
writeBlock(sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4));
writeBlock(conditional((getProperty("machineModel") == "hds"), "(DLY,5)"));
return;
case COMMAND_LOAD_TOOL:
writeBlock(getProperty("machineModel") == "hds" ? mFormat.format(48) : "");
if (getProperty("useToolCall")) {
writeToolBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
} else {
if (!isFirstSection()) {
onCommand(COMMAND_STOP);
writeToolBlock(formatComment("T" + toolFormat.format(tool.number), mFormat.format(6)));
}
}
writeComment(tool.comment);
return;
case COMMAND_LOCK_MULTI_AXIS:
return;
case COMMAND_UNLOCK_MULTI_AXIS:
return;
case COMMAND_START_CHIP_TRANSPORT:
return;
case COMMAND_STOP_CHIP_TRANSPORT:
return;
case COMMAND_BREAK_CONTROL:
return;
case COMMAND_TOOL_MEASURE:
return;
}
var stringId = getCommandStringId(command);
var mcode = mapCommand[stringId];
if (mcode != undefined) {
writeBlock(mFormat.format(mcode));
} else {
onUnsupportedCommand(command);
}
}
function onSectionEnd() {
writeBlock(gPlaneModal.format(17));
if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) {
setCoolant(COOLANT_OFF);
}
if (((getCurrentSectionId() + 1) >= getNumberOfSections()) ||
(tool.number != getNextSection().getTool().number)) {
onCommand(COMMAND_BREAK_CONTROL);
}
if (currentSection.isMultiAxis()) {
writeBlock(gFeedModeModal.format(94)); // inverse time feed off
}
forceAny();
}
function writeRetract() {
if (getProperty("machineModel") != "hds") {
retracted = true;
return;
}
var retract = getRetractParameters.apply(this, arguments);
if (retract && retract.words.length > 0) {
if (typeof gRotationModal != "undefined" && gRotationModal.getCurrent() == 68 && settings.retract.cancelRotationOnRetracting) { // cancel rotation before retracting
cancelWorkPlane(true);
}
gMotionModal.reset();
writeBlock(gFormat.format(79), retract.words);
}
}
// Start of onRewindMachine logic
/** Allow user to override the onRewind logic. */
function onRewindMachineEntry(_a, _b, _c) {
return false;
}
/** Retract to safe position before indexing rotaries. */
function onMoveToSafeRetractPosition() {
writeRetract(Z);
// cancel TCP so that tool doesn't follow rotaries
if (currentSection.isMultiAxis() && tcp.isSupportedByOperation) {
disableLengthCompensation(false, "TCPC OFF");
}
}
/** Rotate axes to new position above reentry position */
function onRotateAxes(_x, _y, _z, _a, _b, _c) {
// position rotary axes
xOutput.disable();
yOutput.disable();
zOutput.disable();
invokeOnRapid5D(_x, _y, _z, _a, _b, _c);
setCurrentABC(new Vector(_a, _b, _c));
xOutput.enable();
yOutput.enable();
zOutput.enable();
}
/** Return from safe position after indexing rotaries. */
function onReturnFromSafeRetractPosition(_x, _y, _z) {
// reinstate TCP / tool length compensation
if (!lengthCompensationActive && getOffsetCode() != undefined) {
if (getProperty("machineModel") == "hd2") {
writeBlock(getOffsetCode(), hFormat.format(tool.lengthOffset));
} else if (getProperty("machineModel") == "hds") {
writeBlock(getOffsetCode());
writeBlock(hFormat.format(tool.lengthOffset));
}
lengthCompensationActive = true;
}
// position in XY
forceXYZ();
xOutput.reset();
yOutput.reset();
zOutput.disable();
invokeOnRapid(_x, _y, _z);
// position in Z
zOutput.enable();
invokeOnRapid(_x, _y, _z);
}
// End of onRewindMachine logic
function getOffsetCode() {
var offsetCode = undefined;
if (getProperty("machineModel") == "hd2") {
var offsetCode = gFormat.format(43);
if (tcp.isSupportedByOperation) {
offsetCode = machineConfiguration.isMultiAxisConfiguration() ? 43.4 : 43.5;
}
} else if (getProperty("machineModel") == "hds") {
if (tcp.isSupportedByOperation && currentSection.isOptimizedForMachine()) {
offsetCode = "(TCP,5)";
}
}
return offsetCode;
}
function onClose() {
optionalSection = false;
writeln("");
onCommand(COMMAND_COOLANT_OFF);
writeRetract(Z);