bed_level_grid => z_values (also *_virt array)

2.0.x
Scott Lahteine 8 years ago
parent 23cdbbb2d3
commit 091179d960

@ -313,7 +313,7 @@ float code_value_temp_diff();
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
extern int bilinear_grid_spacing[2], bilinear_start[2]; extern int bilinear_grid_spacing[2], bilinear_start[2];
extern float bed_level_grid[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; extern float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
float bilinear_z_offset(float logical[XYZ]); float bilinear_z_offset(float logical[XYZ]);
void set_bed_leveling_enabled(bool enable=true); void set_bed_leveling_enabled(bool enable=true);
#endif #endif

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

@ -85,7 +85,7 @@
* 307 GRID_MAX_POINTS_Y (uint8_t) * 307 GRID_MAX_POINTS_Y (uint8_t)
* 308 bilinear_grid_spacing (int x2) * 308 bilinear_grid_spacing (int x2)
* 312 G29 L F bilinear_start (int x2) * 312 G29 L F bilinear_start (int x2)
* 316 bed_level_grid[][] (float x9, up to float x256) +988 * 316 z_values[][] (float x9, up to float x256) +988
* *
* DELTA: 48 bytes * DELTA: 48 bytes
* 348 M666 XYZ endstop_adj (float x3) * 348 M666 XYZ endstop_adj (float x3)
@ -382,9 +382,9 @@ void MarlinSettings::postprocess() {
// //
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
// Compile time test that sizeof(bed_level_grid) is as expected // Compile time test that sizeof(z_values) is as expected
static_assert( static_assert(
sizeof(bed_level_grid) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(bed_level_grid[0][0]), sizeof(z_values) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(z_values[0][0]),
"Bilinear Z array is the wrong size." "Bilinear Z array is the wrong size."
); );
const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y; const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
@ -392,7 +392,7 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(grid_max_y); // 1 byte EEPROM_WRITE(grid_max_y); // 1 byte
EEPROM_WRITE(bilinear_grid_spacing); // 2 ints EEPROM_WRITE(bilinear_grid_spacing); // 2 ints
EEPROM_WRITE(bilinear_start); // 2 ints EEPROM_WRITE(bilinear_start); // 2 ints
EEPROM_WRITE(bed_level_grid); // 9-256 floats EEPROM_WRITE(z_values); // 9-256 floats
#else #else
// For disabled Bilinear Grid write an empty 3x3 grid // For disabled Bilinear Grid write an empty 3x3 grid
const uint8_t grid_max_x = 3, grid_max_y = 3; const uint8_t grid_max_x = 3, grid_max_y = 3;
@ -757,7 +757,7 @@ void MarlinSettings::postprocess() {
set_bed_leveling_enabled(false); set_bed_leveling_enabled(false);
EEPROM_READ(bilinear_grid_spacing); // 2 ints EEPROM_READ(bilinear_grid_spacing); // 2 ints
EEPROM_READ(bilinear_start); // 2 ints EEPROM_READ(bilinear_start); // 2 ints
EEPROM_READ(bed_level_grid); // 9 to 256 floats EEPROM_READ(z_values); // 9 to 256 floats
} }
else // EEPROM data is stale else // EEPROM data is stale
#endif // AUTO_BED_LEVELING_BILINEAR #endif // AUTO_BED_LEVELING_BILINEAR

Loading…
Cancel
Save