Você está na página 1de 27

/**

Copyright (C) 2012-2014 by Autodesk, Inc.


All rights reserved.
Siemens SINUMERIK 840D post processor configuration.
$Revision: 37892 $
$Date: 2014-10-09 13:42:35 +0200 (to, 09 okt 2014) $
FORKID {75AF44EA-0A42-4803-8DE7-43BF08B352B3}
*/
description = "Siemens SINUMERIK 840D";
vendor = "Autodesk, Inc.";
vendorUrl = "http://www.autodesk.com";
legal = "Copyright (C) 2012-2013 by Autodesk, Inc.";
certificationLevel = 2;
minimumRevision = 24000;
extension = "mpf";
setCodePage("ascii");
tolerance = spatial(0.002, MM);
minimumChordLength = spatial(0.01, MM);
minimumCircularRadius = spatial(0.01, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
var useArcTurn = false;
maximumCircularSweep = toRad(useArcTurn ? (999 * 360) : 270); // max revolutions
allowHelicalMoves = true;
allowedCircularPlanes = undefined; // allow any circular motion

// user-defined properties
properties = {
writeMachine: true, // write machine
writeTools: true, // writes the tools
preloadTool: true, // preloads next tool on tool change if any
showSequenceNumbers: true, // show sequence numbers
sequenceNumberStart: 10, // first sequence number
sequenceNumberIncrement: 1, // increment for sequence numbers
optionalStop: true, // optional stop
useShortestDirection: true, // specifies that shortest angular direction shoul
d be used
useParametricFeed: false, // specifies that feed should be output using Q valu
es
showNotes: false, // specifies that operation notes should be output.
useCIP: false, // enable to use the CIP command
useCycle832: false, // enable to use CYCLE832
toolAsName: false // specifies if the tool should be called with a number or w
ith the tool description
};

var gFormat = createFormat({prefix:"G", decimals:0});


var mFormat = createFormat({prefix:"M", decimals:0});
var hFormat = createFormat({prefix:"H", decimals:0});

var dFormat = createFormat({prefix:"D", decimals:0});


var nFormat = createFormat({prefix:"N", decimals:0});
var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4)});
var abcFormat = createFormat({decimals:3, scale:DEG});
var abcDirectFormat = createFormat({decimals:3, scale:DEG, prefix:"=DC(", suffix
:")"});
var feedFormat = createFormat({decimals:(unit == MM ? 1 : 2)});
var toolFormat = createFormat({decimals:0});
var rpmFormat = createFormat({decimals:0});
var secFormat = createFormat({decimals:3});
var taperFormat = createFormat({decimals:1, scale:DEG});
var arFormat = createFormat({decimals:3, scale:DEG});
var
var
var
var
var
var
var
var
var
var
var
var

xOutput = createVariable({prefix:"X"}, xyzFormat);


yOutput = createVariable({prefix:"Y"}, xyzFormat);
zOutput = createVariable({prefix:"Z"}, xyzFormat);
a3Output = createVariable({prefix:"A3=", force:true}, xyzFormat);
b3Output = createVariable({prefix:"B3=", force:true}, xyzFormat);
c3Output = createVariable({prefix:"C3=", force:true}, xyzFormat);
aOutput = createVariable({prefix:"A"}, abcFormat);
bOutput = createVariable({prefix:"B"}, abcFormat);
cOutput = createVariable({prefix:"C"}, abcFormat);
feedOutput = createVariable({prefix:"F"}, feedFormat);
sOutput = createVariable({prefix:"S"}, rpmFormat);
dOutput = createVariable({}, dFormat);

// circular
var iOutput
var jOutput
var kOutput

output
= createReferenceVariable({prefix:"I", force:true}, xyzFormat);
= createReferenceVariable({prefix:"J", force:true}, xyzFormat);
= createReferenceVariable({prefix:"K", force:true}, xyzFormat);

var gMotionModal = createModal({force:true}, gFormat); // modal group 1 // G0-G3


, ...
var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gF
ormat); // modal group 2 // G17-19
var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G94-95
var gUnitModal = createModal({}, gFormat); // modal group 6 // G70-71
// fixed settings
var firstFeedParameter = 1;
var WARNING_WORK_OFFSET = 0;
var WARNING_LENGTH_OFFSET = 1;
var WARNING_DIAMETER_OFFSET = 2;
// collected state
var sequenceNumber;
var currentWorkOffset;
var forceSpindleSpeed = false;
var activeMovements; // do not use by default
var currentFeedId;

/**
Writes the specified block.
*/

function writeBlock() {
if (properties.showSequenceNumbers) {
writeWords2("N" + sequenceNumber, arguments);
sequenceNumber += properties.sequenceNumberIncrement;
} else {
writeWords(arguments);
}
}
function formatComment(text) {
return "; " + String(text);
}
/**
Output a comment.
*/
function writeComment(text) {
if (properties.showSequenceNumbers) {
writeWords2("N" + sequenceNumber, formatComment(text));
sequenceNumber += properties.sequenceNumberIncrement;
} else {
writeWords(formatComment(text));
}
}
function onOpen() {
if (false) {
var aAxis = createAxis({coordinate:0, table:true, axis:[1, 0, 0], range:[-12
0.0001,120.0001], preference:1});
//var bAxis = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[120.0001,120.0001], preference:1});
var cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, 1], range:[0,3
60], cyclic:true});
machineConfiguration = new MachineConfiguration(aAxis, cAxis);
setMachineConfiguration(machineConfiguration);
optimizeMachineAngles2(0);
}
if (properties.useShortestDirection) {
// abcFormat and abcDirectFormat must be compatible except for =DC()
if (machineConfiguration.isMachineCoordinate(0)) {
if (machineConfiguration.getAxisByCoordinate(0).isCyclic() || isSameDirect
ion(machineConfiguration.getAxisByCoordinate(0).getAxis(), machineConfiguration.
getSpindleAxis())) {
aOutput = createVariable({prefix:"A"}, abcDirectFormat);
}
}
if (machineConfiguration.isMachineCoordinate(1)) {
if (machineConfiguration.getAxisByCoordinate(1).isCyclic() || isSameDirect
ion(machineConfiguration.getAxisByCoordinate(1).getAxis(), machineConfiguration.
getSpindleAxis())) {
bOutput = createVariable({prefix:"B"}, abcDirectFormat);
}
}
if (machineConfiguration.isMachineCoordinate(2)) {
if (machineConfiguration.getAxisByCoordinate(2).isCyclic() || isSameDirect
ion(machineConfiguration.getAxisByCoordinate(2).getAxis(), machineConfiguration.
getSpindleAxis())) {
cOutput = createVariable({prefix:"C"}, abcDirectFormat);

}
}
}
if (!machineConfiguration.isMachineCoordinate(0)) {
aOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(1)) {
bOutput.disable();
}
if (!machineConfiguration.isMachineCoordinate(2)) {
cOutput.disable();
}
sequenceNumber = properties.sequenceNumberStart;
// if (!((programName.length >= 2) && (isAlpha(programName[0]) || (programName
[0] == "_")) && isAlpha(programName[1]))) {
// error(localize("Program name must begin with 2 letters."));
// }
writeln("; %_N_" + translateText(String(programName).toUpperCase(), " ", "_")
+ "_MPF");
if (programComment) {
writeComment(programComment);
}
// dump machine configuration
var vendor = machineConfiguration.getVendor();
var model = machineConfiguration.getModel();
var description = machineConfiguration.getDescription();
if (properties.writeMachine && (vendor || model || description)) {
writeComment(localize("Machine"));
if (vendor) {
writeComment(" " + localize("vendor") + ": " + vendor);
}
if (model) {
writeComment(" " + localize("model") + ": " + model);
}
if (description) {
writeComment(" " + localize("description") + ": " + description);
}
}
// dump tool information
if (properties.writeTools) {
var zRanges = {};
if (is3D()) {
var numberOfSections = getNumberOfSections();
for (var i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
var zRange = section.getGlobalZRange();
var tool = section.getTool();
if (zRanges[tool.number]) {
zRanges[tool.number].expandToRange(zRange);
} else {
zRanges[tool.number] = zRange;
}
}
}

var tools = getToolTable();


if (tools.getNumberOfTools() > 0) {
for (var i = 0; i < tools.getNumberOfTools(); ++i) {
var tool = tools.getTool(i);
var comment = "T" + (properties.toolAsName ? "=" + "\"" + (tool.descrip
tion.toUpperCase()) + "\"" : 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.tap
erAngle) + localize("deg");
}
if (zRanges[tool.number]) {
comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[t
ool.number].getMinimum());
}
comment += " - " + getToolTypeName(tool.type);
writeComment(comment);
}
}
}
if (false) { // stock - workpiece
var workpiece = getWorkpiece();
var delta = Vector.diff(workpiece.upper, workpiece.lower);
if (delta.isNonZero()) {
writeBlock(
"WORKPIECE" + "(" + ",,," + "\"" + "BOX" + "\"" + "," + "112" + "," + x
yzFormat.format(workpiece.upper.z) + "," + xyzFormat.format(workpiece.lower.z) +
"," + "80" +
"," + xyzFormat.format(workpiece.upper.x) + "," + xyzFormat.format(workp
iece.upper.y) + "," + xyzFormat.format(workpiece.lower.x) + "," + xyzFormat.form
at(workpiece.lower.y) + ")"
);
}
}
// absolute coordinates and feed per min
writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94));
switch (unit) {
case IN:
writeBlock(gUnitModal.format(70));
//writeBlock(gFormat.format(700));
break;
case MM:
writeBlock(gUnitModal.format(71));
//writeBlock(gFormat.format(710));
break;
}

// lengths
// feeds
// lengths
// feeds

writeBlock(gFormat.format(64)); // continuous-path mode


writeBlock(gPlaneModal.format(17));
}
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();
}
/** Force output of X, Y, Z, A, B, C, and F on next output. */
function forceAny() {
forceXYZ();
forceABC();
feedOutput.reset();
}
function onParameter(name, value) {
}
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
}
currentFeedId = feedContext.id;
feedOutput.reset();
return "F=R" + (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 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"), getParameter("o
peration: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"), getParameter("o
peration:tool_feedCutting"));
activeMovements[MOVEMENT_PREDRILL] = feedContext;
activeFeeds.push(feedContext);
}
++id;
}
if (hasParameter("operation:finishFeedrate")) {
if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
var feedContext = new FeedContext(id, localize("Finish"), getParameter("op
eration: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"), getParameter("op
eration: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"), getParameter("ope
ration: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"), getParameter("oper
ation: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"), getParameter("op
eration: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(getPara
meter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), g
etParameter("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"), getParameter("o
peration:reducedFeedrate"));
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_REDUCED] = feedContext;
}
++id;
}
if (hasParameter("operation:tool_feedRamp")) {
if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << M
OVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) {
var feedContext = new FeedContext(id, localize("Ramping"), getParameter("o
peration: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"), getParameter("op
eration: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.highFeed
rate);
activeFeeds.push(feedContext);
activeMovements[MOVEMENT_HIGH_FEED] = feedContext;
}
++id;
}
for (var i = 0; i < activeFeeds.length; ++i) {
var feedContext = activeFeeds[i];
writeBlock("R" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.fo
rmat(feedContext.feed), formatComment(feedContext.description));
}

}
var currentWorkPlaneABC = undefined;
var currentWorkPlaneABCTurned = false;
function forceWorkPlane() {
currentWorkPlaneABC = undefined;
}
function setWorkPlane(abc, turn) {
if (is3D() && !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) ||
(!currentWorkPlaneABCTurned && turn))) {
return; // no change
}
currentWorkPlaneABC = abc;
currentWorkPlaneABCTurned = turn;
if (turn) {
onCommand(COMMAND_UNLOCK_MULTI_AXIS);
}
var
ly in
var
var
var
var
var
var
var
var
var
var
var
var
var

FR = 1; // 0 = without moving to safety plane, 1 = move to safety plane on


Z, 2 = move to safety plane Z,X,Y
TC = "";
ST = 0;
MODE = 27;
X0 = 0;
Y0 = 0;
Z0 = 0;
A = abc.x;
B = abc.y;
C = abc.z;
X1 = 0;
Y1 = 0;
Z1 = 0;
DIR = turn ? -1 : 0; // direction

writeBlock(
"CYCLE800(" +
FR + "," +
"\"" + TC + "\"," +
ST + "," +
MODE + "," +
xyzFormat.format(X0) + "," +
xyzFormat.format(Y0) + "," +
xyzFormat.format(Z0) + "," +
abcFormat.format(C) + "," +
abcFormat.format(B) + "," +
abcFormat.format(A) + "," +
xyzFormat.format(X1) + "," +
xyzFormat.format(Y1) + "," +
xyzFormat.format(Z1) + "," +
DIR + ")"

);
forceABC();
forceXYZ();
if (turn) {
//if (!currentSection.isMultiAxis()) {
onCommand(COMMAND_LOCK_MULTI_AXIS);
//}
}
}
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" + abcForma
t.format(abc.x))
+ conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcForma
t.format(abc.y))
+ conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcForma
t.format(abc.z))
);
}
var direction = machineConfiguration.getDirection(abc);
if (!isSameDirection(direction, W.forward)) {
error(localize("Orientation not supported."));
}
if (!machineConfiguration.isABCSupported(abc)) {
error(
localize("Work plane is not supported") + ":"
+ conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcForma
t.format(abc.x))
+ conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcForma
t.format(abc.y))
+ conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcForma
t.format(abc.z))
);
}
var tcp = true;

if (tcp) {
setRotation(W); // TCP mode
} else {
var O = machineConfiguration.getOrientation(abc);
var R = machineConfiguration.getRemainingOrientation(abc, W);
setRotation(R);
}
return abc;
}
function onSection() {
if (properties.toolAsName && !tool.description) {
if (hasParameter("operation-comment")) {
error(localize("Tool description is empty in operation " + "\"" + (getPara
meter("operation-comment").toUpperCase()) + "\""));
} else {
error(localize("Tool description is empty."));
}
return;
}
var insertToolCall = isFirstSection() ||
currentSection.getForceToolChange && currentSection.getForceToolChange() ||
(tool.number != getPreviousSection().getTool().number) ||
conditional(properties.toolAsName, tool.description != getPreviousSection().
getTool().description);
var retracted = false; // specifies that the tool has been retracted to the sa
fe plane
var newWorkOffset = isFirstSection() ||
(getPreviousSection().workOffset != currentSection.workOffset); // work offs
et changes
var newWorkPlane = isFirstSection() ||
!isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSecti
on.getGlobalInitialToolAxis());
if (insertToolCall || newWorkOffset || newWorkPlane) {
// retract to safe plane
retracted = true;
writeBlock(gMotionModal.format(0), "SUPA", "Z" + machineConfiguration.getRet
ractPlane(), "D0"); // retract
zOutput.reset();
if (newWorkPlane) {
setWorkPlane(new Vector(0, 0, 0), false); // reset working plane
}
}
writeln("");
if (hasParameter("operation-comment")) {
var comment = getParameter("operation-comment");
if (comment) {
writeComment(comment);
}
}
if (properties.showNotes && hasParameter("notes")) {
var notes = 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);
}
}
}
}
if (insertToolCall) {
forceWorkPlane();
retracted = true;
onCommand(COMMAND_COOLANT_OFF);
if (!isFirstSection() && properties.optionalStop) {
onCommand(COMMAND_OPTIONAL_STOP);
}
if (tool.number > 99999999) {
warning(localize("Tool number exceeds maximum value."));
}
var lengthOffset = tool.lengthOffset;
if (lengthOffset > 99) {
error(localize("Length offset out of range."));
return;
}
writeBlock("T" + (properties.toolAsName ? "=" + "\"" + (tool.description.to
UpperCase()) + "\"" : toolFormat.format(tool.number)), dFormat.format(lengthOffs
et));
writeBlock(mFormat.format(6));
if (tool.comment) {
writeComment(tool.comment);
}
var showToolZMin = false;
if (showToolZMin) {
if (is3D()) {
var numberOfSections = getNumberOfSections();
var zRange = currentSection.getGlobalZRange();
var number = tool.number;
for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) {
var section = getSection(i);
if (section.getTool().number != number) {
break;
}
zRange.expandToRange(section.getGlobalZRange());
}
writeComment(localize("ZMIN") + "=" + zRange.getMinimum());
}
}
if (properties.preloadTool) {
var nextTool = (properties.toolAsName ? getNextToolDescription(tool.descri
ption) : getNextTool(tool.number));
if (nextTool) {
writeBlock("T" + (properties.toolAsName ? "=" + "\"" + (nextTool.descri

ption.toUpperCase()) + "\"" : toolFormat.format(nextTool.number)));


} else {
// preload first tool
var section = getSection(0);
var firstToolNumber = section.getTool().number;
var firstToolDescription = section.getTool().description;
if (properties.toolAsName) {
if (tool.description != firstToolDescription) {
writeBlock("T=" + "\"" + (firstToolDescription.toUpperCase()) + "\""
);
}
} else {
if (tool.number != firstToolNumber) {
writeBlock("T" + toolFormat.format(firstToolNumber));
}
}
}
}
}
if (properties.useCycle832) {
if (hasParameter("operation-strategy") && (getParameter("operation-strategy"
) == "drill")) {
writeBlock("CYCLE832()");
} else if (hasParameter("operation:tolerance")) {
var tolerance = Math.max(getParameter("operation:tolerance"), 0);
if (tolerance > 0) {
var workMode = 1;
var stockToLeaveThreshold = toPreciseUnit(0.1, MM);
if ((hasParameter("operation:stockToLeave") && (getParameter("operation:
stockToLeave") < stockToLeaveThreshold)) ||
(hasParameter("operation:verticalStockToLeave") && (getParameter("op
eration:verticalStockToLeave") < stockToLeaveThreshold))) {
workMode = 1;
} else {
workMode = 2;
}
writeBlock("CYCLE832(" + xyzFormat.format(tolerance) + ", 11200" + workM
ode + ")");
} else {
writeBlock("CYCLE832()");
}
} else {
writeBlock("CYCLE832()");
}
}
if (insertToolCall ||
forceSpindleSpeed ||
isFirstSection() ||
(rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) ||
(tool.clockwise != getPreviousSection().getTool().clockwise)) {
forceSpindleSpeed = false;
if (tool.spindleRPM < 1) {
error(localize("Spindle speed out of range."));
return;
}
if (tool.spindleRPM > 99999) {
warning(localize("Spindle speed exceeds maximum value."));

}
writeBlock(
sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4)
);
}
// wcs
var workOffset = currentSection.workOffset;
if (workOffset == 0) {
warningOnce(localize("Work offset has not been specified. Using G54 as WCS."
), WARNING_WORK_OFFSET);
workOffset = 1;
}
if (workOffset > 0) {
if (workOffset > 4) {
var code = 500 + workOffset - 4 + 4;
if (code > 599) {
error(localize("Work offset out of range."));
return;
}
if (workOffset != currentWorkOffset) {
writeBlock(gFormat.format(code));
currentWorkOffset = workOffset;
}
} else {
if (workOffset != currentWorkOffset) {
writeBlock(gFormat.format(53 + workOffset)); // G54->G59
currentWorkOffset = workOffset;
}
}
}
forceXYZ();
if (!is3D() || machineConfiguration.isMultiAxisConfiguration()) { // use 5-axi
s indexing for multi-axis mode
// set working plane after datum shift
var abc = new Vector(0, 0, 0);
cancelTransformation();
if (!currentSection.isMultiAxis()) {
abc = currentSection.workPlane.getTransposed().eulerZYX_R;
abc = new Vector(-abc.x, -abc.y, -abc.z);
}
setWorkPlane(abc, true); // turn
} else { // pure 3D
var remaining = currentSection.workPlane;
if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) {
error(localize("Tool orientation is not supported."));
return;
}
setRotation(remaining);
}
forceAny();
if (!currentSection.isMultiAxis()) {
onCommand(COMMAND_LOCK_MULTI_AXIS);
}
if (retracted && !insertToolCall) {

var lengthOffset = tool.lengthOffset;


if (lengthOffset > 99) {
error(localize("Length offset out of range."));
return;
}
writeBlock(dFormat.format(lengthOffset));
}
if (currentSection.isMultiAxis()) {
forceWorkPlane();
cancelTransformation();
// turn machine
if (currentSection.isOptimizedForMachine()) {
var abc = currentSection.getInitialToolAxisABC();
writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), aOutput.format
(abc.x), bOutput.format(abc.y), cOutput.format(abc.z));
} else {
var d = currentSection.getGlobalInitialToolAxis();
var a3 = a3Output.format(d.x);
var b3 = b3Output.format(d.y);
var c3 = c3Output.format(d.z);
writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), a3, b3, c3);
}
writeBlock("TRAORI");
var initialPosition = getFramePosition(currentSection.getInitialPosition());
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y),
zOutput.format(initialPosition.z)
);
} else {
var initialPosition = getFramePosition(currentSection.getInitialPosition());
if (!retracted) {
if (getCurrentPosition().z < initialPosition.z) {
writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z));
}
}
if (insertToolCall) {
if (tool.lengthOffset != 0) {
warningOnce(localize("Length offset is not supported."), WARNING_LENGTH_
OFFSET);
}
if (!machineConfiguration.isHeadConfiguration()) {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.for
mat(initialPosition.y)
);
var z = zOutput.format(initialPosition.z);
if (z) {
writeBlock(gMotionModal.format(0), z);
}
} else {
writeBlock(

gAbsIncModal.format(90),
gMotionModal.format(0),
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y),
zOutput.format(initialPosition.z)
);
}
} else {
writeBlock(
gAbsIncModal.format(90),
gMotionModal.format(0),
xOutput.format(initialPosition.x),
yOutput.format(initialPosition.y)
);
}
}
// set coolant after we have positioned at Z
if (insertToolCall) {
forceCoolant();
}
setCoolant(tool.coolant);
if (properties.useParametricFeed &&
hasParameter("operation-strategy") &&
(getParameter("operation-strategy") != "drill")) {
if (!insertToolCall &&
activeMovements &&
(getCurrentSectionId() > 0) &&
(getPreviousSection().getPatternId() == currentSection.getPatternId()))
{
// use the current feeds
} else {
initializeActiveFeeds();
}
} else {
activeMovements = undefined;
}
if (insertToolCall) {
gPlaneModal.reset();
}
}
function getNextToolDescription(description) {
var currentSectionId = getCurrentSectionId();
if (currentSectionId < 0) {
return null;
}
for (var i = currentSectionId + 1; i < getNumberOfSections(); ++i) {
var section = getSection(i);
var sectionTool = section.getTool();
if (description != sectionTool.description) {
return sectionTool; // found next tool
}
}
return null; // not found
}
function onDwell(seconds) {

if (seconds > 0) {
writeBlock(gFormat.format(4), "F" + secFormat.format(seconds));
}
}
function onSpindleSpeed(spindleSpeed) {
writeBlock(sOutput.format(spindleSpeed));
}
var expandCurrentCycle = false;
function onCycle() {
writeBlock(gPlaneModal.format(17));
expandCurrentCycle = false;
if ((cycleType != "tapping") &&
(cycleType != "right-tapping") &&
(cycleType != "left-tapping")) {
writeBlock(feedOutput.format(cycle.feedrate));
}
var RTP = cycle.clearance; // return plane (absolute)
var RFP = cycle.stock; // reference plane (absolute)
var SDIS = cycle.retract - cycle.stock; // safety distance
var DP = cycle.bottom; // depth (absolute)
// var DPR = RFP - cycle.bottom; // depth (relative to reference plane)
var DTB = cycle.dwell;
var SDIR = tool.clockwise ? 3 : 4; // direction of rotation: M3:3 and M4:4
switch (cycleType) {
case "drilling":
writeBlock(
"MCALL CYCLE81(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ + ")"
);
break;
case "counter-boring":
writeBlock(
"MCALL CYCLE82(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) + ")"
);
break;
case "chip-breaking":
// add support for accumulated depth
var FDEP = cycle.stock - cycle.incrementalDepth;
var FDPR = cycle.incrementalDepth; // relative to reference plane (unsigned)
var DAM = 0; // degression (unsigned)
var DTS = 0; // dwell time at start
var FRF = 1; // feedrate factor (unsigned)
var VARI = 0; // chip breaking
var _AXN = 3; // tool axis
var _MDEP = cycle.incrementalDepth; // minimum drilling depth
var _VRT = 0; // retraction distance

var _DTD = (cycle.dwell != undefined) ? cycle.dwell : 0;


var _DIS1 = 0; // limit distance
writeBlock(
"MCALL CYCLE83(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + xyzFormat.format(FDEP) +
", " /*+ xyzFormat.format(FDPR)*/ +
", " + xyzFormat.format(DAM) +
", " + /*conditional(DTB > 0, secFormat.format(DTB))*/ // only dwell at bo
ttom
", " + conditional(DTS > 0, secFormat.format(DTS)) +
", " + xyzFormat.format(FRF) +
", " + xyzFormat.format(VARI) +
", " + /*_AXN +*/
", " + xyzFormat.format(_MDEP) +
", " + xyzFormat.format(_VRT) +
", " + secFormat.format(_DTD) +
", 0" + /*xyzFormat.format(_DIS1) +*/
")"
);
break;
case "deep-drilling":
var FDEP = cycle.stock - cycle.incrementalDepth;
var FDPR = cycle.incrementalDepth; // relative to reference plane (unsigned)
var DAM = 0; // degression (unsigned)
var DTS = 0; // dwell time at start
var FRF = 1; // feedrate factor (unsigned)
var VARI = 1; // full retract
var _MDEP = cycle.incrementalDepth; // minimum drilling depth
var _VRT = 0; // retraction distance
var _DTD = (cycle.dwell != undefined) ? cycle.dwell : 0;
var _DIS1 = 0; // limit distance
writeBlock(
"MCALL CYCLE83(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + xyzFormat.format(FDEP) +
", " /*+ xyzFormat.format(FDPR)*/ +
", " + xyzFormat.format(DAM) +
", " + /*conditional(DTB > 0, secFormat.format(DTB)) +*/ // only dwell at
bottom
", " + conditional(DTS > 0, secFormat.format(DTS)) +
", " + xyzFormat.format(FRF) +
", " + xyzFormat.format(VARI) +
", " + /*_AXN +*/
", " + xyzFormat.format(_MDEP) +
", " + xyzFormat.format(_VRT) +
", " + secFormat.format(_DTD) +
", 0" + /*xyzFormat.format(_DIS1) +*/
")"
);
break;
case "tapping":
case "left-tapping":
case "right-tapping":

var SDAC = SDIR; // direction of rotation after end of cycle


var MPIT = 0; // thread pitch as thread size
var PIT = ((tool.type == TOOL_TAP_LEFT_HAND) ? -1 : 1) * tool.threadPitch; /
/ thread pitch
var POSS = 0; // spindle position for oriented spindle stop in cycle (in deg
rees)
var SST = tool.spindleRPM; // speed for tapping
var SST1 = tool.spindleRPM; // speed for return
writeBlock(
"MCALL CYCLE84(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) +
", " + xyzFormat.format(SDAC) +
", " + xyzFormat.format(MPIT) +
", " + xyzFormat.format(PIT) +
", " + xyzFormat.format(POSS) +
", " + xyzFormat.format(SST) +
", " + xyzFormat.format(SST1) + ")"
);
break;
case "reaming":
var FFR = cycle.feedrate;
var RFF = cycle.retractFeedrate;
writeBlock(
"MCALL CYCLE85(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) +
", " + xyzFormat.format(FFR) +
", " + xyzFormat.format(RFF) + ")"
);
break;
case "stop-boring":
if (cycle.dwell > 0) {
expandCurrentCycle = true;
} else {
writeBlock(
"MCALL CYCLE87(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + SDIR + ")"
);
}
break;
case "fine-boring":
var RPA = 0; // return path in abscissa of the active plane (enter increment
ally with)
var RPO = 0; // return path in the ordinate of the active plane (enter incre
mentally sign)
var RPAP = 0; // return plane in the applicate (enter incrementally with sig
n)
var POSS = 0; // spindle position for oriented spindle stop in cycle (in deg
rees)

writeBlock(
"MCALL CYCLE86(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) +
", " + SDIR +
", " + xyzFormat.format(RPA) +
", " + xyzFormat.format(RPO) +
", " + xyzFormat.format(RPAP) +
", " + xyzFormat.format(POSS) + ")"
);
break;
case "back-boring":
expandCurrentCycle = true;
break;
case "manual-boring":
writeBlock(
"MCALL CYCLE88(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) +
", " + SDIR + ")"
);
break;
case "boring":
// retract feed is ignored
writeBlock(
"MCALL CYCLE89(" + xyzFormat.format(RTP) +
", " + xyzFormat.format(RFP) +
", " + xyzFormat.format(SDIS) +
", " + xyzFormat.format(DP) +
", " /*+ xyzFormat.format(DPR)*/ +
", " + conditional(DTB > 0, secFormat.format(DTB)) + ")"
);
break;
default:
expandCurrentCycle = true;
}
if (!expandCurrentCycle) {
xOutput.reset();
yOutput.reset();
}
}
function onCyclePoint(x, y, z) {
if (!expandCurrentCycle) {
var _x = xOutput.format(x);
var _y = yOutput.format(y);
/*zOutput.format(z)*/
if (_x || _y) {
writeBlock(_x, _y);
}
} else {
expandCyclePoint(x, y, z);
}
}

function onCycleEnd() {
if (!expandCurrentCycle) {
writeBlock("MCALL"); // end modal cycle
}
zOutput.reset();
}
var pendingRadiusCompensation = -1;
function onRadiusCompensation() {
pendingRadiusCompensation = radiusCompensation;
}
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 traver
sal."));
return;
}
writeBlock(gMotionModal.format(0), x, y, z);
feedOutput.reset();
}
}
function onLinear(_x, _y, _z, feed) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var f = getFeed(feed);
if (x || y || z) {
if (pendingRadiusCompensation >= 0) {
pendingRadiusCompensation = -1;
if (tool.diameterOffset != 0) {
warningOnce(localize("Diameter offset is not supported."), WARNING_DIAME
TER_OFFSET);
}
writeBlock(gPlaneModal.format(17));
switch (radiusCompensation) {
case RADIUS_COMPENSATION_LEFT:
writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z,
break;
case RADIUS_COMPENSATION_RIGHT:
writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z,
break;
default:
writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z,
}
} else {
writeBlock(gMotionModal.format(1), x, y, z, f);
}
} else if (f) {
if (getNextRecord().isMotion()) { // try not to output feed without
feedOutput.reset(); // force feed on next line
} else {

f);
f);
f);

motion

writeBlock(gMotionModal.format(1), f);
}
}
}
function onRapid5D(_x, _y, _z, _a, _b, _c) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation mode cannot be changed at rapid traversa
l."));
return;
}
if (currentSection.isOptimizedForMachine()) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = aOutput.format(_a);
var b = bOutput.format(_b);
var c = cOutput.format(_c);
writeBlock(gMotionModal.format(0), x, y, z, a, b, c);
} else {
forceXYZ(); // required
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a3 = a3Output.format(_a);
var b3 = b3Output.format(_b);
var c3 = c3Output.format(_c);
writeBlock(gMotionModal.format(0), x, y, z, a3, b3, c3);
}
feedOutput.reset();
}
function onLinear5D(_x, _y, _z, _a, _b, _c, feed) {
if (pendingRadiusCompensation >= 0) {
error(localize("Radius compensation cannot be activated/deactivated for 5-ax
is move."));
return;
}
if (currentSection.isOptimizedForMachine()) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var a = aOutput.format(_a);
var b = bOutput.format(_b);
var c = cOutput.format(_c);
var f = getFeed(feed);
if (x || y || z || a || b || c) {
writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f);
} else if (f) {
if (getNextRecord().isMotion()) { // try not to output feed without motion
feedOutput.reset(); // force feed on next line
} else {
writeBlock(gMotionModal.format(1), f);
}
}
} else {
forceXYZ(); // required
var x = xOutput.format(_x);
var y = yOutput.format(_y);

var z = zOutput.format(_z);
var a3 = a3Output.format(_a);
var b3 = b3Output.format(_b);
var c3 = c3Output.format(_c);
var f = getFeed(feed);
if (x || y || z || a || b || c) {
writeBlock(gMotionModal.format(1), x, y, z, a3, b3, c3, f);
} else if (f) {
if (getNextRecord().isMotion()) { // try not to output feed without motion
feedOutput.reset(); // force feed on next line
} else {
writeBlock(gMotionModal.format(1), f);
}
}
}
}
function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
writeBlock(gPlaneModal.format(17));
var start = getCurrentPosition();
var turns = useArcTurn ? Math.floor(Math.abs(getCircularSweep())/(2 * Math.PI)
) : 0; // full turns
if (isFullCircle()) {
if (isHelical()) {
linearize(tolerance);
return;
}
if (turns > 1) {
error(localize("Multiple turns are not supported."));
return;
}
// G90/G91 are dont care when we do not used XYZ
switch (getCircularPlane()) {
case PLANE_XY:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {
if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1
7)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));
return;
}
}
writeBlock(gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - sta
rt.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed));
break;
case PLANE_ZX:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {
if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1
8)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));
return;
}
}
writeBlock(gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - sta
rt.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
break;
case PLANE_YZ:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {

if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1


9)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));
return;
}
}
writeBlock(gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - sta
rt.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
break;
default:
linearize(tolerance);
}
} else if (useArcTurn) { // IJK mode
switch (getCircularPlane()) {
case PLANE_XY:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {
if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1
7)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));
return;
}
}
// arFormat.format(Math.abs(getCircularSweep()));
if (turns > 0) {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed), "TURN=" + turns);
} else {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed));
}
break;
case PLANE_ZX:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {
if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1
8)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));
return;
}
}
if (turns > 0) {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed), "TURN=" + turns);
} else {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
}
break;
case PLANE_YZ:
if (radiusCompensation != RADIUS_COMPENSATION_OFF) {
if ((gPlaneModal.getCurrent() != null) && (gPlaneModal.getCurrent() != 1
9)) {
error(localize("Plane cannot be changed when radius compensation is ac
tive."));

return;
}
}
if (turns > 0) {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), jOutput.format(cy start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed), "TURN=" + turns);
} else {
writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 :
3), xOutput.format(x), yOutput.format(y), zOutput.format(z), jOutput.format(cy start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
}
break;
default:
if (turns > 1) {
error(localize("Multiple turns are not supported."));
return;
}
if (properties.useCIP) { // allow CIP
var ip = getPositionU(0.5);
writeBlock(
gAbsIncModal.format(90), "CIP",
xOutput.format(x),
yOutput.format(y),
zOutput.format(z),
"I1=" + xyzFormat.format(ip.x),
"J1=" + xyzFormat.format(ip.y),
"K1=" + xyzFormat.format(ip.z),
getFeed(feed)
);
gMotionModal.reset();
gPlaneModal.reset();
} else {
linearize(tolerance);
}
}
} else { // use radius mode
var r = getCircularRadius();
if (toDeg(getCircularSweep()) > (180 + 1e-9)) {
r = -r; // allow up to <360 deg arcs
}
switch (getCircularPlane()) {
case PLANE_XY:
forceXYZ();
writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOut
put.format(y), zOutput.format(z), "CR=" + xyzFormat.format(r), getFeed(feed));
break;
case PLANE_ZX:
forceXYZ();
writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOut
put.format(y), zOutput.format(z), "CR=" + xyzFormat.format(r), getFeed(feed));
break;
case PLANE_YZ:
forceXYZ();
writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOut
put.format(y), zOutput.format(z), "CR=" + xyzFormat.format(r), getFeed(feed));
break;
default:
linearize(tolerance);
}

}
}
var currentCoolantMode = undefined;
function forceCoolant() {
currentCoolantMode = undefined;
}
function setCoolant(coolant) {
if (coolant == currentCoolantMode) {
return; // coolant is already active
}
var m;
switch (coolant) {
case COOLANT_OFF:
m = 9;
break;
case COOLANT_FLOOD:
m = 8;
break;
default:
onUnsupportedCoolant(coolant);
m = 9;
}
if (m) {
writeBlock(mFormat.format(m));
currentCoolantMode = coolant;
}
}
var mapCommand = {
COMMAND_STOP:0,
COMMAND_OPTIONAL_STOP:1,
COMMAND_END:30,
COMMAND_SPINDLE_CLOCKWISE:3,
COMMAND_SPINDLE_COUNTERCLOCKWISE:4,
COMMAND_STOP_SPINDLE:5,
COMMAND_ORIENTATE_SPINDLE:19,
COMMAND_LOAD_TOOL:6
};
function onCommand(command) {
switch (command) {
case COMMAND_STOP:
writeBlock(mFormat.format(0));
forceSpindleSpeed = true;
return;
case COMMAND_COOLANT_OFF:
setCoolant(COOLANT_OFF);
return;
case COMMAND_COOLANT_ON:
setCoolant(COOLANT_FLOOD);
return;
case COMMAND_START_SPINDLE:
onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNT
ERCLOCKWISE);
return;

case COMMAND_LOCK_MULTI_AXIS:
return;
case COMMAND_UNLOCK_MULTI_AXIS:
return;
case COMMAND_START_CHIP_TRANSPORT:
return;
case COMMAND_STOP_CHIP_TRANSPORT:
return;
case COMMAND_BREAK_CONTROL:
return;
case COMMAND_TOOL_MEASURE:
return;
}
var stringId = getCommandStringId(command);
var mcode = mapCommand[stringId];
if (mcode != undefined) {
writeBlock(mFormat.format(mcode));
} else {
onUnsupportedCommand(command);
}
}
function onSectionEnd() {
if (currentSection.isMultiAxis()) {
writeBlock("TRAFOOF");
}
writeBlock(gPlaneModal.format(17));
forceAny();
}
function onClose() {
writeln("");
writeBlock(gMotionModal.format(0), "SUPA", "Z" + machineConfiguration.getRetra
ctPlane(), "D0"); // retract
setWorkPlane(new Vector(0, 0, 0), true); // reset working plane
var homeX;
if (machineConfiguration.hasHomePositionX()) {
homeX = "X" + xyzFormat.format(machineConfiguration.getHomePositionX());
}
var homeY;
if (machineConfiguration.hasHomePositionY()) {
homeY = "Y" + xyzFormat.format(machineConfiguration.getHomePositionY());
}
if (homeX || homeY) {
writeBlock(
gMotionModal.format(0), "SUPA", homeX, homeY
);
}
onImpliedCommand(COMMAND_END);
onImpliedCommand(COMMAND_STOP_SPINDLE);
writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off
}

Você também pode gostar