UBL-related cleanup, spacing, standards

Reference: #6804
This commit is contained in:
Scott Lahteine 2017-05-21 05:28:38 -05:00
parent 52e20aeab3
commit 02f15f6775
3 changed files with 60 additions and 68 deletions

View File

@ -438,63 +438,56 @@ void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s
#if IS_KINEMATIC // (DELTA or SCARA) #if IS_KINEMATIC // (DELTA or SCARA)
#if ENABLED(DELTA)
#define DELTA_PRINTABLE_RADIUS_SQUARED ((float)DELTA_PRINTABLE_RADIUS * (float)DELTA_PRINTABLE_RADIUS )
#endif
#if IS_SCARA #if IS_SCARA
extern const float L1, L2; extern const float L1, L2;
#endif #endif
inline bool position_is_reachable_raw_xy( float raw_x, float raw_y ) { inline bool position_is_reachable_raw_xy(const float &rx, const float &ry) {
#if ENABLED(DELTA) #if ENABLED(DELTA)
return ( HYPOT2( raw_x, raw_y ) <= DELTA_PRINTABLE_RADIUS_SQUARED ); return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS);
#elif IS_SCARA #elif IS_SCARA
#if MIDDLE_DEAD_ZONE_R > 0 #if MIDDLE_DEAD_ZONE_R > 0
const float R2 = HYPOT2(raw_x - SCARA_OFFSET_X, raw_y - SCARA_OFFSET_Y); const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
return R2 >= sq(float(MIDDLE_DEAD_ZONE_R)) && R2 <= sq(L1 + L2); return R2 >= sq(float(MIDDLE_DEAD_ZONE_R)) && R2 <= sq(L1 + L2);
#else #else
return HYPOT2(raw_x - SCARA_OFFSET_X, raw_y - SCARA_OFFSET_Y) <= sq(L1 + L2); return HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y) <= sq(L1 + L2);
#endif #endif
#else // CARTESIAN #else // CARTESIAN
#error // To be migrated from MakerArm branch in future
#endif #endif
} }
inline bool position_is_reachable_by_probe_raw_xy( float raw_x, float raw_y ) { inline bool position_is_reachable_by_probe_raw_xy(const float &rx, const float &ry) {
// both the nozzle and the probe must be able to reach the point // Both the nozzle and the probe must be able to reach the point.
// This won't work on SCARA since the probe offset rotates with the arm.
return ( position_is_reachable_raw_xy( raw_x, raw_y ) && return position_is_reachable_raw_xy(rx, ry)
position_is_reachable_raw_xy( && position_is_reachable_raw_xy(rx - X_PROBE_OFFSET_FROM_EXTRUDER, ry - Y_PROBE_OFFSET_FROM_EXTRUDER);
raw_x - X_PROBE_OFFSET_FROM_EXTRUDER,
raw_y - Y_PROBE_OFFSET_FROM_EXTRUDER ));
} }
#else // CARTESIAN #else // CARTESIAN
inline bool position_is_reachable_raw_xy( float raw_x, float raw_y ) { inline bool position_is_reachable_raw_xy(const float &rx, const float &ry) {
// note to reviewer: this +/-0.0001 logic is copied from original postion_is_reachable // Add 0.001 margin to deal with float imprecision
return WITHIN(raw_x, X_MIN_POS - 0.0001, X_MAX_POS + 0.0001) return WITHIN(rx, X_MIN_POS - 0.001, X_MAX_POS + 0.001)
&& WITHIN(raw_y, Y_MIN_POS - 0.0001, Y_MAX_POS + 0.0001); && WITHIN(ry, Y_MIN_POS - 0.001, Y_MAX_POS + 0.001);
} }
inline bool position_is_reachable_by_probe_raw_xy( float raw_x, float raw_y ) { inline bool position_is_reachable_by_probe_raw_xy(const float &rx, const float &ry) {
// note to reviewer: this logic is copied from UBL_G29.cpp and does not contain the +/-0.0001 above // Add 0.001 margin to deal with float imprecision
return WITHIN(raw_x, MIN_PROBE_X, MAX_PROBE_X) return WITHIN(rx, MIN_PROBE_X - 0.001, MAX_PROBE_X + 0.001)
&& WITHIN(raw_y, MIN_PROBE_Y, MAX_PROBE_Y); && WITHIN(ry, MIN_PROBE_Y - 0.001, MAX_PROBE_Y + 0.001);
} }
#endif // CARTESIAN #endif // CARTESIAN
inline bool position_is_reachable_by_probe_xy( float target_x, float target_y ) { FORCE_INLINE bool position_is_reachable_by_probe_xy(const float &lx, const float &ly) {
return position_is_reachable_by_probe_raw_xy( return position_is_reachable_by_probe_raw_xy(RAW_X_POSITION(lx), RAW_Y_POSITION(ly));
RAW_X_POSITION( target_x ),
RAW_Y_POSITION( target_y ));
} }
inline bool position_is_reachable_xy( float target_x, float target_y ) { FORCE_INLINE bool position_is_reachable_xy(const float &lx, const float &ly) {
return position_is_reachable_raw_xy( RAW_X_POSITION( target_x ), RAW_Y_POSITION( target_y )); return position_is_reachable_raw_xy(RAW_X_POSITION(lx), RAW_Y_POSITION(ly));
} }
#endif //MARLIN_H #endif //MARLIN_H

View File

@ -4639,6 +4639,7 @@ void home_all_axes() { gcode_G28(true); }
indexIntoAB[xCount][yCount] = abl_probe_index; indexIntoAB[xCount][yCount] = abl_probe_index;
#endif #endif
// Keep looping till a reachable point is found
if (position_is_reachable_xy(xProbe, yProbe)) break; if (position_is_reachable_xy(xProbe, yProbe)) break;
++abl_probe_index; ++abl_probe_index;
} }

View File

@ -135,8 +135,8 @@
* a subsequent G or T leveling operation for backward compatibility. * a subsequent G or T leveling operation for backward compatibility.
* *
* P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using * P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using
* the Z-Probe. Usually the probe can not reach all areas that the nozzle can reach. * the Z-Probe. Usually the probe can't reach all areas that the nozzle can reach. On
* In Cartesian printers, mesh points within the X_OFFSET_FROM_EXTRUDER and Y_OFFSET_FROM_EXTRUDER * Cartesian printers, points within the X_PROBE_OFFSET_FROM_EXTRUDER and Y_PROBE_OFFSET_FROM_EXTRUDER
* area cannot be automatically probed. For Delta printers the area in which DELTA_PROBEABLE_RADIUS * area cannot be automatically probed. For Delta printers the area in which DELTA_PROBEABLE_RADIUS
* and DELTA_PRINTABLE_RADIUS do not overlap will not be automatically probed. * and DELTA_PRINTABLE_RADIUS do not overlap will not be automatically probed.
* *
@ -660,9 +660,9 @@
do_blocking_move_to_z(measured_z); do_blocking_move_to_z(measured_z);
} while (!ubl_lcd_clicked()); } while (!ubl_lcd_clicked());
ubl.has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked. ubl.has_control_of_lcd_panel = true; // There is a race condition for the encoder click.
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
// or here. So, until we are done looking for a long Encoder Wheel Press, // or here. So, until we are done looking for a long encoder press,
// we need to take control of the panel // we need to take control of the panel
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
@ -1346,10 +1346,10 @@
my = pgm_read_float(&ubl.mesh_index_to_ypos[j]); my = pgm_read_float(&ubl.mesh_index_to_ypos[j]);
// If using the probe as the reference there are some unreachable locations. // If using the probe as the reference there are some unreachable locations.
// Also for round beds, there are grid points outside the bed that nozzle can't reach. // Also for round beds, there are grid points outside the bed the nozzle can't reach.
// Prune them from the list and ignore them till the next Phase (manual nozzle probing). // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
if ( ! (probe_as_reference ? position_is_reachable_by_probe_raw_xy(mx, my) : position_is_reachable_raw_xy(mx, my)) ) if (probe_as_reference ? !position_is_reachable_by_probe_raw_xy(mx, my) : !position_is_reachable_raw_xy(mx, my))
continue; continue;
// Reachable. Check if it's the closest location to the nozzle. // Reachable. Check if it's the closest location to the nozzle.
@ -1390,8 +1390,8 @@
} }
void fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map) { void fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map) {
if (!code_seen('R')) // fine_tune_mesh() is special. If no repetion count flag is specified if (!code_seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified
repetition_cnt = 1; // we know to do exactly one mesh location. Otherwise we use what the parser decided. repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided.
mesh_index_pair location; mesh_index_pair location;
uint16_t not_done[16]; uint16_t not_done[16];
@ -1421,9 +1421,8 @@
const float rawx = pgm_read_float(&ubl.mesh_index_to_xpos[location.x_index]), const float rawx = pgm_read_float(&ubl.mesh_index_to_xpos[location.x_index]),
rawy = pgm_read_float(&ubl.mesh_index_to_ypos[location.y_index]); rawy = pgm_read_float(&ubl.mesh_index_to_ypos[location.y_index]);
if ( ! position_is_reachable_raw_xy( rawx, rawy )) { // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable if (!position_is_reachable_raw_xy(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
break; break;
}
float new_z = ubl.z_values[location.x_index][location.y_index]; float new_z = ubl.z_values[location.x_index][location.y_index];
@ -1432,8 +1431,7 @@
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit
do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy)); do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
round_off = (int32_t)(new_z * 1000.0); // we chop off the last digits just to be clean. We are rounding to the new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
new_z = float(round_off) / 1000.0;
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl.has_control_of_lcd_panel = true; ubl.has_control_of_lcd_panel = true;
@ -1451,9 +1449,9 @@
lcd_return_to_status(); lcd_return_to_status();
// There is a race condition for the Encoder Wheel getting clicked. // The technique used here generates a race condition for the encoder click.
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here.
// or here. // Let's work on specifying a proper API for the LCD ASAP, OK?
ubl.has_control_of_lcd_panel = true; ubl.has_control_of_lcd_panel = true;
} }
@ -1478,7 +1476,7 @@
lcd_implementation_clear(); lcd_implementation_clear();
} while (( location.x_index >= 0 ) && (--repetition_cnt>0)); } while (location.x_index >= 0 && --repetition_cnt > 0);
FINE_TUNE_EXIT: FINE_TUNE_EXIT: