47
47
22 Dec 2022 - V1.0.33 : refactored file naming and debugging, indented with astyle
48
48
10 Mar 2023 - V1.0.34 : move coolant code to the spindle control line to help with restarts
49
49
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
51
51
*/
52
- obversion = ' V1.0.36.beta ' ;
52
+ obversion = ' V1.0.36' ;
53
53
description = " OpenBuilds CNC : GRBL/BlackBox" ; // cannot have brackets in comments
54
54
longDescription = description + " : Post" + obversion; // adds description to post library dialog box
55
55
vendor = " OpenBuilds" ;
@@ -75,9 +75,10 @@ minimumCircularSweep = toRad(0.1); // was 0.01
75
75
maximumCircularSweep = toRad(180 );
76
76
allowHelicalMoves = true;
77
77
allowSpiralMoves = 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.
81
82
82
83
// user-defined properties : defaults are set, but they can be changed from a dialog box in Fusion when doing a post.
83
84
properties =
@@ -212,7 +213,7 @@ propertyDefinitions =
212
213
linearizeSmallArcs: {
213
214
group: " arcs" ,
214
215
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." ,
216
217
type: " boolean" ,
217
218
},
218
219
@@ -517,6 +518,16 @@ function writeHeader(secID)
517
518
writeComment(" Laser UseZ = " + properties.UseZ);
518
519
writeComment(" Laser UsePierce = " + properties.UsePierce);
519
520
}
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
+ }
520
531
521
532
writeln(" " );
522
533
if (hasGlobalParameter(" document-path" ))
@@ -1204,13 +1215,14 @@ function onLinear5D(_x, _y, _z, _a, _b, _c, feed)
1204
1215
1205
1216
// this code was generated with the help of ChatGPT AI
1206
1217
// 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!
1207
1219
// if error then returns -9.9375 for all coordinates
1208
1220
// 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
1210
1222
function calculateCircleCenters (point1, point2, radius)
1211
1223
{
1212
1224
// 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) );
1214
1226
if (distance > (radius * 2))
1215
1227
{
1216
1228
//-9.9375 is perfectly stored by doubles and singles and will pass an equality test
@@ -1244,7 +1256,7 @@ function calculateCircleCenters(point1, point2, radius)
1244
1256
1245
1257
// given the 2 points and existing center, find a new, more accurate center
1246
1258
// only works in x,y
1247
- // point parameters are Vectors
1259
+ // point parameters are Vectors, this converts them to arrays for the calc
1248
1260
// returns a Vector point with the revised center values in x,y, ignore Z
1249
1261
function newCenter (p1, p2, oldcenter, radius)
1250
1262
{
@@ -1265,6 +1277,7 @@ function newCenter(p1, p2, oldcenter, radius)
1265
1277
nc2 = new Vector(newcenters[1 ].x, newcenters[1 ].y, 0 );
1266
1278
d1 = Vector.diff(oldcenter, nc1).length;
1267
1279
d2 = Vector.diff(oldcenter, nc2).length;
1280
+ // return the new center that is closest to the old center
1268
1281
if (d1 < d2)
1269
1282
return nc1;
1270
1283
else
@@ -1274,6 +1287,7 @@ function newCenter(p1, p2, oldcenter, radius)
1274
1287
/*
1275
1288
helper for on Circular - calculates a new center for arcs with differing radii
1276
1289
returns the revised center vector
1290
+ maps arcs to XY plane, recenters, and reversemaps to return the new center in the correct plane
1277
1291
*/
1278
1292
function ReCenter (start, end , center, radius, cp)
1279
1293
{
@@ -1282,7 +1296,7 @@ function ReCenter(start, end, center, radius, cp)
1282
1296
switch (cp)
1283
1297
{
1284
1298
case PLANE_XY:
1285
- writeComment('recenter XY');
1299
+ if (debugMode) writeComment('recenter XY');
1286
1300
var nCenter = newCenter(start, end, center, radius );
1287
1301
// writeComment("old center " + center.x + " , " + center.y);
1288
1302
// writeComment("new center " + nCenter.x + " , " + nCenter.y);
@@ -1303,7 +1317,7 @@ function ReCenter(start, end, center, radius, cp)
1303
1317
}
1304
1318
break;
1305
1319
case PLANE_ZX:
1306
- writeComment(' recenter ZX' );
1320
+ if (debugMode) writeComment(' recenter ZX' );
1307
1321
// generate fake x,y vectors
1308
1322
var st = new Vector( start.x, start.z, 0 );
1309
1323
var ed = new Vector(end .x, end .z, 0 )
@@ -1325,7 +1339,7 @@ function ReCenter(start, end, center, radius, cp)
1325
1339
}
1326
1340
break;
1327
1341
case PLANE_YZ:
1328
- writeComment(' recenter YZ' );
1342
+ if (debugMode) writeComment(' recenter YZ' );
1329
1343
var st = new Vector(start.z, start.y, 0 );
1330
1344
var ed = new Vector(end .z, end .y, 0 )
1331
1345
var ct = new Vector(center.z, center.y, 0 );
@@ -1369,7 +1383,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
1369
1383
{
1370
1384
case PLANE_XY:
1371
1385
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
1373
1387
case PLANE_YZ:
1374
1388
// fix X
1375
1389
center.x = (start.x + end.x) / 2.0;
@@ -1384,33 +1398,33 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
1384
1398
// check for differing radii
1385
1399
var r1 = Vector.diff(start, center).length;
1386
1400
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)
1390
1407
{
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);
1400
1412
}
1413
+ }
1401
1414
1402
1415
// arcs smaller than bitradius always have significant radius errors,
1403
1416
// so get radius and linearize them (because we cannot change minimumCircularRadius here)
1404
1417
// note that larger arcs still have radius errors, but they are a much smaller percentage of the radius
1405
1418
// 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
+ }
1414
1428
// not small and not a full circle, output G2 or G3
1415
1429
if ((isLaser || isPlasma) && !powerOn)
1416
1430
{
@@ -1424,6 +1438,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
1424
1438
case PLANE_XY:
1425
1439
xOutput.reset(); // must always have X and Y
1426
1440
yOutput.reset();
1441
+ // dont need to do ioutput and joutput because they are reference variables
1427
1442
if (!isLaser && !isPlasma)
1428
1443
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));
1429
1444
else
@@ -1433,7 +1448,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
1433
1448
}
1434
1449
break;
1435
1450
case PLANE_ZX:
1436
- if (!isLaser)
1451
+ if (!isLaser && !isPlasma )
1437
1452
{
1438
1453
xOutput.reset(); // always have X and Z
1439
1454
zOutput.reset();
@@ -1443,7 +1458,7 @@ function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
1443
1458
linearize(tolerance);
1444
1459
break;
1445
1460
case PLANE_YZ:
1446
- if (!isLaser)
1461
+ if (!isLaser && !isPlasma )
1447
1462
{
1448
1463
yOutput.reset(); // always have Y and Z
1449
1464
zOutput.reset();
0 commit comments