Newer
Older
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
aOutput.reset();
bOutput.reset();
cOutput.reset();
}
/** Force output of X, Y, Z, A, B, C, and F on next output. */
function forceAny() {
forceXYZ();
forceABC();
forceFeed();
}
/**
Writes the specified block.
*/
function writeBlock() {
var text = formatWords(arguments);
if (!text) {
return;
}
if ((optionalSection || skipBlocks) && !getSetting("supportsOptionalBlocks", true)) {
error(localize("Optional blocks are not supported by this post."));
}
if (getProperty("showSequenceNumbers") == "true") {
if (sequenceNumber == undefined || sequenceNumber >= settings.maximumSequenceNumber) {
sequenceNumber = getProperty("sequenceNumberStart");
}
if (optionalSection || skipBlocks) {
if (text) {
writeWords("/", "N" + sequenceNumber, text);
}
} else {
writeWords2("N" + sequenceNumber, arguments);
}
sequenceNumber += getProperty("sequenceNumberIncrement");
} else {
if (optionalSection || skipBlocks) {
writeWords2("/", arguments);
} else {
writeWords(arguments);
}
}
}
validate(settings.comments, "Setting 'comments' is required but not defined.");
function formatComment(text) {
var prefix = settings.comments.prefix;
var suffix = settings.comments.suffix;
text = settings.comments.upperCase ? text.toUpperCase() : text;
text = filterText(String(text), settings.comments.permittedCommentChars).replace(/[()]/g, "");
text = String(text).substring(0, settings.comments.maximumLineLength - prefix.length - suffix.length);
return text != "" ? prefix + text + suffix : "";
}
/**
Output a comment.
*/
function writeComment(text) {
if (!text) {
return;
}
var comments = String(text).split("\n");
for (comment in comments) {
var _comment = formatComment(comments[comment]);
if (_comment) {
writeln(_comment);
}
}
}
function onComment(text) {
writeComment(text);
}
/**
Writes the specified block - used for tool changes only.
*/
function writeToolBlock() {
var show = getProperty("showSequenceNumbers");
setProperty("showSequenceNumbers", (show == "true" || show == "toolChange") ? "true" : "false");
writeBlock(arguments);
setProperty("showSequenceNumbers", show);
}
var skipBlocks = false;
function writeStartBlocks(isRequired, code) {
var safeSkipBlocks = skipBlocks;
if (!isRequired) {
if (!getProperty("safeStartAllOperations", false)) {
return; // when safeStartAllOperations is disabled, dont output code and return
}
// if values are not required, but safe start is enabled - write following blocks as optional
skipBlocks = true;
}
code(); // writes out the code which is passed to this function as an argument
skipBlocks = safeSkipBlocks; // restore skipBlocks value
}
var pendingRadiusCompensation = -1;
function onRadiusCompensation() {
pendingRadiusCompensation = radiusCompensation;
if (pendingRadiusCompensation >= 0 && !getSetting("supportsRadiusCompensation", true)) {
error(localize("Radius compensation mode is not supported."));
return;
}
}
function onPassThrough(text) {
var commands = String(text).split(",");
for (text in commands) {
writeBlock(commands[text]);
}
}
function forceModals() {
if (arguments.length == 0) { // reset all modal variables listed below
if (typeof gMotionModal != "undefined") {
gMotionModal.reset();
}
if (typeof gPlaneModal != "undefined") {
gPlaneModal.reset();
}
if (typeof gAbsIncModal != "undefined") {
gAbsIncModal.reset();
}
if (typeof gFeedModeModal != "undefined") {
gFeedModeModal.reset();
}
} else {
for (var i in arguments) {
arguments[i].reset(); // only reset the modal variable passed to this function
}
}
}
/** Helper function to be able to use a default value for settings which do not exist. */
function getSetting(setting, defaultValue) {
var result = defaultValue;
var keys = setting.split(".");
var obj = settings;
for (var i in keys) {
if (obj[keys[i]] != undefined) { // setting does exist
result = obj[keys[i]];
if (typeof [keys[i]] === "object") {
obj = obj[keys[i]];
continue;
}
} else { // setting does not exist, use default value
if (defaultValue != undefined) {
result = defaultValue;
} else {
error("Setting '" + keys[i] + "' has no default value and/or does not exist.");
return undefined;
}
}
}
return result;
}
function getRetractParameters() {
var words = []; // store all retracted axes in an array
var retractAxes = new Array(false, false, false);
var method = getProperty("safePositionMethod", "undefined");
if (method == "clearanceHeight") {
if (!is3D()) {
error(localize("Safe retract option 'Clearance Height' is only supported when all operations are along the setup Z-axis."));
}
validate(settings.retract, "Setting 'retract' is required but not defined.");
validate(arguments.length != 0, "No axis specified for getRetractParameters().");
for (i in arguments) {
retractAxes[arguments[i]] = true;
}
if ((retractAxes[0] || retractAxes[1]) && !retracted) { // retract Z first before moving to X/Y home
error(localize("Retracting in X/Y is not possible without being retracted in Z."));
if (retractAxes[0] || retractAxes[1]) {
method = getSetting("retract.methodXY", method);
if (retractAxes[2]) {
method = getSetting("retract.methodZ", method);
// define home positions
var useZeroValues = (settings.retract.useZeroValues && settings.retract.useZeroValues.indexOf(method) != -1);
var _xHome = machineConfiguration.hasHomePositionX() && !useZeroValues ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM);
var _yHome = machineConfiguration.hasHomePositionY() && !useZeroValues ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM);
var _zHome = machineConfiguration.getRetractPlane() != 0 && !useZeroValues ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM);
for (var i = 0; i < arguments.length; ++i) {
switch (arguments[i]) {
case X:
words.push("X" + xyzFormat.format(_xHome));
xOutput.reset();
break;
case Y:
words.push("Y" + xyzFormat.format(_yHome));
yOutput.reset();
break;
case Z:
words.push("Z" + xyzFormat.format(_zHome));
zOutput.reset();
retracted = (typeof skipBlocks == "undefined") ? true : !skipBlocks;
error(localize("Unsupported axis specified for getRetractParameters()."));
return undefined;
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
return {method:method, retractAxes:retractAxes, words:words};
}
/** Returns true when subprogram logic does exist into the post. */
function subprogramsAreSupported() {
return typeof subprogramState != "undefined";
}
// <<<<< INCLUDED FROM include_files/commonFunctions.cpi
// >>>>> INCLUDED FROM include_files/defineMachine.cpi
var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads
function defineMachine() {
var useTCP = true;
if (false) { // note: setup your machine here
var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-120, 120], preference:1, tcp:useTCP});
var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[-360, 360], preference:0, tcp:useTCP});
machineConfiguration = new MachineConfiguration(aAxis, cAxis);
setMachineConfiguration(machineConfiguration);
if (receivedMachineConfiguration) {
warning(localize("The provided CAM machine configuration is overwritten by the postprocessor."));
receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten
}
}
if (!receivedMachineConfiguration) {
// multiaxis settings
if (machineConfiguration.isHeadConfiguration()) {
machineConfiguration.setVirtualTooltip(false); // translate the pivot point to the virtual tool tip for nonTCP rotary heads
}
// retract / reconfigure
var performRewinds = false; // set to true to enable the rewind/reconfigure logic
if (performRewinds) {
machineConfiguration.enableMachineRewinds(); // enables the retract/reconfigure logic
safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock, can be overridden with a property
safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate
safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate
machineConfiguration.setSafeRetractDistance(safeRetractDistance);
machineConfiguration.setSafeRetractFeedrate(safeRetractFeed);
machineConfiguration.setSafePlungeFeedrate(safePlungeFeed);
var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values
machineConfiguration.setRewindStockExpansion(stockExpansion);
}
// multi-axis feedrates
if (machineConfiguration.isMultiAxisConfiguration()) {
machineConfiguration.setMultiAxisFeedrate(
useTCP ? FEED_FPM : getProperty("useDPMFeeds") ? FEED_DPM : FEED_INVERSE_TIME,
9999.99, // maximum output value for inverse time feed rates
getProperty("useDPMFeeds") ? DPM_COMBINATION : INVERSE_MINUTES, // INVERSE_MINUTES/INVERSE_SECONDS or DPM_COMBINATION/DPM_STANDARD
0.5, // tolerance to determine when the DPM feed has changed
1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations
);
setMachineConfiguration(machineConfiguration);
}
/* home positions */
// machineConfiguration.setHomePositionX(toPreciseUnit(0, IN));
// machineConfiguration.setHomePositionY(toPreciseUnit(0, IN));
// machineConfiguration.setRetractPlane(toPreciseUnit(0, IN));
}
}
// <<<<< INCLUDED FROM include_files/defineMachine.cpi
// >>>>> INCLUDED FROM include_files/defineWorkPlane.cpi
validate(settings.workPlaneMethod, "Setting 'workPlaneMethod' is required but not defined.");
function defineWorkPlane(_section, _setWorkPlane) {
var abc = new Vector(0, 0, 0);
if (settings.workPlaneMethod.forceMultiAxisIndexing || !is3D() || machineConfiguration.isMultiAxisConfiguration()) {
if (isPolarModeActive()) {
abc = getCurrentDirection();
} else if (_section.isMultiAxis()) {
forceWorkPlane();
cancelTransformation();
abc = _section.isOptimizedForMachine() ? _section.getInitialToolAxisABC() : _section.getGlobalInitialToolAxis();
} else if (settings.workPlaneMethod.useTiltedWorkplane && settings.workPlaneMethod.eulerConvention != undefined) {
if (settings.workPlaneMethod.eulerCalculationMethod == "machine" && machineConfiguration.isMultiAxisConfiguration()) {
abc = machineConfiguration.getOrientation(getWorkPlaneMachineABC(_section, true)).getEuler2(settings.workPlaneMethod.eulerConvention);
} else {
abc = _section.workPlane.getEuler2(settings.workPlaneMethod.eulerConvention);
}
} else {
abc = getWorkPlaneMachineABC(_section, true);
}
if (_setWorkPlane) {
if (_section.isMultiAxis() || isPolarModeActive()) { // 4-5x simultaneous operations
cancelWorkPlane();
positionABC(abc, true);
} else { // 3x and/or 3+2x operations
setWorkPlane(abc);
}
}
} else {
var remaining = _section.workPlane;
if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) {
error(localize("Tool orientation is not supported."));
return abc;
}
setRotation(remaining);
}
if (currentSection && (currentSection.getId() == _section.getId())) {
tcp.isSupportedByOperation = currentSection.getOptimizedTCPMode() == OPTIMIZE_NONE;
if (!currentSection.isMultiAxis() && (settings.workPlaneMethod.useTiltedWorkplane || isSameDirection(machineConfiguration.getSpindleAxis(), currentSection.workPlane.forward))) {
tcp.isSupportedByOperation = false;
}
}
return abc;
}
// <<<<< INCLUDED FROM include_files/defineWorkPlane.cpi
// >>>>> INCLUDED FROM include_files/getWorkPlaneMachineABC.cpi
validate(settings.machineAngles, "Setting 'machineAngles' is required but not defined.");
function getWorkPlaneMachineABC(_section, rotate) {
var currentABC = isFirstSection() ? new Vector(0, 0, 0) : getCurrentDirection();
var abc = machineConfiguration.getABCByPreference(_section.workPlane, currentABC, settings.machineAngles.controllingAxis, settings.machineAngles.type, settings.machineAngles.options);
if (!isSameDirection(machineConfiguration.getDirection(abc), _section.workPlane.forward)) {
error(localize("Orientation not supported."));
}
if (rotate) {
if (settings.workPlaneMethod.optimizeType == undefined || settings.workPlaneMethod.useTiltedWorkplane) { // legacy
var useTCP = false;
var R = machineConfiguration.getRemainingOrientation(abc, _section.workPlane);
setRotation(useTCP ? _section.workPlane : R);
setCurrentDirection(currentABC); // temporary fix for currentDirection
} else {
if (!_section.isOptimizedForMachine()) {
machineConfiguration.setToolLength(compensateToolLength ? _section.getTool().overallLength : 0); // define the tool length for head adjustments
_section.optimize3DPositionsByMachine(machineConfiguration, abc, settings.workPlaneMethod.optimizeType);
}
}
}
return abc;
}
// <<<<< INCLUDED FROM include_files/getWorkPlaneMachineABC.cpi
// >>>>> INCLUDED FROM include_files/positionABC.cpi
function positionABC(abc, force) {
if (typeof unwindABC == "function") {
unwindABC(abc);
}
if (force) {
forceABC();
}
var a = machineConfiguration.isMultiAxisConfiguration() ? aOutput.format(abc.x) : toolVectorOutputI.format(abc.x);
var b = machineConfiguration.isMultiAxisConfiguration() ? bOutput.format(abc.y) : toolVectorOutputJ.format(abc.y);
var c = machineConfiguration.isMultiAxisConfiguration() ? cOutput.format(abc.z) : toolVectorOutputK.format(abc.z);
if (a || b || c) {
if (!retracted) {
if (typeof moveToSafeRetractPosition == "function") {
moveToSafeRetractPosition();
} else {
writeRetract(Z);
}
}
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
gMotionModal.reset();
writeBlock(gMotionModal.format(0), a, b, c);
if (getCurrentSectionId() != -1) {
setCurrentABC(abc); // required for machine simulation
}
}
}
// <<<<< INCLUDED FROM include_files/positionABC.cpi
// >>>>> INCLUDED FROM include_files/writeWCS.cpi
function writeWCS(section, wcsIsRequired) {
if (section.workOffset != currentWorkOffset) {
if (getSetting("workPlaneMethod.cancelTiltFirst", false) && wcsIsRequired) {
cancelWorkPlane();
}
if (typeof forceWorkPlane == "function" && wcsIsRequired) {
forceWorkPlane();
}
writeStartBlocks(wcsIsRequired, function () {
writeBlock(section.wcs);
});
currentWorkOffset = section.workOffset;
}
}
// <<<<< INCLUDED FROM include_files/writeWCS.cpi
// >>>>> INCLUDED FROM include_files/writeToolCall.cpi
function writeToolCall(tool, insertToolCall) {
var tcPosX = getProperty("tcPositionX");
var tcPosY = getProperty("tcPositionY");
var tcPosZ = getProperty("tcPositionZ");
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
if (typeof forceModals == "function" && (insertToolCall || getProperty("safeStartAllOperations"))) {
forceModals();
}
writeStartBlocks(insertToolCall, function () {
if (!retracted) {
writeRetract(Z);
}
if (!isFirstSection() && insertToolCall) {
if (typeof forceWorkPlane == "function") {
forceWorkPlane();
}
onCommand(COMMAND_COOLANT_OFF); // turn off coolant on tool change
if (typeof disableLengthCompensation == "function") {
disableLengthCompensation(false);
}
}
if (tool.manualToolChange) {
onCommand(COMMAND_STOP);
writeComment("MANUAL TOOL CHANGE TO T" + toolFormat.format(tool.number));
} else {
switch (getProperty("tcMoveType")) {
case "disable":
break;
case "all":
writeBlock(gAbsIncModal.format(90), gFormat.format(52), gMotionModal.format(0), "X" + xyzFormat.format(tcPosX), "Y" + xyzFormat.format(tcPosY), "Z" + xyzFormat.format(tcPosZ));
break;
case "ZX":
writeBlock(gAbsIncModal.format(90), gFormat.format(52), gMotionModal.format(0), "Z" + xyzFormat.format(tcPosZ));
writeBlock(gAbsIncModal.format(90), gFormat.format(52), gMotionModal.format(0), "X" + xyzFormat.format(tcPosX), "Y" + xyzFormat.format(tcPosY));
break;
case "XY":
writeBlock(gAbsIncModal.format(90), gFormat.format(52), gMotionModal.format(0), "X" + xyzFormat.format(tcPosX), "Y" + xyzFormat.format(tcPosY));
break;
}
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
if (!isFirstSection() && getProperty("optionalStop") && insertToolCall) {
onCommand(COMMAND_OPTIONAL_STOP);
}
onCommand(COMMAND_LOAD_TOOL);
}
});
}
// <<<<< INCLUDED FROM include_files/writeToolCall.cpi
// >>>>> INCLUDED FROM include_files/startSpindle.cpi
function startSpindle(tool, insertToolCall) {
if (tool.type != TOOL_PROBE) {
var spindleSpeedIsRequired = insertToolCall || forceSpindleSpeed || isFirstSection() ||
rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent()) ||
(tool.clockwise != getPreviousSection().getTool().clockwise);
writeStartBlocks(spindleSpeedIsRequired, function () {
if (spindleSpeedIsRequired || operationNeedsSafeStart) {
onCommand(COMMAND_START_SPINDLE);
}
});
}
}
// <<<<< INCLUDED FROM include_files/startSpindle.cpi
// >>>>> INCLUDED FROM include_files/coolant.cpi
var currentCoolantMode = COOLANT_OFF;
var coolantOff = undefined;
var isOptionalCoolant = false;
var forceCoolant = false;
function setCoolant(coolant) {
var coolantCodes = getCoolantCodes(coolant);
if (Array.isArray(coolantCodes)) {
writeStartBlocks(!isOptionalCoolant, function () {
if (settings.coolant.singleLineCoolant) {
writeBlock(coolantCodes.join(getWordSeparator()));
} else {
for (var c in coolantCodes) {
writeBlock(coolantCodes[c]);
}
}
});
return undefined;
}
return coolantCodes;
}
function getCoolantCodes(coolant, format) {
isOptionalCoolant = false;
if (typeof operationNeedsSafeStart == "undefined") {
operationNeedsSafeStart = false;
}
var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line
var coolants = settings.coolant.coolants;
if (!coolants) {
error(localize("Coolants have not been defined."));
}
if (tool.type && tool.type == TOOL_PROBE) { // avoid coolant output for probing
coolant = COOLANT_OFF;
}
if (coolant == currentCoolantMode) {
if (operationNeedsSafeStart && coolant != COOLANT_OFF) {
isOptionalCoolant = true;
} else if (!forceCoolant || coolant == COOLANT_OFF) {
return undefined; // coolant is already active
}
}
if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && (coolantOff != undefined) && !forceCoolant && !isOptionalCoolant) {
if (Array.isArray(coolantOff)) {
for (var i in coolantOff) {
multipleCoolantBlocks.push(coolantOff[i]);
}
} else {
multipleCoolantBlocks.push(coolantOff);
}
}
forceCoolant = false;
var m;
var coolantCodes = {};
for (var c in coolants) { // find required coolant codes into the coolants array
if (coolants[c].id == coolant) {
coolantCodes.on = coolants[c].on;
if (coolants[c].off != undefined) {
coolantCodes.off = coolants[c].off;
break;
} else {
for (var i in coolants) {
if (coolants[i].id == COOLANT_OFF) {
coolantCodes.off = coolants[i].off;
break;
}
}
}
}
}
if (coolant == COOLANT_OFF) {
m = !coolantOff ? coolantCodes.off : coolantOff; // use the default coolant off command when an 'off' value is not specified
} else {
coolantOff = coolantCodes.off;
m = coolantCodes.on;
}
if (!m) {
onUnsupportedCoolant(coolant);
m = 9;
} else {
if (Array.isArray(m)) {
for (var i in m) {
multipleCoolantBlocks.push(m[i]);
}
} else {
multipleCoolantBlocks.push(m);
}
currentCoolantMode = coolant;
for (var i in multipleCoolantBlocks) {
if (typeof multipleCoolantBlocks[i] == "number") {
multipleCoolantBlocks[i] = mFormat.format(multipleCoolantBlocks[i]);
}
}
if (format == undefined || format) {
return multipleCoolantBlocks; // return the single formatted coolant value
} else {
return m; // return unformatted coolant value
}
}
return undefined;
}
// <<<<< INCLUDED FROM include_files/coolant.cpi
// >>>>> INCLUDED FROM include_files/writeProgramHeader.cpi
function writeProgramHeader() {
// dump machine configuration
var vendor = machineConfiguration.getVendor();
var model = machineConfiguration.getModel();
var mDescription = machineConfiguration.getDescription();
if (getProperty("writeMachine") && (vendor || model || mDescription)) {
writeComment(localize("Machine"));
if (vendor) {
writeComment(" " + localize("vendor") + ": " + vendor);
}
if (model) {
writeComment(" " + localize("model") + ": " + model);
}
if (mDescription) {
writeComment(" " + localize("description") + ": " + mDescription);
}
}
// dump tool information
if (getProperty("writeTools")) {
if (false) { // set to true to use the post kernel version of the tool list
writeToolTable(TOOL_NUMBER_COL);
} else {
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);
}
}
}
}
}
// <<<<< INCLUDED FROM include_files/writeProgramHeader.cpi
// >>>>> INCLUDED FROM include_files/onRapid_fanuc.cpi
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."));
writeBlock(gMotionModal.format(0), x, y, z);
forceFeed();
// <<<<< INCLUDED FROM include_files/onRapid_fanuc.cpi
// >>>>> INCLUDED FROM include_files/onRapid5D_fanuc.cpi
function onRapid5D(_x, _y, _z, _a, _b, _c) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation mode cannot be changed at rapid traversal."));
return;
}
if (!currentSection.isOptimizedForMachine()) {
forceXYZ();
}
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = currentSection.isOptimizedForMachine() ? aOutput.format(_a) : toolVectorOutputI.format(_a);
var b = currentSection.isOptimizedForMachine() ? bOutput.format(_b) : toolVectorOutputJ.format(_b);
var c = currentSection.isOptimizedForMachine() ? cOutput.format(_c) : toolVectorOutputK.format(_c);
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
if (x || y || z || a || b || c) {
writeBlock(gMotionModal.format(0), x, y, z, a, b, c);
forceFeed();
}
}
// <<<<< INCLUDED FROM include_files/onRapid5D_fanuc.cpi
// >>>>> INCLUDED FROM include_files/onLinear5D_fanuc.cpi
function onLinear5D(_x, _y, _z, _a, _b, _c, feed, feedMode) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation cannot be activated/deactivated for 5-axis move."));
return;
}
if (!currentSection.isOptimizedForMachine()) {
forceXYZ();
}
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = currentSection.isOptimizedForMachine() ? aOutput.format(_a) : toolVectorOutputI.format(_a);
var b = currentSection.isOptimizedForMachine() ? bOutput.format(_b) : toolVectorOutputJ.format(_b);
var c = currentSection.isOptimizedForMachine() ? cOutput.format(_c) : toolVectorOutputK.format(_c);
if (feedMode == FEED_INVERSE_TIME) {
forceFeed();
}
var f = feedMode == FEED_INVERSE_TIME ? inverseTimeOutput.format(feed) : getFeed(feed);
var fMode = feedMode == FEED_INVERSE_TIME ? 93 : getProperty("useG95") ? 95 : 94;
if (x || y || z || a || b || c) {
writeBlock(gFeedModeModal.format(fMode), gMotionModal.format(1), x, y, z, a, b, c, f);
} else if (f) {
if (getNextRecord().isMotion()) { // try not to output feed without motion
forceFeed(); // force feed on next line
} else {
writeBlock(gFeedModeModal.format(fMode), gMotionModal.format(1), f);
}
}
}
// <<<<< INCLUDED FROM include_files/onLinear5D_fanuc.cpi
// >>>>> INCLUDED FROM include_files/workPlaneFunctions_fanuc.cpi
var currentWorkPlaneABC = undefined;
function forceWorkPlane() {
currentWorkPlaneABC = undefined;
}
function cancelWorkPlane(force) {
if (typeof gRotationModal != "undefined") {
if (force) {
gRotationModal.reset();
}
writeBlock(gRotationModal.format(69)); // cancel frame
}
forceWorkPlane();
}
function setWorkPlane(abc) {
if (!settings.workPlaneMethod.forceMultiAxisIndexing && is3D() && !machineConfiguration.isMultiAxisConfiguration()) {
return; // ignore
}
var workplaneIsRequired = (currentWorkPlaneABC == undefined) ||
abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) ||
abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) ||
abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z);
writeStartBlocks(workplaneIsRequired, function () {
if (!retracted) {
writeRetract(Z);
}
if (settings.workPlaneMethod.useTiltedWorkplane) {
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
if (settings.workPlaneMethod.cancelTiltFirst) {
cancelWorkPlane();
}
if (machineConfiguration.isMultiAxisConfiguration()) {
var machineABC = abc.isNonZero() ? (currentSection.isMultiAxis() ? getCurrentDirection() : getWorkPlaneMachineABC(currentSection, false)) : abc;
if (settings.workPlaneMethod.useABCPrepositioning || machineABC.isZero()) {
positionABC(machineABC, false);
} else {
setCurrentABC(machineABC);
}
}
if (abc.isNonZero()) {
gRotationModal.reset();
writeBlock(
gRotationModal.format(68.2), "X" + xyzFormat.format(currentSection.workOrigin.x), "Y" + xyzFormat.format(currentSection.workOrigin.y), "Z" + xyzFormat.format(currentSection.workOrigin.z),
"I" + abcFormat.format(abc.x), "J" + abcFormat.format(abc.y), "K" + abcFormat.format(abc.z)
); // set frame
writeBlock(gFormat.format(53.1)); // turn machine
} else {
if (!settings.workPlaneMethod.cancelTiltFirst) {
cancelWorkPlane();
}
}
} else {
positionABC(abc, true);
}
if (!currentSection.isMultiAxis()) {
onCommand(COMMAND_LOCK_MULTI_AXIS);
}
currentWorkPlaneABC = abc;
});
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
// <<<<< INCLUDED FROM include_files/workPlaneFunctions_fanuc.cpi
// >>>>> INCLUDED FROM include_files/initialPositioning_fanuc.cpi
/**
* Writes the initial positioning procedure for a section to get to the start position of the toolpath.
* @param {Vector} position The initial position to move to
* @param {boolean} isRequired true: Output full positioning, false: Output full positioning in optional state or output simple positioning only
* @param {String} codes1 Allows to add additional code to the first positioning line
* @param {String} codes2 Allows to add additional code to the second positioning line (if applicable)
* @example
var myVar1 = formatWords("T" + tool.number, currentSection.wcs);
var myVar2 = getCoolantCodes(tool.coolant);
writeInitialPositioning(initialPosition, isRequired, myVar1, myVar2);
*/
function writeInitialPositioning(position, isRequired, codes1, codes2) {
var motionCode = (highFeedMapping != HIGH_FEED_NO_MAPPING) ? 1 : 0;
var feed = (highFeedMapping != HIGH_FEED_NO_MAPPING) ? getFeed(highFeedrate) : "";
var gOffset = getSetting("outputToolLengthCompensation", true) ? gFormat.format(getOffsetCode()) : "";
var hOffset = getSetting("outputToolLengthOffset", true) ? hFormat.format(tool.lengthOffset) : "";
var additionalCodes = [formatWords(codes1), formatWords(codes2)];
forceModals(gMotionModal);
writeStartBlocks(isRequired, function() {
var modalCodes = formatWords(gAbsIncModal.format(90), gPlaneModal.format(17));
if (typeof disableLengthCompensation == "function") {
disableLengthCompensation(false); // cancel tool length compensation prior to enabling it, required when switching G43/G43.4 modes
}
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
// multi axis prepositioning with TWP
if (currentSection.isMultiAxis() && getSetting("workPlaneMethod.prepositionWithTWP", true) && getSetting("workPlaneMethod.useTiltedWorkplane", false) &&
tcp.isSupportedByOperation && getCurrentDirection().isNonZero()) {
var W = machineConfiguration.isMultiAxisConfiguration() ? machineConfiguration.getOrientation(getCurrentDirection()) :
Matrix.getOrientationFromDirection(getCurrentDirection());
var prePosition = W.getTransposed().multiply(position);
var angles = W.getEuler2(settings.workPlaneMethod.eulerConvention);
setWorkPlane(angles);
writeBlock(modalCodes, gMotionModal.format(motionCode), xOutput.format(prePosition.x), yOutput.format(prePosition.y), feed, additionalCodes[0]);
cancelWorkPlane();
writeBlock(gOffset, hOffset, additionalCodes[1]); // omit Z-axis output is desired
lengthCompensationActive = true;
forceAny(); // required to output XYZ coordinates in the following line
} else {
if (machineConfiguration.isHeadConfiguration()) {
writeBlock(modalCodes, gMotionModal.format(motionCode), gOffset,
xOutput.format(position.x), yOutput.format(position.y), zOutput.format(position.z),
hOffset, feed, additionalCodes
);
} else {
writeBlock(modalCodes, gMotionModal.format(motionCode), xOutput.format(position.x), yOutput.format(position.y), feed, additionalCodes[0]);
writeBlock(gMotionModal.format(motionCode), gOffset, zOutput.format(position.z), hOffset, additionalCodes[1]);
}
lengthCompensationActive = true;
}
forceModals(gMotionModal);
if (isRequired) {
additionalCodes = []; // clear additionalCodes buffer
}
});
validate(lengthCompensationActive, "Tool length compensation is not active."); // make sure that lenght compensation is enabled
if (!isRequired) { // simple positioning
var modalCodes = formatWords(gAbsIncModal.format(90), gPlaneModal.format(17));
if (!retracted && xyzFormat.getResultingValue(getCurrentPosition().z) < xyzFormat.getResultingValue(position.z)) {
writeBlock(modalCodes, gMotionModal.format(motionCode), zOutput.format(position.z), feed);
}
forceXYZ();
writeBlock(modalCodes, gMotionModal.format(motionCode), xOutput.format(position.x), yOutput.format(position.y), feed, additionalCodes);
}
}
Matrix.getOrientationFromDirection = function (ijk) {
var forward = ijk;
var unitZ = new Vector(0, 0, 1);
var W;
if (Math.abs(Vector.dot(forward, unitZ)) < 0.5) {
var imX = Vector.cross(forward, unitZ).getNormalized();
W = new Matrix(imX, Vector.cross(forward, imX), forward);
} else {
var imX = Vector.cross(new Vector(0, 1, 0), forward).getNormalized();
W = new Matrix(imX, Vector.cross(forward, imX), forward);
}
return W;
};
// <<<<< INCLUDED FROM include_files/initialPositioning_fanuc.cpi
// >>>>> INCLUDED FROM include_files/getOffsetCode_fanuc.cpi
function getOffsetCode() {
// assumes a head configuration uses TCP on a Fanuc controller
var offsetCode = 43;
if (currentSection.isMultiAxis()) {
if (machineConfiguration.isMultiAxisConfiguration() && tcp.isSupportedByOperation) {
offsetCode = 43.4;
} else if (!machineConfiguration.isMultiAxisConfiguration()) {
offsetCode = 43.5;
}
}
return offsetCode;