|
@@ -333,7 +333,7 @@
|
333
|
333
|
else {
|
334
|
334
|
while (g29_repetition_cnt--) {
|
335
|
335
|
if (cnt > 20) { cnt = 0; idle(); }
|
336
|
|
- const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
336
|
+ const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL);
|
337
|
337
|
if (location.x_index < 0) {
|
338
|
338
|
// No more REACHABLE mesh points to invalidate, so we ASSUME the user
|
339
|
339
|
// meant to invalidate the ENTIRE mesh, which cannot be done with
|
|
@@ -529,7 +529,7 @@
|
529
|
529
|
}
|
530
|
530
|
else {
|
531
|
531
|
while (g29_repetition_cnt--) { // this only populates reachable mesh points near
|
532
|
|
- const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
532
|
+ const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL);
|
533
|
533
|
if (location.x_index < 0) {
|
534
|
534
|
// No more REACHABLE INVALID mesh points to populate, so we ASSUME
|
535
|
535
|
// user meant to populate ALL INVALID mesh points to value
|
|
@@ -744,6 +744,8 @@
|
744
|
744
|
uint16_t max_iterations = GRID_MAX_POINTS;
|
745
|
745
|
|
746
|
746
|
do {
|
|
747
|
+ if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
748
|
+
|
747
|
749
|
#if ENABLED(NEWPANEL)
|
748
|
750
|
if (ubl_lcd_clicked()) {
|
749
|
751
|
SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
|
|
@@ -757,7 +759,10 @@
|
757
|
759
|
}
|
758
|
760
|
#endif
|
759
|
761
|
|
760
|
|
- location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
|
|
762
|
+ if (close_or_far)
|
|
763
|
+ location = find_furthest_invalid_mesh_point();
|
|
764
|
+ else
|
|
765
|
+ location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL);
|
761
|
766
|
|
762
|
767
|
if (location.x_index >= 0) { // mesh point found and is reachable by probe
|
763
|
768
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
|
@@ -767,8 +772,6 @@
|
767
|
772
|
z_values[location.x_index][location.y_index] = measured_z;
|
768
|
773
|
}
|
769
|
774
|
|
770
|
|
- if (do_ubl_mesh_map) display_map(g29_map_type);
|
771
|
|
-
|
772
|
775
|
} while (location.x_index >= 0 && --max_iterations);
|
773
|
776
|
|
774
|
777
|
STOW_PROBE();
|
|
@@ -962,7 +965,7 @@
|
962
|
965
|
|
963
|
966
|
mesh_index_pair location;
|
964
|
967
|
do {
|
965
|
|
- location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
968
|
+ location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_NOZZLE_AS_REFERENCE, NULL);
|
966
|
969
|
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
|
967
|
970
|
if (location.x_index < 0 && location.y_index < 0) continue;
|
968
|
971
|
|
|
@@ -1289,7 +1292,7 @@
|
1289
|
1292
|
*/
|
1290
|
1293
|
void unified_bed_leveling::g29_eeprom_dump() {
|
1291
|
1294
|
unsigned char cccc;
|
1292
|
|
- uint16_t kkkk;
|
|
1295
|
+ unsigned int kkkk; // Needs to be of unspecfied size to compile clean on all platforms
|
1293
|
1296
|
|
1294
|
1297
|
SERIAL_ECHO_START();
|
1295
|
1298
|
SERIAL_ECHOLNPGM("EEPROM Dump:");
|
|
@@ -1299,7 +1302,7 @@
|
1299
|
1302
|
SERIAL_ECHOPGM(": ");
|
1300
|
1303
|
for (uint16_t j = 0; j < 16; j++) {
|
1301
|
1304
|
kkkk = i + j;
|
1302
|
|
- eeprom_read_block(&cccc, (void *)kkkk, 1);
|
|
1305
|
+ eeprom_read_block(&cccc, (const void *) kkkk, sizeof(unsigned char));
|
1303
|
1306
|
print_hex_byte(cccc);
|
1304
|
1307
|
SERIAL_ECHO(' ');
|
1305
|
1308
|
}
|
|
@@ -1345,18 +1348,84 @@
|
1345
|
1348
|
z_values[x][y] -= tmp_z_values[x][y];
|
1346
|
1349
|
}
|
1347
|
1350
|
|
1348
|
|
- mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, uint16_t bits[16], const bool far_flag) {
|
|
1351
|
+
|
|
1352
|
+ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
|
|
1353
|
+
|
|
1354
|
+ bool found_a_NAN = false;
|
|
1355
|
+ bool found_a_real = false;
|
1349
|
1356
|
mesh_index_pair out_mesh;
|
1350
|
1357
|
out_mesh.x_index = out_mesh.y_index = -1;
|
|
1358
|
+ out_mesh.distance = -99999.99;
|
|
1359
|
+
|
|
1360
|
+ for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
1361
|
+ for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
1362
|
+
|
|
1363
|
+ if ( isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
|
|
1364
|
+
|
|
1365
|
+ const float mx = mesh_index_to_xpos(i),
|
|
1366
|
+ my = mesh_index_to_ypos(j);
|
|
1367
|
+
|
|
1368
|
+ if ( !position_is_reachable_by_probe_raw_xy(mx, my)) // make sure the probe can get to the mesh point
|
|
1369
|
+ continue;
|
|
1370
|
+
|
|
1371
|
+ found_a_NAN = true;
|
|
1372
|
+
|
|
1373
|
+ int8_t closest_x=-1, closest_y=-1;
|
|
1374
|
+ float d1, d2 = 99999.9;
|
|
1375
|
+ for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
|
1376
|
+ for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
|
1377
|
+ if (!isnan(z_values[k][l])) {
|
|
1378
|
+ found_a_real = true;
|
|
1379
|
+
|
|
1380
|
+ // Add in a random weighting factor that scrambles the probing of the
|
|
1381
|
+ // last half of the mesh (when every unprobed mesh point is one index
|
|
1382
|
+ // from a probed location).
|
|
1383
|
+
|
|
1384
|
+ d1 = HYPOT(i - k, j - l) + (1.0 / ((millis() % 47) + 13));
|
|
1385
|
+
|
|
1386
|
+ if (d1 < d2) { // found a closer distance from invalid mesh point at (i,j) to defined mesh point at (k,l)
|
|
1387
|
+ d2 = d1; // found a closer location with
|
|
1388
|
+ closest_x = i; // an assigned mesh point value
|
|
1389
|
+ closest_y = j;
|
|
1390
|
+ }
|
|
1391
|
+ }
|
|
1392
|
+ }
|
|
1393
|
+ }
|
|
1394
|
+
|
|
1395
|
+ //
|
|
1396
|
+ // at this point d2 should have the closest defined mesh point to invalid mesh point (i,j)
|
|
1397
|
+ //
|
|
1398
|
+
|
|
1399
|
+ if (found_a_real && (closest_x >= 0) && (d2 > out_mesh.distance)) {
|
|
1400
|
+ out_mesh.distance = d2; // found an invalid location with a greater distance
|
|
1401
|
+ out_mesh.x_index = closest_x; // to a defined mesh point
|
|
1402
|
+ out_mesh.y_index = closest_y;
|
|
1403
|
+ }
|
|
1404
|
+ }
|
|
1405
|
+ } // for j
|
|
1406
|
+ } // for i
|
|
1407
|
+
|
|
1408
|
+ if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
|
|
1409
|
+ out_mesh.x_index = GRID_MAX_POINTS_X / 2;
|
|
1410
|
+ out_mesh.y_index = GRID_MAX_POINTS_Y / 2;
|
|
1411
|
+ out_mesh.distance = 1.0;
|
|
1412
|
+ }
|
|
1413
|
+ return out_mesh;
|
|
1414
|
+ }
|
|
1415
|
+
|
|
1416
|
+ mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, uint16_t bits[16]) {
|
|
1417
|
+ mesh_index_pair out_mesh;
|
|
1418
|
+ out_mesh.x_index = out_mesh.y_index = -1;
|
|
1419
|
+ out_mesh.distance = -99999.9;
|
1351
|
1420
|
|
1352
|
1421
|
// Get our reference position. Either the nozzle or probe location.
|
1353
|
1422
|
const float px = RAW_X_POSITION(lx) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
|
1354
|
1423
|
py = RAW_Y_POSITION(ly) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
|
1355
|
1424
|
|
1356
|
|
- float best_so_far = far_flag ? -99999.99 : 99999.99;
|
|
1425
|
+ float best_so_far = 99999.99;
|
1357
|
1426
|
|
1358
|
|
- for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
1359
|
|
- for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
1427
|
+ for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
1428
|
+ for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
1360
|
1429
|
|
1361
|
1430
|
if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
|
1362
|
1431
|
|| (type == REAL && !isnan(z_values[i][j]))
|
|
@@ -1376,35 +1445,14 @@
|
1376
|
1445
|
continue;
|
1377
|
1446
|
|
1378
|
1447
|
// Reachable. Check if it's the best_so_far location to the nozzle.
|
1379
|
|
- // Add in a weighting factor that considers the current location of the nozzle.
|
1380
|
1448
|
|
1381
|
1449
|
float distance = HYPOT(px - mx, py - my);
|
1382
|
1450
|
|
1383
|
|
- /**
|
1384
|
|
- * If doing the far_flag action, we want to be as far as possible
|
1385
|
|
- * from the starting point and from any other probed points. We
|
1386
|
|
- * want the next point spread out and filling in any blank spaces
|
1387
|
|
- * in the mesh. So we add in some of the distance to every probed
|
1388
|
|
- * point we can find.
|
1389
|
|
- */
|
1390
|
|
- if (far_flag) {
|
1391
|
|
- for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
1392
|
|
- for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
1393
|
|
- if (i != k && j != l && !isnan(z_values[k][l])) {
|
1394
|
|
- //distance += pow((float) abs(i - k) * (MESH_X_DIST), 2) + pow((float) abs(j - l) * (MESH_Y_DIST), 2); // working here
|
1395
|
|
- distance += HYPOT(MESH_X_DIST, MESH_Y_DIST) / log(HYPOT((i - k) * (MESH_X_DIST) + .001, (j - l) * (MESH_Y_DIST)) + .001);
|
1396
|
|
- }
|
1397
|
|
- }
|
1398
|
|
- }
|
1399
|
|
- }
|
1400
|
|
- else
|
1401
|
1451
|
// factor in the distance from the current location for the normal case
|
1402
|
1452
|
// so the nozzle isn't running all over the bed.
|
1403
|
|
- distance += HYPOT(raw_x - mx, raw_y - my) * 0.1;
|
1404
|
|
-
|
1405
|
|
- // if far_flag, look for farthest point
|
1406
|
|
- if (far_flag == (distance > best_so_far) && distance != best_so_far) {
|
1407
|
|
- best_so_far = distance; // We found a closer/farther location with
|
|
1453
|
+ distance += HYPOT(raw_x - mx, raw_y - my) * 0.1;
|
|
1454
|
+ if (distance < best_so_far) {
|
|
1455
|
+ best_so_far = distance; // We found a closer location with
|
1408
|
1456
|
out_mesh.x_index = i; // the specified type of mesh value.
|
1409
|
1457
|
out_mesh.y_index = j;
|
1410
|
1458
|
out_mesh.distance = best_so_far;
|
|
@@ -1412,7 +1460,6 @@
|
1412
|
1460
|
}
|
1413
|
1461
|
} // for j
|
1414
|
1462
|
} // for i
|
1415
|
|
-
|
1416
|
1463
|
return out_mesh;
|
1417
|
1464
|
}
|
1418
|
1465
|
|
|
@@ -1448,7 +1495,7 @@
|
1448
|
1495
|
uint16_t not_done[16];
|
1449
|
1496
|
memset(not_done, 0xFF, sizeof(not_done));
|
1450
|
1497
|
do {
|
1451
|
|
- location = find_closest_mesh_point_of_type(SET_IN_BITMAP, lx, ly, USE_NOZZLE_AS_REFERENCE, not_done, false);
|
|
1498
|
+ location = find_closest_mesh_point_of_type(SET_IN_BITMAP, lx, ly, USE_NOZZLE_AS_REFERENCE, not_done);
|
1452
|
1499
|
|
1453
|
1500
|
if (location.x_index < 0) break; // stop when we can't find any more reachable points.
|
1454
|
1501
|
|
|
@@ -1572,16 +1619,10 @@
|
1572
|
1619
|
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
|
1573
|
1620
|
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
|
1574
|
1621
|
|
1575
|
|
- // static const smart_fill_info info[] PROGMEM = {
|
1576
|
|
- // { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false } PROGMEM, // Bottom of the mesh looking up
|
1577
|
|
- // { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false } PROGMEM, // Top of the mesh looking down
|
1578
|
|
- // { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true } PROGMEM, // Left side of the mesh looking right
|
1579
|
|
- // { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true } PROGMEM // Right side of the mesh looking left
|
1580
|
|
- // };
|
1581
|
1622
|
for (uint8_t i = 0; i < COUNT(info); ++i) {
|
1582
|
1623
|
const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
|
1583
|
|
- const int8_t sx = pgm_read_word(&f->sx), sy = pgm_read_word(&f->sy),
|
1584
|
|
- ex = pgm_read_word(&f->ex), ey = pgm_read_word(&f->ey);
|
|
1624
|
+ const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
|
|
1625
|
+ ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
|
1585
|
1626
|
if (pgm_read_byte(&f->yfirst)) {
|
1586
|
1627
|
const int8_t dir = ex > sx ? 1 : -1;
|
1587
|
1628
|
for (uint8_t y = sy; y != ey; ++y)
|