4747 22 Dec 2022 - V1.0.33 : refactored file naming and debugging, indented with astyle
4848 10 Mar 2023 - V1.0.34 : move coolant code to the spindle control line to help with restarts
4949 26 Mar 2023 - V1.0.35 : plasma pierce height override, spindle speed change always with an M3, version number display
50- 03 Jun 2023 - V1.0 .36b: beta of code to recenter arcs with bad radii
50+ 03 Jun 2023 - V1.0.36 : code to recenter arcs with bad radii
5151*/
52- obversion = ' V1.0.36.beta ' ;
52+ obversion = ' V1.0.36' ;
5353description = " OpenBuilds CNC : GRBL/BlackBox" ; // cannot have brackets in comments
5454longDescription = description + " : Post" + obversion; // adds description to post library dialog box
5555vendor = " OpenBuilds" ;
@@ -75,9 +75,10 @@ minimumCircularSweep = toRad(0.1); // was 0.01
7575maximumCircularSweep = toRad(180 );
7676allowHelicalMoves = true;
7777allowSpiralMoves = false;
78- allowedCircularPlanes = (1 << PLANE_XY) | (1 << PLANE_ZX) | (1 << PLANE_YZ); // only XY, ZX, and YZ planes
79- // the above circular plane limitation appears to be a solution to the faulty arcs problem (but is not entirely)
80- // an alternative is to set EITHER minimumChordLength OR minimumCircularRadius to a much larger value, like 0.5mm
78+ allowedCircularPlanes = (1 << PLANE_XY); // allow only XY plane
79+ // if you need vertical arcs then uncomment the line below
80+ // allowedCircularPlanes = (1 << PLANE_XY) | (1 << PLANE_ZX) | (1 << PLANE_YZ); // allow all planes, recentering arcs solves YZ/XZ arcs
81+ // if you allow vertical arcs then be aware that ObCONTROL will not display the gocde correctly, but it WILL cut correctly.
8182
8283// user-defined properties : defaults are set, but they can be changed from a dialog box in Fusion when doing a post.
8384properties =
@@ -212,7 +213,7 @@ propertyDefinitions =
212213 linearizeSmallArcs: {
213214 group: " arcs" ,
214215 title: " ARCS: Linearize Small Arcs" ,
215- description: " Arcs with radius < toolRadius can have mismatched radii, set this to Yes to linearize them. This solves G2/G3 radius mismatch errors." ,
216+ description: " Arcs with radius < toolRadius can have mismatched radii, set this to Yes to linearize them. This solves G2/G3 radius mismatch errors." ,
216217 type: " boolean" ,
217218 },
218219
@@ -517,6 +518,16 @@ function writeHeader(secID)
517518 writeComment(" Laser UseZ = " + properties.UseZ);
518519 writeComment(" Laser UsePierce = " + properties.UsePierce);
519520 }
521+ if (allowedCircularPlanes == 1)
522+ {
523+ writeln(" " );
524+ writeComment(" Arcs are limited to the XY plane: if you want vertical arcs then edit allowedCircularPlanes in the CPS file " );
525+ }
526+ else
527+ {
528+ writeln(" " );
529+ writeComment(" Arcs can occur on XY,YZ,ZX planes: CONTROL may not display them correctly but they will cut correctly" );
530+ }
520531
521532 writeln(" " );
522533 if (hasGlobalParameter(" document-path" ))
@@ -1204,13 +1215,14 @@ function onLinear5D(_x, _y, _z, _a, _b, _c, feed)
12041215
12051216// this code was generated with the help of ChatGPT AI
12061217// calculate the centers for the 2 circles passing through both points at the given radius
1218+ // if you ask chatgpt that ^^^ you will get incorrect code!
12071219// if error then returns -9.9375 for all coordinates
12081220// define points as var point1 = { x: 0, y: 0 };
1209- // returns an array of 2 of those things
1221+ // returns an array of 2 of those things comprising the 2 centers
12101222function calculateCircleCenters (point1, point2, radius)
12111223 {
12121224 // Calculate the distance between the points
1213- var distance = Math.sqrt( Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2) );
1225+ var distance = Math.sqrt( Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2) );
12141226 if (distance > (radius * 2))
12151227 {
12161228 //-9.9375 is perfectly stored by doubles and singles and will pass an equality test
@@ -1244,7 +1256,7 @@ function calculateCircleCenters(point1, point2, radius)
12441256
12451257// given the 2 points and existing center, find a new, more accurate center
12461258// only works in x,y
1247- // point parameters are Vectors
1259+ // point parameters are Vectors, this converts them to arrays for the calc
12481260// returns a Vector point with the revised center values in x,y, ignore Z
12491261function newCenter (p1, p2, oldcenter, radius)
12501262 {
@@ -1265,6 +1277,7 @@ function newCenter(p1, p2, oldcenter, radius)
12651277 nc2 = new Vector(newcenters[1 ].x, newcenters[1 ].y, 0 );
12661278 d1 = Vector.diff(oldcenter, nc1).length;
12671279 d2 = Vector.diff(oldcenter, nc2).length;
1280+ // return the new center that is closest to the old center
12681281 if (d1 < d2)
12691282 return nc1;
12701283 else
@@ -1274,6 +1287,7 @@ function newCenter(p1, p2, oldcenter, radius)
12741287/*
12751288 helper for on Circular - calculates a new center for arcs with differing radii
12761289 returns the revised center vector
1290+ maps arcs to XY plane, recenters, and reversemaps to return the new center in the correct plane
12771291*/
12781292function ReCenter (start, end , center, radius, cp)
12791293 {
@@ -1282,7 +1296,7 @@ function ReCenter(start, end, center, radius, cp)
12821296 switch (cp)
12831297 {
12841298 case PLANE_XY:
1285- writeComment('recenter XY');
1299+ if (debugMode) writeComment('recenter XY');
12861300 var nCenter = newCenter(start, end, center, radius );
12871301 // writeComment("old center " + center.x + " , " + center.y);
12881302 // writeComment("new center " + nCenter.x + " , " + nCenter.y);
@@ -1303,7 +1317,7 @@ function ReCenter(start, end, center, radius, cp)
13031317 }
13041318 break;
13051319 case PLANE_ZX:
1306- writeComment(' recenter ZX' );
1320+ if (debugMode) writeComment(' recenter ZX' );
13071321 // generate fake x,y vectors
13081322 var st = new Vector( start.x, start.z, 0 );
13091323 var ed = new Vector(end .x, end .z, 0 )
@@ -1325,7 +1339,7 @@ function ReCenter(start, end, center, radius, cp)
13251339 }
13261340 break;
13271341 case PLANE_YZ:
1328- writeComment(' recenter YZ' );
1342+ if (debugMode) writeComment(' recenter YZ' );
13291343 var st = new Vector(start.z, start.y, 0 );
13301344 var ed = new Vector(end .z, end .y, 0 )
13311345 var ct = new Vector(center.z, center.y, 0 );
@@ -1369,7 +1383,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
13691383 {
13701384 case PLANE_XY:
13711385 center.z = (start.z + end.z) / 2.0; // doing this fixes most arc radius lengths
1372- break;
1386+ break; // because the radius depends on the axial distance as well
13731387 case PLANE_YZ:
13741388 // fix X
13751389 center.x = (start.x + end.x) / 2.0;
@@ -1384,33 +1398,33 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
13841398 // check for differing radii
13851399 var r1 = Vector.diff(start, center).length;
13861400 var r2 = Vector.diff(end , center).length;
1387- // if linearizing and this is small, don't bother to recenter
1388- if ( !(properties.linearizeSmallArcs && (r1 < toolRadius)) )
1389- if (r1 != r2)
1401+ if ( (r1 != r2) && (r1 < toolRadius) ) // always recenter small arcs
1402+ {
1403+ var diff = r1 - r2;
1404+ var pdiff = Math.abs(diff / r1 * 100);
1405+ // if percentage difference too great
1406+ if (pdiff > 0.01)
13901407 {
1391- var diff = r1 - r2;
1392- var pdiff = Math.abs(diff / r1 * 100);
1393- // if percentage difference too great
1394- if (pdiff > 0.01)
1395- {
1396- // adjust center to make radii equal
1397- if (debugMode) writeComment("r1 " + r1 + " r2 " + r2 + " d " + (r1 - r2) + " pdoff " + pdiff );
1398- center = ReCenter(start, end, center, (r1 + r2) /2, cp);
1399- }
1408+ //writeComment("recenter");
1409+ // adjust center to make radii equal
1410+ if (debugMode) writeComment("r1 " + r1 + " r2 " + r2 + " d " + (r1 - r2) + " pdiff " + pdiff );
1411+ center = ReCenter(start, end, center, (r1 + r2) /2, cp);
14001412 }
1413+ }
14011414
14021415 // arcs smaller than bitradius always have significant radius errors,
14031416 // so get radius and linearize them (because we cannot change minimumCircularRadius here)
14041417 // note that larger arcs still have radius errors, but they are a much smaller percentage of the radius
14051418 // and GRBL won't care
1406- var rad = Vector.diff(start,center).length;
1407- if (properties.linearizeSmallArcs && (rad < toolRadius))
1408- {
1409- if (debugMode) writeComment("linearizing arc radius " + round(rad, 4) + " toolRadius " + round(toolRadius, 3));
1410- linearize(tolerance);
1411- if (debugMode) writeComment("done");
1412- return;
1413- }
1419+ var rad = Vector.diff(start,center).length; // radius to NEW Center if it has been calculated
1420+ if (rad < toPreciseUnit(2 , MM)) // only for small arcs, dont need to linearize a 24mm arc on a 50mm tool
1421+ if (properties.linearizeSmallArcs && (rad < toolRadius))
1422+ {
1423+ if (debugMode) writeComment("linearizing arc radius " + round(rad, 4) + " toolRadius " + round(toolRadius, 3));
1424+ linearize(tolerance);
1425+ if (debugMode) writeComment("done");
1426+ return;
1427+ }
14141428 // not small and not a full circle, output G2 or G3
14151429 if ((isLaser || isPlasma) && !powerOn)
14161430 {
@@ -1424,6 +1438,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
14241438 case PLANE_XY:
14251439 xOutput.reset(); // must always have X and Y
14261440 yOutput.reset();
1441+ // dont need to do ioutput and joutput because they are reference variables
14271442 if (!isLaser && !isPlasma)
14281443 writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(center.x - start.x, 0), jOutput.format(center.y - start.y, 0), feedOutput.format(feed));
14291444 else
@@ -1433,7 +1448,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
14331448 }
14341449 break;
14351450 case PLANE_ZX:
1436- if (!isLaser)
1451+ if (!isLaser && !isPlasma )
14371452 {
14381453 xOutput.reset(); // always have X and Z
14391454 zOutput.reset();
@@ -1443,7 +1458,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
14431458 linearize(tolerance);
14441459 break;
14451460 case PLANE_YZ:
1446- if (!isLaser)
1461+ if (!isLaser && !isPlasma )
14471462 {
14481463 yOutput.reset(); // always have Y and Z
14491464 zOutput.reset();
0 commit comments