Short Circuit Johnny 5 Build!

Project Overview:

We loved the movie Short Circuit as kids!  Like Johnny 5, we love input!  We also like disassembling things – something Johnny 5 would NOT agree with!

Follow along as we build a full-scale replica of Johnny 5!  We’re starting with the tracks and working our way up!  The combination of machined, laser cut and 3D printer parts, along with the various electromechanical, pneumatic and hydraulic parts should make this a challenging but fun build!

We’d like to thank the team at Input-Inc who have helped jumpstart this project through their years of hard work inspecting an original Johnny 5 to build a comprehensive CAD model that serves as the basis for our Johnny 5 build!

Johnny 5 Build Videos:

Downloads and CAD Models:

We are building a Johnny 5 replica to inspire, educate, and expose people of all ages to STEM topics like engineering, machining, automation, motor control and more!  Building a replica Johnny 5 is a great way to teach these techniques and skills – and continue what the NYC CNC YouTube channel has been doing since 2007: inspiring folks to learn about Machining, Arduino, CAD, CAM and more!

We will not be releasing the CAD files of Johnny 5 nor will we sell any parts or complete versions of Johnny 5.    NYC CNC and Saunders Machine Works, LLC make no claim to own Johnny 5 or any of the copyrights or trademarks related to it.  NYC CNC and Saunders Machine Works, LLC believe that the operation of this site falls under the definition of “fair use” under the United States copyright laws.   NYC CNC and Saunders Machine Works, LLC are in no way affiliated with or endorsed by the TriStar Pictures or its successors.  For more information on the Johnny 5 Build Project, please visit http://input-inc.com

Track Tensioner Block

Tension Washer & Tiptoe Flange

Modified Post Processor:

 

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
/**
Copyright (C) 2012-2018 by Autodesk, Inc.
All rights reserved.

Tormach PathPilot post processor configuration.

$Revision: 42071 de911d15ab16f0825ccc27d9b231204e8f76c27d $
$Date: 2018-08-09 10:29:50 $

FORKID {3CFDE807-BE2F-4A4C-B12A-03080F4B1285}
*/


description = "Tormach PathPilot";
vendor = "Tormach";
vendorUrl = "http://www.tormach.com";
legal = "Copyright (C) 2012-2018 by Autodesk, Inc.";
certificationLevel = 2;
minimumRevision = 40783;

longDescription = "Tormach PathPilot post for 3-axis and 4-axis milling with SmartCool support.";

extension = "nc";
setCodePage("ascii");

capabilities = CAPABILITY_MILLING;
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 = true;
allowedCircularPlanes = undefined; // allow any circular motion

// user-defined properties
properties = {
writeMachine: true, // write machine
writeTools: true, // writes the tools
writeVersion: false, // include version info
useG30: false, // disable to avoid G30 output
useG28: false, // move table to "load" position at end of program
useM6: true, // disable to avoid M6 output
showSequenceNumbers: false, // show sequence numbers
sequenceNumberStart: 10, // first sequence number
sequenceNumberIncrement: 10, // increment for sequence numbers
sequenceNumberOperation: true, // output sequence numbers at operation start only
optionalStopTool: true, // optional stop before tool change
optionalStopOperation: false, // optional stop between all operations
separateWordsWithSpace: true, // specifies that the words should be separated with a white space
useRadius: false, // specifies that arcs should be output using the radius (R word) instead of the I, J, and K words.
dwellInSeconds: true, // specifies the unit for dwelling: true:seconds and false:milliseconds.
forceWorkOffset: false, // forces the work offset code at tool changes
rotaryTableAxis: "X", // none, X, Y, Z, -X, -Y, -Z
smartCoolEquipped: false, // machine has smart coolant attachment
multiCoolEquipped: false, // machine has multi-coolant module
smartCoolToolSweepPercentage: 100, // tool length percentage to sweep coolant
multiCoolAirBlastSeconds: 4, // air blast time when equipped with Multi-Coolant module
disableCoolant: false, // disables all coolant codes
reversingHead: false, // uses self-reversing tapping head
reversingHeadFeed: 2.0 // percentage of tapping feed to retract the tool with reversing tapping head
};

// user-defined property definitions
propertyDefinitions = {
writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"},
writeTools: {title:"Write tool list", description:"Output a tool list in the header of the code.", group:0, type:"boolean"},
writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"},
useG30: {title:"Use G30", description:"Retract to clearance plane at tool change.", type:"boolean"},
useG28: {title:"Use G28", description:"Position table to load position at end of program.", type:"boolean"},
useM6: {title:"Use M6", description:"Disable to avoid outputting M6.", group:1, type:"boolean"},
showSequenceNumbers: {title:"Use sequence numbers", description:"Use sequence numbers for each block of outputted code.", group:1, type:"boolean"},
sequenceNumberStart: {title:"Start sequence number", description:"The number at which to start the sequence numbers.", group:1, type:"integer"},
sequenceNumberIncrement: {title:"Sequence number increment", description:"The amount by which the sequence number is incremented by in each block.", group:1, type:"integer"},
sequenceNumberOperation: {title:"Sequence number at operation only", description:"Use sequence numbers at start of operation only.", group:1, type:"boolean"},
optionalStopTool: {title:"Optional stop between tools", description:"Outputs optional stop code prior to a tool change.", type:"boolean"},
optionalStopOperation: {title:"Optional stop between operations", description:"Outputs optional stop code prior between all operations.", type:"boolean"},
separateWordsWithSpace: {title:"Separate words with space", description:"Adds spaces between words if 'yes' is selected.", type:"boolean"},
useRadius: {title:"Radius arcs", description:"If yes is selected, arcs are outputted using radius values rather than IJK.", type:"boolean"},
dwellInSeconds: {title:"Dwell in seconds", description:"Specifies the unit for dwelling, set to 'Yes' for seconds and 'No' for milliseconds.", type:"boolean"},
forceWorkOffset: {title:"Force work offset", description:"Forces the work offset code at tool changes.", type:"boolean"},
rotaryTableAxis: {
title: "Rotary table axis",
description: "Select rotary table axis. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.",
type: "enum",
values:[
{title:"No rotary", id:"none"},
{title:"X", id:"x"},
{title:"Y", id:"y"},
{title:"Z", id:"z"},
{title:"X (Reversed)", id:"-x"},
{title:"Y (Reversed)", id:"-y"},
{title:"Z (Reversed)", id:"-z"}
]
},
smartCoolEquipped: {title:"SmartCool equipped", description:"Specifies if the machine has the SmartCool attachment.", type:"boolean"},
multiCoolEquipped: {title:"Multi-Coolant equipped", description:"Specifies if the machine has the Multi-Coolant module.", type:"boolean"},
smartCoolToolSweepPercentage: {title:"SmartCool sweep percentage", description:"Sets the tool length percentage to sweep coolant.", type:"integer"},
multiCoolAirBlastSeconds: {title:"Multi-Coolant air blast in seconds", description:"Sets the Multi-Coolant air blast time in seconds.", type:"integer"},
disableCoolant: {title:"Disable coolant", description:"Disable all coolant codes.", type:"boolean"},
reversingHead: {title:"Use self-reversing tapping head", description:"Expanded cycles are output with a self-reversing tapping head.", type:"boolean"},
reversingHeadFeed: {title:"Self-reversing head feed ratio", description:"The percentage of the tapping feedrate for retracting the tool.", type:"number"}
};

var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,=_-*";

var nFormat = createFormat({prefix:"N", decimals:0});
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), forceDecimal:true});
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:4, forceDecimal:true});
var toolFormat = createFormat({decimals:0});
var rpmFormat = createFormat({decimals:0});
var coolantOptionFormat = createFormat({decimals:0});
var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999
var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999
var taperFormat = createFormat({decimals:1, scale:DEG});
var qFormat = createFormat({prefix:"Q", decimals:0});

var xOutput = createVariable({prefix:"X"}, xyzFormat);
var yOutput = createVariable({prefix:"Y"}, xyzFormat);
var zOutput = createVariable({onchange:function () {retracted = false;}, prefix:"Z"}, xyzFormat);
var aOutput = createVariable({prefix:"A"}, abcFormat);
var bOutput = createVariable({prefix:"B"}, abcFormat);
var cOutput = createVariable({prefix:"C"}, abcFormat);
var feedOutput = createVariable({prefix:"F"}, feedFormat);
var inverseTimeOutput = createVariable({prefix:"F", force:true}, inverseTimeFormat);
var sOutput = createVariable({prefix:"S", force:true}, rpmFormat);
var dOutput = createVariable({}, dFormat);

// circular output
var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat);
var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat);
var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat);

var gMotionModal = createModal({force:true}, 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
var gCycleModal = createModal({force:false}, gFormat); // modal group 9 // G81, ...
var gRetractModal = createModal({force:true}, gFormat); // modal group 10 // G98-99

var WARNING_WORK_OFFSET = 0;

// collected state
var sequenceNumber;
var currentWorkOffset;
var previousCoolantMode;
var coolantZHeight;
var masterAxis;
var movementType;
var retracted = false; // specifies that the tool has been retracted to the safe plane

function formatSequenceNumber() {
if (sequenceNumber > 99999) {
sequenceNumber = properties.sequenceNumberStart;
}
var seqno = nFormat.format(sequenceNumber);
sequenceNumber += properties.sequenceNumberIncrement;
return seqno;
}

/**
Writes the specified block.
*/

function writeBlock() {
if (!formatWords(arguments)) {
return;
}
if (properties.showSequenceNumbers) {
writeWords2(formatSequenceNumber(), arguments);
sequenceNumber += properties.sequenceNumberIncrement;
} else {
writeWords(arguments);
}
}

function formatComment(text) {
return("(" + filterText(String(text), permittedCommentChars) + ")");
}

/**
Output a comment.
*/

function writeComment(text) {
writeln(formatComment(text));
}

function writeCommentSeqno(text) {
writeln(formatSequenceNumber() + formatComment(text));
}

/**
Compare a text string to acceptable choices.

Returns -1 if there is no match.
*/

function parseChoice() {
for (var i = 1; i < arguments.length; ++i) {
if (String(arguments[0]).toUpperCase() == String(arguments[i]).toUpperCase()) {
return i - 1;
}
}
return -1;
}

function onOpen() {
if (properties.useRadius) {
maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC
}
if (properties.sequenceNumberOperation) {
properties.showSequenceNumbers = false;
}

// Define rotary attributes from properties
var rotary = parseChoice(properties.rotaryTableAxis, "-Z", "-Y", "-X", "NONE", "X", "Y", "Z");
if (rotary < 0) { error(localize("Valid rotaryTableAxis values are: None, X, Y, Z, -X, -Y, -Z")); return; } rotary -= 3; // Define Master (carrier) axis masterAxis = Math.abs(rotary) - 1; if (masterAxis >= 0) {
var rotaryVector = [0, 0, 0];
rotaryVector[masterAxis] = rotary/Math.abs(rotary);
var aAxis = createAxis({coordinate:0, table:true, axis:rotaryVector, cyclic:true, preference:0});
machineConfiguration = new MachineConfiguration(aAxis);

setMachineConfiguration(machineConfiguration);
// Single rotary does not use TCP mode
optimizeMachineAngles2(1); // 0 = TCP Mode ON, 1 = TCP Mode OFF
}

if (!machineConfiguration.isMachineCoordinate(0)) {
aOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(1)) {
bOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(2)) {
cOutput.disable();
}

if (!properties.separateWordsWithSpace) {
setWordSeparator("");
}

sequenceNumber = properties.sequenceNumberStart;

writeln("%");
if (programName) {
writeComment(programName);
}
if (programComment) {
writeComment(programComment);
}

if (properties.writeVersion) {
if (typeof getHeaderVersion == "function" && getHeaderVersion()) {
writeComment(localize("post version") + ": " + getHeaderVersion());
}
if (typeof getHeaderDate == "function" && getHeaderDate()) {
writeComment(localize("post modified") + ": " + getHeaderDate());
}
}

// dump machine configuration
var vendor = machineConfiguration.getVendor();
var model = machineConfiguration.getModel();
var description = machineConfiguration.getDescription();

if (properties.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 (properties.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);
}
}
}

if (false) {
// check for duplicate tool number
for (var i = 0; i < getNumberOfSections(); ++i) {
var sectioni = getSection(i);
var tooli = sectioni.getTool();
for (var j = i + 1; j < getNumberOfSections(); ++j) { var sectionj = getSection(j); var toolj = sectionj.getTool(); if (tooli.number == toolj.number) { if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || (tooli.numberOfFlutes != toolj.numberOfFlutes)) { error( subst( localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) ) ); return; } } } } } 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), gFormat.format(54), gFormat.format(64), gFormat.format(50), gPlaneModal.format(17), gFormat.format(40), gFormat.format(80), gFeedModeModal.format(94), gFormat.format(91.1), gFormat.format(49));

switch (unit) {
case IN:
writeBlock(gUnitModal.format(20), formatComment(localize("Inch")));
break;
case MM:
writeBlock(gUnitModal.format(21), formatComment(localize("Metric")));
break;
}
}

function onParameter(name, value) {
if (name == "display") {
writeComment("MSG, " + value);
}
}

function onComment(message) {
var comments = String(message).split(";");
for (comment in comments) {
writeComment(comments[comment]);
}
}

/** 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();
previousDPMFeed = 0;
feedOutput.reset();
}

var currentWorkPlaneABC = undefined;

function forceWorkPlane() {
currentWorkPlaneABC = undefined;
}

function setWorkPlane(abc) {
if (!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);

// NOTE: add retract here

writeBlock(
gMotionModal.format(0),
conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)),
conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)),
conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z))
);

onCommand(COMMAND_LOCK_MULTI_AXIS);

currentWorkPlaneABC = abc;
}

var closestABC = true; // choose closest machine angles
var currentMachineABC;

function getWorkPlaneMachineABC(workPlane) {
var W = workPlane; // map to global frame

var abc = machineConfiguration.getABC(W);
if (closestABC) {
if (currentMachineABC) {
abc = machineConfiguration.remapToABC(abc, currentMachineABC);
} else {
abc = machineConfiguration.getPreferredABC(abc);
}
} else {
abc = machineConfiguration.getPreferredABC(abc);
}

try {
abc = machineConfiguration.remapABC(abc);
currentMachineABC = abc;
} catch (e) {
error(
localize("Machine angles not supported") + ":"
+ conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
+ conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
+ conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
);
}

var direction = machineConfiguration.getDirection(abc);
if (!isSameDirection(direction, W.forward)) {
error(localize("Orientation not supported."));
}

if (!machineConfiguration.isABCSupported(abc)) {
error(
localize("Work plane is not supported") + ":"
+ conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
+ conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
+ conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
);
}

var tcp = false;
cancelTransformation();
if (tcp) {
setRotation(W); // TCP mode
} else {
var O = machineConfiguration.getOrientation(abc);
var R = machineConfiguration.getRemainingOrientation(abc, W);
var rotate = true;
var axis = machineConfiguration.getAxisU();
if (axis.isEnabled() && axis.isTable()) {
var ix = axis.getCoordinate();
var rotAxis = axis.getAxis();
if (isSameDirection(machineConfiguration.getDirection(abc), rotAxis) ||
isSameDirection(machineConfiguration.getDirection(abc), Vector.product(rotAxis, -1))) {
var direction = isSameDirection(machineConfiguration.getDirection(abc), rotAxis) ? 1 : -1;
abc.setCoordinate(ix, Math.atan2(R.right.y, R.right.x) * direction);
rotate = false;
}
}
if (rotate) {
setRotation(R);
}
}
return abc;
}

function onSection() {
var insertToolCall = isFirstSection() ||
currentSection.getForceToolChange && currentSection.getForceToolChange() ||
(tool.number != getPreviousSection().getTool().number);

retracted = false; // specifies that the tool has been retracted to the safe plane
var newWorkOffset = isFirstSection() ||
(getPreviousSection().workOffset != currentSection.workOffset); // work offset changes
var newWorkPlane = isFirstSection() ||
!isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) ||
(currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() &&
Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) ||
(!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) ||
(!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() ||
getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations
if (insertToolCall || newWorkOffset || newWorkPlane) {
writeRetract(Z);
forceWorkPlane();
}
writeln("");

if (hasParameter("operation-comment")) {
var comment = getParameter("operation-comment");
if (comment) {
if (properties.sequenceNumberOperation) {
writeCommentSeqno(comment);
} else {
writeComment(comment);
}
}
}

// optional stop
if (!isFirstSection() && ((insertToolCall && properties.optionalStopTool) || properties.optionalStopOperation)) {
onCommand(COMMAND_OPTIONAL_STOP);
}

if (insertToolCall) {
forceWorkPlane();
// onCommand(COMMAND_COOLANT_OFF);

if (tool.number > 256) {
warning(localize("Tool number exceeds maximum value."));
}

var lengthOffset = tool.lengthOffset;
if (lengthOffset > 256) {
error(localize("Length offset out of range."));
return;
}

if (properties.useM6) {
writeBlock("T" + toolFormat.format(tool.number),
gFormat.format(43),
hFormat.format(lengthOffset),
mFormat.format(6));
} else {
writeBlock("T" + toolFormat.format(tool.number), gFormat.format(43), hFormat.format(lengthOffset));
}

if (tool.comment) {
writeComment(tool.comment);
}
var showToolZMin = false;
if (showToolZMin) {
if (is3D()) {
var numberOfSections = getNumberOfSections();
var zRange = currentSection.getGlobalZRange();
var number = tool.number;
for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) {
var section = getSection(i);
if (section.getTool().number != number) {
break;
}
zRange.expandToRange(section.getGlobalZRange());
}
writeComment(localize("ZMIN") + "=" + zRange.getMinimum());
}
}
}

// Define coolant code
var topOfPart = undefined;
if (hasParameter("operation:surfaceZHigh")) {
topOfPart = getParameter("operation:surfaceZHigh"); // TAG: not safe
}
var c = setCoolant(tool.coolant, topOfPart);

if (true ||
insertToolCall ||
isFirstSection() ||
(rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) ||
(tool.clockwise != getPreviousSection().getTool().clockwise)) {
if (spindleSpeed < 0) { error(localize("Spindle speed out of range.")); return; } if (spindleSpeed > 99999) {
warning(localize("Spindle speed exceeds maximum value."));
}
if (spindleSpeed == 0) {
writeBlock(mFormat.format(5), c[0], c[1], c[2], c[3], formatComment("SPINDLE IS OFF"));
} else {
writeBlock(
sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4),
c[0], c[1], c[2], c[3]
);
if ((spindleSpeed > 5000) && properties.waitForSpindle) {
onDwell(properties.waitForSpindle);
}
}
}

// wcs
if (insertToolCall && properties.forceWorkOffset) { // 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 > 0) {
if (workOffset > 6) {
var p = workOffset; // 1->... // G59 P1 is the same as G54 and so on
if (p > 9) {
error(localize("Work offset out of range."));
} else {
if (workOffset != currentWorkOffset) {
p = 59 + ((p - 6)/10.0);
writeBlock(gFormat.format(p)); // G59.x
currentWorkOffset = workOffset;
}
}
} else {
if (workOffset != currentWorkOffset) {
writeBlock(gFormat.format(53 + workOffset)); // G54->G59
currentWorkOffset = workOffset;
}
}
}

forceXYZ();

if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode
// set working plane after datum shift

var abc = new Vector(0, 0, 0);
if (currentSection.isMultiAxis()) {
forceWorkPlane();
cancelTransformation();
} else {
abc = getWorkPlaneMachineABC(currentSection.workPlane);
}
setWorkPlane(abc);
} else { // pure 3D
var remaining = currentSection.workPlane;
if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) {
error(localize("Tool orientation is not supported."));
return;
}
setRotation(remaining);
}

forceAny();
gMotionModal.reset();

var initialPosition = getFramePosition(currentSection.getInitialPosition());
if (!retracted && !insertToolCall) {
if (getCurrentPosition().z < initialPosition.z) { writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); } } if (!insertToolCall && retracted) { // G43 already called above on tool change var lengthOffset = tool.lengthOffset; if (lengthOffset > 256) {
error(localize("Length offset out of range."));
return;
}

gMotionModal.reset();
writeBlock(gPlaneModal.format(17));

if (!machineConfiguration.isHeadConfiguration()) {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y)
);
writeBlock(gMotionModal.format(0), gFormat.format(43), zOutput.format(initialPosition.z), hFormat.format(lengthOffset));
} else {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
gFormat.format(43), xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y),
zOutput.format(initialPosition.z), hFormat.format(lengthOffset)
);
}
} else {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y)
);
}
}

// allow manual insertion of comma delimited g-code
function onPassThrough(text) {
var commands = String(text).split(",");
for (text in commands) {
writeBlock(commands[text]);
}
}

function onDwell(seconds) {
if (seconds > 99999.999) {
warning(localize("Dwelling time is out of range."));
}
if (properties.dwellInSeconds) {
writeBlock(gFormat.format(4), "P" + secFormat.format(seconds));
} else {
milliseconds = clamp(1, seconds * 1000, 99999999);
writeBlock(gFormat.format(4), "P" + milliFormat.format(milliseconds));
}
}

function onSpindleSpeed(spindleSpeed) {
writeBlock(sOutput.format(spindleSpeed));
}

function setCoolant(coolant, topOfPart) {
var coolCodes = ["", "", "", ""];
coolantZHeight = 9999.0;

if (properties.disableCoolant) {
return coolCodes;
}
// Smart coolant is not enabled
if (!properties.smartCoolEquipped) {
if (coolant == COOLANT_OFF) {
previousCoolantMode = 9;
} else {
previousCoolantMode = 8; // default all coolant modes to flood
if (coolant != COOLANT_FLOOD) {
warning(localize("Unsupported coolant setting. Defaulting to FLOOD."));
}
}
coolCodes[0] = mFormat.format(previousCoolantMode);
} else { // Smart coolant is enabled
if ((coolant == COOLANT_MIST) || (coolant == COOLANT_AIR)) {
previousCoolantMode = 7;
coolCodes[0] = mFormat.format(previousCoolantMode);
} else if (coolant == COOLANT_FLOOD_MIST) { // flood with air blast
previousCoolantMode = 8;
if (properties.multiCoolEquipped) {
if (properties.multiCoolAirBlastSeconds != 0) {
coolCodes[3] = qFormat.format(properties.multiCoolAirBlastSeconds);
}
} else {
warning(localize("COOLANT_FLOOD_MIST programmed without Multi-Coolant support. Defaulting to FLOOD."));
}
} else if (coolant == COOLANT_OFF) {
previousCoolantMode = 9;
coolCodes[0] = mFormat.format(previousCoolantMode);
} else {
previousCoolantMode = 8;
coolCodes[0] = mFormat.format(previousCoolantMode);
if (coolant != COOLANT_FLOOD) {
warning(localize("Unsupported coolant setting. Defaulting to FLOOD."));
}
}

// Determine Smart Coolant location based on machining operation
if (hasParameter("operation-strategy")) {
var strategy = getParameter("operation-strategy");
if (strategy) {

// Drilling strategy. Keep coolant at top of part
if (strategy == "drill") {
if (topOfPart != undefined) {
coolantZHeight = topOfPart;
coolCodes[1] = "E" + xyzFormat.format(coolantZHeight);
}

// Tool end point milling. Keep coolant at end of tool
} else if ((strategy == "face") ||
(strategy == "engrave") ||
(strategy == "contour_new") ||
(strategy == "horizontal_new") ||
(strategy == "parallel_new") ||
(strategy == "scallop_new") ||
(strategy == "pencil_new") ||
(strategy == "radial_new") ||
(strategy == "spiral_new") ||
(strategy == "morphed_spiral") ||
(strategy == "ramp") ||
(strategy == "project")) {
coolCodes[1] = "P" + coolantOptionFormat.format(0);

// Side Milling. Sweep the coolant along the length of the tool
} else {
coolCodes[1] = "P" + coolantOptionFormat.format(0);
coolCodes[2] = "R" + xyzFormat.format(tool.fluteLength * (properties.smartCoolToolSweepPercentage/100.0));
}
}
}
}

return coolCodes;
}

function onCycle() {
writeBlock(gPlaneModal.format(17));
}

function getCommonCycle(x, y, z, r) {
forceXYZ();
return [xOutput.format(x), yOutput.format(y),
zOutput.format(z),
"R" + xyzFormat.format(r)];
}

function expandTappingPoint(x, y, z) {
onRapid(x, y, cycle.clearance);
onLinear(x, y, z, cycle.feedrate);
onLinear(x, y, cycle.clearance, cycle.feedrate * properties.reversingHeadFeed);
}

function onCyclePoint(x, y, z) {
if (isFirstCyclePoint()) {
repositionToCycleClearance(cycle, x, y, z);

// return to initial Z which is clearance plane and set absolute mode

var F = cycle.feedrate;
var P = !cycle.dwell ? 0 : cycle.dwell; // in seconds

// Adjust SmartCool to top of part if it changes
if (properties.smartCoolEquipped && xyzFormat.areDifferent((z + cycle.depth), coolantZHeight)) {
var c = setCoolant(previousCoolantMode, z + cycle.depth);
if (c) {
writeBlock(c[0], c[1], c[2]);
}
}

switch (cycleType) {
case "drilling":
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81),
getCommonCycle(x, y, z, cycle.retract),
feedOutput.format(F)
);
break;
case "counter-boring":
if (P > 0) {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
feedOutput.format(F)
);
} else {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81),
getCommonCycle(x, y, z, cycle.retract),
feedOutput.format(F)
);
}
break;
case "chip-breaking":
if ((P > 0) || (cycle.accumulatedDepth < cycle.depth)) { expandCyclePoint(x, y, z); } else { writeBlock( gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(73), getCommonCycle(x, y, z, cycle.retract), "Q" + xyzFormat.format(cycle.incrementalDepth), feedOutput.format(F) ); } break; case "deep-drilling": writeBlock( gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), getCommonCycle(x, y, z, cycle.retract), "Q" + xyzFormat.format(cycle.incrementalDepth), // conditional(P > 0, "P" + secFormat.format(P)),
feedOutput.format(F)
);
break;
case "tapping":
if (properties.reversingHead) {
expandTappingPoint(x, y, z);
} else {
if (!F) {
F = tool.getTappingFeedrate();
}
writeBlock(sOutput.format(spindleSpeed));
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84),
getCommonCycle(x, y, z, cycle.retract),
conditional(P > 0, "P" + secFormat.format(P)),
feedOutput.format(F)
);
}
break;
case "left-tapping":
if (properties.reversingHead) {
expandTappingPoint(x, y, z);
} else {
if (!F) {
F = tool.getTappingFeedrate();
}
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84),
getCommonCycle(x, y, z, cycle.retract),
conditional(P > 0, "P" + secFormat.format(P)),
feedOutput.format(F)
);
}
break;
case "right-tapping":
if (properties.reversingHead) {
expandTappingPoint(x, y, z);
} else {
if (!F) {
F = tool.getTappingFeedrate();
}
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84),
getCommonCycle(x, y, z, cycle.retract),
conditional(P > 0, "P" + secFormat.format(P)),
feedOutput.format(F)
);
}
break;
case "fine-boring":
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(76),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
"Q" + xyzFormat.format(cycle.shift),
feedOutput.format(F)
);
break;
case "back-boring":
var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0;
var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0;
var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0;
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87),
getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom),
"I" + xyzFormat.format(cycle.shift),
"J" + xyzFormat.format(0),
"P" + secFormat.format(P),
feedOutput.format(F)
);
break;
case "reaming":
if (P > 0) {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
feedOutput.format(F)
);
} else {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85),
getCommonCycle(x, y, z, cycle.retract),
feedOutput.format(F)
);
}
break;
case "stop-boring":
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
feedOutput.format(F)
);
break;
case "manual-boring":
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
feedOutput.format(F)
);
break;
case "boring":
if (P > 0) {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89),
getCommonCycle(x, y, z, cycle.retract),
"P" + secFormat.format(P),
feedOutput.format(F)
);
} else {
writeBlock(
gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85),
getCommonCycle(x, y, z, cycle.retract),
feedOutput.format(F)
);
}
break;
default:
expandCyclePoint(x, y, z);
}
} else {
if (cycleExpanded) {
expandCyclePoint(x, y, z);
} else if (((cycleType == "tapping") || (cycleType == "right-tapping") || (cycleType == "left-tapping")) && properties.reversingHead) {
expandTappingPoint(x, y, z);
} else {
writeBlock(xOutput.format(x), yOutput.format(y));
}
}
}

function onCycleEnd() {
if (!cycleExpanded) {
writeBlock(gCycleModal.format(80));
zOutput.reset();
}
}

var pendingRadiusCompensation = -1;

function onRadiusCompensation() {
pendingRadiusCompensation = radiusCompensation;
}

function onMovement(movement) {
movementType = movement;
}

function onRapid(_x, _y, _z) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
if (x || y || z) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation mode cannot be changed at rapid traversal."));
return;
}
writeBlock(gMotionModal.format(0), x, y, z);
feedOutput.reset();
}
}

function onLinear(_x, _y, _z, feed) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var f = feedOutput.format(feed);
if (x || y || z) {
if (pendingRadiusCompensation >= 0) {
pendingRadiusCompensation = -1;
var d = tool.diameterOffset;
if (d > 256) {
warning(localize("The diameter offset exceeds the maximum value."));
}
writeBlock(gPlaneModal.format(17));
switch (radiusCompensation) {
case RADIUS_COMPENSATION_LEFT:
dOutput.reset();
writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f);
// error(localize("Radius compensation mode is not supported by the CNC control."));
break;
case RADIUS_COMPENSATION_RIGHT:
dOutput.reset();
writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f);
// error(localize("Radius compensation mode is not supported by the CNC control."));
break;
default:
writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), gFormat.format(40), x, y, z, f);
}
} else {
writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, f);
}
} else if (f) {
if (getNextRecord().isMotion()) { // try not to output feed without motion
feedOutput.reset(); // force feed on next line
} else {
writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), f);
}
}
}

function onRapid5D(_x, _y, _z, _a, _b, _c) {
if (!currentSection.isOptimizedForMachine()) {
error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath."));
return;
}
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation mode cannot be changed at rapid traversal."));
return;
}
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = aOutput.format(_a);
var b = bOutput.format(_b);
var c = cOutput.format(_c);
writeBlock(gMotionModal.format(0), x, y, z, a, b, c);
feedOutput.reset();
}

function onLinear5D(_x, _y, _z, _a, _b, _c, feed) {
if (!currentSection.isOptimizedForMachine()) {
error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath."));
return;
}
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation cannot be activated/deactivated for 5-axis move."));
return;
}
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = aOutput.format(_a);
var b = bOutput.format(_b);
var c = cOutput.format(_c);

// get feedrate number
var f = {frn:0, fmode:0};
if (a || b || c) {
f = getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed);
f.frn = inverseTimeOutput.format(f.frn);
} else {
f.frn = feedOutput.format(feed);
f.fmode = 94;
}

if (x || y || z || a || b || c) {
writeBlock(gFeedModeModal.format(f.fmode), gMotionModal.format(1), x, y, z, a, b, c, f.frn);
} else if (f.frn) {
if (getNextRecord().isMotion()) { // try not to output feed without motion
feedOutput.reset(); // force feed on next line
} else {
writeBlock(gFeedModeModal.format(f.fmode), gMotionModal.format(1), f.frn);
}
}
}

// Start of multi-axis feedrate logic
/***** Be sure to add 'useInverseTime' to post properties if necessary. *****/
/***** 'inverseTimeOutput' should be defined if Inverse Time feedrates are supported. *****/
/***** 'previousABC' can be added throughout to maintain previous rotary positions. Required for Mill/Turn machines. *****/
/***** 'headOffset' should be defined when a head rotary axis is defined. *****/
/***** The feedrate mode must be included in motion block output (linear, circular, etc.) for Inverse Time feedrate support. *****/
var dpmBPW = 0.1; // ratio of rotary accuracy to linear accuracy for DPM calculations
var inverseTimeUnits = 1.0; // 1.0 = minutes, 60.0 = seconds
var maxInverseTime = 99999.9999; // maximum value to output for Inverse Time feeds
var maxDPM = 9999.99; // maximum value to output for DPM feeds
var useInverseTimeFeed = true; // use 1/T feeds
var previousDPMFeed = 0; // previously output DPM feed
var dpmFeedToler = 0.5; // tolerance to determine when the DPM feed has changed
// var previousABC = new Vector(0, 0, 0); // previous ABC position if maintained in post, don't define if not used
var forceOptimized = undefined; // used to override optimized-for-angles points (XZC-mode)

/** Calculate the multi-axis feedrate number. */
function getMultiaxisFeed(_x, _y, _z, _a, _b, _c, feed) {
var f = {frn:0, fmode:0};
if (feed <= 0) {
error(localize("Feedrate is less than or equal to 0."));
return f;
}

var length = getMoveLength(_x, _y, _z, _a, _b, _c);

if (useInverseTimeFeed) { // inverse time
f.frn = getInverseTime(length.tool, feed);
f.fmode = 93;
feedOutput.reset();
} else { // degrees per minute
f.frn = getFeedDPM(length, feed);
f.fmode = 94;
}
return f;
}

/** Returns point optimization mode. */
function getOptimizedMode() {
if (forceOptimized != undefined) {
return forceOptimized;
}
// return (currentSection.getOptimizedTCPMode() != 0); // TAG:doesn't return correct value
return true; // always return false for non-TCP based heads
}

/** Calculate the DPM feedrate number. */
function getFeedDPM(_moveLength, _feed) {
if ((_feed == 0) || (_moveLength.tool < 0.0001) || (toDeg(_moveLength.abcLength) < 0.0005)) {
previousDPMFeed = 0;
return _feed;
}
var moveTime = _moveLength.tool / _feed;
if (moveTime == 0) {
previousDPMFeed = 0;
return _feed;
}

var dpmFeed;
var tcp = false; // !getOptimizedMode() && (forceOptimized == undefined); // set to false for rotary heads
if (tcp) { // TCP mode is supported, output feed as FPM
dpmFeed = _feed;
} else if (false) { // standard DPM
dpmFeed = Math.min(toDeg(_moveLength.abcLength) / moveTime, maxDPM);
if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) {
dpmFeed = previousDPMFeed;
}
} else if (true) { // combination FPM/DPM
var length = Math.sqrt(Math.pow(_moveLength.xyzLength, 2.0) + Math.pow((toDeg(_moveLength.abcLength) * dpmBPW), 2.0));
dpmFeed = Math.min((length / moveTime), maxDPM);
if (Math.abs(dpmFeed - previousDPMFeed) < dpmFeedToler) {
dpmFeed = previousDPMFeed;
}
} else { // machine specific calculation
dpmFeed = _feed;
}
previousDPMFeed = dpmFeed;
return dpmFeed;
}

/** Calculate the Inverse time feedrate number. */
function getInverseTime(_length, _feed) {
var inverseTime;
if (_length < 1.e-6) { // tool doesn't move if (typeof maxInverseTime === "number") { inverseTime = maxInverseTime; } else { inverseTime = 999999; } } else { inverseTime = _feed / _length / inverseTimeUnits; if (typeof maxInverseTime === "number") { if (inverseTime > maxInverseTime) {
inverseTime = maxInverseTime;
}
}
}
return inverseTime;
}

/** Calculate radius for each rotary axis. */
function getRotaryRadii(startTool, endTool, startABC, endABC) {
var radii = new Vector(0, 0, 0);
var startRadius;
var endRadius;
var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW());
for (var i = 0; i < 3; ++i) { if (axis[i].isEnabled()) { var startRadius = getRotaryRadius(axis[i], startTool, startABC); var endRadius = getRotaryRadius(axis[i], endTool, endABC); radii.setCoordinate(axis[i].getCoordinate(), Math.max(startRadius, endRadius)); } } return radii; } /** Calculate the distance of the tool position to the center of a rotary axis. */ function getRotaryRadius(axis, toolPosition, abc) { if (!axis.isEnabled()) { return 0; } var direction = axis.getEffectiveAxis(); var normal = direction.getNormalized(); // calculate the rotary center based on head/table var center; var radius; if (axis.isHead()) { var pivot; if (typeof headOffset === "number") { pivot = headOffset; } else { pivot = tool.getBodyLength(); } if (axis.getCoordinate() == machineConfiguration.getAxisU().getCoordinate()) { // rider center = Vector.sum(toolPosition, Vector.product(machineConfiguration.getDirection(abc), pivot)); center = Vector.sum(center, axis.getOffset()); radius = Vector.diff(toolPosition, center).length; } else { // carrier var angle = abc.getCoordinate(machineConfiguration.getAxisU().getCoordinate()); radius = Math.abs(pivot * Math.sin(angle)); radius += axis.getOffset().length; } } else { center = axis.getOffset(); var d1 = toolPosition.x - center.x; var d2 = toolPosition.y - center.y; var d3 = toolPosition.z - center.z; var radius = Math.sqrt( Math.pow((d1 * normal.y) - (d2 * normal.x), 2.0) + Math.pow((d2 * normal.z) - (d3 * normal.y), 2.0) + Math.pow((d3 * normal.x) - (d1 * normal.z), 2.0) ); } return radius; } /** Calculate the linear distance based on the rotation of a rotary axis. */ function getRadialDistance(radius, startABC, endABC) { // calculate length of radial move var delta = Math.abs(endABC - startABC); if (delta > Math.PI) {
delta = 2 * Math.PI - delta;
}
var radialLength = (2 * Math.PI * radius) * (delta / (2 * Math.PI));
return radialLength;
}

/** Calculate tooltip, XYZ, and rotary move lengths. */
function getMoveLength(_x, _y, _z, _a, _b, _c) {
// get starting and ending positions
var moveLength = {};
var startTool;
var endTool;
var startXYZ;
var endXYZ;
var startABC;
if (typeof previousABC !== "undefined") {
startABC = new Vector(previousABC.x, previousABC.y, previousABC.z);
} else {
startABC = getCurrentDirection();
}
var endABC = new Vector(_a, _b, _c);

if (!getOptimizedMode()) { // calculate XYZ from tool tip
startTool = getCurrentPosition();
endTool = new Vector(_x, _y, _z);
startXYZ = startTool;
endXYZ = endTool;

// adjust points for tables
if (!machineConfiguration.getTableABC(startABC).isZero() || !machineConfiguration.getTableABC(endABC).isZero()) {
startXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).getTransposed().multiply(startXYZ);
endXYZ = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).getTransposed().multiply(endXYZ);
}

// adjust points for heads
if (machineConfiguration.getAxisU().isEnabled() && machineConfiguration.getAxisU().isHead()) {
if (typeof getOptimizedHeads === "function") { // use post processor function to adjust heads
startXYZ = getOptimizedHeads(startXYZ.x, startXYZ.y, startXYZ.z, startABC.x, startABC.y, startABC.z);
endXYZ = getOptimizedHeads(endXYZ.x, endXYZ.y, endXYZ.z, endABC.x, endABC.y, endABC.z);
} else { // guess at head adjustments
var startDisplacement = machineConfiguration.getDirection(startABC);
startDisplacement.multiply(headOffset);
var endDisplacement = machineConfiguration.getDirection(endABC);
endDisplacement.multiply(headOffset);
startXYZ = Vector.sum(startTool, startDisplacement);
endXYZ = Vector.sum(endTool, endDisplacement);
}
}
} else { // calculate tool tip from XYZ, heads are always programmed in TCP mode, so not handled here
startXYZ = getCurrentPosition();
endXYZ = new Vector(_x, _y, _z);
startTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(startABC)).multiply(startXYZ);
endTool = machineConfiguration.getOrientation(machineConfiguration.getTableABC(endABC)).multiply(endXYZ);
}

// calculate axes movements
moveLength.xyz = Vector.diff(endXYZ, startXYZ).abs;
moveLength.xyzLength = moveLength.xyz.length;
moveLength.abc = Vector.diff(endABC, startABC).abs;
for (var i = 0; i < 3; ++i) { if (moveLength.abc.getCoordinate(i) > Math.PI) {
moveLength.abc.setCoordinate(i, 2 * Math.PI - moveLength.abc.getCoordinate(i));
}
}
moveLength.abcLength = moveLength.abc.length;

// calculate radii
moveLength.radius = getRotaryRadii(startTool, endTool, startABC, endABC);

// calculate the radial portion of the tool tip movement
var radialLength = Math.sqrt(
Math.pow(getRadialDistance(moveLength.radius.x, startABC.x, endABC.x), 2.0) +
Math.pow(getRadialDistance(moveLength.radius.y, startABC.y, endABC.y), 2.0) +
Math.pow(getRadialDistance(moveLength.radius.z, startABC.z, endABC.z), 2.0)
);

// calculate the tool tip move length
// tool tip distance is the move distance based on a combination of linear and rotary axes movement
moveLength.tool = moveLength.xyzLength + radialLength;

// debug
if (false) {
writeComment("DEBUG - tool = " + moveLength.tool);
writeComment("DEBUG - xyz = " + moveLength.xyz);
var temp = Vector.product(moveLength.abc, 180/Math.PI);
writeComment("DEBUG - abc = " + temp);
writeComment("DEBUG - radius = " + moveLength.radius);
}
return moveLength;
}
// End of multi-axis feedrate logic

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;
}

// controller does not handle transition between planes well
if (((movementType == MOVEMENT_LEAD_IN) ||
(movementType == MOVEMENT_LEAD_OUT)||
(movementType == MOVEMENT_RAMP) ||
(movementType == MOVEMENT_PLUNGE) ||
(movementType == MOVEMENT_RAMP_HELIX) ||
(movementType == MOVEMENT_RAMP_PROFILE) ||
(movementType == MOVEMENT_RAMP_ZIG_ZAG)) &&
(getCircularPlane() != PLANE_XY)) {
linearize(tolerance);
return;
}

var start = getCurrentPosition();

if (isFullCircle()) {
if (properties.useRadius || isHelical()) { // radius mode does not support full arcs
linearize(tolerance);
return;
}
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed));
break;
case PLANE_ZX:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed));
break;
case PLANE_YZ:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed));
break;
default:
linearize(tolerance);
}
} else if (!properties.useRadius) {
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed));
break;
case PLANE_ZX:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed));
break;
case PLANE_YZ:
writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), feedOutput.format(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), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); break; case PLANE_ZX: writeBlock(gPlaneModal.format(18), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); break; case PLANE_YZ: writeBlock(gPlaneModal.format(19), gFeedModeModal.format(94), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); break; default: linearize(tolerance); } } } var mapCommand = { COMMAND_STOP:0, COMMAND_OPTIONAL_STOP:1, COMMAND_END:2, COMMAND_SPINDLE_CLOCKWISE:3, COMMAND_SPINDLE_COUNTERCLOCKWISE:4, COMMAND_STOP_SPINDLE:5, COMMAND_ORIENTATE_SPINDLE:19, COMMAND_LOAD_TOOL:6, COMMAND_COOLANT_ON:8, // flood COMMAND_COOLANT_OFF:9 }; function onCommand(command) { switch (command) { case COMMAND_START_SPINDLE: onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); return; case COMMAND_LOCK_MULTI_AXIS: return; case COMMAND_UNLOCK_MULTI_AXIS: 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 (currentSection.isMultiAxis()) { writeBlock(gFeedModeModal.format(94)); // inverse time feed off } if (((getCurrentSectionId() + 1) >= getNumberOfSections()) ||
(tool.number != getNextSection().getTool().number)) {
onCommand(COMMAND_BREAK_CONTROL);
}

forceAny();

if (((getCurrentSectionId() + 1) >= getNumberOfSections()) ||
(tool.number != getNextSection().getTool().number)) {
writeBlock(
mFormat.format(5),
mFormat.format(9),
gFormat.format(30)

);
}
}

/** Output block to do safe retract and/or move to home position. */
function writeRetract() {
// initialize routine
var _xyzMoved = new Array(false, false, false);
var _useG28 = properties.useG28; // can be either true or false
var _useG30 = properties.useG30; // can be either true or false

// check syntax of call
if (arguments.length == 0) {
error(localize("No axis specified for writeRetract()."));
return;
}
for (var i = 0; i < arguments.length; ++i) {
if ((arguments[i] < 0) || (arguments[i] > 2)) {
error(localize("Bad axis specified for writeRetract()."));
return;
}
if (_xyzMoved[arguments[i]]) {
error(localize("Cannot retract the same axis twice in one line"));
return;
}
_xyzMoved[arguments[i]] = true;
}

// special conditions
if (_xyzMoved[2] && (_xyzMoved[0] || _xyzMoved[1])) { // XY don't use G28
error(localize("You cannot move home in XY & Z in the same block."));
return;
}
if (_xyzMoved[0] != _xyzMoved[1]) {
error(localize("X & Y must be moved to home in the same block."));
return;
}
if (_xyzMoved[0] || _xyzMoved[1]) {
_useG30 = false;
}
if (_xyzMoved[2]) {
_useG28 = false;
}

// define home positions
var _xHome;
var _yHome;
var _zHome;
if (_useG28) {
_xHome = 0;
_yHome = 0;
_zHome = 0;
} else {
if (properties.homePositionCenter &&
hasParameter("part-upper-x") && hasParameter("part-lower-x")) {
_xHome = (getParameter("part-upper-x") + getParameter("part-lower-x")) / 2;
} else {
_xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0;
}
_yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0;
_zHome = machineConfiguration.getRetractPlane();
}

// format home positions
var words = []; // store all retracted axes in an array
for (var i = 0; i < arguments.length; ++i) { // define the axes to move switch (arguments[i]) { case X: words.push("X" + xyzFormat.format(_xHome)); break; case Y: words.push("Y" + xyzFormat.format(_yHome)); break; case Z: words.push("Z" + xyzFormat.format(_zHome)); retracted = true; break; } } // output move to home if (words.length > 0) {
if (_useG28) {
writeBlock(gFormat.format(28));
} else if (_useG30) {
writeBlock(gFormat.format(30));
}

// force any axes that move to home on next block
if (_xyzMoved[0]) {
xOutput.reset();
}
if (_xyzMoved[1]) {
yOutput.reset();
}
if (_xyzMoved[2]) {
zOutput.reset();
}
}
}

function onClose() {
writeln("");

// onCommand(COMMAND_COOLANT_OFF);

writeRetract(Z);

writeRetract(X, Y);

writeBlock("S0");

setWorkPlane(new Vector(0, 0, 0)); // reset working plane

onImpliedCommand(COMMAND_END);
onImpliedCommand(COMMAND_STOP_SPINDLE);
writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off
writeln("%");
}

Tiptoe Tube

Angle Iron

Lower Torso Supports

Watch Short Circuit!

Short Circuit

Short Circuit 2

Related Videos & Resources:

Beatty Robotics Curiosity Mars Rover Antenna