From 091179d96009fc3a76e6ee29a5adb415a11ada4d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 21 Apr 2017 22:46:19 -0500 Subject: [PATCH] bed_level_grid => z_values (also *_virt array) --- Marlin/Marlin.h | 2 +- Marlin/Marlin_main.cpp | 48 +++++++++++++++++----------------- Marlin/configuration_store.cpp | 10 +++---- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index cea3d7fd6c..5ea7eab1f1 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -313,7 +313,7 @@ float code_value_temp_diff(); #if ENABLED(AUTO_BED_LEVELING_BILINEAR) 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]); void set_bed_leveling_enabled(bool enable=true); #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index fb6f793418..962e3b5f03 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -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 diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index d8395a22a0..3dd7595a8b 100755 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -85,7 +85,7 @@ * 307 GRID_MAX_POINTS_Y (uint8_t) * 308 bilinear_grid_spacing (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 * 348 M666 XYZ endstop_adj (float x3) @@ -382,9 +382,9 @@ void MarlinSettings::postprocess() { // #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( - 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." ); 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(bilinear_grid_spacing); // 2 ints EEPROM_WRITE(bilinear_start); // 2 ints - EEPROM_WRITE(bed_level_grid); // 9-256 floats + EEPROM_WRITE(z_values); // 9-256 floats #else // For disabled Bilinear Grid write an empty 3x3 grid const uint8_t grid_max_x = 3, grid_max_y = 3; @@ -757,7 +757,7 @@ void MarlinSettings::postprocess() { set_bed_leveling_enabled(false); EEPROM_READ(bilinear_grid_spacing); // 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 #endif // AUTO_BED_LEVELING_BILINEAR