Skip to content

Commit 7e75403

Browse files
committed
fix for long comments and rapids
fix missing Z word with G53 at start
1 parent f286e10 commit 7e75403

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

OpenbuildsFusion360PostGrbl.cps

+68-10
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Changelog
3030
11 Jun 2020 - V1.0.17 : Improved the header comments, code formatting, removed all tab chars, fixed multifile name extensions
3131
21 Jul 2020 - V1.0.18 : Combined with Laser post - will output laser file as if an extra tool.
3232
08 Aug 2020 - V1.0.19 : Fix for spindleondelay missing on subfiles
33+
02 Oct 2020 - V1.0.20 : Fix for long comments and new restrictions
3334
*/
34-
obversion = 'V1.0.19';
35+
obversion = 'V1.0.20';
3536
description = "OpenBuilds CNC : GRBL/BlackBox"; // cannot have brackets in comments
3637
vendor = "OpenBuilds";
3738
vendorUrl = "https://openbuilds.com";
@@ -240,7 +241,10 @@ var power = 0; // the setpower value, for S word when laser cuttign
240241
var cutmode = 0; // M3 or M4
241242
var Zmax = 0;
242243
var workOffset = 0;
243-
244+
var haveRapid = false; // assume no rapid moves
245+
var powerOn = false; // is the laser power on? used for laser when haveRapid=false
246+
var retractHeight = 1; // will be set by onParameter and used in onLinear to detect rapids
247+
var linmove = 1; // linear move mode
244248

245249
function toTitleCase(str) {
246250
// function to reformat a string to 'title case'
@@ -362,7 +366,22 @@ function writeComment(text) {
362366
// Remove special characters which could confuse GRBL : $, !, ~, ?, (, )
363367
// In order to make it simple, I replace everything which is not A-Z, 0-9, space, : , .
364368
// Finally put everything between () as this is the way GRBL & UGCS expect comments
365-
writeln("(" + String(text).replace( /[^a-zA-Z\d:=,.]+/g, " ") + ")");
369+
// v20 - split the line so no comment is longer than 70 chars
370+
if (text.length > 70) {
371+
text = String(text).replace( /[^a-zA-Z\d:=,.]+/g, " "); // remove illegal chars
372+
var bits = text.split(" "); // get all the words
373+
var out = '';
374+
for (i = 0; i < bits.length; i++) {
375+
out += bits[i] + " ";
376+
if (out.length > 60) { // a logn word on the end can take us to 80 chars!
377+
writeln("(" + out.trim() + ")");
378+
out = "";
379+
}
380+
}
381+
if (out.length > 0)
382+
writeln("(" + out.trim() + ")");
383+
} else
384+
writeln("(" + String(text).replace( /[^a-zA-Z\d:=,.]+/g, " ") + ")");
366385
}
367386

368387
function writeHeader(secID) {
@@ -683,6 +702,7 @@ function onSection() {
683702
// At end of a section, spindle is retracted to clearance height, so it is only needed on the first section
684703
// it is done with G53 - machine coordinates, so I put it in front of anything else
685704
if (isFirstSection()) {
705+
zOutput.reset();
686706
writeBlock(gFormat.format(53), gMotionModal.format(0), zOutput.format(toPreciseUnit( properties.machineHomeZ, MM))); // Retract spindle to Machine Z Home
687707
gMotionModal.reset();
688708
} else if (properties.generateMultiple && (tool.number != getPreviousSection().getTool().number))
@@ -706,7 +726,7 @@ function onSection() {
706726
// spindle on delay if needed
707727
if (m && (isFirstSection() || isNewfile))
708728
onDwell(properties.spindleOnOffDelay);
709-
729+
710730
} else {
711731
if (properties.UseZ)
712732
if (isFirstSection() || (properties.generateMultiple && (tool.number != getPreviousSection().getTool().number)) )
@@ -762,6 +782,7 @@ function onRadiusCompensation() {
762782
}
763783

764784
function onRapid(_x, _y, _z) {
785+
haveRapid = true;
765786
if (!isLaser) {
766787
var x = xOutput.format(_x);
767788
var y = yOutput.format(_y);
@@ -786,16 +807,23 @@ function onRapid(_x, _y, _z) {
786807
}
787808

788809
function onLinear(_x, _y, _z, feed) {
789-
xOutput.reset();
790-
yOutput.reset(); // always output x and y else arcs go mad
810+
if (powerOn || haveRapid) { // do not reset if power is off - for laser G0 moves
811+
xOutput.reset();
812+
yOutput.reset(); // always output x and y else arcs go mad
813+
}
791814
var x = xOutput.format(_x);
792815
var y = yOutput.format(_y);
793816
var f = feedOutput.format(feed);
794817
if (!isLaser) {
795818
var z = zOutput.format(_z);
796819
797820
if (x || y || z) {
798-
writeBlock(gMotionModal.format(1), x, y, z, f);
821+
if (!haveRapid && z) // if z is changing
822+
if (_z < retractHeight) // compare it to retractHeight, below that is G1, >= is G0
823+
linmove = 1;
824+
else
825+
linmove = 0;
826+
writeBlock(gMotionModal.format(linmove), x, y, z, f);
799827
} else if (f) {
800828
if (getNextRecord().isMotion()) {
801829
feedOutput.reset(); // force feed on next line
@@ -806,9 +834,21 @@ function onLinear(_x, _y, _z, feed) {
806834
} else {
807835
// laser
808836
if (x || y) {
809-
var z = properties.UseZ ? zOutput.format(0) : "";
810-
var s = sOutput.format(power);
811-
writeBlock(gMotionModal.format(1), x, y, z, f, s);
837+
if (haveRapid) {
838+
// this is the old process when we have rapids inserted by onRapid
839+
var z = properties.UseZ ? zOutput.format(0) : "";
840+
var s = sOutput.format(power);
841+
writeBlock(gMotionModal.format(1), x, y, z, f, s);
842+
} else {
843+
// this is the new process when do dont have onRapid but GRBL requires G0 moves for noncutting laser moves
844+
var z = properties.UseZ ? zOutput.format(0) : "";
845+
var s = sOutput.format(power);
846+
if (powerOn)
847+
writeBlock(gMotionModal.format(1), x, y, z, f, s);
848+
else
849+
writeBlock(gMotionModal.format(0), x, y, z, f, s);
850+
}
851+
812852
}
813853
}
814854
}
@@ -924,6 +964,24 @@ function onCommand(command) {
924964
writeComment("Program end (M02)");
925965
writeBlock(mFormat.format(2));
926966
break;
967+
case COMMAND_POWER_OFF:
968+
//writeComment("power off");
969+
writeln("");
970+
powerOn = false;
971+
break;
972+
case COMMAND_POWER_ON:
973+
//writeComment("power ON");
974+
writeln("");
975+
powerOn = true;
976+
break;
927977
}
928978
// for other commands see https://cam.autodesk.com/posts/reference/classPostProcessor.html#af3a71236d7fe350fd33bdc14b0c7a4c6
929979
}
980+
981+
function onParameter(name, value) {
982+
//writeComment("onParameter =" + name + "= :" + value); // (onParameter =operation:retractHeight value= :5)
983+
if ( (name.indexOf("retractHeight") >= 0) && (name.indexOf("value") >= 0 ) ) { // == "operation:retractHeight value")
984+
retractHeight = value;
985+
//writeComment("OPERATION " + name +":"+value);
986+
}
987+
}

0 commit comments

Comments
 (0)