diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index 8e86b181b..090641a05 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -83,7 +83,7 @@ class unified_bed_leveling { #if ENABLED(NEWPANEL) static void move_z_with_encoder(const float &multiplier); static float measure_point_with_encoder(); - static float measure_business_card_thickness(float); + static float measure_business_card_thickness(float in_height); static void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool); static void fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map); #endif diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index d66b2e722..d0a899912 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -51,7 +51,7 @@ #if ENABLED(NEWPANEL) void lcd_return_to_status(); - extern void _lcd_ubl_output_map_lcd(); + void _lcd_ubl_output_map_lcd(); #endif extern float meshedit_done; @@ -96,8 +96,8 @@ * previous measurements. * * C G29 P2 C tells the Manual Probe subsystem to not use the current nozzle - * location in its search for the closest unmeasured Mesh Point. Instead, attempt to - * start at one end of the uprobed points and Continue sequentually. + * location in its search for the closest unmeasured Mesh Point. Instead, attempt to + * start at one end of the uprobed points and Continue sequentially. * * G29 P3 C specifies the Constant for the fill. Otherwise, uses a "reasonable" value. * @@ -1038,12 +1038,12 @@ static uint8_t ubl_state_at_invocation = 0; - #if ENABLED(UBL_DEVEL_DEBUGGING) + #ifdef UBL_DEVEL_DEBUGGING static uint8_t ubl_state_recursion_chk = 0; #endif void unified_bed_leveling::save_ubl_active_state_and_disable() { - #if ENABLED(UBL_DEVEL_DEBUGGING) + #ifdef UBL_DEVEL_DEBUGGING ubl_state_recursion_chk++; if (ubl_state_recursion_chk != 1) { SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row."); @@ -1059,7 +1059,7 @@ } void unified_bed_leveling::restore_ubl_active_state_and_leave() { - #if ENABLED(UBL_DEVEL_DEBUGGING) + #ifdef UBL_DEVEL_DEBUGGING if (--ubl_state_recursion_chk) { SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times."); #if ENABLED(NEWPANEL) @@ -1143,7 +1143,7 @@ SERIAL_EOL(); safe_delay(50); - #if ENABLED(UBL_DEVEL_DEBUGGING) + #ifdef UBL_DEVEL_DEBUGGING SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation); SERIAL_EOL(); SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk); @@ -1257,22 +1257,22 @@ found_a_NAN = true; - int8_t closest_x=-1, closest_y=-1; + int8_t closest_x = -1, closest_y = -1; float d1, d2 = 99999.9; 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])) { found_a_real = true; - // Add in a random weighting factor that scrambles the probing of the - // last half of the mesh (when every unprobed mesh point is one index - // from a probed location). + // Add in a random weighting factor that scrambles the probing of the + // last half of the mesh (when every unprobed mesh point is one index + // from a probed location). d1 = HYPOT(i - k, j - l) + (1.0 / ((millis() % 47) + 13)); if (d1 < d2) { // found a closer distance from invalid mesh point at (i,j) to defined mesh point at (k,l) - d2 = d1; // found a closer location with - closest_x = i; // an assigned mesh point value + d2 = d1; // found a closer location with + closest_x = i; // an assigned mesh point value closest_y = j; } } @@ -1280,7 +1280,7 @@ } // - // at this point d2 should have the closest defined mesh point to invalid mesh point (i,j) + // At this point d2 should have the closest defined mesh point to invalid mesh point (i,j) // if (found_a_real && (closest_x >= 0) && (d2 > out_mesh.distance)) { @@ -1523,7 +1523,7 @@ y_min = max(MIN_PROBE_Y, MESH_MIN_Y), y_max = min(MAX_PROBE_Y, MESH_MAX_Y); - bool abort_flag=false; + bool abort_flag = false; float measured_z; @@ -1532,7 +1532,7 @@ struct linear_fit_data lsf_results; -// float z1, z2, z3; // Needed for algorithm validation down below. + //float z1, z2, z3; // Needed for algorithm validation down below. incremental_LSF_reset(&lsf_results); @@ -1542,8 +1542,8 @@ abort_flag = true; else { measured_z -= get_z_correction(UBL_PROBE_PT_1_X, UBL_PROBE_PT_1_Y); -// z1 = measured_z; - if (g29_verbose_level>3) { + //z1 = measured_z; + if (g29_verbose_level > 3) { serial_spaces(16); SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } @@ -1552,12 +1552,12 @@ if (!abort_flag) { measured_z = probe_pt(UBL_PROBE_PT_2_X, UBL_PROBE_PT_2_Y, false, g29_verbose_level); -// z2 = measured_z; + //z2 = measured_z; if (isnan(measured_z)) abort_flag = true; else { measured_z -= get_z_correction(UBL_PROBE_PT_2_X, UBL_PROBE_PT_2_Y); - if (g29_verbose_level>3) { + if (g29_verbose_level > 3) { serial_spaces(16); SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } @@ -1567,12 +1567,12 @@ if (!abort_flag) { measured_z = probe_pt(UBL_PROBE_PT_3_X, UBL_PROBE_PT_3_Y, true, g29_verbose_level); -// z3 = measured_z; + //z3 = measured_z; if (isnan(measured_z)) abort_flag = true; else { measured_z -= get_z_correction(UBL_PROBE_PT_3_X, UBL_PROBE_PT_3_Y); - if (g29_verbose_level>3) { + if (g29_verbose_level > 3) { serial_spaces(16); SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } @@ -1584,54 +1584,54 @@ SERIAL_ECHOPGM("?Error probing point. Aborting operation.\n"); return; } - } else { + } + else { // !do_3_pt_leveling - bool zig_zag = false; - for (uint8_t ix = 0; ix < g29_grid_size; ix++) { - const float rx = float(x_min) + ix * dx; - for (int8_t iy = 0; iy < g29_grid_size; iy++) { - const float ry = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); + bool zig_zag = false; + for (uint8_t ix = 0; ix < g29_grid_size; ix++) { + const float rx = float(x_min) + ix * dx; + for (int8_t iy = 0; iy < g29_grid_size; iy++) { + const float ry = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); if (!abort_flag) { measured_z = probe_pt(rx, ry, parser.seen('E'), g29_verbose_level); // TODO: Needs error handling - if (isnan(measured_z)) - abort_flag = true; + abort_flag = isnan(measured_z); - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - SERIAL_CHAR('('); - SERIAL_PROTOCOL_F(rx, 7); - SERIAL_CHAR(','); - SERIAL_PROTOCOL_F(ry, 7); - SERIAL_ECHOPGM(") logical: "); - SERIAL_CHAR('('); - SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(rx), 7); - SERIAL_CHAR(','); - SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ry), 7); - SERIAL_ECHOPGM(") measured: "); - SERIAL_PROTOCOL_F(measured_z, 7); - SERIAL_ECHOPGM(" correction: "); - SERIAL_PROTOCOL_F(get_z_correction(rx, ry), 7); + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_CHAR('('); + SERIAL_PROTOCOL_F(rx, 7); + SERIAL_CHAR(','); + SERIAL_PROTOCOL_F(ry, 7); + SERIAL_ECHOPGM(") logical: "); + SERIAL_CHAR('('); + SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(rx), 7); + SERIAL_CHAR(','); + SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ry), 7); + SERIAL_ECHOPGM(") measured: "); + SERIAL_PROTOCOL_F(measured_z, 7); + SERIAL_ECHOPGM(" correction: "); + SERIAL_PROTOCOL_F(get_z_correction(rx, ry), 7); + } + #endif + + measured_z -= get_z_correction(rx, ry) /* + zprobe_zoffset */ ; + + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPGM(" final >>>---> "); + SERIAL_PROTOCOL_F(measured_z, 7); + SERIAL_EOL(); + } + #endif + + incremental_LSF(&lsf_results, rx, ry, measured_z); } - #endif - - measured_z -= get_z_correction(rx, ry) /* + zprobe_zoffset */ ; - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - SERIAL_ECHOPGM(" final >>>---> "); - SERIAL_PROTOCOL_F(measured_z, 7); - SERIAL_EOL(); - } - #endif - - incremental_LSF(&lsf_results, rx, ry, measured_z); - } } - zig_zag ^= true; - } + zig_zag ^= true; + } } @@ -1640,7 +1640,6 @@ return; } - vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1.0000).get_normal(); if (g29_verbose_level > 2) { @@ -1714,22 +1713,22 @@ SERIAL_ECHOPGM("]\n"); SERIAL_EOL(); -/* - * The following code can be used to check the validity of the mesh tilting algorithm. - * When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting. - * The only difference is just 3 points are used in the calculations. That fact guarantees - * each probed point should have an exact match when a get_z_correction() for that location - * is calculated. The Z error between the probed point locations and the get_z_correction() - * numbers for those locations should be 0.000 - */ -/* + /** + * The following code can be used to check the validity of the mesh tilting algorithm. + * When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting. + * The only difference is just 3 points are used in the calculations. That fact guarantees + * each probed point should have an exact match when a get_z_correction() for that location + * is calculated. The Z error between the probed point locations and the get_z_correction() + * numbers for those locations should be 0.000 + */ + #if 0 float t, t1, d; t = normal.x * (UBL_PROBE_PT_1_X) + normal.y * (UBL_PROBE_PT_1_Y); d = t + normal.z * z1; SERIAL_ECHOPGM("D from 1st point: "); SERIAL_ECHO_F(d, 6); SERIAL_ECHOPGM(" Z error: "); - SERIAL_ECHO_F(normal.z*z1-get_z_correction(UBL_PROBE_PT_1_X, UBL_PROBE_PT_1_Y),6); + SERIAL_ECHO_F(normal.z*z1-get_z_correction(UBL_PROBE_PT_1_X, UBL_PROBE_PT_1_Y), 6); SERIAL_EOL(); t = normal.x * (UBL_PROBE_PT_2_X) + normal.y * (UBL_PROBE_PT_2_Y); @@ -1738,7 +1737,7 @@ SERIAL_ECHOPGM("D from 2nd point: "); SERIAL_ECHO_F(d, 6); SERIAL_ECHOPGM(" Z error: "); - SERIAL_ECHO_F(normal.z*z2-get_z_correction(UBL_PROBE_PT_2_X, UBL_PROBE_PT_2_Y),6); + SERIAL_ECHO_F(normal.z*z2-get_z_correction(UBL_PROBE_PT_2_X, UBL_PROBE_PT_2_Y), 6); SERIAL_EOL(); t = normal.x * (UBL_PROBE_PT_3_X) + normal.y * (UBL_PROBE_PT_3_Y); @@ -1746,7 +1745,7 @@ SERIAL_ECHOPGM("D from 3rd point: "); SERIAL_ECHO_F(d, 6); SERIAL_ECHOPGM(" Z error: "); - SERIAL_ECHO_F(normal.z*z3-get_z_correction(UBL_PROBE_PT_3_X, UBL_PROBE_PT_3_Y),6); + SERIAL_ECHO_F(normal.z*z3-get_z_correction(UBL_PROBE_PT_3_X, UBL_PROBE_PT_3_Y), 6); SERIAL_EOL(); t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT); @@ -1760,13 +1759,13 @@ SERIAL_ECHOPGM("D from home location using mesh value for Z: "); SERIAL_ECHO_F(d, 6); - SERIAL_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT ); + SERIAL_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT); SERIAL_ECHOPAIR(",", Z_SAFE_HOMING_Y_POINT ); SERIAL_ECHOPGM(") = "); - SERIAL_ECHO_F( get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT),6); + SERIAL_ECHO_F(get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6); SERIAL_EOL(); -*/ - } + #endif + } // DEBUGGING(LEVELING) #endif }