/** Copyright (C) 2012-2018 by Autodesk, Inc. All rights reserved. KUKA KRL post processor configuration. $Revision: 42319 7b9a1dc9f1343527d18a6a1d92801fb7a4787cad $ $Date: 2019-05-31 16:02:09 $ FORKID {7DFE0FFC-783F-40e0-B9E1-D7A63A4BD4C1} */ description = "KUKA KRL VKRC1"; vendor = "KUKA"; vendorUrl = ""; legal = "gawron52's mod"; certificationLevel = 2; minimumRevision = 40783; longDescription = "KUKA KRL GENERATOR FOR VKRC1"; extension = "src"; programNameIsInteger = true; setCodePage("ascii"); capabilities = CAPABILITY_MILLING; tolerance = spatial(0.05, MM); highFeedrate = (unit == IN) ? 100 : 1000; minimumChordLength = spatial(0.25, MM); minimumCircularRadius = spatial(0.01, MM); maximumCircularRadius = spatial(1000, MM); minimumCircularSweep = toRad(0.01); maximumCircularSweep = toRad(180); allowHelicalMoves = true; allowedCircularPlanes = undefined; // allow any circular motion allowSpiralMoves = true; // user-defined properties properties = { writeMachine: false, // write machine writeTools: false, // writes the tools optionalStop: false, // optional stop useCIRC: true // enable to use CIRC }; // user-defined property definitions propertyDefinitions = { writeMachine: {title:"Write machine", description:"Output the machine settings in the header of the code.", group:0, type:"boolean"}, writeTools: {title:"Write tool list", description:"Output a tool list in the header of the code.", group:0, type:"boolean"}, optionalStop: {title:"Optional stop", description:"Outputs optional stop code during when necessary in the code.", type:"boolean"}, useCIRC: {title:"Use CIRC", description:"Enable to use CIRC", type:"boolean"} }; var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:false}); var abcFormat = createFormat({decimals:3, forceDecimal:false, scale:DEG}); var bFormat = createFormat({decimals:3, forceDecimal:false, scale:DEG, offset:180}); // invert B var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:false, scale:1.0/1000.0/60.0}); // mm/min -> m/s var toolFormat = createFormat({decimals:0}); var rpmFormat = createFormat({decimals:0}); var secFormat = createFormat({decimals:3}); // seconds var taperFormat = createFormat({decimals:1, scale:DEG}); var xOutput = createVariable({prefix:"X ", force:true}, xyzFormat); var yOutput = createVariable({prefix:"Y ", force:true}, xyzFormat); var zOutput = createVariable({onchange:function () {retracted = false;}, prefix:"Z ", force:true}, xyzFormat); var aOutput = createVariable({prefix:"A ", force:true}, abcFormat); var bOutput = createVariable({prefix:"B ", force:true}, bFormat); var cOutput = createVariable({prefix:"C ", force:true}, abcFormat); var feedOutput = createVariable({prefix:"$VEL.CP="}, feedFormat); var sOutput = createVariable({prefix:"S", force:true}, rpmFormat); var WARNING_WORK_OFFSET = 0; var useTurnTable = false; // collected state var forceSpindleSpeed = false; var retracted = false; // specifies that the tool has been retracted to the safe plane /** Returns the modulus. */ function getModulus(x, y) { return Math.sqrt(x * x + y * y); } /** Returns the required number of segments for linearization of the corresponding arc segment. */ function getNumberOfSegments(radius, sweep, error) { if (radius > error) { var stepAngle = 2 * Math.acos(1 - error/radius); return Math.max(Math.ceil(sweep/stepAngle), 1); } return 1; } /** Returns the C rotation for the given X and Y coordinates. */ function getC(x, y) { return Math.atan2(y, x); } /** Returns the C rotation for the given X and Y coordinates in the desired rotary direction. */ function getCClosest(x, y, _c, clockwise) { if (_c == Number.POSITIVE_INFINITY) { _c = 0; // undefined } var c = getC(x, y); if (clockwise != undefined) { if (clockwise) { while (c < _c) { c += Math.PI * 2; } } else { while (c > _c) { c -= Math.PI * 2; } } } else { min = _c - Math.PI; max = _c + Math.PI; while (c < min) { c += Math.PI * 2; } while (c > max) { c -= Math.PI * 2; } } return c; } /** Returns the desired tolerance for the given section. */ function getTolerance() { var t = tolerance; if (hasParameter("operation:tolerance")) { if (t > 0) { t = Math.min(t, getParameter("operation:tolerance")); } else { t = getParameter("operation:tolerance"); } } return t; } /** Writes the specified block. */ function writeBlock() { writeWords(arguments); } function formatComment(text) { return "; " + String(text).toUpperCase().replace(/[()]/g, ""); } /** Output a comment. */ function writeComment(text) { writeln(formatComment(text)); } function onOpen() { if (true) { // ZYX euler rotations var aAxis = createAxis({coordinate:2, table:false, axis:[1, 0, 0], range:[-180, 180], preference:-1}); var cAxis = createAxis({coordinate:0, table:false, axis:[0, 0, 1], cyclic:true, preference:1}); machineConfiguration = new MachineConfiguration(aAxis, cAxis); setMachineConfiguration(machineConfiguration); optimizeMachineAngles2(0); // TCP mode } setWordSeparator(""); writeBlock("&ACCESS RVP"); writeBlock("&REL 4"); writeBlock("&COMMENT " + programComment); //programComment - komentarz wpisany przy generowaniu KRL (okno Fusiona), zostanie wyƛwietlony w "Comment" w VKRC // writeBlock("&PARAM TEMPLATE = "); writeBlock("&PARAM EDITMASK = *"); writeBlock("DEF " + FileSystem.replaceExtension(FileSystem.getFilename(getOutputPath().toUpperCase()), "") + "()"); if (programComment) { writeComment(); } writeBlock("EXT BAS (BAS_COMMAND :IN,REAL :IN )"); writeBlock("INT I"); writeBlock("BAS (#INITMOV,0 )"); writeln(""); /* writeComment("****** SETTINGS FOR PTP MOTION ***********************"); writeComment("SET PTP $VEL_AXIS AND $ACC_AXIS"); writeBlock("FOR I = 1 TO 6"); writeBlock(" $VEL_AXIS[I]=50"); writeBlock(" $ACC_AXIS[I]=100"); writeBlock("ENDFOR"); writeln(""); writeComment("****** SETTINGS FOR LIN AND ARC MOTION ***************"); writeComment("SET LIN AND ARC MOTION VARIABLES"); writeBlock("$VEL.CP=0.0001"); writeBlock("$VEL.ORI1=200"); writeBlock("$VEL.ORI2=200"); writeBlock("$ACC.CP=10.00000"); writeBlock("$ACC.ORI1=100"); writeBlock("$ACC.ORI2=100"); writeln(""); */ writeComment("****** SETTINGS FOR POSITIONING CRITERIA ***************"); writeComment("SET POSITIONING CRITERIA"); writeBlock("$APO.CDIS=1.00000"); writeln(""); /* writeBlock("$BASE=EK({X " + xyzFormat.format(0) + ",Y " + xyzFormat.format(-2300) + ",Z " + xyzFormat.format(-259) + ",A " + abcFormat.format(0) + ",B " + + abcFormat.format(0) + ",C " + + abcFormat.format(0) + "}, #EASYS, $NULLFRAME)"); // WCS origin writeBlock("$TOOL={X " + xyzFormat.format(746) + ",Y " + xyzFormat.format(0) + ",Z " + xyzFormat.format(184) + ",A " + abcFormat.format(toRad(0)) + ",B " + + abcFormat.format(toRad(-90)) + ",C " + + abcFormat.format(toRad(180)) + "}"); // tool length/displacement */ writeBlock("$ADVANCE=5"); // look ahead 5 blocks writeln(""); // dump machine configuration var vendor = machineConfiguration.getVendor(); var model = machineConfiguration.getModel(); var description = machineConfiguration.getDescription(); if (properties.writeMachine && (vendor || model || description)) { writeComment(localize("Machine")); if (vendor) { writeComment(" " + localize("vendor") + ": " + vendor); } if (model) { writeComment(" " + localize("model") + ": " + model); } if (description) { writeComment(" " + localize("description") + ": " + description); } } // dump tool information if (properties.writeTools) { var zRanges = {}; if (is3D()) { var numberOfSections = getNumberOfSections(); for (var i = 0; i < numberOfSections; ++i) { var section = getSection(i); var zRange = section.getGlobalZRange(); var tool = section.getTool(); if (zRanges[tool.number]) { zRanges[tool.number].expandToRange(zRange); } else { zRanges[tool.number] = zRange; } } } var tools = getToolTable(); if (tools.getNumberOfTools() > 0) { for (var i = 0; i < tools.getNumberOfTools(); ++i) { var tool = tools.getTool(i); var comment = "T" + 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 (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; } } } } function onComment(message) { writeComment(message); } /** Force output of X, Y, and Z. */ function forceXYZ() { xOutput.reset(); yOutput.reset(); zOutput.reset(); } /** Force output of A, B, and C. */ function forceABC() { aOutput.reset(); bOutput.reset(); cOutput.reset(); } /** Force output of X, Y, Z, A, B, C, and F on next output. */ function forceAny() { forceXYZ(); forceABC(); feedOutput.reset(); } var currentToolAxisABC = new Vector(0, 0, 0); function getWorkPlaneMachineABC(workPlane) { var W = workPlane; // map to global frame var abc = machineConfiguration.getABC(W); abc = machineConfiguration.getPreferredABC(abc); try { abc = machineConfiguration.remapABC(abc); 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)) ); } return abc; } var firstLin = true; function writeLin(x, y, z, a, b, c, e1) { if (useTurnTable) { if (firstLin) { firstLin = false; writeBlock("LIN {" + xOutput.format(x) + "," + yOutput.format(y) + "," + zOutput.format(z) + "," + aOutput.format(a) + "," + bOutput.format(b) + "," + cOutput.format(c) + ",E1 " + abcFormat.format(e1) + ",E2 " + abcFormat.format(0) + ",E3 " + abcFormat.format(0) + ",E4 " + abcFormat.format(0) + ",E5 " + abcFormat.format(0) + ",E6 " + abcFormat.format(0) + "} C_DIS"); } else { writeBlock("LIN {" + xOutput.format(x) + "," + yOutput.format(y) + "," + zOutput.format(z) + "," + aOutput.format(a) + "," + bOutput.format(b) + "," + cOutput.format(c) + ",E1 " + abcFormat.format(e1) + "} C_DIS"); } } else { writeBlock("LIN {" + xOutput.format(x) + "," + yOutput.format(y) + "," + zOutput.format(z) + "," + aOutput.format(a) + "," + bOutput.format(b) + "," + cOutput.format(c) + "} C_DIS"); } } function onSection() { var insertToolCall = isFirstSection() || currentSection.getForceToolChange && currentSection.getForceToolChange() || (tool.number != getPreviousSection().getTool().number); retracted = false; 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 if (insertToolCall || newWorkOffset || newWorkPlane) { // retract } if (hasParameter("operation-comment")) { var comment = getParameter("operation-comment"); if (comment) { writeComment(comment); } } if (insertToolCall) { onCommand(COMMAND_COOLANT_OFF); if (!isFirstSection() && properties.optionalStop) { onCommand(COMMAND_OPTIONAL_STOP); } if (tool.number > 99) { warning(localize("Tool number exceeds maximum value.")); } writeComment("T" + toolFormat.format(tool.number)); if (tool.comment) { writeComment(tool.comment); } var showToolZMin = false; if (showToolZMin) { if (is3D()) { var numberOfSections = getNumberOfSections(); var zRange = currentSection.getGlobalZRange(); var number = tool.number; for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { var section = getSection(i); if (section.getTool().number != number) { break; } zRange.expandToRange(section.getGlobalZRange()); } writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); } } } /* if (insertToolCall || forceSpindleSpeed || isFirstSection() || (rpmFormat.areDifferent(spindleSpeed, getPreviousSection().getTool().spindleRPM)) || (tool.clockwise != getPreviousSection().getTool().clockwise)) { forceSpindleSpeed = false; if (spindleSpeed < 1) { error(localize("Spindle speed out of range.")); return; } if (spindleSpeed > 99999) { warning(localize("Spindle speed exceeds maximum value.")); } writeComment( sOutput.format(spindleSpeed) ); } */ // wcs var workOffset = currentSection.workOffset; if (workOffset == 0) { warningOnce(localize("Work offset is not supported."), WARNING_WORK_OFFSET); } forceXYZ(); currentToolAxisABC = getWorkPlaneMachineABC(currentSection.workPlane); if (false) { // pure 3D var remaining = currentSection.workPlane; if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { error(localize("Tool orientation is not supported.")); return; } setRotation(remaining); } forceAny(); var abc = new Vector(); if (currentSection.isOptimizedForMachine()) { abc = currentSection.getInitialToolAxisABC(); } var initialPosition = getFramePosition(currentSection.getInitialPosition()); if (false) { if (getCurrentPosition().z < initialPosition.z) { writeBlock("PTP {" + xOutput.format(getCurrentPosition().x) + "," + yOutput.format(getCurrentPosition().y) + "," + zOutput.format(initialPosition.z) + "," + aOutput.format(abc.x) + "," + bOutput.format(abc.y) + "," + cOutput.format(abc.z) + ",S 2,T 10}"); } } if (useTurnTable) { var endRadius = getModulus(initialPosition.x, initialPosition.y); var c = getCClosest(initialPosition.x, initialPosition.y, cOutput.getCurrent()); var e1 = -c; writeBlock("PTP {" + xOutput.format(0) + "," + yOutput.format(endRadius) + "," + zOutput.format(initialPosition.z) + "," + aOutput.format(abc.x) + "," + bOutput.format(abc.y) + "," + cOutput.format(Math.PI) + ",E1 " + abcFormat.format(e1) + ",E2 " + abcFormat.format(0) + ",E3 " + abcFormat.format(0) + ",E4 " + abcFormat.format(0) + ",E5 " + abcFormat.format(0) + ",E6 " + abcFormat.format(0) + "}"); } else { writeBlock("PTP {" + xOutput.format(initialPosition.x) + "," + yOutput.format(initialPosition.y) + "," + zOutput.format(initialPosition.z) + "," + aOutput.format(abc.x) + "," + bOutput.format(abc.y) + "," + cOutput.format(abc.z) + ",S 2,T 10}"); } firstLin = true; // set coolant after we have positioned at Z setCoolant(tool.coolant); } function onDwell(seconds) { if (seconds > 99999.999) { warning(localize("Dwelling time is out of range.")); } seconds = clamp(0.001, seconds, 99999.999); writeBlock("WAIT SEC " + secFormat.format(seconds)); } function onSpindleSpeed(spindleSpeed) { writeBlock(sOutput.format(spindleSpeed)); } var pendingRadiusCompensation = -1; function onRadiusCompensation() { pendingRadiusCompensation = radiusCompensation; } function onRapid(_x, _y, _z) { onRapid5D(_x, _y, _z, currentToolAxisABC.x, currentToolAxisABC.y, currentToolAxisABC.z); } function onLinear(_x, _y, _z, feed) { onLinear5D(_x, _y, _z, currentToolAxisABC.x, currentToolAxisABC.y, currentToolAxisABC.z, feed); } function onRapid5D(_x, _y, _z, _a, _b, _c) { return onLinear5D(_x, _y, _z, _a, _b, _c, highFeedrate); } function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { if (pendingRadiusCompensation >= 0) { error(localize("Radius compensation mode is not supported by robot.")); return; } writeBlock(feedOutput.format(feed)); if (useTurnTable) { var start = getCurrentPosition(); var startRadius = getModulus(start.x, start.y); var endRadius = getModulus(_x, _y); var radius = Math.min(startRadius, endRadius); if (!xyzFormat.areDifferent(startRadius, endRadius)) { var c = getCClosest(_x, _y, cOutput.getCurrent()); writeLin(0, endRadius, _z, -Math.PI/2, 0, Math.PI, -c); return; } if (radius < 0.1) { error(localize("Cannot machine radius 0.")); return; } var c = getCClosest(_x, _y, cOutput.getCurrent()); var sweep = Math.abs(c - cOutput.getCurrent()); if (sweep >= (Math.PI - 1e-6)) { error(localize("Cannot machine 180deg sweep.")); return; } var numberOfSegments = getNumberOfSegments(radius, sweep, getTolerance()); // writeComment("onExpandedLinear(): C-sweep:" + abcFormat.format(sweep) + " #segments:" + numberOfSegments); var factor = 1.0/numberOfSegments; for (var i = 1; i <= numberOfSegments; ++i) { var u = i * factor; var ux = u * _x + (1 - u) * start.x; var uy = u * _y + (1 - u) * start.y; var uz = u * _z + (1 - u) * start.z; var y = getModulus(ux, uy); var c = getCClosest(ux, uy, cOutput.getCurrent()); writeLin(0, y, uz, -Math.PI/2, 0, Math.PI, -c); } } else { writeLin(_x, _y, _z, _a, _b, _c); } } function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { if (properties.useCIRC) { var ip = getPositionU(0.5); writeBlock( "CIRC {" + xOutput.format(ip.x) + "," + yOutput.format(ip.y) + "," + zOutput.format(ip.z) + "," + aOutput.format(currentToolAxisABC.x) + "," + bOutput.format(currentToolAxisABC.y) + "," + cOutput.format(currentToolAxisABC.z) + "},{" + xOutput.format(x) + "," + yOutput.format(y) + "," + zOutput.format(z) + "," + aOutput.format(currentToolAxisABC.x) + "," + bOutput.format(currentToolAxisABC.y) + "," + cOutput.format(currentToolAxisABC.z) + "} C_DIS" ); } else { linearize(tolerance); } } var currentCoolantMode = COOLANT_OFF; function setCoolant(coolant) { if (coolant == currentCoolantMode) { return; // coolant is already active } switch (coolant) { case COOLANT_OFF: default: warning(localize("Coolant not supported.")); if (currentCoolantMode == COOLANT_OFF) { return; } coolant = COOLANT_OFF; } currentCoolantMode = coolant; } function onCommand(command) { switch (command) { case COMMAND_STOP: writeBlock("HALT"); forceSpindleSpeed = true; return; case COMMAND_OPTIONAL_STOP: writeComment("WAIT FOR $IN[1]"); // need variable 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: return; case COMMAND_UNLOCK_MULTI_AXIS: return; case COMMAND_BREAK_CONTROL: return; case COMMAND_TOOL_MEASURE: return; default: onUnsupportedCommand(command); } } function onSectionEnd() { var start = getCurrentPosition(); var _a = currentToolAxisABC.x; var _b = currentToolAxisABC.y; var _c = currentToolAxisABC.z; if (useTurnTable) { var endRadius = getModulus(start.x, start.y); var z = start.z; var c = getCClosest(start.x, start.y, cOutput.getCurrent()); var e1 = -c; _c = Math.PI; writeBlock("LIN {" + xOutput.format(0) + "," + yOutput.format(endRadius) + "," + zOutput.format(z) + "," + aOutput.format(_a) + "," + bOutput.format(_b) + "," + cOutput.format(_c) + ",E1 " + abcFormat.format(e1) /*+ ",E2 " + abcFormat.format(0) + ",E3 " + abcFormat.format(0) + ",E4 " + abcFormat.format(0) + ",E5 " + abcFormat.format(0) + ",E6 " + abcFormat.format(0)*/ + "}"); } else { writeBlock("LIN {" + xOutput.format(start.x) + "," + yOutput.format(start.y) + "," + zOutput.format(start.z) + "," + aOutput.format(_a) + "," + bOutput.format(_b) + "," + cOutput.format(_c) + "}"); } if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || (tool.number != getNextSection().getTool().number)) { onCommand(COMMAND_BREAK_CONTROL); } forceAny(); } function onClose() { onCommand(COMMAND_COOLANT_OFF); writeln(""); writeBlock("END"); }