Escolar Documentos
Profissional Documentos
Cultura Documentos
// 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
};
// 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);
/**
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;
}
}
}
// lengths
// feeds
// lengths
// feeds
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;
}
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
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) {
}
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) {
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
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) {
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
}