|
|
|
@ -599,7 +599,7 @@ static uint8_t target_extruder;
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
int bilinear_grid_spacing[2], bilinear_start[2];
|
|
|
|
|
float bed_level_grid[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
|
float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if IS_SCARA
|
|
|
|
@ -2435,7 +2435,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
bilinear_grid_spacing[X_AXIS] = bilinear_grid_spacing[Y_AXIS] = 0;
|
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
|
bed_level_grid[x][y] = NAN;
|
|
|
|
|
z_values[x][y] = NAN;
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
ubl.reset();
|
|
|
|
|
#endif
|
|
|
|
@ -2533,7 +2533,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
SERIAL_CHAR(']');
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (!isnan(bed_level_grid[x][y])) {
|
|
|
|
|
if (!isnan(z_values[x][y])) {
|
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
|
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" (done)");
|
|
|
|
|
#endif
|
|
|
|
@ -2542,9 +2542,9 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
SERIAL_EOL;
|
|
|
|
|
|
|
|
|
|
// Get X neighbors, Y neighbors, and XY neighbors
|
|
|
|
|
float a1 = bed_level_grid[x + xdir][y], a2 = bed_level_grid[x + xdir * 2][y],
|
|
|
|
|
b1 = bed_level_grid[x][y + ydir], b2 = bed_level_grid[x][y + ydir * 2],
|
|
|
|
|
c1 = bed_level_grid[x + xdir][y + ydir], c2 = bed_level_grid[x + xdir * 2][y + ydir * 2];
|
|
|
|
|
float a1 = z_values[x + xdir][y], a2 = z_values[x + xdir * 2][y],
|
|
|
|
|
b1 = z_values[x][y + ydir], b2 = z_values[x][y + ydir * 2],
|
|
|
|
|
c1 = z_values[x + xdir][y + ydir], c2 = z_values[x + xdir * 2][y + ydir * 2];
|
|
|
|
|
|
|
|
|
|
// Treat far unprobed points as zero, near as equal to far
|
|
|
|
|
if (isnan(a2)) a2 = 0.0; if (isnan(a1)) a1 = a2;
|
|
|
|
@ -2554,10 +2554,10 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
const float a = 2 * a1 - a2, b = 2 * b1 - b2, c = 2 * c1 - c2;
|
|
|
|
|
|
|
|
|
|
// Take the average instead of the median
|
|
|
|
|
bed_level_grid[x][y] = (a + b + c) / 3.0;
|
|
|
|
|
z_values[x][y] = (a + b + c) / 3.0;
|
|
|
|
|
|
|
|
|
|
// Median is robust (ignores outliers).
|
|
|
|
|
// bed_level_grid[x][y] = (a < b) ? ((b < c) ? b : (c < a) ? a : c)
|
|
|
|
|
// z_values[x][y] = (a < b) ? ((b < c) ? b : (c < a) ? a : c)
|
|
|
|
|
// : ((c < b) ? b : (a < c) ? a : c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2617,7 +2617,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
static void print_bilinear_leveling_grid() {
|
|
|
|
|
SERIAL_ECHOLNPGM("Bilinear Leveling Grid:");
|
|
|
|
|
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 3,
|
|
|
|
|
[](const uint8_t ix, const uint8_t iy) { return bed_level_grid[ix][iy]; }
|
|
|
|
|
[](const uint8_t ix, const uint8_t iy) { return z_values[ix][iy]; }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2627,13 +2627,13 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
#define ABL_GRID_POINTS_VIRT_Y (GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
|
|
|
|
|
#define ABL_TEMP_POINTS_X (GRID_MAX_POINTS_X + 2)
|
|
|
|
|
#define ABL_TEMP_POINTS_Y (GRID_MAX_POINTS_Y + 2)
|
|
|
|
|
float bed_level_grid_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
|
|
|
|
|
float z_values_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
|
|
|
|
|
int bilinear_grid_spacing_virt[2] = { 0 };
|
|
|
|
|
|
|
|
|
|
static void bed_level_virt_print() {
|
|
|
|
|
SERIAL_ECHOLNPGM("Subdivided with CATMULL ROM Leveling Grid:");
|
|
|
|
|
print_2d_array(ABL_GRID_POINTS_VIRT_X, ABL_GRID_POINTS_VIRT_Y, 5,
|
|
|
|
|
[](const uint8_t ix, const uint8_t iy) { return bed_level_grid_virt[ix][iy]; }
|
|
|
|
|
[](const uint8_t ix, const uint8_t iy) { return z_values_virt[ix][iy]; }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2647,8 +2647,8 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
}
|
|
|
|
|
if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
|
|
|
|
|
return LINEAR_EXTRAPOLATION(
|
|
|
|
|
bed_level_grid[ep][y - 1],
|
|
|
|
|
bed_level_grid[ip][y - 1]
|
|
|
|
|
z_values[ep][y - 1],
|
|
|
|
|
z_values[ip][y - 1]
|
|
|
|
|
);
|
|
|
|
|
else
|
|
|
|
|
return LINEAR_EXTRAPOLATION(
|
|
|
|
@ -2663,8 +2663,8 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
}
|
|
|
|
|
if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
|
|
|
|
|
return LINEAR_EXTRAPOLATION(
|
|
|
|
|
bed_level_grid[x - 1][ep],
|
|
|
|
|
bed_level_grid[x - 1][ip]
|
|
|
|
|
z_values[x - 1][ep],
|
|
|
|
|
z_values[x - 1][ip]
|
|
|
|
|
);
|
|
|
|
|
else
|
|
|
|
|
return LINEAR_EXTRAPOLATION(
|
|
|
|
@ -2672,7 +2672,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
bed_level_virt_coord(x, ip + 1)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return bed_level_grid[x - 1][y - 1];
|
|
|
|
|
return z_values[x - 1][y - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
|
|
|
|
@ -2704,7 +2704,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
for (uint8_t tx = 0; tx < BILINEAR_SUBDIVISIONS; tx++) {
|
|
|
|
|
if ((ty && y == GRID_MAX_POINTS_Y - 1) || (tx && x == GRID_MAX_POINTS_X - 1))
|
|
|
|
|
continue;
|
|
|
|
|
bed_level_grid_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
|
|
|
|
|
z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
|
|
|
|
|
bed_level_virt_2cmr(
|
|
|
|
|
x + 1,
|
|
|
|
|
y + 1,
|
|
|
|
@ -4281,7 +4281,7 @@ inline void gcode_G28() {
|
|
|
|
|
}
|
|
|
|
|
if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
|
|
|
|
|
set_bed_leveling_enabled(false);
|
|
|
|
|
bed_level_grid[i][j] = z;
|
|
|
|
|
z_values[i][j] = z;
|
|
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
|
bed_level_virt_interpolate();
|
|
|
|
|
#endif
|
|
|
|
@ -4499,7 +4499,7 @@ inline void gcode_G28() {
|
|
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
|
|
bed_level_grid[xCount][yCount] = measured_z + zoffset;
|
|
|
|
|
z_values[xCount][yCount] = measured_z + zoffset;
|
|
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
|
|
|
|
@ -4669,7 +4669,7 @@ inline void gcode_G28() {
|
|
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
|
|
bed_level_grid[xCount][yCount] = measured_z + zoffset;
|
|
|
|
|
z_values[xCount][yCount] = measured_z + zoffset;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -8390,7 +8390,7 @@ void quickstop_stepper() {
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
ubl.z_values[px][py] = z;
|
|
|
|
|
#else
|
|
|
|
|
bed_level_grid[px][py] = z;
|
|
|
|
|
z_values[px][py] = z;
|
|
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
|
bed_level_virt_interpolate();
|
|
|
|
|
#endif
|
|
|
|
@ -8508,7 +8508,7 @@ inline void gcode_M503() {
|
|
|
|
|
if (diff) {
|
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
|
bed_level_grid[x][y] -= diff;
|
|
|
|
|
z_values[x][y] -= diff;
|
|
|
|
|
}
|
|
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
|
bed_level_virt_interpolate();
|
|
|
|
@ -10486,12 +10486,12 @@ void ok_to_send() {
|
|
|
|
|
#define ABL_BG_SPACING(A) bilinear_grid_spacing_virt[A]
|
|
|
|
|
#define ABL_BG_POINTS_X ABL_GRID_POINTS_VIRT_X
|
|
|
|
|
#define ABL_BG_POINTS_Y ABL_GRID_POINTS_VIRT_Y
|
|
|
|
|
#define ABL_BG_GRID(X,Y) bed_level_grid_virt[X][Y]
|
|
|
|
|
#define ABL_BG_GRID(X,Y) z_values_virt[X][Y]
|
|
|
|
|
#else
|
|
|
|
|
#define ABL_BG_SPACING(A) bilinear_grid_spacing[A]
|
|
|
|
|
#define ABL_BG_POINTS_X GRID_MAX_POINTS_X
|
|
|
|
|
#define ABL_BG_POINTS_Y GRID_MAX_POINTS_Y
|
|
|
|
|
#define ABL_BG_GRID(X,Y) bed_level_grid[X][Y]
|
|
|
|
|
#define ABL_BG_GRID(X,Y) z_values[X][Y]
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Get the Z adjustment for non-linear bed leveling
|
|
|
|
|