diff --git a/OpenbuildsGRBL.cps b/OpenbuildsGRBL.cps index be2e78c..c85564e 100644 --- a/OpenbuildsGRBL.cps +++ b/OpenbuildsGRBL.cps @@ -17,6 +17,7 @@ This post-Processor should work on GRBL-based machines such as 30/JAN/2017 - V6 : Modified capabilities to also allow waterjet, laser-cutting.. */ + description = "Openbuilds Grbl"; vendor = "Openbuilds"; vendorUrl = "http://openbuilds.com"; @@ -49,9 +50,12 @@ properties = spindleTwoDirections : false, // true : spindle can rotate clockwise and counterclockwise, will send M3 and M4. false : spindle can only go clockwise, will only send M3 hasCoolant : false, // true : machine uses the coolant output, M8 M9 will be sent. false : coolant output not connected, so no M8 M9 will be sent hasSpeedDial : true, // true : the spindle is of type Makite RT0700, Dewalt 611 with a Dial to set speeds 1-6. false : other spindle + wantHoming: false, // do not home by default, can be dangerous machineHomeZ : -10, // absolute machine coordinates where the machine will move to at the end of the job - first retracting Z, then moving home X Y machineHomeX : -10, - machineHomeY : -10 + machineHomeY : -10, + fourAxis: false, // enable four axis mode + makeAAxisOtherWay: false // change direction of rotation of A axis }; // creation of all kinds of G-code formats - controls the amount of decimals used in the generated G-Code @@ -60,6 +64,7 @@ var mFormat = createFormat({prefix:"M", decimals:0}); var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4)}); var arcFormat = createFormat({decimals:(unit == MM ? 4 : 5)}); // uses extra digit in arcs +var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG}); // A axis is rotating, so set unit as degrees var feedFormat = createFormat({decimals:0}); var rpmFormat = createFormat({decimals:0}); var secFormat = createFormat({decimals:1, forceDecimal:true}); @@ -68,6 +73,9 @@ var taperFormat = createFormat({decimals:1, scale:DEG}); var xOutput = createVariable({prefix:"X"}, xyzFormat); var yOutput = createVariable({prefix:"Y"}, xyzFormat); var zOutput = createVariable({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 sOutput = createVariable({prefix:"S", force:true}, rpmFormat); @@ -144,7 +152,17 @@ function writeComment(text) } function onOpen() - { +{ + if (properties.fourAxis) { + // Create the fourth axis + // See page 23 of https://github.com/AutodeskCAM/Documentation/blob/master/Autodesk%20Post%20Processor%20manual-sm-130829.pdf + var aAxis = createAxis({coordinate:0, table:true, axis:[(properties.makeAAxisOtherWay ? -1 : 1) * -1, 0, 0], cyclic:true, preference:1}); + machineConfiguration = new MachineConfiguration(aAxis); + + setMachineConfiguration(machineConfiguration); + optimizeMachineAngles2(1); // map tip mode + } + // Number of checks capturing fatal errors // 1. is CAD file in same units as our GRBL configuration ? // swarfer : GRBL obeys G20/21 so we should only need to output the correct code for the numbers we are outputting, I will look at this later @@ -165,6 +183,9 @@ function onOpen() // 2. is RadiusCompensation not set incorrectly ? onRadiusCompensation(); + bOutput.disable(); // five and six axis not yet supported + cOutput.disable(); + // 3. here you set all the properties of your machine, so they can be used later on var myMachine = getMachineConfiguration(); myMachine.setWidth(600); @@ -303,7 +324,7 @@ function onSection() writeBlock(gAbsIncModal.format(90)); // Set to absolute coordinates if (isMilling()) { - writeBlock(gFormat.format(53), gMotionModal.format(0), "Z" + xyzFormat.format(properties.machineHomeZ)); // Retract spindle to Machine Z Home + if(properties.wantHoming) writeBlock(gFormat.format(53), gMotionModal.format(0), "Z" + xyzFormat.format(properties.machineHomeZ)); // Retract spindle to Machine Z Home } } @@ -359,15 +380,22 @@ function onSection() forceXYZ(); var remaining = currentSection.workPlane; - if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) + if (!properties.fourAxis && !isSameDirection(remaining.forward, new Vector(0, 0, 1))) { - alert("Error", "Tool-Rotation detected - GRBL only supports 3 Axis"); - error("Fatal Error in Operation " + (sectionId + 1) + ": Tool-Rotation detected but GRBL only supports 3 Axis"); + alert("Error", "Tool-Rotation detected - GRBL ony supports 3 Axis or fourAxis is false"); + error("Fatal Error in Operation " + (sectionId + 1) + ": Tool-Rotation detected but GRBL ony supports 3 Axis or fourAxis is false"); } setRotation(remaining); forceAny(); + // Move A axis first if needed + if (properties.fourAxis) { + // See page 24 of https://github.com/AutodeskCAM/Documentation/blob/master/Autodesk%20Post%20Processor%20manual-sm-130829.pdf + var abc = machineConfiguration.getABC(currentSection.workPlane); + setRotation(machineConfiguration.getRemainingOrientation(abc, currentSection.workPlane)); + writeBlock(gMotionModal.format(0), aOutput.format(abc.x)); + } // Rapid move to initial position, first XY, then Z var initialPosition = getFramePosition(currentSection.getInitialPosition()); writeBlock(gAbsIncModal.format(90), gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y)); @@ -434,14 +462,44 @@ function onLinear(_x, _y, _z, feed) function onRapid5D(_x, _y, _z, _a, _b, _c) { - alert("Error", "Tool-Rotation detected - GRBL only supports 3 Axis"); - error("Tool-Rotation detected but GRBL only supports 3 Axis"); + 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); + feedOutput.reset(); + } } function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { - alert("Error", "Tool-Rotation detected - GRBL only supports 3 Axis"); - error("Tool-Rotation detected but GRBL only supports 3 Axis"); + var x = xOutput.format(_x); + var y = yOutput.format(_y); + var z = zOutput.format(_z); + var a = aOutput.format(_a); + var b = bOutput.format(_b); + var c = cOutput.format(_c); + var f = feedOutput.format(feed); + + if (x || y || z || a || b || c) + { + writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f); + } + else if (f) + { + if (getNextRecord().isMotion()) + { + feedOutput.reset(); // force feed on next line + } + else + { + writeBlock(gMotionModal.format(1), f); + } + } } function onCircular(clockwise, cx, cy, cz, x, y, z, feed) @@ -502,7 +560,7 @@ function onClose() writeBlock(gAbsIncModal.format(90)); // Set to absolute coordinates for the following moves if (isMilling()) { - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), "Z" + xyzFormat.format(properties.machineHomeZ)); // Retract spindle to Machine Z Home + if(properties.wantHoming) writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), "Z" + xyzFormat.format(properties.machineHomeZ)); // Retract spindle to Machine Z Home } writeBlock(mFormat.format(5)); // Stop Spindle if (properties.hasCoolant) @@ -510,7 +568,7 @@ function onClose() writeBlock(mFormat.format(9)); // Stop Coolant } onDwell(properties.spindleOnOffDelay); // Wait for spindle to stop - writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), "X" + xyzFormat.format(properties.machineHomeX), "Y" + xyzFormat.format(properties.machineHomeY)); // Return to home position + if(properties.wantHoming) writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), "X" + xyzFormat.format(properties.machineHomeX), "Y" + xyzFormat.format(properties.machineHomeY)); // Return to home position writeBlock(mFormat.format(30)); // Program End writeln("%"); // EndOfFile marker