Skip to content

Commit 9b7c07c

Browse files
committed
remove % from end of file, option to linearize small arcs
1 parent 86a370a commit 9b7c07c

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

OpenbuildsFusion360PostGrbl.cps

+35-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ Changelog
3434
02 Oct 2020 - V1.0.20 : Fix for long comments and new restrictions
3535
05 Nov 2020 - V1.0.21 : poweron/off for plasma, coolant can be turned on for laser/plasma too
3636
04 Dec 2020 - V1.0.22 : Add Router11 and dial settings
37+
16 Jan 2021 - V1.0.23 : Remove end of file marker '%' from end of output, arcs smaller than toolRadius will be linearized
3738
*/
38-
obversion = 'V1.0.22';
39+
obversion = 'V1.0.23';
3940
description = "OpenBuilds CNC : GRBL/BlackBox"; // cannot have brackets in comments
4041
vendor = "OpenBuilds";
4142
vendorUrl = "https://openbuilds.com";
@@ -80,6 +81,7 @@ properties =
8081
PowerThrough : 50,
8182
PowerEtch : 2,
8283
UseZ : false, // if true then Z will be moved to 0 at beginning and back to 'retract height' at end
84+
linearizeSmallArcs: false, // arcs with radius < toolRadius have radius errors, linearize instead?
8385
machineVendor : "OpenBuilds",
8486
machineModel : "Generic",
8587
machineControl : "Grbl 1.1 / BlackBox",
@@ -165,11 +167,17 @@ propertyDefinitions = {
165167
type:"spatial",
166168
group: 6
167169
},
170+
linearizeSmallArcs: {
171+
title:"Linearize Small Arcs",
172+
description: "Arcs with radius < toolRadius can have mismatched radii, set this to Yes to linearize them.",
173+
type:"boolean",
174+
group: 6
175+
},
168176
169177
_Section5: {title:"--- LASER/PLASMA CUTTING OPTIONS ---", description:"Informational only. Not used for any computation.", type:"string", group: 7},
170178
PowerVaporise: {title:"Power for Vaporizing", description:"Scary power VAPORIZE power setting, in percent.", group:8, type:"integer"},
171179
PowerThrough: {title:"Power for Through Cutting", description:"Normal Through cutting power, in percent.", group:8, type:"integer"},
172-
PowerEtch: {title:"Power for Etching", description:"Just enoguh power to Etch the surface, in percent.", group:8, type:"integer"},
180+
PowerEtch: {title:"Power for Etching", description:"Just enough power to Etch the surface, in percent.", group:8, type:"integer"},
173181
UseZ: {title:"Use Z motions at start and end.", description:"Use True if you have a laser on a router with Z motion, or a PLASMA cutter.", group:8, type:"boolean"},
174182

175183
_Section6: {
@@ -217,7 +225,7 @@ var feedOutput = createVariable({prefix:"F"}, feedFormat);
217225
var sOutput = createVariable({prefix:"S", force:false}, rpmFormat);
218226
var mOutput = createVariable({force:false}, mFormat); // only use for M3/4/5
219227

220-
// for arcs, use extra digit (not used anymore from jan 2018)
228+
// for arcs
221229
var xaOutput = createVariable({prefix:"X", force:true}, arcFormat);
222230
var yaOutput = createVariable({prefix:"Y", force:true}, arcFormat);
223231
var zaOutput = createVariable({prefix:"Z", force:false}, arcFormat);
@@ -250,6 +258,7 @@ var haveRapid = false; // assume no rapid moves
250258
var powerOn = false; // is the laser power on? used for laser when haveRapid=false
251259
var retractHeight = 1; // will be set by onParameter and used in onLinear to detect rapids
252260
var linmove = 1; // linear move mode
261+
var toolRadius; // for arc linearization
253262

254263
function toTitleCase(str) {
255264
// function to reformat a string to 'title case'
@@ -626,6 +635,8 @@ function onSection() {
626635
var tool = section.getTool();
627636
var maxfeedrate = section.getMaximumFeedrate();
628637
638+
toolRadius = tool.diameter / 2.0;
639+
629640
if (!isFirstSection() && properties.generateMultiple && (tool.number != getPreviousSection().getTool().number)) {
630641
sequenceNumber ++;
631642
//var fileIndexFormat = createFormat({width:3, zeropad: true, decimals:0});
@@ -723,6 +734,7 @@ function onSection() {
723734
gMotionModal.reset();
724735
} else if (properties.generateMultiple && (tool.number != getPreviousSection().getTool().number))
725736
writeBlock(gFormat.format(53), gFormat.format(0), zOutput.format(toPreciseUnit(properties.machineHomeZ, MM))); // Retract spindle to Machine Z Home
737+
726738
// Insert the Spindle start command
727739
if (tool.clockwise) {
728740
s = sOutput.format(tool.spindleRPM);
@@ -890,13 +902,22 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
890902
var start = getCurrentPosition();
891903
xOutput.reset();
892904
yOutput.reset();
905+
906+
// arcs smaller than bitradius always have significant radius errors, so get radius and linearize them (because we cannot change minimumCircularRadius here)
907+
// note that larger arcs still have radius errors, but they are a much smaller percentage of the radius
908+
var rad = Math.sqrt(Math.pow(start.x - cx,2) + Math.pow(start.y - cy, 2));
909+
if (properties.linearizeSmallArcs && (rad < toolRadius)) {
910+
//writeComment("linearizing arc radius " + round(rad,4) + " toolRadius " + round(toolRadius,3));
911+
linearize(tolerance);
912+
return;
913+
}
893914
if (isFullCircle()) {
894915
writeComment("full circle");
895916
linearize(tolerance);
896917
return;
897918
} else {
898919
if (isPlasma && !powerOn)
899-
linearize(tolerance * 4);
920+
linearize(tolerance * 4); // this is a rapid move so tolerance can be increased for faster motion and fewer lines of code
900921
else
901922
switch (getCircularPlane()) {
902923
case PLANE_XY:
@@ -964,7 +985,7 @@ function onClose() {
964985
writeBlock(gMotionModal.format(0), xOutput.format(0), yOutput.format(0));
965986
}
966987
writeBlock(mFormat.format(30)); // Program End
967-
writeln("%"); // EndOfFile marker
988+
//writeln("%"); // EndOfFile marker
968989
}
969990

970991
function onTerminate() {
@@ -1021,3 +1042,12 @@ function onParameter(name, value) {
10211042
onDwell(properties.spindleOnOffDelay);
10221043
}
10231044
}
1045+
1046+
function round(num,digits) {
1047+
return toFixedNumber(num,digits,10)
1048+
}
1049+
1050+
function toFixedNumber(num, digits, base) {
1051+
var pow = Math.pow(base||10, digits); // cleverness found on web
1052+
return Math.round(num*pow) / pow;
1053+
}

0 commit comments

Comments
 (0)