@@ -30,8 +30,9 @@ Changelog
30
30
11 Jun 2020 - V1.0.17 : Improved the header comments, code formatting, removed all tab chars, fixed multifile name extensions
31
31
21 Jul 2020 - V1.0.18 : Combined with Laser post - will output laser file as if an extra tool.
32
32
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
33
34
*/
34
- obversion = ' V1.0.19 ' ;
35
+ obversion = ' V1.0.20 ' ;
35
36
description = " OpenBuilds CNC : GRBL/BlackBox" ; // cannot have brackets in comments
36
37
vendor = " OpenBuilds" ;
37
38
vendorUrl = " https://openbuilds.com" ;
@@ -240,7 +241,10 @@ var power = 0; // the setpower value, for S word when laser cuttign
240
241
var cutmode = 0 ; // M3 or M4
241
242
var Zmax = 0 ;
242
243
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
244
248
245
249
function toTitleCase (str) {
246
250
// function to reformat a string to 'title case'
@@ -362,7 +366,22 @@ function writeComment(text) {
362
366
// Remove special characters which could confuse GRBL : $, !, ~, ?, (, )
363
367
// In order to make it simple, I replace everything which is not A-Z, 0-9, space, : , .
364
368
// 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, " " ) + " )" );
366
385
}
367
386
368
387
function writeHeader (secID) {
@@ -683,6 +702,7 @@ function onSection() {
683
702
// At end of a section, spindle is retracted to clearance height, so it is only needed on the first section
684
703
// it is done with G53 - machine coordinates, so I put it in front of anything else
685
704
if (isFirstSection()) {
705
+ zOutput.reset();
686
706
writeBlock(gFormat.format(53), gMotionModal.format(0), zOutput.format(toPreciseUnit( properties.machineHomeZ, MM))); // Retract spindle to Machine Z Home
687
707
gMotionModal.reset();
688
708
} else if (properties.generateMultiple && (tool.number != getPreviousSection().getTool().number))
@@ -706,7 +726,7 @@ function onSection() {
706
726
// spindle on delay if needed
707
727
if (m && (isFirstSection() || isNewfile))
708
728
onDwell(properties.spindleOnOffDelay);
709
-
729
+
710
730
} else {
711
731
if (properties.UseZ)
712
732
if (isFirstSection() || (properties.generateMultiple && (tool.number != getPreviousSection().getTool().number)) )
@@ -762,6 +782,7 @@ function onRadiusCompensation() {
762
782
}
763
783
764
784
function onRapid (_x, _y, _z) {
785
+ haveRapid = true;
765
786
if (!isLaser) {
766
787
var x = xOutput.format(_x);
767
788
var y = yOutput.format(_y);
@@ -786,16 +807,23 @@ function onRapid(_x, _y, _z) {
786
807
}
787
808
788
809
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
+ }
791
814
var x = xOutput.format(_x);
792
815
var y = yOutput.format(_y);
793
816
var f = feedOutput.format(feed);
794
817
if (!isLaser) {
795
818
var z = zOutput.format(_z);
796
819
797
820
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);
799
827
} else if (f) {
800
828
if (getNextRecord().isMotion()) {
801
829
feedOutput.reset(); // force feed on next line
@@ -806,9 +834,21 @@ function onLinear(_x, _y, _z, feed) {
806
834
} else {
807
835
// laser
808
836
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
+
812
852
}
813
853
}
814
854
}
@@ -924,6 +964,24 @@ function onCommand(command) {
924
964
writeComment("Program end (M02)");
925
965
writeBlock(mFormat.format(2));
926
966
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;
927
977
}
928
978
// for other commands see https://cam.autodesk.com/posts/reference/classPostProcessor.html#af3a71236d7fe350fd33bdc14b0c7a4c6
929
979
}
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