Encapsulate probe as singleton class (#16751)

This commit is contained in:
Scott Lahteine
2020-02-01 04:21:36 -06:00
committed by GitHub
parent 43d3463d5d
commit 90b6324563
33 changed files with 341 additions and 303 deletions

View File

@ -173,10 +173,10 @@
serialprintPGM(csv ? PSTR("CSV:\n") : PSTR("LCD:\n"));
}
// Add XY probe offset from extruder because probe_at_point() subtracts them when
// Add XY probe offset from extruder because probe.probe_at_point() subtracts them when
// moving to the XY position to be measured. This ensures better agreement between
// the current Z position after G28 and the mesh values.
const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe_offset_xy);
const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe.offset_xy);
if (!lcd) SERIAL_EOL();
for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {

View File

@ -450,7 +450,7 @@
SERIAL_ECHO(g29_pos.y);
SERIAL_ECHOLNPGM(").\n");
}
const xy_pos_t near = g29_pos + probe_offset_xy;
const xy_pos_t near = g29_pos + probe.offset_xy;
probe_entire_mesh(near, parser.seen('T'), parser.seen('E'), parser.seen('U'));
report_current_position();
@ -480,8 +480,8 @@
#if IS_KINEMATIC
X_HOME_POS, Y_HOME_POS
#else
probe_offset_xy.x > 0 ? X_BED_SIZE : 0,
probe_offset_xy.y < 0 ? Y_BED_SIZE : 0
probe.offset_xy.x > 0 ? X_BED_SIZE : 0,
probe.offset_xy.y < 0 ? Y_BED_SIZE : 0
#endif
);
}
@ -742,7 +742,7 @@
* This attempts to fill in locations closest to the nozzle's start location first.
*/
void unified_bed_leveling::probe_entire_mesh(const xy_pos_t &near, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) {
DEPLOY_PROBE(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW
probe.deploy(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW
#if HAS_LCD_MENU
ui.capture();
@ -768,7 +768,7 @@
ui.wait_for_release();
ui.quick_feedback();
ui.release();
STOW_PROBE(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW
probe.stow(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW
return restore_ubl_active_state_and_leave();
}
#endif
@ -778,7 +778,7 @@
: find_closest_mesh_point_of_type(INVALID, near, true);
if (best.pos.x >= 0) { // mesh point found and is reachable by probe
const float measured_z = probe_at_point(
const float measured_z = probe.probe_at_point(
best.meshpos(),
stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level
);
@ -794,20 +794,20 @@
#if HAS_LCD_MENU
ui.release();
#endif
STOW_PROBE(); // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW
probe.stow(); // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW
#if HAS_LCD_MENU
ui.capture();
#endif
#ifdef Z_AFTER_PROBING
move_z_after_probing();
probe.move_z_after_probing();
#endif
restore_ubl_active_state_and_leave();
do_blocking_move_to_xy(
constrain(near.x - probe_offset_xy.x, MESH_MIN_X, MESH_MAX_X),
constrain(near.y - probe_offset_xy.y, MESH_MIN_Y, MESH_MAX_Y)
constrain(near.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X),
constrain(near.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y)
);
}
@ -907,7 +907,7 @@
ui.return_to_status();
mesh_index_pair location;
xy_int8_t &lpos = location.pos;
const xy_int8_t &lpos = location.pos;
do {
location = find_closest_mesh_point_of_type(INVALID, pos);
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
@ -1006,7 +1006,7 @@
#endif
MeshFlags done_flags{0};
xy_int8_t &lpos = location.pos;
const xy_int8_t &lpos = location.pos;
do {
location = find_closest_mesh_point_of_type(SET_IN_BITMAP, pos, false, &done_flags);
@ -1294,7 +1294,7 @@
closest.distance = -99999.9f;
// Get the reference position, either nozzle or probe
const xy_pos_t ref = probe_relative ? pos + probe_offset_xy : pos;
const xy_pos_t ref = probe_relative ? pos + probe.offset_xy : pos;
float best_so_far = 99999.99f;
@ -1393,13 +1393,13 @@
#include "../../../libs/vector_3.h"
void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) {
const float x_min = probe_min_x(), x_max = probe_max_x(),
y_min = probe_min_y(), y_max = probe_max_y(),
const float x_min = probe.min_x(), x_max = probe.max_x(),
y_min = probe.min_y(), y_max = probe.max_y(),
dx = (x_max - x_min) / (g29_grid_size - 1),
dy = (y_max - y_min) / (g29_grid_size - 1);
xy_float_t points[3];
get_three_probe_points(points);
probe.get_three_points(points);
float measured_z;
bool abort_flag = false;
@ -1417,7 +1417,7 @@
ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
#endif
measured_z = probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level);
measured_z = probe.probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level);
if (isnan(measured_z))
abort_flag = true;
else {
@ -1438,7 +1438,7 @@
ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
#endif
measured_z = probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level);
measured_z = probe.probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level);
#ifdef VALIDATE_MESH_TILT
z2 = measured_z;
#endif
@ -1460,7 +1460,7 @@
ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
#endif
measured_z = probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level);
measured_z = probe.probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level);
#ifdef VALIDATE_MESH_TILT
z3 = measured_z;
#endif
@ -1476,9 +1476,9 @@
}
}
STOW_PROBE();
probe.stow();
#ifdef Z_AFTER_PROBING
move_z_after_probing();
probe.move_z_after_probing();
#endif
if (abort_flag) {
@ -1504,7 +1504,7 @@
ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points);
#endif
measured_z = probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling
measured_z = probe.probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling
abort_flag = isnan(measured_z);
@ -1523,7 +1523,7 @@
}
#endif
measured_z -= get_z_correction(rpos) /* + probe_offset.z */ ;
measured_z -= get_z_correction(rpos) /* + probe.offset.z */ ;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
@ -1540,9 +1540,9 @@
zig_zag ^= true;
}
}
STOW_PROBE();
probe.stow();
#ifdef Z_AFTER_PROBING
move_z_after_probing();
probe.move_z_after_probing();
#endif
if (abort_flag || finish_incremental_LSF(&lsf_results)) {
@ -1728,7 +1728,7 @@
adjust_mesh_to_mean(g29_c_flag, g29_constant);
#if HAS_BED_PROBE
SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe_offset.z, 7);
SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe.offset.z, 7);
#endif
SERIAL_ECHOLNPAIR("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50);