-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOkuma Multus U3000.cps
4263 lines (3935 loc) · 157 KB
/
Okuma Multus U3000.cps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright (C) 2012-2018 by Autodesk, Inc.
All rights reserved.
Okuma LB3000 Lathe post processor configuration.
$Revision$
$Date$
FORKID {D93DAA65-1C09-402E-9871-3280B561D994}
*/
///////////////////////////////////////////////////////////////////////////////
// MANUAL NC COMMANDS
//
// The following ACTION commands are supported by this post.
//
// partEject - Manually eject the part
// useXZCMode - Force XZC mode for next operation
// usePolarMode - Force Polar mode for next operation
//
///////////////////////////////////////////////////////////////////////////////
/**
todo:
- cleanup
- check modal feed formats MM/REV MM MIN
- check G17 for onCyclePoint()
- check getSpindle(), results look wrong
*/
description = "Okuma Multus U3000 with OSP-300 control";
vendor = "OKUMA";
vendorUrl = "http://www.okuma.com";
legal = "Copyright (C) 2012-2018 by Autodesk, Inc.";
certificationLevel = 2;
minimumRevision = 24000;
longDescription = "Okuma Multus U3000 (OSP-300 control) post with support for mill-turn.";
extension = "min";
programNameIsInteger = false;
setCodePage("ascii");
capabilities = CAPABILITY_MILLING | CAPABILITY_TURNING;
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(90); // reduced sweep to break up circular moves on quadrant boundaries
allowHelicalMoves = true;
allowedCircularPlanes = undefined; // allow any circular motion
allowSpiralMoves = false;
highFeedrate = (unit == IN) ? 470 : 10000;
// user-defined properties
properties = {
writeMachine: false, // write machine
writeTools: false, // writes the tools
maxTool: 12, // maximum tool number
showSequenceNumbers: true, // show sequence numbers
sequenceNumberStart: 1, // first sequence number
sequenceNumberIncrement: 1, // increment for sequence numbers
sequenceNumberToolOnly: true, // output sequence numbers on tool change only
optionalStop: true, // optional stop
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.
preloadTool: true, // preloads next tool on tool change if any
maximumSpindleSpeed: 4200, // specifies the maximum spindle speed
useParametricFeed: false, // specifies that feed should be output using Q values
showNotes: false, // specifies that operation notes should be output.
useCycles: true, // specifies that drilling cycles should be used.
// gotPartCatcher: false, // specifies if the machine has a part catcher
autoEject: false, // specifies if the part should be automatically ejected at end of program
useTailStock: false, // specifies to use the tailstock or not
gotChipConveyor: false, // specifies to use a chip conveyor Y/N
homePositionX: 9999, // home position for X-axis
homePositionY: 9999, // home position for Y-axis
homePositionZ: 9999, // home position for Z-axis
homePositionW: 1500, // home position for W-axis
optimizeCaxisSelect: false, // optimize output of enable/disable C-axis codes
transferUseTorque: false, // use torque control for stock-transfer
writeVersion: false, // include version info
gotSecondarySpindle: true, // machine has a secondary spindle
useM960: true, // use M960 C-axis shortest direction instead of M15/M16 directional codes
useSimpleThread: true, // outputs a G33 threading cycle, false outputs a G71 (standard) threading cycle
CASOff: false, //Collision Avoidance system
lowGear: false, //Use Low gear for turning operations.
safeRetractDistance: 0.0 // distance to add to retract distance when rewinding rotary axes
};
// 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"},
maxTool: {title:"Max tool number", description:"Defines the maximum tool number.", type:"integer", range:[0, 999999999]},
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"},
sequenceNumberToolOnly: {title:"Sequence numbers only on tool change", description:"Output sequence numbers on tool changes instead of every line.", group:1, type:"boolean"},
optionalStop: {title:"Optional stop", description:"Outputs optional stop code during when necessary in the code.", 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"},
maximumSpindleSpeed: {title:"Max spindle speed", description:"Defines the maximum spindle speed allowed by your machines.", type:"integer", range:[0, 999999999]},
useParametricFeed: {title:"Parametric feed", description:"Specifies the feed value that should be output using a Q value.", type:"boolean"},
showNotes: {title:"Show notes", description:"Writes operation notes as comments in the outputted code.", type:"boolean"},
useCycles: {title:"Use cycles", description:"Specifies if canned drilling cycles should be used.", type:"boolean"},
// gotPartCatcher: {title:"Use part catcher", description:"Specifies whether part catcher code should be output.", type:"boolean"},
autoEject: {title:"Auto eject", description:"Specifies whether the part should automatically eject at the end of a program.", type:"boolean"},
useTailStock: {title:"Use tailstock", description:"Specifies whether to use the tailstock or not.", type:"boolean", presentation:"yesno"},
gotChipConveyor: {title:"Got chip conveyor", description:"Specifies whether to use a chip conveyor.", type:"boolean", presentation:"yesno"},
homePositionX: {title:"X home position in radius", description:"X home position specified in radius.", type:"spatial"},
homePositionY: {title:"Y home position", description:"Y home position.", type:"spatial"},
homePositionZ: {title:"Z home position", description:"Z home position.", type:"spatial"},
homePositionW: {title:"W home position", description:"W home position.", type:"spatial"},
optimizeCaxisSelect: {title:"Optimize C axis selection", description:"Optimizes the output of enable/disable C-axis codes.", type:"boolean"},
transferUseTorque: {title:"Stock-transfer torque control", description:"Use torque control for stock transfer.", type:"boolean"},
writeVersion: {title:"Write version", description:"Write the version number in the header of the code.", group:0, type:"boolean"},
gotSecondarySpindle: {title:"Secondary spindle", description:"Specifies that the machine has a secondary spindle.", group:0, type:"boolean"},
useM960: {title:"Use C-axis Shortest Direction Code", description:"Specifies that an M960 should be used to control the C-axis direction instead of the M15/M16 directional codes.", type:"boolean"},
useSimpleThread: {title:"Use simple threading cycle", description:"Enable to output G33 simple threading cycle, disable to output G71 standard threading cycle.", type:"boolean"},
safeRetractDistance: {title:"Safe retract distance", description:"Specifies the distance to add to retract distance when rewinding rotary axes.", type:"spatial"}
};
// samples:
// throughTool: {on: 88, off: 89}
// throughTool: {on: [8, 88], off: [9, 89]}
var coolants = {
flood: {turret1: {on: 263, off: 262}, turret2: {on: 8, off: 9}},
mist: {},
throughTool: {turret1: {on: 175, off: 174}, turret2: {on: 8, off: 9}},
air: {},
airThroughTool: {turret1: {on: 51, off: 50}, turret2: {on: 51, off: 50}},
suction: {},
floodMist: {},
floodThroughTool: {},
off: 9
};
var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-/";
var gFormat = createFormat({prefix:"G", decimals:0});
var mFormat = createFormat({prefix:"M", decimals:0});
var spatialFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
var integerFormat = createFormat({decimals:0});
var xFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:2}); // diameter mode
var yFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
var zFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
var rFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); // radius
var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG});
var bFormat = createFormat({prefix:"(B=", suffix:")", decimals:3, forceDecimal:true, scale:DEG});
var cFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG, cyclicLimit:toRad(359.9999)});
var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true});
var pitchFormat = createFormat({decimals:6, forceDecimal:true});
var toolFormat = createFormat({decimals:0, width:4, zeropad:true});
var tool1Format = createFormat({decimals:0, width:6, zeropad:true});
var orientationNumberFormat = createFormat({width:2, zeropad:true, decimals:0});
var rpmFormat = createFormat({decimals:0});
var secFormat = createFormat({decimals:2, 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 xOutput = createVariable({onchange:function () {retracted = false;}, prefix:"X"}, xFormat);
var yOutput = createVariable({prefix:"Y"}, yFormat);
var zOutput = createVariable({onchange:function () {retracted = false;}, prefix:"Z"}, zFormat);
var wOutput = createVariable({prefix:"W"}, zFormat);
var aOutput = createVariable({prefix:"A"}, abcFormat);
var bOutput = createVariable({}, bFormat);
var cOutput = createVariable({prefix:"C"}, cFormat);
var feedOutput = createVariable({prefix:"F"}, feedFormat);
var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat);
var sOutput = createVariable({prefix:"S", force:true}, rpmFormat);
var sbOutput = createVariable({prefix:"SB=", force:true}, rpmFormat);
var eOutput = createVariable({prefix:"E", force:true}, secFormat);
var dwellOutput = createVariable({prefix:"F", force:true}, secFormat);
var rOutput = createVariable({prefix:"R", force:true}, rFormat);
// circular output
var iOutput = createReferenceVariable({prefix:"I", force: true}, spatialFormat);
var jOutput = createReferenceVariable({prefix:"J", force: true}, spatialFormat);
var kOutput = createReferenceVariable({prefix:"K", force: true}, spatialFormat);
var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19
var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G98-99
var gSpindleModeModal = createModal({}, gFormat); // modal group 5 // G96-97
var gSpindleModal = createModal({}, mFormat); // M176/177 SPINDLE MODE
var gAbsIncModal = createModal({}, gFormat); // modal group 6 // G90-91
var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ...
var gPolarModal = createModal({}, gFormat); // G137, G136
var gYaxisModal = createModal({}, gFormat);
var cAxisEngageModal = createModal({}, mFormat);
var cAxisBrakeModal = createModal({}, mFormat);
var mInterferModal = createModal({}, mFormat);
var cAxisEnableModal = createModal({}, mFormat);
var cAxisDirectionModal = createModal({}, mFormat);
var gSelectSpindleModal = createModal({}, gFormat);
var tailStockModal = createModal({}, mFormat);
// fixed settings
var firstFeedParameter = 100;
var gotYAxis = true;
var yAxisMinimum = toPreciseUnit(gotYAxis ? -125 : 0, MM); // specifies the minimum range for the Y-axis
var yAxisMaximum = toPreciseUnit(gotYAxis ? 125 : 0, MM); // specifies the maximum range for the Y-axis
var xAxisMinimum = toPreciseUnit(-125, MM); // specifies the maximum range for the X-axis (RADIUS MODE VALUE)
var gotBAxis = true; // B-axis always requires customization to match the machine specific functions for doing rotations
var bAxisIsManual = false; // B-axis is manually set and not programmable
var gotMultiTurret = true; // specifies if the machine has several turrets
var gotPolarInterpolation = true; // specifies if the machine has XY polar interpolation capabilities
var gotDoorControl = true;
var airCleanChuck = true; // use air to clean off chuck at part transfer and part eject
var linearizeXZCMode = false; // XZC mode requires linearization
var WARNING_WORK_OFFSET = 0;
var WARNING_REPEAT_TAPPING = 1;
var SPINDLE_MAIN = 0;
var SPINDLE_SUB = 1;
var SPINDLE_LIVE = 2;
var POSX = 0;
var POXY = 1;
var POSZ = 2;
var NEGZ = -2;
var TRANSFER_PHASE = 0;
var TRANSFER_SPEED = 1;
var TRANSFER_STOP = 2;
// collected state
var sequenceNumber;
var currentWorkOffset;
var optionalSection = false;
var forceSpindleSpeed = false;
var activeMovements; // do not use by default
var currentFeedId;
var previousSpindle;
var activeSpindle=0;
var currentRPM = 0;
var partCutoff = false;
var partWasCutOff = false;
var reverseTap = false;
var showSequenceNumbers;
var stockTransferIsActive = false;
var forceXZCMode = false; // forces XZC output, activated by Action:useXZCMode
var forcePolarMode = false; // force Polar output, activated by Action:usePolarMode
var tapping = false;
var threading = false;
var ejectRoutine = false;
var bestABCIndex = undefined;
var G127isActive = false;
var retracted = false; // specifies that the tool has been retracted to the safe plane
var waitNumber = 10;
var isNewSpindle = false;
var HSSC = false;
var machiningMode = 0;
var lowGear = false;
var korteRetract = false;
var machineState = {
liveToolIsActive: undefined,
cAxisIsEngaged: undefined,
machiningDirection: undefined,
mainSpindleIsActive: undefined,
subSpindleIsActive: undefined,
mainSpindleBrakeIsActive: undefined,
subSpindleBrakeIsActive: undefined,
tailstockIsActive: undefined,
usePolarMode: undefined,
useXZCMode: undefined,
axialCenterDrilling: undefined,
currentBAxisOrientationTurning: new Vector(0, 0, 0),
yAxisModeIsActive: undefined,
currentTurret: undefined
};
function getCode(code, spindle) {
switch(code) {
case "PART_CATCHER_ON":
return 77;
case "PART_CATCHER_OFF":
return 76;
case "TAILSTOCK_ON":
machineState.tailstockIsActive = true;
return 21;
case "TAILSTOCK_OFF":
machineState.tailstockIsActive = false;
return 20;
case "SET_SPINDLE_FRAME":
break;
case "ENABLE_Y_AXIS":
setRadiusDiameterMode("radius");
machineState.yAxisModeIsActive = true;
return 138;
case "DISABLE_Y_AXIS":
setRadiusDiameterMode("diameter");
machineState.yAxisModeIsActive = false;
return 136;
case "ENABLE_C_AXIS":
machineState.cAxisIsEngaged = true;
return 110;
case "DISABLE_C_AXIS":
machineState.cAxisIsEngaged = false;
return 109;
case "POLAR_INTERPOLATION_ON":
return 137;
case "POLAR_INTERPOLATION_OFF":
return 136;
case "ENABLE_TURNING":
return 270;
case "STOP_SPINDLE":
switch (spindle) {
case SPINDLE_MAIN:
case SPINDLE_SUB:
machineState.mainSpindleIsActive = false;
machineState.subSpindleIsActive = false;
return 5;
case SPINDLE_LIVE:
machineState.liveToolIsActive = false;
return 12;
}
break;
case "ORIENT_SPINDLE":
return (spindle == SPINDLE_MAIN) ? 19 : 239;
case "START_SPINDLE_CW":
switch (spindle) {
case SPINDLE_MAIN:
machineState.mainSpindleIsActive = true;
return 3;
case SPINDLE_SUB:
machineState.subSpindleIsActive = true;
return 3;
case SPINDLE_LIVE:
machineState.liveToolIsActive = true;
return 13;
}
break;
case "START_SPINDLE_CCW":
switch (spindle) {
case SPINDLE_MAIN:
machineState.mainSpindleIsActive = true;
return 4;
case SPINDLE_SUB:
machineState.subSpindleIsActive = true;
return 4;
case SPINDLE_LIVE:
machineState.liveToolIsActive = true;
return 14;
}
break;
case "FEED_MODE_MM_REV":
return 95;
case "FEED_MODE_MM_MIN":
return 94;
case "CONSTANT_SURFACE_SPEED_ON":
machineState.constantSurfaceSpeedIsActive = true;
return 96;
case "CONSTANT_SURFACE_SPEED_OFF":
machineState.constantSurfaceSpeedIsActive = false;
return 97;
case "AUTO_AIR_ON":
break;
case "AUTO_AIR_OFF":
break;
case "LOCK_MULTI_AXIS":
return 147;
case "UNLOCK_MULTI_AXIS":
return 146;
case "C_AXIS_CW":
return 15;
case "C_AXIS_CCW":
return 16;
case "CLAMP_CHUCK":
return (spindle == SPINDLE_MAIN) ? 83 : 248;
case "UNCLAMP_CHUCK":
return (spindle == SPINDLE_MAIN) ? 84 : 249;
case "SPINDLE_SYNCHRONIZATION_PHASE":
break;
case "SPINDLE_SYNCHRONIZATION_SPEED":
return 151;
case "SPINDLE_SYNCHRONIZATION_OFF":
return 150;
case "IGNORE_SPINDLE_ORIENTATION":
return 210;
case "TORQUE_LIMIT_ON":
return 29;
case "TORQUE_LIMIT_OFF":
return 28;
case "TORQUE_SKIP_ON":
return 22;
case "SELECT_SPINDLE":
switch (spindle) {
case SPINDLE_MAIN:
return 140;
case SPINDLE_SUB:
return 141;
}
break;
case "RIGID_TAPPING":
break;
case "INTERNAL_INTERLOCK_ON":
return (spindle == SPINDLE_MAIN) ? 185 : 247;
case "INTERNAL_INTERLOCK_OFF":
return (spindle == SPINDLE_MAIN) ? 184 : 246;
case "INTERFERENCE_CHECK_OFF":
break;
case "INTERFERENCE_CHECK_ON":
break;
case "CYCLE_PART_EJECTOR":
break;
default:
error(localize("Command " + code + " is not defined."));
return 0;
}
return 0;
}
/** Returns the modulus. */
function getModulus(x, y) {
return Math.sqrt(x * x + y * y);
}
/**
Returns the C rotation for the given X and Y coordinates.
*/
function getC(x, y) {
var direction;
if (Vector.dot(machineConfiguration.getAxisU().getAxis(), new Vector(0, 0, 1)) != 0) {
direction = (machineConfiguration.getAxisU().getAxis().getCoordinate(2) >= 0) ? 1 : -1; // C-axis is the U-axis
} else {
direction = (machineConfiguration.getAxisV().getAxis().getCoordinate(2) >= 0) ? 1 : -1; // C-axis is the V-axis
}
var c = Math.atan2(y, x) * direction;
if (c < 0) {
c += Math.PI * 2;
}
return c;
}
/**
Returns the C rotation for the given X and Y coordinates in the desired rotary direction.
*/
function getCClosest(x, y, _c, clockwise) {
if (_c == Number.POSITIVE_INFINITY) {
_c = 0; // undefined
}
if (!xFormat.isSignificant(x) && !yFormat.isSignificant(y)) { // keep C if XY is on center
return _c;
}
var c = getC(x, y);
if (c < 0) {
c += Math.PI * 2;
}
return c;
/*
if (clockwise != undefined) {
if (clockwise) {
while (c < _c) {
c += Math.PI * 2;
}
} else {
while (c > _c) {
c -= Math.PI * 2;
}
}
} else {
min = _c - Math.PI;
max = _c + Math.PI;
while (c < min) {
c += Math.PI * 2;
}
while (c > max) {
c -= Math.PI * 2;
}
}
return c;
*/
}
/**
Returns the desired tolerance for the given section.
*/
function getTolerance() {
var t = tolerance;
if (hasParameter("operation:tolerance")) {
if (t > 0) {
t = Math.min(t, getParameter("operation:tolerance"));
} else {
t = getParameter("operation:tolerance");
}
}
return t;
}
/**
Outputs the C-axis direction code.
*/
function setCAxisDirection(previous, current) {
if (!properties.useM960) {
var delta = current - previous;
if (((delta < 0) && (delta > -Math.PI)) || (delta > Math.PI)) {
writeBlock(cAxisDirectionModal.format(getCode("C_AXIS_CCW", getSpindle(true))));
} else if (abcFormat.getResultingValue(delta) != 0) {
writeBlock(cAxisDirectionModal.format(getCode("C_AXIS_CW", getSpindle(true))));
}
}
}
function formatSequenceNumber() {
if (sequenceNumber > 99999) {
sequenceNumber = properties.sequenceNumberStart;
}
var seqno = "N" + sequenceNumber;
sequenceNumber += properties.sequenceNumberIncrement;
return seqno;
}
/**
Writes the specified block.
*/
function writeBlock() {
var seqno = "";
var opskip = "";
if (showSequenceNumbers) {
seqno = formatSequenceNumber();
}
if (optionalSection) {
opskip = "/";
}
var text = formatWords(arguments);
if (text) {
writeWords(opskip, seqno, text);
if (properties.sequenceNumberToolOnly) {
showSequenceNumbers = false;
}
}
}
function writeDebug(_text) {
writeComment("DEBUG - " + _text);
}
function formatComment(text) {
return "(" + String(filterText(String(text).toUpperCase(), permittedCommentChars)).replace(/[\(\)]/g, "") + ")";
}
/**
Output a comment.
*/
function writeComment(text) {
writeln(formatComment(text));
}
function getB(abc, section) {
/*
if (section.spindle == SPINDLE_PRIMARY) {
return abc.y;
} else {
return Math.PI - abc.y;
}
*/
return abc.y;
}
function writeCommentSeqno(text) {
writeln(formatSequenceNumber() + formatComment(text));
}
function defineBAxis() {
if (bAxisIsManual) {
bFormat = createFormat({prefix:"(B=", suffix:")", decimals:3, forceDecimal:true, scale:DEG});
bOutput = createVariable({}, bFormat);
} else {
bFormat = createFormat({prefix:"B", decimals:3, forceDecimal:true, scale:DEG});
bOutput = createVariable({}, bFormat);
barOutput = createVariable({prefix:"W", force:true}, spatialFormat);
}
}
var machineConfigurationMainSpindle;
var machineConfigurationSubSpindle;
function onOpen() {
if (properties.useRadius) {
maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC
}
// Copy certain properties into global variables
showSequenceNumbers = properties.sequenceNumberToolOnly ? false : properties.showSequenceNumbers;
// Setup default M-codes
// mInterferModal.format(getCode("INTERFERENCE_CHECK_ON", SPINDLE_MAIN));
if (true) {
var bAxisMain = createAxis({coordinate:1, table:false, axis:[0, -1, 0], range:[0, 210.001], preference:0});
var cAxisMain = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, range:[0, 359.999], preference:0}); // C axis is modal between primary and secondary spindle
var bAxisSub = createAxis({coordinate:1, table:false, axis:[0, -1, 0], range:[0, 210.001], preference:0});
var cAxisSub = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, range:[0, 359.999], preference:0}); // C axis is modal between primary and secondary spindle
machineConfigurationMainSpindle = gotBAxis ? new MachineConfiguration(bAxisMain, cAxisMain) : new MachineConfiguration(cAxisMain);
machineConfigurationSubSpindle = gotBAxis ? new MachineConfiguration(bAxisSub, cAxisSub) : new MachineConfiguration(cAxisSub);
}
machineConfiguration = new MachineConfiguration(); // creates an empty configuration to be able to set eg vendor information
machineConfiguration.setVendor("OKUMA");
machineConfiguration.setModel("Multus U3000");
yOutput.disable();
gPolarModal.format(getCode("DISABLE_Y_AXIS", true));
aOutput.disable();
if (!gotBAxis) {
bOutput.disable();
} else {
defineBAxis();
}
if (highFeedrate <= 0) {
error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal."));
return;
}
if (!properties.separateWordsWithSpace) {
setWordSeparator("");
}
sequenceNumber = properties.sequenceNumberStart;
if (programName) {
var programId = parseInt(programName, 10);
if ((programId >= 1) && (programId <= 9999)) {
var oFormat = createFormat({width:4, zeropad:true, decimals:0});
writeln("O" + oFormat.format(programId));
}
}
// Select the active spindle
if (properties.gotSecondarySpindle) {
// writeBlock(gSelectSpindleModal.format(getCode("SELECT_SPINDLE", getSection(0).spindle))); // cannot use getSpindle since there is not an active section
}
if (programComment) {
writeln(formatComment(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 compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset;
var comment = "T" + toolFormat.format(tool.number * 100 + compensationOffset % 100) + " " +
"D=" + spatialFormat.format(tool.diameter) + " " +
localize("CR") + "=" + spatialFormat.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") + "=" + spatialFormat.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 (spatialFormat.areDifferent(tooli.diameter, toolj.diameter) ||
spatialFormat.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;
}
}
}
}
}
writeBlock(gAbsIncModal.format(90), gCycleModal.format(80));
writeBlock(gFormat.format((getSection(0).getTool().turret == 2) ? 14 : 13));
writeBlock(gFormat.format(140));
writeBlock("P2");
if (getSection(0).spindle == SPINDLE_PRIMARY) {
writeBlock(gFormat.format(20), "HP=" + spatialFormat.format(1)); // retract
} else {
writeBlock(gFormat.format(20), "HP=" + spatialFormat.format(2)); // retract
}
writeBlock(mFormat.format(331));
writeln("CLEAR");
writeln("DRAW");
writeBlock(gFormat.format(50), sOutput.format(properties.maximumSpindleSpeed));
writeBlock(gFormat.format(141));
writeBlock(gFormat.format(50), sOutput.format(properties.maximumSpindleSpeed));
writeBlock(gFormat.format(110));
writeBlock(mFormat.format(216));
writeBlock(gFormat.format((getSection(0).getTool().turret == 2) ? 13 : 14));
writeBlock(gFormat.format(141));
onCommand(COMMAND_CLOSE_DOOR);
if (getSection(0).spindle == SPINDLE_PRIMARY) {
writeBlock(gFormat.format(20), "HP=" + spatialFormat.format(1)); // retract
} else {
writeBlock(gFormat.format(20), "HP=" + spatialFormat.format(2)); // retract
}
writeBlock(gFormat.format(50), sOutput.format(properties.maximumSpindleSpeed));
writeBlock(gFormat.format(140));
writeBlock(gFormat.format(50), sOutput.format(properties.maximumSpindleSpeed));
writeBlock(gFormat.format(111));
writeBlock(mFormat.format(216));
if (properties.useM960) {
writeBlock(mFormat.format(960));
}
if (properties.gotChipConveyor) {
onCommand(COMMAND_START_CHIP_TRANSPORT);
}
// automatically eject part at end of program
if (properties.autoEject) {
ejectRoutine = true;
}
}
function onComment(message) {
writeComment(message);
}
/** Force output of X, Y, and Z. */
function forceXYZ() {
xOutput.reset();
yOutput.reset();
zOutput.reset();
}
/** Force output of A, B, and C. */
function forceABC() {
aOutput.reset();
bOutput.reset();
cOutput.reset();
}
function forceFeed() {
currentFeedId = undefined;
feedOutput.reset();
}
/** Force output of X, Y, Z, A, B, C, and F on next output. */
function forceAny() {
forceXYZ();
forceABC();
forceFeed();
}
function forceUnlockMultiAxis() {
cAxisBrakeModal.reset();
}
function FeedContext(id, description, feed) {
this.id = id;
this.description = description;
this.feed = 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 "F=V" + (firstFeedParameter + feedContext.id);
}
}
currentFeedId = undefined; // force Q feed next time
}
return feedOutput.format(f); // use feed value
}
function initializeActiveFeeds() {
activeMovements = new Array();
var movements = currentSection.getMovements();
var feedPerRev = currentSection.feedMode == FEED_PER_REVOLUTION;
var id = 0;
var activeFeeds = new Array();
if (hasParameter("operation:tool_feedCutting")) {
if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) {
var feedContext = new FeedContext(id, localize("Cutting"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : 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"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting"));
activeMovements[MOVEMENT_PREDRILL] = feedContext;
activeFeeds.push(feedContext);
}
++id;
}
if (hasParameter("operation:finishFeedrate")) {
if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
var finishFeedrateRel;
if (hasParameter("operation:finishFeedrateRel")) {
finishFeedrateRel = getParameter("operation:finishFeedrateRel");
} else if (hasParameter("operation:finishFeedratePerRevolution")) {
finishFeedrateRel = getParameter("operation:finishFeedratePerRevolution");
}
var feedContext = new FeedContext(id, localize("Finish"), feedPerRev ? finishFeedrateRel : getParameter("operation:finishFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
}
++id;
} else if (hasParameter("operation:tool_feedCutting")) {
if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
var feedContext = new FeedContext(id, localize("Finish"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
}
++id;
}
if (hasParameter("operation:tool_feedEntry")) {
if (movements & (1 << MOVEMENT_LEAD_IN)) {
var feedContext = new FeedContext(id, localize("Entry"), feedPerRev ? getParameter("operation:tool_feedEntryRel") : getParameter("operation:tool_feedEntry"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LEAD_IN] = feedContext;
}
++id;
}
if (hasParameter("operation:tool_feedExit")) {
if (movements & (1 << MOVEMENT_LEAD_OUT)) {
var feedContext = new FeedContext(id, localize("Exit"), feedPerRev ? getParameter("operation:tool_feedExitRel") : getParameter("operation:tool_feedExit"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LEAD_OUT] = feedContext;
}
++id;
}
if (hasParameter("operation:noEngagementFeedrate")) {
if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
var feedContext = new FeedContext(id, localize("Direct"), feedPerRev ? getParameter("operation:noEngagementFeedrateRel") : getParameter("operation:noEngagementFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
}
++id;
} else if (hasParameter("operation:tool_feedCutting") &&
hasParameter("operation:tool_feedEntry") &&
hasParameter("operation:tool_feedExit")) {
if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
var feedContext = new FeedContext(
id,
localize("Direct"),
Math.max(
feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting"),
feedPerRev ? getParameter("operation:tool_feedEntryRel") : getParameter("operation:tool_feedEntry"),
feedPerRev ? getParameter("operation:tool_feedExitRel") : getParameter("operation:tool_feedExit")
)
);
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
}
++id;
}
if (hasParameter("operation:reducedFeedrate")) {
if (movements & (1 << MOVEMENT_REDUCED)) {
var feedContext = new FeedContext(id, localize("Reduced"), feedPerRev ? getParameter("operation:reducedFeedrateRel") : getParameter("operation:reducedFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_REDUCED] = feedContext;
}
++id;
}
if (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"), feedPerRev ? getParameter("operation:tool_feedRampRel") : 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 (hasParameter("operation:tool_feedPlunge")) {
if (movements & (1 << MOVEMENT_PLUNGE)) {
var feedContext = new FeedContext(id, localize("Plunge"), feedPerRev ? getParameter("operation:tool_feedPlungeRel") : 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;
}
for (var i = 0; i < activeFeeds.length; ++i) {
var feedContext = activeFeeds[i];
writeBlock("V" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description));
}
}
var currentWorkPlaneABC = undefined;
function forceWorkPlane() {
currentWorkPlaneABC = undefined;
}
function setWorkPlane(abc) {
// milling only
if (!machineConfiguration.isMultiAxisConfiguration()) {
return; // ignore
}
if (!((currentWorkPlaneABC == undefined) ||
abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) ||