-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdatron c5.cps
More file actions
1807 lines (1601 loc) · 81.8 KB
/
datron c5.cps
File metadata and controls
1807 lines (1601 loc) · 81.8 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-2017 by Autodesk, Inc.
All rights reserved.
DATRON post processor configuration.
$Revision$
$Date$
FORKID {DC597035-3395-48C2-BA86-28EFF6A7E339}
*/
description = "DATRON C5";
vendor = "DATRON";
vendorUrl = "http://www.datron.com";
legal = "Copyright (C) 2012-2017 by Autodesk, Inc.";
certificationLevel = 2;
minimumRevision = 24000;
longDescription = "Post for DATRON C5.";
extension = "mcr";
setCodePage("ascii");
capabilities = CAPABILITY_MILLING;
tolerance = spatial(0.002, MM);
minimumChordLength = spatial(0.01, MM);
minimumCircularRadius = spatial(0.01, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
maximumCircularSweep = toRad(90);
allowHelicalMoves = false;
allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only
mapWorkOrigin = false;
// user-defined properties
properties = {
writeMachine: true, // write machine
writeVersion: false, // include version info
showOperationDialog: true, // shows a start dialog on the control to select the operation to start with
useParametricFeed: true, // specifies that feed should be output using Q values
showNotes: false, // specifies that operation notes should be output
useSmoothing: true, // specifies if smoothing should be used or not
useDynamic: true, // specifies using dynamic mode or not
useTimeStamp: false, // specifies to output time stamp
writeCoolantCommands: false // en/disable coolant code output for the entire program
};
var mFormat = createFormat({prefix:"M", width:2, zeropad:true, decimals:1});
var xyzFormat = createFormat({decimals:(unit == MM ? 5 : 5), forceDecimal:false});
var angleFormat = createFormat({decimals:5, scale:DEG});
var abcFormat = createFormat({decimals:5, scale:DEG});
var feedFormat = createFormat({decimals:(unit == MM ? 2 : 2), scale:(unit == MM ? 0.001 : 1)});
var toolFormat = createFormat({decimals:0});
var rpmFormat = createFormat({decimals:0, scale:0.001});
var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999
var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999
var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, width:7, trim:false});
var xOutput = createVariable({force:true}, xyzFormat);
var yOutput = createVariable({force:true}, xyzFormat);
var zOutput = createVariable({force:true}, xyzFormat);
var aOutput = createVariable({force:true}, abcFormat);
var bOutput = createVariable({force:true}, abcFormat);
var cOutput = createVariable({force:true}, abcFormat);
var feedOutput = createVariable({}, feedFormat);
var sOutput = createVariable({prefix:"S", force:true}, rpmFormat);
var gMotionModal = createModal({prefix:"Axyz ", force:true, suffix:","}, xyzFormat); // modal group 1 // G0-G3, ...
// fixed settings
var language = "de"; // supported languages are: "en", "de"
// collected state
var currentWorkOffset;
var currentFeedValue = -1;
var optionalSection = false;
var forceSpindleSpeed = false;
var activeMovements; // do not use by default
var currentFeedId;
var containsProbingOperations = false;
// format date + time
var timeFormat = createFormat({decimals:0, force:true, width:2, zeropad:true});
var now = new Date();
var nowDay = now.getDate();
var nowMonth = now.getMonth() + 1;
var nowHour = now.getHours();
var nowMin = now.getMinutes();
var nowSec = now.getSeconds();
/**
Writes the specified block.
*/
function writeBlock() {
writeWords(arguments);
}
var charMap = {
"\u00c4":"Ae",
"\u00e4":"ae",
"\u00dc":"Ue",
"\u00fc":"ue",
"\u00d6":"Oe",
"\u00f6":"oe",
"\u00df":"ss",
"\u002d":"_"
};
/** Map specific chars. */
function mapComment(text) {
var result = "";
for (var i = 0; i < text.length; ++i) {
var ch = charMap[text[i]];
result += ch ? ch : text[i];
}
return result;
}
function formatComment(text) {
return mapComment(text);
}
function formatVariable(text) {
var mapped = mapComment(text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase());
return mapped.replace(/[^A-Za-z0-9\-_]/g, "");
}
/**
Output a comment.
*/
function writeComment(text) {
writeln("; !" + formatComment(text) + "!");
}
function onOpen() {
if (true) { // note: setup your machine here
var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[0, 100.001], preference:0});
var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[0, 360], cyclic:true, preference:0});
machineConfiguration = new MachineConfiguration(aAxis, cAxis);
setMachineConfiguration(machineConfiguration);
optimizeMachineAngles2(0); // TCP mode
}
if (!machineConfiguration.isMachineCoordinate(0)) {
aOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(1)) {
bOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(2)) {
cOutput.disable();
}
var numberOfSections = getNumberOfSections();
for (var i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
if (isProbeOperation(section)) {
containsProbingOperations = true;
break;
}
}
// header
writeProgramHeader();
}
function getOperationDescription(section) {
var operationComment = "";
if (section.hasParameter("operation-comment")) {
operationComment = section.getParameter("operation-comment");
operationComment = formatComment(operationComment);
}
var cycleTypeString = "";
if (section.hasParameter("operation:cycleType")) {
cycleTypeString = localize(section.getParameter("operation:cycleType")).toString();
cycleTypeString = formatComment(cycleTypeString);
}
var sectionID = section.getId() + 1;
var description = operationComment/* + "_" + cycleTypeString + "_" + sectionID*/;
return description;
}
/** Writes the tool table. */
function writeToolTable() {
var tools = getToolTable();
writeBlock("; !" + translate("Number of tools in use") + ": " + tools.getNumberOfTools() + "!");
if (tools.getNumberOfTools() > 0) {
for (var i = 0; i < tools.getNumberOfTools(); ++i) {
var tool = tools.getTool(i);
var comment = "T" + (tool.number) + " = " + toolFormat.format(tool.number) + ";!" +
formatComment(getToolTypeName(tool.type)) + " " +
"D:" + xyzFormat.format(tool.diameter) + " " +
"L2:" + xyzFormat.format(tool.fluteLength) + " " +
"L3:" + xyzFormat.format(tool.shoulderLength) + "!";
writeBlock(comment);
}
}
}
/** Writes the program header. */
function writeProgramHeader() {
var date = timeFormat.format(nowDay) + "." + timeFormat.format(nowMonth) + "." + now.getFullYear();
var time = timeFormat.format(nowHour) + ":" + timeFormat.format(nowMin);
if (properties.useTimeStamp) {
writeBlock("!Makro file ; generated at " + date + " - " + time + " V9.85D!");
} else {
writeBlock("!Makro file ; V9.85D!");
}
if (programComment) {
writeBlock("!" + formatComment(programComment) + "!");
} else {
writeBlock("!Makroprojekt description!");
}
writeln("");
writeln("!Please make sure that the language on your control is set to " + "\"" + language + "\"" + "!");
switch (language) {
case "en":
writeBlock("_sprache 1;");
break;
case "de":
writeBlock("_sprache 0;");
break;
default:
writeBlock("_sprache 1;");
}
writeln("");
switch (unit) {
case IN:
writeBlock("Dimension 2;");
break;
case MM:
writeBlock("Dimension 1;");
break;
}
writeln("");
var variablesDeclaration = new Array();
var submacrosDeclaration = new Array();
var dialogsDeclaration = new Array();
if (properties.showOperationDialog) {
variablesDeclaration.push("optional_stop");
}
variablesDeclaration.push("$Message");
dialogsDeclaration.push("_maske _haupt, " + "1000" + ", 0, " + "\"" + translate("Submacro") + " " + translate("Description") + "\"");
if (properties.showOperationDialog) {
dialogsDeclaration.push("_feld optional_stop, 1, 0, 0, 0, 1, 2, 0," + " \"" + "optional_stop" + "\"" + "," + " \"" + "optional_stop" + "\"");
}
// Write variables declaration
var tools = getToolTable();
for (var i = 0; i < tools.getNumberOfTools(); ++i) {
var tool = tools.getTool(i);
variablesDeclaration.push("T" + tool.number);
}
var numberOfSections = getNumberOfSections();
if (properties.showOperationDialog) {
var dropDownElements = new Array();
variablesDeclaration.push("startOperation");
}
var dropDownDialog = "_feld startOperation, 1, 0, 1, 0, 9999, 1, 0, \"Startoperation <";
for (var i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
var sectionID = i + 1;
variablesDeclaration.push("Op_" + formatVariable(getOperationDescription(section)));
submacrosDeclaration.push("Sm_" + formatVariable(getOperationDescription(section)));
if (properties.showOperationDialog) {
dropDownElements.push(formatVariable(getOperationDescription(section)) + "<" + sectionID + ">");
}
if (properties.useParametricFeed) {
activeFeeds = initializeActiveFeeds(section);
for (var j = 0; j < activeFeeds.length; ++j) {
var feedContext = activeFeeds[j];
var feedDescription = formatVariable(feedContext.description);
if (variablesDeclaration.indexOf(feedDescription) == -1) {
variablesDeclaration.push(feedDescription);
}
}
}
}
if (properties.showOperationDialog) {
dropDownDialog += dropDownElements.join(", ");
dropDownDialog += ">\", \"Select the operation to start with. \"";
dialogsDeclaration.push(dropDownDialog);
}
if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) {
// submacrosDeclaration.push("Initposition");
// submacrosDeclaration.push("Endmacro");
}
// variablesDeclaration.push("Curr_zpno");
// variablesDeclaration.push("Zpos");
if (containsProbingOperations) {
variablesDeclaration.push("Xvalue1");
variablesDeclaration.push("Xvalue2");
variablesDeclaration.push("Yvalue1");
variablesDeclaration.push("Yvalue2");
variablesDeclaration.push("Zvalue");
variablesDeclaration.push("Newpos");
variablesDeclaration.push("Rotationvalue");
}
writeBlock("Variable " + variablesDeclaration.join(", ") + ";");
writeln("");
writeBlock("Smakros " + submacrosDeclaration.join(", ") + ";");
writeln("");
writeBlock(dialogsDeclaration.join(EOL) + ";");
writeln("");
if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) {
// writeBlock("_exit Endmacro;");
// writeln("");
}
if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) {
// createEndmacro();
}
}
function writeMainProgram() {
var numberOfSections = getNumberOfSections();
for (var i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
var Description = getOperationDescription(section);
var sectionID = i+1;
var sectionName = formatVariable("Sm_" + Description);
var maskName = formatVariable("Op_" + Description);
writeComment("##########" + Description + "##########");
// writeBlock(translate("Condition") + " " + maskName + ", 0, 1, 0, " + sectionID + ";");
writeBlock(translate("Label") + " " + sectionID + ";");
var tool = section.getTool();
if (properties.showNotes && section.hasParameter("notes")) {
var notes = section.getParameter("notes");
if (notes) {
var lines = String(notes).split("\n");
var r1 = new RegExp("^[\\s]+", "g");
var r2 = new RegExp("[\\s]+$", "g");
for (line in lines) {
var comment = lines[line].replace(r1, "").replace(r2, "");
if (comment) {
writeComment(comment);
}
}
}
}
var showToolZMin = true;
if (showToolZMin) {
if (is3D()) {
var zRange = section.getGlobalZRange();
var number = tool.number;
if (section.getTool().number != number) {
break;
}
zRange.expandToRange(section.getGlobalZRange());
writeln(localize("; ! ZMIN") + " = " + xyzFormat.format(zRange.getMinimum()) + "!");
}
}
if (!isProbeOperation(section)) {
writeBlock(translate("Tool") + " T" + (tool.number) + ", 0, 0, 1, 0;");
if (tool.spindleRPM < 6000) {
tool.spindleRPM = 6000;
}
onSpindleSpeed(tool.spindleRPM);
}
// set coolant after we have positioned at Z
setCoolant(tool.coolant);
var t = tolerance;
if (section.hasParameter("operation:tolerance")) {
t = section.getParameter("operation:tolerance");
}
if (properties.useDynamic) {
var dynamic = 5;
if (t <= 0.02) {
dynamic = 4;
}
if (t <= 0.01) {
dynamic = 3;
}
if (t <= 0.005) {
dynamic = 2;
}
if (t <= 0.003) {
dynamic = 1;
}
writeBlock(translate("Dynamics") + " " + dynamic + ";");
}
if (properties.useParametricFeed) {
activeFeeds = initializeActiveFeeds(section);
for (var j = 0; j < activeFeeds.length; ++j) {
var feedContext = activeFeeds[j];
writeBlock(formatVariable(feedContext.description) + " = " + feedFormat.format(feedContext.feed) + (unit == MM ? ";!m/min!" : ";!inch/min!"));
}
}
/*
// wcs
var workOffset;
if (!is3D()) {
workOffset = 19;
if (workOffset != currentWorkOffset) {
writeBlock("Position " + workOffset + ", 2;");
currentWorkOffset = workOffset;
}
} else {
workOffset = section.workOffset;
if (workOffset != 0 && workOffset < 41) {
if (workOffset != currentWorkOffset) {
writeBlock("Position " + workOffset + ", 2;");
currentWorkOffset = workOffset;
}
}
}
*/
writeBlock(translate("Submacro") + " " + sectionName + ";");
}
}
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();
}
function forceFeed() {
currentFeedId = undefined;
feedOutput.reset();
currentFeedValue = -1;
}
/** Force output of X, Y, Z, A, B, C, and F on next output. */
function forceAny() {
forceXYZ();
forceABC();
forceFeed();
}
function FeedContext(id, description, feed) {
this.id = id;
this.description = description;
this.feed = feed;
}
/** Maps the specified feed value to Q feed or formatted feed. */
function getFeed(f) {
if (activeMovements) {
var feedContext = activeMovements[movement];
if (feedContext != undefined) {
if (!feedFormat.areDifferent(feedContext.feed, f)) {
if (feedContext.id == currentFeedId) {
return ""; // nothing has changed
}
forceFeed();
currentFeedId = feedContext.id;
return (translate("Feed") + " " + formatVariable(feedContext.description) + (Array(4).join(", " + formatVariable(feedContext.description))) + ";");
}
}
currentFeedId = undefined; // force Q feed next time
}
if (feedFormat.areDifferent(currentFeedValue, f)) {
currentFeedValue = f;
return translate("Feed") + " " + feedOutput.format(f) + Array(4).join(", " + feedFormat.format(f)) + ";";
}
return "";
}
function initializeActiveFeeds(section) {
var activeFeeds = new Array();
if (section.hasAnyCycle && section.hasAnyCycle()) {
return activeFeeds;
}
activeMovements = new Array();
var movements = section.getMovements();
var id = 0;
if (section.hasParameter("operation:tool_feedCutting")) {
if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) {
var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_CUTTING] = feedContext;
activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext;
activeMovements[MOVEMENT_EXTENDED] = feedContext;
}
++id;
if (movements & (1 << MOVEMENT_PREDRILL)) {
feedContext = new FeedContext(id, localize("Predrilling"), section.getParameter("operation:tool_feedCutting"));
activeMovements[MOVEMENT_PREDRILL] = feedContext;
activeFeeds.push(feedContext);
}
++id;
if (section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "drill")) {
var feedContext = new FeedContext(id, localize("Cutting"), section.getParameter("operation:tool_feedCutting"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_CUTTING] = feedContext;
}
++id;
}
if (section.hasParameter("operation:finishFeedrate")) {
if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:finishFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
}
++id;
} else if (section.hasParameter("operation:tool_feedCutting")) {
if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
var feedContext = new FeedContext(id, localize("Finish"), section.getParameter("operation:tool_feedCutting"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
}
++id;
}
if (section.hasParameter("operation:tool_feedEntry")) {
if (movements & (1 << MOVEMENT_LEAD_IN)) {
var feedContext = new FeedContext(id, localize("Entry"), section.getParameter("operation:tool_feedEntry"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LEAD_IN] = feedContext;
}
++id;
}
if (section.hasParameter("operation:tool_feedExit")) {
if (movements & (1 << MOVEMENT_LEAD_OUT)) {
var feedContext = new FeedContext(id, localize("Exit"), section.getParameter("operation:tool_feedExit"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LEAD_OUT] = feedContext;
}
++id;
}
if (section.hasParameter("operation:noEngagementFeedrate")) {
if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
var feedContext = new FeedContext(id, localize("Direct"), section.getParameter("operation:noEngagementFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
}
++id;
} else if (section.hasParameter("operation:tool_feedCutting") &&
section.hasParameter("operation:tool_feedEntry") &&
section.hasParameter("operation:tool_feedExit")) {
if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
var feedContext = new FeedContext(id, localize("Direct"), Math.max(section.getParameter("operation:tool_feedCutting"), section.getParameter("operation:tool_feedEntry"), section.getParameter("operation:tool_feedExit")));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
}
++id;
}
if (section.hasParameter("operation:reducedFeedrate")) {
if (movements & (1 << MOVEMENT_REDUCED)) {
var feedContext = new FeedContext(id, localize("Reduced"), section.getParameter("operation:reducedFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_REDUCED] = feedContext;
}
++id;
}
if (section.hasParameter("operation:tool_feedRamp")) {
if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) {
var feedContext = new FeedContext(id, localize("Ramping"), section.getParameter("operation:tool_feedRamp"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_RAMP] = feedContext;
activeMovements[MOVEMENT_RAMP_HELIX] = feedContext;
activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext;
activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext;
}
++id;
}
if (section.hasParameter("operation:tool_feedPlunge")) {
if (movements & (1 << MOVEMENT_PLUNGE)) {
var feedContext = new FeedContext(id, localize("Plunge"), section.getParameter("operation:tool_feedPlunge"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_PLUNGE] = feedContext;
}
++id;
}
if (true) { // high feed
if (movements & (1 << MOVEMENT_HIGH_FEED)) {
var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate);
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_HIGH_FEED] = feedContext;
}
++id;
}
return activeFeeds;
}
var currentWorkPlaneABC = undefined;
function forceWorkPlane() {
currentWorkPlaneABC = undefined;
}
function onRewindMachine() {
writeComment("REWIND OF MACHINE AXIS");
}
function setWorkPlane(abc, turn) {
forceWorkPlane(); // always need the new workPlane
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
}
gMotionModal.reset();
var st = turn ? 1 : 0;
// move origin
var initialPosition = getFramePosition((currentSection.getInitialPosition()));
var xv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.x : currentSection.workOrigin.x) : xyzFormat.format(0);
var yv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.y : currentSection.workOrigin.y) : xyzFormat.format(0);
var zv = turn ? xyzFormat.format(currentSection.isMultiAxis() ? initialPosition.z : currentSection.workOrigin.z) : xyzFormat.format(0);
// rotate workplane and axis
var xs = abcFormat.format(abc.x);
var ys = abcFormat.format(abc.y);
var zs = abcFormat.format(abc.z);
var wz = turn ? 0 : 2; // 0 = indexing with retract 1= indexing with moving tool 2 = coordinate system rotation only
var vr = feedFormat.format(10000); // feed for indexing
if (turn) {
writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";");
writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";");
} else {
writeBlock(translate("Tilt") + " " + st + ", " + xs + ", " + ys + ", " + zs + ", " + wz + ", " + vr + ";");
writeBlock(translate("Shift") + " " + st + ", " + xv + ", " + yv + ", " + zv + ";");
}
currentWorkPlaneABC = abc;
}
var closestABC = false; // 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))
);
return undefined;
}
var direction = machineConfiguration.getDirection(abc);
if (!isSameDirection(direction, W.forward)) {
error(localize("Orientation not supported."));
return undefined;
}
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))
);
return undefined;
}
var tcp = false;
if (tcp) {
setRotation(W); // TCP mode
} else {
var O = machineConfiguration.getOrientation(abc);
var R = machineConfiguration.getRemainingOrientation(abc, W);
setRotation(R);
}
return abc;
}
function isProbeOperation(section) {
return section.hasParameter("operation-strategy") && (section.getParameter("operation-strategy") == "probe");
}
function onSection() {
var forceToolAndRetract = optionalSection && !currentSection.isOptional();
optionalSection = currentSection.isOptional();
var insertToolCall = forceToolAndRetract || isFirstSection() ||
currentSection.getForceToolChange && currentSection.getForceToolChange() ||
(tool.number != getPreviousSection().getTool().number);
var 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());
writeBlock("(");
if (insertToolCall || newWorkOffset || newWorkPlane) {
// retract to safe plane
retracted = true;
writeBlock(translate("ToolRetraction") + ";");
forceXYZ();
}
if (insertToolCall) {
forceWorkPlane();
retracted = true;
if (tool.number > 99) {
warning(localize("Tool number exceeds maximum value."));
}
}
if (insertToolCall ||
forceSpindleSpeed ||
isFirstSection() ||
(rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) ||
(tool.clockwise != getPreviousSection().getTool().clockwise)) {
forceSpindleSpeed = false;
if (tool.spindleRPM < 6000) {
tool.spindleRPM = 6000;
}
if (tool.spindleRPM > 60000) {
warning(localize("Spindle speed exceeds maximum value."));
}
if (!tool.clockwise) {
error(localize("Spindle direction not supported."));
return;
}
}
forceXYZ();
if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode
// set working plane after datum shift
if (currentSection.isMultiAxis()) {
forceWorkPlane();
cancelTransformation();
if (!retracted) {
writeBlock(translate("ToolRetraction") + ";");
}
} else {
var eulerXYZ = currentSection.workPlane.getTransposed().eulerZYX_R;
var abc = new Vector(-eulerXYZ.x, -eulerXYZ.y, -eulerXYZ.z);
setWorkPlane(abc, true);
}
} else { // pure 3D
var remaining = currentSection.workPlane;
if (!isSameDirection(remaining.forward, new Vector(0, 0, 1)) || currentSection.isMultiAxis()) {
//error(localize("Tool orientation is not supported."));
error(translate(
"\r\n________________________________________" +
"\r\n| error |" +
"\r\n| |" +
"\r\n| 4/5 axis operations detected. |" +
"\r\n| You have to enable the property |" +
"\r\n| got4thAxis or got5Axis, |" +
"\r\n| otherwise you can only post |" +
"\r\n| 3 Axis programs. |" +
"\r\n| If you still have issues, |" +
"\r\n| please contact www.DATRON.com! |" +
"\r\n|_______________________________________|\r\n"));
return;
}
setRotation(remaining);
}
forceAny();
var t = tolerance;
if (hasParameter("operation:tolerance")) {
if (t < getParameter("operation:tolerance")) {
t = getParameter("operation:tolerance");
}
}
if (properties.useSmoothing && !isProbeOperation(currentSection)) {
writeBlock(translate("Contour_smoothing") + " 1, " + xyzFormat.format(t * 1.2) + ", 0.1, 110, 1;");
}
var initialPosition = getFramePosition(currentSection.getInitialPosition());
if (!retracted) {
if (getCurrentPosition().z < initialPosition.z) {
writeBlock(translate("ToolRetraction") + ";");
}
}
if (currentSection.isMultiAxis()) {
var abc = currentSection.getInitialToolAxisABC();
writeComment("Prepositioning start");
setWorkPlane(abc, true);
writeBlock(gMotionModal.format(1), xyzFormat.format(0) + ", " + xyzFormat.format(0) + ", " + "z6p" + ";");
writeBlock(gMotionModal.format(1), "x6p" + ", " + "y6p" + ", " + xyzFormat.format(0) + ";");
setWorkPlane(new Vector(0, 0, 0), false);
writeComment("Prepositioning end");
cancelTransformation();
forceWorkPlane();
if (currentSection.getOptimizedTCPMode() == 0) {
writeBlock("Rtcp 1;");
}
} else {
writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + "z6p" + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(initialPosition.x) + ", " + yOutput.format(initialPosition.y) + ", " + zOutput.format(initialPosition.z) + ", 0, 0;");
}
if (properties.useParametricFeed /*&&
hasParameter("operation-strategy") &&
(getParameter("operation-strategy") != "drill")*/ &&
!(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) {
if (!insertToolCall &&
activeMovements &&
(getCurrentSectionId() > 0) &&
(getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0)) {
// use the current feeds
} else {
initializeActiveFeeds(currentSection);
}
} else {
activeMovements = undefined;
}
}
function onDwell(seconds) {
writeln(localize("Dwell") + " " + secFormat.format(seconds) + ", 0, 0, 0, 0, 0, 0;");
}
function onSpindleSpeed(spindleSpeed) {
writeBlock(translate("Rpm") + " 3, " + rpmFormat.format(spindleSpeed) + ", 0, 30;");
}
function onCycle() {
}
/** Convert approach to sign. */
function approach(value) {
validate((value == "positive") || (value == "negative"), "Invalid approach.");
return (value == "positive") ? 1 : -1;
}
function onCyclePoint(x, y, z) {
writeBlock(getFeed(cycle.feedrate));
if (isProbeOperation(currentSection)) {
forceXYZ();
}
switch (cycleType) {
case "bore-milling":
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;");
mcrBoreMilling(cycle);
break;
case "thread-milling":
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.clearance) + ",0,0;");
mcrThreadMilling(cycle);
break;
case "probing-x":
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
var touchPositionX1 = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel);
writeBlock("Xvalue1 = " + touchPositionX1 + ";");
writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;");
writeBlock("Newpos = X6p + (" + xOutput.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Xvalue1;");
writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;");
break;
case "probing-y":
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
var touchPositionY1 = y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2 + cycle.probeOvertravel);
writeBlock("Yvalue1 = " + touchPositionY1 + ";");
writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;");
writeBlock("Newpos = Y6p + (" + yOutput.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)) + ") - Yvalue1;");
writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;");
break;
case "probing-z":
var zpos = zOutput.format(Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract));
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zpos + ", 0, 0;");
writeBlock(translate("Zheight") + " 0, 0, 1, 0, " + zpos + ", " + zpos + ";");
break;
case "probing-x-wall":
var touchPositionX1 = x + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel);
var touchPositionX2 = x - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel);
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";");
writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;");
writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";");
writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;");
writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;");
writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;");
writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
break;
case "probing-y-wall":
var touchPositionY1 = y + cycle.width1 / 2 + (tool.diameter / 2 - cycle.probeOvertravel);
var touchPositionY2 = y - cycle.width1 / 2 - (tool.diameter / 2 - cycle.probeOvertravel);
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y + cycle.width1 / 2 + (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
writeBlock("Yvalue1 = " + xyzFormat.format(touchPositionY1) + ";");
writeBlock("Taxyz 2, X6p, Yvalue1, Z6p, 1, 0, 0;");
writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y - cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
writeBlock("Yvalue2 = " + xyzFormat.format(touchPositionY2) + ";");
writeBlock("Taxyz 2, X6p, Yvalue2, Z6p, 1, 0, 0;");
writeBlock("Newpos = y6p + " + yOutput.format(y) + " - (Yvalue1 + Yvalue2) / 2;");
writeBlock(translate("Setzp") + " X6p, Newpos, Z6p;");
writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
break;
case "probing-x-channel":
var touchPositionX1 = x + (cycle.width1 / 2 + cycle.probeOvertravel);
var touchPositionX2 = x - (cycle.width1 / 2 + cycle.probeOvertravel);
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";");
writeBlock("Taxyz 2, Xvalue1, Y6p, Z6p, 1, 0, 0;");
writeBlock("Xvalue2 = " + xyzFormat.format(touchPositionX2) + ";");
writeBlock("Taxyz 2, Xvalue2, Y6p, Z6p, 1, 0, 0;");
writeBlock("Newpos = x6p + " + xOutput.format(x) + " - (Xvalue1 + Xvalue2) / 2;");
writeBlock(translate("Setzp") + " Newpos, Y6p, Z6p;");
writeBlock(gMotionModal.format(1), "X6p, Y6p" + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
break;
case "probing-x-channel-with-island":
writeBlock(gMotionModal.format(1), xOutput.format(x) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(1), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(cycle.stock) + ", 0, 0;");
writeBlock(gMotionModal.format(0), xOutput.format(x + cycle.width1 / 2 - (cycle.probeClearance + tool.diameter / 2)) + ", " + yOutput.format(y) + ", " + zOutput.format(z - cycle.depth) + ", 0, 0;");
var touchPositionX1 = xOutput.getCurrent() + cycle.probeClearance + cycle.probeOvertravel;
writeBlock("Xvalue1 = " + xyzFormat.format(touchPositionX1) + ";");