diff --git a/Haas_Lathes_BIDC/Bechtel ST-20.cps b/Haas_Lathes_BIDC/Bechtel ST-20.cps index 51df0fd..2e52c7a 100644 --- a/Haas_Lathes_BIDC/Bechtel ST-20.cps +++ b/Haas_Lathes_BIDC/Bechtel ST-20.cps @@ -410,7 +410,7 @@ staticProperties = { safeStartAllOperations: true, useYAxisForDrilling: false, useG187: false, - postVersion: "BIDC-ST0.G10.K21", + postVersion: "BIDC-ST0-v1.1.0", }; const MAXTOOLS = 12; @@ -2174,6 +2174,7 @@ function onSection() { } if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { + writeComment("Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor."); throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." } diff --git a/Haas_Lathes_BIDC/Bechtel ST-20Y.cps b/Haas_Lathes_BIDC/Bechtel ST-20Y.cps index cb49205..f0e1e4d 100644 --- a/Haas_Lathes_BIDC/Bechtel ST-20Y.cps +++ b/Haas_Lathes_BIDC/Bechtel ST-20Y.cps @@ -410,7 +410,7 @@ staticProperties = { safeStartAllOperations: true, useYAxisForDrilling: false, useG187: false, - postVersion: "BIDC-STY.G11.K21-1" + postVersion: "BIDC-STY-v1.1.0" }; var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-"; @@ -2279,6 +2279,7 @@ function onSection() { } if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { + writeComment("Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor."); throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." } diff --git a/Haas_Lathes_BIDC/haas turning.cps b/Haas_Lathes_BIDC/haas turning.cps deleted file mode 100644 index c15ffe5..0000000 --- a/Haas_Lathes_BIDC/haas turning.cps +++ /dev/null @@ -1,1725 +0,0 @@ -/** - Copyright (C) 2012-2019 by Autodesk, Inc. - All rights reserved. - - HAAS Lathe post processor configuration. - - $Revision: 42631 621a6aaa12feb9f27eb24e2b06cf85758a41d354 $ - $Date: 2020-01-21 14:14:08 $ -*/ - -description = "HAAS Turning"; -vendor = "Haas Automation"; -vendorUrl = "https://www.haascnc.com"; -legal = "Copyright (C) 2012-2019 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 40783; - -longDescription = "Generic HAAS turning post. Turn on the property 'manualToolChange' if your CNC does not have an automatic tool changer. Use Turret 0 for Positional Turret, Turret 101 for QCTP on X- Post, Turret 102 for QCTP on X+ Post, Turret 103 for Gang Tooling on X- Post, Turret 104 for Gang Tooling on X+ Tool Post."; - -extension = "nc"; -programNameIsInteger = true; -setCodePage("ascii"); - -capabilities = CAPABILITY_TURNING; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(355); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion -allowSpiralMoves = true; -highFeedrate = (unit == IN) ? 100 : 5000; - -// user-defined properties -properties = { - writeMachine: false, // write machine - writeTools: false, // writes the tools - showSequenceNumbers: true, // show sequence numbers - sequenceNumberStart: 10, // first sequence number - sequenceNumberIncrement: 1, // increment for sequence numbers - optionalStop: true, // optional stop - separateWordsWithSpace: true, // specifies that the words should be separated with a white space - useRadius: false, // specifies that arcs should be output using the radius (R word) instead of the I, J, and K words. - maximumSpindleSpeed: 100 * 60, // specifies the maximum spindle speed - useParametricFeed: false, // specifies that feed should be output using Q values - showNotes: false, // specifies that operation notes should be output. - useCycles: true, // specifies that drilling cycles should be used. - manualToolChange: false, // specifies that the machine does not have a tool changer. - g53HomePositionX: 0, // home position for X-axis - g53HomePositionZ: 0, // home position for Z-axis - useTailStock: false, // specifies to use the tailstock or not - gotChipConveyor: true // specifies to use a chip conveyor Y/N -}; - -propertyDefinitions = { - writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, - writeTools: {title:"Write tool list", description:"Output a tool list in the header of the code.", group:0, type:"boolean"}, - showSequenceNumbers: {title:"Use sequence numbers", description:"Use sequence numbers for each block of outputted code.", group:1, type:"boolean"}, - sequenceNumberStart: {title:"Start sequence number", description:"The number at which to start the sequence numbers.", group:1, type:"integer"}, - sequenceNumberIncrement: {title:"Sequence number increment", description:"The amount by which the sequence number is incremented by in each block.", group:1, type:"integer"}, - optionalStop: {title:"Optional stop", description:"Specifies that optional stops M1 should be output at tool changes.", type:"boolean"}, - separateWordsWithSpace: {title:"Separate words with space", description:"Adds spaces between words if 'yes' is selected.", type:"boolean"}, - useRadius: {title:"Radius arcs", description:"If yes is selected, arcs are output using radius values rather than IJK.", type:"boolean"}, - maximumSpindleSpeed: {title:"Maximum spindle speed", description:"The maximum spindle speed in RPM.", type:"integer"}, - useParametricFeed: {title:"Parametric feed", description:"Parametric feed values based on movement type are output.", type:"boolean"}, - showNotes: {title:"Show notes", description:"Enable to output notes for operations.", type:"boolean"}, - useCycles: {title:"Use canned cycles", description:"Enable to output canned cycles.", type:"boolean"}, - manualToolChange: {title:"Manual tool changer", description:"Enable to do manual tool changes when the CNC doesn't have an automatic tool changer.", type:"boolean"}, - g53HomePositionX: {title:"G53 home Position X", description:"G53 X-axis home position.", type:"number"}, - g53HomePositionZ: {title:"G53 home Position Z", description:"G53 Z-axis home position.", type:"number"}, - useTailStock: {title:"Use tail stock", description:"Enable to use the tail stock.", type:"boolean"}, - gotChipConveyor: {title:"Got chip conveyor", description:"Specifies whether to use a chip conveyor.", type:"boolean", presentation:"yesno"} -}; - -var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-"; - -var gFormat = createFormat({prefix:"G", decimals:0}); -var mFormat = createFormat({prefix:"M", decimals:0}); - -var spatialFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var xFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:2}); // diameter mode -var yFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var zFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var rFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); // radius -var feedFormat = createFormat({decimals:(unit == MM ? 4 : 5), forceDecimal:true}); -var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var xOutput = createVariable({prefix:"X"}, xFormat); -var yOutput = createVariable({prefix:"Y"}, yFormat); -var zOutput = createVariable({prefix:"Z"}, zFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var pOutput = createVariable({prefix:"P", force:true}, rpmFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I", force:true}, spatialFormat); -var jOutput = createReferenceVariable({prefix:"J", force:true}, spatialFormat); -var kOutput = createReferenceVariable({prefix:"K", force:true}, spatialFormat); - -var g92IOutput = createVariable({prefix:"I"}, zFormat); // no scaling - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G98-99 -var gSpindleModeModal = createModal({}, gFormat); // modal group 5 // G96-97 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... - -// fixed settings -var firstFeedParameter = 100; -var gotSecondarySpindle = true; -var gotDoorControl = true; -var gotTailStock = true; -var gotBarFeeder = true; - -var WARNING_WORK_OFFSET = 0; - -var QCTP = 0; -var TURRET = 1; -var GANG = 2; - -var FRONT = -1; -var REAR = 1; - -// collected state -var sequenceNumber; -var currentWorkOffset; -var optionalSection = false; -var forceSpindleSpeed = false; -var activeMovements; // do not use by default -var currentFeedId; -var maximumCircularRadiiDifference = toPreciseUnit(0.005, MM); -var toolingData; -var previousToolingData; - -function getCode(code) { - switch (code) { - // case "PART_CATCHER_ON": - // return mFormat.format(SPECIFY YOUR CODE HERE); - // case "PART_CATCHER_OFF": - // return mFormat.format(SPECIFY YOUR CODE HERE); - case "TAILSTOCK_ON": - return mFormat.format(21); - case "TAILSTOCK_OFF": - return mFormat.format(22); - // case "ENGAGE_C_AXIS": - // machineState.cAxisIsEngaged = true; - // return cAxisEngageModal.format(UNSUPPORTED); - // case "DISENGAGE_C_AXIS": - // machineState.cAxisIsEngaged = false; - // return cAxisEngageModal.format(UNSUPPORTED); - // case "POLAR_INTERPOLATION_ON": - // return gPolarModal.format(UNSUPPORTED); - // case "POLAR_INTERPOLATION_OFF": - // return gPolarModal.format(UNSUPPORTED); - // case "STOP_LIVE_TOOL": - // machineState.liveToolIsActive = false; - // return mFormat.format(UNSUPPORTED); - // case "STOP_MAIN_SPINDLE": - // machineState.mainSpindleIsActive = false; - // return mFormat.format(UNSUPPORTED); - // case "STOP_SUB_SPINDLE": - // machineState.subSpindleIsActive = false; - // return mFormat.format(UNSUPPORTED); - // case "START_LIVE_TOOL_CW": - // machineState.liveToolIsActive = true; - // return mFormat.format(UNSUPPORTED); - // case "START_LIVE_TOOL_CCW": - // machineState.liveToolIsActive = true; - // return mFormat.format(UNSUPPORTED); - case "START_MAIN_SPINDLE_CW": - // machineState.mainSpindleIsActive = true; - return mFormat.format(3); - case "START_MAIN_SPINDLE_CCW": - // machineState.mainSpindleIsActive = true; - return mFormat.format(4); - case "START_SUB_SPINDLE_CW": - // machineState.subSpindleIsActive = true; - return mFormat.format(143); - case "START_SUB_SPINDLE_CCW": - // machineState.subSpindleIsActive = true; - return mFormat.format(144); - // case "MAIN_SPINDLE_BRAKE_ON": - // machineState.mainSpindleBrakeIsActive = true; - // return cAxisBrakeModal.format(UNSUPPORTED); - // case "MAIN_SPINDLE_BRAKE_OFF": - // machineState.mainSpindleBrakeIsActive = false; - // return cAxisBrakeModal.format(UNSUPPORTED); - // case "SUB_SPINDLE_BRAKE_ON": - // machineState.subSpindleBrakeIsActive = true; - // return cAxisBrakeModal.format(UNSUPPORTED); - // case "SUB_SPINDLE_BRAKE_OFF": - // machineState.subSpindleBrakeIsActive = false; - // return cAxisBrakeModal.format(UNSUPPORTED); - case "FEED_MODE_UNIT_REV": - return gFeedModeModal.format(99); - case "FEED_MODE_UNIT_MIN": - return gFeedModeModal.format(98); - case "CONSTANT_SURFACE_SPEED_ON": - return gSpindleModeModal.format(96); - case "CONSTANT_SURFACE_SPEED_OFF": - return gSpindleModeModal.format(97); - // case "MAINSPINDLE_AIR_BLAST_ON": - // return mFormat.format(UNSUPPORTED); - // case "MAINSPINDLE_AIR_BLAST_OFF": - // return mFormat.format(UNSUPPORTED); - // case "SUBSPINDLE_AIR_BLAST_ON": - // return mFormat.format(UNSUPPORTED); - // case "SUBSPINDLE_AIR_BLAST_OFF": - // return mFormat.format(UNSUPPORTED); - // case "CLAMP_PRIMARY_CHUCK": - // return mFormat.format(UNSUPPORTED); - // case "UNCLAMP_PRIMARY_CHUCK": - // return mFormat.format(UNSUPPORTED); - // case "CLAMP_SECONDARY_CHUCK": - // return mFormat.format(UNSUPPORTED); - // case "UNCLAMP_SECONDARY_CHUCK": - // return mFormat.format(UNSUPPORTED); - // case "SPINDLE_SYNCHRONIZATION_ON": - // machineState.spindleSynchronizationIsActive = true; - // return gSynchronizedSpindleModal.format(UNSUPPORTED); - // case "SPINDLE_SYNCHRONIZATION_OFF": - // machineState.spindleSynchronizationIsActive = false; - // return gSynchronizedSpindleModal.format(UNSUPPORTED); - // case "START_CHIP_TRANSPORT": - // return mFormat.format(UNSUPPORTED); - // case "STOP_CHIP_TRANSPORT": - // return mFormat.format(UNSUPPORTED); - // case "OPEN_DOOR": - // return mFormat.format(UNSUPPORTED); - // case "CLOSE_DOOR": - // return mFormat.format(UNSUPPORTED); - case "COOLANT_FLOOD_ON": - return mFormat.format(8); - case "COOLANT_FLOOD_OFF": - return mFormat.format(9); - case "COOLANT_AIR_ON": - return mFormat.format(83); - case "COOLANT_AIR_OFF": - return mFormat.format(84); - case "COOLANT_THROUGH_TOOL_ON": - return mFormat.format(88); - case "COOLANT_THROUGH_TOOL_OFF": - return mFormat.format(89); - case "COOLANT_OFF": - return mFormat.format(9); - default: - error(localize("Command " + code + " is not defined.")); - return 0; - } -} - -/** - Writes the specified block. -*/ -function writeBlock() { - var text = formatWords(arguments); - if (!text) { - return; - } - if (properties.showSequenceNumbers) { - if (optionalSection) { - if (text) { - writeWords("/", "N" + sequenceNumber, text); - } - } else { - writeWords2("N" + sequenceNumber, arguments); - } - sequenceNumber += properties.sequenceNumberIncrement; - } else { - if (optionalSection) { - writeWords2("/", arguments); - } else { - writeWords(arguments); - } - } -} - -/** - Writes the specified optional block. -*/ -function writeOptionalBlock() { - if (properties.showSequenceNumbers) { - var words = formatWords(arguments); - if (words) { - writeWords("/", "N" + sequenceNumber, words); - sequenceNumber += properties.sequenceNumberIncrement; - } - } else { - writeWords2("/", arguments); - } -} - -function formatComment(text) { - return "(" + String(text).replace(/[()]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text)); -} - -function onOpen() { - if (properties.useRadius) { - maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC - } - - yOutput.disable(); - - if (highFeedrate <= 0) { - error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal.")); - return; - } - - if (!properties.separateWordsWithSpace) { - setWordSeparator(""); - } - - sequenceNumber = properties.sequenceNumberStart; - writeln("%"); - - if (programName) { - var programId; - try { - programId = getAsInt(programName); - } catch (e) { - error(localize("Program name must be a number.")); - return; - } - if (!((programId >= 1) && (programId <= 9999))) { - error(localize("Program number is out of range.")); - return; - } - var oFormat = createFormat({width:4, zeropad:true, decimals:0}); - if (programComment) { - writeln("O" + oFormat.format(programId) + " (" + filterText(String(programComment).toUpperCase(), permittedCommentChars) + ")"); - } else { - writeln("O" + oFormat.format(programId)); - } - } else { - error(localize("Program name has not been specified.")); - return; - } - - // 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); - } - } - - if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { - for (var i = 0; i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset > 0) { - error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); - return; - } - } - } - - // dump tool information - if (properties.writeTools) { - var zRanges = {}; - if (is3D()) { - var numberOfSections = getNumberOfSections(); - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - var zRange = section.getGlobalZRange(); - var tool = section.getTool(); - if (zRanges[tool.number]) { - zRanges[tool.number].expandToRange(zRange); - } else { - zRanges[tool.number] = zRange; - } - } - } - - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - var compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset; - var comment = "T" + toolFormat.format(tool.number * 100 + compensationOffset % 100) + " " + - (tool.diameter != 0 ? "D=" + spatialFormat.format(tool.diameter) + " " : "") + - (tool.isTurningTool() ? localize("NR") + "=" + spatialFormat.format(tool.noseRadius) : localize("CR") + "=" + spatialFormat.format(tool.cornerRadius)) + - (tool.taperAngle > 0 && (tool.taperAngle < Math.PI) ? " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg") : "") + - (zRanges[tool.number] ? " - " + localize("ZMIN") + "=" + spatialFormat.format(zRanges[tool.number].getMinimum()) : "") + - " - " + localize(getToolTypeName(tool.type)); - writeComment(comment); - } - } - } - - // absolute coordinates and feed per min - writeBlock(getCode("FEED_MODE_UNIT_MIN"), gPlaneModal.format(18)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } - - var usesPrimarySpindle = false; - var usesSecondarySpindle = false; - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.getType() != TYPE_TURNING) { - continue; - } - switch (section.spindle) { - case SPINDLE_PRIMARY: - usesPrimarySpindle = true; - break; - case SPINDLE_SECONDARY: - usesSecondarySpindle = true; - break; - } - } - if (usesPrimarySpindle) { - writeBlock(gFormat.format(50), sOutput.format(properties.maximumSpindleSpeed)); - sOutput.reset(); - } - if (gotSecondarySpindle) { - if (usesSecondarySpindle) { - writeBlock(gFormat.format(50), pOutput.format(properties.maximumSpindleSpeed)); - pOutput.reset(); - } - } - - onCommand(COMMAND_START_CHIP_TRANSPORT); -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); -} - -/** Force output of X, Y, Z, and F on next output. */ -function forceAny() { - forceXYZ(); - forceFeed(); -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return "F#" + (firstFeedParameter + feedContext.id); - } - } - currentFeedId = undefined; // force Q feed next time - } - return feedOutput.format(f); // use feed value -} - -function initializeActiveFeeds() { - activeMovements = new Array(); - var movements = currentSection.getMovements(); - var feedPerRev = currentSection.feedMode == FEED_PER_REVOLUTION; - - var id = 0; - var activeFeeds = new Array(); - if (hasParameter("operation:tool_feedCutting")) { - if (movements & ((1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED))) { - var feedContext = new FeedContext(id, localize("Cutting"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting")); - activeMovements[MOVEMENT_PREDRILL] = feedContext; - activeFeeds.push(feedContext); - } - ++id; - } - - if (hasParameter("operation:finishFeedrate")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var finishFeedrateRel; - if (hasParameter("operation:finishFeedrateRel")) { - finishFeedrateRel = getParameter("operation:finishFeedrateRel"); - } else if (hasParameter("operation:finishFeedratePerRevolution")) { - finishFeedrateRel = getParameter("operation:finishFeedratePerRevolution"); - } - var feedContext = new FeedContext(id, localize("Finish"), feedPerRev ? finishFeedrateRel : getParameter("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), feedPerRev ? getParameter("operation:tool_feedEntryRel") : getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), feedPerRev ? getParameter("operation:tool_feedExitRel") : getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), feedPerRev ? getParameter("operation:noEngagementFeedrateRel") : getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting") && - hasParameter("operation:tool_feedEntry") && - hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext( - id, - localize("Direct"), - Math.max( - feedPerRev ? getParameter("operation:tool_feedCuttingRel") : getParameter("operation:tool_feedCutting"), - feedPerRev ? getParameter("operation:tool_feedEntryRel") : getParameter("operation:tool_feedEntry"), - feedPerRev ? getParameter("operation:tool_feedExitRel") : getParameter("operation:tool_feedExit") - ) - ); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), feedPerRev ? getParameter("operation:reducedFeedrateRel") : getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), feedPerRev ? getParameter("operation:tool_feedRampRel") : getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), feedPerRev ? getParameter("operation:tool_feedPlungeRel") : getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if (movements & (1 << MOVEMENT_HIGH_FEED)) { - var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - } - ++id; - } - - for (var i = 0; i < activeFeeds.length; ++i) { - var feedContext = activeFeeds[i]; - writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description)); - } -} - -function getSpindle() { - if (getNumberOfSections() == 0) { - return SPINDLE_PRIMARY; - } - if (getCurrentSectionId() < 0) { - return getSection(getNumberOfSections() - 1).spindle == 0; - } - if (currentSection.getType() == TYPE_TURNING) { - return currentSection.spindle; - } else { - if (isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { - return SPINDLE_PRIMARY; - } else if (isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, -1))) { - if (!gotSecondarySpindle) { - error(localize("Secondary spindle is not available.")); - } - return SPINDLE_SECONDARY; - } else { - return SPINDLE_PRIMARY; - } - } -} - -function ToolingData(_tool) { - switch (_tool.turret) { - // Positional Turret - case 0: - this.tooling = TURRET; - this.toolPost = REAR; - break; - // QCTP X- - case 101: - this.tooling = QCTP; - this.toolPost = FRONT; - break; - // QCTP X+ - case 102: - this.tooling = QCTP; - this.toolPost = REAR; - break; - // Gang Tooling X- - case 103: - this.tooling = GANG; - this.toolPost = FRONT; - break; - // Gang Tooling X+ - case 104: - this.tooling = GANG; - this.toolPost = REAR; - break; - default: - error(localize("Turret number must be 0 (main turret), 101 (QCTP X-), 102 (QCTP X+, 103 (gang tooling X-), or 104 (gang tooling X+).")); - break; - } - this.number = _tool.number; - this.comment = _tool.comment; - this.toolLength = _tool.bodyLength; - // HSMWorks returns 0 in tool.bodyLength - if ((tool.bodyLength == 0) && hasParameter("operation:tool_bodyLength")) { - this.toolLength = getParameter("operation:tool_bodyLength"); - } -} - -function onSection() { - if (currentSection.getType() != TYPE_TURNING) { - if (!hasParameter("operation-strategy") || (getParameter("operation-strategy") != "drill")) { - if (currentSection.getType() == TYPE_MILLING) { - error(localize("Milling toolpath is not supported.")); - } else { - error(localize("Non-turning toolpath is not supported.")); - } - return; - } - } - - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var turning = (currentSection.getType() == TYPE_TURNING); - - var insertToolCall = forceToolAndRetract || isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number) || - (tool.compensationOffset != getPreviousSection().getTool().compensationOffset) || - (tool.diameterOffset != getPreviousSection().getTool().diameterOffset) || - (tool.lengthOffset != getPreviousSection().getTool().lengthOffset); - - var retracted = false; // specifies that the tool has been retracted to the safe plane - var newSpindle = isFirstSection() || - (getPreviousSection().spindle != currentSection.spindle); - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()); - - // determine which tooling holder is used - if (!isFirstSection()) { - previousToolingData = toolingData; - } - toolingData = new ToolingData(tool); - toolingData.operationComment = ""; - if (hasParameter("operation-comment")) { - toolingData.operationComment = getParameter("operation-comment"); - } - toolingData.toolChange = insertToolCall; - if (isFirstSection()) { - previousToolingData = toolingData; - } - - // turning using front tool post - if (toolingData.toolPost == FRONT) { - xFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:-2}); - xOutput = createVariable({prefix:"X"}, xFormat); - iFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:-1}); // radius mode - iOutput = createReferenceVariable({prefix:"I"}, iFormat); - - // turning using rear tool post - } else { - xFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:2}); - xOutput = createVariable({prefix:"X"}, xFormat); - iFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true, scale:1}); // radius mode - iOutput = createReferenceVariable({prefix:"I"}, iFormat); - } - - if (insertToolCall || newSpindle || newWorkOffset || newWorkPlane) { - - // retract to safe plane - retracted = true; - if (!isFirstSection() && insertToolCall) { - onCommand(COMMAND_COOLANT_OFF); - } - //writeBlock(gFormat.format(53), gMotionModal.format(0), "Z" + zFormat.format(properties.g53HomePositionZ)); // retract - //zOutput.reset(); - writeBlock(gFormat.format(28)); // retract - xOutput.reset(); - } - - 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) { - retracted = true; - gFeedModeModal.reset(); - - if (!isFirstSection() && properties.optionalStop) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if (tool.number > 99) { - warning(localize("Tool number exceeds maximum value.")); - } - - if ((toolingData.tooling == QCTP) || tool.getManualToolChange()) { - var comment = formatComment(localize("CHANGE TO T") + tool.number + " " + localize("ON") + " " + - localize((toolingData.toolPost == REAR) ? "REAR TOOL POST" : "FRONT TOOL POST")); - writeBlock(mFormat.format(0), comment); - } - - var compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset; - if (compensationOffset > 99) { - error(localize("Compensation offset is out of range.")); - return; - } - writeBlock("T" + toolFormat.format(tool.number * 100 + compensationOffset)); - if (tool.comment) { - writeComment(tool.comment); - } - if (tool.manualToolChange || properties.manualToolChange) { - onCommand(COMMAND_STOP); - writeComment("MANUAL TOOL CHANGE TO T" + toolFormat.format(tool.number * 100 + compensationOffset)); - } - } - - if (newSpindle) { - // select spindle if required - } - - // see page 138 in 96-8700an for stock transfer / G199/G198 - if (currentSection.feedMode == FEED_PER_REVOLUTION) { - writeBlock(getCode("FEED_MODE_UNIT_REV")); - } else { - writeBlock(getCode("FEED_MODE_UNIT_MIN")); - } - - if (insertToolCall || - newSpindle || - isFirstSection() || - (isSpindleSpeedDifferent())) { - - if (!turning) { - if (spindleSpeed < 1) { - error(localize("Spindle speed out of range.")); - return; - } - if (spindleSpeed > 3000) { - warning(localize("Spindle speed exceeds maximum value.")); - } - } - - switch (currentSection.spindle) { - case SPINDLE_PRIMARY: // main spindle - if (properties.useTailStock) { - if (gotTailStock) { - writeBlock(getCode(currentSection.tailstock ? "TAILSTOCK_ON" : "TAILSTOCK_OFF")); - } - // writeBlock(mFormat.format(clampPrimaryChuck ? 10 : 11)); - // writeBlock(mFormat.format(clampSecondaryChuck ? 110 : 111)); - } - break; - case SPINDLE_SECONDARY: // sub spindle - if (!gotSecondarySpindle) { - error(localize("Secondary spindle is not available.")); - return; - } - if (properties.useTailStock) { - // use could also swap spindles using G14/G15 - if (gotTailStock && currentSection.tailstock) { - error(localize("Tail stock is not supported for secondary spindle.")); - return; - // writeBlock(getCode(currentSection.tailstock ? "TAILSTOCK_ON" : "TAILSTOCK_OFF")); - } - // writeBlock(mFormat.format(clampPrimaryChuck ? 10 : 11)); - // writeBlock(mFormat.format(clampSecondaryChuck ? 110 : 111)); - } - break; - } - startSpindle(false, true, getFramePosition(currentSection.getInitialPosition())); - } - - // wcs - if (insertToolCall) { // force work offset when changing tool - currentWorkOffset = undefined; - } - 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 > 6) { - var code = workOffset - 6; - if (code > 99) { - error(localize("Work offset out of range.")); - return; - } - if (workOffset != currentWorkOffset) { - writeBlock(gFormat.format(154), "P" + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - // set coolant after we have positioned at Z - setCoolant(tool.coolant); - - forceAny(); - gMotionModal.reset(); - - setRotation(currentSection.workPlane); - - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - if (!retracted) { - // TAG: need to retract along X or Z - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - } - } - - if (insertToolCall || tool.getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), zOutput.format(initialPosition.z) - ); - gMotionModal.reset(); - } - - // enable SFM spindle speed - if (tool.getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - startSpindle(false, false); - } - - if (currentSection.partCatcher) { - engagePartCatcher(true); - } - - if (properties.useParametricFeed && - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill") && // legacy - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(); - } - } else { - activeMovements = undefined; - } - - if (insertToolCall || retracted) { - gPlaneModal.reset(); - } -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - milliseconds = clamp(1, seconds * 1000, 99999999); - writeBlock(/*gFeedModeModal.format(94),*/ gFormat.format(4), "P" + milliFormat.format(milliseconds)); -} - -var pendingRadiusCompensation = -1; - -function onRadiusCompensation() { - pendingRadiusCompensation = radiusCompensation; -} - -var resetFeed = false; - -function getHighfeedrate(radius) { - if (currentSection.feedMode == FEED_PER_REVOLUTION) { - var rpm = spindleSpeed; // rev/min - if (currentSection.getTool().getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - var O = 2 * Math.PI * radius; // in/rev - rpm = tool.surfaceSpeed / O; // in/min div in/rev => rev/min - } - return highFeedrate / rpm; // in/min div rev/min => in/rev - } - return highFeedrate; -} - -function onRapid(_x, _y, _z) { - var x = xOutput.format(_x); - var y = yOutput.format(_y); - var z = zOutput.format(_z); - if (x || y || z) { - var useG1 = ((x ? 1 : 0) + (y ? 1 : 0) + (z ? 1 : 0)) > 1 && !isCannedCycle; - if (pendingRadiusCompensation >= 0) { - pendingRadiusCompensation = -1; - if (useG1) { - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, getFeed(getHighfeedrate(_x))); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, getFeed(getHighfeedrate(_x))); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, getFeed(getHighfeedrate(_x))); - } - } else { - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(gMotionModal.format(0), gFormat.format(41), x, y, z); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(gMotionModal.format(0), gFormat.format(42), x, y, z); - break; - default: - writeBlock(gMotionModal.format(0), gFormat.format(40), x, y, z); - } - } - } - if (useG1) { - // axes are not synchronized - writeBlock(gMotionModal.format(1), x, y, z, getFeed(getHighfeedrate(_x))); - } else { - writeBlock(gMotionModal.format(0), x, y, z); - forceFeed(); - } - resetFeed = false; - } -} - -function onLinear(_x, _y, _z, feed) { - if (isSpeedFeedSynchronizationActive()) { - resetFeed = true; - var threadPitch = getParameter("operation:threadPitch"); - var threadsPerInch = 1.0 / threadPitch; // per mm for metric - writeBlock(gMotionModal.format(32), xOutput.format(_x), yOutput.format(_y), zOutput.format(_z), pitchOutput.format(1 / threadsPerInch)); - return; - } - if (resetFeed) { - resetFeed = false; - forceFeed(); - } - 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; - writeBlock(gPlaneModal.format(18)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - writeBlock(gMotionModal.format(isSpeedFeedSynchronizationActive() ? 32 : 1), gFormat.format(41), x, y, z, f); - break; - case RADIUS_COMPENSATION_RIGHT: - writeBlock(gMotionModal.format(isSpeedFeedSynchronizationActive() ? 32 : 1), gFormat.format(42), x, y, z, f); - break; - default: - writeBlock(gMotionModal.format(isSpeedFeedSynchronizationActive() ? 32 : 1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gMotionModal.format(isSpeedFeedSynchronizationActive() ? 32 : 1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(isSpeedFeedSynchronizationActive() ? 32 : 1), f); - } - } -} - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - if (isSpeedFeedSynchronizationActive()) { - error(localize("Speed-feed synchronization is not supported for circular moves.")); - return; - } - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - var directionCode = (toolingData.toolPost == REAR) ? (clockwise ? 2 : 3) : (clockwise ? 3 : 2); - - if (isFullCircle()) { - if (properties.useRadius || isHelical()) { // radius mode does not support full arcs - linearize(tolerance); - return; - } - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(directionCode), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(directionCode), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(directionCode), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } else if (!properties.useRadius) { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(directionCode), 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: - writeBlock(gPlaneModal.format(18), gMotionModal.format(directionCode), 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: - writeBlock(gPlaneModal.format(19), gMotionModal.format(directionCode), 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: - 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: - writeBlock(gPlaneModal.format(17), gMotionModal.format(directionCode), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(directionCode), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(directionCode), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } -} - -function onCycle() { -} - -var saveShowSequenceNumbers = true; -var xyzFormat = createFormat({decimals:(unit == MM ? 4 : 5), forceDecimal:true}); -var pathBlockNumber = {start: 0, end: 0}; -var isCannedCycle = false; - -function onCyclePath() { - saveShowSequenceNumbers = properties.showSequenceNumbers; - isCannedCycle = true; - // buffer all paths and stop feeds being output - feedOutput.disable(); - properties.showSequenceNumbers = false; - redirectToBuffer(); - gMotionModal.reset(); - if ((hasParameter("operation:grooving") && getParameter("operation:grooving").toUpperCase() != "OFF")) { - forceXYZ(); - } -} - -function onCyclePathEnd() { - properties.showSequenceNumbers = saveShowSequenceNumbers; // reset property to initial state - feedOutput.enable(); - var cyclePath = String(getRedirectionBuffer()).split(EOL); // get cycle path from buffer - closeRedirection(); - for (line in cyclePath) { // remove empty elements - if (cyclePath[line] == "") { - cyclePath.splice(line); - } - } - - var verticalPasses; - if (cycle.profileRoughingCycle == 0) { - verticalPasses = false; - } else if (cycle.profileRoughingCycle == 1) { - verticalPasses = true; - } else { - error(localize("Unsupported passes type.")); - return; - } - // output cycle data - switch (cycleType) { - case "turning-canned-rough": - writeBlock(gFormat.format(verticalPasses ? 72 : 71), - "P" + (getStartEndSequenceNumber(cyclePath, true)), - "Q" + (getStartEndSequenceNumber(cyclePath, false)), - "U" + xFormat.format(cycle.xStockToLeave), - "W" + xyzFormat.format(cycle.zStockToLeave), - "D" + xyzFormat.format(cycle.depthOfCut), - getFeed(cycle.cutfeedrate) - ); - break; - default: - error(localize("Unsupported turning canned cycle.")); - } - - for (var i = 0; i < cyclePath.length; ++i) { - if (i == 0 || i == (cyclePath.length - 1)) { // write sequence number on first and last line of the cycle path - properties.showSequenceNumbers = true; - if ((i == 0 && pathBlockNumber.start != sequenceNumber) || (i == (cyclePath.length - 1) && pathBlockNumber.end != sequenceNumber)) { - error(localize("Mismatch of start/end block number in turning canned cycle.")); - return; - } - } - writeBlock(cyclePath[i]); // output cycle path - properties.showSequenceNumbers = saveShowSequenceNumbers; // reset property to initial state - isCannedCycle = false; - } -} - -function getStartEndSequenceNumber(cyclePath, start) { - if (start) { - pathBlockNumber.start = sequenceNumber + conditional(saveShowSequenceNumbers, properties.sequenceNumberIncrement); - return pathBlockNumber.start; - } else { - pathBlockNumber.end = sequenceNumber + properties.sequenceNumberIncrement + conditional(saveShowSequenceNumbers, (cyclePath.length - 1) * properties.sequenceNumberIncrement); - return pathBlockNumber.end; - } -} - -function getCommonCycle(x, y, z, r) { - forceXYZ(); // force xyz on first drill hole of any cycle - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + spatialFormat.format(r)]; -} - -function onCyclePoint(x, y, z) { - if (!properties.useCycles || currentSection.isMultiAxis()) { - expandCyclePoint(x, y, z); - return; - } - - if (isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1)) || - isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, -1))) { - gPlaneModal.format(17); // 2-axis lathes typically don't use G17 - } else { - expandCyclePoint(x, y, z); - return; - } - - switch (cycleType) { - case "thread-turning": - var inverted = (toolingData.toolPost == REAR) ? 1 : -1; - var i = -cycle.incrementalX * inverted; // positive if taper goes down - delta radius - var threadsPerInch = 1.0 / cycle.pitch; // per mm for metric - var f = 1 / threadsPerInch; - // writeBlock(mFormat.format(23)); // chamfer/fade on - fading is default behavior - writeBlock(gMotionModal.format(92), xOutput.format(x - cycle.incrementalX), yOutput.format(y), zOutput.format(z), conditional(zFormat.isSignificant(i), g92IOutput.format(i)), pitchOutput.format(f)); - // writeBlock(mFormat.format(24)); // chamfer/fade off - forceFeed(); - return; - } - - if (isFirstCyclePoint()) { - repositionToCycleClearance(cycle, x, y, z); - - var F = cycle.feedrate; - var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(F) - ); - } else { - writeBlock( - gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "chip-breaking": - case "deep-drilling": - // either use Q or I,J,K - writeBlock( - gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract), - "Q" + spatialFormat.format(cycle.incrementalDepth), - // conditional(cycle.incrementalDepthReduction > 0, "J" + spatialFormat.format(cycle.incrementalDepthReduction)), - // conditional(cycle.minimumIncrementalDepth > 0, "K" + spatialFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), - feedOutput.format(F) - ); - break; - case "tapping": - F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - writeBlock( - gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 184 : 84), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - pitchOutput.format(F) - ); - forceFeed(); - break; - case "left-tapping": - F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - writeBlock( - gCycleModal.format(184), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - pitchOutput.format(F) - ); - forceFeed(); - break; - case "right-tapping": - F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - writeBlock( - gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - pitchOutput.format(F) - ); - forceFeed(); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - writeBlock( - gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 184 : 84)), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - "Q" + spatialFormat.format(cycle.incrementalDepth), - pitchOutput.format(F) - ); - forceFeed(); - break; - case "fine-boring": - writeBlock( - gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), // not optional - "Q" + spatialFormat.format(cycle.shift), - feedOutput.format(F) - ); - break; - case "reaming": - if (P > 0) { - writeBlock( - gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), - feedOutput.format(F) - ); - } else { - writeBlock( - gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - case "boring": - if (P > 0) { - writeBlock( - gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract), - "P" + milliFormat.format(P), // not optional - feedOutput.format(F) - ); - } else { - writeBlock( - gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract), - feedOutput.format(F) - ); - } - break; - default: - expandCyclePoint(x, y, z); - } - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - var _z = zOutput.format(z); - if (!_x && !_y && !_z) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - xOutput.reset(); // at least one axis is required - _x = xOutput.format(x); - break; - case 18: // ZX - zOutput.reset(); // at least one axis is required - _z = zOutput.format(z); - break; - case 19: // YZ - yOutput.reset(); // at least one axis is required - _y = yOutput.format(y); - break; - } - } - writeBlock(_x, _y, _z); - } - } -} - -function onCycleEnd() { - if (!cycleExpanded) { - switch (cycleType) { - case "thread-turning": - forceFeed(); - xOutput.reset(); - zOutput.reset(); - g92IOutput.reset(); - break; - default: - writeBlock(gCycleModal.format(80)); - } - } -} - -var currentCoolantMode = COOLANT_OFF; - -function setCoolant(coolant) { - if (coolant == currentCoolantMode) { - return; // coolant is already active - } - - var m = undefined; - if (coolant == COOLANT_OFF) { - if (currentCoolantMode == COOLANT_THROUGH_TOOL) { - writeBlock(getCode("COOLANT_THROUGH_TOOL_OFF")); - } else if (currentCoolantMode == COOLANT_AIR) { - writeBlock(getCode("COOLANT_AIR_OFF")); - } else { - writeBlock(getCode("COOLANT_OFF")); - } - currentCoolantMode = COOLANT_OFF; - return; - } - - switch (coolant) { - case COOLANT_FLOOD: - m = getCode("COOLANT_FLOOD_ON"); - break; - case COOLANT_THROUGH_TOOL: - m = getCode("COOLANT_THROUGH_TOOL_ON"); - break; - case COOLANT_AIR: - m = getCode("COOLANT_AIR_ON"); - break; - default: - onUnsupportedCoolant(coolant); - m = getCode("COOLANT_OFF"); - } - - if (m) { - writeBlock(m); - currentCoolantMode = coolant; - } -} - -function isSpindleSpeedDifferent() { - if (isFirstSection()) { - return true; - } - if (getPreviousSection().getTool().clockwise != tool.clockwise) { - return true; - } - if (tool.getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - if ((getPreviousSection().getTool().getSpindleMode() != SPINDLE_CONSTANT_SURFACE_SPEED) || - rpmFormat.areDifferent(getPreviousSection().getTool().surfaceSpeed, tool.surfaceSpeed)) { - return true; - } - } else { - if ((getPreviousSection().getTool().getSpindleMode() != SPINDLE_CONSTANT_SPINDLE_SPEED) || - rpmFormat.areDifferent(getPreviousSection().getTool().spindleRPM, spindleSpeed)) { - return true; - } - } - return false; -} - -function onSpindleSpeed(spindleSpeed) { - if ((sOutput.getCurrent() != Number.POSITIVE_INFINITY) && rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) { // avoid redundant output of spindle speed - startSpindle(false, false, getFramePosition(currentSection.getInitialPosition()), spindleSpeed); - } - if ((pOutput.getCurrent() != Number.POSITIVE_INFINITY) && rpmFormat.areDifferent(spindleSpeed, pOutput.getCurrent())) { // avoid redundant output of spindle speed - startSpindle(false, false, getFramePosition(currentSection.getInitialPosition()), spindleSpeed); - } -} - -function startSpindle(tappingMode, forceRPMMode, initialPosition, rpm) { - var spindleDir; - var spindleMode; - var _spindleSpeed = spindleSpeed; - if (rpm !== undefined) { - _spindleSpeed = rpm; - } - - gSpindleModeModal.reset(); - - if ((getSpindle() == SPINDLE_SECONDARY) && !gotSecondarySpindle) { - error(localize("Secondary spindle is not available.")); - return; - } - - if (false /*tappingMode*/) { - spindleDir = getCode("RIGID_TAPPING"); - } else { - if (getSpindle() == SPINDLE_SECONDARY) { - spindleDir = tool.clockwise ? getCode("START_SUB_SPINDLE_CW") : getCode("START_SUB_SPINDLE_CCW"); - } else { - spindleDir = tool.clockwise ? getCode("START_MAIN_SPINDLE_CW") : getCode("START_MAIN_SPINDLE_CCW"); - } - } - - var maximumSpindleSpeed = (tool.maximumSpindleSpeed > 0) ? Math.min(tool.maximumSpindleSpeed, properties.maximumSpindleSpeed) : properties.maximumSpindleSpeed; - if (tool.getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - _spindleSpeed = tool.surfaceSpeed * ((unit == MM) ? 1 / 1000.0 : 1 / 12.0); - if (forceRPMMode) { // RPM mode is forced until move to initial position - if (xFormat.getResultingValue(initialPosition.x) == 0) { - _spindleSpeed = maximumSpindleSpeed; - } else { - _spindleSpeed = Math.min((_spindleSpeed * ((unit == MM) ? 1000.0 : 12.0) / (Math.PI * Math.abs(initialPosition.x * 2))), maximumSpindleSpeed); - } - spindleMode = getCode("CONSTANT_SURFACE_SPEED_OFF"); - } else { - writeBlock(gFormat.format(50), sOutput.format(maximumSpindleSpeed)); - spindleMode = getCode("CONSTANT_SURFACE_SPEED_ON"); - } - } else { - spindleMode = getCode("CONSTANT_SURFACE_SPEED_OFF"); - } - if (getSpindle(true) == SPINDLE_SECONDARY) { - writeBlock( - spindleMode, - pOutput.format(_spindleSpeed), - spindleDir - ); - } else { - writeBlock( - spindleMode, - sOutput.format(_spindleSpeed), - spindleDir - ); - } - // wait for spindle here if required -} - -function onCommand(command) { - switch (command) { - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - break; - case COMMAND_COOLANT_ON: - setCoolant(COOLANT_FLOOD); - break; - case COMMAND_LOCK_MULTI_AXIS: - writeBlock(mFormat.format((getSpindle() == 0) ? 14 : 114)); - break; - case COMMAND_UNLOCK_MULTI_AXIS: - writeBlock(mFormat.format((getSpindle() == 0) ? 15 : 115)); - break; - case COMMAND_START_CHIP_TRANSPORT: - if (properties.gotChipConveyor) { - writeBlock(mFormat.format(31)); - } - break; - case COMMAND_STOP_CHIP_TRANSPORT: - if (properties.gotChipConveyor) { - writeBlock(mFormat.format(33)); - } - break; - case COMMAND_OPEN_DOOR: - if (gotDoorControl) { - writeBlock(mFormat.format(85)); // optional - } - break; - case COMMAND_CLOSE_DOOR: - if (gotDoorControl) { - writeBlock(mFormat.format(86)); // optional - } - break; - case COMMAND_BREAK_CONTROL: - break; - case COMMAND_TOOL_MEASURE: - break; - case COMMAND_ACTIVATE_SPEED_FEED_SYNCHRONIZATION: - break; - case COMMAND_DEACTIVATE_SPEED_FEED_SYNCHRONIZATION: - break; - - case COMMAND_STOP: - writeBlock(mFormat.format(0)); - forceSpindleSpeed = true; - break; - case COMMAND_OPTIONAL_STOP: - writeBlock(mFormat.format(1)); - break; - case COMMAND_END: - writeBlock(mFormat.format(2)); - break; - case COMMAND_SPINDLE_CLOCKWISE: - switch (currentSection.spindle) { - case SPINDLE_PRIMARY: - writeBlock(mFormat.format(3)); - break; - case SPINDLE_SECONDARY: - writeBlock(mFormat.format(143)); - break; - } - break; - case COMMAND_SPINDLE_COUNTERCLOCKWISE: - switch (currentSection.spindle) { - case SPINDLE_PRIMARY: - writeBlock(mFormat.format(4)); - break; - case SPINDLE_SECONDARY: - writeBlock(mFormat.format(144)); - break; - } - break; - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_STOP_SPINDLE: - switch (currentSection.spindle) { - case SPINDLE_PRIMARY: - writeBlock(mFormat.format(5)); - break; - case SPINDLE_SECONDARY: - writeBlock(mFormat.format(145)); - break; - } - break; - case COMMAND_ORIENTATE_SPINDLE: - if (getSpindle() == 0) { - writeBlock(mFormat.format(19)); // use P or R to set angle (optional) - } else { - writeBlock(mFormat.format(119)); - } - break; - //case COMMAND_CLAMP: // add support for clamping - //case COMMAND_UNCLAMP: // add support for clamping - default: - onUnsupportedCommand(command); - } -} - -function engagePartCatcher(engage) { - if (engage) { - // catch part here - writeBlock(getCode("PART_CATCHER_ON"), formatComment(localize("PART CATCHER ON"))); - } else { - onCommand(COMMAND_COOLANT_OFF); - writeBlock(gFormat.format(53), gMotionModal.format(0), "X" + xFormat.format(properties.g53HomePositionX)); // retract - writeBlock(gFormat.format(53), gMotionModal.format(0), "Z" + zFormat.format(properties.g53HomePositionZ)); // retract - writeBlock(getCode("PART_CATCHER_OFF"), formatComment(localize("PART CATCHER OFF"))); - forceXYZ(); - } -} - -function onSectionEnd() { - - // cancel SFM mode to preserve spindle speed - if (tool.getSpindleMode() == SPINDLE_CONSTANT_SURFACE_SPEED) { - startSpindle(false, true, getFramePosition(currentSection.getFinalPosition())); - } - - if (currentSection.partCatcher) { - engagePartCatcher(false); - } - - forceAny(); -} - -function onClose() { - writeln(""); - - optionalSection = false; - - onCommand(COMMAND_COOLANT_OFF); - - if (properties.gotChipConveyor) { - onCommand(COMMAND_STOP_CHIP_TRANSPORT); - } - - // we might want to retract in Z before X - writeBlock(gFormat.format(53), gMotionModal.format(0), "X" + xFormat.format(properties.g53HomePositionX)); // retract - xOutput.reset(); - writeBlock(gFormat.format(53), gMotionModal.format(0), "Z" + zFormat.format(properties.g53HomePositionZ)); // retract - zOutput.reset(); - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - writeln("%"); -} diff --git a/Haas_Mills_BIDC/Bechtel DT.cps b/Haas_Mills_BIDC/Bechtel DT.cps deleted file mode 100644 index b53bde4..0000000 --- a/Haas_Mills_BIDC/Bechtel DT.cps +++ /dev/null @@ -1,4658 +0,0 @@ -/** - Copyright (C) 2012-2021 by Autodesk, Inc. - All rights reserved. - - HAAS post processor configuration. - - $Revision: 43348 37c695f19b2eab4d5737a29df773b981b83fa8d4 $ - $Date: 2021-07-12 15:10:04 $ - - Modified by BIDC of Purdue University - Authors: Gavin Williams (will1742@purdue.edu) -*/ - -//////////////////////////////////////////////////////////////////////////////////////////////// -// MANUAL NC COMMANDS -// -// The following ACTION commands are supported by this post. -// -// CYCLE_REVERSAL - Reverses the spindle in a drilling cycle -// USEPOLARMODE - Enables polar interpolation for the following operation. -// VFD_HIGH - Uses high pressure flood coolant if machine has VFD -// VFD_LOW - Uses low pressure flood coolant if machine has VFD -// VFD_NORMAL - Uses normal pressure flood coolant if machine has VFD -// -//////////////////////////////////////////////////////////////////////////////////////////////// - -description = "HAAS - Next Generation Control"; -vendor = "Haas Automation"; -vendorUrl = "https://www.haascnc.com"; -legal = "Copyright (C) 2012-2021 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 45702; - -longDescription = "Generic post for the HAAS Next Generation control. The post includes support for multi-axis indexing and simultaneous machining. The post utilizes the dynamic work offset feature so you can place your work piece as desired without having to repost your NC programs." + EOL + -"You can specify following pre-configured machines by using the property 'Machine model':" + EOL + -"UMC-500" + EOL + "UMC-750" + EOL + "UMC-1000" + EOL + "UMC-1600-H"; - -extension = "nc"; -programNameIsInteger = true; -setCodePage("ascii"); -keywords = "MODEL_IMAGE PREVIEW_IMAGE"; - -capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(355); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion -allowSpiralMoves = true; -highFeedrate = (unit == IN) ? 650 : 5000; - -// user-defined properties -properties = {/* - machineModel: { - title: "Machine model", - description: "Specifies the pre-configured machine model.", - type: "enum", - group: 0, - values: [ - {title: "None", id: "none"}, - {title: "UMC-500", id: "umc-500"}, - {title: "UMC-750", id: "umc-750"}, - {title: "UMC-1000", id: "umc-1000"}, - {title: "UMC-1600-H", id: "umc-1600"} - ], - value: "none", - scope: "post" - }, - hasAAxis: { - title: "Has A-axis rotary", - description: "Enable if the machine has an A-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasBAxis: { - title: "Has B-axis rotary", - description: "Enable if the machine has a B-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasCAxis: { - title: "Has C-axis rotary", - description: "Enable if the machine has a C-axis table. Specifies a trunnion setup if an A-axis or B-axis is defined. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - throughSpindle: { - title: "Allow Through Spindle Coolant", - description: "Enables through spindle coolant, if off uses flood", - type: "boolean", - group: 50, - value: true, - scope: "post" - }, - useDPMFeeds: { - title: "Rotary moves use DPM feeds", - description: "Enable to output DPM feeds, disable for Inverse Time feeds with rotary axes moves.", - group: 1, - type: "boolean", - value: false, - scope: "post" - },*/ - useTCPC: { - title: "Use TCPC programming", - description: "The control supports Tool Center Point Control programming.", - group: 1, - type: "boolean", - value: true, - scope: "post" - },/* - useDWO: { - title: "Use DWO", - description: "Specifies that the Dynamic Work Offset feature (G254/G255) should be used.", - group: 1, - type: "boolean", - value: true, - scope: "post" - }, - preloadTool: { - title: "Preload tool", - description: "Preloads the next tool at a tool change (if any).", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - chipTransport: { - title: "Use chip transport", - description: "Enable to turn on chip transport at start of program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - optionalStop: { - title: "Optional stop", - description: "Specifies that optional stops M1 should be output at tool changes.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - separateWordsWithSpace: { - title: "Separate words with space", - description: "Adds spaces between words if 'yes' is selected.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useRadius: { - title: "Radius arcs", - description: "If yes is selected, arcs are output using radius values rather than IJK.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useParametricFeed: { - title: "Parametric feed", - description: "Parametric feed values based on movement type are output.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useG0: { - title: "Use G0", - description: "Specifies that G0s should be used for rapid moves when moving along a single axis.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - safePositionMethod: { - title: "Safe Retracts", - description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.", - type: "enum", - values: [ - {title: "G28", id: "G28"}, - {title: "G53", id: "G53"}, - {title: "Clearance Height", id: "clearanceHeight"} - ], - value: "G53", - scope: "post" - }, - useG187: { - title: "Use G187", - description: "Specifies that smoothing using G187 should be used.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - homePositionCenter: { - title: "Home position center", - description: "Enable to center the part along X at the end of program for easy access. Requires a CNC with a moving table.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - optionallyCycleToolsAtStart: { - title: "Optionally cycle tools at start", - description: "Cycle through each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - measureToolsAtStart: { - title: "Optionally measure tools at start", - description: "Measure each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - forceHomeOnIndexing: { - title: "Force XY home position on indexing", - description: "Move XY to their home positions on multi-axis indexing.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - toolBreakageTolerance: { - title: "Tool breakage tolerance", - description: "Specifies the tolerance for which tool break detection will raise an alarm.", - group: 2, - type: "spatial", - value: 0.1, - scope: "post" - }, - safeStartAllOperations: { - title: "Safe start all operations", - description: "Write optional blocks at the beginning of all operations that include all commands to start program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - fastToolChange: { - title: "Fast tool change", - description: "Skip spindle off, coolant off, and Z retract to make tool change quicker.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useG95forTapping: { - title: "Use G95 for tapping", - description: "use IPR/MPR instead of IPM/MPM for tapping", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - safeRetractDistance: { - title: "Safe retract distance", - description: "Specifies the distance to add to retract distance when rewinding rotary axes.", - group: 2, - type: "spatial", - value: 0, - scope: "post" - },*/ - useSubroutines: { - title: "Use subroutines", - description: "Select your desired subroutine option. 'All Operations' creates subroutines per each operation, 'Cycles' creates subroutines for cycle operations on same holes, and 'Patterns' creates subroutines for patterned operations.", - type: "enum", - values: [ - {title: "No", id: "none"}, - {title: "All Operations", id: "allOperations"}, - {title: "Cycles", id: "cycles"}, - {title: "Patterns", id: "patterns"} - ], - group: 3, - value: "none", - scope: "post" - },/* - writeMachine: { - title: "Write machine", - description: "Output the machine settings in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - writeTools: { - title: "Write tool list", - description: "Output a tool list in the header of the code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - writeVersion: { - title: "Write version", - description: "Write the version number in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showSequenceNumbers: { - title: "Use sequence numbers", - description: "Use sequence numbers for each block of outputted code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - sequenceNumberStart: { - title: "Start sequence number", - description: "The number at which to start the sequence numbers.", - group: 4, - type: "integer", - value: 10, - scope: "post" - }, - sequenceNumberIncrement: { - title: "Sequence number increment", - description: "The amount by which the sequence number is incremented by in each block.", - group: 4, - type: "integer", - value: 5, - scope: "post" - }, - sequenceNumberOnlyOnToolChange: { - title: "Block number only on tool change", - description: "Specifies that block numbers should only be output at tool changes.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showNotes: { - title: "Show notes", - description: "Enable to output notes for operations.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - useM130PartImages: { - title: "Include M130 part images", - description: "Enable to include M130 part images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - useM130ToolImages: { - title: "Include M130 tool images", - description: "Enable to include M130 tool images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - coolantPressure: { - title: "Coolant pressure", - description: "Select the coolant pressure if equipped with a Variable Frequency Drive. Select 'Default' if this option is not installed.", - type: "enum", - group: 2, - values: [ - {title: "Default", id: ""}, - {title: "Low", id: "P0"}, - {title: "Normal", id: "P1"}, - {title: "High", id: "P2"} - ], - value: "", - scope: "post" - }, - singleResultsFile: { - title: "Create single results file", - description: "Set to false if you want to store the measurement results for each probe / inspection toolpath in a separate file", - group: 0, - type: "boolean", - value: true, - scope: "post" - }*/ - toolsToLoad: { - title: "Tools to load and probe", - description: "List or provide a range of tools to probe e.g. 1, 2, 3 or 1-5. Leaving this empty will probe all tools", - group: 4, - type: "string", - value: "", - scope: "post" - }, - toolLengthValidation: { - title: "Tool Length Validation", - description: "Length validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - pencilWCSValidation: { - title: "WCS Validation", - description: "WCS validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - measureToolsAtStart: { - title: "Tool Probing", - description: "Tool Probing. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - loadToolsAtStart: { - title: "Tool Loading", - description: "Tool Loading. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - displayMediaCalls: { - title: "Display Media", - description: "Enable to include M130 part images with the NC file, disable to see the information in comments.", - group: 4, - value: false, - scope: "post" - } -}; - -staticProperties = { - machineModel: "none", - safePositionMethod: "G53", - useDPMFeeds: false, - useTCPC: true, - useDWO: true, - safeStartAllOperations: true, - preloadTool: true, - chipTransport: false, - optionalStop: true, - separateWordsWithSpace: true, - useRadius: false, - useParametricFeed: true, - useG0: true, - useG187: false, - homePositionCenter: false, - optionallyCycleToolsAtStart: false, - measureToolsAtStart: true, - forceHomeOnIndexing: false, - toolBreakageTolerance: 0.1, - fastToolChange: false, - useG95forTapping: true, - safeRetractDistance: 0, - //useSubroutines: "allOperations", - writeMachine: false, - writeTools: true, - writeVersion: false, - showSequenceNumbers: true, - sequenceNumberStart: 10, - sequenceNumberIncrement: 5, - sequenceNumberOnlyOnToolChange: false, - showNotes: true, - useM130PartImages: false, - useM130ToolImages: false, - coolantPressure: "", - singleResultsFile: true, - useP9995: true, - hasAAxis: "false", - hasBAxis: "false", - hasCAxis: "false", - postVersion: "DT1G8A21" - }; - - const HAAS_DRILL = 1; - const HAAS_TAP = 2; - const HAAS_SHELL = 3; - const HAAS_END_MILL = 4; - const HAAS_CENTER = 5; - const HAAS_BALL_NOSE = 6; - const HAAS_PROBE = 7; - - const NO_PROBING = 0; - const LEN_ROT = 1; - const LEN_NON_ROT = 2; - const LEN_DIA_ROT = 3; - - const DEFAULT_HAAS_K_FACTOR = 0.05; - const NULL_HAAS_K_FACTOR = 0; - - const CLEARANCE_HEIGHT = 1; - const LENGTH_TOLERANCE = .25; - const DIAM_TOLERANCE = .01; - - // VF4 specific - const MAX_TOOL_LENGTH = 7; - const MAX_TOOL_DIAM = 2; - const X_TRAVEL_LIMIT = -20; - const Y_TRAVEL_LIMIT = -16; - - const MAX_TOOL_NUM = 20; - -var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines -// samples: -// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} -// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} -var coolants = [ - {id: COOLANT_FLOOD, on: 8}, - {id: COOLANT_MIST}, - {id: COOLANT_THROUGH_TOOL, on: 88, off: 89}, - {id: COOLANT_AIR, on: 83, off: 84}, - {id: COOLANT_AIR_THROUGH_TOOL, on: 73, off: 74}, - {id: COOLANT_SUCTION}, - {id: COOLANT_FLOOD_MIST}, - {id: COOLANT_FLOOD_THROUGH_TOOL, on: [88, 8], off: [89, 9]}, - {id: COOLANT_OFF, off: 9} -]; - -// old machines only support 4 digits -var oFormat = createFormat({width:5, zeropad:true, decimals:0}); -var nFormat = createFormat({decimals:0}); - -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 probeWCSFormat = createFormat({decimals:2, forceDecimal:true}); -var macroFormat = createFormat({prefix:"#", decimals:0}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var rFormat = xyzFormat; // radius -var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true}); -var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var forceX = createFormat({prefix:"X", decimals:4, forceDecimal:true}); -var forceY = createFormat({prefix:"Y", decimals:4, forceDecimal:true}); -var forceZ = createFormat({prefix:"Z", decimals:4, forceDecimal:true}); - -var xOutput = createVariable({prefix:"X"}, xyzFormat); -var yOutput = createVariable({prefix:"Y"}, xyzFormat); -var zOutput = createVariable({onchange: function() {retracted = false;}, prefix:"Z"}, xyzFormat); -var aOutput = createVariable({prefix:"A"}, abcFormat); -var bOutput = createVariable({prefix:"B"}, abcFormat); -var cOutput = createVariable({prefix:"C"}, abcFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var dOutput = createVariable({}, dFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat); -var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat); -var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat); - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({force:true}, gFormat); // modal group 10 // G98-99 -var gRotationModal = createModal({ - onchange: function () { - if (probeVariables.probeAngleMethod == "G68") { - probeVariables.outputRotationCodes = true; - } - } -}, gFormat); // modal group 16 // G68-G69 - -// fixed settings -var firstFeedParameter = 100; // the first variable to use with parametric feed -var forceResetWorkPlane = false; // enable to force reset of machine ABC on new orientation -var minimumCyclePoints = 5; // minimum number of points in cycle operation to consider for subprogram -var useDwoForPositioning = true; // specifies to use the DWO feature for XY positioning for multi-axis operations - -var WARNING_WORK_OFFSET = 0; - -var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported -var probeVariables = { - outputRotationCodes: false, // defines if it is required to output rotation codes - probeAngleMethod: "OFF", // OFF, AXIS_ROT, G68, G54.4 - compensationXY: undefined, - rotationalAxis: -1 -}; - -var SUB_UNKNOWN = 0; -var SUB_PATTERN = 1; -var SUB_CYCLE = 2; - -// collected state -var sequenceNumber; -var currentWorkOffset; -var coolantPressure; -var optionalSection = false; -var forceSpindleSpeed = false; -var forceCoolant = false; -var activeMovements; // do not use by default -var currentFeedId; -var maximumCircularRadiiDifference = toPreciseUnit(0.005, MM); -var maximumLineLength = 80; // the maximum number of charaters allowed in a line -var subprograms = []; -var currentPattern = -1; -var firstPattern = false; -var currentSubprogram; -var lastSubprogram; -var initialSubprogramNumber = 90000; -var definedPatterns = new Array(); -var incrementalMode = false; -var saveShowSequenceNumbers; -var cycleSubprogramIsActive = false; -var patternIsActive = false; -var lastOperationComment = ""; -var incrementalSubprogram; -var retracted = false; // specifies that the tool has been retracted to the safe plane -var hasA = false; -var hasB = false; -var hasC = false; -var measureTool = false; -var cycleReverse = false; -var probeMultipleFeatures = true; -var maximumSpindleRPM = 15000; -var homePositionCenter = false; - -// used to convert blocks to optional for safeStartAllOperations, might get used outside of onSection -var operationNeedsSafeStart = false; - -/** - Writes the specified block. -*/ -var skipBlock = false; -function writeBlock() { - var text = formatWords(arguments); - if (!text) { - return; - } - var maximumSequenceNumber = ((getProperty("useSubroutines") == "allOperations") || (getProperty("useSubroutines") == "patterns") || - (getProperty("useSubroutines") == "cycles")) ? initialSubprogramNumber : 99999; - if (staticProperties.showSequenceNumbers) { - if (sequenceNumber >= maximumSequenceNumber) { - sequenceNumber = staticProperties.sequenceNumberStart; - } - if (optionalSection || skipBlock) { - if (text) { - writeWords("/", "N" + sequenceNumber, text); - } - } else { - writeWords2("N" + sequenceNumber, arguments); - } - sequenceNumber += staticProperties.sequenceNumberIncrement; - } else { - if (optionalSection || skipBlock) { - writeWords2("/", arguments); - } else { - writeWords(arguments); - } - } - skipBlock = false; -} - -/** - Writes the specified block - used for tool changes only. -*/ -function writeToolBlock() { - var show = staticProperties.showSequenceNumbers; - staticProperties.showSequenceNumbers = (show || staticProperties.sequenceNumberOnlyOnToolChange); - writeBlock(arguments); - staticProperties.showSequenceNumbers = show; -} - -/** - Writes the specified optional block. -*/ -function writeOptionalBlock() { - skipBlock = true; - writeBlock(arguments); -} - -function formatComment(text) { - return "(" + String(text).replace(/[()]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text.substr(0, maximumLineLength - 2))); -} - -/** - Returns the matching HAAS tool type for the tool. -*/ -function getHaasToolType(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return 1; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return 2; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return 3; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - return 4; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_THREAD: - case TOOL_MILLING_FORM: - return 5; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - return 6; // ball nose - case TOOL_PROBE: - return 7; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -function getHaasProbingType(toolType, use9023) { - switch (getHaasToolType(toolType)) { - case 3: - case 4: - return (use9023 ? 23 : 1); // rotate - case 1: - case 2: - case 5: - case 6: - case 7: - return (use9023 ? 12 : 2); // non rotate - case 0: - return (use9023 ? 13 : 3); // rotate length and dia - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - - -// Added new probe mapping - see documentation -// will1742 | Gavin Williams -function getHaasToolTypeBIDC(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return HAAS_DRILL; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return HAAS_TAP; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return HAAS_SHELL; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - case TOOL_MILLING_THREAD: - return HAAS_END_MILL; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_FORM: - return HAAS_CENTER; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - case TOOL_MILLING_RADIUS: - return HAAS_BALL_NOSE; // ball nose - case TOOL_PROBE: - return HAAS_PROBE; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -// 06/25/21 | Gavin Williams | will1742 -// 002 Probing -function formatCNumber(probeType, use9023){ - if (use9023) { - if (probeType == LEN_NON_ROT || probeType == LEN_DIA_ROT){ - return probeType + 10; - } - return 23; - } - return probeType; -} - -function getHaasProbingTypeBIDC(tool, use9023) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_PROBE: - return formatCNumber(NO_PROBING, use9023); - case HAAS_TAP: - case HAAS_DRILL: - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_CENTER: - if (tool.type == TOOL_MILLING_FORM) { - return formatCNumber(NO_PROBING, use9023); - } - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_END_MILL: - return formatCNumber((tool.type == TOOL_MILLING_TAPERED ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_BALL_NOSE: - return formatCNumber((tool.type == TOOL_MILLING_RADIUS ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_SHELL: - if ((tool.type == TOOL_MILLING_FACE) && (tool.taperAngle !=0)) { - return formatCNumber(LEN_ROT, use9023); - } - return formatCNumber(LEN_DIA_ROT, use9023); - default: - return -1; - } -} - -function getHaasKFactorBIDC(tool) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_SHELL: - case HAAS_END_MILL: - if (tool.type == TOOL_BORING_BAR || tool.type == TOOL_MILLING_END_FLAT) { - return DEFAULT_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_FACE && tool.taperAngle != 0) { - return NULL_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_THREAD) { - return DEFAULT_HAAS_K_FACTOR + tool.getThreadPitch(); - } - return DEFAULT_HAAS_K_FACTOR + tool.cornerRadius; - case HAAS_BALL_NOSE: - if (tool.type == TOOL_MILLING_RADIUS) { - return NULL_HAAS_K_FACTOR; - } - return DEFAULT_HAAS_K_FACTOR + (tool.diameter/2); - case HAAS_CENTER: - case HAAS_PROBE: - case HAAS_DRILL: - case HAAS_TAP: - - return NULL_HAAS_K_FACTOR; - default: - return -1; - } -} - -function writeToolCycleBlock(tool) { - writeOptionalBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - writeOptionalBlock(mFormat.format(0)); // wait for operator -} - -function prepareForToolCheck() { - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - - // cancel TCP so that tool doesn't follow tables - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - if ((currentSection.isMultiAxis() && getCurrentDirection().length != 0) || - (currentMachineABC != undefined && currentMachineABC.length != 0)) { - setWorkPlane(new Vector(0, 0, 0)); - forceWorkPlane(); - } -} - -function writeToolMeasureBlock(tool, preMeasure) { - var writeFunction = getProperty("measureToolsAtStart") ? writeBlock : writeOptionalBlock; - var comment = measureTool ? formatComment("MEASURE TOOL") : ""; - if (!preMeasure) { - prepareForToolCheck(); - } - if (!staticProperties.useP9995) { // use Macro P9023 to measure tools - var probingType = getHaasProbingTypeBIDC(tool.type, true); - writeFunction( - gFormat.format(65), - "P9023", - "A" + probingType + ".", - "T" + toolFormat.format(tool.number), - conditional((probingType != 12), "H" + xyzFormat.format(tool.bodyLength + tool.holderLength)), - conditional((probingType != 12), "D" + xyzFormat.format(tool.diameter)), - comment - ); - } else { // use Macro P9995 to measure tools - // writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - setMacro(1600 + tool.number, tool.numberOfFlutes, "Number of Flutes", !getProperty("measureToolsAtStart")); - setMacro(2400 + tool.number, xyzFormat.format(tool.diameter), "Tool Diameter", !getProperty("measureToolsAtStart")); - var probeType = getHaasProbingTypeBIDC(tool, false); - writeFunction( - gFormat.format(65), - "P9995", - "A0.", - "B" + getHaasToolTypeBIDC(tool.type) + ".", - "C" + probeType + ".", - "T" + toolFormat.format(tool.number), - "E" + xyzFormat.format(tool.bodyLength + tool.holderLength), - "D" + xyzFormat.format(tool.diameter), - "K" + xyzFormat.format(getHaasKFactorBIDC(tool)), - "I0.", - comment - ); // probe tooling - var line1 = "IF [[#" + (2000 + tool.number) + " GT " + - (tool.bodyLength + tool.holderLength + LENGTH_TOLERANCE).toFixed(2) + "] OR [#" + - (2000 + tool.number) + " LT " + - (tool.bodyLength + tool.holderLength - LENGTH_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool length out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line1 : "/ " + line1); - if (probeType == 3) { - var line2 = "IF [[#" + (2400 + tool.number) + " GT " + - (tool.diameter + DIAM_TOLERANCE).toFixed(2) + "] OR [#" + - (2400 + tool.number) + " LT " + - (tool.diameter - DIAM_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool diameter out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line2 : "/ " + line2); - } - } - measureTool = false; -} - -// 6/28/21 | Gavin Williams | will1742 -// 002 Improved Probing -// sets specified macro number with value -function setMacro(macro, value, comment, isOptional) { - if (isOptional) { - writeWords("/ #" + macro + "=" + value, "(" + comment + ")"); - } else { - writeWords("#" + macro + "=" + value, "(" + comment + ")"); - } -} - -function defineMachineModel() { - var useTCPC = getProperty("useTCPC"); - switch (staticProperties.machineModel) { - case "umc-500": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-23.96, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-3.37, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-750": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-29.0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-8, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(2.5, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1000": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-40.07, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-10.76, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1600": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-120, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 7500; - break; - } - machineConfiguration.setModel(staticProperties.machineModel.toUpperCase()); - machineConfiguration.setVendor("Haas Automation"); - - setMachineConfiguration(machineConfiguration); - if (receivedMachineConfiguration) { - warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); - receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten - } -} - -// Start of machine configuration logic -var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads -var virtualTooltip = false; // translate the pivot point to the virtual tool tip for nonTCP rotary heads -// internal variables, do not change -var receivedMachineConfiguration; -var tcpIsSupported; - -function activateMachine() { - // determine if TCP is supported by the machine - tcpIsSupported = false; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i in axes) { - if (axes[i].isEnabled() && axes[i].isTCPEnabled()) { - tcpIsSupported = true; - break; - } - } - - // setup usage of multiAxisFeatures - useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : - (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); - useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : - (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); - - if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { - cOutput.disable(); - } - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // don't need to modify any settings for 3-axis machines - } - - // retract/reconfigure - safeRetractDistance = staticProperties.safeRetractDistance != undefined ? staticProperties.safeRetractDistance : - (typeof safeRetractDistance == "number" ? safeRetractDistance : 0); - if (machineConfiguration.performRewinds() || (typeof performRewinds == "undefined" ? false : performRewinds)) { - machineConfiguration.enableMachineRewinds(); // enables the rewind/reconfigure logic - if (typeof stockExpansion != "undefined") { - machineConfiguration.setRewindStockExpansion(stockExpansion); - if (!receivedMachineConfiguration) { - setMachineConfiguration(machineConfiguration); - } - } - } - - if (machineConfiguration.isHeadConfiguration()) { - compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; - virtualTooltip = typeof virtualTooltip == "undefined" ? false : virtualTooltip; - machineConfiguration.setVirtualTooltip(virtualTooltip); - } - setFeedrateMode(); - - if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.isMultiAxis()) { - machineConfiguration.setToolLength(section.getTool().getBodyLength()); // define the tool length for head adjustments - section.optimizeMachineAnglesByMachine(machineConfiguration, tcpIsSupported ? 0 : 1); - } - } - } else { - optimizeMachineAngles2(tcpIsSupported ? 0 : 1); - } -} - -function setFeedrateMode(reset) { - if ((tcpIsSupported && !reset) || !machineConfiguration.isMultiAxisConfiguration()) { - return; - } - machineConfiguration.setMultiAxisFeedrate( - tcpIsSupported ? FEED_FPM : staticProperties.useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, - 9999.99, // maximum output value for inverse time feed rates - INVERSE_MINUTES, // can be INVERSE_SECONDS or DPM_COMBINATION for DPM feeds - 0.5, // tolerance to determine when the DPM feed has changed - 1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations - ); - if (!receivedMachineConfiguration || (revision < 45765)) { - setMachineConfiguration(machineConfiguration); - } -} - -function defineMachine() { - hasA = staticProperties.hasAAxis != "false"; - hasB = staticProperties.hasBAxis != "false"; - hasC = staticProperties.hasCAxis != "false"; - - if (hasA && hasB && hasC) { - error(localize("Only two rotary axes can be active at the same time.")); - return; - } else if ((hasA || hasB || hasC) && staticProperties.machineModel != "none") { - error(localize("You can only select either a machine model or use the ABC axis properties.")); - return; - } else if (((hasA || hasB || hasC) || staticProperties.machineModel != "none") && (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration())) { - error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); - return; - } - if (staticProperties.machineModel == "none") { - if (hasA || hasB || hasC) { // configure machine - var aAxis; - var bAxis; - var cAxis; - var useTCPC = getProperty("useTCPC"); - if (hasA) { // A Axis - For horizontal machines and trunnions - var dir = staticProperties.hasAAxis == "reversed" ? -1 : 1; - if (hasC || hasB) { - var aMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var aMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], range:[aMin, aMax], preference:dir, reset:(hasB ? 0 : 1), tcp:useTCPC}); - } else { - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasB) { // B Axis - For horizontal machines and trunnions - var dir = staticProperties.hasBAxis == "reversed" ? -1 : 1; - if (hasC) { - var bMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var bMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], range:[bMin, bMax], preference:-dir, reset:1, tcp:useTCPC}); - } else if (hasA) { - bAxis = createAxis({coordinate:1, table:true, axis:[0, 0, dir], cyclic:true, tcp:useTCPC}); - } else { - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasC) { // C Axis - For trunnions only - var dir = staticProperties.hasCAxis == "reversed" ? -1 : 1; - cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, dir], cyclic:true, reset:1, tcp:useTCPC}); - } - - if (hasA && hasC) { // AC trunnion - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else if (hasB && hasC) { // BC trunnion - machineConfiguration = new MachineConfiguration(bAxis, cAxis); - } else if (hasA && hasB) { // AB trunnion - machineConfiguration = new MachineConfiguration(aAxis, bAxis); - } else if (hasA) { // A rotary - machineConfiguration = new MachineConfiguration(aAxis); - } else if (hasB) { // B rotary - horizontal machine only - machineConfiguration = new MachineConfiguration(bAxis); - } else if (hasC) { // C rotary - machineConfiguration = new MachineConfiguration(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 - } - } - } else { - defineMachineModel(); - } - /* home positions */ - // machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - // machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - // machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); -} -// End of machine configuration logic - -function onOpen() { - receivedMachineConfiguration = (typeof machineConfiguration.isReceived == "function") ? machineConfiguration.isReceived() : - ((machineConfiguration.getDescription() != "") || machineConfiguration.isMultiAxisConfiguration()); - if (typeof defineMachine == "function") { - defineMachine(); // hardcoded machine configuration - } - activateMachine(); // enable the machine optimizations and settings - - if (staticProperties.useDPMFeeds) { - gFeedModeModal.format(94); - } - if (staticProperties.useRadius) { - maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC - } - if (staticProperties.sequenceNumberOnlyOnToolChange) { - staticProperties.showSequenceNumbers = false; - } - if (!staticProperties.useDWO) { - useDWOForPositioning = false; - } - - gRotationModal.format(69); // Default to G69 Rotation Off - - if (highFeedrate <= 0) { - error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal.")); - return; - } - - if (!staticProperties.separateWordsWithSpace) { - setWordSeparator(""); - } - saveShowSequenceNumbers = staticProperties.showSequenceNumbers; - sequenceNumber = staticProperties.sequenceNumberStart; - writeln("%"); - - if (programName) { - var programId; - try { - programId = getAsInt(programName); - } catch (e) { - error(localize("Program name must be a number.")); - return; - } - if (!((programId >= 1) && (programId <= 99999))) { - error(localize("Program number is out of range.")); - return; - } - writeln( - "O" + oFormat.format(programId) + - conditional(programComment, " " + formatComment(programComment.substr(0, maximumLineLength - 2 - ("O" + oFormat.format(programId)).length - 1))) - ); - lastSubprogram = (initialSubprogramNumber - 1); - } else { - error(localize("Program name has not been specified.")); - return; - } - - writeComment("Career Account Username: " + getGlobalParameter("username")); - writeComment("Filename: " + getGlobalParameter("document-path")); - writeComment("Date: " + getGlobalParameter("generated-at")); - writeComment("Post Version: " + staticProperties.postVersion); - - if (staticProperties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (staticProperties.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 (staticProperties.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" + 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); - - if (staticProperties.useM130PartImages) { - var toolRenderer = createToolRenderer(); - if (toolRenderer) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - toolRenderer.setFluteColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - toolRenderer.setShoulderColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setShaftColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setHolderColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - if (i % 2 == 0) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - } else { - toolRenderer.setBackgroundColor(new Color(240 / 255.0, 240 / 255.0, 240 / 255.0)); - } - var path = "tool" + tool.number + ".png"; - var width = 400; - var height = 532; - toolRenderer.exportAs(path, "image/png", tool, width, height); - } - } - } - } - } - - writeln(""); - writeComment("Reset work plane, cancel all cycles and offsets"); - writeBlock(gFormat.format(0), - gFormat.format(17), - gFormat.format(40), - gFormat.format(49), - gFormat.format(80), - gFormat.format(90)); - - // 6/21/21 | Gavin Williams | will1742 - // Probing now required. Using P9995. - // optionally cycle through all tools - var tools = getToolTable(); - - var writeFunction = getProperty("loadToolsAtStart") ? writeBlock : writeOptionalBlock; - - if (tools.getNumberOfTools() > 0) { - writeln(""); - /* - writeOptionalBlock(mFormat.format(0), formatComment(localize("Read note"))); // wait for operator - writeComment(localize("With BLOCK DELETE turned off each tool will cycle through")); - writeComment(localize("the spindle to verify that the correct tool is in the tool magazine")); - if (getProperty("optionallyMeasureToolsAtStart")) { - writeComment(localize("and to automatically measure it")); - } - writeComment(localize("Once the tools are verified turn BLOCK DELETE on to skip verification")); - */ - - // 6/21/21 | Gavin Williams | will1742 - writeComment("Load and probe tools"); - - // Display general tool probe info - displayMedia("toolProbeReminder.jpg", !getProperty("loadToolsAtStart")); - - let parsedTools = []; - - // Maybe should be anonymous function?? - function defaultFill() { - parsedTools = [] - for (var i = 0; i < tools.getNumberOfTools(); i++){ - parsedTools[i] = tools.getTool(i).number; - } - } - - // also maybe anonymous - // TODO: tool.getNumberOfTools needs to be machine-specific constant - function invalidToolNum(toolNum) { - return (toolNum < 1 || toolNum > MAX_TOOL_NUM); - } - - // parse string for specific tools to load - if (getProperty("toolsToLoad") != "") { - // get list of numbers - let toolNumArray = getProperty("toolsToLoad").split(','); - - // iterate through and fill ranges - for (var i = 0; i < toolNumArray.length; i++){ - toolNumArray[i] = toolNumArray[i].trim(); - - // fill range - if (toolNumArray[i].indexOf("-") >= 0) { - let numRange = toolNumArray[i].split("-"); - if (invalidToolNum(parseInt(numRange[0])) || invalidToolNum(parseInt(numRange[1]))) { - defaultFill(); - break; - } - for(var j = numRange[0]; j <= numRange[1]; j++){ - parsedTools.push(parseInt(j)); - } - continue; - } - // check if valid num - if (invalidToolNum(parseInt(toolNumArray[i]))) { - defaultFill(); - break; - } - // push single num - parsedTools.push(parseInt(toolNumArray[i])); - } - } else { - defaultFill(); - } - - for (var i = 0; i < tools.getNumberOfTools(); i++) { - var tool = tools.getTool(i); - if (tool.bodyLength + tool.holderLength > MAX_TOOL_LENGTH) { - throw "Error: T" + tool.number + " length greater than machine max" - } - - if (tool.diameter > MAX_TOOL_DIAM) { - throw "Error : T" + tool.number + " diameter greater than machine max" - } - - if (parsedTools.indexOf(tool.number) <= -1) { - continue; - } - - if (getProperty("measureToolsAtStart") && (tool.type == TOOL_PROBE)) { - continue; - } - - // 07/16/21 | will1742 | Gavin Williams - // Verify tool numbers - if (tool.number == 20 && tool.type != TOOL_PROBE) { - throw "Error: T20 is reserved for Probe"; - } - - if (tool.number == 19) { - throw "Error: T19 is reserved for WCS verification tool"; - } - - writeln(""); - 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"); - } - comment += " - " + getToolTypeName(tool.type); - writeComment(tool.description); - writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool - displayMedia("toolLoad" + tool.number + ".jpg", !getProperty("loadToolsAtStart"), "Load Tool " + tool.number); - // writeFunction(formatComment("Load Tool")); //Pause until operator loads tool - writeToolMeasureBlock(tool, true); - } - } - - writeln(""); - writeComment("SETUP FOR OPERATION"); - writeFunction(mFormat.format(131)); - - if (staticProperties.useDWO) { - var failed = false; - var dynamicWCSs = {}; - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var description = section.hasParameter("operation-comment") ? section.getParameter("operation-comment") : ("#" + (i + 1)); - if (!section.hasDynamicWorkOffset()) { - error(subst(localize("Dynamic work offset has not been set for operation '%1'."), description)); - failed = true; - } - - var o = section.getDynamicWCSOrigin(); - var p = section.getDynamicWCSPlane(); - if (dynamicWCSs[section.getDynamicWorkOffset()]) { - if ((Vector.diff(o, dynamicWCSs[section.getDynamicWorkOffset()].origin).length > 1e-9) || - (Matrix.diff(p, dynamicWCSs[section.getDynamicWorkOffset()].plane).n1 > 1e-9)) { - error(subst(localize("Dynamic WCS mismatch for operation '%1'."), description)); - failed = true; - } - } else { - dynamicWCSs[section.getDynamicWorkOffset()] = {origin:o, plane:p}; - } - } - if (failed) { - return; - } - } - - if (false) { - // check for duplicate tool number - for (var i = 0; i < getNumberOfSections(); ++i) { - var sectioni = getSection(i); - var tooli = sectioni.getTool(); - for (var j = i + 1; j < getNumberOfSections(); ++j) { - var sectionj = getSection(j); - var toolj = sectionj.getTool(); - if (tooli.number == toolj.number) { - if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || - xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || - abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || - (tooli.numberOfFlutes != toolj.numberOfFlutes)) { - error( - subst( - localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), - sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), - sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) - ) - ); - return; - } - } - } - } - } - - if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { - for (var i = 0; i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset > 0) { - error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); - return; - } - } - } - - // absolute coordinates and feed per min - writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } - - coolantPressure = staticProperties.coolantPressure; - - if (staticProperties.chipTransport) { - onCommand(COMMAND_START_CHIP_TRANSPORT); - } - // Probing Surface Inspection - if (typeof inspectionWriteVariables == "function") { - inspectionWriteVariables(); - } -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -var lengthCompensationActive = false; -/** Disables length compensation if currently active or if forced. */ -function disableLengthCompensation(force, message) { - if (lengthCompensationActive || force) { - writeBlock(gFormat.format(49), conditional(message, formatComment(message))); - lengthCompensationActive = false; - } -} - -function writeG187() { - if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "drill")) { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } else if (hasParameter("operation:tolerance")) { - var tolerance = Math.max(getParameter("operation:tolerance"), 0); - if (tolerance > 0) { - var stockToLeaveThreshold = toUnit(0.1, MM); - var stockToLeave = 0; - var verticalStockToLeave = 0; - if (hasParameter("operation:stockToLeave")) { - stockToLeave = xyzFormat.getResultingValue(getParameter("operation:stockToLeave")); - } - if (hasParameter("operation:verticalStockToLeave")) { - verticalStockToLeave = xyzFormat.getResultingValue(getParameter("operation:verticalStockToLeave")); - } - - var workMode; - if (((stockToLeave > stockToLeaveThreshold) && (verticalStockToLeave > stockToLeaveThreshold)) || - (hasParameter("operation:strategy") && getParameter("operation:strategy") == "face")) { - workMode = 1; // roughing - } else { - if ((stockToLeave > 0) || (verticalStockToLeave > 0)) { - workMode = 2; // default - } else { - workMode = 3; // fine - } - } - writeBlock(gFormat.format(187), "P" + workMode); // set tolerance mode - // writeBlock(gFormat.format(187), "P" + workMode, "E" + xyzFormat.format(tolerance)); // set tolerance mode - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return "F#" + (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("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), getParameter("operation: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("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting") && - hasParameter("operation:tool_feedEntry") && - hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(getParameter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { - var feed; - if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { - feed = getParameter("operation:highFeedrate"); - } else { - feed = this.highFeedrate; - } - var feedContext = new FeedContext(id, localize("High Feed"), feed); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - activeMovements[MOVEMENT_RAPID] = feedContext; - } - ++id; - } - - for (var i = 0; i < activeFeeds.length; ++i) { - var feedContext = activeFeeds[i]; - writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description)); - } -} - -var currentWorkPlaneABC = undefined; -var activeG254 = false; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function defineWorkPlane(_section, _setWorkPlane) { - var abc = new Vector(0, 0, 0); - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (_section.isMultiAxis()) { - cancelTransformation(); - abc = _section.getInitialToolAxisABC(); - if (_setWorkPlane) { - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - if (!retracted) { - moveToSafeRetractPosition(); - } - forceWorkPlane(); - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - } - } else { - abc = getWorkPlaneMachineABC(_section.workPlane, _setWorkPlane); - if (_setWorkPlane) { - setWorkPlane(abc); - } - } - } else { // pure 3D - var remaining = _section.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - error(localize("Tool orientation is not supported.")); - return abc; - } - setRotation(remaining); - } - return abc; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - var _skipBlock = false; - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - if (operationNeedsSafeStart) { - _skipBlock = true; - } else { - return; // no change - } - } - skipBlock = _skipBlock; - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(false); - } - - if (activeG254) { - skipBlock = _skipBlock; - activeG254 = false; - writeBlock(gFormat.format(255)); // cancel DWO - } - - gMotionModal.reset(); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - - skipBlock = _skipBlock; - onCommand(COMMAND_LOCK_MULTI_AXIS); - - if (staticProperties.useDWO && - (abcFormat.isSignificant(abc.x % (Math.PI * 2)) || abcFormat.isSignificant(abc.y % (Math.PI * 2)) || abcFormat.isSignificant(abc.z % (Math.PI * 2)))) { - skipBlock = _skipBlock; - activeG254 = true; - writeBlock(gFormat.format(254)); // enable DWO - } - - setCurrentABC(abc); // required for machine simulation - currentWorkPlaneABC = abc; -} - -var closestABC = true; // choose closest machine angles -var currentMachineABC = new Vector(0, 0, 0); - -function getPreferenceWeight(_abc) { - var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); - var abc = new Array(_abc.x, _abc.y, _abc.z); - var preference = 0; - for (var i = 0; i < 3; ++i) { - if (axis[i].isEnabled()) { - preference += ((abcFormat.getResultingValue(abc[axis[i].getCoordinate()]) * axis[i].getPreference()) < 0) ? -1 : 1; - } - } - return preference; -} - -function remapToABC(currentABC, previousABC) { - var both = machineConfiguration.getABCByDirectionBoth(machineConfiguration.getDirection(currentABC)); - var abc1 = machineConfiguration.remapToABC(both[0], previousABC); - abc1 = machineConfiguration.remapABC(abc1); - var abc2 = machineConfiguration.remapToABC(both[1], previousABC); - abc2 = machineConfiguration.remapABC(abc2); - - // choose angles based on preference - var preference1 = getPreferenceWeight(abc1); - var preference2 = getPreferenceWeight(abc2); - if (preference1 > preference2) { - return abc1; - } else if (preference2 > preference1) { - return abc2; - } - - // choose angles based on closest solution - if (Vector.diff(abc1, previousABC).length < Vector.diff(abc2, previousABC).length) { - return abc1; - } else { - return abc2; - } -} - -function getWorkPlaneMachineABC(workPlane, _setWorkPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - if (_setWorkPlane) { - currentMachineABC = abc; - } - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - 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" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function printProbeResults() { - return currentSection.getParameter("printResults", 0) == 1; -} - -function onPassThrough(text) { - var commands = String(text).split(","); - for (text in commands) { - writeBlock(commands[text]); - } -} - -function onManualNC(command, value) { - switch (command) { - case COMMAND_ACTION: - if (String(value).toUpperCase() == "CYCLE_REVERSAL") { - cycleReverse = true; - } else if (String(value).toUpperCase() == "VFD_LOW") { - coolantPressure = "P0"; - } else if (String(value).toUpperCase() == "VFD_NORMAL") { - coolantPressure = "P1"; - } else if (String(value).toUpperCase() == "VFD_HIGH") { - coolantPressure = "P2"; - } else if (String(value).toUpperCase() == "USEPOLARMODE") { - usePolarMode = true; - } - break; - default: - expandManualNC(command, value); - } -} - -var probeOutputWorkOffset = 1; -var stockTopZ = -1; -var stockUpperX; -var stockLowerX; -var stockUpperY; -var stockLowerY; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } - - // Added 6/15/21 | Gavin Williams | will1742 - // Issue 001 Input and Validation - if (name == "stock-upper-z") { - stockTopZ = value; - } - if (name == "stock-upper-x") { - stockUpperX = value; - } - if (name == "stock-lower-x") { - stockLowerX = value; - } - if (name == "stock-upper-y") { - stockUpperY = value; - } - if (name == "stock-lower-y") { - stockLowerY = value; - } -} - -var seenPatternIds = {}; - -function previewImage() { - var permittedExtensions = ["JPG", "MP4", "MOV", "PNG", "JPEG"]; - var patternId = currentSection.getPatternId(); - var show = false; - if (!seenPatternIds[patternId]) { - show = true; - seenPatternIds[patternId] = true; - } - var images = []; - if (show) { - if (FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath))) { - images.push(modelImagePath); - } - if (hasParameter("autodeskcam:preview-name") && FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), getParameter("autodeskcam:preview-name")))) { - images.push(getParameter("autodeskcam:preview-name")); - } - - for (var i = 0; i < images.length; ++i) { - var fileExtension = images[i].slice(images[i].lastIndexOf(".") + 1, images[i].length).toUpperCase(); - var permittedExtension = false; - for (var j = 0; j < permittedExtensions.length; ++j) { - if (fileExtension == permittedExtensions[j]) { - permittedExtension = true; - break; // found - } - } - if (!permittedExtension) { - warning(localize("The image file format " + "\"" + fileExtension + "\"" + " is not supported on HAAS controls.")); - } - - if (!staticProperties.useM130PartImages || !permittedExtension) { - FileSystem.remove(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), images[i])); // remove - images.splice([i], 1); // remove from array - } - } - if (images.length > 0) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(" + images[images.length - 1] + ")") - : - writeOptionalBlock(mFormat.format(130), "(" + images[images.length - 1] + ")"); - } - } -} - -/** Returns true if the spatial vectors are significantly different. */ -function areSpatialVectorsDifferent(_vector1, _vector2) { - return (xyzFormat.getResultingValue(_vector1.x) != xyzFormat.getResultingValue(_vector2.x)) || - (xyzFormat.getResultingValue(_vector1.y) != xyzFormat.getResultingValue(_vector2.y)) || - (xyzFormat.getResultingValue(_vector1.z) != xyzFormat.getResultingValue(_vector2.z)); -} - -/** Returns true if the spatial boxes are a pure translation. */ -function areSpatialBoxesTranslated(_box1, _box2) { - return !areSpatialVectorsDifferent(Vector.diff(_box1[1], _box1[0]), Vector.diff(_box2[1], _box2[0])) && - !areSpatialVectorsDifferent(Vector.diff(_box2[0], _box1[0]), Vector.diff(_box2[1], _box1[1])); -} - -/** Returns true if the spatial boxes are same. */ -function areSpatialBoxesSame(_box1, _box2) { - return !areSpatialVectorsDifferent(_box1[0], _box2[0]) && !areSpatialVectorsDifferent(_box1[1], _box2[1]); -} - -function subprogramDefine(_initialPosition, _abc, _retracted, _zIsOutput) { - // convert patterns into subprograms - var usePattern = false; - patternIsActive = false; - if (currentSection.isPatterned && currentSection.isPatterned() && (getProperty("useSubroutines") == "patterns")) { - currentPattern = currentSection.getPatternId(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_PATTERN) && (currentPattern == definedPatterns[i].patternId)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_PATTERN); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_PATTERN, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: _initialPosition - }); - } - - if (usePattern) { - // make sure Z-position is output prior to subprogram call - if (!_retracted && !_zIsOutput) { - writeBlock(gMotionModal.format(0), zOutput.format(_initialPosition.z)); - } - - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - patternIsActive = true; - - if (firstPattern) { - subprogramStart(_initialPosition, _abc, incrementalSubprogram); - } else { - skipRemainingSection(); - setCurrentPosition(getFramePosition(currentSection.getFinalPosition())); - } - } - } - - // Output cycle operation as subprogram - if (!usePattern && (getProperty("useSubroutines") == "cycles") && currentSection.doesStrictCycle && - (currentSection.getNumberOfCycles() == 1) && currentSection.getNumberOfCyclePoints() >= minimumCyclePoints) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - currentPattern = currentSection.getNumberOfCyclePoints(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_CYCLE) && (currentPattern == definedPatterns[i].patternId) && - !areSpatialVectorsDifferent(_initialPosition, definedPatterns[i].initialPosition) && - !areSpatialVectorsDifferent(finalPosition, definedPatterns[i].finalPosition)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_CYCLE); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_CYCLE, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: finalPosition - }); - } - cycleSubprogramIsActive = usePattern; - } - - // Output each operation as a subprogram - if (!usePattern && (getProperty("useSubroutines") == "allOperations")) { - currentSubprogram = ++lastSubprogram; - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - firstPattern = true; - subprogramStart(_initialPosition, _abc, false); - } -} - -function subprogramStart(_initialPosition, _abc, _incremental) { - redirectToBuffer(); - var comment = ""; - if (hasParameter("operation-comment")) { - comment = getParameter("operation-comment"); - } - writeln( - "N" + nFormat.format(currentSubprogram) + - conditional(comment, formatComment(comment.substr(0, maximumLineLength - 2 - 6 - 1))) - ); - staticProperties.showSequenceNumbers = false; - if (_incremental) { - setIncrementalMode(_initialPosition, _abc); - } - gPlaneModal.reset(); - gMotionModal.reset(); -} - -function subprogramEnd() { - if (firstPattern) { - writeBlock(mFormat.format(99)); - writeln(""); - subprograms += getRedirectionBuffer(); - } - forceAny(); - firstPattern = false; - staticProperties.showSequenceNumbers = saveShowSequenceNumbers; - closeRedirection(); -} - -function subprogramIsValid(_section, _patternId, _patternType) { - var sectionId = _section.getId(); - var numberOfSections = getNumberOfSections(); - var validSubprogram = _patternType != SUB_CYCLE; - - var masterPosition = new Array(); - masterPosition[0] = getFramePosition(_section.getInitialPosition()); - masterPosition[1] = getFramePosition(_section.getFinalPosition()); - var tempBox = _section.getBoundingBox(); - var masterBox = new Array(); - masterBox[0] = getFramePosition(tempBox[0]); - masterBox[1] = getFramePosition(tempBox[1]); - - var rotation = getRotation(); - var translation = getTranslation(); - incrementalSubprogram = undefined; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (section.getId() != sectionId) { - defineWorkPlane(section, false); - // check for valid pattern - if (_patternType == SUB_PATTERN) { - if (section.getPatternId() == _patternId) { - var patternPosition = new Array(); - patternPosition[0] = getFramePosition(section.getInitialPosition()); - patternPosition[1] = getFramePosition(section.getFinalPosition()); - tempBox = section.getBoundingBox(); - var patternBox = new Array(); - patternBox[0] = getFramePosition(tempBox[0]); - patternBox[1] = getFramePosition(tempBox[1]); - - if (areSpatialBoxesSame(masterPosition, patternPosition) && areSpatialBoxesSame(masterBox, patternBox) && !section.isMultiAxis()) { - incrementalSubprogram = incrementalSubprogram ? incrementalSubprogram : false; - } else if (!areSpatialBoxesTranslated(masterPosition, patternPosition) || !areSpatialBoxesTranslated(masterBox, patternBox)) { - validSubprogram = false; - break; - } else { - incrementalSubprogram = true; - } - } - - // check for valid cycle operation - } else if (_patternType == SUB_CYCLE) { - if ((section.getNumberOfCyclePoints() == _patternId) && (section.getNumberOfCycles() == 1)) { - var patternInitial = getFramePosition(section.getInitialPosition()); - var patternFinal = getFramePosition(section.getFinalPosition()); - if (!areSpatialVectorsDifferent(patternInitial, masterPosition[0]) && !areSpatialVectorsDifferent(patternFinal, masterPosition[1])) { - validSubprogram = true; - break; - } - } - } - } - } - setRotation(rotation); - setTranslation(translation); - return (validSubprogram); -} - -function setAxisMode(_format, _output, _prefix, _value, _incr) { - var i = _output.isEnabled(); - if (_output == zOutput) { - _output = _incr ? createIncrementalVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format) : createVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format); - } else { - _output = _incr ? createIncrementalVariable({prefix: _prefix}, _format) : createVariable({prefix: _prefix}, _format); - } - _output.format(_value); - _output.format(_value); - i = i ? _output.enable() : _output.disable(); - return _output; -} - -function setIncrementalMode(xyz, abc) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, true); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, true); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, true); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, true); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, true); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, true); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(91)); - incrementalMode = true; -} - -function setAbsoluteMode(xyz, abc) { - if (incrementalMode) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, false); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, false); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, false); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, false); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, false); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, false); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(90)); - incrementalMode = false; - } -} - -function onSection() { - if (isFirstSection()) { - writeln(""); - writeComment("STOCK PREP"); - var Stock_X_55 = (stockUpperX + stockLowerX)/2; - // TODO: Tolerance Checks - // writeln(macroFormat.format(100) + "=[" + macroFormat.format(5241) + "+" + xyzFormat.format(Stock_X_55) + "]"); - // writeWords("IF [" + macroFormat.format(100) + " GT 0.] THEN " + macroFormat.format(100) + "=0."); - // writeWords("IF [" + macroFormat.format(100) + " LT " + (X_TRAVEL_LIMIT*-1) + "." + "] THEN " + macroFormat.format(100) + "=" + (X_TRAVEL_LIMIT*-1) + "."); - // writeBlock(gFormat.format(53), "X" + macroFormat.format(100), yOutput.format(0)); - writeBlock(gFormat.format(55), gFormat.format(0), xOutput.format(Stock_X_55)); - writeBlock(gFormat.format(53), gFormat.format(0), yOutput.format(0)); - displayMedia("loadStock.jpg", false); - } - - - // 07/06/21 | Gavin Williams | will1742 - // 002 Improved Probing - // uses pencil to verify WCS, prompts user - if (isFirstSection() && getProperty("pencilWCSValidation")) { - var stockMidX = (stockUpperX + stockLowerX)/2; - var stockMidY = (stockUpperY + stockLowerY)/2; - writeln(""); - writeComment("VERIFY WCS"); - writeBlock("T" + toolFormat.format(19), mFormat.format(6)); //Changes Tool - - writeBlock(gFormat.format(55), gFormat.format(0), forceX.format(stockMidX), forceY.format(stockMidY)); - displayMedia("xyWCSCheck.jpg", false, "Open door and check x-y position"); - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - var gotoRef = takeInput("Is the pencil centered above your stock? stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - writeBlock(gFormat.format(55), gFormat.format(43), hFormat.format(19), zOutput.format(stockTopZ)); - displayMedia("zWCSCheck.jpg", false, "Open door and check z position"); - - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - gotoRef = takeInput("Is the pencil touching the center of your stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - } - - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - retracted = false; - - var zIsOutput = false; // true if the Z-position has been output, used for patterns - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || - (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || - getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations - - operationNeedsSafeStart = staticProperties.safeStartAllOperations && !isFirstSection(); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.fastToolChange && !isProbeOperation()) { - currentCoolantMode = COOLANT_OFF; - } else if (insertToolCall) { // no coolant off command if safe start operation - onCommand(COMMAND_COOLANT_OFF); - } - } - - if ((insertToolCall && !staticProperties.fastToolChange) || newWorkOffset || newWorkPlane || toolChecked) { - - // stop spindle before retract during tool change - if (insertToolCall && !isFirstSection() && !toolChecked && !staticProperties.fastToolChange) { - onCommand(COMMAND_STOP_SPINDLE); - } - - // retract to safe plane - writeRetract(Z); - - if (forceResetWorkPlane && newWorkPlane) { - forceWorkPlane(); - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - } - } - - if (!isFirstSection() && getProperty("toolLengthValidation")) { - displayMedia("checkPartTool.jpg", false, "Check Part and Tool"); - } else if (!isFirstSection()) { - writeBlock(mFormat.format(1)); - writeComment("Check Part and Tool"); - } - - if (hasParameter("operation-comment")) { - var comment = getParameter("operation-comment"); - if (comment && ((comment !== lastOperationComment) || !patternIsActive || insertToolCall)) { - writeln(""); - writeComment(comment); - lastOperationComment = comment; - } else if (!patternIsActive || insertToolCall) { - writeln(""); - } - } else { - writeln(""); - } - - if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { - // throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." - } - - if (staticProperties.showNotes) { - var notes = getParameter("notes"); - writeComment("PEER MENTOR 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); - } - } - } - } - - // enable polar interpolation - if (usePolarMode && (tool.type != TOOL_PROBE)) { - if (polarDirection == undefined) { - error(localize("Polar direction property must be a vector - x,y,z.")); - return; - } - setPolarMode(currentSection, true); - } - - defineWorkPlane(currentSection, false); - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - forceAny(); - - if (operationNeedsSafeStart) { - if (!retracted) { - // skipBlock = true; - writeRetract(Z); - } - } - - if (insertToolCall || operationNeedsSafeStart) { - - if (staticProperties.useM130PartImages) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(tool" + tool.number + ".png)") - : - writeOptionalBlock(mFormat.format(130), "(tool" + tool.number + ".png)"); - } - - if (!isFirstSection() && staticProperties.optionalStop && insertToolCall) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if ((tool.number > 200 && tool.number < 1000) || tool.number > 9999) { - warning(localize("Tool number out of range.")); - } - - skipBlock = !insertToolCall; - writeToolBlock( - "T" + toolFormat.format(tool.number), - mFormat.format(6) - ); - if (tool.comment) { - writeComment(tool.comment); - } - if (measureTool) { - writeToolMeasureBlock(tool, false); - } - if (insertToolCall) { - forceWorkPlane(); - } - 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") + "=" + xyzFormat.format(zRange.getMinimum())); - } - } - } - - // activate those two coolant modes before the spindle is turned on - if ((tool.coolant == COOLANT_THROUGH_TOOL) || (tool.coolant == COOLANT_AIR_THROUGH_TOOL) || (tool.coolant == COOLANT_FLOOD_THROUGH_TOOL)) { - if (!isFirstSection() && !insertToolCall && (currentCoolantMode != tool.coolant)) { - onCommand(COMMAND_STOP_SPINDLE); - forceSpindleSpeed = true; - } - // setCoolant(tool.coolant); - } else if ((currentCoolantMode == COOLANT_THROUGH_TOOL) || (currentCoolantMode == COOLANT_AIR_THROUGH_TOOL) || (currentCoolantMode == COOLANT_FLOOD_THROUGH_TOOL)) { - onCommand(COMMAND_STOP_SPINDLE); - setCoolant(COOLANT_OFF); - forceSpindleSpeed = true; - } - - if (toolChecked) { - forceSpindleSpeed = true; // spindle must be restarted if tool is checked without a tool change - toolChecked = false; // state of tool is not known at the beginning of a section since it could be broken for the previous section - } - var spindleChanged = tool.type != TOOL_PROBE && - (insertToolCall || forceSpindleSpeed || isFirstSection() || - (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)); - if (spindleChanged || (operationNeedsSafeStart && tool.type != TOOL_PROBE)) { - forceSpindleSpeed = false; - - if (spindleSpeed < 1) { - error(localize("Spindle speed out of range.")); - return; - } - maximumSpindleRPM = machineConfiguration.getMaximumSpindleSpeed() > 0 ? machineConfiguration.getMaximumSpindleSpeed() : maximumSpindleRPM; - if (spindleSpeed > maximumSpindleRPM) { - warning(subst(localize("Spindle speed '" + spindleSpeed + " RPM' exceeds maximum value of '%1 RPM."), maximumSpindleRPM)); - } - // skipBlock = !spindleChanged; - writeBlock( - sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) - ); - } - - previewImage(); - - if (staticProperties.useParametricFeed && - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill") && // legacy - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(); - } - } else { - activeMovements = undefined; - } - - // wcs - if (insertToolCall || operationNeedsSafeStart) { // force work offset when changing tool - currentWorkOffset = undefined; - skipBlock = operationNeedsSafeStart && !newWorkOffset && !insertToolCall; - } - 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 > 6) { - var code = workOffset - 6; - if (code > 99) { - error(localize("Work offset out of range.")); - return; - } - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(154), "P" + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - if (newWorkPlane || (insertToolCall && !retracted)) { // go to home position for safety - if (!retracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing && machineConfiguration.isMultiAxisConfiguration()) { - writeRetract(X, Y); - } - } - - // Unwind axis if previous section was Multi-Axis - if (!isFirstSection() && (getPreviousSection().isMultiAxis() || usePolarMode) && machineConfiguration.isMachineCoordinate(2)) { // TAG - if (!retracted) { - moveToSafeRetractPosition(); - } - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - currentMachineABC.setZ(0); - } - - if (newWorkOffset) { - forceWorkPlane(); - } - - var abc = defineWorkPlane(currentSection, true); - - setProbeAngle(); // output probe angle rotations if required - - gMotionModal.reset(); - - if (staticProperties.useG187) { - writeG187(); - } - - var G = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? 1 : 0; - var F = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? getFeed(toPreciseUnit(highFeedrate, MM)) : ""; - if (insertToolCall || retracted || operationNeedsSafeStart || !lengthCompensationActive || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))) { - var _skipBlock = !(insertToolCall || retracted || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))); - var lengthOffset = tool.lengthOffset; - if ((lengthOffset > 200 && lengthOffset < 1000) || lengthOffset > 9999) { - error(localize("Length offset out of range.")); - return; - } - - gMotionModal.reset(); - writeBlock(gPlaneModal.format(17)); - - if (usePolarMode) { - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(); - } - var polarPosition = getPolarPosition(initialPosition.x, initialPosition.y, initialPosition.z); - setCurrentPositionAndDirection(polarPosition); - initialPosition = new Vector(polarPosition.first.x, polarPosition.first.y, polarPosition.first.z); - writeBlock(gMotionModal.format(0), aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - } - - if (!machineConfiguration.isHeadConfiguration()) { - if (tcpIsSupported && useDwoForPositioning && currentSection.isMultiAxis()) { - var O = machineConfiguration.getOrientation(abc); - var initialPositionDWO = O.getTransposed().multiply(getGlobalPosition(currentSection.getInitialPosition())); - // writeComment("PREPOSITIONING START"); - skipBlock = _skipBlock; - writeBlock(gFormat.format(254)); - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPositionDWO.x), yOutput.format(initialPositionDWO.y), F); - skipBlock = _skipBlock; - writeBlock(gFormat.format(255)); - // writeComment("PREPOSITIONING END"); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), // G0 motion mode is required for the G234 command - gFormat.format(234), - xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } else { - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), F); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } - } else { - skipBlock = _skipBlock; - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(currentSection.isMultiAxis() && tcpIsSupported ? 0 : G), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y), - zOutput.format(initialPosition.z), - F, - hFormat.format(lengthOffset) - ); - } - zIsOutput = true; - lengthCompensationActive = true; - if (_skipBlock) { - forceXYZ(); - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - } else { - validate(lengthCompensationActive, "Length compensation is not active."); - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - zIsOutput = true; - } - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - if (gMotionModal.getCurrent() == 0) { - forceFeed(); - } - gMotionModal.reset(); - validate(lengthCompensationActive, "Length compensation is not active."); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.preloadTool) { - var nextTool = getNextTool(tool.number); - if (nextTool) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(nextTool.number)); - } else { - // preload first tool - var section = getSection(0); - var firstToolNumber = section.getTool().number; - if (tool.number != firstToolNumber) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(firstToolNumber)); - } - } - } - } - - if (isProbeOperation()) { - validate(probeVariables.probeAngleMethod != "G68", "You cannot probe while G68 Rotation is in effect."); - validate(probeVariables.probeAngleMethod != "G54.4", "You cannot probe while workpiece setting error compensation G54.4 is enabled."); - writeBlock(gFormat.format(65), "P" + 9832); // spin the probe on - inspectionCreateResultsFileHeader(); - } else { - // surface Inspection - if (isInspectionOperation() && (typeof inspectionProcessSectionStart == "function")) { - inspectionProcessSectionStart(); - } - } - - if (getProperty("toolLengthValidation")) { - writeComment("TOOL VALIDATION"); - // Added 06/15/21 | Gavin Williams | will1742 - // Verifies tool-stock distance. Post fails if tool fails clearance standards - if (toolDistance < CLEARANCE_HEIGHT) { - throw "Error: Clearance height must be " + CLEARANCE_HEIGHT + " or more inches from stock"; - } - - if (toolDistance == Infinity) { - throw "Error: invalid tool distance. Contact a TA."; - } - var toolDistance = initialPosition.z - stockTopZ; - - // Prompt user to check stock-tool distance - displayMedia("checkDistance" + toolDistance.toPrecision(2).toString().replace(".", "_") + ".jpg", false, "Check tool distance: " + toolDistance.toPrecision(2).toString() + "in"); - writeComment("OPEN DOOR"); - //displayMedia("Net Share/Media/checkPrompt.jpg"); - - // asks user if measured height is accurate to displayed - //var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['N', 'Y']); - - // Create GOTO cases for Y/N selection, halt if N - /* - getTA("Net Share/Media/TAWarning.jpg", gotoRef['N'], onSecGotoRef); - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - writeWords( - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - */ - - // initialize spindle and engage coolant if heights are correct - if (tool.type != TOOL_PROBE) { - writeBlock(mFormat.format((tool.clockwise ? 3 : 4))); - } - } - - if (tool.type != TOOL_PROBE) { - setCoolant(tool.coolant); - writeBlock(gFormat.format(4), "P500"); - } - - writeComment("BEGIN OPERATION"); - // define subprogram - subprogramDefine(initialPosition, abc, retracted, zIsOutput); -} - -// Added 9/30/21 | Kevin Pan | pan261 -// Issue 001 Input and Validation, Issue 029 -// Displays a file: MP4, MOV, PNG, JPEG. 1920x1080 or comments if displayeMediaCalls is false -// Input: Absolute path to file, optional calls, comment to write with m0 -function displayMedia(file, isOptional, comment) { - var writeFunction = isOptional ? writeOptionalBlock : writeBlock; - - if (!getProperty("displayMediaCalls")) { - writeFunction(mFormat.format(0)); - comment ? - writeComment(comment) - : - null; - return; - } else { - writeFunction(mFormat.format(130), formatComment("Net Share/Media/" + file)); - comment ? - writeFunction(mFormat.format(0), formatComment(comment)) - : - writeFunction(mFormat.format(0)); - writeFunction(mFormat.format(131)); - } -} - -// Added 6/14/21 | Gavin Williams | will1742 -// Issue 001 Input and Validation -// Takes input from the user -// Input: string prompt, will be displayed to users -// char array options, capital letters accepted as input -// int opSeqNum, optional arg to init prompt at specific value -// Output: 2D dict {Letter, Coorresponding GOTO} -// EX: [Y, 56][N, 57] -var macroNumber = 500; -function takeInput(prompt, options) { - - // Cycle through macro variables, reset at end of general purpose vars - if (macroNumber > 549) macroNumber = 500; - - // init macro var to 0 - setMacro(macroNumber, 0, "Initialize macro variable", false); - - // disply prompt and save response - writeBlock(mFormat.format(109), "P" + nFormat.format(macroNumber), formatComment(prompt)); - sequenceNumber -= staticProperties.sequenceNumberIncrement; - var gotoRef = sequenceNumber; - - // wait for input - writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + nFormat.format(gotoRef) + " " + formatComment("NULL")); - - // print if's and goto's - var gotoMap = {}; - var gotoInc = 1; - options.forEach(function (element) { - writeWords("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc), formatComment(element)); - gotoMap[element] = (sequenceNumber + gotoInc); - gotoInc += 1; - }); - - var incNum = staticProperties.sequenceNumberIncrement; - // adjust sequence number if needed - for (i = incNum; i < gotoInc; i+=incNum) { - sequenceNumber += staticProperties.sequenceNumberIncrement; - } - - // return to input until valid option is entered - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("INVALID INPUT")); - - // increase var number, iterate sequence number - macroNumber += 1; - sequenceNumber += staticProperties.sequenceNumberIncrement; - return gotoMap; -} - -// Added 06/15/21 | Gavin Williamas | will1742 -// Issue 001 Input and validation -// Halts program until TA arrives. Jumps to gotoRef -function getTA(file, seqNum, gotoRef) { - writeWords("N" + nFormat.format(seqNum), - gFormat.format(53), gFormat.format(0), zOutput.format(0.), - formatComment("Retract spindle")); - writeWords(mFormat.format(130), formatComment(file)); - writeWords(mFormat.format(0), formatComment("Halt Program")); - writeWords(mFormat.format(131)); - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("Return to beginning of operation")); -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - seconds = clamp(0.001, seconds, 99999.999); - writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + milliFormat.format(seconds * 1000)); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(sOutput.format(spindleSpeed)); -} - -function onCycle() { - writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r, c) { - forceXYZ(); - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - return [xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), - zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), - bOutput.format(polarPosition.second.y), - cOutput.format(polarPosition.second.z), - "R" + xyzFormat.format(r)]; - } else { - if (incrementalMode) { - zOutput.format(c); - return [xOutput.format(x), yOutput.format(y), - "Z" + xyzFormat.format(z - r), - "R" + xyzFormat.format(r - c)]; - } else { - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; - } - } -} - -function setCyclePosition(_position) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - zOutput.format(_position); - break; - case 18: // ZX - yOutput.format(_position); - break; - case 19: // YZ - xOutput.format(_position); - break; - } -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function setProbeAngleMethod() { - probeVariables.probeAngleMethod = (machineConfiguration.getNumberOfAxes() < 5 || is3D()) ? (getProperty("useG54x4") ? "G54.4" : "G68") : "UNSUPPORTED"; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i = 0; i < axes.length; ++i) { - if (axes[i].isEnabled() && isSameDirection((axes[i].getAxis()).getAbsolute(), new Vector(0, 0, 1)) && axes[i].isTable()) { - probeVariables.probeAngleMethod = "AXIS_ROT"; - probeVariables.rotationalAxis = axes[i].getCoordinate(); - break; - } - } - probeVariables.outputRotationCodes = true; -} - -/** Output rotation offset based on angular probing cycle. */ -function setProbeAngle() { - if (probeVariables.outputRotationCodes) { - validate(probeOutputWorkOffset <= 6, "Angular Probing only supports work offsets 1-6."); - if (probeVariables.probeAngleMethod == "G68" && (Vector.diff(currentSection.getGlobalInitialToolAxis(), new Vector(0, 0, 1)).length > 1e-4)) { - error(localize("You cannot use multi axis toolpaths while G68 Rotation is in effect.")); - } - var validateWorkOffset = false; - switch (probeVariables.probeAngleMethod) { - case "G54.4": - var param = 26000 + (probeOutputWorkOffset * 10); - writeBlock("#" + param + "=#135"); - writeBlock("#" + (param + 1) + "=#136"); - writeBlock("#" + (param + 5) + "=#144"); - writeBlock(gFormat.format(54.4), "P" + probeOutputWorkOffset); - break; - case "G68": - gRotationModal.reset(); - gAbsIncModal.reset(); - writeBlock(gRotationModal.format(68), gAbsIncModal.format(90), probeVariables.compensationXY, "R[#194]"); - validateWorkOffset = true; - break; - case "AXIS_ROT": - var param = 5200 + probeOutputWorkOffset * 20 + probeVariables.rotationalAxis + 4; - writeBlock("#" + param + " = " + "[#" + param + " + #194]"); - forceWorkPlane(); // force workplane to rotate ABC in order to apply rotation offsets - currentWorkOffset = undefined; // force WCS output to make use of updated parameters - validateWorkOffset = true; - break; - default: - error(localize("Angular Probing is not supported for this machine configuration.")); - return; - } - if (validateWorkOffset) { - for (var i = currentSection.getId(); i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset != currentSection.workOffset) { - error(localize("WCS offset cannot change while using angle rotation compensation.")); - return; - } - } - } - probeVariables.outputRotationCodes = false; - } -} - -function protectedProbeMove(_cycle, x, y, z) { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - var _z = zOutput.format(z); - if (_z && z >= getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } - if (_x || _y) { - writeBlock(gFormat.format(65), "P" + 9810, _x, _y, getFeed(highFeedrate)); // protected positioning move - } - if (_z && z < getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } -} - -function cancelG68Rotation(force) { - if (force) { - gRotationModal.reset(); - } - writeBlock(gRotationModal.format(69)); -} - -function onCyclePoint(x, y, z) { - if (isInspectionOperation() && (typeof inspectionCycleInspect == "function")) { - inspectionCycleInspect(cycle, x, y, z); - return; - } - if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { - expandCyclePoint(x, y, z); - return; - } - if (isProbeOperation()) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { - if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } else if (staticProperties.useDWO) { - error(localize("Your machine does not support the selected probing operation with DWO enabled.")); - return; - } - } - if (printProbeResults()) { - writeProbingToolpathInformation(z - cycle.depth + tool.diameter / 2); - inspectionWriteCADTransform(); - inspectionWriteWorkplaneTransform(); - if (typeof inspectionWriteVariables == "function") { - inspectionVariables.pointNumber += 1; - } - } - protectedProbeMove(cycle, x, y, z); - } - - var forceCycle = false; - switch (cycleType) { - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceCycle = true; - if (!isFirstCyclePoint()) { - writeBlock(gCycleModal.format(80)); - gMotionModal.reset(); - } - } - if (forceCycle || isFirstCyclePoint() || isProbeOperation()) { - if (!isProbeOperation()) { - // return to initial Z which is clearance plane and set absolute mode - repositionToCycleClearance(cycle, x, y, z); - } - - var F = cycle.feedrate; - var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "chip-breaking": - if ((cycle.accumulatedDepth < cycle.depth) && (cycle.incrementalDepthReduction > 0)) { - expandCyclePoint(x, y, z); - } else if (cycle.accumulatedDepth < cycle.depth) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - ("Q" + xyzFormat.format(cycle.incrementalDepth)), - ("K" + xyzFormat.format(cycle.accumulatedDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "deep-drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "left-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "right-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - // Parameter 57 bit 6, REPT RIG TAP, is set to 1 (On) - // On Mill software versions12.09 and above, REPT RIG TAP has been moved from the Parameters to Setting 133 - var u = cycle.stock; - var step = cycle.incrementalDepth; - var first = true; - while (u > cycle.bottom) { - if (step < cycle.minimumIncrementalDepth) { - step = cycle.minimumIncrementalDepth; - } - - u -= step; - step -= cycle.incrementalDepthReduction; - gCycleModal.reset(); // required - if ((u - 0.001) <= cycle.bottom) { - u = cycle.bottom; - } - if (first) { - first = false; - writeBlock( - gRetractModal.format(99), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), - getCommonCycle((gPlaneModal.getCurrent() == 19) ? u : x, (gPlaneModal.getCurrent() == 18) ? u : y, (gPlaneModal.getCurrent() == 17) ? u : z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - } else { - var position; - var depth; - switch (gPlaneModal.getCurrent()) { - case 17: - xOutput.reset(); - position = xOutput.format(x); - depth = "Z" + xyzFormat.format(u); - break; - case 18: - zOutput.reset(); - position = zOutput.format(z); - depth = "Y" + xyzFormat.format(u); - break; - case 19: - yOutput.reset(); - position = yOutput.format(y); - depth = "X" + xyzFormat.format(u); - break; - } - writeBlock(conditional(u <= cycle.bottom, gRetractModal.format(98)), position, depth); - } - } - forceFeed(); - break; - case "fine-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - break; - case "back-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; - var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; - var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; - writeBlock( - gRetractModal.format(98), gCycleModal.format(77), - getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom, cycle.clearance), - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "reaming": - writeBlock( - gRetractModal.format(98), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - - case "probing-x": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-y": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-z": - protectedProbeMove(cycle, x, y, Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock( - gFormat.format(65), "P" + 9811, - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "Z" + xyzFormat.format(z - cycle.depth), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "Z" + xyzFormat.format(z - cycle.depth), - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-inner-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9815, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-outer-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9816, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 90), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-y-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 0), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-xy-pcd-hole": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "K" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - case "probing-xy-pcd-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - default: - expandCyclePoint(x, y, z); - } - - // place cycle operation in subprogram - if (cycleSubprogramIsActive) { - if (forceCycle || cycleExpanded || isProbeOperation()) { - cycleSubprogramIsActive = false; - } else { - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - subprogramStart(new Vector(x, y, z), new Vector(0, 0, 0), false); - } - } - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - - // 2nd through nth cycle point - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - writeBlock(xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - return; - } - var _x; - var _y; - var _z; - if (!xyzFormat.areDifferent(x, xOutput.getCurrent()) && - !xyzFormat.areDifferent(y, yOutput.getCurrent()) && - !xyzFormat.areDifferent(z, zOutput.getCurrent())) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - xOutput.reset(); // at least one axis is required - break; - case 18: // ZX - zOutput.reset(); // at least one axis is required - break; - case 19: // YZ - yOutput.reset(); // at least one axis is required - break; - } - } - if (incrementalMode) { // set current position to retract height - setCyclePosition(cycle.retract); - } - writeBlock(xOutput.format(x), yOutput.format(y), zOutput.format(z)); - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - } - } -} - -function getProbingArguments(cycle, updateWCS) { - var outputWCSCode = updateWCS && currentSection.strategy == "probe"; - if (outputWCSCode) { - validate(probeOutputWorkOffset <= 99, "Work offset is out of range."); - var nextWorkOffset = hasNextSection() ? getNextSection().workOffset == 0 ? 1 : getNextSection().workOffset : -1; - if (probeOutputWorkOffset == nextWorkOffset) { - currentWorkOffset = undefined; - } - } - return [ - (cycle.angleAskewAction == "stop-message" ? "B" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), - ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "F" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), - (cycle.wrongSizeAction == "stop-message" ? "H" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), - (cycle.outOfPositionAction == "stop-message" ? "M" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), - ((cycle.updateToolWear && cycleType == "probing-z") ? "T" + xyzFormat.format(cycle.toolLengthOffset) : undefined), - ((cycle.updateToolWear && cycleType !== "probing-z") ? "T" + xyzFormat.format(cycle.toolDiameterOffset) : undefined), - (cycle.updateToolWear ? "V" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), - (cycle.printResults ? "W" + xyzFormat.format(1 + cycle.incrementComponent) : undefined), // 1 for advance feature, 2 for reset feature count and advance component number. first reported result in a program should use W2. - conditional(outputWCSCode, "S" + probeWCSFormat.format(probeOutputWorkOffset > 6 ? (0.01 * (probeOutputWorkOffset - 6) + 154) : probeOutputWorkOffset)) - ]; -} - -function onCycleEnd() { - if (isProbeOperation()) { - zOutput.reset(); - gMotionModal.reset(); - writeBlock(gFormat.format(65), "P" + 9810, zOutput.format(cycle.retract)); // protected retract move - } else { - if (cycleSubprogramIsActive) { - subprogramEnd(); - cycleSubprogramIsActive = false; - } - if (!cycleExpanded) { - writeBlock(gCycleModal.format(80), conditional(staticProperties.useG95forTapping, gFeedModeModal.format(94))); - gMotionModal.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 traversal.")); - return; - } - if (!staticProperties.useG0 && (((x ? 1 : 0) + (y ? 1 : 0) + (z ? 1 : 0)) > 1)) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z); - forceFeed(); - } - } -} - -function onLinear(_x, _y, _z, feed) { - if (pendingRadiusCompensation >= 0) { - // ensure that we end at desired position when compensation is turned off - xOutput.reset(); - yOutput.reset(); - } - 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; - var d = tool.diameterOffset; - if ((d > 200 && d < 1000) || d > 9999) { - warning(localize("Diameter offset out of range.")); - } - writeBlock(gPlaneModal.format(17), gFeedModeModal.format(94)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); - break; - case RADIUS_COMPENSATION_RIGHT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(1), f); - } - } -} - -var forceG0 = false; -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var num = - (xyzFormat.areDifferent(_x, xOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_y, yOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_z, zOutput.getCurrent()) ? 1 : 0) + - ((aOutput.isEnabled() && abcFormat.areDifferent(_a, aOutput.getCurrent())) ? 1 : 0) + - ((bOutput.isEnabled() && abcFormat.areDifferent(_b, bOutput.getCurrent())) ? 1 : 0) + - ((cOutput.isEnabled() && abcFormat.areDifferent(_c, cOutput.getCurrent())) ? 1 : 0); - /* - if (!getProperty("useG0") && !forceG0 && (tcpIsSupported || (num > 1))) { - invokeOnLinear5D(_x, _y, _z, _a, _b, _c, highFeedrate); // onLinear5D handles inverse time feedrates - forceG0 = false; - return; - } - */ - 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); - - if (x || y || z || a || b || c) { - if (!staticProperties.useG0 && (tcpIsSupported || (num > 1))) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, a, b, c, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z, a, b, c); - forceFeed(); - } - } -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed, feedMode) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - 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); - - if (feedMode == FEED_INVERSE_TIME) { - forceFeed(); - } - var f = getFeed(feed); - var fMode = (feedMode == FEED_INVERSE_TIME) ? 93 : 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); - } - } -} - -function moveToSafeRetractPosition(isRetracted) { - var _skipBlock = skipBlock; - if (!isRetracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing) { - skipBlock = _skipBlock; - writeRetract(X, Y); - } -} - -// Start of onRewindMachine logic -var performRewinds = false; // only use this setting with hardcoded machine configurations, set to true to enable the rewind/reconfigure logic -var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values -safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock -safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate -safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate - -/** Allow user to override the onRewind logic. */ -function onRewindMachineEntry(_a, _b, _c) { - return false; -} - -/** Retract to safe position before indexing rotaries. */ -function onMoveToSafeRetractPosition() { - // cancel TCP so that tool doesn't follow rotaries - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - moveToSafeRetractPosition(false); -} - -/** Rotate axes to new position above reentry position */ -function onRotateAxes(_x, _y, _z, _a, _b, _c) { - // position rotary axes - xOutput.disable(); - yOutput.disable(); - zOutput.disable(); - forceG0 = true; - invokeOnRapid5D(_x, _y, _z, _a, _b, _c); - setCurrentABC(new Vector(_a, _b, _c)); - xOutput.enable(); - yOutput.enable(); - zOutput.enable(); -} - -/** Return from safe position after indexing rotaries. */ -function onReturnFromSafeRetractPosition(_x, _y, _z) { - // reinstate TCP - if (tcpIsSupported) { - writeBlock(gMotionModal.format(0), gFormat.format(234), hFormat.format(tool.lengthOffset), formatComment("TCPC ON")); - forceFeed(); - lengthCompensationActive = true; - } - - // position in XY - forceXYZ(); - xOutput.reset(); - yOutput.reset(); - zOutput.disable(); - invokeOnRapid(_x, _y, _z); - - // position in Z - zOutput.enable(); - invokeOnRapid(_x, _y, _z); -} -// End of onRewindMachine logic - -// Start of polar interpolation -var usePolarMode = false; // enables polar interpolation for a single operation -var polarDirection = new Vector(1, 0, 0); // vector to maintain tool at while in polar interpolation -var saveTcpIsSupported = undefined; -function setPolarMode(section, mode) { - if (!mode) { // turn off polar mode if required - if (usePolarMode) { - var currentPosition = getCurrentPosition(); - var polarPosition = getPolarPosition(currentPosition.x, currentPosition.y, currentPosition.z); - currentMachineABC = new Vector(polarPosition.second.x, polarPosition.second.y, polarPosition.second.z); - deactivatePolarMode(); - tcpIsSupported = saveTcpIsSupported; - setFeedrateMode(true); - usePolarMode = false; - } - return; - } - - var direction = polarDirection; - - // determine the rotary axis to use for polar interpolation - var axis = undefined; - if (machineConfiguration.getAxisV().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisV().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisV(); - } - } - if (axis == undefined && machineConfiguration.getAxisU().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisU().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisU(); - } - } - if (axis == undefined) { - error(localize("Polar interpolation requires an active rotary axis be defined in direction of workplane normal.")); - } - - // calculate directional vector from initial position - if (direction == undefined) { - error(localize("Polar interpolation initiated without a directional vector.")); - return; - } else if (direction.isZero()) { - var initialPosition = getFramePosition(section.getInitialPosition()); - direction = Vector.diff(initialPosition, axis.getOffset()).getNormalized(); - } - - // put vector in plane of rotary axis - var temp = Vector.cross(direction, axis.getAxis()).getNormalized(); - direction = Vector.cross(axis.getAxis(), temp).getNormalized(); - - // activate polar interpolation - saveTcpIsSupported = tcpIsSupported; - tcpIsSupported = false; // temporary disable tcp support for polar mode - setFeedrateMode(); - activatePolarMode(tolerance / 2, 0, direction); -} -// End of polar interpolation - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - if (isSpiral()) { - var startRadius = getCircularStartRadius(); - var endRadius = getCircularRadius(); - var dr = Math.abs(endRadius - startRadius); - if (dr > maximumCircularRadiiDifference) { // maximum limit - linearize(tolerance); // or alternatively use other G-codes for spiral motion - return; - } - } - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (staticProperties.useRadius || isHelical()) { // radius mode does not support full arcs - linearize(tolerance); - return; - } - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } else if (!staticProperties.useRadius) { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), 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: - writeBlock(gPlaneModal.format(18), 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: - writeBlock(gPlaneModal.format(19), 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: - 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: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } -} - -var currentCoolantMode = COOLANT_OFF; -var coolantOff = undefined; -var isOptionalCoolant = false; - -function setCoolant(coolant) { - var coolantCodes = getCoolantCodes(coolant); - forceSingleLine = false; - if ((coolantCodes != undefined) && (coolant == COOLANT_FLOOD)) { - if (coolantPressure != "") { - forceSingleLine = true; - coolantCodes.push(coolantPressure); - } - } - if (Array.isArray(coolantCodes)) { - if (singleLineCoolant || forceSingleLine) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes.join(getWordSeparator())); - } else { - for (var c in coolantCodes) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes[c]); - } - } - return undefined; - } - return coolantCodes; -} - -var isSpecialCoolantActive = false; - -function getCoolantCodes(coolant) { - isOptionalCoolant = false; - var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line - if (!coolants) { - error(localize("Coolants have not been defined.")); - } - if (isProbeOperation()) { // avoid coolant output for probing - coolant = COOLANT_OFF; - } - if (coolant == currentCoolantMode) { - if (operationNeedsSafeStart && coolant != COOLANT_OFF && !isSpecialCoolantActive) { - //isOptionalCoolant = true; - } else if (!forceCoolant || coolant == COOLANT_OFF) { - return undefined; // coolant is already active - } - } - if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && !isOptionalCoolant && !forceCoolant) { - if (Array.isArray(coolantOff)) { - for (var i in coolantOff) { - multipleCoolantBlocks.push(mFormat.format(coolantOff[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(coolantOff)); - } - } - forceCoolant = false; - - if (isSpecialCoolantActive) { - forceSpindleSpeed = true; - } - var m; - var coolantCodes = {}; - for (var c in coolants) { // find required coolant codes into the coolants array - if (coolants[c].id == coolant) { - isSpecialCoolantActive = (coolants[c].id == COOLANT_THROUGH_TOOL) || (coolants[c].id == COOLANT_FLOOD_THROUGH_TOOL) || (coolants[c].id == COOLANT_AIR_THROUGH_TOOL); - 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(mFormat.format(m[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(m)); - } - currentCoolantMode = coolant; - return multipleCoolantBlocks; // return the single formatted coolant value - } - return undefined; -} - -var mapCommand = { - COMMAND_END:2, - 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; - forceCoolant = true; - return; - case COMMAND_OPTIONAL_STOP: - writeBlock(mFormat.format(1)); - forceSpindleSpeed = true; - forceCoolant = true; - return; - case COMMAND_COOLANT_ON: - setCoolant(COOLANT_FLOOD); - return; - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_LOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(10)); // lock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(12)); // lock 5th-axis motion - } - } - return; - case COMMAND_UNLOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(11)); // unlock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(13)); // unlock 5th-axis motion - } - } - return; - case COMMAND_BREAK_CONTROL: - if (!toolChecked) { // avoid duplicate COMMAND_BREAK_CONTROL - prepareForToolCheck(); - writeBlock( - gFormat.format(65), - "P" + 9853, - "T" + toolFormat.format(tool.number), - "B" + xyzFormat.format(0), - "H" + xyzFormat.format(staticProperties.toolBreakageTolerance) - ); - toolChecked = true; - lengthCompensationActive = false; // macro 9853 cancels tool length compensation - } - return; - case COMMAND_TOOL_MEASURE: - measureTool = true; - return; - case COMMAND_START_CHIP_TRANSPORT: - writeBlock(mFormat.format(31)); - return; - case COMMAND_STOP_CHIP_TRANSPORT: - writeBlock(mFormat.format(33)); - return; - case COMMAND_PROBE_ON: - return; - case COMMAND_PROBE_OFF: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -var toolChecked = false; // specifies that the tool has been checked with the probe - -function onSectionEnd() { - if (isInspectionOperation() && !isLastSection()) { - writeBlock(gFormat.format(103), "P0", formatComment("LOOKAHEAD ON")); - } - if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) { - setCoolant(COOLANT_OFF); - } - if ((((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) && - tool.breakControl) { - onCommand(COMMAND_BREAK_CONTROL); - } else { - toolChecked = false; - } - - if (true) { - if (isRedirecting()) { - if (firstPattern) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - var abc; - if (currentSection.isMultiAxis() && machineConfiguration.isMultiAxisConfiguration()) { - abc = currentSection.getFinalToolAxisABC(); - } else { - abc = currentWorkPlaneABC; - } - if (abc == undefined) { - abc = new Vector(0, 0, 0); - } - setAbsoluteMode(finalPosition, abc); - subprogramEnd(); - } - } - } - forceAny(); - - if (currentSection.isMultiAxis()) { - writeBlock(gFeedModeModal.format(94)); // inverse time feed off - if (currentSection.isOptimizedForMachine()) { - // the code below gets the machine angles from previous operation. closestABC must also be set to true - currentMachineABC = currentSection.getFinalToolAxisABC(); - } - if (tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - } - - if (isProbeOperation()) { - writeBlock(gFormat.format(65), "P" + 9833); // spin the probe off - if (probeVariables.probeAngleMethod != "G68") { - setProbeAngle(); // output probe angle rotations if required - } - } - - // reset for next section - operationNeedsSafeStart = false; - coolantPressure = staticProperties.coolantPressure; - cycleReverse = false; - - setPolarMode(currentSection, false); -} - -/** Output block to do safe retract and/or move to home position. */ -function writeRetract() { - var words = []; // store all retracted axes in an array - var retractAxes = new Array(false, false, false); - var method = staticProperties.safePositionMethod; - if (method == "clearanceHeight") { - if (!is3D()) { - error(localize("Retract option 'Clearance Height' is not supported for multi-axis machining.")); - } else { - return; - } - } - validate(arguments.length != 0, "No axis specified for writeRetract()."); - - for (i in arguments) { - retractAxes[arguments[i]] = true; - } - if ((retractAxes[0] || retractAxes[1]) && !retracted && !skipBlock) { // retract Z first before moving to X/Y home - error(localize("Retracting in X/Y is not possible without being retracted in Z.")); - return; - } - // special conditions - if (retractAxes[0] || retractAxes[1]) { - method = "G53"; - } - cancelG68Rotation(); // G68 has to be canceled for retracts - - // define home positions - var _xHome; - var _yHome; - var _zHome; - if (method == "G28") { - _xHome = toPreciseUnit(0, MM); - _yHome = toPreciseUnit(0, MM); - _zHome = toPreciseUnit(0, MM); - } else { - if (homePositionCenter && - hasParameter("part-upper-x") && hasParameter("part-lower-x")) { - _xHome = (getParameter("part-upper-x") + getParameter("part-lower-x")) / 2; - } else { - _xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM); - } - _yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM); - _zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM); - } - for (var i = 0; i < arguments.length; ++i) { - switch (arguments[i]) { - case X: - // special conditions - if (homePositionCenter) { // output X in standard block by itself if centering - writeBlock(gMotionModal.format(0), "X" + xyzFormat.format(_xHome)); - xOutput.reset(); - break; - } - 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 = !skipBlock; - break; - default: - error(localize("Unsupported axis specified for writeRetract().")); - return; - } - } - if (words.length > 0) { - switch (method) { - case "G28": - gMotionModal.reset(); - gAbsIncModal.reset(); - writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); - writeBlock(gAbsIncModal.format(90)); - break; - case "G53": - gMotionModal.reset(); - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); - break; - default: - error(localize("Unsupported safe position method.")); - return; - } - } -} - -var isDPRNTopen = false; -function inspectionCreateResultsFileHeader() { - if (isDPRNTopen) { - if (!staticProperties.singleResultsFile) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - } - } - - if (isProbeOperation() && !printProbeResults()) { - return; // if print results is not desired by probe/ probeWCS - } - - if (!isDPRNTopen) { - writeBlock("PCLOS"); - writeBlock("POPEN"); - // check for existence of none alphanumeric characters but not spaces - var resFile; - if (staticProperties.singleResultsFile) { - resFile = getParameter("job-description") + "-RESULTS"; - } else { - resFile = getParameter("operation-comment") + "-RESULTS"; - } - resFile = resFile.replace(/:/g, "-"); - resFile = resFile.replace(/[^a-zA-Z0-9 -]/g, ""); - resFile = resFile.replace(/\s/g, "-"); - writeln("DPRNT[START]"); - writeln("DPRNT[RESULTSFILE*" + resFile + "]"); - if (hasGlobalParameter("document-id")) { - writeln("DPRNT[DOCUMENTID*" + getGlobalParameter("document-id") + "]"); - } - if (hasGlobalParameter("model-version")) { - writeln("DPRNT[MODELVERSION*" + getGlobalParameter("model-version") + "]"); - } - } - if (isProbeOperation() && printProbeResults()) { - isDPRNTopen = true; - } -} - -function getPointNumber() { - if (typeof inspectionWriteVariables == "function") { - return (inspectionVariables.pointNumber); - } else { - return ("#172[60]"); - } -} - -function inspectionWriteCADTransform() { - var cadOrigin = currentSection.getModelOrigin(); - var cadWorkPlane = currentSection.getModelPlane().getTransposed(); - var cadEuler = cadWorkPlane.getEuler2(EULER_XYZ_S); - writeln( - "DPRNT[G331" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(cadEuler.x) + - "*B" + abcFormat.format(cadEuler.y) + - "*C" + abcFormat.format(cadEuler.z) + - "*X" + xyzFormat.format(-cadOrigin.x) + - "*Y" + xyzFormat.format(-cadOrigin.y) + - "*Z" + xyzFormat.format(-cadOrigin.z) + - "]" - ); -} - -function inspectionWriteWorkplaneTransform() { - var orientation = (machineConfiguration.isMultiAxisConfiguration() && currentMachineABC != undefined) ? machineConfiguration.getOrientation(currentMachineABC) : currentSection.workPlane; - var abc = orientation.getEuler2(EULER_XYZ_S); - writeln("DPRNT[G330" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(abc.x) + - "*B" + abcFormat.format(abc.y) + - "*C" + abcFormat.format(abc.z) + - "*X0*Y0*Z0*I0*R0]" - ); -} - -function writeProbingToolpathInformation(cycleDepth) { - writeln("DPRNT[TOOLPATHID*" + getParameter("autodeskcam:operation-id") + "]"); - if (isInspectionOperation()) { - writeln("DPRNT[TOOLPATH*" + getParameter("operation-comment") + "]"); - } else { - writeln("DPRNT[CYCLEDEPTH*" + xyzFormat.format(cycleDepth) + "]"); - } -} - -function onClose() { - writeRetract(Z); - - if (isDPRNTopen) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - if (typeof inspectionProcessSectionEnd == "function") { - inspectionProcessSectionEnd(); - } - } - cancelG68Rotation(); - writeln(""); - - optionalSection = false; - - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - writeBlock(mFormat.format(0)); - - writeln(""); - writeComment("UNLOAD TOOLS"); - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - if (tool.number == 20 || tool.number == 19) { - continue; - } - writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - displayMedia("removeTool" + tool.number + ".jpg", false, "Remove tool " + tool.number); - } - } - - function gotoWithMessage(xLoc, yLoc, fileName, comment) { - writeBlock(gFormat.format(53), xOutput.format(xLoc), yOutput.format(yLoc)); - displayMedia(fileName, false, comment); - } - - writeln(""); - writeComment("CLEAN MACHINE"); - gotoWithMessage(X_TRAVEL_LIMIT/2, 0, "airGunClean.jpg", "Use air gun to clean"); - displayMedia("floodCoolantOff.jpg", false, "Turn flood coolant off") - setCoolant(COOLANT_FLOOD); - gotoWithMessage(0, Y_TRAVEL_LIMIT, "sprayLowerRight.jpg", "Spray lower right"); - gotoWithMessage(X_TRAVEL_LIMIT, Y_TRAVEL_LIMIT, "sprayLowerLeft.jpg", "Spray lower left"); - gotoWithMessage(0, 0, "sprayUpperRight.jpg", "Spray upper right") - gotoWithMessage(X_TRAVEL_LIMIT, 0, "sprayUpperLeft.jpg", "Spray upper left") - onCommand(COMMAND_COOLANT_OFF); - onCommand(COMMAND_START_CHIP_TRANSPORT); - gotoWithMessage(X_TRAVEL_LIMIT/2, Y_TRAVEL_LIMIT, "sweepChips.jpg", "Sweep chips"); - onCommand(COMMAND_STOP_CHIP_TRANSPORT); - - writeln(""); - // retract - if (!staticProperties.homePositionCenter || currentMachineABC.length != 0) { - writeRetract(X, Y); - } - - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - - // MAY NEED CHANGE HOMING ORDER TO ROTARY THEN LINEAR FOR NON-UMC MACHINES - - // Unwind Rotary table at end - if (machineConfiguration.isMultiAxisConfiguration()) { - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - if (machineConfiguration.isMachineCoordinate(2)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(1)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "B" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(0)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "A" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(0)) - ); - } - if (staticProperties.homePositionCenter) { - homePositionCenter = staticProperties.homePositionCenter; - writeRetract(X, Y); - } - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - - if (staticProperties.useM130PartImages || staticProperties.useM130ToolImages) { - writeBlock(mFormat.format(131)); - } - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - if (subprograms.length > 0) { - writeln(""); - write(subprograms); - } - writeln(""); - writeln("%"); -} - -/* -keywords += (keywords ? " MODEL_IMAGE" : "MODEL_IMAGE"); - -function onTerminate() { - var outputPath = getOutputPath(); - var programFilename = FileSystem.getFilename(outputPath); - var programSize = FileSystem.getFileSize(outputPath); - var postPath = findFile("setup-sheet-excel-2007.cps"); - var intermediatePath = getIntermediatePath(); - var a = "--property unit " + ((unit == IN) ? "0" : "1"); // use 0 for inch and 1 for mm - if (programName) { - a += " --property programName \"'" + programName + "'\""; - } - if (programComment) { - a += " --property programComment \"'" + programComment + "'\""; - } - a += " --property programFilename \"'" + programFilename + "'\""; - a += " --property programSize \"" + programSize + "\""; - a += " --noeditor --log temp.log \"" + postPath + "\" \"" + intermediatePath + "\" \"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\""; - execute(getPostProcessorPath(), a, false, ""); - executeNoWait("excel", "\"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\"", false, ""); -} -*/ - -function setProperty(property, value) { - properties[property].current = value; -} diff --git a/Haas_Mills_BIDC/Bechtel Milling.cps b/Haas_Mills_BIDC/Bechtel Milling.cps index 6ae1fae..9c6f192 100644 --- a/Haas_Mills_BIDC/Bechtel Milling.cps +++ b/Haas_Mills_BIDC/Bechtel Milling.cps @@ -539,7 +539,7 @@ staticProperties = { hasAAxis: "false", hasBAxis: "false", hasCAxis: "false", - postVersion: "BIDC-NGC.G11.K21-1" + postVersion: "BIDC-NGC-v1.1.0" }; const HAAS_DRILL = 1; @@ -2483,7 +2483,8 @@ function onSection() { } if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { - // throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." + writeComment("Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor."); + throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." } if (staticProperties.showNotes) { diff --git a/Haas_Mills_BIDC/Bechtel VF2.cps b/Haas_Mills_BIDC/Bechtel VF2.cps deleted file mode 100644 index 4d0b5b7..0000000 --- a/Haas_Mills_BIDC/Bechtel VF2.cps +++ /dev/null @@ -1,4658 +0,0 @@ -/** - Copyright (C) 2012-2021 by Autodesk, Inc. - All rights reserved. - - HAAS post processor configuration. - - $Revision: 43348 37c695f19b2eab4d5737a29df773b981b83fa8d4 $ - $Date: 2021-07-12 15:10:04 $ - - Modified by BIDC of Purdue University - Authors: Gavin Williams (will1742@purdue.edu) -*/ - -//////////////////////////////////////////////////////////////////////////////////////////////// -// MANUAL NC COMMANDS -// -// The following ACTION commands are supported by this post. -// -// CYCLE_REVERSAL - Reverses the spindle in a drilling cycle -// USEPOLARMODE - Enables polar interpolation for the following operation. -// VFD_HIGH - Uses high pressure flood coolant if machine has VFD -// VFD_LOW - Uses low pressure flood coolant if machine has VFD -// VFD_NORMAL - Uses normal pressure flood coolant if machine has VFD -// -//////////////////////////////////////////////////////////////////////////////////////////////// - -description = "HAAS - Next Generation Control"; -vendor = "Haas Automation"; -vendorUrl = "https://www.haascnc.com"; -legal = "Copyright (C) 2012-2021 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 45702; - -longDescription = "Generic post for the HAAS Next Generation control. The post includes support for multi-axis indexing and simultaneous machining. The post utilizes the dynamic work offset feature so you can place your work piece as desired without having to repost your NC programs." + EOL + -"You can specify following pre-configured machines by using the property 'Machine model':" + EOL + -"UMC-500" + EOL + "UMC-750" + EOL + "UMC-1000" + EOL + "UMC-1600-H"; - -extension = "nc"; -programNameIsInteger = true; -setCodePage("ascii"); -keywords = "MODEL_IMAGE PREVIEW_IMAGE"; - -capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(355); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion -allowSpiralMoves = true; -highFeedrate = (unit == IN) ? 650 : 5000; - -// user-defined properties -properties = {/* - machineModel: { - title: "Machine model", - description: "Specifies the pre-configured machine model.", - type: "enum", - group: 0, - values: [ - {title: "None", id: "none"}, - {title: "UMC-500", id: "umc-500"}, - {title: "UMC-750", id: "umc-750"}, - {title: "UMC-1000", id: "umc-1000"}, - {title: "UMC-1600-H", id: "umc-1600"} - ], - value: "none", - scope: "post" - }, - hasAAxis: { - title: "Has A-axis rotary", - description: "Enable if the machine has an A-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasBAxis: { - title: "Has B-axis rotary", - description: "Enable if the machine has a B-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasCAxis: { - title: "Has C-axis rotary", - description: "Enable if the machine has a C-axis table. Specifies a trunnion setup if an A-axis or B-axis is defined. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - throughSpindle: { - title: "Allow Through Spindle Coolant", - description: "Enables through spindle coolant, if off uses flood", - type: "boolean", - group: 50, - value: true, - scope: "post" - }, - useDPMFeeds: { - title: "Rotary moves use DPM feeds", - description: "Enable to output DPM feeds, disable for Inverse Time feeds with rotary axes moves.", - group: 1, - type: "boolean", - value: false, - scope: "post" - },*/ - useTCPC: { - title: "Use TCPC programming", - description: "The control supports Tool Center Point Control programming.", - group: 1, - type: "boolean", - value: true, - scope: "post" - },/* - useDWO: { - title: "Use DWO", - description: "Specifies that the Dynamic Work Offset feature (G254/G255) should be used.", - group: 1, - type: "boolean", - value: true, - scope: "post" - }, - preloadTool: { - title: "Preload tool", - description: "Preloads the next tool at a tool change (if any).", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - chipTransport: { - title: "Use chip transport", - description: "Enable to turn on chip transport at start of program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - optionalStop: { - title: "Optional stop", - description: "Specifies that optional stops M1 should be output at tool changes.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - separateWordsWithSpace: { - title: "Separate words with space", - description: "Adds spaces between words if 'yes' is selected.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useRadius: { - title: "Radius arcs", - description: "If yes is selected, arcs are output using radius values rather than IJK.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useParametricFeed: { - title: "Parametric feed", - description: "Parametric feed values based on movement type are output.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useG0: { - title: "Use G0", - description: "Specifies that G0s should be used for rapid moves when moving along a single axis.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - safePositionMethod: { - title: "Safe Retracts", - description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.", - type: "enum", - values: [ - {title: "G28", id: "G28"}, - {title: "G53", id: "G53"}, - {title: "Clearance Height", id: "clearanceHeight"} - ], - value: "G53", - scope: "post" - }, - useG187: { - title: "Use G187", - description: "Specifies that smoothing using G187 should be used.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - homePositionCenter: { - title: "Home position center", - description: "Enable to center the part along X at the end of program for easy access. Requires a CNC with a moving table.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - optionallyCycleToolsAtStart: { - title: "Optionally cycle tools at start", - description: "Cycle through each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - measureToolsAtStart: { - title: "Optionally measure tools at start", - description: "Measure each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - forceHomeOnIndexing: { - title: "Force XY home position on indexing", - description: "Move XY to their home positions on multi-axis indexing.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - toolBreakageTolerance: { - title: "Tool breakage tolerance", - description: "Specifies the tolerance for which tool break detection will raise an alarm.", - group: 2, - type: "spatial", - value: 0.1, - scope: "post" - }, - safeStartAllOperations: { - title: "Safe start all operations", - description: "Write optional blocks at the beginning of all operations that include all commands to start program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - fastToolChange: { - title: "Fast tool change", - description: "Skip spindle off, coolant off, and Z retract to make tool change quicker.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useG95forTapping: { - title: "Use G95 for tapping", - description: "use IPR/MPR instead of IPM/MPM for tapping", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - safeRetractDistance: { - title: "Safe retract distance", - description: "Specifies the distance to add to retract distance when rewinding rotary axes.", - group: 2, - type: "spatial", - value: 0, - scope: "post" - },*/ - useSubroutines: { - title: "Use subroutines", - description: "Select your desired subroutine option. 'All Operations' creates subroutines per each operation, 'Cycles' creates subroutines for cycle operations on same holes, and 'Patterns' creates subroutines for patterned operations.", - type: "enum", - values: [ - {title: "No", id: "none"}, - {title: "All Operations", id: "allOperations"}, - {title: "Cycles", id: "cycles"}, - {title: "Patterns", id: "patterns"} - ], - group: 3, - value: "none", - scope: "post" - },/* - writeMachine: { - title: "Write machine", - description: "Output the machine settings in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - writeTools: { - title: "Write tool list", - description: "Output a tool list in the header of the code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - writeVersion: { - title: "Write version", - description: "Write the version number in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showSequenceNumbers: { - title: "Use sequence numbers", - description: "Use sequence numbers for each block of outputted code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - sequenceNumberStart: { - title: "Start sequence number", - description: "The number at which to start the sequence numbers.", - group: 4, - type: "integer", - value: 10, - scope: "post" - }, - sequenceNumberIncrement: { - title: "Sequence number increment", - description: "The amount by which the sequence number is incremented by in each block.", - group: 4, - type: "integer", - value: 5, - scope: "post" - }, - sequenceNumberOnlyOnToolChange: { - title: "Block number only on tool change", - description: "Specifies that block numbers should only be output at tool changes.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showNotes: { - title: "Show notes", - description: "Enable to output notes for operations.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - useM130PartImages: { - title: "Include M130 part images", - description: "Enable to include M130 part images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - useM130ToolImages: { - title: "Include M130 tool images", - description: "Enable to include M130 tool images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - coolantPressure: { - title: "Coolant pressure", - description: "Select the coolant pressure if equipped with a Variable Frequency Drive. Select 'Default' if this option is not installed.", - type: "enum", - group: 2, - values: [ - {title: "Default", id: ""}, - {title: "Low", id: "P0"}, - {title: "Normal", id: "P1"}, - {title: "High", id: "P2"} - ], - value: "", - scope: "post" - }, - singleResultsFile: { - title: "Create single results file", - description: "Set to false if you want to store the measurement results for each probe / inspection toolpath in a separate file", - group: 0, - type: "boolean", - value: true, - scope: "post" - }*/ - toolsToLoad: { - title: "Tools to load and probe", - description: "List or provide a range of tools to probe e.g. 1, 2, 3 or 1-5. Leaving this empty will probe all tools", - group: 4, - type: "string", - value: "", - scope: "post" - }, - toolLengthValidation: { - title: "Tool Length Validation", - description: "Length validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - pencilWCSValidation: { - title: "WCS Validation", - description: "WCS validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - measureToolsAtStart: { - title: "Tool Probing", - description: "Tool Probing. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - loadToolsAtStart: { - title: "Tool Loading", - description: "Tool Loading. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - displayMediaCalls: { - title: "Display Media", - description: "Enable to include M130 part images with the NC file, disable to see the information in comments.", - group: 4, - value: false, - scope: "post" - } -}; - -staticProperties = { - machineModel: "none", - safePositionMethod: "G53", - useDPMFeeds: false, - useTCPC: true, - useDWO: true, - safeStartAllOperations: true, - preloadTool: true, - chipTransport: false, - optionalStop: true, - separateWordsWithSpace: true, - useRadius: false, - useParametricFeed: true, - useG0: true, - useG187: false, - homePositionCenter: false, - optionallyCycleToolsAtStart: false, - measureToolsAtStart: true, - forceHomeOnIndexing: false, - toolBreakageTolerance: 0.1, - fastToolChange: false, - useG95forTapping: true, - safeRetractDistance: 0, - //useSubroutines: "allOperations", - writeMachine: false, - writeTools: true, - writeVersion: false, - showSequenceNumbers: true, - sequenceNumberStart: 10, - sequenceNumberIncrement: 5, - sequenceNumberOnlyOnToolChange: false, - showNotes: true, - useM130PartImages: false, - useM130ToolImages: false, - coolantPressure: "", - singleResultsFile: true, - useP9995: true, - hasAAxis: "false", - hasBAxis: "false", - hasCAxis: "false", - postVersion: "VF2G8A21" - }; - - const HAAS_DRILL = 1; - const HAAS_TAP = 2; - const HAAS_SHELL = 3; - const HAAS_END_MILL = 4; - const HAAS_CENTER = 5; - const HAAS_BALL_NOSE = 6; - const HAAS_PROBE = 7; - - const NO_PROBING = 0; - const LEN_ROT = 1; - const LEN_NON_ROT = 2; - const LEN_DIA_ROT = 3; - - const DEFAULT_HAAS_K_FACTOR = 0.05; - const NULL_HAAS_K_FACTOR = 0; - - const CLEARANCE_HEIGHT = 1; - const LENGTH_TOLERANCE = .25; - const DIAM_TOLERANCE = .01; - - // VF4 specific - const MAX_TOOL_LENGTH = 11; - const MAX_TOOL_DIAM = 5; - const X_TRAVEL_LIMIT = -30; - const Y_TRAVEL_LIMIT = -15; - - const MAX_TOOL_NUM = 20; - -var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines -// samples: -// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} -// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} -var coolants = [ - {id: COOLANT_FLOOD, on: 8}, - {id: COOLANT_MIST}, - {id: COOLANT_THROUGH_TOOL, on: 88, off: 89}, - {id: COOLANT_AIR, on: 83, off: 84}, - {id: COOLANT_AIR_THROUGH_TOOL, on: 73, off: 74}, - {id: COOLANT_SUCTION}, - {id: COOLANT_FLOOD_MIST}, - {id: COOLANT_FLOOD_THROUGH_TOOL, on: [88, 8], off: [89, 9]}, - {id: COOLANT_OFF, off: 9} -]; - -// old machines only support 4 digits -var oFormat = createFormat({width:5, zeropad:true, decimals:0}); -var nFormat = createFormat({decimals:0}); - -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 probeWCSFormat = createFormat({decimals:2, forceDecimal:true}); -var macroFormat = createFormat({prefix:"#", decimals:0}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var rFormat = xyzFormat; // radius -var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true}); -var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var forceX = createFormat({prefix:"X", decimals:4, forceDecimal:true}); -var forceY = createFormat({prefix:"Y", decimals:4, forceDecimal:true}); -var forceZ = createFormat({prefix:"Z", decimals:4, forceDecimal:true}); - -var xOutput = createVariable({prefix:"X"}, xyzFormat); -var yOutput = createVariable({prefix:"Y"}, xyzFormat); -var zOutput = createVariable({onchange: function() {retracted = false;}, prefix:"Z"}, xyzFormat); -var aOutput = createVariable({prefix:"A"}, abcFormat); -var bOutput = createVariable({prefix:"B"}, abcFormat); -var cOutput = createVariable({prefix:"C"}, abcFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var dOutput = createVariable({}, dFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat); -var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat); -var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat); - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({force:true}, gFormat); // modal group 10 // G98-99 -var gRotationModal = createModal({ - onchange: function () { - if (probeVariables.probeAngleMethod == "G68") { - probeVariables.outputRotationCodes = true; - } - } -}, gFormat); // modal group 16 // G68-G69 - -// fixed settings -var firstFeedParameter = 100; // the first variable to use with parametric feed -var forceResetWorkPlane = false; // enable to force reset of machine ABC on new orientation -var minimumCyclePoints = 5; // minimum number of points in cycle operation to consider for subprogram -var useDwoForPositioning = true; // specifies to use the DWO feature for XY positioning for multi-axis operations - -var WARNING_WORK_OFFSET = 0; - -var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported -var probeVariables = { - outputRotationCodes: false, // defines if it is required to output rotation codes - probeAngleMethod: "OFF", // OFF, AXIS_ROT, G68, G54.4 - compensationXY: undefined, - rotationalAxis: -1 -}; - -var SUB_UNKNOWN = 0; -var SUB_PATTERN = 1; -var SUB_CYCLE = 2; - -// collected state -var sequenceNumber; -var currentWorkOffset; -var coolantPressure; -var optionalSection = false; -var forceSpindleSpeed = false; -var forceCoolant = false; -var activeMovements; // do not use by default -var currentFeedId; -var maximumCircularRadiiDifference = toPreciseUnit(0.005, MM); -var maximumLineLength = 80; // the maximum number of charaters allowed in a line -var subprograms = []; -var currentPattern = -1; -var firstPattern = false; -var currentSubprogram; -var lastSubprogram; -var initialSubprogramNumber = 90000; -var definedPatterns = new Array(); -var incrementalMode = false; -var saveShowSequenceNumbers; -var cycleSubprogramIsActive = false; -var patternIsActive = false; -var lastOperationComment = ""; -var incrementalSubprogram; -var retracted = false; // specifies that the tool has been retracted to the safe plane -var hasA = false; -var hasB = false; -var hasC = false; -var measureTool = false; -var cycleReverse = false; -var probeMultipleFeatures = true; -var maximumSpindleRPM = 15000; -var homePositionCenter = false; - -// used to convert blocks to optional for safeStartAllOperations, might get used outside of onSection -var operationNeedsSafeStart = false; - -/** - Writes the specified block. -*/ -var skipBlock = false; -function writeBlock() { - var text = formatWords(arguments); - if (!text) { - return; - } - var maximumSequenceNumber = ((getProperty("useSubroutines") == "allOperations") || (getProperty("useSubroutines") == "patterns") || - (getProperty("useSubroutines") == "cycles")) ? initialSubprogramNumber : 99999; - if (staticProperties.showSequenceNumbers) { - if (sequenceNumber >= maximumSequenceNumber) { - sequenceNumber = staticProperties.sequenceNumberStart; - } - if (optionalSection || skipBlock) { - if (text) { - writeWords("/", "N" + sequenceNumber, text); - } - } else { - writeWords2("N" + sequenceNumber, arguments); - } - sequenceNumber += staticProperties.sequenceNumberIncrement; - } else { - if (optionalSection || skipBlock) { - writeWords2("/", arguments); - } else { - writeWords(arguments); - } - } - skipBlock = false; -} - -/** - Writes the specified block - used for tool changes only. -*/ -function writeToolBlock() { - var show = staticProperties.showSequenceNumbers; - staticProperties.showSequenceNumbers = (show || staticProperties.sequenceNumberOnlyOnToolChange); - writeBlock(arguments); - staticProperties.showSequenceNumbers = show; -} - -/** - Writes the specified optional block. -*/ -function writeOptionalBlock() { - skipBlock = true; - writeBlock(arguments); -} - -function formatComment(text) { - return "(" + String(text).replace(/[()]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text.substr(0, maximumLineLength - 2))); -} - -/** - Returns the matching HAAS tool type for the tool. -*/ -function getHaasToolType(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return 1; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return 2; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return 3; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - return 4; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_THREAD: - case TOOL_MILLING_FORM: - return 5; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - return 6; // ball nose - case TOOL_PROBE: - return 7; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -function getHaasProbingType(toolType, use9023) { - switch (getHaasToolType(toolType)) { - case 3: - case 4: - return (use9023 ? 23 : 1); // rotate - case 1: - case 2: - case 5: - case 6: - case 7: - return (use9023 ? 12 : 2); // non rotate - case 0: - return (use9023 ? 13 : 3); // rotate length and dia - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - - -// Added new probe mapping - see documentation -// will1742 | Gavin Williams -function getHaasToolTypeBIDC(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return HAAS_DRILL; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return HAAS_TAP; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return HAAS_SHELL; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - case TOOL_MILLING_THREAD: - return HAAS_END_MILL; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_FORM: - return HAAS_CENTER; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - case TOOL_MILLING_RADIUS: - return HAAS_BALL_NOSE; // ball nose - case TOOL_PROBE: - return HAAS_PROBE; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -// 06/25/21 | Gavin Williams | will1742 -// 002 Probing -function formatCNumber(probeType, use9023){ - if (use9023) { - if (probeType == LEN_NON_ROT || probeType == LEN_DIA_ROT){ - return probeType + 10; - } - return 23; - } - return probeType; -} - -function getHaasProbingTypeBIDC(tool, use9023) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_PROBE: - return formatCNumber(NO_PROBING, use9023); - case HAAS_TAP: - case HAAS_DRILL: - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_CENTER: - if (tool.type == TOOL_MILLING_FORM) { - return formatCNumber(NO_PROBING, use9023); - } - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_END_MILL: - return formatCNumber((tool.type == TOOL_MILLING_TAPERED ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_BALL_NOSE: - return formatCNumber((tool.type == TOOL_MILLING_RADIUS ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_SHELL: - if ((tool.type == TOOL_MILLING_FACE) && (tool.taperAngle !=0)) { - return formatCNumber(LEN_ROT, use9023); - } - return formatCNumber(LEN_DIA_ROT, use9023); - default: - return -1; - } -} - -function getHaasKFactorBIDC(tool) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_SHELL: - case HAAS_END_MILL: - if (tool.type == TOOL_BORING_BAR || tool.type == TOOL_MILLING_END_FLAT) { - return DEFAULT_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_FACE && tool.taperAngle != 0) { - return NULL_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_THREAD) { - return DEFAULT_HAAS_K_FACTOR + tool.getThreadPitch(); - } - return DEFAULT_HAAS_K_FACTOR + tool.cornerRadius; - case HAAS_BALL_NOSE: - if (tool.type == TOOL_MILLING_RADIUS) { - return NULL_HAAS_K_FACTOR; - } - return DEFAULT_HAAS_K_FACTOR + (tool.diameter/2); - case HAAS_CENTER: - case HAAS_PROBE: - case HAAS_DRILL: - case HAAS_TAP: - - return NULL_HAAS_K_FACTOR; - default: - return -1; - } -} - -function writeToolCycleBlock(tool) { - writeOptionalBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - writeOptionalBlock(mFormat.format(0)); // wait for operator -} - -function prepareForToolCheck() { - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - - // cancel TCP so that tool doesn't follow tables - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - if ((currentSection.isMultiAxis() && getCurrentDirection().length != 0) || - (currentMachineABC != undefined && currentMachineABC.length != 0)) { - setWorkPlane(new Vector(0, 0, 0)); - forceWorkPlane(); - } -} - -function writeToolMeasureBlock(tool, preMeasure) { - var writeFunction = getProperty("measureToolsAtStart") ? writeBlock : writeOptionalBlock; - var comment = measureTool ? formatComment("MEASURE TOOL") : ""; - if (!preMeasure) { - prepareForToolCheck(); - } - if (!staticProperties.useP9995) { // use Macro P9023 to measure tools - var probingType = getHaasProbingTypeBIDC(tool.type, true); - writeFunction( - gFormat.format(65), - "P9023", - "A" + probingType + ".", - "T" + toolFormat.format(tool.number), - conditional((probingType != 12), "H" + xyzFormat.format(tool.bodyLength + tool.holderLength)), - conditional((probingType != 12), "D" + xyzFormat.format(tool.diameter)), - comment - ); - } else { // use Macro P9995 to measure tools - // writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - setMacro(1600 + tool.number, tool.numberOfFlutes, "Number of Flutes", !getProperty("measureToolsAtStart")); - setMacro(2400 + tool.number, xyzFormat.format(tool.diameter), "Tool Diameter", !getProperty("measureToolsAtStart")); - var probeType = getHaasProbingTypeBIDC(tool, false); - writeFunction( - gFormat.format(65), - "P9995", - "A0.", - "B" + getHaasToolTypeBIDC(tool.type) + ".", - "C" + probeType + ".", - "T" + toolFormat.format(tool.number), - "E" + xyzFormat.format(tool.bodyLength + tool.holderLength), - "D" + xyzFormat.format(tool.diameter), - "K" + xyzFormat.format(getHaasKFactorBIDC(tool)), - "I0.", - comment - ); // probe tooling - var line1 = "IF [[#" + (2000 + tool.number) + " GT " + - (tool.bodyLength + tool.holderLength + LENGTH_TOLERANCE).toFixed(2) + "] OR [#" + - (2000 + tool.number) + " LT " + - (tool.bodyLength + tool.holderLength - LENGTH_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool length out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line1 : "/ " + line1); - if (probeType == 3) { - var line2 = "IF [[#" + (2400 + tool.number) + " GT " + - (tool.diameter + DIAM_TOLERANCE).toFixed(2) + "] OR [#" + - (2400 + tool.number) + " LT " + - (tool.diameter - DIAM_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool diameter out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line2 : "/ " + line2); - } - } - measureTool = false; -} - -// 6/28/21 | Gavin Williams | will1742 -// 002 Improved Probing -// sets specified macro number with value -function setMacro(macro, value, comment, isOptional) { - if (isOptional) { - writeWords("/ #" + macro + "=" + value, "(" + comment + ")"); - } else { - writeWords("#" + macro + "=" + value, "(" + comment + ")"); - } -} - -function defineMachineModel() { - var useTCPC = getProperty("useTCPC"); - switch (staticProperties.machineModel) { - case "umc-500": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-23.96, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-3.37, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-750": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-29.0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-8, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(2.5, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1000": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-40.07, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-10.76, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1600": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-120, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 7500; - break; - } - machineConfiguration.setModel(staticProperties.machineModel.toUpperCase()); - machineConfiguration.setVendor("Haas Automation"); - - setMachineConfiguration(machineConfiguration); - if (receivedMachineConfiguration) { - warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); - receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten - } -} - -// Start of machine configuration logic -var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads -var virtualTooltip = false; // translate the pivot point to the virtual tool tip for nonTCP rotary heads -// internal variables, do not change -var receivedMachineConfiguration; -var tcpIsSupported; - -function activateMachine() { - // determine if TCP is supported by the machine - tcpIsSupported = false; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i in axes) { - if (axes[i].isEnabled() && axes[i].isTCPEnabled()) { - tcpIsSupported = true; - break; - } - } - - // setup usage of multiAxisFeatures - useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : - (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); - useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : - (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); - - if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { - cOutput.disable(); - } - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // don't need to modify any settings for 3-axis machines - } - - // retract/reconfigure - safeRetractDistance = staticProperties.safeRetractDistance != undefined ? staticProperties.safeRetractDistance : - (typeof safeRetractDistance == "number" ? safeRetractDistance : 0); - if (machineConfiguration.performRewinds() || (typeof performRewinds == "undefined" ? false : performRewinds)) { - machineConfiguration.enableMachineRewinds(); // enables the rewind/reconfigure logic - if (typeof stockExpansion != "undefined") { - machineConfiguration.setRewindStockExpansion(stockExpansion); - if (!receivedMachineConfiguration) { - setMachineConfiguration(machineConfiguration); - } - } - } - - if (machineConfiguration.isHeadConfiguration()) { - compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; - virtualTooltip = typeof virtualTooltip == "undefined" ? false : virtualTooltip; - machineConfiguration.setVirtualTooltip(virtualTooltip); - } - setFeedrateMode(); - - if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.isMultiAxis()) { - machineConfiguration.setToolLength(section.getTool().getBodyLength()); // define the tool length for head adjustments - section.optimizeMachineAnglesByMachine(machineConfiguration, tcpIsSupported ? 0 : 1); - } - } - } else { - optimizeMachineAngles2(tcpIsSupported ? 0 : 1); - } -} - -function setFeedrateMode(reset) { - if ((tcpIsSupported && !reset) || !machineConfiguration.isMultiAxisConfiguration()) { - return; - } - machineConfiguration.setMultiAxisFeedrate( - tcpIsSupported ? FEED_FPM : staticProperties.useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, - 9999.99, // maximum output value for inverse time feed rates - INVERSE_MINUTES, // can be INVERSE_SECONDS or DPM_COMBINATION for DPM feeds - 0.5, // tolerance to determine when the DPM feed has changed - 1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations - ); - if (!receivedMachineConfiguration || (revision < 45765)) { - setMachineConfiguration(machineConfiguration); - } -} - -function defineMachine() { - hasA = staticProperties.hasAAxis != "false"; - hasB = staticProperties.hasBAxis != "false"; - hasC = staticProperties.hasCAxis != "false"; - - if (hasA && hasB && hasC) { - error(localize("Only two rotary axes can be active at the same time.")); - return; - } else if ((hasA || hasB || hasC) && staticProperties.machineModel != "none") { - error(localize("You can only select either a machine model or use the ABC axis properties.")); - return; - } else if (((hasA || hasB || hasC) || staticProperties.machineModel != "none") && (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration())) { - error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); - return; - } - if (staticProperties.machineModel == "none") { - if (hasA || hasB || hasC) { // configure machine - var aAxis; - var bAxis; - var cAxis; - var useTCPC = getProperty("useTCPC"); - if (hasA) { // A Axis - For horizontal machines and trunnions - var dir = staticProperties.hasAAxis == "reversed" ? -1 : 1; - if (hasC || hasB) { - var aMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var aMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], range:[aMin, aMax], preference:dir, reset:(hasB ? 0 : 1), tcp:useTCPC}); - } else { - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasB) { // B Axis - For horizontal machines and trunnions - var dir = staticProperties.hasBAxis == "reversed" ? -1 : 1; - if (hasC) { - var bMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var bMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], range:[bMin, bMax], preference:-dir, reset:1, tcp:useTCPC}); - } else if (hasA) { - bAxis = createAxis({coordinate:1, table:true, axis:[0, 0, dir], cyclic:true, tcp:useTCPC}); - } else { - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasC) { // C Axis - For trunnions only - var dir = staticProperties.hasCAxis == "reversed" ? -1 : 1; - cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, dir], cyclic:true, reset:1, tcp:useTCPC}); - } - - if (hasA && hasC) { // AC trunnion - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else if (hasB && hasC) { // BC trunnion - machineConfiguration = new MachineConfiguration(bAxis, cAxis); - } else if (hasA && hasB) { // AB trunnion - machineConfiguration = new MachineConfiguration(aAxis, bAxis); - } else if (hasA) { // A rotary - machineConfiguration = new MachineConfiguration(aAxis); - } else if (hasB) { // B rotary - horizontal machine only - machineConfiguration = new MachineConfiguration(bAxis); - } else if (hasC) { // C rotary - machineConfiguration = new MachineConfiguration(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 - } - } - } else { - defineMachineModel(); - } - /* home positions */ - // machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - // machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - // machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); -} -// End of machine configuration logic - -function onOpen() { - receivedMachineConfiguration = (typeof machineConfiguration.isReceived == "function") ? machineConfiguration.isReceived() : - ((machineConfiguration.getDescription() != "") || machineConfiguration.isMultiAxisConfiguration()); - if (typeof defineMachine == "function") { - defineMachine(); // hardcoded machine configuration - } - activateMachine(); // enable the machine optimizations and settings - - if (staticProperties.useDPMFeeds) { - gFeedModeModal.format(94); - } - if (staticProperties.useRadius) { - maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC - } - if (staticProperties.sequenceNumberOnlyOnToolChange) { - staticProperties.showSequenceNumbers = false; - } - if (!staticProperties.useDWO) { - useDWOForPositioning = false; - } - - gRotationModal.format(69); // Default to G69 Rotation Off - - if (highFeedrate <= 0) { - error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal.")); - return; - } - - if (!staticProperties.separateWordsWithSpace) { - setWordSeparator(""); - } - saveShowSequenceNumbers = staticProperties.showSequenceNumbers; - sequenceNumber = staticProperties.sequenceNumberStart; - writeln("%"); - - if (programName) { - var programId; - try { - programId = getAsInt(programName); - } catch (e) { - error(localize("Program name must be a number.")); - return; - } - if (!((programId >= 1) && (programId <= 99999))) { - error(localize("Program number is out of range.")); - return; - } - writeln( - "O" + oFormat.format(programId) + - conditional(programComment, " " + formatComment(programComment.substr(0, maximumLineLength - 2 - ("O" + oFormat.format(programId)).length - 1))) - ); - lastSubprogram = (initialSubprogramNumber - 1); - } else { - error(localize("Program name has not been specified.")); - return; - } - - writeComment("Career Account Username: " + getGlobalParameter("username")); - writeComment("Filename: " + getGlobalParameter("document-path")); - writeComment("Date: " + getGlobalParameter("generated-at")); - writeComment("Post Version: " + staticProperties.postVersion); - - if (staticProperties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (staticProperties.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 (staticProperties.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" + 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); - - if (staticProperties.useM130PartImages) { - var toolRenderer = createToolRenderer(); - if (toolRenderer) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - toolRenderer.setFluteColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - toolRenderer.setShoulderColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setShaftColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setHolderColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - if (i % 2 == 0) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - } else { - toolRenderer.setBackgroundColor(new Color(240 / 255.0, 240 / 255.0, 240 / 255.0)); - } - var path = "tool" + tool.number + ".png"; - var width = 400; - var height = 532; - toolRenderer.exportAs(path, "image/png", tool, width, height); - } - } - } - } - } - - writeln(""); - writeComment("Reset work plane, cancel all cycles and offsets"); - writeBlock(gFormat.format(0), - gFormat.format(17), - gFormat.format(40), - gFormat.format(49), - gFormat.format(80), - gFormat.format(90)); - - // 6/21/21 | Gavin Williams | will1742 - // Probing now required. Using P9995. - // optionally cycle through all tools - var tools = getToolTable(); - - var writeFunction = getProperty("loadToolsAtStart") ? writeBlock : writeOptionalBlock; - - if (tools.getNumberOfTools() > 0) { - writeln(""); - /* - writeOptionalBlock(mFormat.format(0), formatComment(localize("Read note"))); // wait for operator - writeComment(localize("With BLOCK DELETE turned off each tool will cycle through")); - writeComment(localize("the spindle to verify that the correct tool is in the tool magazine")); - if (getProperty("optionallyMeasureToolsAtStart")) { - writeComment(localize("and to automatically measure it")); - } - writeComment(localize("Once the tools are verified turn BLOCK DELETE on to skip verification")); - */ - - // 6/21/21 | Gavin Williams | will1742 - writeComment("Load and probe tools"); - - // Display general tool probe info - displayMedia("toolProbeReminder.jpg", !getProperty("loadToolsAtStart")); - - let parsedTools = []; - - // Maybe should be anonymous function?? - function defaultFill() { - parsedTools = [] - for (var i = 0; i < tools.getNumberOfTools(); i++){ - parsedTools[i] = tools.getTool(i).number; - } - } - - // also maybe anonymous - // TODO: tool.getNumberOfTools needs to be machine-specific constant - function invalidToolNum(toolNum) { - return (toolNum < 1 || toolNum > MAX_TOOL_NUM); - } - - // parse string for specific tools to load - if (getProperty("toolsToLoad") != "") { - // get list of numbers - let toolNumArray = getProperty("toolsToLoad").split(','); - - // iterate through and fill ranges - for (var i = 0; i < toolNumArray.length; i++){ - toolNumArray[i] = toolNumArray[i].trim(); - - // fill range - if (toolNumArray[i].indexOf("-") >= 0) { - let numRange = toolNumArray[i].split("-"); - if (invalidToolNum(parseInt(numRange[0])) || invalidToolNum(parseInt(numRange[1]))) { - defaultFill(); - break; - } - for(var j = numRange[0]; j <= numRange[1]; j++){ - parsedTools.push(parseInt(j)); - } - continue; - } - // check if valid num - if (invalidToolNum(parseInt(toolNumArray[i]))) { - defaultFill(); - break; - } - // push single num - parsedTools.push(parseInt(toolNumArray[i])); - } - } else { - defaultFill(); - } - - for (var i = 0; i < tools.getNumberOfTools(); i++) { - var tool = tools.getTool(i); - if (tool.bodyLength + tool.holderLength > MAX_TOOL_LENGTH) { - throw "Error: T" + tool.number + " length greater than machine max" - } - - if (tool.diameter > MAX_TOOL_DIAM) { - throw "Error : T" + tool.number + " diameter greater than machine max" - } - - if (parsedTools.indexOf(tool.number) <= -1) { - continue; - } - - if (getProperty("measureToolsAtStart") && (tool.type == TOOL_PROBE)) { - continue; - } - - // 07/16/21 | will1742 | Gavin Williams - // Verify tool numbers - if (tool.number == 20 && tool.type != TOOL_PROBE) { - throw "Error: T20 is reserved for Probe"; - } - - if (tool.number == 19) { - throw "Error: T19 is reserved for WCS verification tool"; - } - - writeln(""); - 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"); - } - comment += " - " + getToolTypeName(tool.type); - writeComment(tool.description); - writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool - displayMedia("toolLoad" + tool.number + ".jpg", !getProperty("loadToolsAtStart"), "Load Tool " + tool.number); - writeToolMeasureBlock(tool, true); - } - } - - writeln(""); - writeComment("SETUP FOR OPERATION"); - writeFunction(mFormat.format(131)); - - if (staticProperties.useDWO) { - var failed = false; - var dynamicWCSs = {}; - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var description = section.hasParameter("operation-comment") ? section.getParameter("operation-comment") : ("#" + (i + 1)); - if (!section.hasDynamicWorkOffset()) { - error(subst(localize("Dynamic work offset has not been set for operation '%1'."), description)); - failed = true; - } - - var o = section.getDynamicWCSOrigin(); - var p = section.getDynamicWCSPlane(); - if (dynamicWCSs[section.getDynamicWorkOffset()]) { - if ((Vector.diff(o, dynamicWCSs[section.getDynamicWorkOffset()].origin).length > 1e-9) || - (Matrix.diff(p, dynamicWCSs[section.getDynamicWorkOffset()].plane).n1 > 1e-9)) { - error(subst(localize("Dynamic WCS mismatch for operation '%1'."), description)); - failed = true; - } - } else { - dynamicWCSs[section.getDynamicWorkOffset()] = {origin:o, plane:p}; - } - } - if (failed) { - return; - } - } - - if (false) { - // check for duplicate tool number - for (var i = 0; i < getNumberOfSections(); ++i) { - var sectioni = getSection(i); - var tooli = sectioni.getTool(); - for (var j = i + 1; j < getNumberOfSections(); ++j) { - var sectionj = getSection(j); - var toolj = sectionj.getTool(); - if (tooli.number == toolj.number) { - if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || - xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || - abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || - (tooli.numberOfFlutes != toolj.numberOfFlutes)) { - error( - subst( - localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), - sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), - sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) - ) - ); - return; - } - } - } - } - } - - if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { - for (var i = 0; i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset > 0) { - error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); - return; - } - } - } - - // absolute coordinates and feed per min - writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } - - coolantPressure = staticProperties.coolantPressure; - - if (staticProperties.chipTransport) { - onCommand(COMMAND_START_CHIP_TRANSPORT); - } - // Probing Surface Inspection - if (typeof inspectionWriteVariables == "function") { - inspectionWriteVariables(); - } -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -var lengthCompensationActive = false; -/** Disables length compensation if currently active or if forced. */ -function disableLengthCompensation(force, message) { - if (lengthCompensationActive || force) { - writeBlock(gFormat.format(49), conditional(message, formatComment(message))); - lengthCompensationActive = false; - } -} - -function writeG187() { - if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "drill")) { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } else if (hasParameter("operation:tolerance")) { - var tolerance = Math.max(getParameter("operation:tolerance"), 0); - if (tolerance > 0) { - var stockToLeaveThreshold = toUnit(0.1, MM); - var stockToLeave = 0; - var verticalStockToLeave = 0; - if (hasParameter("operation:stockToLeave")) { - stockToLeave = xyzFormat.getResultingValue(getParameter("operation:stockToLeave")); - } - if (hasParameter("operation:verticalStockToLeave")) { - verticalStockToLeave = xyzFormat.getResultingValue(getParameter("operation:verticalStockToLeave")); - } - - var workMode; - if (((stockToLeave > stockToLeaveThreshold) && (verticalStockToLeave > stockToLeaveThreshold)) || - (hasParameter("operation:strategy") && getParameter("operation:strategy") == "face")) { - workMode = 1; // roughing - } else { - if ((stockToLeave > 0) || (verticalStockToLeave > 0)) { - workMode = 2; // default - } else { - workMode = 3; // fine - } - } - writeBlock(gFormat.format(187), "P" + workMode); // set tolerance mode - // writeBlock(gFormat.format(187), "P" + workMode, "E" + xyzFormat.format(tolerance)); // set tolerance mode - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return "F#" + (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("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), getParameter("operation: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("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting") && - hasParameter("operation:tool_feedEntry") && - hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(getParameter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { - var feed; - if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { - feed = getParameter("operation:highFeedrate"); - } else { - feed = this.highFeedrate; - } - var feedContext = new FeedContext(id, localize("High Feed"), feed); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - activeMovements[MOVEMENT_RAPID] = feedContext; - } - ++id; - } - - for (var i = 0; i < activeFeeds.length; ++i) { - var feedContext = activeFeeds[i]; - writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description)); - } -} - -var currentWorkPlaneABC = undefined; -var activeG254 = false; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function defineWorkPlane(_section, _setWorkPlane) { - var abc = new Vector(0, 0, 0); - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (_section.isMultiAxis()) { - cancelTransformation(); - abc = _section.getInitialToolAxisABC(); - if (_setWorkPlane) { - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - if (!retracted) { - moveToSafeRetractPosition(); - } - forceWorkPlane(); - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - } - } else { - abc = getWorkPlaneMachineABC(_section.workPlane, _setWorkPlane); - if (_setWorkPlane) { - setWorkPlane(abc); - } - } - } else { // pure 3D - var remaining = _section.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - error(localize("Tool orientation is not supported.")); - return abc; - } - setRotation(remaining); - } - return abc; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - var _skipBlock = false; - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - if (operationNeedsSafeStart) { - _skipBlock = true; - } else { - return; // no change - } - } - skipBlock = _skipBlock; - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(false); - } - - if (activeG254) { - skipBlock = _skipBlock; - activeG254 = false; - writeBlock(gFormat.format(255)); // cancel DWO - } - - gMotionModal.reset(); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - - skipBlock = _skipBlock; - onCommand(COMMAND_LOCK_MULTI_AXIS); - - if (staticProperties.useDWO && - (abcFormat.isSignificant(abc.x % (Math.PI * 2)) || abcFormat.isSignificant(abc.y % (Math.PI * 2)) || abcFormat.isSignificant(abc.z % (Math.PI * 2)))) { - skipBlock = _skipBlock; - activeG254 = true; - writeBlock(gFormat.format(254)); // enable DWO - } - - setCurrentABC(abc); // required for machine simulation - currentWorkPlaneABC = abc; -} - -var closestABC = true; // choose closest machine angles -var currentMachineABC = new Vector(0, 0, 0); - -function getPreferenceWeight(_abc) { - var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); - var abc = new Array(_abc.x, _abc.y, _abc.z); - var preference = 0; - for (var i = 0; i < 3; ++i) { - if (axis[i].isEnabled()) { - preference += ((abcFormat.getResultingValue(abc[axis[i].getCoordinate()]) * axis[i].getPreference()) < 0) ? -1 : 1; - } - } - return preference; -} - -function remapToABC(currentABC, previousABC) { - var both = machineConfiguration.getABCByDirectionBoth(machineConfiguration.getDirection(currentABC)); - var abc1 = machineConfiguration.remapToABC(both[0], previousABC); - abc1 = machineConfiguration.remapABC(abc1); - var abc2 = machineConfiguration.remapToABC(both[1], previousABC); - abc2 = machineConfiguration.remapABC(abc2); - - // choose angles based on preference - var preference1 = getPreferenceWeight(abc1); - var preference2 = getPreferenceWeight(abc2); - if (preference1 > preference2) { - return abc1; - } else if (preference2 > preference1) { - return abc2; - } - - // choose angles based on closest solution - if (Vector.diff(abc1, previousABC).length < Vector.diff(abc2, previousABC).length) { - return abc1; - } else { - return abc2; - } -} - -function getWorkPlaneMachineABC(workPlane, _setWorkPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - if (_setWorkPlane) { - currentMachineABC = abc; - } - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - 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" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function printProbeResults() { - return currentSection.getParameter("printResults", 0) == 1; -} - -function onPassThrough(text) { - var commands = String(text).split(","); - for (text in commands) { - writeBlock(commands[text]); - } -} - -function onManualNC(command, value) { - switch (command) { - case COMMAND_ACTION: - if (String(value).toUpperCase() == "CYCLE_REVERSAL") { - cycleReverse = true; - } else if (String(value).toUpperCase() == "VFD_LOW") { - coolantPressure = "P0"; - } else if (String(value).toUpperCase() == "VFD_NORMAL") { - coolantPressure = "P1"; - } else if (String(value).toUpperCase() == "VFD_HIGH") { - coolantPressure = "P2"; - } else if (String(value).toUpperCase() == "USEPOLARMODE") { - usePolarMode = true; - } - break; - default: - expandManualNC(command, value); - } -} - -var probeOutputWorkOffset = 1; -var stockTopZ = -1; -var stockUpperX; -var stockLowerX; -var stockUpperY; -var stockLowerY; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } - - // Added 6/15/21 | Gavin Williams | will1742 - // Issue 001 Input and Validation - if (name == "stock-upper-z") { - stockTopZ = value; - } - if (name == "stock-upper-x") { - stockUpperX = value; - } - if (name == "stock-lower-x") { - stockLowerX = value; - } - if (name == "stock-upper-y") { - stockUpperY = value; - } - if (name == "stock-lower-y") { - stockLowerY = value; - } -} - -var seenPatternIds = {}; - -function previewImage() { - var permittedExtensions = ["JPG", "MP4", "MOV", "PNG", "JPEG"]; - var patternId = currentSection.getPatternId(); - var show = false; - if (!seenPatternIds[patternId]) { - show = true; - seenPatternIds[patternId] = true; - } - var images = []; - if (show) { - if (FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath))) { - images.push(modelImagePath); - } - if (hasParameter("autodeskcam:preview-name") && FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), getParameter("autodeskcam:preview-name")))) { - images.push(getParameter("autodeskcam:preview-name")); - } - - for (var i = 0; i < images.length; ++i) { - var fileExtension = images[i].slice(images[i].lastIndexOf(".") + 1, images[i].length).toUpperCase(); - var permittedExtension = false; - for (var j = 0; j < permittedExtensions.length; ++j) { - if (fileExtension == permittedExtensions[j]) { - permittedExtension = true; - break; // found - } - } - if (!permittedExtension) { - warning(localize("The image file format " + "\"" + fileExtension + "\"" + " is not supported on HAAS controls.")); - } - - if (!staticProperties.useM130PartImages || !permittedExtension) { - FileSystem.remove(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), images[i])); // remove - images.splice([i], 1); // remove from array - } - } - if (images.length > 0) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(" + images[images.length - 1] + ")") - : - writeOptionalBlock(mFormat.format(130), "(" + images[images.length - 1] + ")"); - } - } -} - -/** Returns true if the spatial vectors are significantly different. */ -function areSpatialVectorsDifferent(_vector1, _vector2) { - return (xyzFormat.getResultingValue(_vector1.x) != xyzFormat.getResultingValue(_vector2.x)) || - (xyzFormat.getResultingValue(_vector1.y) != xyzFormat.getResultingValue(_vector2.y)) || - (xyzFormat.getResultingValue(_vector1.z) != xyzFormat.getResultingValue(_vector2.z)); -} - -/** Returns true if the spatial boxes are a pure translation. */ -function areSpatialBoxesTranslated(_box1, _box2) { - return !areSpatialVectorsDifferent(Vector.diff(_box1[1], _box1[0]), Vector.diff(_box2[1], _box2[0])) && - !areSpatialVectorsDifferent(Vector.diff(_box2[0], _box1[0]), Vector.diff(_box2[1], _box1[1])); -} - -/** Returns true if the spatial boxes are same. */ -function areSpatialBoxesSame(_box1, _box2) { - return !areSpatialVectorsDifferent(_box1[0], _box2[0]) && !areSpatialVectorsDifferent(_box1[1], _box2[1]); -} - -function subprogramDefine(_initialPosition, _abc, _retracted, _zIsOutput) { - // convert patterns into subprograms - var usePattern = false; - patternIsActive = false; - if (currentSection.isPatterned && currentSection.isPatterned() && (getProperty("useSubroutines") == "patterns")) { - currentPattern = currentSection.getPatternId(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_PATTERN) && (currentPattern == definedPatterns[i].patternId)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_PATTERN); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_PATTERN, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: _initialPosition - }); - } - - if (usePattern) { - // make sure Z-position is output prior to subprogram call - if (!_retracted && !_zIsOutput) { - writeBlock(gMotionModal.format(0), zOutput.format(_initialPosition.z)); - } - - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - patternIsActive = true; - - if (firstPattern) { - subprogramStart(_initialPosition, _abc, incrementalSubprogram); - } else { - skipRemainingSection(); - setCurrentPosition(getFramePosition(currentSection.getFinalPosition())); - } - } - } - - // Output cycle operation as subprogram - if (!usePattern && (getProperty("useSubroutines") == "cycles") && currentSection.doesStrictCycle && - (currentSection.getNumberOfCycles() == 1) && currentSection.getNumberOfCyclePoints() >= minimumCyclePoints) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - currentPattern = currentSection.getNumberOfCyclePoints(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_CYCLE) && (currentPattern == definedPatterns[i].patternId) && - !areSpatialVectorsDifferent(_initialPosition, definedPatterns[i].initialPosition) && - !areSpatialVectorsDifferent(finalPosition, definedPatterns[i].finalPosition)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_CYCLE); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_CYCLE, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: finalPosition - }); - } - cycleSubprogramIsActive = usePattern; - } - - // Output each operation as a subprogram - if (!usePattern && (getProperty("useSubroutines") == "allOperations")) { - currentSubprogram = ++lastSubprogram; - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - firstPattern = true; - subprogramStart(_initialPosition, _abc, false); - } -} - -function subprogramStart(_initialPosition, _abc, _incremental) { - redirectToBuffer(); - var comment = ""; - if (hasParameter("operation-comment")) { - comment = getParameter("operation-comment"); - } - writeln( - "N" + nFormat.format(currentSubprogram) + - conditional(comment, formatComment(comment.substr(0, maximumLineLength - 2 - 6 - 1))) - ); - staticProperties.showSequenceNumbers = false; - if (_incremental) { - setIncrementalMode(_initialPosition, _abc); - } - gPlaneModal.reset(); - gMotionModal.reset(); -} - -function subprogramEnd() { - if (firstPattern) { - writeBlock(mFormat.format(99)); - writeln(""); - subprograms += getRedirectionBuffer(); - } - forceAny(); - firstPattern = false; - staticProperties.showSequenceNumbers = saveShowSequenceNumbers; - closeRedirection(); -} - -function subprogramIsValid(_section, _patternId, _patternType) { - var sectionId = _section.getId(); - var numberOfSections = getNumberOfSections(); - var validSubprogram = _patternType != SUB_CYCLE; - - var masterPosition = new Array(); - masterPosition[0] = getFramePosition(_section.getInitialPosition()); - masterPosition[1] = getFramePosition(_section.getFinalPosition()); - var tempBox = _section.getBoundingBox(); - var masterBox = new Array(); - masterBox[0] = getFramePosition(tempBox[0]); - masterBox[1] = getFramePosition(tempBox[1]); - - var rotation = getRotation(); - var translation = getTranslation(); - incrementalSubprogram = undefined; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (section.getId() != sectionId) { - defineWorkPlane(section, false); - // check for valid pattern - if (_patternType == SUB_PATTERN) { - if (section.getPatternId() == _patternId) { - var patternPosition = new Array(); - patternPosition[0] = getFramePosition(section.getInitialPosition()); - patternPosition[1] = getFramePosition(section.getFinalPosition()); - tempBox = section.getBoundingBox(); - var patternBox = new Array(); - patternBox[0] = getFramePosition(tempBox[0]); - patternBox[1] = getFramePosition(tempBox[1]); - - if (areSpatialBoxesSame(masterPosition, patternPosition) && areSpatialBoxesSame(masterBox, patternBox) && !section.isMultiAxis()) { - incrementalSubprogram = incrementalSubprogram ? incrementalSubprogram : false; - } else if (!areSpatialBoxesTranslated(masterPosition, patternPosition) || !areSpatialBoxesTranslated(masterBox, patternBox)) { - validSubprogram = false; - break; - } else { - incrementalSubprogram = true; - } - } - - // check for valid cycle operation - } else if (_patternType == SUB_CYCLE) { - if ((section.getNumberOfCyclePoints() == _patternId) && (section.getNumberOfCycles() == 1)) { - var patternInitial = getFramePosition(section.getInitialPosition()); - var patternFinal = getFramePosition(section.getFinalPosition()); - if (!areSpatialVectorsDifferent(patternInitial, masterPosition[0]) && !areSpatialVectorsDifferent(patternFinal, masterPosition[1])) { - validSubprogram = true; - break; - } - } - } - } - } - setRotation(rotation); - setTranslation(translation); - return (validSubprogram); -} - -function setAxisMode(_format, _output, _prefix, _value, _incr) { - var i = _output.isEnabled(); - if (_output == zOutput) { - _output = _incr ? createIncrementalVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format) : createVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format); - } else { - _output = _incr ? createIncrementalVariable({prefix: _prefix}, _format) : createVariable({prefix: _prefix}, _format); - } - _output.format(_value); - _output.format(_value); - i = i ? _output.enable() : _output.disable(); - return _output; -} - -function setIncrementalMode(xyz, abc) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, true); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, true); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, true); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, true); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, true); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, true); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(91)); - incrementalMode = true; -} - -function setAbsoluteMode(xyz, abc) { - if (incrementalMode) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, false); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, false); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, false); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, false); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, false); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, false); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(90)); - incrementalMode = false; - } -} - -function onSection() { - if (isFirstSection()) { - writeln(""); - writeComment("STOCK PREP"); - var Stock_X_55 = (stockUpperX + stockLowerX)/2; - // TODO: Tolerance Checks - // writeln(macroFormat.format(100) + "=[" + macroFormat.format(5241) + "+" + xyzFormat.format(Stock_X_55) + "]"); - // writeWords("IF [" + macroFormat.format(100) + " GT 0.] THEN " + macroFormat.format(100) + "=0."); - // writeWords("IF [" + macroFormat.format(100) + " LT " + (X_TRAVEL_LIMIT*-1) + "." + "] THEN " + macroFormat.format(100) + "=" + (X_TRAVEL_LIMIT*-1) + "."); - // writeBlock(gFormat.format(53), "X" + macroFormat.format(100), yOutput.format(0)); - writeBlock(gFormat.format(55), gFormat.format(0), xOutput.format(Stock_X_55)); - writeBlock(gFormat.format(53), gFormat.format(0), yOutput.format(0)); - displayMedia("loadStock.jpg", false); - } - - - // 07/06/21 | Gavin Williams | will1742 - // 002 Improved Probing - // uses pencil to verify WCS, prompts user - if (isFirstSection() && getProperty("pencilWCSValidation")) { - var stockMidX = (stockUpperX + stockLowerX)/2; - var stockMidY = (stockUpperY + stockLowerY)/2; - writeln(""); - writeComment("VERIFY WCS"); - writeBlock("T" + toolFormat.format(19), mFormat.format(6)); //Changes Tool - - writeBlock(gFormat.format(55), gFormat.format(0), forceX.format(stockMidX), forceY.format(stockMidY)); - displayMedia("xyWCSCheck.jpg", false, "Open door and check x-y position"); - - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - var gotoRef = takeInput("Is the pencil centered above your stock? stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - writeBlock(gFormat.format(55), gFormat.format(43), hFormat.format(19), zOutput.format(stockTopZ)); - displayMedia("zWCSCheck.jpg", false, "Open door and check z position"); - - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - gotoRef = takeInput("Is the pencil touching the center of your stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - } - - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - retracted = false; - - var zIsOutput = false; // true if the Z-position has been output, used for patterns - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || - (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || - getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations - - operationNeedsSafeStart = staticProperties.safeStartAllOperations && !isFirstSection(); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.fastToolChange && !isProbeOperation()) { - currentCoolantMode = COOLANT_OFF; - } else if (insertToolCall) { // no coolant off command if safe start operation - onCommand(COMMAND_COOLANT_OFF); - } - } - - if ((insertToolCall && !staticProperties.fastToolChange) || newWorkOffset || newWorkPlane || toolChecked) { - - // stop spindle before retract during tool change - if (insertToolCall && !isFirstSection() && !toolChecked && !staticProperties.fastToolChange) { - onCommand(COMMAND_STOP_SPINDLE); - } - - // retract to safe plane - writeRetract(Z); - - if (forceResetWorkPlane && newWorkPlane) { - forceWorkPlane(); - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - } - } - - if (!isFirstSection() && getProperty("toolLengthValidation")) { - displayMedia("checkPartTool.jpg", false, "Check Part and Tool"); - } else if (!isFirstSection()) { - writeBlock(mFormat.format(1)); - writeComment("Check Part and Tool"); - } - - if (hasParameter("operation-comment")) { - var comment = getParameter("operation-comment"); - if (comment && ((comment !== lastOperationComment) || !patternIsActive || insertToolCall)) { - writeln(""); - writeComment(comment); - lastOperationComment = comment; - } else if (!patternIsActive || insertToolCall) { - writeln(""); - } - } else { - writeln(""); - } - - if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { - // throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." - } - - if (staticProperties.showNotes) { - var notes = getParameter("notes"); - writeComment("PEER MENTOR 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); - } - } - } - } - - // enable polar interpolation - if (usePolarMode && (tool.type != TOOL_PROBE)) { - if (polarDirection == undefined) { - error(localize("Polar direction property must be a vector - x,y,z.")); - return; - } - setPolarMode(currentSection, true); - } - - defineWorkPlane(currentSection, false); - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - forceAny(); - - if (operationNeedsSafeStart) { - if (!retracted) { - // skipBlock = true; - writeRetract(Z); - } - } - - if (insertToolCall || operationNeedsSafeStart) { - - if (staticProperties.useM130PartImages) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(tool" + tool.number + ".png)") - : - writeOptionalBlock(mFormat.format(130), "(tool" + tool.number + ".png)"); - } - - if (!isFirstSection() && staticProperties.optionalStop && insertToolCall) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if ((tool.number > 200 && tool.number < 1000) || tool.number > 9999) { - warning(localize("Tool number out of range.")); - } - - skipBlock = !insertToolCall; - writeToolBlock( - "T" + toolFormat.format(tool.number), - mFormat.format(6) - ); - if (tool.comment) { - writeComment(tool.comment); - } - if (measureTool) { - writeToolMeasureBlock(tool, false); - } - if (insertToolCall) { - forceWorkPlane(); - } - 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") + "=" + xyzFormat.format(zRange.getMinimum())); - } - } - } - - // activate those two coolant modes before the spindle is turned on - if ((tool.coolant == COOLANT_THROUGH_TOOL) || (tool.coolant == COOLANT_AIR_THROUGH_TOOL) || (tool.coolant == COOLANT_FLOOD_THROUGH_TOOL)) { - if (!isFirstSection() && !insertToolCall && (currentCoolantMode != tool.coolant)) { - onCommand(COMMAND_STOP_SPINDLE); - forceSpindleSpeed = true; - } - // setCoolant(tool.coolant); - } else if ((currentCoolantMode == COOLANT_THROUGH_TOOL) || (currentCoolantMode == COOLANT_AIR_THROUGH_TOOL) || (currentCoolantMode == COOLANT_FLOOD_THROUGH_TOOL)) { - onCommand(COMMAND_STOP_SPINDLE); - setCoolant(COOLANT_OFF); - forceSpindleSpeed = true; - } - - if (toolChecked) { - forceSpindleSpeed = true; // spindle must be restarted if tool is checked without a tool change - toolChecked = false; // state of tool is not known at the beginning of a section since it could be broken for the previous section - } - var spindleChanged = tool.type != TOOL_PROBE && - (insertToolCall || forceSpindleSpeed || isFirstSection() || - (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)); - if (spindleChanged || (operationNeedsSafeStart && tool.type != TOOL_PROBE)) { - forceSpindleSpeed = false; - - if (spindleSpeed < 1) { - error(localize("Spindle speed out of range.")); - return; - } - maximumSpindleRPM = machineConfiguration.getMaximumSpindleSpeed() > 0 ? machineConfiguration.getMaximumSpindleSpeed() : maximumSpindleRPM; - if (spindleSpeed > maximumSpindleRPM) { - warning(subst(localize("Spindle speed '" + spindleSpeed + " RPM' exceeds maximum value of '%1 RPM."), maximumSpindleRPM)); - } - // skipBlock = !spindleChanged; - writeBlock( - sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) - ); - } - - previewImage(); - - if (staticProperties.useParametricFeed && - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill") && // legacy - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(); - } - } else { - activeMovements = undefined; - } - - // wcs - if (insertToolCall || operationNeedsSafeStart) { // force work offset when changing tool - currentWorkOffset = undefined; - skipBlock = operationNeedsSafeStart && !newWorkOffset && !insertToolCall; - } - 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 > 6) { - var code = workOffset - 6; - if (code > 99) { - error(localize("Work offset out of range.")); - return; - } - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(154), "P" + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - if (newWorkPlane || (insertToolCall && !retracted)) { // go to home position for safety - if (!retracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing && machineConfiguration.isMultiAxisConfiguration()) { - writeRetract(X, Y); - } - } - - // Unwind axis if previous section was Multi-Axis - if (!isFirstSection() && (getPreviousSection().isMultiAxis() || usePolarMode) && machineConfiguration.isMachineCoordinate(2)) { // TAG - if (!retracted) { - moveToSafeRetractPosition(); - } - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - currentMachineABC.setZ(0); - } - - if (newWorkOffset) { - forceWorkPlane(); - } - - var abc = defineWorkPlane(currentSection, true); - - setProbeAngle(); // output probe angle rotations if required - - gMotionModal.reset(); - - if (staticProperties.useG187) { - writeG187(); - } - - var G = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? 1 : 0; - var F = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? getFeed(toPreciseUnit(highFeedrate, MM)) : ""; - if (insertToolCall || retracted || operationNeedsSafeStart || !lengthCompensationActive || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))) { - var _skipBlock = !(insertToolCall || retracted || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))); - var lengthOffset = tool.lengthOffset; - if ((lengthOffset > 200 && lengthOffset < 1000) || lengthOffset > 9999) { - error(localize("Length offset out of range.")); - return; - } - - gMotionModal.reset(); - writeBlock(gPlaneModal.format(17)); - - if (usePolarMode) { - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(); - } - var polarPosition = getPolarPosition(initialPosition.x, initialPosition.y, initialPosition.z); - setCurrentPositionAndDirection(polarPosition); - initialPosition = new Vector(polarPosition.first.x, polarPosition.first.y, polarPosition.first.z); - writeBlock(gMotionModal.format(0), aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - } - - if (!machineConfiguration.isHeadConfiguration()) { - if (tcpIsSupported && useDwoForPositioning && currentSection.isMultiAxis()) { - var O = machineConfiguration.getOrientation(abc); - var initialPositionDWO = O.getTransposed().multiply(getGlobalPosition(currentSection.getInitialPosition())); - // writeComment("PREPOSITIONING START"); - skipBlock = _skipBlock; - writeBlock(gFormat.format(254)); - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPositionDWO.x), yOutput.format(initialPositionDWO.y), F); - skipBlock = _skipBlock; - writeBlock(gFormat.format(255)); - // writeComment("PREPOSITIONING END"); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), // G0 motion mode is required for the G234 command - gFormat.format(234), - xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } else { - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), F); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } - } else { - skipBlock = _skipBlock; - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(currentSection.isMultiAxis() && tcpIsSupported ? 0 : G), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y), - zOutput.format(initialPosition.z), - F, - hFormat.format(lengthOffset) - ); - } - zIsOutput = true; - lengthCompensationActive = true; - if (_skipBlock) { - forceXYZ(); - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - } else { - validate(lengthCompensationActive, "Length compensation is not active."); - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - zIsOutput = true; - } - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - if (gMotionModal.getCurrent() == 0) { - forceFeed(); - } - gMotionModal.reset(); - validate(lengthCompensationActive, "Length compensation is not active."); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.preloadTool) { - var nextTool = getNextTool(tool.number); - if (nextTool) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(nextTool.number)); - } else { - // preload first tool - var section = getSection(0); - var firstToolNumber = section.getTool().number; - if (tool.number != firstToolNumber) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(firstToolNumber)); - } - } - } - } - - if (isProbeOperation()) { - validate(probeVariables.probeAngleMethod != "G68", "You cannot probe while G68 Rotation is in effect."); - validate(probeVariables.probeAngleMethod != "G54.4", "You cannot probe while workpiece setting error compensation G54.4 is enabled."); - writeBlock(gFormat.format(65), "P" + 9832); // spin the probe on - inspectionCreateResultsFileHeader(); - } else { - // surface Inspection - if (isInspectionOperation() && (typeof inspectionProcessSectionStart == "function")) { - inspectionProcessSectionStart(); - } - } - - if (getProperty("toolLengthValidation")) { - writeComment("TOOL VALIDATION"); - // Added 06/15/21 | Gavin Williams | will1742 - // Verifies tool-stock distance. Post fails if tool fails clearance standards - if (toolDistance < CLEARANCE_HEIGHT) { - throw "Error: Clearance height must be " + CLEARANCE_HEIGHT + " or more inches from stock"; - } - - if (toolDistance == Infinity) { - throw "Error: invalid tool distance. Contact a TA."; - } - var toolDistance = initialPosition.z - stockTopZ; - - // Prompt user to check stock-tool distance - displayMedia("checkDistance" + toolDistance.toPrecision(2).toString().replace(".", "_") + ".jpg", false, "Check distance: " + toolDistance.toPrecision(2).toString() + "in"); - writeComment("OPEN DOOR"); - //displayMedia("Net Share/Media/checkPrompt.jpg"); - - // asks user if measured height is accurate to displayed - //var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['N', 'Y']); - - // Create GOTO cases for Y/N selection, halt if N - /* - getTA("Net Share/Media/TAWarning.jpg", gotoRef['N'], onSecGotoRef); - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - writeWords( - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - */ - - // initialize spindle and engage coolant if heights are correct - if (tool.type != TOOL_PROBE) { - writeBlock(mFormat.format((tool.clockwise ? 3 : 4))); - } - } - - if (tool.type != TOOL_PROBE) { - setCoolant(tool.coolant); - writeBlock(gFormat.format(4), "P500"); - } - - writeComment("BEGIN OPERATION"); - // define subprogram - subprogramDefine(initialPosition, abc, retracted, zIsOutput); -} - -// Added 9/30/21 | Kevin Pan | pan261 -// Issue 001 Input and Validation, Issue 029 -// Displays a file: MP4, MOV, PNG, JPEG. 1920x1080 or comments if displayeMediaCalls is false -// Input: Absolute path to file, optional calls, comment to write with m0 -function displayMedia(file, isOptional, comment) { - var writeFunction = isOptional ? writeOptionalBlock : writeBlock; - - if (!getProperty("displayMediaCalls")) { - writeFunction(mFormat.format(0)); - comment ? - writeComment(comment) - : - null; - return; - } else { - writeFunction(mFormat.format(130), formatComment("Net Share/Media/" + file)); - comment ? - writeFunction(mFormat.format(0), formatComment(comment)) - : - writeFunction(mFormat.format(0)); - writeFunction(mFormat.format(131)); - } -} - -// Added 6/14/21 | Gavin Williams | will1742 -// Issue 001 Input and Validation -// Takes input from the user -// Input: string prompt, will be displayed to users -// char array options, capital letters accepted as input -// int opSeqNum, optional arg to init prompt at specific value -// Output: 2D dict {Letter, Coorresponding GOTO} -// EX: [Y, 56][N, 57] -var macroNumber = 500; -function takeInput(prompt, options) { - - // Cycle through macro variables, reset at end of general purpose vars - if (macroNumber > 549) macroNumber = 500; - - // init macro var to 0 - setMacro(macroNumber, 0, "Initialize macro variable", false); - - // disply prompt and save response - writeBlock(mFormat.format(109), "P" + nFormat.format(macroNumber), formatComment(prompt)); - sequenceNumber -= staticProperties.sequenceNumberIncrement; - var gotoRef = sequenceNumber; - - // wait for input - writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + nFormat.format(gotoRef) + " " + formatComment("NULL")); - - // print if's and goto's - var gotoMap = {}; - var gotoInc = 1; - options.forEach(function (element) { - writeWords("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc), formatComment(element)); - gotoMap[element] = (sequenceNumber + gotoInc); - gotoInc += 1; - }); - - var incNum = staticProperties.sequenceNumberIncrement; - // adjust sequence number if needed - for (i = incNum; i < gotoInc; i+=incNum) { - sequenceNumber += staticProperties.sequenceNumberIncrement; - } - - // return to input until valid option is entered - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("INVALID INPUT")); - - // increase var number, iterate sequence number - macroNumber += 1; - sequenceNumber += staticProperties.sequenceNumberIncrement; - return gotoMap; -} - -// Added 06/15/21 | Gavin Williamas | will1742 -// Issue 001 Input and validation -// Halts program until TA arrives. Jumps to gotoRef -function getTA(file, seqNum, gotoRef) { - writeWords("N" + nFormat.format(seqNum), - gFormat.format(53), gFormat.format(0), zOutput.format(0.), - formatComment("Retract spindle")); - getProperty("displayMediaCalls"); - writeWords(mFormat.format(0), formatComment("Halt Program")); - writeWords(mFormat.format(131)); - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("Return to beginning of operation")); -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - seconds = clamp(0.001, seconds, 99999.999); - writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + milliFormat.format(seconds * 1000)); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(sOutput.format(spindleSpeed)); -} - -function onCycle() { - writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r, c) { - forceXYZ(); - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - return [xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), - zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), - bOutput.format(polarPosition.second.y), - cOutput.format(polarPosition.second.z), - "R" + xyzFormat.format(r)]; - } else { - if (incrementalMode) { - zOutput.format(c); - return [xOutput.format(x), yOutput.format(y), - "Z" + xyzFormat.format(z - r), - "R" + xyzFormat.format(r - c)]; - } else { - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; - } - } -} - -function setCyclePosition(_position) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - zOutput.format(_position); - break; - case 18: // ZX - yOutput.format(_position); - break; - case 19: // YZ - xOutput.format(_position); - break; - } -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function setProbeAngleMethod() { - probeVariables.probeAngleMethod = (machineConfiguration.getNumberOfAxes() < 5 || is3D()) ? (getProperty("useG54x4") ? "G54.4" : "G68") : "UNSUPPORTED"; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i = 0; i < axes.length; ++i) { - if (axes[i].isEnabled() && isSameDirection((axes[i].getAxis()).getAbsolute(), new Vector(0, 0, 1)) && axes[i].isTable()) { - probeVariables.probeAngleMethod = "AXIS_ROT"; - probeVariables.rotationalAxis = axes[i].getCoordinate(); - break; - } - } - probeVariables.outputRotationCodes = true; -} - -/** Output rotation offset based on angular probing cycle. */ -function setProbeAngle() { - if (probeVariables.outputRotationCodes) { - validate(probeOutputWorkOffset <= 6, "Angular Probing only supports work offsets 1-6."); - if (probeVariables.probeAngleMethod == "G68" && (Vector.diff(currentSection.getGlobalInitialToolAxis(), new Vector(0, 0, 1)).length > 1e-4)) { - error(localize("You cannot use multi axis toolpaths while G68 Rotation is in effect.")); - } - var validateWorkOffset = false; - switch (probeVariables.probeAngleMethod) { - case "G54.4": - var param = 26000 + (probeOutputWorkOffset * 10); - writeBlock("#" + param + "=#135"); - writeBlock("#" + (param + 1) + "=#136"); - writeBlock("#" + (param + 5) + "=#144"); - writeBlock(gFormat.format(54.4), "P" + probeOutputWorkOffset); - break; - case "G68": - gRotationModal.reset(); - gAbsIncModal.reset(); - writeBlock(gRotationModal.format(68), gAbsIncModal.format(90), probeVariables.compensationXY, "R[#194]"); - validateWorkOffset = true; - break; - case "AXIS_ROT": - var param = 5200 + probeOutputWorkOffset * 20 + probeVariables.rotationalAxis + 4; - writeBlock("#" + param + " = " + "[#" + param + " + #194]"); - forceWorkPlane(); // force workplane to rotate ABC in order to apply rotation offsets - currentWorkOffset = undefined; // force WCS output to make use of updated parameters - validateWorkOffset = true; - break; - default: - error(localize("Angular Probing is not supported for this machine configuration.")); - return; - } - if (validateWorkOffset) { - for (var i = currentSection.getId(); i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset != currentSection.workOffset) { - error(localize("WCS offset cannot change while using angle rotation compensation.")); - return; - } - } - } - probeVariables.outputRotationCodes = false; - } -} - -function protectedProbeMove(_cycle, x, y, z) { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - var _z = zOutput.format(z); - if (_z && z >= getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } - if (_x || _y) { - writeBlock(gFormat.format(65), "P" + 9810, _x, _y, getFeed(highFeedrate)); // protected positioning move - } - if (_z && z < getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } -} - -function cancelG68Rotation(force) { - if (force) { - gRotationModal.reset(); - } - writeBlock(gRotationModal.format(69)); -} - -function onCyclePoint(x, y, z) { - if (isInspectionOperation() && (typeof inspectionCycleInspect == "function")) { - inspectionCycleInspect(cycle, x, y, z); - return; - } - if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { - expandCyclePoint(x, y, z); - return; - } - if (isProbeOperation()) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { - if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } else if (staticProperties.useDWO) { - error(localize("Your machine does not support the selected probing operation with DWO enabled.")); - return; - } - } - if (printProbeResults()) { - writeProbingToolpathInformation(z - cycle.depth + tool.diameter / 2); - inspectionWriteCADTransform(); - inspectionWriteWorkplaneTransform(); - if (typeof inspectionWriteVariables == "function") { - inspectionVariables.pointNumber += 1; - } - } - protectedProbeMove(cycle, x, y, z); - } - - var forceCycle = false; - switch (cycleType) { - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceCycle = true; - if (!isFirstCyclePoint()) { - writeBlock(gCycleModal.format(80)); - gMotionModal.reset(); - } - } - if (forceCycle || isFirstCyclePoint() || isProbeOperation()) { - if (!isProbeOperation()) { - // return to initial Z which is clearance plane and set absolute mode - repositionToCycleClearance(cycle, x, y, z); - } - - var F = cycle.feedrate; - var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "chip-breaking": - if ((cycle.accumulatedDepth < cycle.depth) && (cycle.incrementalDepthReduction > 0)) { - expandCyclePoint(x, y, z); - } else if (cycle.accumulatedDepth < cycle.depth) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - ("Q" + xyzFormat.format(cycle.incrementalDepth)), - ("K" + xyzFormat.format(cycle.accumulatedDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "deep-drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "left-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "right-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - // Parameter 57 bit 6, REPT RIG TAP, is set to 1 (On) - // On Mill software versions12.09 and above, REPT RIG TAP has been moved from the Parameters to Setting 133 - var u = cycle.stock; - var step = cycle.incrementalDepth; - var first = true; - while (u > cycle.bottom) { - if (step < cycle.minimumIncrementalDepth) { - step = cycle.minimumIncrementalDepth; - } - - u -= step; - step -= cycle.incrementalDepthReduction; - gCycleModal.reset(); // required - if ((u - 0.001) <= cycle.bottom) { - u = cycle.bottom; - } - if (first) { - first = false; - writeBlock( - gRetractModal.format(99), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), - getCommonCycle((gPlaneModal.getCurrent() == 19) ? u : x, (gPlaneModal.getCurrent() == 18) ? u : y, (gPlaneModal.getCurrent() == 17) ? u : z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - } else { - var position; - var depth; - switch (gPlaneModal.getCurrent()) { - case 17: - xOutput.reset(); - position = xOutput.format(x); - depth = "Z" + xyzFormat.format(u); - break; - case 18: - zOutput.reset(); - position = zOutput.format(z); - depth = "Y" + xyzFormat.format(u); - break; - case 19: - yOutput.reset(); - position = yOutput.format(y); - depth = "X" + xyzFormat.format(u); - break; - } - writeBlock(conditional(u <= cycle.bottom, gRetractModal.format(98)), position, depth); - } - } - forceFeed(); - break; - case "fine-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - break; - case "back-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; - var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; - var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; - writeBlock( - gRetractModal.format(98), gCycleModal.format(77), - getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom, cycle.clearance), - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "reaming": - writeBlock( - gRetractModal.format(98), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - - case "probing-x": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-y": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-z": - protectedProbeMove(cycle, x, y, Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock( - gFormat.format(65), "P" + 9811, - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "Z" + xyzFormat.format(z - cycle.depth), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "Z" + xyzFormat.format(z - cycle.depth), - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-inner-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9815, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-outer-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9816, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 90), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-y-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 0), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-xy-pcd-hole": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "K" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - case "probing-xy-pcd-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - default: - expandCyclePoint(x, y, z); - } - - // place cycle operation in subprogram - if (cycleSubprogramIsActive) { - if (forceCycle || cycleExpanded || isProbeOperation()) { - cycleSubprogramIsActive = false; - } else { - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - subprogramStart(new Vector(x, y, z), new Vector(0, 0, 0), false); - } - } - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - - // 2nd through nth cycle point - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - writeBlock(xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - return; - } - var _x; - var _y; - var _z; - if (!xyzFormat.areDifferent(x, xOutput.getCurrent()) && - !xyzFormat.areDifferent(y, yOutput.getCurrent()) && - !xyzFormat.areDifferent(z, zOutput.getCurrent())) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - xOutput.reset(); // at least one axis is required - break; - case 18: // ZX - zOutput.reset(); // at least one axis is required - break; - case 19: // YZ - yOutput.reset(); // at least one axis is required - break; - } - } - if (incrementalMode) { // set current position to retract height - setCyclePosition(cycle.retract); - } - writeBlock(xOutput.format(x), yOutput.format(y), zOutput.format(z)); - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - } - } -} - -function getProbingArguments(cycle, updateWCS) { - var outputWCSCode = updateWCS && currentSection.strategy == "probe"; - if (outputWCSCode) { - validate(probeOutputWorkOffset <= 99, "Work offset is out of range."); - var nextWorkOffset = hasNextSection() ? getNextSection().workOffset == 0 ? 1 : getNextSection().workOffset : -1; - if (probeOutputWorkOffset == nextWorkOffset) { - currentWorkOffset = undefined; - } - } - return [ - (cycle.angleAskewAction == "stop-message" ? "B" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), - ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "F" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), - (cycle.wrongSizeAction == "stop-message" ? "H" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), - (cycle.outOfPositionAction == "stop-message" ? "M" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), - ((cycle.updateToolWear && cycleType == "probing-z") ? "T" + xyzFormat.format(cycle.toolLengthOffset) : undefined), - ((cycle.updateToolWear && cycleType !== "probing-z") ? "T" + xyzFormat.format(cycle.toolDiameterOffset) : undefined), - (cycle.updateToolWear ? "V" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), - (cycle.printResults ? "W" + xyzFormat.format(1 + cycle.incrementComponent) : undefined), // 1 for advance feature, 2 for reset feature count and advance component number. first reported result in a program should use W2. - conditional(outputWCSCode, "S" + probeWCSFormat.format(probeOutputWorkOffset > 6 ? (0.01 * (probeOutputWorkOffset - 6) + 154) : probeOutputWorkOffset)) - ]; -} - -function onCycleEnd() { - if (isProbeOperation()) { - zOutput.reset(); - gMotionModal.reset(); - writeBlock(gFormat.format(65), "P" + 9810, zOutput.format(cycle.retract)); // protected retract move - } else { - if (cycleSubprogramIsActive) { - subprogramEnd(); - cycleSubprogramIsActive = false; - } - if (!cycleExpanded) { - writeBlock(gCycleModal.format(80), conditional(staticProperties.useG95forTapping, gFeedModeModal.format(94))); - gMotionModal.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 traversal.")); - return; - } - if (!staticProperties.useG0 && (((x ? 1 : 0) + (y ? 1 : 0) + (z ? 1 : 0)) > 1)) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z); - forceFeed(); - } - } -} - -function onLinear(_x, _y, _z, feed) { - if (pendingRadiusCompensation >= 0) { - // ensure that we end at desired position when compensation is turned off - xOutput.reset(); - yOutput.reset(); - } - 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; - var d = tool.diameterOffset; - if ((d > 200 && d < 1000) || d > 9999) { - warning(localize("Diameter offset out of range.")); - } - writeBlock(gPlaneModal.format(17), gFeedModeModal.format(94)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); - break; - case RADIUS_COMPENSATION_RIGHT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(1), f); - } - } -} - -var forceG0 = false; -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var num = - (xyzFormat.areDifferent(_x, xOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_y, yOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_z, zOutput.getCurrent()) ? 1 : 0) + - ((aOutput.isEnabled() && abcFormat.areDifferent(_a, aOutput.getCurrent())) ? 1 : 0) + - ((bOutput.isEnabled() && abcFormat.areDifferent(_b, bOutput.getCurrent())) ? 1 : 0) + - ((cOutput.isEnabled() && abcFormat.areDifferent(_c, cOutput.getCurrent())) ? 1 : 0); - /* - if (!getProperty("useG0") && !forceG0 && (tcpIsSupported || (num > 1))) { - invokeOnLinear5D(_x, _y, _z, _a, _b, _c, highFeedrate); // onLinear5D handles inverse time feedrates - forceG0 = false; - return; - } - */ - 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); - - if (x || y || z || a || b || c) { - if (!staticProperties.useG0 && (tcpIsSupported || (num > 1))) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, a, b, c, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z, a, b, c); - forceFeed(); - } - } -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed, feedMode) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - 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); - - if (feedMode == FEED_INVERSE_TIME) { - forceFeed(); - } - var f = getFeed(feed); - var fMode = (feedMode == FEED_INVERSE_TIME) ? 93 : 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); - } - } -} - -function moveToSafeRetractPosition(isRetracted) { - var _skipBlock = skipBlock; - if (!isRetracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing) { - skipBlock = _skipBlock; - writeRetract(X, Y); - } -} - -// Start of onRewindMachine logic -var performRewinds = false; // only use this setting with hardcoded machine configurations, set to true to enable the rewind/reconfigure logic -var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values -safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock -safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate -safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate - -/** Allow user to override the onRewind logic. */ -function onRewindMachineEntry(_a, _b, _c) { - return false; -} - -/** Retract to safe position before indexing rotaries. */ -function onMoveToSafeRetractPosition() { - // cancel TCP so that tool doesn't follow rotaries - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - moveToSafeRetractPosition(false); -} - -/** Rotate axes to new position above reentry position */ -function onRotateAxes(_x, _y, _z, _a, _b, _c) { - // position rotary axes - xOutput.disable(); - yOutput.disable(); - zOutput.disable(); - forceG0 = true; - invokeOnRapid5D(_x, _y, _z, _a, _b, _c); - setCurrentABC(new Vector(_a, _b, _c)); - xOutput.enable(); - yOutput.enable(); - zOutput.enable(); -} - -/** Return from safe position after indexing rotaries. */ -function onReturnFromSafeRetractPosition(_x, _y, _z) { - // reinstate TCP - if (tcpIsSupported) { - writeBlock(gMotionModal.format(0), gFormat.format(234), hFormat.format(tool.lengthOffset), formatComment("TCPC ON")); - forceFeed(); - lengthCompensationActive = true; - } - - // position in XY - forceXYZ(); - xOutput.reset(); - yOutput.reset(); - zOutput.disable(); - invokeOnRapid(_x, _y, _z); - - // position in Z - zOutput.enable(); - invokeOnRapid(_x, _y, _z); -} -// End of onRewindMachine logic - -// Start of polar interpolation -var usePolarMode = false; // enables polar interpolation for a single operation -var polarDirection = new Vector(1, 0, 0); // vector to maintain tool at while in polar interpolation -var saveTcpIsSupported = undefined; -function setPolarMode(section, mode) { - if (!mode) { // turn off polar mode if required - if (usePolarMode) { - var currentPosition = getCurrentPosition(); - var polarPosition = getPolarPosition(currentPosition.x, currentPosition.y, currentPosition.z); - currentMachineABC = new Vector(polarPosition.second.x, polarPosition.second.y, polarPosition.second.z); - deactivatePolarMode(); - tcpIsSupported = saveTcpIsSupported; - setFeedrateMode(true); - usePolarMode = false; - } - return; - } - - var direction = polarDirection; - - // determine the rotary axis to use for polar interpolation - var axis = undefined; - if (machineConfiguration.getAxisV().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisV().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisV(); - } - } - if (axis == undefined && machineConfiguration.getAxisU().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisU().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisU(); - } - } - if (axis == undefined) { - error(localize("Polar interpolation requires an active rotary axis be defined in direction of workplane normal.")); - } - - // calculate directional vector from initial position - if (direction == undefined) { - error(localize("Polar interpolation initiated without a directional vector.")); - return; - } else if (direction.isZero()) { - var initialPosition = getFramePosition(section.getInitialPosition()); - direction = Vector.diff(initialPosition, axis.getOffset()).getNormalized(); - } - - // put vector in plane of rotary axis - var temp = Vector.cross(direction, axis.getAxis()).getNormalized(); - direction = Vector.cross(axis.getAxis(), temp).getNormalized(); - - // activate polar interpolation - saveTcpIsSupported = tcpIsSupported; - tcpIsSupported = false; // temporary disable tcp support for polar mode - setFeedrateMode(); - activatePolarMode(tolerance / 2, 0, direction); -} -// End of polar interpolation - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - if (isSpiral()) { - var startRadius = getCircularStartRadius(); - var endRadius = getCircularRadius(); - var dr = Math.abs(endRadius - startRadius); - if (dr > maximumCircularRadiiDifference) { // maximum limit - linearize(tolerance); // or alternatively use other G-codes for spiral motion - return; - } - } - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (staticProperties.useRadius || isHelical()) { // radius mode does not support full arcs - linearize(tolerance); - return; - } - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } else if (!staticProperties.useRadius) { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), 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: - writeBlock(gPlaneModal.format(18), 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: - writeBlock(gPlaneModal.format(19), 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: - 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: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } -} - -var currentCoolantMode = COOLANT_OFF; -var coolantOff = undefined; -var isOptionalCoolant = false; - -function setCoolant(coolant) { - var coolantCodes = getCoolantCodes(coolant); - forceSingleLine = false; - if ((coolantCodes != undefined) && (coolant == COOLANT_FLOOD)) { - if (coolantPressure != "") { - forceSingleLine = true; - coolantCodes.push(coolantPressure); - } - } - if (Array.isArray(coolantCodes)) { - if (singleLineCoolant || forceSingleLine) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes.join(getWordSeparator())); - } else { - for (var c in coolantCodes) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes[c]); - } - } - return undefined; - } - return coolantCodes; -} - -var isSpecialCoolantActive = false; - -function getCoolantCodes(coolant) { - isOptionalCoolant = false; - var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line - if (!coolants) { - error(localize("Coolants have not been defined.")); - } - if (isProbeOperation()) { // avoid coolant output for probing - coolant = COOLANT_OFF; - } - if (coolant == currentCoolantMode) { - if (operationNeedsSafeStart && coolant != COOLANT_OFF && !isSpecialCoolantActive) { - //isOptionalCoolant = true; - } else if (!forceCoolant || coolant == COOLANT_OFF) { - return undefined; // coolant is already active - } - } - if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && !isOptionalCoolant && !forceCoolant) { - if (Array.isArray(coolantOff)) { - for (var i in coolantOff) { - multipleCoolantBlocks.push(mFormat.format(coolantOff[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(coolantOff)); - } - } - forceCoolant = false; - - if (isSpecialCoolantActive) { - forceSpindleSpeed = true; - } - var m; - var coolantCodes = {}; - for (var c in coolants) { // find required coolant codes into the coolants array - if (coolants[c].id == coolant) { - isSpecialCoolantActive = (coolants[c].id == COOLANT_THROUGH_TOOL) || (coolants[c].id == COOLANT_FLOOD_THROUGH_TOOL) || (coolants[c].id == COOLANT_AIR_THROUGH_TOOL); - 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(mFormat.format(m[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(m)); - } - currentCoolantMode = coolant; - return multipleCoolantBlocks; // return the single formatted coolant value - } - return undefined; -} - -var mapCommand = { - COMMAND_END:2, - 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; - forceCoolant = true; - return; - case COMMAND_OPTIONAL_STOP: - writeBlock(mFormat.format(1)); - forceSpindleSpeed = true; - forceCoolant = true; - return; - case COMMAND_COOLANT_ON: - setCoolant(COOLANT_FLOOD); - return; - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_LOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(10)); // lock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(12)); // lock 5th-axis motion - } - } - return; - case COMMAND_UNLOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(11)); // unlock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(13)); // unlock 5th-axis motion - } - } - return; - case COMMAND_BREAK_CONTROL: - if (!toolChecked) { // avoid duplicate COMMAND_BREAK_CONTROL - prepareForToolCheck(); - writeBlock( - gFormat.format(65), - "P" + 9853, - "T" + toolFormat.format(tool.number), - "B" + xyzFormat.format(0), - "H" + xyzFormat.format(staticProperties.toolBreakageTolerance) - ); - toolChecked = true; - lengthCompensationActive = false; // macro 9853 cancels tool length compensation - } - return; - case COMMAND_TOOL_MEASURE: - measureTool = true; - return; - case COMMAND_START_CHIP_TRANSPORT: - writeBlock(mFormat.format(31)); - return; - case COMMAND_STOP_CHIP_TRANSPORT: - writeBlock(mFormat.format(33)); - return; - case COMMAND_PROBE_ON: - return; - case COMMAND_PROBE_OFF: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -var toolChecked = false; // specifies that the tool has been checked with the probe - -function onSectionEnd() { - if (isInspectionOperation() && !isLastSection()) { - writeBlock(gFormat.format(103), "P0", formatComment("LOOKAHEAD ON")); - } - if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) { - setCoolant(COOLANT_OFF); - } - if ((((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) && - tool.breakControl) { - onCommand(COMMAND_BREAK_CONTROL); - } else { - toolChecked = false; - } - - if (true) { - if (isRedirecting()) { - if (firstPattern) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - var abc; - if (currentSection.isMultiAxis() && machineConfiguration.isMultiAxisConfiguration()) { - abc = currentSection.getFinalToolAxisABC(); - } else { - abc = currentWorkPlaneABC; - } - if (abc == undefined) { - abc = new Vector(0, 0, 0); - } - setAbsoluteMode(finalPosition, abc); - subprogramEnd(); - } - } - } - forceAny(); - - if (currentSection.isMultiAxis()) { - writeBlock(gFeedModeModal.format(94)); // inverse time feed off - if (currentSection.isOptimizedForMachine()) { - // the code below gets the machine angles from previous operation. closestABC must also be set to true - currentMachineABC = currentSection.getFinalToolAxisABC(); - } - if (tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - } - - if (isProbeOperation()) { - writeBlock(gFormat.format(65), "P" + 9833); // spin the probe off - if (probeVariables.probeAngleMethod != "G68") { - setProbeAngle(); // output probe angle rotations if required - } - } - - // reset for next section - operationNeedsSafeStart = false; - coolantPressure = staticProperties.coolantPressure; - cycleReverse = false; - - setPolarMode(currentSection, false); -} - -/** Output block to do safe retract and/or move to home position. */ -function writeRetract() { - var words = []; // store all retracted axes in an array - var retractAxes = new Array(false, false, false); - var method = staticProperties.safePositionMethod; - if (method == "clearanceHeight") { - if (!is3D()) { - error(localize("Retract option 'Clearance Height' is not supported for multi-axis machining.")); - } else { - return; - } - } - validate(arguments.length != 0, "No axis specified for writeRetract()."); - - for (i in arguments) { - retractAxes[arguments[i]] = true; - } - if ((retractAxes[0] || retractAxes[1]) && !retracted && !skipBlock) { // retract Z first before moving to X/Y home - error(localize("Retracting in X/Y is not possible without being retracted in Z.")); - return; - } - // special conditions - if (retractAxes[0] || retractAxes[1]) { - method = "G53"; - } - cancelG68Rotation(); // G68 has to be canceled for retracts - - // define home positions - var _xHome; - var _yHome; - var _zHome; - if (method == "G28") { - _xHome = toPreciseUnit(0, MM); - _yHome = toPreciseUnit(0, MM); - _zHome = toPreciseUnit(0, MM); - } else { - if (homePositionCenter && - hasParameter("part-upper-x") && hasParameter("part-lower-x")) { - _xHome = (getParameter("part-upper-x") + getParameter("part-lower-x")) / 2; - } else { - _xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM); - } - _yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM); - _zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM); - } - for (var i = 0; i < arguments.length; ++i) { - switch (arguments[i]) { - case X: - // special conditions - if (homePositionCenter) { // output X in standard block by itself if centering - writeBlock(gMotionModal.format(0), "X" + xyzFormat.format(_xHome)); - xOutput.reset(); - break; - } - 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 = !skipBlock; - break; - default: - error(localize("Unsupported axis specified for writeRetract().")); - return; - } - } - if (words.length > 0) { - switch (method) { - case "G28": - gMotionModal.reset(); - gAbsIncModal.reset(); - writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); - writeBlock(gAbsIncModal.format(90)); - break; - case "G53": - gMotionModal.reset(); - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); - break; - default: - error(localize("Unsupported safe position method.")); - return; - } - } -} - -var isDPRNTopen = false; -function inspectionCreateResultsFileHeader() { - if (isDPRNTopen) { - if (!staticProperties.singleResultsFile) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - } - } - - if (isProbeOperation() && !printProbeResults()) { - return; // if print results is not desired by probe/ probeWCS - } - - if (!isDPRNTopen) { - writeBlock("PCLOS"); - writeBlock("POPEN"); - // check for existence of none alphanumeric characters but not spaces - var resFile; - if (staticProperties.singleResultsFile) { - resFile = getParameter("job-description") + "-RESULTS"; - } else { - resFile = getParameter("operation-comment") + "-RESULTS"; - } - resFile = resFile.replace(/:/g, "-"); - resFile = resFile.replace(/[^a-zA-Z0-9 -]/g, ""); - resFile = resFile.replace(/\s/g, "-"); - writeln("DPRNT[START]"); - writeln("DPRNT[RESULTSFILE*" + resFile + "]"); - if (hasGlobalParameter("document-id")) { - writeln("DPRNT[DOCUMENTID*" + getGlobalParameter("document-id") + "]"); - } - if (hasGlobalParameter("model-version")) { - writeln("DPRNT[MODELVERSION*" + getGlobalParameter("model-version") + "]"); - } - } - if (isProbeOperation() && printProbeResults()) { - isDPRNTopen = true; - } -} - -function getPointNumber() { - if (typeof inspectionWriteVariables == "function") { - return (inspectionVariables.pointNumber); - } else { - return ("#172[60]"); - } -} - -function inspectionWriteCADTransform() { - var cadOrigin = currentSection.getModelOrigin(); - var cadWorkPlane = currentSection.getModelPlane().getTransposed(); - var cadEuler = cadWorkPlane.getEuler2(EULER_XYZ_S); - writeln( - "DPRNT[G331" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(cadEuler.x) + - "*B" + abcFormat.format(cadEuler.y) + - "*C" + abcFormat.format(cadEuler.z) + - "*X" + xyzFormat.format(-cadOrigin.x) + - "*Y" + xyzFormat.format(-cadOrigin.y) + - "*Z" + xyzFormat.format(-cadOrigin.z) + - "]" - ); -} - -function inspectionWriteWorkplaneTransform() { - var orientation = (machineConfiguration.isMultiAxisConfiguration() && currentMachineABC != undefined) ? machineConfiguration.getOrientation(currentMachineABC) : currentSection.workPlane; - var abc = orientation.getEuler2(EULER_XYZ_S); - writeln("DPRNT[G330" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(abc.x) + - "*B" + abcFormat.format(abc.y) + - "*C" + abcFormat.format(abc.z) + - "*X0*Y0*Z0*I0*R0]" - ); -} - -function writeProbingToolpathInformation(cycleDepth) { - writeln("DPRNT[TOOLPATHID*" + getParameter("autodeskcam:operation-id") + "]"); - if (isInspectionOperation()) { - writeln("DPRNT[TOOLPATH*" + getParameter("operation-comment") + "]"); - } else { - writeln("DPRNT[CYCLEDEPTH*" + xyzFormat.format(cycleDepth) + "]"); - } -} - -function onClose() { - writeRetract(Z); - - if (isDPRNTopen) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - if (typeof inspectionProcessSectionEnd == "function") { - inspectionProcessSectionEnd(); - } - } - cancelG68Rotation(); - writeln(""); - - optionalSection = false; - - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - writeBlock(mFormat.format(0)); - - writeln(""); - writeComment("UNLOAD TOOLS"); - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - if (tool.number == 20 || tool.number == 19) { - continue; - } - writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - displayMedia("removeTool" + tool.number + ".jpg", false, "Remove tool " + tool.number); - } - } - - function gotoWithMessage(xLoc, yLoc, fileName, comment) { - writeBlock(gFormat.format(53), xOutput.format(xLoc), yOutput.format(yLoc)); - displayMedia(fileName, false, comment); - } - - writeln(""); - writeComment("CLEAN MACHINE"); - gotoWithMessage(X_TRAVEL_LIMIT/2, 0, "airGunClean.jpg", "Use air gun to clean"); - displayMedia("floodCoolantOff.jpg", false, "Turn flood coolant off") - setCoolant(COOLANT_FLOOD); - gotoWithMessage(0, Y_TRAVEL_LIMIT, "sprayLowerRight.jpg", "Spray lower right"); - gotoWithMessage(X_TRAVEL_LIMIT, Y_TRAVEL_LIMIT, "sprayLowerLeft.jpg", "Spray lower left"); - gotoWithMessage(0, 0, "sprayUpperRight.jpg", "Spray upper right") - gotoWithMessage(X_TRAVEL_LIMIT, 0, "sprayUpperLeft.jpg", "Spray upper left") - onCommand(COMMAND_COOLANT_OFF); - onCommand(COMMAND_START_CHIP_TRANSPORT); - gotoWithMessage(X_TRAVEL_LIMIT/2, Y_TRAVEL_LIMIT, "sweepChips.jpg", "Sweep chips"); - onCommand(COMMAND_STOP_CHIP_TRANSPORT); - - writeln(""); - // retract - if (!staticProperties.homePositionCenter || currentMachineABC.length != 0) { - writeRetract(X, Y); - } - - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - - // MAY NEED CHANGE HOMING ORDER TO ROTARY THEN LINEAR FOR NON-UMC MACHINES - - // Unwind Rotary table at end - if (machineConfiguration.isMultiAxisConfiguration()) { - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - if (machineConfiguration.isMachineCoordinate(2)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(1)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "B" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(0)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "A" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(0)) - ); - } - if (staticProperties.homePositionCenter) { - homePositionCenter = staticProperties.homePositionCenter; - writeRetract(X, Y); - } - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - - if (staticProperties.useM130PartImages || staticProperties.useM130ToolImages) { - writeBlock(mFormat.format(131)); - } - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - if (subprograms.length > 0) { - writeln(""); - write(subprograms); - } - writeln(""); - writeln("%"); -} - -/* -keywords += (keywords ? " MODEL_IMAGE" : "MODEL_IMAGE"); - -function onTerminate() { - var outputPath = getOutputPath(); - var programFilename = FileSystem.getFilename(outputPath); - var programSize = FileSystem.getFileSize(outputPath); - var postPath = findFile("setup-sheet-excel-2007.cps"); - var intermediatePath = getIntermediatePath(); - var a = "--property unit " + ((unit == IN) ? "0" : "1"); // use 0 for inch and 1 for mm - if (programName) { - a += " --property programName \"'" + programName + "'\""; - } - if (programComment) { - a += " --property programComment \"'" + programComment + "'\""; - } - a += " --property programFilename \"'" + programFilename + "'\""; - a += " --property programSize \"" + programSize + "\""; - a += " --noeditor --log temp.log \"" + postPath + "\" \"" + intermediatePath + "\" \"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\""; - execute(getPostProcessorPath(), a, false, ""); - executeNoWait("excel", "\"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\"", false, ""); -} -*/ - -function setProperty(property, value) { - properties[property].current = value; -} diff --git a/Haas_Mills_BIDC/Bechtel VF4.cps b/Haas_Mills_BIDC/Bechtel VF4.cps deleted file mode 100644 index 56e0a2f..0000000 --- a/Haas_Mills_BIDC/Bechtel VF4.cps +++ /dev/null @@ -1,4661 +0,0 @@ -/** - Copyright (C) 2012-2021 by Autodesk, Inc. - All rights reserved. - - HAAS post processor configuration. - - $Revision: 43348 37c695f19b2eab4d5737a29df773b981b83fa8d4 $ - $Date: 2021-07-12 15:10:04 $ - - Modified by BIDC of Purdue University - Authors: Gavin Williams (will1742@purdue.edu) -*/ - -//////////////////////////////////////////////////////////////////////////////////////////////// -// MANUAL NC COMMANDS -// -// The following ACTION commands are supported by this post. -// -// CYCLE_REVERSAL - Reverses the spindle in a drilling cycle -// USEPOLARMODE - Enables polar interpolation for the following operation. -// VFD_HIGH - Uses high pressure flood coolant if machine has VFD -// VFD_LOW - Uses low pressure flood coolant if machine has VFD -// VFD_NORMAL - Uses normal pressure flood coolant if machine has VFD -// -//////////////////////////////////////////////////////////////////////////////////////////////// - -description = "HAAS - Next Generation Control"; -vendor = "Haas Automation"; -vendorUrl = "https://www.haascnc.com"; -legal = "Copyright (C) 2012-2021 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 45702; - -longDescription = "Generic post for the HAAS Next Generation control. The post includes support for multi-axis indexing and simultaneous machining. The post utilizes the dynamic work offset feature so you can place your work piece as desired without having to repost your NC programs." + EOL + -"You can specify following pre-configured machines by using the property 'Machine model':" + EOL + -"UMC-500" + EOL + "UMC-750" + EOL + "UMC-1000" + EOL + "UMC-1600-H"; - -extension = "nc"; -programNameIsInteger = true; -setCodePage("ascii"); -keywords = "MODEL_IMAGE PREVIEW_IMAGE"; - -capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(355); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion -allowSpiralMoves = true; -highFeedrate = (unit == IN) ? 650 : 5000; - -// user-defined properties -properties = {/* - machineModel: { - title: "Machine model", - description: "Specifies the pre-configured machine model.", - type: "enum", - group: 0, - values: [ - {title: "None", id: "none"}, - {title: "UMC-500", id: "umc-500"}, - {title: "UMC-750", id: "umc-750"}, - {title: "UMC-1000", id: "umc-1000"}, - {title: "UMC-1600-H", id: "umc-1600"} - ], - value: "none", - scope: "post" - }, - hasAAxis: { - title: "Has A-axis rotary", - description: "Enable if the machine has an A-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasBAxis: { - title: "Has B-axis rotary", - description: "Enable if the machine has a B-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasCAxis: { - title: "Has C-axis rotary", - description: "Enable if the machine has a C-axis table. Specifies a trunnion setup if an A-axis or B-axis is defined. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - throughSpindle: { - title: "Allow Through Spindle Coolant", - description: "Enables through spindle coolant, if off uses flood", - type: "boolean", - group: 50, - value: true, - scope: "post" - }, - useDPMFeeds: { - title: "Rotary moves use DPM feeds", - description: "Enable to output DPM feeds, disable for Inverse Time feeds with rotary axes moves.", - group: 1, - type: "boolean", - value: false, - scope: "post" - },*/ - useTCPC: { - title: "Use TCPC programming", - description: "The control supports Tool Center Point Control programming.", - group: 1, - type: "boolean", - value: true, - scope: "post" - },/* - useDWO: { - title: "Use DWO", - description: "Specifies that the Dynamic Work Offset feature (G254/G255) should be used.", - group: 1, - type: "boolean", - value: true, - scope: "post" - }, - preloadTool: { - title: "Preload tool", - description: "Preloads the next tool at a tool change (if any).", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - chipTransport: { - title: "Use chip transport", - description: "Enable to turn on chip transport at start of program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - optionalStop: { - title: "Optional stop", - description: "Specifies that optional stops M1 should be output at tool changes.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - separateWordsWithSpace: { - title: "Separate words with space", - description: "Adds spaces between words if 'yes' is selected.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useRadius: { - title: "Radius arcs", - description: "If yes is selected, arcs are output using radius values rather than IJK.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useParametricFeed: { - title: "Parametric feed", - description: "Parametric feed values based on movement type are output.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useG0: { - title: "Use G0", - description: "Specifies that G0s should be used for rapid moves when moving along a single axis.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - safePositionMethod: { - title: "Safe Retracts", - description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.", - type: "enum", - values: [ - {title: "G28", id: "G28"}, - {title: "G53", id: "G53"}, - {title: "Clearance Height", id: "clearanceHeight"} - ], - value: "G53", - scope: "post" - }, - useG187: { - title: "Use G187", - description: "Specifies that smoothing using G187 should be used.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - homePositionCenter: { - title: "Home position center", - description: "Enable to center the part along X at the end of program for easy access. Requires a CNC with a moving table.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - optionallyCycleToolsAtStart: { - title: "Optionally cycle tools at start", - description: "Cycle through each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - measureToolsAtStart: { - title: "Optionally measure tools at start", - description: "Measure each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - forceHomeOnIndexing: { - title: "Force XY home position on indexing", - description: "Move XY to their home positions on multi-axis indexing.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - toolBreakageTolerance: { - title: "Tool breakage tolerance", - description: "Specifies the tolerance for which tool break detection will raise an alarm.", - group: 2, - type: "spatial", - value: 0.1, - scope: "post" - }, - safeStartAllOperations: { - title: "Safe start all operations", - description: "Write optional blocks at the beginning of all operations that include all commands to start program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - fastToolChange: { - title: "Fast tool change", - description: "Skip spindle off, coolant off, and Z retract to make tool change quicker.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useG95forTapping: { - title: "Use G95 for tapping", - description: "use IPR/MPR instead of IPM/MPM for tapping", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - safeRetractDistance: { - title: "Safe retract distance", - description: "Specifies the distance to add to retract distance when rewinding rotary axes.", - group: 2, - type: "spatial", - value: 0, - scope: "post" - },*/ - useSubroutines: { - title: "Use subroutines", - description: "Select your desired subroutine option. 'All Operations' creates subroutines per each operation, 'Cycles' creates subroutines for cycle operations on same holes, and 'Patterns' creates subroutines for patterned operations.", - type: "enum", - values: [ - {title: "No", id: "none"}, - {title: "All Operations", id: "allOperations"}, - {title: "Cycles", id: "cycles"}, - {title: "Patterns", id: "patterns"} - ], - group: 3, - value: "none", - scope: "post" - },/* - writeMachine: { - title: "Write machine", - description: "Output the machine settings in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - writeTools: { - title: "Write tool list", - description: "Output a tool list in the header of the code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - writeVersion: { - title: "Write version", - description: "Write the version number in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showSequenceNumbers: { - title: "Use sequence numbers", - description: "Use sequence numbers for each block of outputted code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - sequenceNumberStart: { - title: "Start sequence number", - description: "The number at which to start the sequence numbers.", - group: 4, - type: "integer", - value: 10, - scope: "post" - }, - sequenceNumberIncrement: { - title: "Sequence number increment", - description: "The amount by which the sequence number is incremented by in each block.", - group: 4, - type: "integer", - value: 5, - scope: "post" - }, - sequenceNumberOnlyOnToolChange: { - title: "Block number only on tool change", - description: "Specifies that block numbers should only be output at tool changes.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showNotes: { - title: "Show notes", - description: "Enable to output notes for operations.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - useM130PartImages: { - title: "Include M130 part images", - description: "Enable to include M130 part images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - useM130ToolImages: { - title: "Include M130 tool images", - description: "Enable to include M130 tool images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - coolantPressure: { - title: "Coolant pressure", - description: "Select the coolant pressure if equipped with a Variable Frequency Drive. Select 'Default' if this option is not installed.", - type: "enum", - group: 2, - values: [ - {title: "Default", id: ""}, - {title: "Low", id: "P0"}, - {title: "Normal", id: "P1"}, - {title: "High", id: "P2"} - ], - value: "", - scope: "post" - }, - singleResultsFile: { - title: "Create single results file", - description: "Set to false if you want to store the measurement results for each probe / inspection toolpath in a separate file", - group: 0, - type: "boolean", - value: true, - scope: "post" - }*/ - toolsToLoad: { - title: "Tools to load and probe", - description: "List or provide a range of tools to probe e.g. 1, 2, 3 or 1-5. Leaving this empty will probe all tools", - group: 4, - type: "string", - value: "", - scope: "post" - }, - toolLengthValidation: { - title: "Tool Length Validation", - description: "Length validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - pencilWCSValidation: { - title: "WCS Validation", - description: "WCS validation. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - measureToolsAtStart: { - title: "Tool Probing", - description: "Tool Probing. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - loadToolsAtStart: { - title: "Tool Loading", - description: "Tool Loading. By setting this to optional, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" - }, - displayMediaCalls: { - title: "Display Media", - description: "Enable to include M130 part images with the NC file, disable to see the information in comments.", - group: 4, - value: false, - scope: "post" - } -}; - -staticProperties = { - machineModel: "none", - safePositionMethod: "G53", - useDPMFeeds: false, - useTCPC: true, - useDWO: true, - safeStartAllOperations: true, - preloadTool: true, - chipTransport: false, - optionalStop: true, - separateWordsWithSpace: true, - useRadius: false, - useParametricFeed: true, - useG0: true, - useG187: false, - homePositionCenter: false, - optionallyCycleToolsAtStart: false, - measureToolsAtStart: true, - forceHomeOnIndexing: false, - toolBreakageTolerance: 0.1, - fastToolChange: false, - useG95forTapping: true, - safeRetractDistance: 0, - //useSubroutines: "allOperations", - writeMachine: false, - writeTools: true, - writeVersion: false, - showSequenceNumbers: true, - sequenceNumberStart: 10, - sequenceNumberIncrement: 5, - sequenceNumberOnlyOnToolChange: false, - showNotes: true, - useM130PartImages: false, - useM130ToolImages: false, - coolantPressure: "", - singleResultsFile: true, - useP9995: true, - hasAAxis: "false", - hasBAxis: "false", - hasCAxis: "false", - postVersion: "VF4G8A21" - }; - - const HAAS_DRILL = 1; - const HAAS_TAP = 2; - const HAAS_SHELL = 3; - const HAAS_END_MILL = 4; - const HAAS_CENTER = 5; - const HAAS_BALL_NOSE = 6; - const HAAS_PROBE = 7; - - const NO_PROBING = 0; - const LEN_ROT = 1; - const LEN_NON_ROT = 2; - const LEN_DIA_ROT = 3; - - const DEFAULT_HAAS_K_FACTOR = 0.05; - const NULL_HAAS_K_FACTOR = 0; - - const CLEARANCE_HEIGHT = 1; - const LENGTH_TOLERANCE = .25; - const DIAM_TOLERANCE = .01; - - // VF4 specific - const MAX_TOOL_LENGTH = 13; - const MAX_TOOL_DIAM = 5; - const X_TRAVEL_LIMIT = -50; - const Y_TRAVEL_LIMIT = -20; - - const MAX_TOOL_NUM = 20; -var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines -// samples: -// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} -// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} -var coolants = [ - {id: COOLANT_FLOOD, on: 8}, - {id: COOLANT_MIST}, - {id: COOLANT_THROUGH_TOOL, on: 88, off: 89}, - {id: COOLANT_AIR, on: 83, off: 84}, - {id: COOLANT_AIR_THROUGH_TOOL, on: 73, off: 74}, - {id: COOLANT_SUCTION}, - {id: COOLANT_FLOOD_MIST}, - {id: COOLANT_FLOOD_THROUGH_TOOL, on: [88, 8], off: [89, 9]}, - {id: COOLANT_OFF, off: 9} -]; - -// old machines only support 4 digits -var oFormat = createFormat({width:5, zeropad:true, decimals:0}); -var nFormat = createFormat({decimals:0}); - -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 probeWCSFormat = createFormat({decimals:2, forceDecimal:true}); -var macroFormat = createFormat({prefix:"#", decimals:0}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var rFormat = xyzFormat; // radius -var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true}); -var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var forceX = createFormat({prefix:"X", decimals:4, forceDecimal:true}); -var forceY = createFormat({prefix:"Y", decimals:4, forceDecimal:true}); -var forceZ = createFormat({prefix:"Z", decimals:4, forceDecimal:true}); - -var xOutput = createVariable({prefix:"X"}, xyzFormat); -var yOutput = createVariable({prefix:"Y"}, xyzFormat); -var zOutput = createVariable({onchange: function() {retracted = false;}, prefix:"Z"}, xyzFormat); -var aOutput = createVariable({prefix:"A"}, abcFormat); -var bOutput = createVariable({prefix:"B"}, abcFormat); -var cOutput = createVariable({prefix:"C"}, abcFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var dOutput = createVariable({}, dFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat); -var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat); -var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat); - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({force:true}, gFormat); // modal group 10 // G98-99 -var gRotationModal = createModal({ - onchange: function () { - if (probeVariables.probeAngleMethod == "G68") { - probeVariables.outputRotationCodes = true; - } - } -}, gFormat); // modal group 16 // G68-G69 - -// fixed settings -var firstFeedParameter = 100; // the first variable to use with parametric feed -var forceResetWorkPlane = false; // enable to force reset of machine ABC on new orientation -var minimumCyclePoints = 5; // minimum number of points in cycle operation to consider for subprogram -var useDwoForPositioning = true; // specifies to use the DWO feature for XY positioning for multi-axis operations - -var WARNING_WORK_OFFSET = 0; - -var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported -var probeVariables = { - outputRotationCodes: false, // defines if it is required to output rotation codes - probeAngleMethod: "OFF", // OFF, AXIS_ROT, G68, G54.4 - compensationXY: undefined, - rotationalAxis: -1 -}; - -var SUB_UNKNOWN = 0; -var SUB_PATTERN = 1; -var SUB_CYCLE = 2; - -// collected state -var sequenceNumber; -var currentWorkOffset; -var coolantPressure; -var optionalSection = false; -var forceSpindleSpeed = false; -var forceCoolant = false; -var activeMovements; // do not use by default -var currentFeedId; -var maximumCircularRadiiDifference = toPreciseUnit(0.005, MM); -var maximumLineLength = 80; // the maximum number of charaters allowed in a line -var subprograms = []; -var currentPattern = -1; -var firstPattern = false; -var currentSubprogram; -var lastSubprogram; -var initialSubprogramNumber = 90000; -var definedPatterns = new Array(); -var incrementalMode = false; -var saveShowSequenceNumbers; -var cycleSubprogramIsActive = false; -var patternIsActive = false; -var lastOperationComment = ""; -var incrementalSubprogram; -var retracted = false; // specifies that the tool has been retracted to the safe plane -var hasA = false; -var hasB = false; -var hasC = false; -var measureTool = false; -var cycleReverse = false; -var probeMultipleFeatures = true; -var maximumSpindleRPM = 15000; -var homePositionCenter = false; - -// used to convert blocks to optional for safeStartAllOperations, might get used outside of onSection -var operationNeedsSafeStart = false; - -/** - Writes the specified block. -*/ -var skipBlock = false; -function writeBlock() { - var text = formatWords(arguments); - if (!text) { - return; - } - var maximumSequenceNumber = ((getProperty("useSubroutines") == "allOperations") || (getProperty("useSubroutines") == "patterns") || - (getProperty("useSubroutines") == "cycles")) ? initialSubprogramNumber : 99999; - if (staticProperties.showSequenceNumbers) { - if (sequenceNumber >= maximumSequenceNumber) { - sequenceNumber = staticProperties.sequenceNumberStart; - } - if (optionalSection || skipBlock) { - if (text) { - writeWords("/", "N" + sequenceNumber, text); - } - } else { - writeWords2("N" + sequenceNumber, arguments); - } - sequenceNumber += staticProperties.sequenceNumberIncrement; - } else { - if (optionalSection || skipBlock) { - writeWords2("/", arguments); - } else { - writeWords(arguments); - } - } - skipBlock = false; -} - -/** - Writes the specified block - used for tool changes only. -*/ -function writeToolBlock() { - var show = staticProperties.showSequenceNumbers; - staticProperties.showSequenceNumbers = (show || staticProperties.sequenceNumberOnlyOnToolChange); - writeBlock(arguments); - staticProperties.showSequenceNumbers = show; -} - -/** - Writes the specified optional block. -*/ -function writeOptionalBlock() { - skipBlock = true; - writeBlock(arguments); -} - -function formatComment(text) { - return "(" + String(text).replace(/[()]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text.substr(0, maximumLineLength - 2))); -} - -/** - Returns the matching HAAS tool type for the tool. -*/ -function getHaasToolType(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return 1; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return 2; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return 3; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - return 4; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_THREAD: - case TOOL_MILLING_FORM: - return 5; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - return 6; // ball nose - case TOOL_PROBE: - return 7; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -function getHaasProbingType(toolType, use9023) { - switch (getHaasToolType(toolType)) { - case 3: - case 4: - return (use9023 ? 23 : 1); // rotate - case 1: - case 2: - case 5: - case 6: - case 7: - return (use9023 ? 12 : 2); // non rotate - case 0: - return (use9023 ? 13 : 3); // rotate length and dia - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - - -// Added new probe mapping - see documentation -// will1742 | Gavin Williams -function getHaasToolTypeBIDC(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return HAAS_DRILL; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return HAAS_TAP; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return HAAS_SHELL; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - case TOOL_MILLING_THREAD: - return HAAS_END_MILL; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_FORM: - return HAAS_CENTER; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - case TOOL_MILLING_RADIUS: - return HAAS_BALL_NOSE; // ball nose - case TOOL_PROBE: - return HAAS_PROBE; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -// 06/25/21 | Gavin Williams | will1742 -// 002 Probing -function formatCNumber(probeType, use9023){ - if (use9023) { - if (probeType == LEN_NON_ROT || probeType == LEN_DIA_ROT){ - return probeType + 10; - } - return 23; - } - return probeType; -} - -function getHaasProbingTypeBIDC(tool, use9023) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_PROBE: - return formatCNumber(NO_PROBING, use9023); - case HAAS_TAP: - case HAAS_DRILL: - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_CENTER: - if (tool.type == TOOL_MILLING_FORM) { - return formatCNumber(NO_PROBING, use9023); - } - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_END_MILL: - return formatCNumber((tool.type == TOOL_MILLING_TAPERED ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_BALL_NOSE: - return formatCNumber((tool.type == TOOL_MILLING_RADIUS ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_SHELL: - if ((tool.type == TOOL_MILLING_FACE) && (tool.taperAngle !=0)) { - return formatCNumber(LEN_ROT, use9023); - } - return formatCNumber(LEN_DIA_ROT, use9023); - default: - return -1; - } -} - -function getHaasKFactorBIDC(tool) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_SHELL: - case HAAS_END_MILL: - if (tool.type == TOOL_BORING_BAR || tool.type == TOOL_MILLING_END_FLAT) { - return DEFAULT_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_FACE && tool.taperAngle != 0) { - return NULL_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_THREAD) { - return DEFAULT_HAAS_K_FACTOR + tool.getThreadPitch(); - } - return DEFAULT_HAAS_K_FACTOR + tool.cornerRadius; - case HAAS_BALL_NOSE: - if (tool.type == TOOL_MILLING_RADIUS) { - return NULL_HAAS_K_FACTOR; - } - return DEFAULT_HAAS_K_FACTOR + (tool.diameter/2); - case HAAS_CENTER: - case HAAS_PROBE: - case HAAS_DRILL: - case HAAS_TAP: - - return NULL_HAAS_K_FACTOR; - default: - return -1; - } -} - -function writeToolCycleBlock(tool) { - writeOptionalBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - writeOptionalBlock(mFormat.format(0)); // wait for operator -} - -function prepareForToolCheck() { - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - - // cancel TCP so that tool doesn't follow tables - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - if ((currentSection.isMultiAxis() && getCurrentDirection().length != 0) || - (currentMachineABC != undefined && currentMachineABC.length != 0)) { - setWorkPlane(new Vector(0, 0, 0)); - forceWorkPlane(); - } -} - -function writeToolMeasureBlock(tool, preMeasure) { - var writeFunction = getProperty("measureToolsAtStart") ? writeBlock : writeOptionalBlock; - var comment = measureTool ? formatComment("MEASURE TOOL") : ""; - if (!preMeasure) { - prepareForToolCheck(); - } - if (!staticProperties.useP9995) { // use Macro P9023 to measure tools - var probingType = getHaasProbingTypeBIDC(tool.type, true); - writeFunction( - gFormat.format(65), - "P9023", - "A" + probingType + ".", - "T" + toolFormat.format(tool.number), - conditional((probingType != 12), "H" + xyzFormat.format(tool.bodyLength + tool.holderLength)), - conditional((probingType != 12), "D" + xyzFormat.format(tool.diameter)), - comment - ); - } else { // use Macro P9995 to measure tools - // writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - setMacro(1600 + tool.number, tool.numberOfFlutes, "Number of Flutes", !getProperty("measureToolsAtStart")); - setMacro(2400 + tool.number, xyzFormat.format(tool.diameter), "Tool Diameter", !getProperty("measureToolsAtStart")); - var probeType = getHaasProbingTypeBIDC(tool, false); - writeFunction( - gFormat.format(65), - "P9995", - "A0.", - "B" + getHaasToolTypeBIDC(tool.type) + ".", - "C" + probeType + ".", - "T" + toolFormat.format(tool.number), - "E" + xyzFormat.format(tool.bodyLength + tool.holderLength), - "D" + xyzFormat.format(tool.diameter), - "K" + xyzFormat.format(getHaasKFactorBIDC(tool)), - "I0.", - comment - ); // probe tooling - var line1 = "IF [[#" + (2000 + tool.number) + " GT " + - (tool.bodyLength + tool.holderLength + LENGTH_TOLERANCE).toFixed(2) + "] OR [#" + - (2000 + tool.number) + " LT " + - (tool.bodyLength + tool.holderLength - LENGTH_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool length out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line1 : "/ " + line1); - if (probeType == 3) { - var line2 = "IF [[#" + (2400 + tool.number) + " GT " + - (tool.diameter + DIAM_TOLERANCE).toFixed(2) + "] OR [#" + - (2400 + tool.number) + " LT " + - (tool.diameter - DIAM_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool diameter out of tolerance)"; - - writeWords(getProperty("measureToolsAtStart") ? line2 : "/ " + line2); - } - } - measureTool = false; -} - -// 6/28/21 | Gavin Williams | will1742 -// 002 Improved Probing -// sets specified macro number with value -function setMacro(macro, value, comment, isOptional) { - if (isOptional) { - writeWords("/ #" + macro + "=" + value, "(" + comment + ")"); - } else { - writeWords("#" + macro + "=" + value, "(" + comment + ")"); - } -} - -function defineMachineModel() { - var useTCPC = getProperty("useTCPC"); - switch (staticProperties.machineModel) { - case "umc-500": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-23.96, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-3.37, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-750": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-29.0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-8, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(2.5, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1000": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-40.07, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-10.76, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1600": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-120, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 7500; - break; - } - machineConfiguration.setModel(staticProperties.machineModel.toUpperCase()); - machineConfiguration.setVendor("Haas Automation"); - - setMachineConfiguration(machineConfiguration); - if (receivedMachineConfiguration) { - warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); - receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten - } -} - -// Start of machine configuration logic -var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads -var virtualTooltip = false; // translate the pivot point to the virtual tool tip for nonTCP rotary heads -// internal variables, do not change -var receivedMachineConfiguration; -var tcpIsSupported; - -function activateMachine() { - // determine if TCP is supported by the machine - tcpIsSupported = false; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i in axes) { - if (axes[i].isEnabled() && axes[i].isTCPEnabled()) { - tcpIsSupported = true; - break; - } - } - - // setup usage of multiAxisFeatures - useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : - (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); - useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : - (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); - - if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { - cOutput.disable(); - } - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // don't need to modify any settings for 3-axis machines - } - - // retract/reconfigure - safeRetractDistance = staticProperties.safeRetractDistance != undefined ? staticProperties.safeRetractDistance : - (typeof safeRetractDistance == "number" ? safeRetractDistance : 0); - if (machineConfiguration.performRewinds() || (typeof performRewinds == "undefined" ? false : performRewinds)) { - machineConfiguration.enableMachineRewinds(); // enables the rewind/reconfigure logic - if (typeof stockExpansion != "undefined") { - machineConfiguration.setRewindStockExpansion(stockExpansion); - if (!receivedMachineConfiguration) { - setMachineConfiguration(machineConfiguration); - } - } - } - - if (machineConfiguration.isHeadConfiguration()) { - compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; - virtualTooltip = typeof virtualTooltip == "undefined" ? false : virtualTooltip; - machineConfiguration.setVirtualTooltip(virtualTooltip); - } - setFeedrateMode(); - - if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.isMultiAxis()) { - machineConfiguration.setToolLength(section.getTool().getBodyLength()); // define the tool length for head adjustments - section.optimizeMachineAnglesByMachine(machineConfiguration, tcpIsSupported ? 0 : 1); - } - } - } else { - optimizeMachineAngles2(tcpIsSupported ? 0 : 1); - } -} - -function setFeedrateMode(reset) { - if ((tcpIsSupported && !reset) || !machineConfiguration.isMultiAxisConfiguration()) { - return; - } - machineConfiguration.setMultiAxisFeedrate( - tcpIsSupported ? FEED_FPM : staticProperties.useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, - 9999.99, // maximum output value for inverse time feed rates - INVERSE_MINUTES, // can be INVERSE_SECONDS or DPM_COMBINATION for DPM feeds - 0.5, // tolerance to determine when the DPM feed has changed - 1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations - ); - if (!receivedMachineConfiguration || (revision < 45765)) { - setMachineConfiguration(machineConfiguration); - } -} - -function defineMachine() { - hasA = staticProperties.hasAAxis != "false"; - hasB = staticProperties.hasBAxis != "false"; - hasC = staticProperties.hasCAxis != "false"; - - if (hasA && hasB && hasC) { - error(localize("Only two rotary axes can be active at the same time.")); - return; - } else if ((hasA || hasB || hasC) && staticProperties.machineModel != "none") { - error(localize("You can only select either a machine model or use the ABC axis properties.")); - return; - } else if (((hasA || hasB || hasC) || staticProperties.machineModel != "none") && (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration())) { - error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); - return; - } - if (staticProperties.machineModel == "none") { - if (hasA || hasB || hasC) { // configure machine - var aAxis; - var bAxis; - var cAxis; - var useTCPC = getProperty("useTCPC"); - if (hasA) { // A Axis - For horizontal machines and trunnions - var dir = staticProperties.hasAAxis == "reversed" ? -1 : 1; - if (hasC || hasB) { - var aMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var aMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], range:[aMin, aMax], preference:dir, reset:(hasB ? 0 : 1), tcp:useTCPC}); - } else { - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasB) { // B Axis - For horizontal machines and trunnions - var dir = staticProperties.hasBAxis == "reversed" ? -1 : 1; - if (hasC) { - var bMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var bMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], range:[bMin, bMax], preference:-dir, reset:1, tcp:useTCPC}); - } else if (hasA) { - bAxis = createAxis({coordinate:1, table:true, axis:[0, 0, dir], cyclic:true, tcp:useTCPC}); - } else { - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasC) { // C Axis - For trunnions only - var dir = staticProperties.hasCAxis == "reversed" ? -1 : 1; - cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, dir], cyclic:true, reset:1, tcp:useTCPC}); - } - - if (hasA && hasC) { // AC trunnion - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else if (hasB && hasC) { // BC trunnion - machineConfiguration = new MachineConfiguration(bAxis, cAxis); - } else if (hasA && hasB) { // AB trunnion - machineConfiguration = new MachineConfiguration(aAxis, bAxis); - } else if (hasA) { // A rotary - machineConfiguration = new MachineConfiguration(aAxis); - } else if (hasB) { // B rotary - horizontal machine only - machineConfiguration = new MachineConfiguration(bAxis); - } else if (hasC) { // C rotary - machineConfiguration = new MachineConfiguration(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 - } - } - } else { - defineMachineModel(); - } - /* home positions */ - // machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - // machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - // machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); -} -// End of machine configuration logic - -function onOpen() { - receivedMachineConfiguration = (typeof machineConfiguration.isReceived == "function") ? machineConfiguration.isReceived() : - ((machineConfiguration.getDescription() != "") || machineConfiguration.isMultiAxisConfiguration()); - if (typeof defineMachine == "function") { - defineMachine(); // hardcoded machine configuration - } - activateMachine(); // enable the machine optimizations and settings - - if (staticProperties.useDPMFeeds) { - gFeedModeModal.format(94); - } - if (staticProperties.useRadius) { - maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC - } - if (staticProperties.sequenceNumberOnlyOnToolChange) { - staticProperties.showSequenceNumbers = false; - } - if (!staticProperties.useDWO) { - useDWOForPositioning = false; - } - - gRotationModal.format(69); // Default to G69 Rotation Off - - if (highFeedrate <= 0) { - error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal.")); - return; - } - - if (!staticProperties.separateWordsWithSpace) { - setWordSeparator(""); - } - saveShowSequenceNumbers = staticProperties.showSequenceNumbers; - sequenceNumber = staticProperties.sequenceNumberStart; - writeln("%"); - - if (programName) { - var programId; - try { - programId = getAsInt(programName); - } catch (e) { - error(localize("Program name must be a number.")); - return; - } - if (!((programId >= 1) && (programId <= 99999))) { - error(localize("Program number is out of range.")); - return; - } - writeln( - "O" + oFormat.format(programId) + - conditional(programComment, " " + formatComment(programComment.substr(0, maximumLineLength - 2 - ("O" + oFormat.format(programId)).length - 1))) - ); - lastSubprogram = (initialSubprogramNumber - 1); - } else { - error(localize("Program name has not been specified.")); - return; - } - - writeComment("Career Account Username: " + getGlobalParameter("username")); - writeComment("Filename: " + getGlobalParameter("document-path")); - writeComment("Date: " + getGlobalParameter("generated-at")); - writeComment("Post Version: " + staticProperties.postVersion); - - if (staticProperties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (staticProperties.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 (staticProperties.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" + 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); - - if (staticProperties.useM130PartImages) { - var toolRenderer = createToolRenderer(); - if (toolRenderer) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - toolRenderer.setFluteColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - toolRenderer.setShoulderColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setShaftColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setHolderColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - if (i % 2 == 0) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - } else { - toolRenderer.setBackgroundColor(new Color(240 / 255.0, 240 / 255.0, 240 / 255.0)); - } - var path = "tool" + tool.number + ".png"; - var width = 400; - var height = 532; - toolRenderer.exportAs(path, "image/png", tool, width, height); - } - } - } - } - } - - writeln(""); - writeComment("Reset work plane, cancel all cycles and offsets"); - writeBlock(gFormat.format(0), - gFormat.format(17), - gFormat.format(40), - gFormat.format(49), - gFormat.format(80), - gFormat.format(90)); - - // 6/21/21 | Gavin Williams | will1742 - // Probing now required. Using P9995. - // optionally cycle through all tools - var tools = getToolTable(); - - var writeFunction = getProperty("loadToolsAtStart") ? writeBlock : writeOptionalBlock; - - if (tools.getNumberOfTools() > 0) { - writeln(""); - /* - writeOptionalBlock(mFormat.format(0), formatComment(localize("Read note"))); // wait for operator - writeComment(localize("With BLOCK DELETE turned off each tool will cycle through")); - writeComment(localize("the spindle to verify that the correct tool is in the tool magazine")); - if (getProperty("optionallyMeasureToolsAtStart")) { - writeComment(localize("and to automatically measure it")); - } - writeComment(localize("Once the tools are verified turn BLOCK DELETE on to skip verification")); - */ - - // 6/21/21 | Gavin Williams | will1742 - writeComment("Load and probe tools"); - - // Display general tool probe info - displayMedia("toolProbeReminder.jpg", !getProperty("loadToolsAtStart")); - - let parsedTools = []; - - // Maybe should be anonymous function?? - function defaultFill() { - parsedTools = [] - for (var i = 0; i < tools.getNumberOfTools(); i++){ - parsedTools[i] = tools.getTool(i).number; - } - } - - // also maybe anonymous - // TODO: tool.getNumberOfTools needs to be machine-specific constant - function invalidToolNum(toolNum) { - return (toolNum < 1 || toolNum > MAX_TOOL_NUM); - } - - // parse string for specific tools to load - if (getProperty("toolsToLoad") != "") { - // get list of numbers - let toolNumArray = getProperty("toolsToLoad").split(','); - - // iterate through and fill ranges - for (var i = 0; i < toolNumArray.length; i++){ - toolNumArray[i] = toolNumArray[i].trim(); - - // fill range - if (toolNumArray[i].indexOf("-") >= 0) { - let numRange = toolNumArray[i].split("-"); - if (invalidToolNum(parseInt(numRange[0])) || invalidToolNum(parseInt(numRange[1]))) { - defaultFill(); - break; - } - for(var j = numRange[0]; j <= numRange[1]; j++){ - parsedTools.push(parseInt(j)); - } - continue; - } - // check if valid num - if (invalidToolNum(parseInt(toolNumArray[i]))) { - defaultFill(); - break; - } - // push single num - parsedTools.push(parseInt(toolNumArray[i])); - } - } else { - defaultFill(); - } - - for (var i = 0; i < tools.getNumberOfTools(); i++) { - var tool = tools.getTool(i); - if (tool.bodyLength + tool.holderLength > MAX_TOOL_LENGTH) { - throw "Error: T" + tool.number + " length greater than machine max" - } - - if (tool.diameter > MAX_TOOL_DIAM) { - throw "Error : T" + tool.number + " diameter greater than machine max" - } - - if (parsedTools.indexOf(tool.number) <= -1) { - continue; - } - - if (getProperty("measureToolsAtStart") && (tool.type == TOOL_PROBE)) { - continue; - } - - // 07/16/21 | will1742 | Gavin Williams - // Verify tool numbers - if (tool.number == 20 && tool.type != TOOL_PROBE) { - throw "Error: T20 is reserved for Probe"; - } - - if (tool.number == 19) { - throw "Error: T19 is reserved for WCS verification tool"; - } - - writeln(""); - 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"); - } - comment += " - " + getToolTypeName(tool.type); - writeComment(tool.description); - writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool - displayMedia("toolLoad" + tool.number + ".jpg", !getProperty("loadToolsAtStart"), "Load Tool " + tool.number); - writeToolMeasureBlock(tool, true); - } - } - - writeln(""); - writeComment("SETUP FOR OPERATION"); - writeFunction(mFormat.format(131)); - - if (staticProperties.useDWO) { - var failed = false; - var dynamicWCSs = {}; - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var description = section.hasParameter("operation-comment") ? section.getParameter("operation-comment") : ("#" + (i + 1)); - if (!section.hasDynamicWorkOffset()) { - error(subst(localize("Dynamic work offset has not been set for operation '%1'."), description)); - failed = true; - } - - var o = section.getDynamicWCSOrigin(); - var p = section.getDynamicWCSPlane(); - if (dynamicWCSs[section.getDynamicWorkOffset()]) { - if ((Vector.diff(o, dynamicWCSs[section.getDynamicWorkOffset()].origin).length > 1e-9) || - (Matrix.diff(p, dynamicWCSs[section.getDynamicWorkOffset()].plane).n1 > 1e-9)) { - error(subst(localize("Dynamic WCS mismatch for operation '%1'."), description)); - failed = true; - } - } else { - dynamicWCSs[section.getDynamicWorkOffset()] = {origin:o, plane:p}; - } - } - if (failed) { - return; - } - } - - if (false) { - // check for duplicate tool number - for (var i = 0; i < getNumberOfSections(); ++i) { - var sectioni = getSection(i); - var tooli = sectioni.getTool(); - for (var j = i + 1; j < getNumberOfSections(); ++j) { - var sectionj = getSection(j); - var toolj = sectionj.getTool(); - if (tooli.number == toolj.number) { - if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || - xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || - abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || - (tooli.numberOfFlutes != toolj.numberOfFlutes)) { - error( - subst( - localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), - sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), - sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) - ) - ); - return; - } - } - } - } - } - - if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { - for (var i = 0; i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset > 0) { - error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); - return; - } - } - } - - // absolute coordinates and feed per min - writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } - - coolantPressure = staticProperties.coolantPressure; - - if (staticProperties.chipTransport) { - onCommand(COMMAND_START_CHIP_TRANSPORT); - } - // Probing Surface Inspection - if (typeof inspectionWriteVariables == "function") { - inspectionWriteVariables(); - } -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -var lengthCompensationActive = false; -/** Disables length compensation if currently active or if forced. */ -function disableLengthCompensation(force, message) { - if (lengthCompensationActive || force) { - writeBlock(gFormat.format(49), conditional(message, formatComment(message))); - lengthCompensationActive = false; - } -} - -function writeG187() { - if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "drill")) { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } else if (hasParameter("operation:tolerance")) { - var tolerance = Math.max(getParameter("operation:tolerance"), 0); - if (tolerance > 0) { - var stockToLeaveThreshold = toUnit(0.1, MM); - var stockToLeave = 0; - var verticalStockToLeave = 0; - if (hasParameter("operation:stockToLeave")) { - stockToLeave = xyzFormat.getResultingValue(getParameter("operation:stockToLeave")); - } - if (hasParameter("operation:verticalStockToLeave")) { - verticalStockToLeave = xyzFormat.getResultingValue(getParameter("operation:verticalStockToLeave")); - } - - var workMode; - if (((stockToLeave > stockToLeaveThreshold) && (verticalStockToLeave > stockToLeaveThreshold)) || - (hasParameter("operation:strategy") && getParameter("operation:strategy") == "face")) { - workMode = 1; // roughing - } else { - if ((stockToLeave > 0) || (verticalStockToLeave > 0)) { - workMode = 2; // default - } else { - workMode = 3; // fine - } - } - writeBlock(gFormat.format(187), "P" + workMode); // set tolerance mode - // writeBlock(gFormat.format(187), "P" + workMode, "E" + xyzFormat.format(tolerance)); // set tolerance mode - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return "F#" + (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("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), getParameter("operation: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("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting") && - hasParameter("operation:tool_feedEntry") && - hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(getParameter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { - var feed; - if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { - feed = getParameter("operation:highFeedrate"); - } else { - feed = this.highFeedrate; - } - var feedContext = new FeedContext(id, localize("High Feed"), feed); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - activeMovements[MOVEMENT_RAPID] = feedContext; - } - ++id; - } - - for (var i = 0; i < activeFeeds.length; ++i) { - var feedContext = activeFeeds[i]; - writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description)); - } -} - -var currentWorkPlaneABC = undefined; -var activeG254 = false; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function defineWorkPlane(_section, _setWorkPlane) { - var abc = new Vector(0, 0, 0); - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (_section.isMultiAxis()) { - cancelTransformation(); - abc = _section.getInitialToolAxisABC(); - if (_setWorkPlane) { - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - if (!retracted) { - moveToSafeRetractPosition(); - } - forceWorkPlane(); - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - } - } else { - abc = getWorkPlaneMachineABC(_section.workPlane, _setWorkPlane); - if (_setWorkPlane) { - setWorkPlane(abc); - } - } - } else { // pure 3D - var remaining = _section.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - error(localize("Tool orientation is not supported.")); - return abc; - } - setRotation(remaining); - } - return abc; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - var _skipBlock = false; - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - if (operationNeedsSafeStart) { - _skipBlock = true; - } else { - return; // no change - } - } - skipBlock = _skipBlock; - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(false); - } - - if (activeG254) { - skipBlock = _skipBlock; - activeG254 = false; - writeBlock(gFormat.format(255)); // cancel DWO - } - - gMotionModal.reset(); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - - skipBlock = _skipBlock; - onCommand(COMMAND_LOCK_MULTI_AXIS); - - if (staticProperties.useDWO && - (abcFormat.isSignificant(abc.x % (Math.PI * 2)) || abcFormat.isSignificant(abc.y % (Math.PI * 2)) || abcFormat.isSignificant(abc.z % (Math.PI * 2)))) { - skipBlock = _skipBlock; - activeG254 = true; - writeBlock(gFormat.format(254)); // enable DWO - } - - setCurrentABC(abc); // required for machine simulation - currentWorkPlaneABC = abc; -} - -var closestABC = true; // choose closest machine angles -var currentMachineABC = new Vector(0, 0, 0); - -function getPreferenceWeight(_abc) { - var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); - var abc = new Array(_abc.x, _abc.y, _abc.z); - var preference = 0; - for (var i = 0; i < 3; ++i) { - if (axis[i].isEnabled()) { - preference += ((abcFormat.getResultingValue(abc[axis[i].getCoordinate()]) * axis[i].getPreference()) < 0) ? -1 : 1; - } - } - return preference; -} - -function remapToABC(currentABC, previousABC) { - var both = machineConfiguration.getABCByDirectionBoth(machineConfiguration.getDirection(currentABC)); - var abc1 = machineConfiguration.remapToABC(both[0], previousABC); - abc1 = machineConfiguration.remapABC(abc1); - var abc2 = machineConfiguration.remapToABC(both[1], previousABC); - abc2 = machineConfiguration.remapABC(abc2); - - // choose angles based on preference - var preference1 = getPreferenceWeight(abc1); - var preference2 = getPreferenceWeight(abc2); - if (preference1 > preference2) { - return abc1; - } else if (preference2 > preference1) { - return abc2; - } - - // choose angles based on closest solution - if (Vector.diff(abc1, previousABC).length < Vector.diff(abc2, previousABC).length) { - return abc1; - } else { - return abc2; - } -} - -function getWorkPlaneMachineABC(workPlane, _setWorkPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - if (_setWorkPlane) { - currentMachineABC = abc; - } - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - 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" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function printProbeResults() { - return currentSection.getParameter("printResults", 0) == 1; -} - -function onPassThrough(text) { - var commands = String(text).split(","); - for (text in commands) { - writeBlock(commands[text]); - } -} - -function onManualNC(command, value) { - switch (command) { - case COMMAND_ACTION: - if (String(value).toUpperCase() == "CYCLE_REVERSAL") { - cycleReverse = true; - } else if (String(value).toUpperCase() == "VFD_LOW") { - coolantPressure = "P0"; - } else if (String(value).toUpperCase() == "VFD_NORMAL") { - coolantPressure = "P1"; - } else if (String(value).toUpperCase() == "VFD_HIGH") { - coolantPressure = "P2"; - } else if (String(value).toUpperCase() == "USEPOLARMODE") { - usePolarMode = true; - } - break; - default: - expandManualNC(command, value); - } -} - -var probeOutputWorkOffset = 1; -var stockTopZ = -1; -var stockUpperX; -var stockLowerX; -var stockUpperY; -var stockLowerY; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } - - // Added 6/15/21 | Gavin Williams | will1742 - // Issue 001 Input and Validation - if (name == "stock-upper-z") { - stockTopZ = value; - } - if (name == "stock-upper-x") { - stockUpperX = value; - } - if (name == "stock-lower-x") { - stockLowerX = value; - } - if (name == "stock-upper-y") { - stockUpperY = value; - } - if (name == "stock-lower-y") { - stockLowerY = value; - } -} - -var seenPatternIds = {}; - -function previewImage() { - var permittedExtensions = ["JPG", "MP4", "MOV", "PNG", "JPEG"]; - var patternId = currentSection.getPatternId(); - var show = false; - if (!seenPatternIds[patternId]) { - show = true; - seenPatternIds[patternId] = true; - } - var images = []; - if (show) { - if (FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath))) { - images.push(modelImagePath); - } - if (hasParameter("autodeskcam:preview-name") && FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), getParameter("autodeskcam:preview-name")))) { - images.push(getParameter("autodeskcam:preview-name")); - } - - for (var i = 0; i < images.length; ++i) { - var fileExtension = images[i].slice(images[i].lastIndexOf(".") + 1, images[i].length).toUpperCase(); - var permittedExtension = false; - for (var j = 0; j < permittedExtensions.length; ++j) { - if (fileExtension == permittedExtensions[j]) { - permittedExtension = true; - break; // found - } - } - if (!permittedExtension) { - warning(localize("The image file format " + "\"" + fileExtension + "\"" + " is not supported on HAAS controls.")); - } - - if (!staticProperties.useM130PartImages || !permittedExtension) { - FileSystem.remove(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), images[i])); // remove - images.splice([i], 1); // remove from array - } - } - if (images.length > 0) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(" + images[images.length - 1] + ")") - : - writeOptionalBlock(mFormat.format(130), "(" + images[images.length - 1] + ")"); - } - } -} - -/** Returns true if the spatial vectors are significantly different. */ -function areSpatialVectorsDifferent(_vector1, _vector2) { - return (xyzFormat.getResultingValue(_vector1.x) != xyzFormat.getResultingValue(_vector2.x)) || - (xyzFormat.getResultingValue(_vector1.y) != xyzFormat.getResultingValue(_vector2.y)) || - (xyzFormat.getResultingValue(_vector1.z) != xyzFormat.getResultingValue(_vector2.z)); -} - -/** Returns true if the spatial boxes are a pure translation. */ -function areSpatialBoxesTranslated(_box1, _box2) { - return !areSpatialVectorsDifferent(Vector.diff(_box1[1], _box1[0]), Vector.diff(_box2[1], _box2[0])) && - !areSpatialVectorsDifferent(Vector.diff(_box2[0], _box1[0]), Vector.diff(_box2[1], _box1[1])); -} - -/** Returns true if the spatial boxes are same. */ -function areSpatialBoxesSame(_box1, _box2) { - return !areSpatialVectorsDifferent(_box1[0], _box2[0]) && !areSpatialVectorsDifferent(_box1[1], _box2[1]); -} - -function subprogramDefine(_initialPosition, _abc, _retracted, _zIsOutput) { - // convert patterns into subprograms - var usePattern = false; - patternIsActive = false; - if (currentSection.isPatterned && currentSection.isPatterned() && (getProperty("useSubroutines") == "patterns")) { - currentPattern = currentSection.getPatternId(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_PATTERN) && (currentPattern == definedPatterns[i].patternId)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_PATTERN); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_PATTERN, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: _initialPosition - }); - } - - if (usePattern) { - // make sure Z-position is output prior to subprogram call - if (!_retracted && !_zIsOutput) { - writeBlock(gMotionModal.format(0), zOutput.format(_initialPosition.z)); - } - - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - patternIsActive = true; - - if (firstPattern) { - subprogramStart(_initialPosition, _abc, incrementalSubprogram); - } else { - skipRemainingSection(); - setCurrentPosition(getFramePosition(currentSection.getFinalPosition())); - } - } - } - - // Output cycle operation as subprogram - if (!usePattern && (getProperty("useSubroutines") == "cycles") && currentSection.doesStrictCycle && - (currentSection.getNumberOfCycles() == 1) && currentSection.getNumberOfCyclePoints() >= minimumCyclePoints) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - currentPattern = currentSection.getNumberOfCyclePoints(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_CYCLE) && (currentPattern == definedPatterns[i].patternId) && - !areSpatialVectorsDifferent(_initialPosition, definedPatterns[i].initialPosition) && - !areSpatialVectorsDifferent(finalPosition, definedPatterns[i].finalPosition)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_CYCLE); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_CYCLE, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: finalPosition - }); - } - cycleSubprogramIsActive = usePattern; - } - - // Output each operation as a subprogram - if (!usePattern && (getProperty("useSubroutines") == "allOperations")) { - currentSubprogram = ++lastSubprogram; - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - firstPattern = true; - subprogramStart(_initialPosition, _abc, false); - } -} - -function subprogramStart(_initialPosition, _abc, _incremental) { - redirectToBuffer(); - var comment = ""; - if (hasParameter("operation-comment")) { - comment = getParameter("operation-comment"); - } - writeln( - "N" + nFormat.format(currentSubprogram) + - conditional(comment, formatComment(comment.substr(0, maximumLineLength - 2 - 6 - 1))) - ); - staticProperties.showSequenceNumbers = false; - if (_incremental) { - setIncrementalMode(_initialPosition, _abc); - } - gPlaneModal.reset(); - gMotionModal.reset(); -} - -function subprogramEnd() { - if (firstPattern) { - writeBlock(mFormat.format(99)); - writeln(""); - subprograms += getRedirectionBuffer(); - } - forceAny(); - firstPattern = false; - staticProperties.showSequenceNumbers = saveShowSequenceNumbers; - closeRedirection(); -} - -function subprogramIsValid(_section, _patternId, _patternType) { - var sectionId = _section.getId(); - var numberOfSections = getNumberOfSections(); - var validSubprogram = _patternType != SUB_CYCLE; - - var masterPosition = new Array(); - masterPosition[0] = getFramePosition(_section.getInitialPosition()); - masterPosition[1] = getFramePosition(_section.getFinalPosition()); - var tempBox = _section.getBoundingBox(); - var masterBox = new Array(); - masterBox[0] = getFramePosition(tempBox[0]); - masterBox[1] = getFramePosition(tempBox[1]); - - var rotation = getRotation(); - var translation = getTranslation(); - incrementalSubprogram = undefined; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (section.getId() != sectionId) { - defineWorkPlane(section, false); - // check for valid pattern - if (_patternType == SUB_PATTERN) { - if (section.getPatternId() == _patternId) { - var patternPosition = new Array(); - patternPosition[0] = getFramePosition(section.getInitialPosition()); - patternPosition[1] = getFramePosition(section.getFinalPosition()); - tempBox = section.getBoundingBox(); - var patternBox = new Array(); - patternBox[0] = getFramePosition(tempBox[0]); - patternBox[1] = getFramePosition(tempBox[1]); - - if (areSpatialBoxesSame(masterPosition, patternPosition) && areSpatialBoxesSame(masterBox, patternBox) && !section.isMultiAxis()) { - incrementalSubprogram = incrementalSubprogram ? incrementalSubprogram : false; - } else if (!areSpatialBoxesTranslated(masterPosition, patternPosition) || !areSpatialBoxesTranslated(masterBox, patternBox)) { - validSubprogram = false; - break; - } else { - incrementalSubprogram = true; - } - } - - // check for valid cycle operation - } else if (_patternType == SUB_CYCLE) { - if ((section.getNumberOfCyclePoints() == _patternId) && (section.getNumberOfCycles() == 1)) { - var patternInitial = getFramePosition(section.getInitialPosition()); - var patternFinal = getFramePosition(section.getFinalPosition()); - if (!areSpatialVectorsDifferent(patternInitial, masterPosition[0]) && !areSpatialVectorsDifferent(patternFinal, masterPosition[1])) { - validSubprogram = true; - break; - } - } - } - } - } - setRotation(rotation); - setTranslation(translation); - return (validSubprogram); -} - -function setAxisMode(_format, _output, _prefix, _value, _incr) { - var i = _output.isEnabled(); - if (_output == zOutput) { - _output = _incr ? createIncrementalVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format) : createVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format); - } else { - _output = _incr ? createIncrementalVariable({prefix: _prefix}, _format) : createVariable({prefix: _prefix}, _format); - } - _output.format(_value); - _output.format(_value); - i = i ? _output.enable() : _output.disable(); - return _output; -} - -function setIncrementalMode(xyz, abc) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, true); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, true); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, true); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, true); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, true); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, true); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(91)); - incrementalMode = true; -} - -function setAbsoluteMode(xyz, abc) { - if (incrementalMode) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, false); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, false); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, false); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, false); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, false); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, false); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(90)); - incrementalMode = false; - } -} - -function onSection() { - if (isFirstSection()) { - writeln(""); - writeComment("STOCK PREP"); - var Stock_X_55 = (stockUpperX + stockLowerX)/2; - // TODO: Tolerance Checks - // writeln(macroFormat.format(100) + "=[" + macroFormat.format(5241) + "+" + xyzFormat.format(Stock_X_55) + "]"); - // writeWords("IF [" + macroFormat.format(100) + " GT 0.] THEN " + macroFormat.format(100) + "=0."); - // writeWords("IF [" + macroFormat.format(100) + " LT " + (X_TRAVEL_LIMIT*-1) + "." + "] THEN " + macroFormat.format(100) + "=" + (X_TRAVEL_LIMIT*-1) + "."); - // writeBlock(gFormat.format(53), "X" + macroFormat.format(100), yOutput.format(0)); - writeBlock(gFormat.format(55), gFormat.format(0), xOutput.format(Stock_X_55)); - writeBlock(gFormat.format(53), gFormat.format(0), yOutput.format(0)); - displayMedia("loadStock.jpg", false); - } - - - // 07/06/21 | Gavin Williams | will1742 - // 002 Improved Probing - // uses pencil to verify WCS, prompts user - if (isFirstSection() && getProperty("pencilWCSValidation")) { - var stockMidX = (stockUpperX + stockLowerX)/2; - var stockMidY = (stockUpperY + stockLowerY)/2; - writeln(""); - writeComment("VERIFY WCS"); - writeBlock("T" + toolFormat.format(19), mFormat.format(6)); //Changes Tool - - writeBlock(gFormat.format(55), gFormat.format(0), forceX.format(stockMidX), forceY.format(stockMidY)); - if (staticProperties.hasAAxis != "false" && staticProperties.hasCAxis != "false") { - writeBlock(gFormat.format(0), aOutput.format(0), cOutput.format(0)); - } else if (staticProperties.hasAAxis != "false") { - writeBlock(gFormat.format(0), aOutput.format(0)); - } - displayMedia("xyWCSCheck.jpg", false, "Open door and check x-y position"); - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - var gotoRef = takeInput("Is the pencil centered above your stock? stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - writeBlock(gFormat.format(55), gFormat.format(43), hFormat.format(19), zOutput.format(stockTopZ)); - displayMedia("zWCSCheck.jpg", false, "Open door and check z position"); - - /* - displayMedia("Net Share/Media/checkPrompt.jpg"); - gotoRef = takeInput("Is the pencil touching the center of your stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - */ - } - - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - retracted = false; - - var zIsOutput = false; // true if the Z-position has been output, used for patterns - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || - (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || - getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations - - operationNeedsSafeStart = staticProperties.safeStartAllOperations && !isFirstSection(); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.fastToolChange && !isProbeOperation()) { - currentCoolantMode = COOLANT_OFF; - } else if (insertToolCall) { // no coolant off command if safe start operation - onCommand(COMMAND_COOLANT_OFF); - } - } - - if ((insertToolCall && !staticProperties.fastToolChange) || newWorkOffset || newWorkPlane || toolChecked) { - - // stop spindle before retract during tool change - if (insertToolCall && !isFirstSection() && !toolChecked && !staticProperties.fastToolChange) { - onCommand(COMMAND_STOP_SPINDLE); - } - - // retract to safe plane - writeRetract(Z); - - if (forceResetWorkPlane && newWorkPlane) { - forceWorkPlane(); - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - } - } - - if (!isFirstSection() && getProperty("toolLengthValidation")) { - displayMedia("checkPartTool.jpg", false, "Check Part and Tool"); - } else if (!isFirstSection()) { - writeBlock(mFormat.format(1)); - writeComment("Check Part and Tool"); - } - - if (hasParameter("operation-comment")) { - var comment = getParameter("operation-comment"); - if (comment && ((comment !== lastOperationComment) || !patternIsActive || insertToolCall)) { - writeln(""); - writeComment(comment); - lastOperationComment = comment; - } else if (!patternIsActive || insertToolCall) { - writeln(""); - } - } else { - writeln(""); - } - - if (hasParameter("notes") && getParameter("notes").toUpperCase().indexOf("APPROVED") <= -1) { - // throw "Operation \"" + getParameter("operation-comment") + "\" not approved. See a Peer Mentor." - } - - if (staticProperties.showNotes) { - var notes = getParameter("notes"); - writeComment("PEER MENTOR 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); - } - } - } - } - - // enable polar interpolation - if (usePolarMode && (tool.type != TOOL_PROBE)) { - if (polarDirection == undefined) { - error(localize("Polar direction property must be a vector - x,y,z.")); - return; - } - setPolarMode(currentSection, true); - } - - defineWorkPlane(currentSection, false); - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - forceAny(); - - if (operationNeedsSafeStart) { - if (!retracted) { - // skipBlock = true; - writeRetract(Z); - } - } - - if (insertToolCall || operationNeedsSafeStart) { - - if (staticProperties.useM130PartImages) { - getProperty("displayMediaCalls") ? - writeBlock(mFormat.format(130), "(tool" + tool.number + ".png)") - : - writeOptionalBlock(mFormat.format(130), "(tool" + tool.number + ".png)"); - } - - if (!isFirstSection() && staticProperties.optionalStop && insertToolCall) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if ((tool.number > 200 && tool.number < 1000) || tool.number > 9999) { - warning(localize("Tool number out of range.")); - } - - skipBlock = !insertToolCall; - writeToolBlock( - "T" + toolFormat.format(tool.number), - mFormat.format(6) - ); - if (tool.comment) { - writeComment(tool.comment); - } - if (measureTool) { - writeToolMeasureBlock(tool, false); - } - if (insertToolCall) { - forceWorkPlane(); - } - 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") + "=" + xyzFormat.format(zRange.getMinimum())); - } - } - } - - // activate those two coolant modes before the spindle is turned on - if ((tool.coolant == COOLANT_THROUGH_TOOL) || (tool.coolant == COOLANT_AIR_THROUGH_TOOL) || (tool.coolant == COOLANT_FLOOD_THROUGH_TOOL)) { - if (!isFirstSection() && !insertToolCall && (currentCoolantMode != tool.coolant)) { - onCommand(COMMAND_STOP_SPINDLE); - forceSpindleSpeed = true; - } - // setCoolant(tool.coolant); - } else if ((currentCoolantMode == COOLANT_THROUGH_TOOL) || (currentCoolantMode == COOLANT_AIR_THROUGH_TOOL) || (currentCoolantMode == COOLANT_FLOOD_THROUGH_TOOL)) { - onCommand(COMMAND_STOP_SPINDLE); - setCoolant(COOLANT_OFF); - forceSpindleSpeed = true; - } - - if (toolChecked) { - forceSpindleSpeed = true; // spindle must be restarted if tool is checked without a tool change - toolChecked = false; // state of tool is not known at the beginning of a section since it could be broken for the previous section - } - var spindleChanged = tool.type != TOOL_PROBE && - (insertToolCall || forceSpindleSpeed || isFirstSection() || - (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)); - if (spindleChanged || (operationNeedsSafeStart && tool.type != TOOL_PROBE)) { - forceSpindleSpeed = false; - - if (spindleSpeed < 1) { - error(localize("Spindle speed out of range.")); - return; - } - maximumSpindleRPM = machineConfiguration.getMaximumSpindleSpeed() > 0 ? machineConfiguration.getMaximumSpindleSpeed() : maximumSpindleRPM; - if (spindleSpeed > maximumSpindleRPM) { - warning(subst(localize("Spindle speed '" + spindleSpeed + " RPM' exceeds maximum value of '%1 RPM."), maximumSpindleRPM)); - } - // skipBlock = !spindleChanged; - writeBlock( - sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) - ); - } - - previewImage(); - - if (staticProperties.useParametricFeed && - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill") && // legacy - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(); - } - } else { - activeMovements = undefined; - } - - // wcs - if (insertToolCall || operationNeedsSafeStart) { // force work offset when changing tool - currentWorkOffset = undefined; - skipBlock = operationNeedsSafeStart && !newWorkOffset && !insertToolCall; - } - 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 > 6) { - var code = workOffset - 6; - if (code > 99) { - error(localize("Work offset out of range.")); - return; - } - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(154), "P" + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - if (newWorkPlane || (insertToolCall && !retracted)) { // go to home position for safety - if (!retracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing && machineConfiguration.isMultiAxisConfiguration()) { - writeRetract(X, Y); - } - } - - // Unwind axis if previous section was Multi-Axis - if (!isFirstSection() && (getPreviousSection().isMultiAxis() || usePolarMode) && machineConfiguration.isMachineCoordinate(2)) { // TAG - if (!retracted) { - moveToSafeRetractPosition(); - } - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - currentMachineABC.setZ(0); - } - - if (newWorkOffset) { - forceWorkPlane(); - } - - var abc = defineWorkPlane(currentSection, true); - - setProbeAngle(); // output probe angle rotations if required - - gMotionModal.reset(); - - if (staticProperties.useG187) { - writeG187(); - } - - var G = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? 1 : 0; - var F = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? getFeed(toPreciseUnit(highFeedrate, MM)) : ""; - if (insertToolCall || retracted || operationNeedsSafeStart || !lengthCompensationActive || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))) { - var _skipBlock = !(insertToolCall || retracted || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))); - var lengthOffset = tool.lengthOffset; - if ((lengthOffset > 200 && lengthOffset < 1000) || lengthOffset > 9999) { - error(localize("Length offset out of range.")); - return; - } - - gMotionModal.reset(); - writeBlock(gPlaneModal.format(17)); - - if (usePolarMode) { - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(); - } - var polarPosition = getPolarPosition(initialPosition.x, initialPosition.y, initialPosition.z); - setCurrentPositionAndDirection(polarPosition); - initialPosition = new Vector(polarPosition.first.x, polarPosition.first.y, polarPosition.first.z); - writeBlock(gMotionModal.format(0), aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - } - - if (!machineConfiguration.isHeadConfiguration()) { - if (tcpIsSupported && useDwoForPositioning && currentSection.isMultiAxis()) { - var O = machineConfiguration.getOrientation(abc); - var initialPositionDWO = O.getTransposed().multiply(getGlobalPosition(currentSection.getInitialPosition())); - // writeComment("PREPOSITIONING START"); - skipBlock = _skipBlock; - writeBlock(gFormat.format(254)); - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPositionDWO.x), yOutput.format(initialPositionDWO.y), F); - skipBlock = _skipBlock; - writeBlock(gFormat.format(255)); - // writeComment("PREPOSITIONING END"); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), // G0 motion mode is required for the G234 command - gFormat.format(234), - xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } else { - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), F); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } - } else { - skipBlock = _skipBlock; - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(currentSection.isMultiAxis() && tcpIsSupported ? 0 : G), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y), - zOutput.format(initialPosition.z), - F, - hFormat.format(lengthOffset) - ); - } - zIsOutput = true; - lengthCompensationActive = true; - if (_skipBlock) { - forceXYZ(); - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - } else { - validate(lengthCompensationActive, "Length compensation is not active."); - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - zIsOutput = true; - } - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - if (gMotionModal.getCurrent() == 0) { - forceFeed(); - } - gMotionModal.reset(); - validate(lengthCompensationActive, "Length compensation is not active."); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.preloadTool) { - var nextTool = getNextTool(tool.number); - if (nextTool) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(nextTool.number)); - } else { - // preload first tool - var section = getSection(0); - var firstToolNumber = section.getTool().number; - if (tool.number != firstToolNumber) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(firstToolNumber)); - } - } - } - } - - if (isProbeOperation()) { - validate(probeVariables.probeAngleMethod != "G68", "You cannot probe while G68 Rotation is in effect."); - validate(probeVariables.probeAngleMethod != "G54.4", "You cannot probe while workpiece setting error compensation G54.4 is enabled."); - writeBlock(gFormat.format(65), "P" + 9832); // spin the probe on - inspectionCreateResultsFileHeader(); - } else { - // surface Inspection - if (isInspectionOperation() && (typeof inspectionProcessSectionStart == "function")) { - inspectionProcessSectionStart(); - } - } - - if (getProperty("toolLengthValidation")) { - writeComment("TOOL VALIDATION"); - // Added 06/15/21 | Gavin Williams | will1742 - // Verifies tool-stock distance. Post fails if tool fails clearance standards - if (toolDistance < CLEARANCE_HEIGHT) { - throw "Error: Clearance height must be " + CLEARANCE_HEIGHT + " or more inches from stock"; - } - - if (toolDistance == Infinity) { - throw "Error: invalid tool distance. Contact a TA."; - } - var toolDistance = initialPosition.z - stockTopZ; - - // Prompt user to check stock-tool distance - displayMedia("checkDistance" + toolDistance.toPrecision(2).toString().replace(".", "_") + ".jpg", false, "Check distance: " + toolDistance.toPrecision(2).toString() +"in"); - writeComment("OPEN DOOR"); - //displayMedia("Net Share/Media/checkPrompt.jpg"); - - // asks user if measured height is accurate to displayed - //var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['N', 'Y']); - - // Create GOTO cases for Y/N selection, halt if N - /* - getTA("Net Share/Media/TAWarning.jpg", gotoRef['N'], onSecGotoRef); - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - writeWords( - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - */ - - // initialize spindle and engage coolant if heights are correct - if (tool.type != TOOL_PROBE) { - writeBlock(mFormat.format((tool.clockwise ? 3 : 4))); - } - } - - if (tool.type != TOOL_PROBE) { - setCoolant(tool.coolant); - writeBlock(gFormat.format(4), "P500"); - } - - writeComment("BEGIN OPERATION"); - // define subprogram - subprogramDefine(initialPosition, abc, retracted, zIsOutput); -} - -// Added 9/30/21 | Kevin Pan | pan261 -// Issue 001 Input and Validation, Issue 029 -// Displays a file: MP4, MOV, PNG, JPEG. 1920x1080 or comments if displayeMediaCalls is false -// Input: Absolute path to file, optional calls, comment to write with m0 -function displayMedia(file, isOptional, comment) { - var writeFunction = isOptional ? writeOptionalBlock : writeBlock; - - if (!getProperty("displayMediaCalls")) { - writeFunction(mFormat.format(0)); - comment ? - writeComment(comment) - : - null; - return; - } else { - writeFunction(mFormat.format(130), formatComment("Net Share/Media/" + file)); - comment ? - writeFunction(mFormat.format(0), formatComment(comment)) - : - writeFunction(mFormat.format(0)); - writeFunction(mFormat.format(131)); - } -} - -// Added 6/14/21 | Gavin Williams | will1742 -// Issue 001 Input and Validation -// Takes input from the user -// Input: string prompt, will be displayed to users -// char array options, capital letters accepted as input -// int opSeqNum, optional arg to init prompt at specific value -// Output: 2D dict {Letter, Coorresponding GOTO} -// EX: [Y, 56][N, 57] -var macroNumber = 500; -function takeInput(prompt, options) { - - // Cycle through macro variables, reset at end of general purpose vars - if (macroNumber > 549) macroNumber = 500; - - // init macro var to 0 - setMacro(macroNumber, 0, "Initialize macro variable", false); - - // disply prompt and save response - writeBlock(mFormat.format(109), "P" + nFormat.format(macroNumber), formatComment(prompt)); - sequenceNumber -= staticProperties.sequenceNumberIncrement; - var gotoRef = sequenceNumber; - - // wait for input - writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + nFormat.format(gotoRef) + " " + formatComment("NULL")); - - // print if's and goto's - var gotoMap = {}; - var gotoInc = 1; - options.forEach(function (element) { - writeWords("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc), formatComment(element)); - gotoMap[element] = (sequenceNumber + gotoInc); - gotoInc += 1; - }); - - var incNum = staticProperties.sequenceNumberIncrement; - // adjust sequence number if needed - for (i = incNum; i < gotoInc; i+=incNum) { - sequenceNumber += staticProperties.sequenceNumberIncrement; - } - - // return to input until valid option is entered - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("INVALID INPUT")); - - // increase var number, iterate sequence number - macroNumber += 1; - sequenceNumber += staticProperties.sequenceNumberIncrement; - return gotoMap; -} - -// Added 06/15/21 | Gavin Williamas | will1742 -// Issue 001 Input and validation -// Halts program until TA arrives. Jumps to gotoRef -function getTA(file, seqNum, gotoRef) { - writeWords("N" + nFormat.format(seqNum), - gFormat.format(53), gFormat.format(0), zOutput.format(0.), - formatComment("Retract spindle")); - writeWords(mFormat.format(130), formatComment(file)); - writeWords(mFormat.format(0), formatComment("Halt Program")); - writeWords(mFormat.format(131)); - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("Return to beginning of operation")); -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - seconds = clamp(0.001, seconds, 99999.999); - writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + milliFormat.format(seconds * 1000)); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(sOutput.format(spindleSpeed)); -} - -function onCycle() { - writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r, c) { - forceXYZ(); - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - return [xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), - zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), - bOutput.format(polarPosition.second.y), - cOutput.format(polarPosition.second.z), - "R" + xyzFormat.format(r)]; - } else { - if (incrementalMode) { - zOutput.format(c); - return [xOutput.format(x), yOutput.format(y), - "Z" + xyzFormat.format(z - r), - "R" + xyzFormat.format(r - c)]; - } else { - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; - } - } -} - -function setCyclePosition(_position) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - zOutput.format(_position); - break; - case 18: // ZX - yOutput.format(_position); - break; - case 19: // YZ - xOutput.format(_position); - break; - } -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function setProbeAngleMethod() { - probeVariables.probeAngleMethod = (machineConfiguration.getNumberOfAxes() < 5 || is3D()) ? (getProperty("useG54x4") ? "G54.4" : "G68") : "UNSUPPORTED"; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i = 0; i < axes.length; ++i) { - if (axes[i].isEnabled() && isSameDirection((axes[i].getAxis()).getAbsolute(), new Vector(0, 0, 1)) && axes[i].isTable()) { - probeVariables.probeAngleMethod = "AXIS_ROT"; - probeVariables.rotationalAxis = axes[i].getCoordinate(); - break; - } - } - probeVariables.outputRotationCodes = true; -} - -/** Output rotation offset based on angular probing cycle. */ -function setProbeAngle() { - if (probeVariables.outputRotationCodes) { - validate(probeOutputWorkOffset <= 6, "Angular Probing only supports work offsets 1-6."); - if (probeVariables.probeAngleMethod == "G68" && (Vector.diff(currentSection.getGlobalInitialToolAxis(), new Vector(0, 0, 1)).length > 1e-4)) { - error(localize("You cannot use multi axis toolpaths while G68 Rotation is in effect.")); - } - var validateWorkOffset = false; - switch (probeVariables.probeAngleMethod) { - case "G54.4": - var param = 26000 + (probeOutputWorkOffset * 10); - writeBlock("#" + param + "=#135"); - writeBlock("#" + (param + 1) + "=#136"); - writeBlock("#" + (param + 5) + "=#144"); - writeBlock(gFormat.format(54.4), "P" + probeOutputWorkOffset); - break; - case "G68": - gRotationModal.reset(); - gAbsIncModal.reset(); - writeBlock(gRotationModal.format(68), gAbsIncModal.format(90), probeVariables.compensationXY, "R[#194]"); - validateWorkOffset = true; - break; - case "AXIS_ROT": - var param = 5200 + probeOutputWorkOffset * 20 + probeVariables.rotationalAxis + 4; - writeBlock("#" + param + " = " + "[#" + param + " + #194]"); - forceWorkPlane(); // force workplane to rotate ABC in order to apply rotation offsets - currentWorkOffset = undefined; // force WCS output to make use of updated parameters - validateWorkOffset = true; - break; - default: - error(localize("Angular Probing is not supported for this machine configuration.")); - return; - } - if (validateWorkOffset) { - for (var i = currentSection.getId(); i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset != currentSection.workOffset) { - error(localize("WCS offset cannot change while using angle rotation compensation.")); - return; - } - } - } - probeVariables.outputRotationCodes = false; - } -} - -function protectedProbeMove(_cycle, x, y, z) { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - var _z = zOutput.format(z); - if (_z && z >= getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } - if (_x || _y) { - writeBlock(gFormat.format(65), "P" + 9810, _x, _y, getFeed(highFeedrate)); // protected positioning move - } - if (_z && z < getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } -} - -function cancelG68Rotation(force) { - if (force) { - gRotationModal.reset(); - } - writeBlock(gRotationModal.format(69)); -} - -function onCyclePoint(x, y, z) { - if (isInspectionOperation() && (typeof inspectionCycleInspect == "function")) { - inspectionCycleInspect(cycle, x, y, z); - return; - } - if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { - expandCyclePoint(x, y, z); - return; - } - if (isProbeOperation()) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { - if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } else if (staticProperties.useDWO) { - error(localize("Your machine does not support the selected probing operation with DWO enabled.")); - return; - } - } - if (printProbeResults()) { - writeProbingToolpathInformation(z - cycle.depth + tool.diameter / 2); - inspectionWriteCADTransform(); - inspectionWriteWorkplaneTransform(); - if (typeof inspectionWriteVariables == "function") { - inspectionVariables.pointNumber += 1; - } - } - protectedProbeMove(cycle, x, y, z); - } - - var forceCycle = false; - switch (cycleType) { - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceCycle = true; - if (!isFirstCyclePoint()) { - writeBlock(gCycleModal.format(80)); - gMotionModal.reset(); - } - } - if (forceCycle || isFirstCyclePoint() || isProbeOperation()) { - if (!isProbeOperation()) { - // return to initial Z which is clearance plane and set absolute mode - repositionToCycleClearance(cycle, x, y, z); - } - - var F = cycle.feedrate; - var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "chip-breaking": - if ((cycle.accumulatedDepth < cycle.depth) && (cycle.incrementalDepthReduction > 0)) { - expandCyclePoint(x, y, z); - } else if (cycle.accumulatedDepth < cycle.depth) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - ("Q" + xyzFormat.format(cycle.incrementalDepth)), - ("K" + xyzFormat.format(cycle.accumulatedDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "deep-drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "left-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "right-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - // Parameter 57 bit 6, REPT RIG TAP, is set to 1 (On) - // On Mill software versions12.09 and above, REPT RIG TAP has been moved from the Parameters to Setting 133 - var u = cycle.stock; - var step = cycle.incrementalDepth; - var first = true; - while (u > cycle.bottom) { - if (step < cycle.minimumIncrementalDepth) { - step = cycle.minimumIncrementalDepth; - } - - u -= step; - step -= cycle.incrementalDepthReduction; - gCycleModal.reset(); // required - if ((u - 0.001) <= cycle.bottom) { - u = cycle.bottom; - } - if (first) { - first = false; - writeBlock( - gRetractModal.format(99), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), - getCommonCycle((gPlaneModal.getCurrent() == 19) ? u : x, (gPlaneModal.getCurrent() == 18) ? u : y, (gPlaneModal.getCurrent() == 17) ? u : z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - } else { - var position; - var depth; - switch (gPlaneModal.getCurrent()) { - case 17: - xOutput.reset(); - position = xOutput.format(x); - depth = "Z" + xyzFormat.format(u); - break; - case 18: - zOutput.reset(); - position = zOutput.format(z); - depth = "Y" + xyzFormat.format(u); - break; - case 19: - yOutput.reset(); - position = yOutput.format(y); - depth = "X" + xyzFormat.format(u); - break; - } - writeBlock(conditional(u <= cycle.bottom, gRetractModal.format(98)), position, depth); - } - } - forceFeed(); - break; - case "fine-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - break; - case "back-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; - var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; - var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; - writeBlock( - gRetractModal.format(98), gCycleModal.format(77), - getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom, cycle.clearance), - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "reaming": - writeBlock( - gRetractModal.format(98), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - - case "probing-x": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-y": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-z": - protectedProbeMove(cycle, x, y, Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock( - gFormat.format(65), "P" + 9811, - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "Z" + xyzFormat.format(z - cycle.depth), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "Z" + xyzFormat.format(z - cycle.depth), - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-inner-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9815, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-outer-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9816, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 90), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-y-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 0), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-xy-pcd-hole": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "K" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - case "probing-xy-pcd-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - default: - expandCyclePoint(x, y, z); - } - - // place cycle operation in subprogram - if (cycleSubprogramIsActive) { - if (forceCycle || cycleExpanded || isProbeOperation()) { - cycleSubprogramIsActive = false; - } else { - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - subprogramStart(new Vector(x, y, z), new Vector(0, 0, 0), false); - } - } - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - - // 2nd through nth cycle point - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - writeBlock(xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - return; - } - var _x; - var _y; - var _z; - if (!xyzFormat.areDifferent(x, xOutput.getCurrent()) && - !xyzFormat.areDifferent(y, yOutput.getCurrent()) && - !xyzFormat.areDifferent(z, zOutput.getCurrent())) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - xOutput.reset(); // at least one axis is required - break; - case 18: // ZX - zOutput.reset(); // at least one axis is required - break; - case 19: // YZ - yOutput.reset(); // at least one axis is required - break; - } - } - if (incrementalMode) { // set current position to retract height - setCyclePosition(cycle.retract); - } - writeBlock(xOutput.format(x), yOutput.format(y), zOutput.format(z)); - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - } - } -} - -function getProbingArguments(cycle, updateWCS) { - var outputWCSCode = updateWCS && currentSection.strategy == "probe"; - if (outputWCSCode) { - validate(probeOutputWorkOffset <= 99, "Work offset is out of range."); - var nextWorkOffset = hasNextSection() ? getNextSection().workOffset == 0 ? 1 : getNextSection().workOffset : -1; - if (probeOutputWorkOffset == nextWorkOffset) { - currentWorkOffset = undefined; - } - } - return [ - (cycle.angleAskewAction == "stop-message" ? "B" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), - ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "F" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), - (cycle.wrongSizeAction == "stop-message" ? "H" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), - (cycle.outOfPositionAction == "stop-message" ? "M" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), - ((cycle.updateToolWear && cycleType == "probing-z") ? "T" + xyzFormat.format(cycle.toolLengthOffset) : undefined), - ((cycle.updateToolWear && cycleType !== "probing-z") ? "T" + xyzFormat.format(cycle.toolDiameterOffset) : undefined), - (cycle.updateToolWear ? "V" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), - (cycle.printResults ? "W" + xyzFormat.format(1 + cycle.incrementComponent) : undefined), // 1 for advance feature, 2 for reset feature count and advance component number. first reported result in a program should use W2. - conditional(outputWCSCode, "S" + probeWCSFormat.format(probeOutputWorkOffset > 6 ? (0.01 * (probeOutputWorkOffset - 6) + 154) : probeOutputWorkOffset)) - ]; -} - -function onCycleEnd() { - if (isProbeOperation()) { - zOutput.reset(); - gMotionModal.reset(); - writeBlock(gFormat.format(65), "P" + 9810, zOutput.format(cycle.retract)); // protected retract move - } else { - if (cycleSubprogramIsActive) { - subprogramEnd(); - cycleSubprogramIsActive = false; - } - if (!cycleExpanded) { - writeBlock(gCycleModal.format(80), conditional(staticProperties.useG95forTapping, gFeedModeModal.format(94))); - gMotionModal.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 traversal.")); - return; - } - if (!staticProperties.useG0 && (((x ? 1 : 0) + (y ? 1 : 0) + (z ? 1 : 0)) > 1)) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z); - forceFeed(); - } - } -} - -function onLinear(_x, _y, _z, feed) { - if (pendingRadiusCompensation >= 0) { - // ensure that we end at desired position when compensation is turned off - xOutput.reset(); - yOutput.reset(); - } - 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; - var d = tool.diameterOffset; - if ((d > 200 && d < 1000) || d > 9999) { - warning(localize("Diameter offset out of range.")); - } - writeBlock(gPlaneModal.format(17), gFeedModeModal.format(94)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); - break; - case RADIUS_COMPENSATION_RIGHT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(1), f); - } - } -} - -var forceG0 = false; -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var num = - (xyzFormat.areDifferent(_x, xOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_y, yOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_z, zOutput.getCurrent()) ? 1 : 0) + - ((aOutput.isEnabled() && abcFormat.areDifferent(_a, aOutput.getCurrent())) ? 1 : 0) + - ((bOutput.isEnabled() && abcFormat.areDifferent(_b, bOutput.getCurrent())) ? 1 : 0) + - ((cOutput.isEnabled() && abcFormat.areDifferent(_c, cOutput.getCurrent())) ? 1 : 0); - /* - if (!getProperty("useG0") && !forceG0 && (tcpIsSupported || (num > 1))) { - invokeOnLinear5D(_x, _y, _z, _a, _b, _c, highFeedrate); // onLinear5D handles inverse time feedrates - forceG0 = false; - return; - } - */ - 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); - - if (x || y || z || a || b || c) { - if (!staticProperties.useG0 && (tcpIsSupported || (num > 1))) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, a, b, c, getFeed(highFeedrate)); - } else { - writeBlock(gMotionModal.format(0), x, y, z, a, b, c); - forceFeed(); - } - } -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed, feedMode) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - 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); - - if (feedMode == FEED_INVERSE_TIME) { - forceFeed(); - } - var f = getFeed(feed); - var fMode = (feedMode == FEED_INVERSE_TIME) ? 93 : 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); - } - } -} - -function moveToSafeRetractPosition(isRetracted) { - var _skipBlock = skipBlock; - if (!isRetracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing) { - skipBlock = _skipBlock; - writeRetract(X, Y); - } -} - -// Start of onRewindMachine logic -var performRewinds = false; // only use this setting with hardcoded machine configurations, set to true to enable the rewind/reconfigure logic -var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values -safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock -safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate -safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate - -/** Allow user to override the onRewind logic. */ -function onRewindMachineEntry(_a, _b, _c) { - return false; -} - -/** Retract to safe position before indexing rotaries. */ -function onMoveToSafeRetractPosition() { - // cancel TCP so that tool doesn't follow rotaries - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - moveToSafeRetractPosition(false); -} - -/** Rotate axes to new position above reentry position */ -function onRotateAxes(_x, _y, _z, _a, _b, _c) { - // position rotary axes - xOutput.disable(); - yOutput.disable(); - zOutput.disable(); - forceG0 = true; - invokeOnRapid5D(_x, _y, _z, _a, _b, _c); - setCurrentABC(new Vector(_a, _b, _c)); - xOutput.enable(); - yOutput.enable(); - zOutput.enable(); -} - -/** Return from safe position after indexing rotaries. */ -function onReturnFromSafeRetractPosition(_x, _y, _z) { - // reinstate TCP - if (tcpIsSupported) { - writeBlock(gMotionModal.format(0), gFormat.format(234), hFormat.format(tool.lengthOffset), formatComment("TCPC ON")); - forceFeed(); - lengthCompensationActive = true; - } - - // position in XY - forceXYZ(); - xOutput.reset(); - yOutput.reset(); - zOutput.disable(); - invokeOnRapid(_x, _y, _z); - - // position in Z - zOutput.enable(); - invokeOnRapid(_x, _y, _z); -} -// End of onRewindMachine logic - -// Start of polar interpolation -var usePolarMode = false; // enables polar interpolation for a single operation -var polarDirection = new Vector(1, 0, 0); // vector to maintain tool at while in polar interpolation -var saveTcpIsSupported = undefined; -function setPolarMode(section, mode) { - if (!mode) { // turn off polar mode if required - if (usePolarMode) { - var currentPosition = getCurrentPosition(); - var polarPosition = getPolarPosition(currentPosition.x, currentPosition.y, currentPosition.z); - currentMachineABC = new Vector(polarPosition.second.x, polarPosition.second.y, polarPosition.second.z); - deactivatePolarMode(); - tcpIsSupported = saveTcpIsSupported; - setFeedrateMode(true); - usePolarMode = false; - } - return; - } - - var direction = polarDirection; - - // determine the rotary axis to use for polar interpolation - var axis = undefined; - if (machineConfiguration.getAxisV().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisV().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisV(); - } - } - if (axis == undefined && machineConfiguration.getAxisU().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisU().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisU(); - } - } - if (axis == undefined) { - error(localize("Polar interpolation requires an active rotary axis be defined in direction of workplane normal.")); - } - - // calculate directional vector from initial position - if (direction == undefined) { - error(localize("Polar interpolation initiated without a directional vector.")); - return; - } else if (direction.isZero()) { - var initialPosition = getFramePosition(section.getInitialPosition()); - direction = Vector.diff(initialPosition, axis.getOffset()).getNormalized(); - } - - // put vector in plane of rotary axis - var temp = Vector.cross(direction, axis.getAxis()).getNormalized(); - direction = Vector.cross(axis.getAxis(), temp).getNormalized(); - - // activate polar interpolation - saveTcpIsSupported = tcpIsSupported; - tcpIsSupported = false; // temporary disable tcp support for polar mode - setFeedrateMode(); - activatePolarMode(tolerance / 2, 0, direction); -} -// End of polar interpolation - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - if (isSpiral()) { - var startRadius = getCircularStartRadius(); - var endRadius = getCircularRadius(); - var dr = Math.abs(endRadius - startRadius); - if (dr > maximumCircularRadiiDifference) { // maximum limit - linearize(tolerance); // or alternatively use other G-codes for spiral motion - return; - } - } - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (staticProperties.useRadius || isHelical()) { // radius mode does not support full arcs - linearize(tolerance); - return; - } - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } else if (!staticProperties.useRadius) { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), 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: - writeBlock(gPlaneModal.format(18), 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: - writeBlock(gPlaneModal.format(19), 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: - 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: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } -} - -var currentCoolantMode = COOLANT_OFF; -var coolantOff = undefined; -var isOptionalCoolant = false; - -function setCoolant(coolant) { - var coolantCodes = getCoolantCodes(coolant); - forceSingleLine = false; - if ((coolantCodes != undefined) && (coolant == COOLANT_FLOOD)) { - if (coolantPressure != "") { - forceSingleLine = true; - coolantCodes.push(coolantPressure); - } - } - if (Array.isArray(coolantCodes)) { - if (singleLineCoolant || forceSingleLine) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes.join(getWordSeparator())); - } else { - for (var c in coolantCodes) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes[c]); - } - } - return undefined; - } - return coolantCodes; -} - -var isSpecialCoolantActive = false; - -function getCoolantCodes(coolant) { - isOptionalCoolant = false; - var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line - if (!coolants) { - error(localize("Coolants have not been defined.")); - } - if (isProbeOperation()) { // avoid coolant output for probing - coolant = COOLANT_OFF; - } - if (coolant == currentCoolantMode) { - if (operationNeedsSafeStart && coolant != COOLANT_OFF && !isSpecialCoolantActive) { - //isOptionalCoolant = true; - } else if (!forceCoolant || coolant == COOLANT_OFF) { - return undefined; // coolant is already active - } - } - if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && !isOptionalCoolant && !forceCoolant) { - if (Array.isArray(coolantOff)) { - for (var i in coolantOff) { - multipleCoolantBlocks.push(mFormat.format(coolantOff[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(coolantOff)); - } - } - forceCoolant = false; - - if (isSpecialCoolantActive) { - forceSpindleSpeed = true; - } - var m; - var coolantCodes = {}; - for (var c in coolants) { // find required coolant codes into the coolants array - if (coolants[c].id == coolant) { - isSpecialCoolantActive = (coolants[c].id == COOLANT_THROUGH_TOOL) || (coolants[c].id == COOLANT_FLOOD_THROUGH_TOOL) || (coolants[c].id == COOLANT_AIR_THROUGH_TOOL); - 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(mFormat.format(m[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(m)); - } - currentCoolantMode = coolant; - return multipleCoolantBlocks; // return the single formatted coolant value - } - return undefined; -} - -var mapCommand = { - COMMAND_END:2, - 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; - forceCoolant = true; - return; - case COMMAND_OPTIONAL_STOP: - writeBlock(mFormat.format(1)); - forceSpindleSpeed = true; - forceCoolant = true; - return; - case COMMAND_COOLANT_ON: - setCoolant(COOLANT_FLOOD); - return; - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_LOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(10)); // lock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(12)); // lock 5th-axis motion - } - } - return; - case COMMAND_UNLOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(11)); // unlock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(13)); // unlock 5th-axis motion - } - } - return; - case COMMAND_BREAK_CONTROL: - if (!toolChecked) { // avoid duplicate COMMAND_BREAK_CONTROL - prepareForToolCheck(); - writeBlock( - gFormat.format(65), - "P" + 9853, - "T" + toolFormat.format(tool.number), - "B" + xyzFormat.format(0), - "H" + xyzFormat.format(staticProperties.toolBreakageTolerance) - ); - toolChecked = true; - lengthCompensationActive = false; // macro 9853 cancels tool length compensation - } - return; - case COMMAND_TOOL_MEASURE: - measureTool = true; - return; - case COMMAND_START_CHIP_TRANSPORT: - writeBlock(mFormat.format(31)); - return; - case COMMAND_STOP_CHIP_TRANSPORT: - writeBlock(mFormat.format(33)); - return; - case COMMAND_PROBE_ON: - return; - case COMMAND_PROBE_OFF: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -var toolChecked = false; // specifies that the tool has been checked with the probe - -function onSectionEnd() { - if (isInspectionOperation() && !isLastSection()) { - writeBlock(gFormat.format(103), "P0", formatComment("LOOKAHEAD ON")); - } - if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) { - setCoolant(COOLANT_OFF); - } - if ((((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) && - tool.breakControl) { - onCommand(COMMAND_BREAK_CONTROL); - } else { - toolChecked = false; - } - - if (true) { - if (isRedirecting()) { - if (firstPattern) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - var abc; - if (currentSection.isMultiAxis() && machineConfiguration.isMultiAxisConfiguration()) { - abc = currentSection.getFinalToolAxisABC(); - } else { - abc = currentWorkPlaneABC; - } - if (abc == undefined) { - abc = new Vector(0, 0, 0); - } - setAbsoluteMode(finalPosition, abc); - subprogramEnd(); - } - } - } - forceAny(); - - if (currentSection.isMultiAxis()) { - writeBlock(gFeedModeModal.format(94)); // inverse time feed off - if (currentSection.isOptimizedForMachine()) { - // the code below gets the machine angles from previous operation. closestABC must also be set to true - currentMachineABC = currentSection.getFinalToolAxisABC(); - } - if (tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - } - - if (isProbeOperation()) { - writeBlock(gFormat.format(65), "P" + 9833); // spin the probe off - if (probeVariables.probeAngleMethod != "G68") { - setProbeAngle(); // output probe angle rotations if required - } - } - - // reset for next section - operationNeedsSafeStart = false; - coolantPressure = staticProperties.coolantPressure; - cycleReverse = false; - - setPolarMode(currentSection, false); -} - -/** Output block to do safe retract and/or move to home position. */ -function writeRetract() { - var words = []; // store all retracted axes in an array - var retractAxes = new Array(false, false, false); - var method = staticProperties.safePositionMethod; - if (method == "clearanceHeight") { - if (!is3D()) { - error(localize("Retract option 'Clearance Height' is not supported for multi-axis machining.")); - } else { - return; - } - } - validate(arguments.length != 0, "No axis specified for writeRetract()."); - - for (i in arguments) { - retractAxes[arguments[i]] = true; - } - if ((retractAxes[0] || retractAxes[1]) && !retracted && !skipBlock) { // retract Z first before moving to X/Y home - error(localize("Retracting in X/Y is not possible without being retracted in Z.")); - return; - } - // special conditions - if (retractAxes[0] || retractAxes[1]) { - method = "G53"; - } - cancelG68Rotation(); // G68 has to be canceled for retracts - - // define home positions - var _xHome; - var _yHome; - var _zHome; - if (method == "G28") { - _xHome = toPreciseUnit(0, MM); - _yHome = toPreciseUnit(0, MM); - _zHome = toPreciseUnit(0, MM); - } else { - if (homePositionCenter && - hasParameter("part-upper-x") && hasParameter("part-lower-x")) { - _xHome = (getParameter("part-upper-x") + getParameter("part-lower-x")) / 2; - } else { - _xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM); - } - _yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM); - _zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM); - } - for (var i = 0; i < arguments.length; ++i) { - switch (arguments[i]) { - case X: - // special conditions - if (homePositionCenter) { // output X in standard block by itself if centering - writeBlock(gMotionModal.format(0), "X" + xyzFormat.format(_xHome)); - xOutput.reset(); - break; - } - 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 = !skipBlock; - break; - default: - error(localize("Unsupported axis specified for writeRetract().")); - return; - } - } - if (words.length > 0) { - switch (method) { - case "G28": - gMotionModal.reset(); - gAbsIncModal.reset(); - writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); - writeBlock(gAbsIncModal.format(90)); - break; - case "G53": - gMotionModal.reset(); - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); - break; - default: - error(localize("Unsupported safe position method.")); - return; - } - } -} - -var isDPRNTopen = false; -function inspectionCreateResultsFileHeader() { - if (isDPRNTopen) { - if (!staticProperties.singleResultsFile) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - } - } - - if (isProbeOperation() && !printProbeResults()) { - return; // if print results is not desired by probe/ probeWCS - } - - if (!isDPRNTopen) { - writeBlock("PCLOS"); - writeBlock("POPEN"); - // check for existence of none alphanumeric characters but not spaces - var resFile; - if (staticProperties.singleResultsFile) { - resFile = getParameter("job-description") + "-RESULTS"; - } else { - resFile = getParameter("operation-comment") + "-RESULTS"; - } - resFile = resFile.replace(/:/g, "-"); - resFile = resFile.replace(/[^a-zA-Z0-9 -]/g, ""); - resFile = resFile.replace(/\s/g, "-"); - writeln("DPRNT[START]"); - writeln("DPRNT[RESULTSFILE*" + resFile + "]"); - if (hasGlobalParameter("document-id")) { - writeln("DPRNT[DOCUMENTID*" + getGlobalParameter("document-id") + "]"); - } - if (hasGlobalParameter("model-version")) { - writeln("DPRNT[MODELVERSION*" + getGlobalParameter("model-version") + "]"); - } - } - if (isProbeOperation() && printProbeResults()) { - isDPRNTopen = true; - } -} - -function getPointNumber() { - if (typeof inspectionWriteVariables == "function") { - return (inspectionVariables.pointNumber); - } else { - return ("#172[60]"); - } -} - -function inspectionWriteCADTransform() { - var cadOrigin = currentSection.getModelOrigin(); - var cadWorkPlane = currentSection.getModelPlane().getTransposed(); - var cadEuler = cadWorkPlane.getEuler2(EULER_XYZ_S); - writeln( - "DPRNT[G331" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(cadEuler.x) + - "*B" + abcFormat.format(cadEuler.y) + - "*C" + abcFormat.format(cadEuler.z) + - "*X" + xyzFormat.format(-cadOrigin.x) + - "*Y" + xyzFormat.format(-cadOrigin.y) + - "*Z" + xyzFormat.format(-cadOrigin.z) + - "]" - ); -} - -function inspectionWriteWorkplaneTransform() { - var orientation = (machineConfiguration.isMultiAxisConfiguration() && currentMachineABC != undefined) ? machineConfiguration.getOrientation(currentMachineABC) : currentSection.workPlane; - var abc = orientation.getEuler2(EULER_XYZ_S); - writeln("DPRNT[G330" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(abc.x) + - "*B" + abcFormat.format(abc.y) + - "*C" + abcFormat.format(abc.z) + - "*X0*Y0*Z0*I0*R0]" - ); -} - -function writeProbingToolpathInformation(cycleDepth) { - writeln("DPRNT[TOOLPATHID*" + getParameter("autodeskcam:operation-id") + "]"); - if (isInspectionOperation()) { - writeln("DPRNT[TOOLPATH*" + getParameter("operation-comment") + "]"); - } else { - writeln("DPRNT[CYCLEDEPTH*" + xyzFormat.format(cycleDepth) + "]"); - } -} - -function onClose() { - writeRetract(Z); - - if (isDPRNTopen) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - if (typeof inspectionProcessSectionEnd == "function") { - inspectionProcessSectionEnd(); - } - } - cancelG68Rotation(); - writeln(""); - - optionalSection = false; - - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - writeBlock(mFormat.format(0)); - - writeln(""); - writeComment("UNLOAD TOOLS"); - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - if (tool.number == 20 || tool.number == 19) { - continue; - } - writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - displayMedia("removeTool" + tool.number + ".jpg", false, "Remove tool " + tool.number); - } - } - - function gotoWithMessage(xLoc, yLoc, fileName, comment) { - writeBlock(gFormat.format(53), xOutput.format(xLoc), yOutput.format(yLoc)); - displayMedia(fileName, false, comment); - } - - writeln(""); - writeComment("CLEAN MACHINE"); - gotoWithMessage(X_TRAVEL_LIMIT/2, 0, "airGunClean.jpg", "Use air gun to clean"); - displayMedia("floodCoolantOff.jpg", false, "Turn flood coolant off"); - setCoolant(COOLANT_FLOOD); - gotoWithMessage(0, Y_TRAVEL_LIMIT, "sprayLowerRight.jpg", "Spray lower right"); - gotoWithMessage(X_TRAVEL_LIMIT, Y_TRAVEL_LIMIT, "sprayLowerLeft.jpg", "Spray lower left"); - gotoWithMessage(0, 0, "sprayUpperRight.jpg", "Spray upper right") - gotoWithMessage(X_TRAVEL_LIMIT, 0, "sprayUpperLeft.jpg", "Spray upper left") - onCommand(COMMAND_COOLANT_OFF); - onCommand(COMMAND_START_CHIP_TRANSPORT); - gotoWithMessage(X_TRAVEL_LIMIT/2, Y_TRAVEL_LIMIT, "sweepChips.jpg", "Sweep chips"); - onCommand(COMMAND_STOP_CHIP_TRANSPORT); - - writeln(""); - // retract - if (!staticProperties.homePositionCenter || currentMachineABC.length != 0) { - writeRetract(X, Y); - } - - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - - // MAY NEED CHANGE HOMING ORDER TO ROTARY THEN LINEAR FOR NON-UMC MACHINES - - // Unwind Rotary table at end - if (machineConfiguration.isMultiAxisConfiguration()) { - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - if (machineConfiguration.isMachineCoordinate(2)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(1)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "B" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(0)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "A" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(0)) - ); - } - if (staticProperties.homePositionCenter) { - homePositionCenter = staticProperties.homePositionCenter; - writeRetract(X, Y); - } - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - - if (staticProperties.useM130PartImages || staticProperties.useM130ToolImages) { - writeBlock(mFormat.format(131)); - } - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - if (subprograms.length > 0) { - writeln(""); - write(subprograms); - } - writeln(""); - writeln("%"); -} - -/* -keywords += (keywords ? " MODEL_IMAGE" : "MODEL_IMAGE"); - -function onTerminate() { - var outputPath = getOutputPath(); - var programFilename = FileSystem.getFilename(outputPath); - var programSize = FileSystem.getFileSize(outputPath); - var postPath = findFile("setup-sheet-excel-2007.cps"); - var intermediatePath = getIntermediatePath(); - var a = "--property unit " + ((unit == IN) ? "0" : "1"); // use 0 for inch and 1 for mm - if (programName) { - a += " --property programName \"'" + programName + "'\""; - } - if (programComment) { - a += " --property programComment \"'" + programComment + "'\""; - } - a += " --property programFilename \"'" + programFilename + "'\""; - a += " --property programSize \"" + programSize + "\""; - a += " --noeditor --log temp.log \"" + postPath + "\" \"" + intermediatePath + "\" \"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\""; - execute(getPostProcessorPath(), a, false, ""); - executeNoWait("excel", "\"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\"", false, ""); -} -*/ - -function setProperty(property, value) { - properties[property].current = value; -} diff --git a/Haas_Mills_BIDC/haas vf2 deprecated.cps b/Haas_Mills_BIDC/haas vf2 deprecated.cps deleted file mode 100644 index 4bd392b..0000000 --- a/Haas_Mills_BIDC/haas vf2 deprecated.cps +++ /dev/null @@ -1,5249 +0,0 @@ -/** - Copyright (C) 2012-2021 by Autodesk, Inc. - All rights reserved. - - HAAS post processor configuration. - - $Revision: 43303 89bc27ff4d3595014e0e8cba412811fbed9f3e74 $ - $Date: 2021-06-01 08:35:38 $ - - Modified by BIDC of Purdue University - Authors: Gavin Williams (will1742@purdue.edu) -*/ - -// >>>>> INCLUDED FROM ../../../haas next generation.cps -//////////////////////////////////////////////////////////////////////////////////////////////// -// MANUAL NC COMMANDS -// -// The following ACTION commands are supported by this post. -// -// CYCLE_REVERSAL - Reverses the spindle in a drilling cycle -// USEPOLARMODE - Enables polar interpolation for the following operation. -// VFD_HIGH - Uses high pressure flood coolant if machine has VFD -// VFD_LOW - Uses low pressure flood coolant if machine has VFD -// VFD_NORMAL - Uses normal pressure flood coolant if machine has VFD -// -//////////////////////////////////////////////////////////////////////////////////////////////// - -description = "HAAS - Next Generation Control"; -vendor = "Haas Automation"; -vendorUrl = "https://www.haascnc.com"; -legal = "Copyright (C) 2012-2021 by Autodesk, Inc."; -certificationLevel = 2; -minimumRevision = 45702; - -longDescription = "Generic post for the HAAS Next Generation control. The post includes support for multi-axis indexing and simultaneous machining. The post utilizes the dynamic work offset feature so you can place your work piece as desired without having to repost your NC programs." + EOL + -"You can specify following pre-configured machines by using the property 'Machine model':" + EOL + -"UMC-500" + EOL + "UMC-750" + EOL + "UMC-1000" + EOL + "UMC-1600-H"; - -extension = "nc"; -programNameIsInteger = true; -setCodePage("ascii"); -keywords = "MODEL_IMAGE PREVIEW_IMAGE"; - -capabilities = CAPABILITY_MILLING | CAPABILITY_MACHINE_SIMULATION; -tolerance = spatial(0.002, MM); - -minimumChordLength = spatial(0.25, MM); -minimumCircularRadius = spatial(0.01, MM); -maximumCircularRadius = spatial(1000, MM); -minimumCircularSweep = toRad(0.01); -maximumCircularSweep = toRad(355); -allowHelicalMoves = true; -allowedCircularPlanes = undefined; // allow any circular motion -allowSpiralMoves = true; -highFeedrate = 650 * 25.4; // must be in MM - -// user-defined properties -properties = {/* - machineModel: { - title: "Machine model", - description: "Specifies the pre-configured machine model.", - type: "enum", - group: 0, - values: [ - {title: "None", id: "none"}, - {title: "UMC-500", id: "umc-500"}, - {title: "UMC-750", id: "umc-750"}, - {title: "UMC-1000", id: "umc-1000"}, - {title: "UMC-1600-H", id: "umc-1600"} - ], - value: "none", - scope: "post" - },*/ - hasAAxis: { - title: "Has A-axis rotary", - description: "Enable if the machine has an A-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasBAxis: { - title: "Has B-axis rotary", - description: "Enable if the machine has a B-axis table/trunnion. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - }, - hasCAxis: { - title: "Has C-axis rotary", - description: "Enable if the machine has a C-axis table. Specifies a trunnion setup if an A-axis or B-axis is defined. Check the table direction on the machine and use the (Reversed) selection if the table is moving in the opposite direction.", - type: "enum", - group: 1, - values: [ - {title: "No", id: "false"}, - {title: "Yes", id: "true"}, - {title: "Reversed", id: "reversed"} - ], - value: "false", - scope: "post" - },/* - useDPMFeeds: { - title: "Rotary moves use DPM feeds", - description: "Enable to output DPM feeds, disable for Inverse Time feeds with rotary axes moves.", - group: 1, - type: "boolean", - value: false, - scope: "post" - },*/ - useTCPC: { - title: "Use TCPC programming", - description: "The control supports Tool Center Point Control programming.", - group: 1, - type: "boolean", - value: true, - scope: "post" - },/* - useDWO: { - title: "Use DWO", - description: "Specifies that the Dynamic Work Offset feature (G254/G255) should be used.", - group: 1, - type: "boolean", - value: true, - scope: "post" - }, - preloadTool: { - title: "Preload tool", - description: "Preloads the next tool at a tool change (if any).", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - chipTransport: { - title: "Use chip transport", - description: "Enable to turn on chip transport at start of program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - optionalStop: { - title: "Optional stop", - description: "Specifies that optional stops M1 should be output at tool changes.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - separateWordsWithSpace: { - title: "Separate words with space", - description: "Adds spaces between words if 'yes' is selected.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useRadius: { - title: "Radius arcs", - description: "If yes is selected, arcs are output using radius values rather than IJK.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useParametricFeed: { - title: "Parametric feed", - description: "Parametric feed values based on movement type are output.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - useG0: { - title: "Use G0", - description: "Specifies that G0s should be used for rapid moves when moving along a single axis.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - safePositionMethod: { - title: "Safe Retracts", - description: "Select your desired retract option. 'Clearance Height' retracts to the operation clearance height.", - type: "enum", - values: [ - {title: "G28", id: "G28"}, - {title: "G53", id: "G53"}, - {title: "Clearance Height", id: "clearanceHeight"} - ], - value: "G53", - scope: "post" - }, - useG187: { - title: "Use G187", - description: "Specifies that smoothing using G187 should be used.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - homePositionCenter: { - title: "Home position center", - description: "Enable to center the part along X at the end of program for easy access. Requires a CNC with a moving table.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - optionallyCycleToolsAtStart: { - title: "Optionally cycle tools at start", - description: "Cycle through each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - measureToolsAtStart: { - title: "Optionally measure tools at start", - description: "Measure each tool used at the beginning of the program when block delete is turned off.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - forceHomeOnIndexing: { - title: "Force XY home position on indexing", - description: "Move XY to their home positions on multi-axis indexing.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - toolBreakageTolerance: { - title: "Tool breakage tolerance", - description: "Specifies the tolerance for which tool break detection will raise an alarm.", - group: 2, - type: "spatial", - value: 0.1, - scope: "post" - }, - safeStartAllOperations: { - title: "Safe start all operations", - description: "Write optional blocks at the beginning of all operations that include all commands to start program.", - group: 2, - type: "boolean", - value: true, - scope: "post" - }, - fastToolChange: { - title: "Fast tool change", - description: "Skip spindle off, coolant off, and Z retract to make tool change quicker.", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - useG95forTapping: { - title: "Use G95 for tapping", - description: "use IPR/MPR instead of IPM/MPM for tapping", - group: 2, - type: "boolean", - value: false, - scope: "post" - }, - safeRetractDistance: { - title: "Safe retract distance", - description: "Specifies the distance to add to retract distance when rewinding rotary axes.", - group: 2, - type: "spatial", - value: 0, - scope: "post" - },*/ - useSubroutines: { - title: "Use subroutines", - description: "Select your desired subroutine option. 'All Operations' creates subroutines per each operation, 'Cycles' creates subroutines for cycle operations on same holes, and 'Patterns' creates subroutines for patterned operations.", - type: "enum", - values: [ - {title: "No", id: "none"}, - {title: "All Operations", id: "allOperations"}, - {title: "Cycles", id: "cycles"}, - {title: "Patterns", id: "patterns"} - ], - group: 3, - value: "allOperations", - scope: "post" - },/* - writeMachine: { - title: "Write machine", - description: "Output the machine settings in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - writeTools: { - title: "Write tool list", - description: "Output a tool list in the header of the code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - writeVersion: { - title: "Write version", - description: "Write the version number in the header of the code.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showSequenceNumbers: { - title: "Use sequence numbers", - description: "Use sequence numbers for each block of outputted code.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - sequenceNumberStart: { - title: "Start sequence number", - description: "The number at which to start the sequence numbers.", - group: 4, - type: "integer", - value: 10, - scope: "post" - }, - sequenceNumberIncrement: { - title: "Sequence number increment", - description: "The amount by which the sequence number is incremented by in each block.", - group: 4, - type: "integer", - value: 5, - scope: "post" - }, - sequenceNumberOnlyOnToolChange: { - title: "Block number only on tool change", - description: "Specifies that block numbers should only be output at tool changes.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - showNotes: { - title: "Show notes", - description: "Enable to output notes for operations.", - group: 4, - type: "boolean", - value: true, - scope: "post" - }, - useM130PartImages: { - title: "Include M130 part images", - description: "Enable to include M130 part images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - useM130ToolImages: { - title: "Include M130 tool images", - description: "Enable to include M130 tool images with the NC file.", - group: 4, - type: "boolean", - value: false, - scope: "post" - }, - coolantPressure: { - title: "Coolant pressure", - description: "Select the coolant pressure if equipped with a Variable Frequency Drive. Select 'Default' if this option is not installed.", - type: "enum", - group: 2, - values: [ - {title: "Default", id: ""}, - {title: "Low", id: "P0"}, - {title: "Normal", id: "P1"}, - {title: "High", id: "P2"} - ], - value: "", - scope: "post" - }, - singleResultsFile: { - title: "Create single results file", - description: "Set to false if you want to store the measurement results for each probe / inspection toolpath in a separate file", - group: 0, - type: "boolean", - value: true, - scope: "post" - }*/ -}; - -staticProperties = { - machineModel: "none", - safePositionMethod: "G53", - useDPMFeeds: false, - useTCPC: true, - useDWO: true, - safeStartAllOperations: true, - preloadTool: true, - chipTransport: false, - optionalStop: true, - separateWordsWithSpace: true, - useRadius: false, - useParametricFeed: true, - useG0: true, - useG187: false, - homePositionCenter: false, - optionallyCycleToolsAtStart: false, - measureToolsAtStart: true, - forceHomeOnIndexing: true, - toolBreakageTolerance: 0.1, - fastToolChange: false, - useG95forTapping: true, - safeRetractDistance: 0, - //useSubroutines: "allOperations", - writeMachine: false, - writeTools: true, - writeVersion: false, - showSequenceNumbers: true, - sequenceNumberStart: 10, - sequenceNumberIncrement: 5, - sequenceNumberOnlyOnToolChange: false, - showNotes: true, - useM130PartImages: false, - useM130ToolImages: false, - coolantPressure: "", - singleResultsFile: true, - }; - - const HAAS_DRILL = 1; - const HAAS_TAP = 2; - const HAAS_SHELL = 3; - const HAAS_END_MILL = 4; - const HAAS_CENTER = 5; - const HAAS_BALL_NOSE = 6; - const HAAS_PROBE = 7; - - const NO_PROBING = 0; - const LEN_ROT = 1; - const LEN_NON_ROT = 2; - const LEN_DIA_ROT = 3; - - const DEFAULT_HAAS_K_FACTOR = 0.05; - const NULL_HAAS_K_FACTOR = 0; - - const CLEARANCE_HEIGHT = 1; - const LENGTH_TOLERANCE = .25; - const DIAM_TOLERANCE = .01; - -var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines -// samples: -// {id: COOLANT_THROUGH_TOOL, on: 88, off: 89} -// {id: COOLANT_THROUGH_TOOL, on: [8, 88], off: [9, 89]} -var coolants = [ - {id: COOLANT_FLOOD, on: 8}, - {id: COOLANT_MIST}, - {id: COOLANT_THROUGH_TOOL, on: 88, off: 89}, - {id: COOLANT_AIR, on: 83, off: 84}, - {id: COOLANT_AIR_THROUGH_TOOL, on: 73, off: 74}, - {id: COOLANT_SUCTION}, - {id: COOLANT_FLOOD_MIST}, - {id: COOLANT_FLOOD_THROUGH_TOOL, on: [88, 8], off: [89, 9]}, - {id: COOLANT_OFF, off: 9} -]; - -// old machines only support 4 digits -var oFormat = createFormat({width:5, zeropad:true, decimals:0}); -var nFormat = createFormat({decimals:0}); - -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 probeWCSFormat = createFormat({decimals:2, forceDecimal:true}); - -var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var rFormat = xyzFormat; // radius -var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG}); -var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true}); -var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true}); -var toolFormat = createFormat({decimals:0}); -var rpmFormat = createFormat({decimals:0}); -var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000 -var milliFormat = createFormat({decimals:0}); // milliseconds // range 1-9999 -var taperFormat = createFormat({decimals:1, scale:DEG}); - -var xOutput = createVariable({prefix:"X"}, xyzFormat); -var yOutput = createVariable({prefix:"Y"}, xyzFormat); -var zOutput = createVariable({onchange: function() {retracted = false;}, prefix:"Z"}, xyzFormat); -var aOutput = createVariable({prefix:"A"}, abcFormat); -var bOutput = createVariable({prefix:"B"}, abcFormat); -var cOutput = createVariable({prefix:"C"}, abcFormat); -var feedOutput = createVariable({prefix:"F"}, feedFormat); -var pitchOutput = createVariable({prefix:"F", force:true}, pitchFormat); -var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); -var dOutput = createVariable({}, dFormat); - -// circular output -var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat); -var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat); -var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat); - -var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... -var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19 -var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 -var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 -var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 -var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... -var gRetractModal = createModal({force:true}, gFormat); // modal group 10 // G98-99 -var gRotationModal = createModal({ - onchange: function () { - if (probeVariables.probeAngleMethod == "G68") { - probeVariables.outputRotationCodes = true; - } - } -}, gFormat); // modal group 16 // G68-G69 - -// fixed settings -var firstFeedParameter = 100; // the first variable to use with parametric feed -var forceResetWorkPlane = false; // enable to force reset of machine ABC on new orientation -var minimumCyclePoints = 5; // minimum number of points in cycle operation to consider for subprogram -var useDwoForPositioning = true; // specifies to use the DWO feature for XY positioning for multi-axis operations - -var WARNING_WORK_OFFSET = 0; - -var allowIndexingWCSProbing = false; // specifies that probe WCS with tool orientation is supported -var probeVariables = { - outputRotationCodes: false, // defines if it is required to output rotation codes - probeAngleMethod: "OFF", // OFF, AXIS_ROT, G68, G54.4 - compensationXY: undefined, - rotationalAxis: -1 -}; - -var SUB_UNKNOWN = 0; -var SUB_PATTERN = 1; -var SUB_CYCLE = 2; - -// collected state -var sequenceNumber; -var currentWorkOffset; -var coolantPressure; -var optionalSection = false; -var forceSpindleSpeed = false; -var forceCoolant = false; -var activeMovements; // do not use by default -var currentFeedId; -var maximumCircularRadiiDifference = toPreciseUnit(0.005, MM); -var maximumLineLength = 80; // the maximum number of charaters allowed in a line -var subprograms = []; -var currentPattern = -1; -var firstPattern = false; -var currentSubprogram; -var lastSubprogram; -var initialSubprogramNumber = 90000; -var definedPatterns = new Array(); -var incrementalMode = false; -var saveShowSequenceNumbers; -var cycleSubprogramIsActive = false; -var patternIsActive = false; -var lastOperationComment = ""; -var incrementalSubprogram; -var retracted = false; // specifies that the tool has been retracted to the safe plane -var hasA = false; -var hasB = false; -var hasC = false; -var measureTool = false; -var cycleReverse = false; -var probeMultipleFeatures = true; -var maximumSpindleRPM = 15000; -var homePositionCenter = false; - -// used to convert blocks to optional for safeStartAllOperations, might get used outside of onSection -var operationNeedsSafeStart = false; - -/** - Writes the specified block. -*/ -var skipBlock = false; -function writeBlock() { - var text = formatWords(arguments); - if (!text) { - return; - } - var maximumSequenceNumber = ((getProperty("useSubroutines") == "allOperations") || (getProperty("useSubroutines") == "patterns") || - (getProperty("useSubroutines") == "cycles")) ? initialSubprogramNumber : 99999; - if (staticProperties.showSequenceNumbers) { - if (sequenceNumber >= maximumSequenceNumber) { - sequenceNumber = staticProperties.sequenceNumberStart; - } - if (optionalSection || skipBlock) { - if (text) { - writeWords("/", "N" + sequenceNumber, text); - } - } else { - writeWords2("N" + sequenceNumber, arguments); - } - sequenceNumber += staticProperties.sequenceNumberIncrement; - } else { - if (optionalSection || skipBlock) { - writeWords2("/", arguments); - } else { - writeWords(arguments); - } - } - skipBlock = false; -} - -/** - Writes the specified block - used for tool changes only. -*/ -function writeToolBlock() { - var show = staticProperties.showSequenceNumbers; - staticProperties.showSequenceNumbers = (show || staticProperties.sequenceNumberOnlyOnToolChange); - writeBlock(arguments); - staticProperties.showSequenceNumbers = show; -} - -/** - Writes the specified optional block. -*/ -function writeOptionalBlock() { - skipBlock = true; - writeBlock(arguments); -} - -function formatComment(text) { - return "(" + String(text).replace(/[()]/g, "") + ")"; -} - -/** - Output a comment. -*/ -function writeComment(text) { - writeln(formatComment(text.substr(0, maximumLineLength - 2))); -} - -/** - Returns the matching HAAS tool type for the tool. -*/ -function getHaasToolType(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return 1; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return 2; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return 3; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - return 4; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_THREAD: - case TOOL_MILLING_FORM: - return 5; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - return 6; // ball nose - case TOOL_PROBE: - return 7; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -function getHaasProbingType(toolType, use9023) { - switch (getHaasToolType(toolType.type)) { - case 3: - case 4: - return (use9023 ? 23 : 1); // rotate - case 1: - case 2: - case 5: - case 6: - case 7: - return (use9023 ? 12 : 2); // non rotate - case 0: - return (use9023 ? 13 : 3); // rotate length and dia - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -function getHaasToolTypeBIDC(toolType) { - switch (toolType) { - case TOOL_DRILL: - case TOOL_REAMER: - return HAAS_DRILL; // drill - case TOOL_TAP_RIGHT_HAND: - case TOOL_TAP_LEFT_HAND: - return HAAS_TAP; // tap - case TOOL_MILLING_FACE: - case TOOL_MILLING_SLOT: - case TOOL_BORING_BAR: - return HAAS_SHELL; // shell mill - case TOOL_MILLING_END_FLAT: - case TOOL_MILLING_END_BULLNOSE: - case TOOL_MILLING_TAPERED: - case TOOL_MILLING_DOVETAIL: - case TOOL_MILLING_THREAD: - return HAAS_END_MILL; // end mill - case TOOL_DRILL_SPOT: - case TOOL_MILLING_CHAMFER: - case TOOL_DRILL_CENTER: - case TOOL_COUNTER_SINK: - case TOOL_COUNTER_BORE: - case TOOL_MILLING_FORM: - return HAAS_CENTER; // center drill - case TOOL_MILLING_END_BALL: - case TOOL_MILLING_LOLLIPOP: - case TOOL_MILLING_RADIUS: - return HAAS_BALL_NOSE; // ball nose - case TOOL_PROBE: - return HAAS_PROBE; // probe - default: - error(localize("Invalid HAAS tool type.")); - return -1; - } -} - -// 06/25/21 | Gavin Williams | will1742 -// 002 Probing -function formatCNumber(probeType, use9023){ - if (use9023) { - if (probeType == LEN_NON_ROT || probeType == LEN_DIA_ROT){ - return probeType + 10; - } - return 23; - } - return probeType; -} - -function getHaasProbingTypeBIDC(tool, use9023) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_PROBE: - return formatCNumber(NO_PROBING, use9023); - case HAAS_TAP: - case HAAS_DRILL: - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_CENTER: - if (tool.type == TOOL_MILLING_FORM) { - return formatCNumber(NO_PROBING, use9023); - } - return formatCNumber(LEN_NON_ROT, use9023); - case HAAS_END_MILL: - return formatCNumber((tool.type == TOOL_MILLING_TAPERED ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_BALL_NOSE: - return formatCNumber((tool.type == TOOL_MILLING_RADIUS ? LEN_ROT : LEN_DIA_ROT), use9023); - case HAAS_SHELL: - if ((tool.type == TOOL_MILLING_FACE) && (tool.taperAngle !=0)) { - return formatCNumber(LEN_ROT, use9023); - } - return formatCNumber(LEN_DIA_ROT, use9023); - default: - return -1; - } -} - -function getHaasKFactorBIDC(tool) { - switch (getHaasToolTypeBIDC(tool.type)) { - case HAAS_SHELL: - case HAAS_END_MILL: - if (tool.type == TOOL_BORING_BAR || tool.type == TOOL_MILLING_END_FLAT) { - return DEFAULT_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_FACE && tool.taperAngle != 0) { - return NULL_HAAS_K_FACTOR; - } - if (tool.type == TOOL_MILLING_THREAD) { - return DEFAULT_HAAS_K_FACTOR + tool.getThreadPitch(); - } - return DEFAULT_HAAS_K_FACTOR + tool.cornerRadius; - case HAAS_BALL_NOSE: - if (tool.type == TOOL_MILLING_RADIUS) { - return NULL_HAAS_K_FACTOR; - } - return DEFAULT_HAAS_K_FACTOR + (tool.diameter/2); - case HAAS_CENTER: - case HAAS_PROBE: - case HAAS_DRILL: - case HAAS_TAP: - - return NULL_HAAS_K_FACTOR; - default: - return -1; - } -} - -function writeToolCycleBlock(tool) { - writeOptionalBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - writeOptionalBlock(mFormat.format(0)); // wait for operator -} - -function prepareForToolCheck() { - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - - // cancel TCP so that tool doesn't follow tables - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - if ((currentSection.isMultiAxis() && getCurrentDirection().length != 0) || - (currentMachineABC != undefined && currentMachineABC.length != 0)) { - setWorkPlane(new Vector(0, 0, 0)); - forceWorkPlane(); - } -} - -function writeToolMeasureBlock(tool, preMeasure) { - // var writeFunction = measureTool ? writeBlock : writeOptionalBlock; - var writeFunction = writeBlock; - var comment = measureTool ? formatComment("MEASURE TOOL") : ""; - if (!preMeasure) { - prepareForToolCheck(); - } - if (false) { // use Macro P9023 to measure tools - var probingType = getHaasProbingType(tool.type, true); - writeFunction( - gFormat.format(65), - "P9023", - "A" + probingType + ".", - "T" + toolFormat.format(tool.number), - conditional((probingType != 12), "H" + xyzFormat.format(tool.bodyLength + tool.holderLength)), - conditional((probingType != 12), "D" + xyzFormat.format(tool.diameter)), - comment - ); - } else { // use Macro P9995 to measure tools - // writeFunction("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool - setMacro(1600 + tool.number, tool.numberOfFlutes, "Number of Flutes"); - var probeType = getHaasProbingTypeBIDC(tool, false) - writeFunction( - gFormat.format(65), - "P9995", - "A0.", - "B" + getHaasToolTypeBIDC(tool.type) + ".", - "C" + probeType + ".", - "T" + toolFormat.format(tool.number), - "E" + xyzFormat.format(tool.bodyLength + tool.holderLength), - "D" + xyzFormat.format(tool.diameter), - "K" + xyzFormat.format(getHaasKFactorBIDC(tool)), - "I0.", - comment - ); // probe tool - writeWords("IF [[#" + (2000 + tool.number) + " GT " + - (tool.bodyLength + tool.holderLength + LENGTH_TOLERANCE).toFixed(2) + "] OR [#" + - (2000 + tool.number) + " LT " + - (tool.bodyLength + tool.holderLength - LENGTH_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool length out of tolerance)"); - - if (probeType == 3) { - writeWords("IF [[#" + (2000 + tool.number) + " GT " + - (tool.diameter + DIAM_TOLERANCE).toFixed(2) + "] OR [#" + - (2000 + tool.number) + " LT " + - (tool.diameter - DIAM_TOLERANCE).toFixed(2) + "]] THEN #3000 = 1 (Tool diameter out of tolerance)"); - } - } - measureTool = false; -} - -// 6/28/21 | Gavin Williams | will1742 -// 002 Improved Probing -// sets specified macro number with value -function setMacro(macro, value, comment) { - writeWords("#" + macro + "=" + value, "(" + comment + ")"); -} - -function defineMachineModel() { - var useTCPC = getProperty("useTCPC"); - switch (staticProperties.machineModel) { - case "umc-500": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-23.96, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-3.37, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-750": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-29.0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-8, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(2.5, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1000": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-35, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(-40.07, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(-10.76, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 8100; - break; - case "umc-1600": - var axis1 = createAxis({coordinate:1, table:true, axis:[0, 1, 0], range:[-120, 120], preference:1, tcp:useTCPC}); - var axis2 = createAxis({coordinate:2, table:true, axis:[0, 0, 1], cyclic:true, preference:0, reset:1, tcp:useTCPC}); - machineConfiguration = new MachineConfiguration(axis1, axis2); - machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); - maximumSpindleRPM = 7500; - break; - } - machineConfiguration.setModel(staticProperties.machineModel.toUpperCase()); - machineConfiguration.setVendor("Haas Automation"); - - setMachineConfiguration(machineConfiguration); - if (receivedMachineConfiguration) { - warning(localize("The provided CAM machine configuration is overwritten by the postprocessor.")); - receivedMachineConfiguration = false; // CAM provided machine configuration is overwritten - } -} - -// Start of machine configuration logic -var compensateToolLength = false; // add the tool length to the pivot distance for nonTCP rotary heads -var virtualTooltip = false; // translate the pivot point to the virtual tool tip for nonTCP rotary heads -// internal variables, do not change -var receivedMachineConfiguration; -var tcpIsSupported; - -function activateMachine() { - // determine if TCP is supported by the machine - tcpIsSupported = false; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i in axes) { - if (axes[i].isEnabled() && axes[i].isTCPEnabled()) { - tcpIsSupported = true; - break; - } - } - - // setup usage of multiAxisFeatures - useMultiAxisFeatures = getProperty("useMultiAxisFeatures") != undefined ? getProperty("useMultiAxisFeatures") : - (typeof useMultiAxisFeatures != "undefined" ? useMultiAxisFeatures : false); - useABCPrepositioning = getProperty("useABCPrepositioning") != undefined ? getProperty("useABCPrepositioning") : - (typeof useABCPrepositioning != "undefined" ? useABCPrepositioning : false); - - if (!machineConfiguration.isMachineCoordinate(0) && (typeof aOutput != "undefined")) { - aOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(1) && (typeof bOutput != "undefined")) { - bOutput.disable(); - } - if (!machineConfiguration.isMachineCoordinate(2) && (typeof cOutput != "undefined")) { - cOutput.disable(); - } - - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // don't need to modify any settings for 3-axis machines - } - - // retract/reconfigure - safeRetractDistance = staticProperties.safeRetractDistance != undefined ? staticProperties.safeRetractDistance : - (typeof safeRetractDistance == "number" ? safeRetractDistance : 0); - if (machineConfiguration.performRewinds() || (typeof performRewinds == "undefined" ? false : performRewinds)) { - machineConfiguration.enableMachineRewinds(); // enables the rewind/reconfigure logic - if (typeof stockExpansion != "undefined") { - machineConfiguration.setRewindStockExpansion(stockExpansion); - if (!receivedMachineConfiguration) { - setMachineConfiguration(machineConfiguration); - } - } - } - - if (machineConfiguration.isHeadConfiguration()) { - compensateToolLength = typeof compensateToolLength == "undefined" ? false : compensateToolLength; - virtualTooltip = typeof virtualTooltip == "undefined" ? false : virtualTooltip; - machineConfiguration.setVirtualTooltip(virtualTooltip); - } - setFeedrateMode(); - - if (machineConfiguration.isHeadConfiguration() && compensateToolLength) { - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.isMultiAxis()) { - machineConfiguration.setToolLength(section.getTool().getBodyLength()); // define the tool length for head adjustments - section.optimizeMachineAnglesByMachine(machineConfiguration, tcpIsSupported ? 0 : 1); - } - } - } else { - optimizeMachineAngles2(tcpIsSupported ? 0 : 1); - } -} - -function setFeedrateMode(reset) { - if ((tcpIsSupported && !reset) || !machineConfiguration.isMultiAxisConfiguration()) { - return; - } - machineConfiguration.setMultiAxisFeedrate( - tcpIsSupported ? FEED_FPM : staticProperties.useDPMFeeds ? FEED_DPM : FEED_INVERSE_TIME, - 9999.99, // maximum output value for inverse time feed rates - INVERSE_MINUTES, // can be INVERSE_SECONDS or DPM_COMBINATION for DPM feeds - 0.5, // tolerance to determine when the DPM feed has changed - 1.0 // ratio of rotary accuracy to linear accuracy for DPM calculations - ); - if (!receivedMachineConfiguration || (revision < 45765)) { - setMachineConfiguration(machineConfiguration); - } -} - -function defineMachine() { - hasA = getProperty("hasAAxis") != "false"; - hasB = getProperty("hasBAxis") != "false"; - hasC = getProperty("hasCAxis") != "false"; - - if (hasA && hasB && hasC) { - error(localize("Only two rotary axes can be active at the same time.")); - return; - } else if ((hasA || hasB || hasC) && staticProperties.machineModel != "none") { - error(localize("You can only select either a machine model or use the ABC axis properties.")); - return; - } else if (((hasA || hasB || hasC) || staticProperties.machineModel != "none") && (receivedMachineConfiguration && machineConfiguration.isMultiAxisConfiguration())) { - error(localize("You can only select either a machine in the CAM setup or use the properties to define your kinematics.")); - return; - } - if (staticProperties.machineModel == "none") { - if (hasA || hasB || hasC) { // configure machine - var aAxis; - var bAxis; - var cAxis; - var useTCPC = getProperty("useTCPC"); - if (hasA) { // A Axis - For horizontal machines and trunnions - var dir = getProperty("hasAAxis") == "reversed" ? -1 : 1; - if (hasC || hasB) { - var aMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var aMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], range:[aMin, aMax], preference:dir, reset:(hasB ? 0 : 1), tcp:useTCPC}); - } else { - aAxis = createAxis({coordinate:0, table:true, axis:[dir, 0, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasB) { // B Axis - For horizontal machines and trunnions - var dir = getProperty("hasBAxis") == "reversed" ? -1 : 1; - if (hasC) { - var bMin = (dir == 1) ? -120 - 0.0001 : -30 - 0.0001; - var bMax = (dir == 1) ? 30 + 0.0001 : 120 + 0.0001; - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], range:[bMin, bMax], preference:-dir, reset:1, tcp:useTCPC}); - } else if (hasA) { - bAxis = createAxis({coordinate:1, table:true, axis:[0, 0, dir], cyclic:true, tcp:useTCPC}); - } else { - bAxis = createAxis({coordinate:1, table:true, axis:[0, dir, 0], cyclic:true, tcp:useTCPC}); - } - } - - if (hasC) { // C Axis - For trunnions only - var dir = getProperty("hasCAxis") == "reversed" ? -1 : 1; - cAxis = createAxis({coordinate:2, table:true, axis:[0, 0, dir], cyclic:true, reset:1, tcp:useTCPC}); - } - - if (hasA && hasC) { // AC trunnion - machineConfiguration = new MachineConfiguration(aAxis, cAxis); - } else if (hasB && hasC) { // BC trunnion - machineConfiguration = new MachineConfiguration(bAxis, cAxis); - } else if (hasA && hasB) { // AB trunnion - machineConfiguration = new MachineConfiguration(aAxis, bAxis); - } else if (hasA) { // A rotary - machineConfiguration = new MachineConfiguration(aAxis); - } else if (hasB) { // B rotary - horizontal machine only - machineConfiguration = new MachineConfiguration(bAxis); - } else if (hasC) { // C rotary - machineConfiguration = new MachineConfiguration(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 - } - } - } else { - defineMachineModel(); - } - /* home positions */ - // machineConfiguration.setHomePositionX(toPreciseUnit(0, IN)); - // machineConfiguration.setHomePositionY(toPreciseUnit(0, IN)); - // machineConfiguration.setRetractPlane(toPreciseUnit(0, IN)); -} -// End of machine configuration logic - -function onOpen() { - receivedMachineConfiguration = (typeof machineConfiguration.isReceived == "function") ? machineConfiguration.isReceived() : - ((machineConfiguration.getDescription() != "") || machineConfiguration.isMultiAxisConfiguration()); - - // removed hardcoded machine configs to allow for simulation - if (typeof defineMachine == "function") { - defineMachine(); // hardcoded machine configuration - } - activateMachine(); // enable the machine optimizations and settings - - if (staticProperties.useDPMFeeds) { - gFeedModeModal.format(94); - } - if (staticProperties.useRadius) { - maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC - } - if (staticProperties.sequenceNumberOnlyOnToolChange) { - staticProperties.showSequenceNumbers = false; - } - if (!staticProperties.useDWO) { - useDWOForPositioning = false; - } - - gRotationModal.format(69); // Default to G69 Rotation Off - - if (toPreciseUnit(highFeedrate, MM) <= 0) { - error(localize("You must set 'highFeedrate' because axes are not synchronized for rapid traversal.")); - return; - } - - if (!staticProperties.separateWordsWithSpace) { - setWordSeparator(""); - } - saveShowSequenceNumbers = staticProperties.showSequenceNumbers; - sequenceNumber = staticProperties.sequenceNumberStart; - writeln("%"); - - if (programName) { - var programId; - try { - programId = getAsInt(programName); - } catch (e) { - error(localize("Program name must be a number.")); - return; - } - if (!((programId >= 1) && (programId <= 99999))) { - error(localize("Program number is out of range.")); - return; - } - writeln( - "O" + oFormat.format(programId) + - conditional(programComment, " " + formatComment(programComment.substr(0, maximumLineLength - 2 - ("O" + oFormat.format(programId)).length - 1))) - ); - lastSubprogram = (initialSubprogramNumber - 1); - } else { - error(localize("Program name has not been specified.")); - return; - } - - writeWords(writeComment(getGlobalParameter("username") + ": " + getGlobalParameter("document-path")), writeComment(getGlobalParameter("generated-at"))); - - if (staticProperties.useG0) { - writeComment(localize("Using G0 which travels along dogleg path.")); - } else { - writeComment(subst(localize("Using high feed G1 F%1 instead of G0."), feedFormat.format(toPreciseUnit(highFeedrate, MM)))); - } - - if (staticProperties.writeVersion) { - if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { - writeComment(localize("post version") + ": " + getHeaderVersion()); - } - if ((typeof getHeaderDate == "function") && getHeaderDate()) { - writeComment(localize("post modified") + ": " + getHeaderDate()); - } - } - - // dump machine configuration - var vendor = machineConfiguration.getVendor(); - var model = machineConfiguration.getModel(); - var description = machineConfiguration.getDescription(); - - if (staticProperties.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 (staticProperties.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" + 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); - - if (staticProperties.useM130PartImages) { - var toolRenderer = createToolRenderer(); - if (toolRenderer) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - toolRenderer.setFluteColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - toolRenderer.setShoulderColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setShaftColor(new Color(80.0 / 255, 80.0 / 255, 80.0 / 255)); - toolRenderer.setHolderColor(new Color(40.0 / 255, 40.0 / 255, 40.0 / 255)); - if (i % 2 == 0) { - toolRenderer.setBackgroundColor(new Color(1, 1, 1)); - } else { - toolRenderer.setBackgroundColor(new Color(240 / 255.0, 240 / 255.0, 240 / 255.0)); - } - var path = "tool" + tool.number + ".png"; - var width = 400; - var height = 532; - toolRenderer.exportAs(path, "image/png", tool, width, height); - } - } - } - } - } - - // 6/21/21 | Gavin Williams | will1742 - // Probing now required. Using P9995. - // optionally cycle through all tools - if (staticProperties.optionallyCycleToolsAtStart || staticProperties.measureToolsAtStart) { - var tools = getToolTable(); - if (tools.getNumberOfTools() > 0) { - writeln(""); - /* - writeOptionalBlock(mFormat.format(0), formatComment(localize("Read note"))); // wait for operator - writeComment(localize("With BLOCK DELETE turned off each tool will cycle through")); - writeComment(localize("the spindle to verify that the correct tool is in the tool magazine")); - if (staticProperties.measureToolsAtStart) { - writeComment(localize("and to automatically measure it")); - } - writeComment(localize("Once the tools are verified turn BLOCK DELETE on to skip verification")); - */ - - // 6/21/21 | Gavin Williams | will1742 - writeComment("Load and probe tools"); - writeBlock(gFormat.format(0), - gFormat.format(17), - gFormat.format(40), - gFormat.format(49), - gFormat.format(80), - gFormat.format(90), formatComment("Reset work plane, cancel all cycles and offsets")); - - displayMedia("Net Share/Media/toolProbeReminder.jpg"); - for (var i = 0; i < tools.getNumberOfTools(); ++i) { - var tool = tools.getTool(i); - if (staticProperties.measureToolsAtStart && (tool.type == TOOL_PROBE)) { - continue; - } - 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"); - } - comment += " - " + getToolTypeName(tool.type); - writeComment(comment); - writeComment(tool.description); - if (staticProperties.measureToolsAtStart) { - writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool - displayMedia("Net Share/Media/toolLoad" + tool.number + ".jpg"); - writeBlock(mFormat.format(0), formatComment("Load Tool")); //Pause until operator loads tool - writeToolMeasureBlock(tool, true); - } else { - writeToolCycleBlock(tool); - } - } - } - writeBlock(mFormat.format(131)); - writeln(""); - } - - if (staticProperties.useDWO) { - var failed = false; - var dynamicWCSs = {}; - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - var description = section.hasParameter("operation-comment") ? section.getParameter("operation-comment") : ("#" + (i + 1)); - if (!section.hasDynamicWorkOffset()) { - error(subst(localize("Dynamic work offset has not been set for operation '%1'."), description)); - failed = true; - } - - var o = section.getDynamicWCSOrigin(); - var p = section.getDynamicWCSPlane(); - if (dynamicWCSs[section.getDynamicWorkOffset()]) { - if ((Vector.diff(o, dynamicWCSs[section.getDynamicWorkOffset()].origin).length > 1e-9) || - (Matrix.diff(p, dynamicWCSs[section.getDynamicWorkOffset()].plane).n1 > 1e-9)) { - error(subst(localize("Dynamic WCS mismatch for operation '%1'."), description)); - failed = true; - } - } else { - dynamicWCSs[section.getDynamicWorkOffset()] = {origin:o, plane:p}; - } - } - if (failed) { - return; - } - } - - if (false) { - // check for duplicate tool number - for (var i = 0; i < getNumberOfSections(); ++i) { - var sectioni = getSection(i); - var tooli = sectioni.getTool(); - for (var j = i + 1; j < getNumberOfSections(); ++j) { - var sectionj = getSection(j); - var toolj = sectionj.getTool(); - if (tooli.number == toolj.number) { - if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || - xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || - abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || - (tooli.numberOfFlutes != toolj.numberOfFlutes)) { - error( - subst( - localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), - sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), - sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) - ) - ); - return; - } - } - } - } - } - - if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { - for (var i = 0; i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset > 0) { - error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); - return; - } - } - } - - // absolute coordinates and feed per min - writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17)); - - switch (unit) { - case IN: - writeBlock(gUnitModal.format(20)); - break; - case MM: - writeBlock(gUnitModal.format(21)); - break; - } - - coolantPressure = staticProperties.coolantPressure; - - if (staticProperties.chipTransport) { - onCommand(COMMAND_START_CHIP_TRANSPORT); - } - // Probing Surface Inspection - if (typeof inspectionWriteVariables == "function") { - inspectionWriteVariables(); - } -} - -function onComment(message) { - writeComment(message); -} - -/** Force output of X, Y, and Z. */ -function forceXYZ() { - xOutput.reset(); - yOutput.reset(); - zOutput.reset(); -} - -/** Force output of A, B, and C. */ -function forceABC() { - aOutput.reset(); - bOutput.reset(); - cOutput.reset(); -} - -function forceFeed() { - currentFeedId = undefined; - feedOutput.reset(); -} - -/** Force output of X, Y, Z, A, B, C, and F on next output. */ -function forceAny() { - forceXYZ(); - forceABC(); - forceFeed(); -} - -var lengthCompensationActive = false; -/** Disables length compensation if currently active or if forced. */ -function disableLengthCompensation(force, message) { - if (lengthCompensationActive || force) { - writeBlock(gFormat.format(49), conditional(message, formatComment(message))); - lengthCompensationActive = false; - } -} - -function writeG187() { - if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "drill")) { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } else if (hasParameter("operation:tolerance")) { - var tolerance = Math.max(getParameter("operation:tolerance"), 0); - if (tolerance > 0) { - var stockToLeaveThreshold = toUnit(0.1, MM); - var stockToLeave = 0; - var verticalStockToLeave = 0; - if (hasParameter("operation:stockToLeave")) { - stockToLeave = xyzFormat.getResultingValue(getParameter("operation:stockToLeave")); - } - if (hasParameter("operation:verticalStockToLeave")) { - verticalStockToLeave = xyzFormat.getResultingValue(getParameter("operation:verticalStockToLeave")); - } - - var workMode; - if (((stockToLeave > stockToLeaveThreshold) && (verticalStockToLeave > stockToLeaveThreshold)) || - (hasParameter("operation:strategy") && getParameter("operation:strategy") == "face")) { - workMode = 1; // roughing - } else { - if ((stockToLeave > 0) || (verticalStockToLeave > 0)) { - workMode = 2; // default - } else { - workMode = 3; // fine - } - } - writeBlock(gFormat.format(187), "P" + workMode); // set tolerance mode - // writeBlock(gFormat.format(187), "P" + workMode, "E" + xyzFormat.format(tolerance)); // set tolerance mode - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } - } else { - writeBlock(gFormat.format(187)); // reset G187 setting to machine default - } -} - -function FeedContext(id, description, feed) { - this.id = id; - this.description = description; - this.feed = feed; -} - -function getFeed(f) { - if (activeMovements) { - var feedContext = activeMovements[movement]; - if (feedContext != undefined) { - if (!feedFormat.areDifferent(feedContext.feed, f)) { - if (feedContext.id == currentFeedId) { - return ""; // nothing has changed - } - forceFeed(); - currentFeedId = feedContext.id; - return "F#" + (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("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_CUTTING] = feedContext; - activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext; - activeMovements[MOVEMENT_EXTENDED] = feedContext; - } - ++id; - if (movements & (1 << MOVEMENT_PREDRILL)) { - feedContext = new FeedContext(id, localize("Predrilling"), getParameter("operation: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("operation:finishFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting")) { - if (movements & (1 << MOVEMENT_FINISH_CUTTING)) { - var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:tool_feedCutting")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedEntry")) { - if (movements & (1 << MOVEMENT_LEAD_IN)) { - var feedContext = new FeedContext(id, localize("Entry"), getParameter("operation:tool_feedEntry")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_IN] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LEAD_OUT)) { - var feedContext = new FeedContext(id, localize("Exit"), getParameter("operation:tool_feedExit")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LEAD_OUT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:noEngagementFeedrate")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), getParameter("operation:noEngagementFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } else if (hasParameter("operation:tool_feedCutting") && - hasParameter("operation:tool_feedEntry") && - hasParameter("operation:tool_feedExit")) { - if (movements & (1 << MOVEMENT_LINK_DIRECT)) { - var feedContext = new FeedContext(id, localize("Direct"), Math.max(getParameter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), getParameter("operation:tool_feedExit"))); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_LINK_DIRECT] = feedContext; - } - ++id; - } - - if (hasParameter("operation:reducedFeedrate")) { - if (movements & (1 << MOVEMENT_REDUCED)) { - var feedContext = new FeedContext(id, localize("Reduced"), getParameter("operation:reducedFeedrate")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_REDUCED] = feedContext; - } - ++id; - } - - if (hasParameter("operation:tool_feedRamp")) { - if (movements & ((1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG))) { - var feedContext = new FeedContext(id, localize("Ramping"), getParameter("operation:tool_feedRamp")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_RAMP] = feedContext; - activeMovements[MOVEMENT_RAMP_HELIX] = feedContext; - activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext; - activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext; - } - ++id; - } - if (hasParameter("operation:tool_feedPlunge")) { - if (movements & (1 << MOVEMENT_PLUNGE)) { - var feedContext = new FeedContext(id, localize("Plunge"), getParameter("operation:tool_feedPlunge")); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_PLUNGE] = feedContext; - } - ++id; - } - if (true) { // high feed - if ((movements & (1 << MOVEMENT_HIGH_FEED)) || (highFeedMapping != HIGH_FEED_NO_MAPPING)) { - var feed; - if (hasParameter("operation:highFeedrateMode") && getParameter("operation:highFeedrateMode") != "disabled") { - feed = getParameter("operation:highFeedrate"); - } else { - feed = toPreciseUnit(this.highFeedrate, MM); - } - var feedContext = new FeedContext(id, localize("High Feed"), feed); - activeFeeds.push(feedContext); - activeMovements[MOVEMENT_HIGH_FEED] = feedContext; - activeMovements[MOVEMENT_RAPID] = feedContext; - } - ++id; - } - - for (var i = 0; i < activeFeeds.length; ++i) { - var feedContext = activeFeeds[i]; - writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description)); - } -} - -var currentWorkPlaneABC = undefined; -var activeG254 = false; - -function forceWorkPlane() { - currentWorkPlaneABC = undefined; -} - -function defineWorkPlane(_section, _setWorkPlane) { - var abc = new Vector(0, 0, 0); - if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode - // set working plane after datum shift - - if (_section.isMultiAxis()) { - cancelTransformation(); - abc = _section.getInitialToolAxisABC(); - if (_setWorkPlane) { - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - if (!retracted) { - moveToSafeRetractPosition(); - } - forceWorkPlane(); - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - } - } else { - abc = getWorkPlaneMachineABC(_section.workPlane, _setWorkPlane); - if (_setWorkPlane) { - setWorkPlane(abc); - } - } - } else { // pure 3D - var remaining = _section.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - error(localize("Tool orientation is not supported.")); - return abc; - } - setRotation(remaining); - } - return abc; -} - -function setWorkPlane(abc) { - if (!machineConfiguration.isMultiAxisConfiguration()) { - return; // ignore - } - - var _skipBlock = false; - if (!((currentWorkPlaneABC == undefined) || - abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || - abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || - abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { - if (operationNeedsSafeStart) { - _skipBlock = true; - } else { - return; // no change - } - } - skipBlock = _skipBlock; - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(false); - } - - if (activeG254) { - skipBlock = _skipBlock; - activeG254 = false; - writeBlock(gFormat.format(255)); // cancel DWO - } - - gMotionModal.reset(); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) - ); - - skipBlock = _skipBlock; - onCommand(COMMAND_LOCK_MULTI_AXIS); - - if (staticProperties.useDWO && - (abcFormat.isSignificant(abc.x % (Math.PI * 2)) || abcFormat.isSignificant(abc.y % (Math.PI * 2)) || abcFormat.isSignificant(abc.z % (Math.PI * 2)))) { - skipBlock = _skipBlock; - activeG254 = true; - writeBlock(gFormat.format(254)); // enable DWO - } - - setCurrentABC(abc); // required for machine simulation - currentWorkPlaneABC = abc; -} - -var closestABC = true; // choose closest machine angles -var currentMachineABC = new Vector(0, 0, 0); - -function getPreferenceWeight(_abc) { - var axis = new Array(machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()); - var abc = new Array(_abc.x, _abc.y, _abc.z); - var preference = 0; - for (var i = 0; i < 3; ++i) { - if (axis[i].isEnabled()) { - preference += ((abcFormat.getResultingValue(abc[axis[i].getCoordinate()]) * axis[i].getPreference()) < 0) ? -1 : 1; - } - } - return preference; -} - -function remapToABC(currentABC, previousABC) { - var both = machineConfiguration.getABCByDirectionBoth(machineConfiguration.getDirection(currentABC)); - var abc1 = machineConfiguration.remapToABC(both[0], previousABC); - abc1 = machineConfiguration.remapABC(abc1); - var abc2 = machineConfiguration.remapToABC(both[1], previousABC); - abc2 = machineConfiguration.remapABC(abc2); - - // choose angles based on preference - var preference1 = getPreferenceWeight(abc1); - var preference2 = getPreferenceWeight(abc2); - if (preference1 > preference2) { - return abc1; - } else if (preference2 > preference1) { - return abc2; - } - - // choose angles based on closest solution - if (Vector.diff(abc1, previousABC).length < Vector.diff(abc2, previousABC).length) { - return abc1; - } else { - return abc2; - } -} - -function getWorkPlaneMachineABC(workPlane, _setWorkPlane) { - var W = workPlane; // map to global frame - - var abc = machineConfiguration.getABC(W); - if (closestABC) { - if (currentMachineABC) { - abc = remapToABC(abc, currentMachineABC); - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - } else { - abc = machineConfiguration.getPreferredABC(abc); - } - - try { - abc = machineConfiguration.remapABC(abc); - if (_setWorkPlane) { - currentMachineABC = abc; - } - } catch (e) { - error( - localize("Machine angles not supported") + ":" - + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - 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" + abcFormat.format(abc.x)) - + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) - + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) - ); - } - - var tcp = false; - if (tcp) { - setRotation(W); // TCP mode - } else { - var O = machineConfiguration.getOrientation(abc); - var R = machineConfiguration.getRemainingOrientation(abc, W); - setRotation(R); - } - - return abc; -} - -function printProbeResults() { - return currentSection.getParameter("printResults", 0) == 1; -} - -function onPassThrough(text) { - var commands = String(text).split(","); - for (text in commands) { - writeBlock(commands[text]); - } -} - -function onManualNC(command, value) { - switch (command) { - case COMMAND_ACTION: - if (String(value).toUpperCase() == "CYCLE_REVERSAL") { - cycleReverse = true; - } else if (String(value).toUpperCase() == "VFD_LOW") { - coolantPressure = "P0"; - } else if (String(value).toUpperCase() == "VFD_NORMAL") { - coolantPressure = "P1"; - } else if (String(value).toUpperCase() == "VFD_HIGH") { - coolantPressure = "P2"; - } else if (String(value).toUpperCase() == "USEPOLARMODE") { - usePolarMode = true; - } - break; - default: - expandManualNC(command, value); - } -} - -var probeOutputWorkOffset = 1; -var stockTopZ = -1; -var stockUpperX; -var stockLowerX; -var stockUpperY; -var stockLowerY; - -function onParameter(name, value) { - if (name == "probe-output-work-offset") { - probeOutputWorkOffset = (value > 0) ? value : 1; - } - - // Added 6/15/21 | Gavin Williams | will1742 - // Issue 001 Input and Validation - if (name == "stock-upper-z") { - stockTopZ = value; - } - if (name == "stock-upper-x") { - stockUpperX = value; - } - if (name == "stock-lower-x") { - stockLowerX = value; - } - if (name == "stock-upper-y") { - stockUpperY = value; - } - if (name == "stock-lower-y") { - stockLowerY = value; - } -} - -var seenPatternIds = {}; - -function previewImage() { - var permittedExtensions = ["JPG", "MP4", "MOV", "PNG", "JPEG"]; - var patternId = currentSection.getPatternId(); - var show = false; - if (!seenPatternIds[patternId]) { - show = true; - seenPatternIds[patternId] = true; - } - var images = []; - if (show) { - if (FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath))) { - images.push(modelImagePath); - } - if (hasParameter("autodeskcam:preview-name") && FileSystem.isFile(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), getParameter("autodeskcam:preview-name")))) { - images.push(getParameter("autodeskcam:preview-name")); - } - - for (var i = 0; i < images.length; ++i) { - var fileExtension = images[i].slice(images[i].lastIndexOf(".") + 1, images[i].length).toUpperCase(); - var permittedExtension = false; - for (var j = 0; j < permittedExtensions.length; ++j) { - if (fileExtension == permittedExtensions[j]) { - permittedExtension = true; - break; // found - } - } - if (!permittedExtension) { - warning(localize("The image file format " + "\"" + fileExtension + "\"" + " is not supported on HAAS controls.")); - } - - if (!staticProperties.useM130PartImages || !permittedExtension) { - FileSystem.remove(FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), images[i])); // remove - images.splice([i], 1); // remove from array - } - } - if (images.length > 0) { - writeBlock(mFormat.format(130), "(" + images[images.length - 1] + ")"); - } - } -} - -/** Returns true if the spatial vectors are significantly different. */ -function areSpatialVectorsDifferent(_vector1, _vector2) { - return (xyzFormat.getResultingValue(_vector1.x) != xyzFormat.getResultingValue(_vector2.x)) || - (xyzFormat.getResultingValue(_vector1.y) != xyzFormat.getResultingValue(_vector2.y)) || - (xyzFormat.getResultingValue(_vector1.z) != xyzFormat.getResultingValue(_vector2.z)); -} - -/** Returns true if the spatial boxes are a pure translation. */ -function areSpatialBoxesTranslated(_box1, _box2) { - return !areSpatialVectorsDifferent(Vector.diff(_box1[1], _box1[0]), Vector.diff(_box2[1], _box2[0])) && - !areSpatialVectorsDifferent(Vector.diff(_box2[0], _box1[0]), Vector.diff(_box2[1], _box1[1])); -} - -/** Returns true if the spatial boxes are same. */ -function areSpatialBoxesSame(_box1, _box2) { - return !areSpatialVectorsDifferent(_box1[0], _box2[0]) && !areSpatialVectorsDifferent(_box1[1], _box2[1]); -} - -function subprogramDefine(_initialPosition, _abc, _retracted, _zIsOutput) { - // convert patterns into subprograms - var usePattern = false; - patternIsActive = false; - if (currentSection.isPatterned && currentSection.isPatterned() && (getProperty("useSubroutines") == "patterns")) { - currentPattern = currentSection.getPatternId(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_PATTERN) && (currentPattern == definedPatterns[i].patternId)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_PATTERN); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_PATTERN, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: _initialPosition - }); - } - - if (usePattern) { - // make sure Z-position is output prior to subprogram call - if (!_retracted && !_zIsOutput) { - writeBlock(gMotionModal.format(0), zOutput.format(_initialPosition.z)); - } - - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - patternIsActive = true; - - if (firstPattern) { - subprogramStart(_initialPosition, _abc, incrementalSubprogram); - } else { - skipRemainingSection(); - setCurrentPosition(getFramePosition(currentSection.getFinalPosition())); - } - } - } - - // Output cycle operation as subprogram - if (!usePattern && (getProperty("useSubroutines") == "cycles") && currentSection.doesStrictCycle && - (currentSection.getNumberOfCycles() == 1) && currentSection.getNumberOfCyclePoints() >= minimumCyclePoints) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - currentPattern = currentSection.getNumberOfCyclePoints(); - firstPattern = true; - for (var i = 0; i < definedPatterns.length; ++i) { - if ((definedPatterns[i].patternType == SUB_CYCLE) && (currentPattern == definedPatterns[i].patternId) && - !areSpatialVectorsDifferent(_initialPosition, definedPatterns[i].initialPosition) && - !areSpatialVectorsDifferent(finalPosition, definedPatterns[i].finalPosition)) { - currentSubprogram = definedPatterns[i].subProgram; - usePattern = definedPatterns[i].validPattern; - firstPattern = false; - break; - } - } - - if (firstPattern) { - // determine if this is a valid pattern for creating a subprogram - usePattern = subprogramIsValid(currentSection, currentPattern, SUB_CYCLE); - if (usePattern) { - currentSubprogram = ++lastSubprogram; - } - definedPatterns.push({ - patternType: SUB_CYCLE, - patternId: currentPattern, - subProgram: currentSubprogram, - validPattern: usePattern, - initialPosition: _initialPosition, - finalPosition: finalPosition - }); - } - cycleSubprogramIsActive = usePattern; - } - - // Output each operation as a subprogram - if (!usePattern && (getProperty("useSubroutines") == "allOperations")) { - currentSubprogram = ++lastSubprogram; - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - firstPattern = true; - subprogramStart(_initialPosition, _abc, false); - } -} - -function subprogramStart(_initialPosition, _abc, _incremental) { - redirectToBuffer(); - var comment = ""; - if (hasParameter("operation-comment")) { - comment = getParameter("operation-comment"); - } - writeln( - "N" + nFormat.format(currentSubprogram) + - conditional(comment, formatComment(comment.substr(0, maximumLineLength - 2 - 6 - 1))) - ); - staticProperties.showSequenceNumbers = false; - if (_incremental) { - setIncrementalMode(_initialPosition, _abc); - } - gPlaneModal.reset(); - gMotionModal.reset(); -} - -function subprogramEnd() { - if (firstPattern) { - writeBlock(mFormat.format(99)); - writeln(""); - subprograms += getRedirectionBuffer(); - } - forceAny(); - firstPattern = false; - staticProperties.showSequenceNumbers = saveShowSequenceNumbers; - closeRedirection(); -} - -function subprogramIsValid(_section, _patternId, _patternType) { - var sectionId = _section.getId(); - var numberOfSections = getNumberOfSections(); - var validSubprogram = _patternType != SUB_CYCLE; - - var masterPosition = new Array(); - masterPosition[0] = getFramePosition(_section.getInitialPosition()); - masterPosition[1] = getFramePosition(_section.getFinalPosition()); - var tempBox = _section.getBoundingBox(); - var masterBox = new Array(); - masterBox[0] = getFramePosition(tempBox[0]); - masterBox[1] = getFramePosition(tempBox[1]); - - var rotation = getRotation(); - var translation = getTranslation(); - incrementalSubprogram = undefined; - - for (var i = 0; i < numberOfSections; ++i) { - var section = getSection(i); - if (section.getId() != sectionId) { - defineWorkPlane(section, false); - // check for valid pattern - if (_patternType == SUB_PATTERN) { - if (section.getPatternId() == _patternId) { - var patternPosition = new Array(); - patternPosition[0] = getFramePosition(section.getInitialPosition()); - patternPosition[1] = getFramePosition(section.getFinalPosition()); - tempBox = section.getBoundingBox(); - var patternBox = new Array(); - patternBox[0] = getFramePosition(tempBox[0]); - patternBox[1] = getFramePosition(tempBox[1]); - - if (areSpatialBoxesSame(masterPosition, patternPosition) && areSpatialBoxesSame(masterBox, patternBox) && !section.isMultiAxis()) { - incrementalSubprogram = incrementalSubprogram ? incrementalSubprogram : false; - } else if (!areSpatialBoxesTranslated(masterPosition, patternPosition) || !areSpatialBoxesTranslated(masterBox, patternBox)) { - validSubprogram = false; - break; - } else { - incrementalSubprogram = true; - } - } - - // check for valid cycle operation - } else if (_patternType == SUB_CYCLE) { - if ((section.getNumberOfCyclePoints() == _patternId) && (section.getNumberOfCycles() == 1)) { - var patternInitial = getFramePosition(section.getInitialPosition()); - var patternFinal = getFramePosition(section.getFinalPosition()); - if (!areSpatialVectorsDifferent(patternInitial, masterPosition[0]) && !areSpatialVectorsDifferent(patternFinal, masterPosition[1])) { - validSubprogram = true; - break; - } - } - } - } - } - setRotation(rotation); - setTranslation(translation); - return (validSubprogram); -} - -function setAxisMode(_format, _output, _prefix, _value, _incr) { - var i = _output.isEnabled(); - if (_output == zOutput) { - _output = _incr ? createIncrementalVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format) : createVariable({onchange: function() {retracted = false;}, prefix: _prefix}, _format); - } else { - _output = _incr ? createIncrementalVariable({prefix: _prefix}, _format) : createVariable({prefix: _prefix}, _format); - } - _output.format(_value); - _output.format(_value); - i = i ? _output.enable() : _output.disable(); - return _output; -} - -function setIncrementalMode(xyz, abc) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, true); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, true); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, true); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, true); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, true); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, true); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(91)); - incrementalMode = true; -} - -function setAbsoluteMode(xyz, abc) { - if (incrementalMode) { - xOutput = setAxisMode(xyzFormat, xOutput, "X", xyz.x, false); - yOutput = setAxisMode(xyzFormat, yOutput, "Y", xyz.y, false); - zOutput = setAxisMode(xyzFormat, zOutput, "Z", xyz.z, false); - aOutput = setAxisMode(abcFormat, aOutput, "A", abc.x, false); - bOutput = setAxisMode(abcFormat, bOutput, "B", abc.y, false); - cOutput = setAxisMode(abcFormat, cOutput, "C", abc.z, false); - gAbsIncModal.reset(); - writeBlock(gAbsIncModal.format(90)); - incrementalMode = false; - } -} - -function onSection() { - // 07/06/21 | Gavin Williams | will1742 - // 002 Improved Probing - // uses pencil to verify WCS, prompts user - if (isFirstSection() && getProperty("pencilWCSValidation")) { - var stockMidX = (stockUpperX + stockLowerX)/2; - var stockMidY = (stockUpperY + stockLowerY)/2; - writeln(""); - writeComment("Verify WCS"); - writeBlock("T" + toolFormat.format(19), mFormat.format(6)); //Changes Tool - - writeBlock(gFormat.format(55), gFormat.format(0), xOutput.format(stockMidX), yOutput.format(stockMidY)); - displayMedia("Net Share/Media/xyWCSCheck.jpg"); - writeBlock(mFormat.format(0), formatComment("Open door")); - displayMedia("Net Share/Media/checkPrompt.jpg"); - var gotoRef = takeInput("Is the pencil centered above your stock? stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - - writeBlock(gFormat.format(55), gFormat.format(43), hFormat.format(19), zOutput.format(stockTopZ)); - displayMedia("Net Share/Media/zWCSCheck.jpg"); - writeBlock(mFormat.format(0), formatComment("Open door")); - displayMedia("Net Share/Media/checkPrompt.jpg"); - gotoRef = takeInput("Is the pencil touching the center of your stock? [Y/N]", ['N', 'Y']); - - writeWords("N" + nFormat.format(gotoRef['N']), mFormat.format(131)); - writeWords(mFormat.format(02), formatComment("Halt Program")); - - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - } - - - var forceToolAndRetract = optionalSection && !currentSection.isOptional(); - optionalSection = currentSection.isOptional(); - - var insertToolCall = isFirstSection() || - currentSection.getForceToolChange && currentSection.getForceToolChange() || - (tool.number != getPreviousSection().getTool().number); - - retracted = false; - - var zIsOutput = false; // true if the Z-position has been output, used for patterns - var newWorkOffset = isFirstSection() || - (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes - var newWorkPlane = isFirstSection() || - !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || - (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && - Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || - (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || - (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || - getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations - - operationNeedsSafeStart = staticProperties.safeStartAllOperations && !isFirstSection(); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.fastToolChange && !isProbeOperation()) { - currentCoolantMode = COOLANT_OFF; - } else if (insertToolCall) { // no coolant off command if safe start operation - onCommand(COMMAND_COOLANT_OFF); - } - } - - if ((insertToolCall && !staticProperties.fastToolChange) || newWorkOffset || newWorkPlane || toolChecked) { - - // stop spindle before retract during tool change - if (insertToolCall && !isFirstSection() && !toolChecked && !staticProperties.fastToolChange) { - onCommand(COMMAND_STOP_SPINDLE); - } - - // retract to safe plane - writeRetract(Z); - - if (forceResetWorkPlane && newWorkPlane) { - forceWorkPlane(); - setWorkPlane(new Vector(0, 0, 0)); // reset working plane - } - } - - if (hasParameter("operation-comment")) { - var comment = getParameter("operation-comment"); - if (comment && ((comment !== lastOperationComment) || !patternIsActive || insertToolCall)) { - writeln(""); - writeComment(comment); - lastOperationComment = comment; - } else if (!patternIsActive || insertToolCall) { - writeln(""); - } - } else { - writeln(""); - } - - if (staticProperties.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); - } - } - } - } - - // enable polar interpolation - if (usePolarMode && (tool.type != TOOL_PROBE)) { - if (polarDirection == undefined) { - error(localize("Polar direction property must be a vector - x,y,z.")); - return; - } - setPolarMode(currentSection, true); - } - - defineWorkPlane(currentSection, false); - var initialPosition = getFramePosition(currentSection.getInitialPosition()); - forceAny(); - - // Added 06/15/21 | Gavin Williams | Will1742 - var onSecGotoRef = sequenceNumber; - - if (operationNeedsSafeStart) { - if (!retracted) { - // skipBlock = true; - writeRetract(Z); - } - } - - if (insertToolCall || operationNeedsSafeStart) { - - if (staticProperties.useM130PartImages) { - writeBlock(mFormat.format(130), "(tool" + tool.number + ".png)"); - } - - if (!isFirstSection() && staticProperties.optionalStop && insertToolCall) { - onCommand(COMMAND_OPTIONAL_STOP); - } - - if ((tool.number > 200 && tool.number < 1000) || tool.number > 9999) { - warning(localize("Tool number out of range.")); - } - - skipBlock = !insertToolCall; - writeToolBlock( - "T" + toolFormat.format(tool.number), - mFormat.format(6) - ); - if (tool.comment) { - writeComment(tool.comment); - } - if (measureTool) { - writeToolMeasureBlock(tool, false); - } - if (insertToolCall) { - forceWorkPlane(); - } - 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") + "=" + xyzFormat.format(zRange.getMinimum())); - } - } - } - - // activate those two coolant modes before the spindle is turned on - if ((tool.coolant == COOLANT_THROUGH_TOOL) || (tool.coolant == COOLANT_AIR_THROUGH_TOOL) || (tool.coolant == COOLANT_FLOOD_THROUGH_TOOL)) { - if (!isFirstSection() && !insertToolCall && (currentCoolantMode != tool.coolant)) { - onCommand(COMMAND_STOP_SPINDLE); - forceSpindleSpeed = true; - } - setCoolant(tool.coolant); - } else if ((currentCoolantMode == COOLANT_THROUGH_TOOL) || (currentCoolantMode == COOLANT_AIR_THROUGH_TOOL) || (currentCoolantMode == COOLANT_FLOOD_THROUGH_TOOL)) { - onCommand(COMMAND_STOP_SPINDLE); - setCoolant(COOLANT_OFF); - forceSpindleSpeed = true; - } - - if (toolChecked) { - forceSpindleSpeed = true; // spindle must be restarted if tool is checked without a tool change - toolChecked = false; // state of tool is not known at the beginning of a section since it could be broken for the previous section - } - var spindleChanged = tool.type != TOOL_PROBE && - (insertToolCall || forceSpindleSpeed || isFirstSection() || - (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || - (tool.clockwise != getPreviousSection().getTool().clockwise)); - if (spindleChanged || (operationNeedsSafeStart && tool.type != TOOL_PROBE)) { - forceSpindleSpeed = false; - - if (spindleSpeed < 1) { - error(localize("Spindle speed out of range.")); - return; - } - maximumSpindleRPM = machineConfiguration.getMaximumSpindleSpeed() > 0 ? machineConfiguration.getMaximumSpindleSpeed() : maximumSpindleRPM; - if (spindleSpeed > maximumSpindleRPM) { - warning(subst(localize("Spindle speed '" + spindleSpeed + " RPM' exceeds maximum value of '%1 RPM."), maximumSpindleRPM)); - } - // skipBlock = !spindleChanged; - writeBlock( - sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) - ); - } - - previewImage(); - - if (staticProperties.useParametricFeed && - hasParameter("operation-strategy") && - (getParameter("operation-strategy") != "drill") && // legacy - !(currentSection.hasAnyCycle && currentSection.hasAnyCycle())) { - if (!insertToolCall && - activeMovements && - (getCurrentSectionId() > 0) && - ((getPreviousSection().getPatternId() == currentSection.getPatternId()) && (currentSection.getPatternId() != 0))) { - // use the current feeds - } else { - initializeActiveFeeds(); - } - } else { - activeMovements = undefined; - } - - // wcs - if (insertToolCall || operationNeedsSafeStart) { // force work offset when changing tool - currentWorkOffset = undefined; - skipBlock = operationNeedsSafeStart && !newWorkOffset && !insertToolCall; - } - 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 > 6) { - var code = workOffset - 6; - if (code > 99) { - error(localize("Work offset out of range.")); - return; - } - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(154), "P" + code); - currentWorkOffset = workOffset; - } - } else { - if (workOffset != currentWorkOffset) { - if (!skipBlock) { - forceWorkPlane(); - } - writeBlock(gFormat.format(53 + workOffset)); // G54->G59 - currentWorkOffset = workOffset; - } - } - } - - if (newWorkPlane || (insertToolCall && !retracted)) { // go to home position for safety - if (!retracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing && machineConfiguration.isMultiAxisConfiguration()) { - writeRetract(X, Y); - } - } - - // Unwind axis if previous section was Multi-Axis - if (!isFirstSection() && (getPreviousSection().isMultiAxis() || usePolarMode) && machineConfiguration.isMachineCoordinate(2)) { // TAG - if (!retracted) { - moveToSafeRetractPosition(); - } - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - currentMachineABC.setZ(0); - } - - if (newWorkOffset) { - forceWorkPlane(); - } - - var abc = defineWorkPlane(currentSection, true); - - setProbeAngle(); // output probe angle rotations if required - - gMotionModal.reset(); - - if (staticProperties.useG187) { - writeG187(); - } - - var G = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? 1 : 0; - var F = ((highFeedMapping != HIGH_FEED_NO_MAPPING) || !staticProperties.useG0) ? getFeed(toPreciseUnit(highFeedrate, MM)) : ""; - if (insertToolCall || retracted || operationNeedsSafeStart || !lengthCompensationActive || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))) { - var _skipBlock = !(insertToolCall || retracted || - (!isFirstSection() && (currentSection.isMultiAxis() != getPreviousSection().isMultiAxis()))); - var lengthOffset = tool.lengthOffset; - if ((lengthOffset > 200 && lengthOffset < 1000) || lengthOffset > 9999) { - error(localize("Length offset out of range.")); - return; - } - - gMotionModal.reset(); - writeBlock(gPlaneModal.format(17)); - - if (usePolarMode) { - if (!retracted) { - skipBlock = _skipBlock; - moveToSafeRetractPosition(); - } - var polarPosition = getPolarPosition(initialPosition.x, initialPosition.y, initialPosition.z); - setCurrentPositionAndDirection(polarPosition); - initialPosition = new Vector(polarPosition.first.x, polarPosition.first.y, polarPosition.first.z); - writeBlock(gMotionModal.format(0), aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - } - - if (!machineConfiguration.isHeadConfiguration()) { - if (tcpIsSupported && useDwoForPositioning && currentSection.isMultiAxis()) { - var O = machineConfiguration.getOrientation(abc); - var initialPositionDWO = O.getTransposed().multiply(getGlobalPosition(currentSection.getInitialPosition())); - // writeComment("PREPOSITIONING START"); - skipBlock = _skipBlock; - writeBlock(gFormat.format(254)); - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPositionDWO.x), yOutput.format(initialPositionDWO.y), F); - skipBlock = _skipBlock; - writeBlock(gFormat.format(255)); - // writeComment("PREPOSITIONING END"); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), // G0 motion mode is required for the G234 command - gFormat.format(234), - xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } else { - skipBlock = _skipBlock; - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y), F); - skipBlock = _skipBlock; - writeBlock( - gMotionModal.format(0), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - } - } else { - skipBlock = _skipBlock; - writeBlock( - gAbsIncModal.format(90), - gMotionModal.format(currentSection.isMultiAxis() && tcpIsSupported ? 0 : G), - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - xOutput.format(initialPosition.x), - yOutput.format(initialPosition.y), - zOutput.format(initialPosition.z), - F, - hFormat.format(lengthOffset) - ); - } - zIsOutput = true; - lengthCompensationActive = true; - if (_skipBlock) { - forceXYZ(); - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - if (gMotionModal.getCurrent() == 0) { - forceFeed(); - } - gMotionModal.reset(); - } else { - validate(lengthCompensationActive, "Length compensation is not active."); - if (getCurrentPosition().z < initialPosition.z) { - writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); - zIsOutput = true; - } - var x = xOutput.format(initialPosition.x); - var y = yOutput.format(initialPosition.y); - if (x && y) { - // axes are not synchronized - writeBlock(gAbsIncModal.format(90), gMotionModal.format(G), x, y, F); - } else { - writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), x, y); - } - } - - validate(lengthCompensationActive, "Length compensation is not active."); - - if (insertToolCall || operationNeedsSafeStart) { - if (staticProperties.preloadTool) { - var nextTool = getNextTool(tool.number); - if (nextTool) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(nextTool.number)); - } else { - // preload first tool - var section = getSection(0); - var firstToolNumber = section.getTool().number; - if (tool.number != firstToolNumber) { - skipBlock = !insertToolCall; - writeBlock("T" + toolFormat.format(firstToolNumber)); - } - } - } - } - - if (isProbeOperation()) { - validate(probeVariables.probeAngleMethod != "G68", "You cannot probe while G68 Rotation is in effect."); - validate(probeVariables.probeAngleMethod != "G54.4", "You cannot probe while workpiece setting error compensation G54.4 is enabled."); - writeBlock(gFormat.format(65), "P" + 9832); // spin the probe on - inspectionCreateResultsFileHeader(); - } else { - // surface Inspection - if (isInspectionOperation() && (typeof inspectionProcessSectionStart == "function")) { - inspectionProcessSectionStart(); - } - } - - if (getProperty("toolHeightValidation")) { - writeComment("BEGIN VALIDATION SECTION"); - // Added 06/15/21 | Gavin Williams | will1742 - // Verifies tool-stock distance. Post fails if tool fails clearance standards - if (toolDistance < CLEARANCE_HEIGHT) { - throw "Error: Clearance height must be " + CLEARANCE_HEIGHT + " or more inches from stock"; - } - - if (toolDistance == Infinity) { - throw "Error: invalid tool distance. Contact a TA."; - } - var toolDistance = initialPosition.z - stockTopZ; - - // Prompt user to check stock-tool distance - displayMedia("Net Share/Media/checkDistance.jpg"); - writeBlock(mFormat.format(0), formatComment("Open door")); - displayMedia("Net Share/Media/checkPrompt.jpg"); - - // asks user if measured height is accurate to displayed - var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['N', 'Y']); - - // Create GOTO cases for Y/N selection, halt if N - getTA("Net Share/Media/TAWarning.jpg", gotoRef['N'], onSecGotoRef); - writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); - writeWords( - conditional(!currentSection.isMultiAxis() || !tcpIsSupported, gFormat.format(43)), - conditional(currentSection.isMultiAxis() && tcpIsSupported, gFormat.format(234)), - zOutput.format(initialPosition.z), - hFormat.format(lengthOffset) - ); - writeComment("END VALIDATION SECTION"); - - // initialize spindle and engage coolant if heights are correct - if (tool.type != TOOL_PROBE) { - writeBlock(mFormat.format((tool.clockwise ? 3 : 4)), formatComment("Restart spindle")); - } - } - - if (tool.type != TOOL_PROBE) { - setCoolant(tool.coolant); - } - - // define subprogram - subprogramDefine(initialPosition, abc, retracted, zIsOutput); -} - -// Added 6/14/21 | Gavin Williams | will1742 -// Issue 001 Input and Validation -// Displays a file: MP4, MOV, PNG, JPEG. 1920x1080 -// Input: Absolute path to file -function displayMedia(file) { - writeBlock(mFormat.format(130), formatComment(file)); -} - -// Added 6/14/21 | Gavin Williams | will1742 -// Issue 001 Input and Validation -// Takes input from the user -// Input: string prompt, will be displayed to users -// char array options, capital letters accepted as input -// int opSeqNum, optional arg to init prompt at specific value -// Output: 2D dict {Letter, Coorresponding GOTO} -// EX: [Y, 56][N, 57] -var macroNumber = 500; -function takeInput(prompt, options) { - - // Cycle through macro variables, reset at end of general purpose vars - if (macroNumber > 549) macroNumber = 500; - - // init macro var to 0 - setMacro(macroNumber, 0, "Initialize macro variable"); - - // disply prompt and save response - writeBlock(mFormat.format(109), "P" + nFormat.format(macroNumber), formatComment(prompt)); - sequenceNumber -= staticProperties.sequenceNumberIncrement; - var gotoRef = sequenceNumber; - - // wait for input - writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + nFormat.format(gotoRef) + " " + formatComment("NULL")); - - // print if's and goto's - var gotoMap = {}; - var gotoInc = 1; - options.forEach(function (element) { - writeWords("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc), formatComment(element)); - gotoMap[element] = (sequenceNumber + gotoInc); - gotoInc += 1; - }); - - var incNum = staticProperties.sequenceNumberIncrement; - // adjust sequence number if needed - for (i = incNum; i < gotoInc; i+=incNum) { - sequenceNumber += staticProperties.sequenceNumberIncrement; - } - - // return to input until valid option is entered - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("INVALID INPUT")); - - // increase var number, iterate sequence number - macroNumber += 1; - sequenceNumber += staticProperties.sequenceNumberIncrement; - return gotoMap; -} - -// Added 06/15/21 | Gavin Williamas | will1742 -// Issue 001 Input and validation -// Halts program until TA arrives. Jumps to gotoRef -function getTA(file, seqNum, gotoRef) { - writeWords("N" + nFormat.format(seqNum), - gFormat.format(53), gFormat.format(0), zOutput.format(0.), - formatComment("Retract spindle")); - writeWords(mFormat.format(130), formatComment(file)); - writeWords(mFormat.format(0), formatComment("Halt Program")); - writeWords(mFormat.format(131)); - writeWords("GOTO" + nFormat.format(gotoRef), formatComment("Return to beginning of operation")); -} - -function onDwell(seconds) { - if (seconds > 99999.999) { - warning(localize("Dwelling time is out of range.")); - } - seconds = clamp(0.001, seconds, 99999.999); - writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + milliFormat.format(seconds * 1000)); -} - -function onSpindleSpeed(spindleSpeed) { - writeBlock(sOutput.format(spindleSpeed)); -} - -function onCycle() { - writeBlock(gPlaneModal.format(17)); -} - -function getCommonCycle(x, y, z, r, c) { - forceXYZ(); - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - return [xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), - zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), - bOutput.format(polarPosition.second.y), - cOutput.format(polarPosition.second.z), - "R" + xyzFormat.format(r)]; - } else { - if (incrementalMode) { - zOutput.format(c); - return [xOutput.format(x), yOutput.format(y), - "Z" + xyzFormat.format(z - r), - "R" + xyzFormat.format(r - c)]; - } else { - return [xOutput.format(x), yOutput.format(y), - zOutput.format(z), - "R" + xyzFormat.format(r)]; - } - } -} - -function setCyclePosition(_position) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - zOutput.format(_position); - break; - case 18: // ZX - yOutput.format(_position); - break; - case 19: // YZ - xOutput.format(_position); - break; - } -} - -/** Convert approach to sign. */ -function approach(value) { - validate((value == "positive") || (value == "negative"), "Invalid approach."); - return (value == "positive") ? 1 : -1; -} - -function setProbeAngleMethod() { - probeVariables.probeAngleMethod = (machineConfiguration.getNumberOfAxes() < 5 || is3D()) ? (getProperty("useG54x4") ? "G54.4" : "G68") : "UNSUPPORTED"; - var axes = [machineConfiguration.getAxisU(), machineConfiguration.getAxisV(), machineConfiguration.getAxisW()]; - for (var i = 0; i < axes.length; ++i) { - if (axes[i].isEnabled() && isSameDirection((axes[i].getAxis()).getAbsolute(), new Vector(0, 0, 1)) && axes[i].isTable()) { - probeVariables.probeAngleMethod = "AXIS_ROT"; - probeVariables.rotationalAxis = axes[i].getCoordinate(); - break; - } - } - probeVariables.outputRotationCodes = true; -} - -/** Output rotation offset based on angular probing cycle. */ -function setProbeAngle() { - if (probeVariables.outputRotationCodes) { - validate(probeOutputWorkOffset <= 6, "Angular Probing only supports work offsets 1-6."); - if (probeVariables.probeAngleMethod == "G68" && (Vector.diff(currentSection.getGlobalInitialToolAxis(), new Vector(0, 0, 1)).length > 1e-4)) { - error(localize("You cannot use multi axis toolpaths while G68 Rotation is in effect.")); - } - var validateWorkOffset = false; - switch (probeVariables.probeAngleMethod) { - case "G54.4": - var param = 26000 + (probeOutputWorkOffset * 10); - writeBlock("#" + param + "=#135"); - writeBlock("#" + (param + 1) + "=#136"); - writeBlock("#" + (param + 5) + "=#144"); - writeBlock(gFormat.format(54.4), "P" + probeOutputWorkOffset); - break; - case "G68": - gRotationModal.reset(); - gAbsIncModal.reset(); - writeBlock(gRotationModal.format(68), gAbsIncModal.format(90), probeVariables.compensationXY, "R[#194]"); - validateWorkOffset = true; - break; - case "AXIS_ROT": - var param = 5200 + probeOutputWorkOffset * 20 + probeVariables.rotationalAxis + 4; - writeBlock("#" + param + " = " + "[#" + param + " + #194]"); - forceWorkPlane(); // force workplane to rotate ABC in order to apply rotation offsets - currentWorkOffset = undefined; // force WCS output to make use of updated parameters - validateWorkOffset = true; - break; - default: - error(localize("Angular Probing is not supported for this machine configuration.")); - return; - } - if (validateWorkOffset) { - for (var i = currentSection.getId(); i < getNumberOfSections(); ++i) { - if (getSection(i).workOffset != currentSection.workOffset) { - error(localize("WCS offset cannot change while using angle rotation compensation.")); - return; - } - } - } - probeVariables.outputRotationCodes = false; - } -} - -function protectedProbeMove(_cycle, x, y, z) { - var _x = xOutput.format(x); - var _y = yOutput.format(y); - var _z = zOutput.format(z); - if (_z && z >= getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } - if (_x || _y) { - writeBlock(gFormat.format(65), "P" + 9810, _x, _y, getFeed(toPreciseUnit(highFeedrate, MM))); // protected positioning move - } - if (_z && z < getCurrentPosition().z) { - writeBlock(gFormat.format(65), "P" + 9810, _z, getFeed(cycle.feedrate)); // protected positioning move - } -} - -function cancelG68Rotation(force) { - if (force) { - gRotationModal.reset(); - } - writeBlock(gRotationModal.format(69)); -} - -function onCyclePoint(x, y, z) { - if (isInspectionOperation() && (typeof inspectionCycleInspect == "function")) { - inspectionCycleInspect(cycle, x, y, z); - return; - } - if (!isSameDirection(getRotation().forward, new Vector(0, 0, 1))) { - expandCyclePoint(x, y, z); - return; - } - if (isProbeOperation()) { - if (!isSameDirection(currentSection.workPlane.forward, new Vector(0, 0, 1))) { - if (!allowIndexingWCSProbing && currentSection.strategy == "probe") { - error(localize("Updating WCS / work offset using probing is only supported by the CNC in the WCS frame.")); - return; - } else if (staticProperties.useDWO) { - error(localize("Your machine does not support the selected probing operation with DWO enabled.")); - return; - } - } - if (printProbeResults()) { - writeProbingToolpathInformation(z - cycle.depth + tool.diameter / 2); - inspectionWriteCADTransform(); - inspectionWriteWorkplaneTransform(); - if (typeof inspectionWriteVariables == "function") { - inspectionVariables.pointNumber += 1; - } - } - protectedProbeMove(cycle, x, y, z); - } - - var forceCycle = false; - switch (cycleType) { - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - forceCycle = true; - if (!isFirstCyclePoint()) { - writeBlock(gCycleModal.format(80)); - gMotionModal.reset(); - } - } - if (forceCycle || isFirstCyclePoint() || isProbeOperation()) { - if (!isProbeOperation()) { - // return to initial Z which is clearance plane and set absolute mode - repositionToCycleClearance(cycle, x, y, z); - } - - var F = cycle.feedrate; - var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds - - switch (cycleType) { - case "drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "counter-boring": - if (P > 0) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(82), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(81), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "chip-breaking": - if ((cycle.accumulatedDepth < cycle.depth) && (cycle.incrementalDepthReduction > 0)) { - expandCyclePoint(x, y, z); - } else if (cycle.accumulatedDepth < cycle.depth) { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - ("Q" + xyzFormat.format(cycle.incrementalDepth)), - ("K" + xyzFormat.format(cycle.accumulatedDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(73), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - } - break; - case "deep-drilling": - writeBlock( - gRetractModal.format(98), gCycleModal.format(83), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - (((cycle.incrementalDepthReduction > 0) ? "I" : "Q") + xyzFormat.format(cycle.incrementalDepth)), - conditional(cycle.incrementalDepthReduction > 0, "J" + xyzFormat.format(cycle.incrementalDepthReduction)), - conditional(cycle.incrementalDepthReduction > 0, "K" + xyzFormat.format(cycle.minimumIncrementalDepth)), - conditional(P > 0, "P" + milliFormat.format(P)), // optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "left-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(74), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "right-tapping": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - writeBlock( - gRetractModal.format(98), gCycleModal.format(84), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - forceFeed(); - break; - case "tapping-with-chip-breaking": - case "left-tapping-with-chip-breaking": - case "right-tapping-with-chip-breaking": - var tappingFPM = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); - F = (staticProperties.useG95forTapping ? tool.getThreadPitch() : tappingFPM); - if (staticProperties.useG95forTapping) { - writeBlock(gFeedModeModal.format(95)); - } - // Parameter 57 bit 6, REPT RIG TAP, is set to 1 (On) - // On Mill software versions12.09 and above, REPT RIG TAP has been moved from the Parameters to Setting 133 - var u = cycle.stock; - var step = cycle.incrementalDepth; - var first = true; - while (u > cycle.bottom) { - if (step < cycle.minimumIncrementalDepth) { - step = cycle.minimumIncrementalDepth; - } - - u -= step; - step -= cycle.incrementalDepthReduction; - gCycleModal.reset(); // required - if ((u - 0.001) <= cycle.bottom) { - u = cycle.bottom; - } - if (first) { - first = false; - writeBlock( - gRetractModal.format(99), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND ? 74 : 84)), - getCommonCycle((gPlaneModal.getCurrent() == 19) ? u : x, (gPlaneModal.getCurrent() == 18) ? u : y, (gPlaneModal.getCurrent() == 17) ? u : z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), pitchOutput.format(F) - ); - } else { - var position; - var depth; - switch (gPlaneModal.getCurrent()) { - case 17: - xOutput.reset(); - position = xOutput.format(x); - depth = "Z" + xyzFormat.format(u); - break; - case 18: - zOutput.reset(); - position = zOutput.format(z); - depth = "Y" + xyzFormat.format(u); - break; - case 19: - yOutput.reset(); - position = yOutput.format(y); - depth = "X" + xyzFormat.format(u); - break; - } - writeBlock(conditional(u <= cycle.bottom, gRetractModal.format(98)), position, depth); - } - } - forceFeed(); - break; - case "fine-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(76), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - break; - case "back-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0; - var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0; - var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0; - writeBlock( - gRetractModal.format(98), gCycleModal.format(77), - getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom, cycle.clearance), - "Q" + xyzFormat.format(cycle.shift), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "reaming": - writeBlock( - gRetractModal.format(98), gCycleModal.format(85), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "stop-boring": - if (P > 0) { - expandCyclePoint(x, y, z); - } else { - writeBlock( - gRetractModal.format(98), gCycleModal.format(86), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - forceSpindleSpeed = true; - } - break; - case "manual-boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(88), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - case "boring": - writeBlock( - gRetractModal.format(98), gCycleModal.format(89), - getCommonCycle(x, y, z, cycle.retract, cycle.clearance), - "P" + milliFormat.format(P), // not optional - conditional(cycleReverse, "E2000"), feedOutput.format(F) - ); - break; - - case "probing-x": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-y": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9811, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-z": - protectedProbeMove(cycle, x, y, Math.min(z - cycle.depth + cycle.probeClearance, cycle.retract)); - writeBlock( - gFormat.format(65), "P" + 9811, - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-wall": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-y-channel-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width1), - zOutput.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9814, - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9823, - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9814, - "Z" + xyzFormat.format(z - cycle.depth), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-circular-partial-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9823, - "Z" + xyzFormat.format(z - cycle.depth), - "A" + xyzFormat.format(cycle.partialCircleAngleA), - "B" + xyzFormat.format(cycle.partialCircleAngleB), - "C" + xyzFormat.format(cycle.partialCircleAngleC), - "D" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9812, - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - // not required "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "R" + xyzFormat.format(cycle.probeClearance), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-rectangular-hole-with-island": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "X" + xyzFormat.format(cycle.width1), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - writeBlock( - gFormat.format(65), "P" + 9812, - "Z" + xyzFormat.format(z - cycle.depth), - "Y" + xyzFormat.format(cycle.width2), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(-cycle.probeClearance), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-inner-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9815, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-xy-outer-corner": - var cornerX = x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2); - var cornerY = y + approach(cycle.approach2) * (cycle.probeClearance + tool.diameter / 2); - var cornerI = 0; - var cornerJ = 0; - if (cycle.probeSpacing !== undefined) { - cornerI = cycle.probeSpacing; - cornerJ = cycle.probeSpacing; - } - if ((cornerI != 0) && (cornerJ != 0)) { - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X[#185] Y[#186]"; - } - } - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9816, xOutput.format(cornerX), yOutput.format(cornerY), - conditional(cornerI != 0, "I" + xyzFormat.format(cornerI)), - conditional(cornerJ != 0, "J" + xyzFormat.format(cornerJ)), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, true) - ); - break; - case "probing-x-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "X" + xyzFormat.format(x + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 90), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-y-plane-angle": - protectedProbeMove(cycle, x, y, z - cycle.depth); - writeBlock( - gFormat.format(65), "P" + 9843, - "Y" + xyzFormat.format(y + approach(cycle.approach1) * (cycle.probeClearance + tool.diameter / 2)), - "D" + xyzFormat.format(cycle.probeSpacing), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "A" + xyzFormat.format(cycle.nominalAngle != undefined ? cycle.nominalAngle : 0), - getProbingArguments(cycle, false) - ); - if (currentSection.strategy == "probe") { - setProbeAngleMethod(); - probeVariables.compensationXY = "X" + xyzFormat.format(0) + " Y" + xyzFormat.format(0); - } - break; - case "probing-xy-pcd-hole": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "K" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - case "probing-xy-pcd-boss": - protectedProbeMove(cycle, x, y, z); - writeBlock( - gFormat.format(65), "P" + 9819, - "A" + xyzFormat.format(cycle.pcdStartingAngle), - "B" + xyzFormat.format(cycle.numberOfSubfeatures), - "C" + xyzFormat.format(cycle.widthPCD), - "D" + xyzFormat.format(cycle.widthFeature), - "Z" + xyzFormat.format(z - cycle.depth), - "Q" + xyzFormat.format(cycle.probeOvertravel), - "R" + xyzFormat.format(cycle.probeClearance), - getProbingArguments(cycle, false) - ); - if (cycle.updateToolWear) { - error(localize("Action -Update Tool Wear- is not supported with this cycle")); - return; - } - break; - default: - expandCyclePoint(x, y, z); - } - - // place cycle operation in subprogram - if (cycleSubprogramIsActive) { - if (forceCycle || cycleExpanded || isProbeOperation()) { - cycleSubprogramIsActive = false; - } else { - // call subprogram - writeBlock(mFormat.format(97), "P" + nFormat.format(currentSubprogram)); - subprogramStart(new Vector(x, y, z), new Vector(0, 0, 0), false); - } - } - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - - // 2nd through nth cycle point - } else { - if (cycleExpanded) { - expandCyclePoint(x, y, z); - } else { - if (usePolarMode) { - var polarPosition = getPolarPosition(x, y, z); - writeBlock(xOutput.format(polarPosition.first.x), yOutput.format(polarPosition.first.y), zOutput.format(polarPosition.first.z), - aOutput.format(polarPosition.second.x), bOutput.format(polarPosition.second.y), cOutput.format(polarPosition.second.z)); - return; - } - var _x; - var _y; - var _z; - if (!xyzFormat.areDifferent(x, xOutput.getCurrent()) && - !xyzFormat.areDifferent(y, yOutput.getCurrent()) && - !xyzFormat.areDifferent(z, zOutput.getCurrent())) { - switch (gPlaneModal.getCurrent()) { - case 17: // XY - xOutput.reset(); // at least one axis is required - break; - case 18: // ZX - zOutput.reset(); // at least one axis is required - break; - case 19: // YZ - yOutput.reset(); // at least one axis is required - break; - } - } - if (incrementalMode) { // set current position to retract height - setCyclePosition(cycle.retract); - } - writeBlock(xOutput.format(x), yOutput.format(y), zOutput.format(z)); - if (incrementalMode) { // set current position to clearance height - setCyclePosition(cycle.clearance); - } - } - } -} - -function getProbingArguments(cycle, updateWCS) { - var outputWCSCode = updateWCS && currentSection.strategy == "probe"; - if (outputWCSCode) { - validate(probeOutputWorkOffset <= 99, "Work offset is out of range."); - var nextWorkOffset = hasNextSection() ? getNextSection().workOffset == 0 ? 1 : getNextSection().workOffset : -1; - if (probeOutputWorkOffset == nextWorkOffset) { - currentWorkOffset = undefined; - } - } - return [ - (cycle.angleAskewAction == "stop-message" ? "B" + xyzFormat.format(cycle.toleranceAngle ? cycle.toleranceAngle : 0) : undefined), - ((cycle.updateToolWear && cycle.toolWearErrorCorrection < 100) ? "F" + xyzFormat.format(cycle.toolWearErrorCorrection ? cycle.toolWearErrorCorrection / 100 : 100) : undefined), - (cycle.wrongSizeAction == "stop-message" ? "H" + xyzFormat.format(cycle.toleranceSize ? cycle.toleranceSize : 0) : undefined), - (cycle.outOfPositionAction == "stop-message" ? "M" + xyzFormat.format(cycle.tolerancePosition ? cycle.tolerancePosition : 0) : undefined), - ((cycle.updateToolWear && cycleType == "probing-z") ? "T" + xyzFormat.format(cycle.toolLengthOffset) : undefined), - ((cycle.updateToolWear && cycleType !== "probing-z") ? "T" + xyzFormat.format(cycle.toolDiameterOffset) : undefined), - (cycle.updateToolWear ? "V" + xyzFormat.format(cycle.toolWearUpdateThreshold ? cycle.toolWearUpdateThreshold : 0) : undefined), - (cycle.printResults ? "W" + xyzFormat.format(1 + cycle.incrementComponent) : undefined), // 1 for advance feature, 2 for reset feature count and advance component number. first reported result in a program should use W2. - conditional(outputWCSCode, "S" + probeWCSFormat.format(probeOutputWorkOffset > 6 ? (0.01 * (probeOutputWorkOffset - 6) + 154) : probeOutputWorkOffset)) - ]; -} - -function onCycleEnd() { - if (isProbeOperation()) { - zOutput.reset(); - gMotionModal.reset(); - writeBlock(gFormat.format(65), "P" + 9810, zOutput.format(cycle.retract)); // protected retract move - } else { - if (cycleSubprogramIsActive) { - subprogramEnd(); - cycleSubprogramIsActive = false; - } - if (!cycleExpanded) { - writeBlock(gCycleModal.format(80), conditional(staticProperties.useG95forTapping, gFeedModeModal.format(94))); - gMotionModal.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 traversal.")); - return; - } - if (!staticProperties.useG0 && (((x ? 1 : 0) + (y ? 1 : 0) + (z ? 1 : 0)) > 1)) { - // axes are not synchronized - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, getFeed(toPreciseUnit(highFeedrate, MM))); - } else { - writeBlock(gMotionModal.format(0), x, y, z); - forceFeed(); - } - } -} - -function onLinear(_x, _y, _z, feed) { - if (pendingRadiusCompensation >= 0) { - // ensure that we end at desired position when compensation is turned off - xOutput.reset(); - yOutput.reset(); - } - 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; - var d = tool.diameterOffset; - if ((d > 200 && d < 1000) || d > 9999) { - warning(localize("Diameter offset out of range.")); - } - writeBlock(gPlaneModal.format(17), gFeedModeModal.format(94)); - switch (radiusCompensation) { - case RADIUS_COMPENSATION_LEFT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f); - break; - case RADIUS_COMPENSATION_RIGHT: - dOutput.reset(); - writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f); - break; - default: - writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); - } - } else { - writeBlock(gFeedModeModal.format(94), gMotionModal.format(1), x, y, z, f); - } - } else if (f) { - if (getNextRecord().isMotion()) { // try not to output feed without motion - forceFeed(); // force feed on next line - } else { - writeBlock(gMotionModal.format(1), f); - } - } -} - -var forceG0 = false; -function onRapid5D(_x, _y, _z, _a, _b, _c) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation mode cannot be changed at rapid traversal.")); - return; - } - - var num = - (xyzFormat.areDifferent(_x, xOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_y, yOutput.getCurrent()) ? 1 : 0) + - (xyzFormat.areDifferent(_z, zOutput.getCurrent()) ? 1 : 0) + - ((aOutput.isEnabled() && abcFormat.areDifferent(_a, aOutput.getCurrent())) ? 1 : 0) + - ((bOutput.isEnabled() && abcFormat.areDifferent(_b, bOutput.getCurrent())) ? 1 : 0) + - ((cOutput.isEnabled() && abcFormat.areDifferent(_c, cOutput.getCurrent())) ? 1 : 0); - if (!staticProperties.useG0 && !forceG0 && (tcpIsSupported || (num > 1))) { - invokeOnLinear5D(_x, _y, _z, _a, _b, _c, highFeedrate); // onLinear5D handles inverse time feedrates - forceG0 = false; - return; - } - - 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); - - if (x || y || z || a || b || c) { - writeBlock(gMotionModal.format(0), x, y, z, a, b, c); - forceFeed(); - forceG0 = false; - } -} - -function onLinear5D(_x, _y, _z, _a, _b, _c, feed, feedMode) { - if (!currentSection.isOptimizedForMachine()) { - error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); - return; - } - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); - return; - } - - 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); - - if (feedMode == FEED_INVERSE_TIME) { - forceFeed(); - } - var f = getFeed(feed); - var fMode = (feedMode == FEED_INVERSE_TIME) ? 93 : 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); - } - } -} - -function moveToSafeRetractPosition(isRetracted) { - var _skipBlock = skipBlock; - if (!isRetracted) { - writeRetract(Z); - } - if (staticProperties.forceHomeOnIndexing) { - skipBlock = _skipBlock; - writeRetract(X, Y); - } -} - -// Start of onRewindMachine logic -var performRewinds = false; // only use this setting with hardcoded machine configurations, set to true to enable the rewind/reconfigure logic -var stockExpansion = new Vector(toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN), toPreciseUnit(0.1, IN)); // expand stock XYZ values -safeRetractDistance = (unit == IN) ? 1 : 25; // additional distance to retract out of stock -safeRetractFeed = (unit == IN) ? 20 : 500; // retract feed rate -safePlungeFeed = (unit == IN) ? 10 : 250; // plunge feed rate - -/** Allow user to override the onRewind logic. */ -function onRewindMachineEntry(_a, _b, _c) { - return false; -} - -/** Retract to safe position before indexing rotaries. */ -function onMoveToSafeRetractPosition() { - // cancel TCP so that tool doesn't follow rotaries - if (currentSection.isMultiAxis() && tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - moveToSafeRetractPosition(false); -} - -/** Rotate axes to new position above reentry position */ -function onRotateAxes(_x, _y, _z, _a, _b, _c) { - // position rotary axes - xOutput.disable(); - yOutput.disable(); - zOutput.disable(); - forceG0 = true; - invokeOnRapid5D(_x, _y, _z, _a, _b, _c); - setCurrentABC(new Vector(_a, _b, _c)); - xOutput.enable(); - yOutput.enable(); - zOutput.enable(); -} - -/** Return from safe position after indexing rotaries. */ -function onReturnFromSafeRetractPosition(_x, _y, _z) { - // reinstate TCP - if (tcpIsSupported) { - writeBlock(gMotionModal.format(0), gFormat.format(234), hFormat.format(tool.lengthOffset), formatComment("TCPC ON")); - forceFeed(); - lengthCompensationActive = true; - } - - // position in XY - forceXYZ(); - xOutput.reset(); - yOutput.reset(); - zOutput.disable(); - invokeOnRapid(_x, _y, _z); - - // position in Z - zOutput.enable(); - invokeOnRapid(_x, _y, _z); -} -// End of onRewindMachine logic - -// Start of polar interpolation -var usePolarMode = false; // enables polar interpolation for a single operation -var polarDirection = new Vector(1, 0, 0); // vector to maintain tool at while in polar interpolation -var saveTcpIsSupported = undefined; -function setPolarMode(section, mode) { - if (!mode) { // turn off polar mode if required - if (usePolarMode) { - var currentPosition = getCurrentPosition(); - var polarPosition = getPolarPosition(currentPosition.x, currentPosition.y, currentPosition.z); - currentMachineABC = new Vector(polarPosition.second.x, polarPosition.second.y, polarPosition.second.z); - deactivatePolarMode(); - tcpIsSupported = saveTcpIsSupported; - setFeedrateMode(true); - usePolarMode = false; - } - return; - } - - var direction = polarDirection; - - // determine the rotary axis to use for polar interpolation - var axis = undefined; - if (machineConfiguration.getAxisV().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisV().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisV(); - } - } - if (axis == undefined && machineConfiguration.getAxisU().isEnabled()) { - if (Vector.dot(machineConfiguration.getAxisU().getAxis(), section.workPlane.getForward()) != 0) { - axis = machineConfiguration.getAxisU(); - } - } - if (axis == undefined) { - error(localize("Polar interpolation requires an active rotary axis be defined in direction of workplane normal.")); - } - - // calculate directional vector from initial position - if (direction == undefined) { - error(localize("Polar interpolation initiated without a directional vector.")); - return; - } else if (direction.isZero()) { - var initialPosition = getFramePosition(section.getInitialPosition()); - direction = Vector.diff(initialPosition, axis.getOffset()).getNormalized(); - } - - // put vector in plane of rotary axis - var temp = Vector.cross(direction, axis.getAxis()).getNormalized(); - direction = Vector.cross(axis.getAxis(), temp).getNormalized(); - - // activate polar interpolation - saveTcpIsSupported = tcpIsSupported; - tcpIsSupported = false; // temporary disable tcp support for polar mode - setFeedrateMode(); - activatePolarMode(tolerance / 2, 0, direction); -} -// End of polar interpolation - -function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { - if (isSpiral()) { - var startRadius = getCircularStartRadius(); - var endRadius = getCircularRadius(); - var dr = Math.abs(endRadius - startRadius); - if (dr > maximumCircularRadiiDifference) { // maximum limit - linearize(tolerance); // or alternatively use other G-codes for spiral motion - return; - } - } - - if (pendingRadiusCompensation >= 0) { - error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); - return; - } - - var start = getCurrentPosition(); - - if (isFullCircle()) { - if (staticProperties.useRadius || isHelical()) { // radius mode does not support full arcs - linearize(tolerance); - return; - } - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } else if (!staticProperties.useRadius) { - switch (getCircularPlane()) { - case PLANE_XY: - writeBlock(gPlaneModal.format(17), 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: - writeBlock(gPlaneModal.format(18), 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: - writeBlock(gPlaneModal.format(19), 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: - 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: - writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_ZX: - writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - case PLANE_YZ: - writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed)); - break; - default: - linearize(tolerance); - } - } -} - -var currentCoolantMode = COOLANT_OFF; -var coolantOff = undefined; -var isOptionalCoolant = false; - -function setCoolant(coolant) { - var coolantCodes = getCoolantCodes(coolant); - forceSingleLine = false; - if ((coolantCodes != undefined) && (coolant == COOLANT_FLOOD)) { - if (coolantPressure != "") { - forceSingleLine = true; - coolantCodes.push(coolantPressure); - } - } - if (Array.isArray(coolantCodes)) { - if (singleLineCoolant || forceSingleLine) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes.join(getWordSeparator())); - } else { - for (var c in coolantCodes) { - skipBlock = isOptionalCoolant; - writeBlock(coolantCodes[c]); - } - } - return undefined; - } - return coolantCodes; -} - -var isSpecialCoolantActive = false; - -function getCoolantCodes(coolant) { - isOptionalCoolant = false; - var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line - if (!coolants) { - error(localize("Coolants have not been defined.")); - } - if (isProbeOperation()) { // avoid coolant output for probing - coolant = COOLANT_OFF; - } - if (coolant == currentCoolantMode) { - if (operationNeedsSafeStart && coolant != COOLANT_OFF && !isSpecialCoolantActive) { - // isOptionalCoolant = true; - } else if (!forceCoolant || coolant == COOLANT_OFF) { - return undefined; // coolant is already active - } - } - if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF) && !isOptionalCoolant && !forceCoolant) { - if (Array.isArray(coolantOff)) { - for (var i in coolantOff) { - multipleCoolantBlocks.push(mFormat.format(coolantOff[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(coolantOff)); - } - } - forceCoolant = false; - - if (isSpecialCoolantActive) { - forceSpindleSpeed = true; - } - var m; - var coolantCodes = {}; - for (var c in coolants) { // find required coolant codes into the coolants array - if (coolants[c].id == coolant) { - isSpecialCoolantActive = (coolants[c].id == COOLANT_THROUGH_TOOL) || (coolants[c].id == COOLANT_FLOOD_THROUGH_TOOL) || (coolants[c].id == COOLANT_AIR_THROUGH_TOOL); - 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(mFormat.format(m[i])); - } - } else { - multipleCoolantBlocks.push(mFormat.format(m)); - } - currentCoolantMode = coolant; - return multipleCoolantBlocks; // return the single formatted coolant value - } - return undefined; -} - -var mapCommand = { - COMMAND_END:2, - 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; - forceCoolant = true; - return; - case COMMAND_OPTIONAL_STOP: - writeBlock(mFormat.format(1)); - forceSpindleSpeed = true; - currentCoolantMode = COOLANT_OFF; - forceCoolant = true; - return; - case COMMAND_COOLANT_ON: - setCoolant(COOLANT_FLOOD); - return; - case COMMAND_COOLANT_OFF: - setCoolant(COOLANT_OFF); - return; - case COMMAND_START_SPINDLE: - onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); - return; - case COMMAND_LOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(10)); // lock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(12)); // lock 5th-axis motion - } - } - return; - case COMMAND_UNLOCK_MULTI_AXIS: - if (machineConfiguration.isMultiAxisConfiguration() && (machineConfiguration.getNumberOfAxes() >= 4)) { - var _skipBlock = skipBlock; - writeBlock(mFormat.format(11)); // unlock 4th-axis motion - if (machineConfiguration.getNumberOfAxes() == 5) { - skipBlock = _skipBlock; - writeBlock(mFormat.format(13)); // unlock 5th-axis motion - } - } - return; - case COMMAND_BREAK_CONTROL: - if (!toolChecked) { // avoid duplicate COMMAND_BREAK_CONTROL - prepareForToolCheck(); - writeBlock( - gFormat.format(65), - "P" + 9853, - "T" + toolFormat.format(tool.number), - "B" + xyzFormat.format(0), - "H" + xyzFormat.format(staticProperties.toolBreakageTolerance) - ); - toolChecked = true; - lengthCompensationActive = false; // macro 9853 cancels tool length compensation - } - return; - case COMMAND_TOOL_MEASURE: - measureTool = true; - return; - case COMMAND_START_CHIP_TRANSPORT: - writeBlock(mFormat.format(31)); - return; - case COMMAND_STOP_CHIP_TRANSPORT: - writeBlock(mFormat.format(33)); - return; - case COMMAND_PROBE_ON: - return; - case COMMAND_PROBE_OFF: - return; - } - - var stringId = getCommandStringId(command); - var mcode = mapCommand[stringId]; - if (mcode != undefined) { - writeBlock(mFormat.format(mcode)); - } else { - onUnsupportedCommand(command); - } -} - -var toolChecked = false; // specifies that the tool has been checked with the probe - -function onSectionEnd() { - if (isInspectionOperation() && !isLastSection()) { - writeBlock(gFormat.format(103), "P0", formatComment("LOOKAHEAD ON")); - } - if (!isLastSection() && (getNextSection().getTool().coolant != tool.coolant)) { - setCoolant(COOLANT_OFF); - } - if ((((getCurrentSectionId() + 1) >= getNumberOfSections()) || - (tool.number != getNextSection().getTool().number)) && - tool.breakControl) { - onCommand(COMMAND_BREAK_CONTROL); - } else { - toolChecked = false; - } - - if (true) { - if (isRedirecting()) { - if (firstPattern) { - var finalPosition = getFramePosition(currentSection.getFinalPosition()); - var abc; - if (currentSection.isMultiAxis() && machineConfiguration.isMultiAxisConfiguration()) { - abc = currentSection.getFinalToolAxisABC(); - } else { - abc = currentWorkPlaneABC; - } - if (abc == undefined) { - abc = new Vector(0, 0, 0); - } - setAbsoluteMode(finalPosition, abc); - subprogramEnd(); - } - } - } - forceAny(); - - if (currentSection.isMultiAxis()) { - writeBlock(gFeedModeModal.format(94)); // inverse time feed off - if (currentSection.isOptimizedForMachine()) { - // the code below gets the machine angles from previous operation. closestABC must also be set to true - currentMachineABC = currentSection.getFinalToolAxisABC(); - } - if (tcpIsSupported) { - disableLengthCompensation(false, "TCPC OFF"); - } - } - - if (isProbeOperation()) { - writeBlock(gFormat.format(65), "P" + 9833); // spin the probe off - if (probeVariables.probeAngleMethod != "G68") { - setProbeAngle(); // output probe angle rotations if required - } - } - - // reset for next section - operationNeedsSafeStart = false; - coolantPressure = staticProperties.coolantPressure; - cycleReverse = false; - - setPolarMode(currentSection, false); -} - -/** Output block to do safe retract and/or move to home position. */ -function writeRetract() { - var words = []; // store all retracted axes in an array - var retractAxes = new Array(false, false, false); - var method = staticProperties.safePositionMethod; - if (method == "clearanceHeight") { - if (!is3D()) { - error(localize("Retract option 'Clearance Height' is not supported for multi-axis machining.")); - } else { - return; - } - } - validate(arguments.length != 0, "No axis specified for writeRetract()."); - - for (i in arguments) { - retractAxes[arguments[i]] = true; - } - if ((retractAxes[0] || retractAxes[1]) && !retracted && !skipBlock) { // retract Z first before moving to X/Y home - error(localize("Retracting in X/Y is not possible without being retracted in Z.")); - return; - } - // special conditions - if (retractAxes[0] || retractAxes[1]) { - method = "G53"; - } - cancelG68Rotation(); // G68 has to be canceled for retracts - - // define home positions - var _xHome; - var _yHome; - var _zHome; - if (method == "G28") { - _xHome = toPreciseUnit(0, MM); - _yHome = toPreciseUnit(0, MM); - _zHome = toPreciseUnit(0, MM); - } else { - if (homePositionCenter && - hasParameter("part-upper-x") && hasParameter("part-lower-x")) { - _xHome = (getParameter("part-upper-x") + getParameter("part-lower-x")) / 2; - } else { - _xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM); - } - _yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM); - _zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM); - } - for (var i = 0; i < arguments.length; ++i) { - switch (arguments[i]) { - case X: - // special conditions - if (homePositionCenter) { // output X in standard block by itself if centering - writeBlock(gMotionModal.format(0), "X" + xyzFormat.format(_xHome)); - xOutput.reset(); - break; - } - 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 = !skipBlock; - break; - default: - error(localize("Unsupported axis specified for writeRetract().")); - return; - } - } - if (words.length > 0) { - switch (method) { - case "G28": - gMotionModal.reset(); - gAbsIncModal.reset(); - writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); - writeBlock(gAbsIncModal.format(90)); - break; - case "G53": - gMotionModal.reset(); - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); - break; - default: - error(localize("Unsupported safe position method.")); - return; - } - } -} - -var isDPRNTopen = false; -function inspectionCreateResultsFileHeader() { - if (isDPRNTopen) { - if (!staticProperties.singleResultsFile) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - } - } - - if (isProbeOperation() && !printProbeResults()) { - return; // if print results is not desired by probe/ probeWCS - } - - if (!isDPRNTopen) { - writeBlock("PCLOS"); - writeBlock("POPEN"); - // check for existence of none alphanumeric characters but not spaces - var resFile; - if (staticProperties.singleResultsFile) { - resFile = getParameter("job-description") + "-RESULTS"; - } else { - resFile = getParameter("operation-comment") + "-RESULTS"; - } - resFile = resFile.replace(/:/g, "-"); - resFile = resFile.replace(/[^a-zA-Z0-9 -]/g, ""); - resFile = resFile.replace(/\s/g, "-"); - writeln("DPRNT[START]"); - writeln("DPRNT[RESULTSFILE*" + resFile + "]"); - if (hasGlobalParameter("document-id")) { - writeln("DPRNT[DOCUMENTID*" + getGlobalParameter("document-id") + "]"); - } - if (hasGlobalParameter("model-version")) { - writeln("DPRNT[MODELVERSION*" + getGlobalParameter("model-version") + "]"); - } - } - if (isProbeOperation() && printProbeResults()) { - isDPRNTopen = true; - } -} - -function getPointNumber() { - if (typeof inspectionWriteVariables == "function") { - return (inspectionVariables.pointNumber); - } else { - return ("#172[60]"); - } -} - -function inspectionWriteCADTransform() { - var cadOrigin = currentSection.getModelOrigin(); - var cadWorkPlane = currentSection.getModelPlane().getTransposed(); - var cadEuler = cadWorkPlane.getEuler2(EULER_XYZ_S); - writeln( - "DPRNT[G331" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(cadEuler.x) + - "*B" + abcFormat.format(cadEuler.y) + - "*C" + abcFormat.format(cadEuler.z) + - "*X" + xyzFormat.format(-cadOrigin.x) + - "*Y" + xyzFormat.format(-cadOrigin.y) + - "*Z" + xyzFormat.format(-cadOrigin.z) + - "]" - ); -} - -function inspectionWriteWorkplaneTransform() { - var orientation = (machineConfiguration.isMultiAxisConfiguration() && currentMachineABC != undefined) ? machineConfiguration.getOrientation(currentMachineABC) : currentSection.workPlane; - var abc = orientation.getEuler2(EULER_XYZ_S); - writeln("DPRNT[G330" + - "*N" + getPointNumber() + - "*A" + abcFormat.format(abc.x) + - "*B" + abcFormat.format(abc.y) + - "*C" + abcFormat.format(abc.z) + - "*X0*Y0*Z0*I0*R0]" - ); -} - -function writeProbingToolpathInformation(cycleDepth) { - writeln("DPRNT[TOOLPATHID*" + getParameter("autodeskcam:operation-id") + "]"); - if (isInspectionOperation()) { - writeln("DPRNT[TOOLPATH*" + getParameter("operation-comment") + "]"); - } else { - writeln("DPRNT[CYCLEDEPTH*" + xyzFormat.format(cycleDepth) + "]"); - } -} - -function onClose() { - if (isDPRNTopen) { - writeln("DPRNT[END]"); - writeBlock("PCLOS"); - isDPRNTopen = false; - if (typeof inspectionProcessSectionEnd == "function") { - inspectionProcessSectionEnd(); - } - } - cancelG68Rotation(); - writeln(""); - - optionalSection = false; - - onCommand(COMMAND_STOP_SPINDLE); - onCommand(COMMAND_COOLANT_OFF); - - // retract - writeRetract(Z); - if (!staticProperties.homePositionCenter || currentMachineABC.length != 0) { - writeRetract(X, Y); - } - - if (activeG254) { - writeBlock(gFormat.format(255)); // cancel DWO - activeG254 = false; - } - - // MAY NEED CHANGE HOMING ORDER TO ROTARY THEN LINEAR FOR NON-UMC MACHINES - - // Unwind Rotary table at end - if (machineConfiguration.isMultiAxisConfiguration()) { - onCommand(COMMAND_UNLOCK_MULTI_AXIS); - if (machineConfiguration.isMachineCoordinate(2)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "C" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(1)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "B" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } else if (machineConfiguration.isMachineCoordinate(0)) { - writeBlock(gFormat.format(28), gAbsIncModal.format(91), "A" + abcFormat.format(0)); - writeBlock(gAbsIncModal.format(90)); - } - gMotionModal.reset(); - writeBlock( - gMotionModal.format(0), - conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(0)), - conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(0)) - ); - } - if (staticProperties.homePositionCenter) { - homePositionCenter = staticProperties.homePositionCenter; - writeRetract(X, Y); - } - - onImpliedCommand(COMMAND_END); - onImpliedCommand(COMMAND_STOP_SPINDLE); - - if (staticProperties.useM130PartImages || staticProperties.useM130ToolImages) { - writeBlock(mFormat.format(131)); - } - writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off - if (subprograms.length > 0) { - writeln(""); - write(subprograms); - } - writeln(""); - writeComment(verif(getGlobalParameter("username") + getGlobalParameter("generated-at")).toString()); - writeln("%"); -} - -function verif(str) { - var hash = 0; - if (str.length == 0) { - return hash; - } - for (var i = 0; i < str.length; i++) { - var char = str.charCodeAt(i); - hash = ((((hash<<5)-hash)>>2)+char)<<4; - hash = hash & hash; - } - return hash ^ staticProperties.useG0; -} -/* -keywords += (keywords ? " MODEL_IMAGE" : "MODEL_IMAGE"); - -function onTerminate() { - var outputPath = getOutputPath(); - var programFilename = FileSystem.getFilename(outputPath); - var programSize = FileSystem.getFileSize(outputPath); - var postPath = findFile("setup-sheet-excel-2007.cps"); - var intermediatePath = getIntermediatePath(); - var a = "--property unit " + ((unit == IN) ? "0" : "1"); // use 0 for inch and 1 for mm - if (programName) { - a += " --property programName \"'" + programName + "'\""; - } - if (programComment) { - a += " --property programComment \"'" + programComment + "'\""; - } - a += " --property programFilename \"'" + programFilename + "'\""; - a += " --property programSize \"" + programSize + "\""; - a += " --noeditor --log temp.log \"" + postPath + "\" \"" + intermediatePath + "\" \"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\""; - execute(getPostProcessorPath(), a, false, ""); - executeNoWait("excel", "\"" + FileSystem.replaceExtension(outputPath, "xlsx") + "\"", false, ""); -} -*/ - -function setProperty(property, value) { - properties[property].current = value; -} -// <<<<< INCLUDED FROM ../../../haas next generation.cps - -capabilities |= CAPABILITY_INSPECTION; -description = "HAAS - Next Generation Control Inspect Surface"; -longDescription = "Generic post for the HAAS Next Generation control with inspect surface capabilities."; - -var controlType = "NGC"; // Specifies the control model "NGC" or "Classic" -// >>>>> INCLUDED FROM ../common/haas base inspection.cps -/* -properties.probeLocalVar = { - title: "Local variable start", - description: "Specify the starting value for macro # variables that are to be used for calculations during inspection paths.", - group: 99, - type: "integer", - value: (controlType == "NGC" ? 10000 : 100), - scope: "post" -}; -properties.useDirectConnection = { - title: "Stream Measured Point Data", - description: "Set to true to stream inspection results.", - group: 99, - type: "boolean", - value: false, - scope: "post" -}; -properties.probeResultsBuffer = { - title: "Measurement results store start", - description: "Specify the starting value of macro # variables where measurement results are stored.", - group: 99, - type: "integer", - value: (controlType == "NGC" ? 10100 : 150), - scope: "post" -}; -properties.probeNumberofPoints = { - title: "Measurement number of points to store", - description: "This is the maximum number of measurement results that can be stored in the buffer.", - group: 99, - type: "integer", - value: 4, - scope: "post" -}; -properties.controlConnectorVersion = { - title: "Results connector version", - description: "Interface version for direct connection to read inspection results.", - group: 99, - type: "integer", - value: 1, - scope: "post" -}; -properties.toolOffsetType = { - title: "Tool offset type", - description: "Select the which offsets are available on the tool offset page.", - group: 99, - type: "enum", - values: [ - {id: "geomWear", title: "Geometry & Wear"}, - {id: "geomOnly", title: "Geometry only"} - ], - value: "geomWear", - scope: "post" -}; -properties.commissioningMode = { - title: "Inspection Commissioning Mode", - description: "Enables commissioning mode where M0 and messages are output at key points in the program.", - group: 99, - type: "boolean", - value: true, - scope: "post" -}; -properties.probeOnCommand = { - title: "Probe On Command", - description: "The command used to turn the probe on, this can be a M code or sub program call.", - group: 99, - type: "string", - value: "G65 P9832", - scope: "post" -}; -properties.probeOffCommand = { - title: "Probe Off Command", - description: "The command used to turn the probe off, this can be a M code or sub program call.", - group: 99, - type: "string", - value: "G65 P9833", - scope: "post" -}; -properties.probeCalibratedRadius = { - title: "Calibrated Radius", - description: "Macro Variable used for storing probe calibrated radi.", - group: 99, - type: "integer", - value: (controlType == "NGC" ? 10556 : 556), - scope: "post" -}; -properties.probeEccentricityX = { - title: "Eccentricity X", - description: "Macro Variable used for storing the X eccentricity.", - group: 99, - type: "integer", - value: (controlType == "NGC" ? 10558 : 558), - scope: "post" -}; -properties.probeEccentricityY = { - title: "Eccentricity Y", - description: "Macro Variable used for storing the Y eccentricity.", - group: 99, - type: "integer", - value: (controlType == "NGC" ? 10559 : 559), - scope: "post" -}; -properties.probeCalibrationMethod = { - title: "Probe calibration Method", - description: "Select the probe calibration method.", - group: 99, - type: "enum", - values: [ - {id: "Renishaw", title: "Renishaw"}, - {id: "Autodesk", title: "Autodesk"}, - {id: "Other", title: "Other"} - ], - value: "Renishaw", - scope: "post" -}; -properties.calibrationNCOutput = { - title: "Calibration NC Output Type", - description: "Choose none if the NC program created is to be used for calibrating the probe.", - group: 99, - type: "enum", - values: [ - {id: "none", title: "none"}, - {id: "Ring Gauge", title: "Ring Gauge"} - ], - value: "none", - scope: "post" -};*/ -properties.toolHeightValidation = { - title: "Tool Length Validation", - description: "Length validation. By turning this off, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" -}; - -properties.pencilWCSValidation = { - title: "WCS Validation", - description: "WCS validation. By turning this off, you accept responsibility for any resulting crashes.", - group: 99, - type: "boolean", - value: true, - scope: "post" -}; - -var ijkFormat = createFormat({decimals:5, forceDecimal:true}); -// inspection variables -var inspectionVariables = { - localVariablePrefix: "#", - probeRadius: 0, - systemVariableMeasuredX: 5061, - systemVariableMeasuredY: 5062, - systemVariableMeasuredZ: 5063, - pointNumber: 1, - probeResultsBufferFull: false, - probeResultsBufferIndex: 1, - hasInspectionSections: false, - inspectionSectionCount: 0, - systemVariableOffsetLengthTable: 2200, - systemVariableOffsetWearTable: 2000, - workpieceOffset: "", - systemVariablePreviousX: 5001, - systemVariablePreviousY: 5002, - systemVariablePreviousZ: 5003, - systemVariableCurrentX: 5021, - systemVariableCurrentY: 5022, - systemVariableCurrentZ: 5023, -}; - -var macroFormat = createFormat({prefix:inspectionVariables.localVariablePrefix, decimals:0}); -var LINEAR_MOVE = 1; -var SAFE_MOVE = 2; -var SAFE_MOVE_DWO = 3; -var MEASURE_MOVE = 4; -var ALARM_IF_DEFLECTED = "M78"; -var ALARM_IF_NOT_DEFLECTED = "M79"; -var NO_DEFLECTION_CHECK = ""; - -function inspectionWriteVariables() { - // loop through all NC stream sections to check for surface inspection - for (var i = 0; i < getNumberOfSections(); ++i) { - var section = getSection(i); - if (section.strategy == "inspectSurface") { - inspectionVariables.workpieceOffset = section.workOffset; - var count = 1; - var localVar = getProperty("probeLocalVar"); - var prefix = inspectionVariables.localVariablePrefix; - inspectionVariables.probeRadius = prefix + count; - inspectionVariables.xTarget = prefix + ++count; - inspectionVariables.yTarget = prefix + ++count; - inspectionVariables.zTarget = prefix + ++count; - inspectionVariables.xMeasured = prefix + ++count; - inspectionVariables.yMeasured = prefix + ++count; - inspectionVariables.zMeasured = prefix + ++count; - inspectionVariables.activeToolLength = prefix + ++count; - inspectionVariables.macroVariable1 = prefix + ++count; - inspectionVariables.macroVariable2 = prefix + ++count; - inspectionVariables.macroVariable3 = prefix + ++count; - inspectionVariables.macroVariable4 = prefix + ++count; - inspectionVariables.macroVariable5 = prefix + ++count; - inspectionVariables.macroVariable6 = prefix + ++count; - inspectionVariables.macroVariable7 = prefix + ++count; - inspectionVariables.wcsVectorX = prefix + ++count; - inspectionVariables.wcsVectorY = prefix + ++count; - inspectionVariables.wcsVectorZ = prefix + ++count; - inspectionVariables.previousWCSX = prefix + ++count; - inspectionVariables.previousWCSY = prefix + ++count; - inspectionVariables.previousWCSZ = prefix + ++count; - if (getProperty("calibrationNCOutput") == "Ring Gauge") { - inspectionVariables.measuredXStartingAddress = localVar; - inspectionVariables.measuredYStartingAddress = localVar + 10; - inspectionVariables.measuredZStartingAddress = localVar + 20; - inspectionVariables.measuredIStartingAddress = localVar + 30; - inspectionVariables.measuredJStartingAddress = localVar + 40; - inspectionVariables.measuredKStartingAddress = localVar + 50; - } - inspectionValidateInspectionSettings(); - inspectionVariables.probeResultsReadPointer = prefix + (getProperty("probeResultsBuffer") + 2); - inspectionVariables.probeResultsWritePointer = prefix + (getProperty("probeResultsBuffer") + 3); - inspectionVariables.probeResultsCollectionActive = prefix + (getProperty("probeResultsBuffer") + 4); - inspectionVariables.probeResultsStartAddress = getProperty("probeResultsBuffer") + 5; - if (getProperty("toolOffsetType") == "geomOnly") { - inspectionVariables.systemVariableOffsetLengthTable = "2000"; - } - if (getProperty("commissioningMode")) { - writeBlock("#3006=1" + formatComment("Inspection commissioning mode is active, when the machine is measuring correctly please disable this in the post properties")); - } - if (getProperty("useDirectConnection")) { - // check to make sure local variables used in results buffer and inspection do not clash - var localStart = getProperty("probeLocalVar"); - var localEnd = count; - var BufferStart = getProperty("probeResultsBuffer"); - var bufferEnd = getProperty("probeResultsBuffer") + ((3 * getProperty("probeNumberofPoints")) + 8); - if ((localStart >= BufferStart && localStart <= bufferEnd) || (localEnd >= BufferStart && localEnd <= bufferEnd)) { - error("Local variables defined (" + prefix + localStart + "-" + prefix + localEnd + - ") and live probe results storage area (" + prefix + BufferStart + "-" + prefix + bufferEnd + ") overlap." - ); - } - writeBlock(macroFormat.format(getProperty("probeResultsBuffer")) + " = " + getProperty("controlConnectorVersion")); - writeBlock(macroFormat.format(getProperty("probeResultsBuffer") + 1) + " = " + getProperty("probeNumberofPoints")); - writeBlock(inspectionVariables.probeResultsReadPointer + " = 0"); - writeBlock(inspectionVariables.probeResultsWritePointer + " = 1"); - writeBlock(inspectionVariables.probeResultsCollectionActive + " = 0"); - if (getProperty("probeResultultsBuffer") == 0) { - error("Probe Results Buffer start address cannot be zero when using a direct connection."); - } - inspectionWriteFusionConnectorInterface("HEADER"); - } - inspectionVariables.hasInspectionSections = true; - break; - } - } -} - -function onProbe(status) { - if (status) { // probe ON - if (getProperty("commissioningMode") && getProperty("calibrationNCOutput") == "Ring Gauge") { - writeBlock(mFormat.format(19), "R#1"); - } else { - writeBlock(mFormat.format(19)); - } - writeBlock(getProperty("probeOnCommand")); // Command for switching the probe on - onDwell(2); - if (getProperty("commissioningMode")) { - writeBlock("#3006=1" + formatComment("Ensure Probe Is Active")); - } - } else { // probe OFF - writeBlock(getProperty("probeOffCommand")); // Command for switching the probe off - onDwell(2); - if (getProperty("commissioningMode")) { - writeBlock("#3006=1" + formatComment("Ensure Probe Has Deactivated")); - } - } -} - -function inspectionCycleInspect(cycle, x, y, z) { - if (getNumberOfCyclePoints() != 3) { - error(localize("Missing Endpoint in Inspection Cycle, check Approach and Retract heights")); - } - forceFeed(); // ensure feed is always output - just incase. - if (isFirstCyclePoint()) { - writeComment("Approach Move"); - // safe move to approach point start - if (activeG254) { - // Apply Eccentricity - gMotionModal.reset(); - writeBlock(gFormat.format(61)); //exact stop mode on - writeBlock(gAbsIncModal.format(91), gFormat.format(1), - "X-" + macroFormat.format(getProperty("probeEccentricityX")), - "Y-" + macroFormat.format(getProperty("probeEccentricityY")), - feedOutput.format(cycle.safeFeed) - ); - writeBlock(gFormat.format(103), "P1", formatComment("LOOKAHEAD OFF")); - inspectionGetCoordinates(true); - inspectionCalculateTargetEndpoint(x, y, z, SAFE_MOVE_DWO); - // move alond probing vector with DWO off - inspectionWriteCycleMove(gAbsIncModal.format(91), cycle.safeFeed, SAFE_MOVE_DWO, ALARM_IF_DEFLECTED); - // Apply radius delta correction - writeBlock(gAbsIncModal.format(91), gFormat.format(1), - "Z+[" + xyzFormat.format(tool.diameter / 2) + "-" + inspectionVariables.probeRadius + "]", - feedOutput.format(cycle.safeFeed) - ); - writeBlock(gFormat.format(103), "P1", formatComment("LOOKAHEAD OFF")); - inspectionGetCoordinates(false); - } else { - // only do trigger check when DWO is not active - inspectionCalculateTargetEndpoint(x, y, z, SAFE_MOVE); - inspectionWriteCycleMove(gAbsIncModal.format(90), cycle.safeFeed, SAFE_MOVE, ALARM_IF_DEFLECTED); - } - return; - } - if (isLastCyclePoint()) { - // retract move - writeComment("Retract Move"); - inspectionCalculateTargetEndpoint(x, y, z, LINEAR_MOVE); - inspectionWriteCycleMove(gAbsIncModal.format(90), cycle.linkFeed, LINEAR_MOVE, NO_DEFLECTION_CHECK); - forceXYZ(); - writeBlock(gFormat.format(64)); //exact stop mode on - return; - } - // measure move - if (getProperty("commissioningMode") && (inspectionVariables.pointNumber == 1)) { - writeBlock("#3006=1" + formatComment("Probe is about to contact part. Axes should stop on contact")); - } - inspectionWriteNominalData(cycle); - if (getProperty("useDirectConnection")) { - inspectionWriteFusionConnectorInterface("MEASURE"); - } - inspectionCalculateTargetEndpoint(x, y, z, MEASURE_MOVE); - var f = cycle.measureFeed; - if (activeG254) { - inspectionWriteCycleMove(gAbsIncModal.format(91), f, MEASURE_MOVE, ALARM_IF_NOT_DEFLECTED); - writeBlock(inspectionVariables.xTarget + "=" + macroFormat.format(inspectionVariables.systemVariableMeasuredX)); - writeBlock(inspectionVariables.yTarget + "=" + macroFormat.format(inspectionVariables.systemVariableMeasuredY)); - writeBlock(inspectionVariables.zTarget + "=" + macroFormat.format(inspectionVariables.systemVariableMeasuredZ) + " - " + inspectionVariables.activeToolLength); - inspectionWriteCycleMove(gAbsIncModal.format(90), f, LINEAR_MOVE, NO_DEFLECTION_CHECK); - inspectionReconfirmPositionDWO(f); - } else { - inspectionWriteCycleMove(gAbsIncModal.format(90), f, MEASURE_MOVE, ALARM_IF_NOT_DEFLECTED); - } - inspectionCorrectProbeMeasurement(); - inspectionWriteMeasuredData(); -} - -function inspectionWriteNominalData(cycle) { - var m = getRotation(); - var v = new Vector(cycle.nominalX, cycle.nominalY, cycle.nominalZ); - var vt = m.multiply(v); - var pathVector = new Vector(cycle.nominalI, cycle.nominalJ, cycle.nominalK); - var nv = m.multiply(pathVector).normalized; - cycle.nominalX = vt.x; - cycle.nominalY = vt.y; - cycle.nominalZ = vt.z; - cycle.nominalI = nv.x; - cycle.nominalJ = nv.y; - cycle.nominalK = nv.z; - writeln("DPRNT[G800" + - "*N" + inspectionVariables.pointNumber + - "*X" + xyzFormat.format(cycle.nominalX) + - "*Y" + xyzFormat.format(cycle.nominalY) + - "*Z" + xyzFormat.format(cycle.nominalZ) + - "*I" + ijkFormat.format(cycle.nominalI) + - "*J" + ijkFormat.format(cycle.nominalJ) + - "*K" + ijkFormat.format(cycle.nominalK) + - "*O" + xyzFormat.format(getParameter("operation:inspectSurfaceOffset")) + - "*U" + xyzFormat.format(getParameter("operation:inspectUpperTolerance")) + - "*L" + xyzFormat.format(getParameter("operation:inspectLowerTolerance")) + - "]" - ); -} - -function inspectionCalculateTargetEndpoint(x, y, z, moveType) { - writeComment("CALCULATE TARGET ENDPOINT"); - if (activeG254 && (moveType == MEASURE_MOVE || moveType == SAFE_MOVE_DWO)) { - // get measure move vector with TWP active - var searchIJK = new Vector(0, 0, 0); - var searchDistance; - var moveDistance; - - switch (moveType) { - case MEASURE_MOVE: - // writeComment("CTE - MEASURE_MOVE"); - searchDistance = getParameter("probeClearance") + getParameter("probeOvertravel"); - moveDistance = searchDistance * 0.1; - searchDistance -= moveDistance; - searchIJK.i = cycle.nominalI * -1 * moveDistance; - searchIJK.j = cycle.nominalJ * -1 * moveDistance; - searchIJK.k = cycle.nominalK * -1 * moveDistance; - break; - case SAFE_MOVE_DWO: - // get safe move unit vector with DWO active - // writeComment("CTE - SAFE_MOVE_DWO"); - var xyz = new Vector(0, 0, 0); - xyz = getCurrentPosition(); - var vectorI = x - xyz.x; - var vectorJ = y - xyz.y; - var vectorK = z - xyz.z; - var magnitude = Math.sqrt((vectorI * vectorI) + (vectorJ * vectorJ) + (vectorK * vectorK)); - moveDistance = magnitude * 0.1; - searchIJK.i = (vectorI / magnitude) * moveDistance; - searchIJK.j = (vectorJ / magnitude) * moveDistance; - searchIJK.k = (vectorK / magnitude) * moveDistance; - searchDistance = magnitude - moveDistance; - break; - default: - // writeComment("CTE - DEFAULT"); - } - // xyzTarget is previous move endpoint - with eccentricity correction - writeBlock(inspectionVariables.xTarget + " =" + xyzFormat.format(searchIJK.i)); - writeBlock(inspectionVariables.yTarget + " =" + xyzFormat.format(searchIJK.j)); - writeBlock(inspectionVariables.zTarget + " =" + xyzFormat.format(searchIJK.k)); - inspectionWriteCycleMove(gAbsIncModal.format(91), moveType == MEASURE_MOVE ? cycle.measureFeed : cycle.safeFeed, LINEAR_MOVE, NO_DEFLECTION_CHECK); - writeBlock(gFormat.format(255)); - writeComment("Calculate vector in WPCS"); - writeBlock(inspectionVariables.wcsVectorX + " =" + macroFormat.format(inspectionVariables.systemVariableCurrentX) + "-" + inspectionVariables.previousWCSX); - writeBlock(inspectionVariables.wcsVectorY + " =" + macroFormat.format(inspectionVariables.systemVariableCurrentY) + "-" + inspectionVariables.previousWCSY); - writeBlock(inspectionVariables.wcsVectorZ + " =[" + macroFormat.format(inspectionVariables.systemVariableCurrentZ) + "-" + inspectionVariables.activeToolLength + "]-" + inspectionVariables.previousWCSZ); - writeBlock(inspectionVariables.macroVariable4 + " =SQRT[" + - "[" + inspectionVariables.wcsVectorX + "*" + inspectionVariables.wcsVectorX + "]" + "+" + - "[" + inspectionVariables.wcsVectorY + "*" + inspectionVariables.wcsVectorY + "]" + "+" + - "[" + inspectionVariables.wcsVectorZ + "*" + inspectionVariables.wcsVectorZ + "]]" - ); - writeComment("Convert to unit vector"); - // safe or measure move endpointwith DWO active - writeBlock(inspectionVariables.xTarget + " =[" + xyzFormat.format(searchDistance) + " * [" + inspectionVariables.wcsVectorX + "/" + inspectionVariables.macroVariable4 + "]]"); - writeBlock(inspectionVariables.yTarget + " =[" + xyzFormat.format(searchDistance) + " * [" + inspectionVariables.wcsVectorY + "/" + inspectionVariables.macroVariable4 + "]]"); - writeBlock(inspectionVariables.zTarget + " =[" + xyzFormat.format(searchDistance) + " * [" + inspectionVariables.wcsVectorZ + "/" + inspectionVariables.macroVariable4 + "]]"); - } else { - writeBlock(inspectionVariables.xTarget + " =" + xyzFormat.format(x) + "-" + macroFormat.format(getProperty("probeEccentricityX"))); - writeBlock(inspectionVariables.yTarget + " =" + xyzFormat.format(y) + "-" + macroFormat.format(getProperty("probeEccentricityY"))); - writeBlock(inspectionVariables.zTarget + " =" + xyzFormat.format(z) + "+[" + xyzFormat.format(tool.diameter / 2) + "-" + inspectionVariables.probeRadius + "]"); - } -} - -function inspectionWriteCycleMove(absInc, feedRate, moveType, triggerCheck) { - // writeComment("moveType = " + moveType, triggerCheck); - var motionCommand = moveType == LINEAR_MOVE ? 1 : 31; - gMotionModal.reset(); - writeBlock(absInc, - gFormat.format(motionCommand), - "X" + inspectionVariables.xTarget, - "Y" + inspectionVariables.yTarget, - "Z" + inspectionVariables.zTarget, - feedOutput.format(feedRate), - triggerCheck - ); - writeBlock(gFormat.format(103), "P1", formatComment("LOOKAHEAD OFF")); -} - -function inspectionProbeTriggerCheck(triggered) { - var condition = triggered ? " GT " : " LT "; - var message = triggered ? "NO POINT TAKEN" : "PATH OBSTRUCTED"; - var inPositionTolerance = (unit == MM) ? 0.01 : 0.0004; - writeBlock(inspectionVariables.macroVariable1 + " =" + inspectionVariables.xTarget + "-" + macroFormat.format(inspectionVariables.systemVariableMeasuredX)); - writeBlock(inspectionVariables.macroVariable2 + " =" + inspectionVariables.yTarget + "-" + macroFormat.format(inspectionVariables.systemVariableMeasuredY)); - writeBlock(inspectionVariables.macroVariable3 + " =" + inspectionVariables.zTarget + "-" + macroFormat.format(inspectionVariables.systemVariableMeasuredZ) + "+" + inspectionVariables.activeToolLength); - writeBlock(inspectionVariables.macroVariable4 + " =" + - "[" + inspectionVariables.macroVariable1 + "*" + inspectionVariables.macroVariable1 + "]" + "+" + - "[" + inspectionVariables.macroVariable2 + "*" + inspectionVariables.macroVariable2 + "]" + "+" + - "[" + inspectionVariables.macroVariable3 + "*" + inspectionVariables.macroVariable3 + "]" - ); - forceSequenceNumbers(true); - writeBlock("IF [" + inspectionVariables.macroVariable4 + condition + inPositionTolerance + "] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1 " + formatComment(message)); - writeBlock(" "); - forceSequenceNumbers(false); -} - -function inspectionCorrectProbeMeasurement() { - writeComment("Correct Measurements"); - var MeasuredX = macroFormat.format(inspectionVariables.systemVariableMeasuredX); - var MeasuredY = macroFormat.format(inspectionVariables.systemVariableMeasuredY); - var MeasuredZ = macroFormat.format(inspectionVariables.systemVariableMeasuredZ); - if (activeG254) { - // Actual is previous target system parameter - with eccentricity correction - MeasuredX = macroFormat.format(inspectionVariables.systemVariablePreviousX); - MeasuredY = macroFormat.format(inspectionVariables.systemVariablePreviousY); - MeasuredZ = macroFormat.format(inspectionVariables.systemVariablePreviousZ); - } - writeBlock(inspectionVariables.xMeasured + " =" + MeasuredX + "+" + macroFormat.format(getProperty("probeEccentricityX"))); - writeBlock(inspectionVariables.yMeasured + " =" + MeasuredY + "+" + macroFormat.format(getProperty("probeEccentricityY"))); - // need to consider probe centre tool output point in future too - var correctToolLength = activeG254 ? "" : ("-" + inspectionVariables.activeToolLength); - writeBlock(inspectionVariables.zMeasured + " =" + MeasuredZ + "+" + inspectionVariables.probeRadius + correctToolLength); -} - -function inspectionWriteFusionConnectorInterface(ncSection) { - if (ncSection == "MEASURE") { - writeBlock("IF " + inspectionVariables.probeResultsCollectionActive + " NE 1 GOTO " + inspectionVariables.pointNumber); - writeBlock("WHILE [" + inspectionVariables.probeResultsReadPointer + " EQ " + inspectionVariables.probeResultsWritePointer + "] DO 1"); - onDwell(0.5); - writeComment("WAITING FOR FUSION CONNECTION"); - writeBlock("G53"); - writeBlock("END 1"); - writeBlock("N" + inspectionVariables.pointNumber); - } else { - writeBlock("WHILE [" + inspectionVariables.probeResultsCollectionActive + " NE 1] DO 1"); - onDwell(0.5); - writeComment("WAITING FOR FUSION CONNECTION"); - writeBlock("G53"); - writeBlock("END 1"); - } -} - -function inspectionCalculateDeviation() { - var outputFormat = (unit == MM) ? "[53]" : "[44]"; - //calculate the deviation and produce a warning if out of tolerance. - //(Measured + ((vector *(-1))*calibrated radi)) - - writeComment("calculate deviation"); - //compensate for tip rad in X - writeBlock( - inspectionVariables.macroVariable1 + "=[" + - inspectionVariables.xMeasured + "+[[" + - ijkFormat.format(cycle.nominalI) + "*[-1]]*" + - inspectionVariables.probeRadius + "]]" - ); - //compensate for tip rad in Y - writeBlock( - inspectionVariables.macroVariable2 + "=[" + - inspectionVariables.yMeasured + "+[[" + - ijkFormat.format(cycle.nominalJ) + "*[-1]]*" + - inspectionVariables.probeRadius + "]]" - ); - //compensate for tip rad in Z - writeBlock( - inspectionVariables.macroVariable3 + "=[" + - inspectionVariables.zMeasured + "+[[" + - ijkFormat.format(cycle.nominalK) + "*[-1]]*" + - inspectionVariables.probeRadius + "]]" - ); - //Calculate deviation vector (Measured x - nominal x) - writeBlock( - inspectionVariables.macroVariable4 + "=" + - inspectionVariables.macroVariable1 + "-" + - xyzFormat.format(cycle.nominalX) - ); - //Calculate deviation vector (Measured y - nominal y) - writeBlock( - inspectionVariables.macroVariable5 + "=" + - inspectionVariables.macroVariable2 + "-" + - xyzFormat.format(cycle.nominalY) - ); - //Calculate deviation vector (Measured Z - nominal Z) - writeBlock( - inspectionVariables.macroVariable6 + "=[" + - inspectionVariables.macroVariable3 + "-[" + - xyzFormat.format(cycle.nominalZ) + "]]" - ); - //sqrt xyz.xyz this is the value of the deviation - writeBlock( - inspectionVariables.macroVariable7 + "=SQRT[[" + - inspectionVariables.macroVariable4 + "*" + - inspectionVariables.macroVariable4 + "]+[" + - inspectionVariables.macroVariable5 + "*" + - inspectionVariables.macroVariable5 + "]+[" + - inspectionVariables.macroVariable6 + "*" + - inspectionVariables.macroVariable6 + "]]" - ); - //sign of the vector - writeBlock( - inspectionVariables.macroVariable1 + "=[[" + - ijkFormat.format(cycle.nominalI) + "*" + - inspectionVariables.macroVariable4 + "]+[" + - ijkFormat.format(cycle.nominalJ) + "*" + - inspectionVariables.macroVariable5 + "]+[" + - ijkFormat.format(cycle.nominalK) + "*" + - inspectionVariables.macroVariable6 + "]]" - ); - //Print out deviation value - forceSequenceNumbers(true); - writeBlock( - "IF [" + inspectionVariables.macroVariable1 + "GE0] GOTO" + skipNLines(3) - ); - writeBlock( - inspectionVariables.macroVariable4 + "=" + - inspectionVariables.macroVariable7 - ); - writeBlock("GOTO" + skipNLines(2)); - writeBlock( - inspectionVariables.macroVariable4 + "=[" + - inspectionVariables.macroVariable7 + "*[-1]]" - ); - writeBlock(" "); - writeln( - "DPRNT[G802" + "*N" + inspectionVariables.pointNumber + - "*DEVIATION*" + inspectionVariables.macroVariable4 + outputFormat + "]" - ); - //Tolerance check - writeBlock( - "IF [" + inspectionVariables.macroVariable4 + - "LT" + (xyzFormat.format(getParameter("operation:inspectUpperTolerance"))) + - "] GOTO" + skipNLines(3) - ); - writeBlock( - "#3006 = 1" + formatComment("Inspection point over tolerance") - ); - writeBlock("GOTO" + skipNLines(3)); - writeBlock( - "IF [" + inspectionVariables.macroVariable4 + - "GT" + (xyzFormat.format(getParameter("operation:inspectLowerTolerance"))) + - "] GOTO" + skipNLines(2) - ); - writeBlock( - "#3006 = 1" + formatComment("Inspection point under tolerance") - ); - writeBlock(" "); - forceSequenceNumbers(false); -} - -function inspectionWriteMeasuredData() { - var outputFormat = (unit == MM) ? "[53]" : "[44]"; - writeln("DPRNT[G801" + - "*N" + inspectionVariables.pointNumber + - "*X" + inspectionVariables.xMeasured + outputFormat + - "*Y" + inspectionVariables.yMeasured + outputFormat + - "*Z" + inspectionVariables.zMeasured + outputFormat + - "*R" + inspectionVariables.probeRadius + outputFormat + - "]" - ); - - if (cycle.outOfPositionAction == "stop-message") { - inspectionCalculateDeviation(); - } - - if (getProperty("useDirectConnection")) { - var writeResultIndexX = inspectionVariables.probeResultsStartAddress + (3 * inspectionVariables.probeResultsBufferIndex); - var writeResultIndexY = inspectionVariables.probeResultsStartAddress + (3 * inspectionVariables.probeResultsBufferIndex) + 1; - var writeResultIndexZ = inspectionVariables.probeResultsStartAddress + (3 * inspectionVariables.probeResultsBufferIndex) + 2; - - writeBlock(macroFormat.format(writeResultIndexX) + " = " + inspectionVariables.xMeasured); - writeBlock(macroFormat.format(writeResultIndexY) + " = " + inspectionVariables.yMeasured); - writeBlock(macroFormat.format(writeResultIndexZ) + " = " + inspectionVariables.zMeasured); - inspectionVariables.probeResultsBufferIndex += 1; - if (inspectionVariables.probeResultsBufferIndex > getProperty("probeNumberofPoints")) { - inspectionVariables.probeResultsBufferIndex = 0; - } - writeBlock(inspectionVariables.probeResultsWritePointer + " = " + inspectionVariables.probeResultsBufferIndex); - } - if (getProperty("commissioningMode") && (getProperty("calibrationNCOutput") == "Ring Gauge")) { - writeBlock(macroFormat.format(inspectionVariables.measuredXStartingAddress + inspectionVariables.pointNumber) + - " =" + inspectionVariables.xMeasured); - writeBlock(macroFormat.format(inspectionVariables.measuredYStartingAddress + inspectionVariables.pointNumber) + - " =" + inspectionVariables.yMeasured); - writeBlock(macroFormat.format(inspectionVariables.measuredZStartingAddress + inspectionVariables.pointNumber) + - " =" + inspectionVariables.zMeasured); - writeBlock(macroFormat.format(inspectionVariables.measuredIStartingAddress + inspectionVariables.pointNumber) + - " =" + xyzFormat.format(cycle.nominalI)); - writeBlock(macroFormat.format(inspectionVariables.measuredJStartingAddress + inspectionVariables.pointNumber) + - " =" + xyzFormat.format(cycle.nominalJ)); - writeBlock(macroFormat.format(inspectionVariables.measuredKStartingAddress + inspectionVariables.pointNumber) + - " =" + xyzFormat.format(cycle.nominalK)); - } - inspectionVariables.pointNumber += 1; -} - -function forceSequenceNumbers(force) { - if (force) { - staticProperties.showSequenceNumbers = true; - } else { - staticProperties.showSequenceNumbers = saveShowSequenceNumbers; - } -} - -function skipNLines(n) { - return (n * staticProperties.sequenceNumberIncrement + sequenceNumber); -} - -function inspectionProcessSectionStart() { - writeBlock(gFormat.format(103), "P1", formatComment("LOOKAHEAD OFF")); - // only write header once if user selects a single results file - if (!isDPRNTopen || !staticProperties.singleResultsFile || (currentSection.workOffset != inspectionVariables.workpieceOffset)) { - inspectionCreateResultsFileHeader(); - inspectionVariables.workpieceOffset = currentSection.workOffset; - } - // write the toolpath name as a comment - writeProbingToolpathInformation(); - inspectionWriteCADTransform(); - inspectionWriteWorkplaneTransform(); - inspectionVariables.inspectionSectionCount += 1; - if (getProperty("toolOffsetType") == "geomOnly") { - writeComment("Geometry Only"); - writeBlock( - inspectionVariables.activeToolLength + "=" + - inspectionVariables.localVariablePrefix + "[" + - inspectionVariables.systemVariableOffsetLengthTable + " + " + - macroFormat.format(4111) + - "]" - ); - } else { - writeComment("Geometry and Wear"); - writeBlock( - inspectionVariables.activeToolLength + "=" + - inspectionVariables.localVariablePrefix + "[" + - inspectionVariables.systemVariableOffsetLengthTable + " + " + - macroFormat.format(4111) + - "] + " + - inspectionVariables.localVariablePrefix + "[" + - inspectionVariables.systemVariableOffsetWearTable + " + " + - macroFormat.format(4111) + - "]" - ); - } - if (getProperty("probeCalibrationMethod") == "Renishaw") { - writeBlock(inspectionVariables.probeRadius + "=[[" + - macroFormat.format(getProperty("probeCalibratedRadius")) + " + " + - macroFormat.format(getProperty("probeCalibratedRadius") + 1) + "]" + "/2]" - ); - } else { - writeBlock(inspectionVariables.probeRadius + "=" + macroFormat.format(getProperty("probeCalibratedRadius"))); - } - if (getProperty("commissioningMode") && !isDPRNTopen) { - var outputFormat = (unit == MM) ? "[53]" : "[44]"; - writeln("DPRNT[CALIBRATED*RADIUS*" + inspectionVariables.probeRadius + outputFormat + "]"); - writeln("DPRNT[ECCENTRICITY*X****" + macroFormat.format(getProperty("probeEccentricityX")) + outputFormat + "]"); - writeln("DPRNT[ECCENTRICITY*Y****" + macroFormat.format(getProperty("probeEccentricityY")) + outputFormat + "]"); - forceSequenceNumbers(true); - writeBlock("IF [" + inspectionVariables.probeRadius + " NE #0] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY CALIBRATED RADIUS INCORRECT")); - writeBlock("IF [" + inspectionVariables.probeRadius + " NE 0] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY CALIBRATED RADIUS INCORRECT")); - writeBlock("IF [" + inspectionVariables.probeRadius + " LT " + xyzFormat.format(tool.diameter / 2) + "] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY CALIBRATED RADIUS INCORRECT")); - var maxEccentricity = (unit == MM) ? 0.2 : 0.0079; - writeBlock("IF [ABS[" + macroFormat.format(getProperty("probeEccentricityX")) + "] LT " + maxEccentricity + "] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY ECCENTRICITY X INCORRECT")); - writeBlock("IF [ABS[" + macroFormat.format(getProperty("probeEccentricityY")) + "] LT " + maxEccentricity + "] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY ECCENTRICITY Y INCORRECT")); - writeBlock("IF [" + macroFormat.format(getProperty("probeEccentricityX")) + " NE #0] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY ECCENTRICITY X INCORRECT")); - writeBlock("IF [" + macroFormat.format(getProperty("probeEccentricityY")) + " NE #0] GOTO" + skipNLines(2)); - writeBlock("#3000 = 1" + formatComment("PROBE NOT CALIBRATED OR PROPERTY ECCENTRICITY Y INCORRECT")); - writeBlock(" "); - forceSequenceNumbers(false); - } - isDPRNTopen = true; -} - -function inspectionProcessSectionEnd() { - // close inspection results file if the NC has inspection toolpaths - if (inspectionVariables.hasInspectionSections) { - if (getProperty("commissioningMode")) { - if (controlType == "NGC") { - forceSequenceNumbers(true); - writeBlock(inspectionVariables.macroVariable1 + " = [#20261 * " + 4 * staticProperties.sequenceNumberIncrement + " + " + skipNLines(2) + "]"); - writeBlock("GOTO " + inspectionVariables.macroVariable1); - writeBlock(" "); - writeBlock("#3006=1" + formatComment("DPRNT LOCATION NOT SET")); - onCommand(COMMAND_STOP); - writeBlock("GOTO " + skipNLines(8)); - writeBlock(" "); - writeBlock("#3006=1" + formatComment("CHECK SETTING 262 FOR RESULTS FILE LOCATION")); - onCommand(COMMAND_STOP); - writeBlock("GOTO " + skipNLines(4)); - writeBlock(" "); - writeBlock("#3006=1" + formatComment("RESULTS FILE WRITTEN TO TCP PORT")); - onCommand(COMMAND_STOP); - writeBlock(" "); - forceSequenceNumbers(false); - } else { - writeBlock("#3006=1" + formatComment("RESULTS FILE WRITTEN TO SERIAL PORT")); - } - } - writeBlock(gFormat.format(103), "P0", formatComment("LOOKAHEAD ON")); - } -} - -function inspectionGetCoordinates(isApproachMove) { - if (isApproachMove) { - writeComment("Get Current Point DWO ON"); - writeBlock(inspectionVariables.xTarget + " =" + macroFormat.format(inspectionVariables.systemVariablePreviousX)); - writeBlock(inspectionVariables.yTarget + " =" + macroFormat.format(inspectionVariables.systemVariablePreviousY)); - writeBlock(inspectionVariables.zTarget + " =" + macroFormat.format(inspectionVariables.systemVariablePreviousZ)); - } - writeComment("Current Point in WCS"); - writeBlock(gFormat.format(255)); - writeBlock(inspectionVariables.previousWCSX + " =" + macroFormat.format(inspectionVariables.systemVariableCurrentX)); - writeBlock(inspectionVariables.previousWCSY + " =" + macroFormat.format(inspectionVariables.systemVariableCurrentY)); - writeBlock(inspectionVariables.previousWCSZ + " =" + macroFormat.format(inspectionVariables.systemVariableCurrentZ) + "-" + inspectionVariables.activeToolLength); - inspectionReconfirmPositionDWO(cycle.safeFeed); -} - -function inspectionReconfirmPositionDWO(f) { - // zero length move to re-confirm current position - writeComment("Re-confirm position DWO Active"); - writeBlock(gFormat.format(254)); - writeBlock(gAbsIncModal.format(91), gMotionModal.format(1), "X0.0 Y0.0", feedOutput.format(f)); - writeBlock("Z0.0"); - writeBlock(gFormat.format(103), "P1", formatComment("LOOKAHEAD OFF")); -} -// <<<<< INCLUDED FROM ../common/haas base inspection.cps - -function inspectionValidateInspectionSettings() { - var errorText = ""; - if (getProperty("probeOnCommand") == "") { - errorText += "\n-Probe On Command-"; - } - if (getProperty("probeOffCommand") == "") { - errorText += "\n-Probe Off Command-"; - } - if (getProperty("probeCalibratedRadius") == 0) { - errorText += "\n-Calibrated Radius-"; - } - if (getProperty("probeEccentricityX") == 0) { - errorText += "\n-Eccentricity X-"; - } - if (getProperty("probeEccentricityY") == 0) { - errorText += "\n-Eccentricity Y-"; - } - if (errorText != "") { - error(localize("The following properties need to be configured:" + errorText + "\n-Please consult the guide PDF found at https://cam.autodesk.com/hsmposts?p=haas_next_generation_inspect_surface for more information-")); - } -}