|
|
@ -365,8 +365,7 @@ |
|
|
|
#endif |
|
|
|
|
|
|
|
case 0: |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a bowl shape - similar to
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
|
|
|
|
GRID_LOOP(x, y) { // Create a bowl shape similar to a poorly-calibrated Delta
|
|
|
|
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x, |
|
|
|
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y; |
|
|
|
z_values[x][y] += 2.0f * HYPOT(p1, p2); |
|
|
@ -374,16 +373,15 @@ |
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]); |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
|
|
|
LOOP_L_N(x, GRID_MAX_POINTS_X) { // Create a diagonal line several Mesh cells thick that is raised
|
|
|
|
z_values[x][x] += 9.999f; |
|
|
|
z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
|
|
|
|
z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
|
|
|
|
#if ENABLED(EXTENSIBLE_UI) |
|
|
|
ExtUI::onMeshUpdate(x, x, z_values[x][x]); |
|
|
|
ExtUI::onMeshUpdate(x, (x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1), z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1]); |
|
|
|
ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]); |
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
@ -467,7 +465,7 @@ |
|
|
|
//
|
|
|
|
// Manually Probe Mesh in areas that can't be reached by the probe
|
|
|
|
//
|
|
|
|
SERIAL_ECHOLNPGM("Manually probing unreachable mesh locations."); |
|
|
|
SERIAL_ECHOLNPGM("Manually probing unreachable points."); |
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); |
|
|
|
|
|
|
|
if (parser.seen('C') && !xy_seen) { |
|
|
@ -537,9 +535,7 @@ |
|
|
|
if (cpos.x < 0) { |
|
|
|
// No more REAL INVALID mesh points to populate, so we ASSUME
|
|
|
|
// user meant to populate ALL INVALID mesh points to value
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) |
|
|
|
if (isnan(z_values[x][y])) z_values[x][y] = g29_constant; |
|
|
|
GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant; |
|
|
|
break; // No more invalid Mesh Points to populate
|
|
|
|
} |
|
|
|
else { |
|
|
@ -696,8 +692,7 @@ |
|
|
|
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) { |
|
|
|
float sum = 0; |
|
|
|
int n = 0; |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) |
|
|
|
GRID_LOOP(x, y) |
|
|
|
if (!isnan(z_values[x][y])) { |
|
|
|
sum += z_values[x][y]; |
|
|
|
n++; |
|
|
@ -709,8 +704,7 @@ |
|
|
|
// Sum the squares of difference from mean
|
|
|
|
//
|
|
|
|
float sum_of_diff_squared = 0; |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) |
|
|
|
GRID_LOOP(x, y) |
|
|
|
if (!isnan(z_values[x][y])) |
|
|
|
sum_of_diff_squared += sq(z_values[x][y] - mean); |
|
|
|
|
|
|
@ -721,8 +715,7 @@ |
|
|
|
SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6); |
|
|
|
|
|
|
|
if (cflag) |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) |
|
|
|
GRID_LOOP(x, y) |
|
|
|
if (!isnan(z_values[x][y])) { |
|
|
|
z_values[x][y] -= mean + value; |
|
|
|
#if ENABLED(EXTENSIBLE_UI) |
|
|
@ -732,8 +725,7 @@ |
|
|
|
} |
|
|
|
|
|
|
|
void unified_bed_leveling::shift_mesh_height() { |
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) |
|
|
|
GRID_LOOP(x, y) |
|
|
|
if (!isnan(z_values[x][y])) { |
|
|
|
z_values[x][y] += g29_constant; |
|
|
|
#if ENABLED(EXTENSIBLE_UI) |
|
|
@ -1243,12 +1235,10 @@ |
|
|
|
|
|
|
|
mesh_index_pair farthest { -1, -1, -99999.99 }; |
|
|
|
|
|
|
|
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) { |
|
|
|
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { |
|
|
|
|
|
|
|
if (isnan(z_values[i][j])) { // Invalid mesh point?
|
|
|
|
GRID_LOOP(i, j) { |
|
|
|
if (!isnan(z_values[i][j])) continue; // Skip valid mesh points
|
|
|
|
|
|
|
|
// Skip points the probe can't reach
|
|
|
|
// Skip unreachable points
|
|
|
|
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j))) |
|
|
|
continue; |
|
|
|
|
|
|
@ -1256,9 +1246,9 @@ |
|
|
|
|
|
|
|
xy_int8_t near { -1, -1 }; |
|
|
|
float d1, d2 = 99999.9f; |
|
|
|
for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) { |
|
|
|
for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) { |
|
|
|
if (!isnan(z_values[k][l])) { |
|
|
|
GRID_LOOP(k, l) { |
|
|
|
if (isnan(z_values[k][l])) continue; |
|
|
|
|
|
|
|
found_a_real = true; |
|
|
|
|
|
|
|
// Add in a random weighting factor that scrambles the probing of the
|
|
|
@ -1272,8 +1262,6 @@ |
|
|
|
near.set(i, j); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
// At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
|
|
|
@ -1283,12 +1271,10 @@ |
|
|
|
farthest.pos = near; // Found an invalid location farther from the defined mesh point
|
|
|
|
farthest.distance = d2; |
|
|
|
} |
|
|
|
} |
|
|
|
} // for j
|
|
|
|
} // for i
|
|
|
|
} // GRID_LOOP
|
|
|
|
|
|
|
|
if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
|
|
|
|
farthest.pos.set(GRID_MAX_POINTS_X / 2, GRID_MAX_POINTS_Y / 2); |
|
|
|
farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2); |
|
|
|
farthest.distance = 1; |
|
|
|
} |
|
|
|
return farthest; |
|
|
@ -1304,8 +1290,7 @@ |
|
|
|
|
|
|
|
float best_so_far = 99999.99f; |
|
|
|
|
|
|
|
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) { |
|
|
|
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { |
|
|
|
GRID_LOOP(i, j) { |
|
|
|
if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL)) |
|
|
|
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j)) |
|
|
|
) { |
|
|
@ -1332,8 +1317,7 @@ |
|
|
|
closest.distance = best_so_far; |
|
|
|
} |
|
|
|
} |
|
|
|
} // for j
|
|
|
|
} // for i
|
|
|
|
} // GRID_LOOP
|
|
|
|
|
|
|
|
return closest; |
|
|
|
} |
|
|
@ -1373,7 +1357,7 @@ |
|
|
|
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
|
|
|
|
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 }; |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < COUNT(info); ++i) { |
|
|
|
LOOP_L_N(i, COUNT(info)) { |
|
|
|
const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]); |
|
|
|
const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy), |
|
|
|
ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey); |
|
|
@ -1496,12 +1480,13 @@ |
|
|
|
|
|
|
|
bool zig_zag = false; |
|
|
|
|
|
|
|
uint16_t total_points = g29_grid_size * g29_grid_size, point_num = 1; |
|
|
|
const uint16_t total_points = sq(g29_grid_size); |
|
|
|
uint16_t point_num = 1; |
|
|
|
|
|
|
|
xy_pos_t rpos; |
|
|
|
for (uint8_t ix = 0; ix < g29_grid_size; ix++) { |
|
|
|
LOOP_L_N(ix, g29_grid_size) { |
|
|
|
rpos.x = x_min + ix * dx; |
|
|
|
for (int8_t iy = 0; iy < g29_grid_size; iy++) { |
|
|
|
LOOP_L_N(iy, g29_grid_size) { |
|
|
|
rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); |
|
|
|
|
|
|
|
if (!abort_flag) { |
|
|
@ -1569,8 +1554,7 @@ |
|
|
|
|
|
|
|
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1)); |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { |
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { |
|
|
|
GRID_LOOP(i, j) { |
|
|
|
float mx = mesh_index_to_xpos(i), |
|
|
|
my = mesh_index_to_ypos(j), |
|
|
|
mz = z_values[i][j]; |
|
|
@ -1602,7 +1586,6 @@ |
|
|
|
ExtUI::onMeshUpdate(i, j, z_values[i][j]); |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) { |
|
|
|
rotation.debug(PSTR("rotation matrix:\n")); |
|
|
@ -1661,7 +1644,7 @@ |
|
|
|
// being extrapolated so that nearby points will have greater influence on
|
|
|
|
// the point being extrapolated. Then extrapolate the mesh point from WLSF.
|
|
|
|
|
|
|
|
static_assert(GRID_MAX_POINTS_Y <= 16, "GRID_MAX_POINTS_Y too big"); |
|
|
|
static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big"); |
|
|
|
uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 }; |
|
|
|
struct linear_fit_data lsf_results; |
|
|
|
|
|
|
@ -1669,23 +1652,20 @@ |
|
|
|
|
|
|
|
const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST); |
|
|
|
|
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) |
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) |
|
|
|
if (!isnan(z_values[jx][jy])) |
|
|
|
SBI(bitmap[jx], jy); |
|
|
|
GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy); |
|
|
|
|
|
|
|
xy_pos_t ppos; |
|
|
|
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) { |
|
|
|
LOOP_L_N(ix, GRID_MAX_POINTS_X) { |
|
|
|
ppos.x = mesh_index_to_xpos(ix); |
|
|
|
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) { |
|
|
|
LOOP_L_N(iy, GRID_MAX_POINTS_Y) { |
|
|
|
ppos.y = mesh_index_to_ypos(iy); |
|
|
|
if (isnan(z_values[ix][iy])) { |
|
|
|
// undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
|
|
|
|
incremental_LSF_reset(&lsf_results); |
|
|
|
xy_pos_t rpos; |
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) { |
|
|
|
LOOP_L_N(jx, GRID_MAX_POINTS_X) { |
|
|
|
rpos.x = mesh_index_to_xpos(jx); |
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) { |
|
|
|
LOOP_L_N(jy, GRID_MAX_POINTS_Y) { |
|
|
|
if (TEST(bitmap[jx], jy)) { |
|
|
|
rpos.y = mesh_index_to_ypos(jy); |
|
|
|
const float rz = z_values[jx][jy], |
|
|
@ -1747,7 +1727,7 @@ |
|
|
|
SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50); |
|
|
|
|
|
|
|
SERIAL_ECHOPGM("X-Axis Mesh Points at: "); |
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { |
|
|
|
LOOP_L_N(i, GRID_MAX_POINTS_X) { |
|
|
|
SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3); |
|
|
|
SERIAL_ECHOPGM(" "); |
|
|
|
serial_delay(25); |
|
|
@ -1755,7 +1735,7 @@ |
|
|
|
SERIAL_EOL(); |
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); |
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) { |
|
|
|
LOOP_L_N(i, GRID_MAX_POINTS_Y) { |
|
|
|
SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3); |
|
|
|
SERIAL_ECHOPGM(" "); |
|
|
|
serial_delay(25); |
|
|
@ -1840,8 +1820,7 @@ |
|
|
|
|
|
|
|
SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh."); |
|
|
|
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) |
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { |
|
|
|
GRID_LOOP(x, y) { |
|
|
|
z_values[x][y] -= tmp_z_values[x][y]; |
|
|
|
#if ENABLED(EXTENSIBLE_UI) |
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]); |
|
|
|