Encapsulate probe as singleton class (#16751)
This commit is contained in:
@ -587,12 +587,12 @@ void MarlinSettings::postprocess() {
|
||||
#if HAS_FILAMENT_SENSOR
|
||||
const bool &runout_sensor_enabled = runout.enabled;
|
||||
#else
|
||||
const bool runout_sensor_enabled = true;
|
||||
constexpr bool runout_sensor_enabled = true;
|
||||
#endif
|
||||
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM)
|
||||
const float &runout_distance_mm = runout.runout_distance();
|
||||
#else
|
||||
const float runout_distance_mm = 0;
|
||||
constexpr float runout_distance_mm = 0;
|
||||
#endif
|
||||
_FIELD_TEST(runout_sensor_enabled);
|
||||
EEPROM_WRITE(runout_sensor_enabled);
|
||||
@ -643,7 +643,12 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
_FIELD_TEST(probe_offset);
|
||||
EEPROM_WRITE(probe_offset);
|
||||
#if HAS_BED_PROBE
|
||||
const xyz_pos_t &zpo = probe.offset;
|
||||
#else
|
||||
constexpr xyz_pos_t zpo{0};
|
||||
#endif
|
||||
EEPROM_WRITE(zpo);
|
||||
}
|
||||
|
||||
//
|
||||
@ -1458,7 +1463,7 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
#if HAS_FILAMENT_SENSOR
|
||||
bool &runout_sensor_enabled = runout.enabled;
|
||||
const bool &runout_sensor_enabled = runout.enabled;
|
||||
#else
|
||||
bool runout_sensor_enabled;
|
||||
#endif
|
||||
@ -1515,7 +1520,7 @@ void MarlinSettings::postprocess() {
|
||||
{
|
||||
_FIELD_TEST(probe_offset);
|
||||
#if HAS_BED_PROBE
|
||||
xyz_pos_t &zpo = probe_offset;
|
||||
const xyz_pos_t &zpo = probe.offset;
|
||||
#else
|
||||
xyz_pos_t zpo;
|
||||
#endif
|
||||
@ -1609,7 +1614,7 @@ void MarlinSettings::postprocess() {
|
||||
{
|
||||
_FIELD_TEST(bltouch_last_written_mode);
|
||||
#if ENABLED(BLTOUCH)
|
||||
bool &bltouch_last_written_mode = bltouch.last_written_mode;
|
||||
const bool &bltouch_last_written_mode = bltouch.last_written_mode;
|
||||
#else
|
||||
bool bltouch_last_written_mode;
|
||||
#endif
|
||||
@ -2120,14 +2125,14 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
{
|
||||
#if ENABLED(BACKLASH_GCODE)
|
||||
xyz_float_t &backlash_distance_mm = backlash.distance_mm;
|
||||
uint8_t &backlash_correction = backlash.correction;
|
||||
const xyz_float_t &backlash_distance_mm = backlash.distance_mm;
|
||||
const uint8_t &backlash_correction = backlash.correction;
|
||||
#else
|
||||
float backlash_distance_mm[XYZ];
|
||||
uint8_t backlash_correction;
|
||||
#endif
|
||||
#if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
|
||||
float &backlash_smoothing_mm = backlash.smoothing_mm;
|
||||
const float &backlash_smoothing_mm = backlash.smoothing_mm;
|
||||
#else
|
||||
float backlash_smoothing_mm;
|
||||
#endif
|
||||
@ -2461,10 +2466,10 @@ void MarlinSettings::reset() {
|
||||
constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
|
||||
static_assert(COUNT(dpo) == 3, "NOZZLE_TO_PROBE_OFFSET must contain offsets for X, Y, and Z.");
|
||||
#if HAS_PROBE_XY_OFFSET
|
||||
LOOP_XYZ(a) probe_offset[a] = dpo[a];
|
||||
LOOP_XYZ(a) probe.offset[a] = dpo[a];
|
||||
#else
|
||||
probe_offset.x = probe_offset.y = 0;
|
||||
probe_offset.z = dpo[Z_AXIS];
|
||||
probe.offset.x = probe.offset.y = 0;
|
||||
probe.offset.z = dpo[Z_AXIS];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -3216,13 +3221,13 @@ void MarlinSettings::reset() {
|
||||
CONFIG_ECHO_START();
|
||||
SERIAL_ECHOLNPAIR_P(
|
||||
#if HAS_PROBE_XY_OFFSET
|
||||
PSTR(" M851 X"), LINEAR_UNIT(probe_offset_xy.x),
|
||||
SP_Y_STR, LINEAR_UNIT(probe_offset_xy.y),
|
||||
PSTR(" M851 X"), LINEAR_UNIT(probe.offset_xy.x),
|
||||
SP_Y_STR, LINEAR_UNIT(probe.offset_xy.y),
|
||||
SP_Z_STR
|
||||
#else
|
||||
PSTR(" M851 X0 Y0 Z")
|
||||
#endif
|
||||
, LINEAR_UNIT(probe_offset.z)
|
||||
, LINEAR_UNIT(probe.offset.z)
|
||||
);
|
||||
#endif
|
||||
|
||||
|
@ -95,7 +95,7 @@ void recalc_delta_settings() {
|
||||
float delta_calibration_radius() {
|
||||
return calibration_radius_factor * (
|
||||
#if HAS_BED_PROBE
|
||||
FLOOR((DELTA_PRINTABLE_RADIUS) - _MAX(HYPOT(probe_offset_xy.x, probe_offset_xy.y), MIN_PROBE_EDGE))
|
||||
FLOOR((DELTA_PRINTABLE_RADIUS) - _MAX(HYPOT(probe.offset_xy.x, probe.offset_xy.y), MIN_PROBE_EDGE))
|
||||
#else
|
||||
DELTA_PRINTABLE_RADIUS
|
||||
#endif
|
||||
@ -251,7 +251,7 @@ void home_delta() {
|
||||
// Move all carriages together linearly until an endstop is hit.
|
||||
current_position.z = (delta_height + 10
|
||||
#if HAS_BED_PROBE
|
||||
- probe_offset.z
|
||||
- probe.offset.z
|
||||
#endif
|
||||
);
|
||||
line_to_current_position(homing_feedrate(Z_AXIS));
|
||||
|
@ -280,7 +280,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
|
||||
, true
|
||||
#endif
|
||||
);
|
||||
xyze_pos_t &cartes = pos;
|
||||
const xyze_pos_t &cartes = pos;
|
||||
#endif
|
||||
if (axis == ALL_AXES)
|
||||
current_position = cartes;
|
||||
@ -547,7 +547,7 @@ void restore_feedrate_and_scaling() {
|
||||
soft_endstop.min[axis] = base_min_pos(axis);
|
||||
soft_endstop.max[axis] = (axis == Z_AXIS ? delta_height
|
||||
#if HAS_BED_PROBE
|
||||
- probe_offset.z
|
||||
- probe.offset.z
|
||||
#endif
|
||||
: base_max_pos(axis));
|
||||
|
||||
@ -1281,7 +1281,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
|
||||
#if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
|
||||
// Wait for bed to heat back up between probing points
|
||||
if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) {
|
||||
serialprintPGM(msg_wait_for_bed_heating);
|
||||
serialprintPGM(probe.msg_wait_for_bed_heating);
|
||||
#if HAS_DISPLAY
|
||||
LCD_MESSAGEPGM(MSG_BED_HEATING);
|
||||
#endif
|
||||
@ -1307,7 +1307,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
|
||||
if (is_home_dir) {
|
||||
|
||||
#if HOMING_Z_WITH_PROBE && QUIET_PROBING
|
||||
if (axis == Z_AXIS) probing_pause(true);
|
||||
if (axis == Z_AXIS) probe.set_probing_paused(true);
|
||||
#endif
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
@ -1347,7 +1347,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
|
||||
if (is_home_dir) {
|
||||
|
||||
#if HOMING_Z_WITH_PROBE && QUIET_PROBING
|
||||
if (axis == Z_AXIS) probing_pause(false);
|
||||
if (axis == Z_AXIS) probe.set_probing_paused(false);
|
||||
#endif
|
||||
|
||||
endstops.validate_homing_move();
|
||||
@ -1397,7 +1397,7 @@ void set_axis_is_at_home(const AxisEnum axis) {
|
||||
#elif ENABLED(DELTA)
|
||||
current_position[axis] = (axis == Z_AXIS ? delta_height
|
||||
#if HAS_BED_PROBE
|
||||
- probe_offset.z
|
||||
- probe.offset.z
|
||||
#endif
|
||||
: base_home_pos(axis));
|
||||
#else
|
||||
@ -1411,9 +1411,9 @@ void set_axis_is_at_home(const AxisEnum axis) {
|
||||
if (axis == Z_AXIS) {
|
||||
#if HOMING_Z_WITH_PROBE
|
||||
|
||||
current_position.z -= probe_offset.z;
|
||||
current_position.z -= probe.offset.z;
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe_offset.z = ", probe_offset.z);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z);
|
||||
|
||||
#else
|
||||
|
||||
@ -1509,7 +1509,7 @@ void homeaxis(const AxisEnum axis) {
|
||||
|
||||
// Homing Z towards the bed? Deploy the Z probe or endstop.
|
||||
#if HOMING_Z_WITH_PROBE
|
||||
if (axis == Z_AXIS && DEPLOY_PROBE()) return;
|
||||
if (axis == Z_AXIS && probe.deploy()) return;
|
||||
#endif
|
||||
|
||||
// Set flags for X, Y, Z motor locking
|
||||
@ -1751,7 +1751,7 @@ void homeaxis(const AxisEnum axis) {
|
||||
|
||||
// Put away the Z probe
|
||||
#if HOMING_Z_WITH_PROBE
|
||||
if (axis == Z_AXIS && STOW_PROBE()) return;
|
||||
if (axis == Z_AXIS && probe.stow()) return;
|
||||
#endif
|
||||
|
||||
#if DISABLED(DELTA) && defined(HOMING_BACKOFF_MM)
|
||||
|
@ -329,7 +329,7 @@ void homeaxis(const AxisEnum axis);
|
||||
// Return true if the both nozzle and the probe can reach the given point.
|
||||
// Note: This won't work on SCARA since the probe offset rotates with the arm.
|
||||
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
|
||||
return position_is_reachable(rx - probe_offset.x, ry - probe_offset.y)
|
||||
return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y)
|
||||
&& position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
|
||||
}
|
||||
|
||||
@ -369,9 +369,9 @@ void homeaxis(const AxisEnum axis);
|
||||
* nozzle must be be able to reach +10,-10.
|
||||
*/
|
||||
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
|
||||
return position_is_reachable(rx - probe_offset_xy.x, ry - probe_offset_xy.y)
|
||||
&& WITHIN(rx, probe_min_x() - slop, probe_max_x() + slop)
|
||||
&& WITHIN(ry, probe_min_y() - slop, probe_max_y() + slop);
|
||||
return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y)
|
||||
&& WITHIN(rx, probe.min_x() - slop, probe.max_x() + slop)
|
||||
&& WITHIN(ry, probe.min_y() - slop, probe.max_y() + slop);
|
||||
}
|
||||
|
||||
#endif // HAS_BED_PROBE
|
||||
|
@ -2779,7 +2779,7 @@ void Planner::set_max_acceleration(const uint8_t axis, float targetValue) {
|
||||
const xyze_float_t &max_acc_edit_scaled = max_accel_edit;
|
||||
#else
|
||||
constexpr xyze_float_t max_accel_edit = DEFAULT_MAX_ACCELERATION;
|
||||
const xyze_float_t max_acc_edit_scaled = max_accel_edit * 2;
|
||||
constexpr xyze_float_t max_acc_edit_scaled = max_accel_edit * 2;
|
||||
#endif
|
||||
limit_and_warn(targetValue, axis, PSTR("Acceleration"), max_acc_edit_scaled);
|
||||
#endif
|
||||
@ -2796,7 +2796,7 @@ void Planner::set_max_feedrate(const uint8_t axis, float targetValue) {
|
||||
const xyze_float_t &max_fr_edit_scaled = max_fr_edit;
|
||||
#else
|
||||
constexpr xyze_float_t max_fr_edit = DEFAULT_MAX_FEEDRATE;
|
||||
const xyze_float_t max_fr_edit_scaled = max_fr_edit * 2;
|
||||
constexpr xyze_float_t max_fr_edit_scaled = max_fr_edit * 2;
|
||||
#endif
|
||||
limit_and_warn(targetValue, axis, PSTR("Feedrate"), max_fr_edit_scaled);
|
||||
#endif
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* probe.cpp
|
||||
* module/probe.cpp
|
||||
*/
|
||||
|
||||
#include "../inc/MarlinConfig.h"
|
||||
@ -84,14 +84,14 @@
|
||||
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
|
||||
#include "../core/debug_out.h"
|
||||
|
||||
Probe probe;
|
||||
|
||||
xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
xyz_pos_t Probe::offset; // Initialized by settings.load()
|
||||
|
||||
#if HAS_PROBE_XY_OFFSET
|
||||
xyz_pos_t &probe_offset_xy = probe_offset;
|
||||
const xyz_pos_t &Probe::offset_xy = probe.offset;
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLED(Z_PROBE_SLED)
|
||||
|
||||
#ifndef SLED_DOCKING_OFFSET
|
||||
@ -104,7 +104,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
* stow[in] If false, move to MAX_X and engage the solenoid
|
||||
* If true, move to MAX_X and release the solenoid
|
||||
*/
|
||||
static void dock_sled(bool stow) {
|
||||
static void dock_sled(const bool stow) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("dock_sled(", stow, ")");
|
||||
|
||||
// Dock sled a bit closer to ensure proper capturing
|
||||
@ -118,7 +118,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
#elif ENABLED(TOUCH_MI_PROBE)
|
||||
|
||||
// Move to the magnet to unlock the probe
|
||||
void run_deploy_moves_script() {
|
||||
inline void run_deploy_moves_script() {
|
||||
#ifndef TOUCH_MI_DEPLOY_XPOS
|
||||
#define TOUCH_MI_DEPLOY_XPOS X_MIN_POS
|
||||
#elif TOUCH_MI_DEPLOY_XPOS > X_MAX_BED
|
||||
@ -153,7 +153,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
}
|
||||
|
||||
// Move down to the bed to stow the probe
|
||||
void run_stow_moves_script() {
|
||||
inline void run_stow_moves_script() {
|
||||
const xyz_pos_t oldpos = current_position;
|
||||
endstops.enable_z_probe(false);
|
||||
do_blocking_move_to_z(TOUCH_MI_RETRACT_Z, MMM_TO_MMS(HOMING_FEEDRATE_Z));
|
||||
@ -162,7 +162,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
|
||||
#elif ENABLED(Z_PROBE_ALLEN_KEY)
|
||||
|
||||
void run_deploy_moves_script() {
|
||||
inline void run_deploy_moves_script() {
|
||||
#ifdef Z_PROBE_ALLEN_KEY_DEPLOY_1
|
||||
#ifndef Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE
|
||||
#define Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE 0.0
|
||||
@ -200,7 +200,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
#endif
|
||||
}
|
||||
|
||||
void run_stow_moves_script() {
|
||||
inline void run_stow_moves_script() {
|
||||
#ifdef Z_PROBE_ALLEN_KEY_STOW_1
|
||||
#ifndef Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE
|
||||
#define Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE 0.0
|
||||
@ -241,7 +241,8 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
#endif // Z_PROBE_ALLEN_KEY
|
||||
|
||||
#if QUIET_PROBING
|
||||
void probing_pause(const bool p) {
|
||||
|
||||
void Probe::set_probing_paused(const bool p) {
|
||||
#if ENABLED(PROBING_HEATERS_OFF)
|
||||
thermalManager.pause(p);
|
||||
#endif
|
||||
@ -262,16 +263,17 @@ xyz_pos_t probe_offset; // Initialized by settings.load()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#endif // QUIET_PROBING
|
||||
|
||||
/**
|
||||
* Raise Z to a minimum height to make room for a probe to move
|
||||
*/
|
||||
inline void do_probe_raise(const float z_raise) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("do_probe_raise(", z_raise, ")");
|
||||
void Probe::do_z_raise(const float z_raise) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::move_z(", z_raise, ")");
|
||||
|
||||
float z_dest = z_raise;
|
||||
if (probe_offset.z < 0) z_dest -= probe_offset.z;
|
||||
if (offset.z < 0) z_dest -= offset.z;
|
||||
|
||||
NOMORE(z_dest, Z_MAX_POS);
|
||||
|
||||
@ -351,11 +353,15 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// returns false for ok and true for failure
|
||||
bool set_probe_deployed(const bool deploy) {
|
||||
/**
|
||||
* Attempt to deploy or stow the probe
|
||||
*
|
||||
* Return TRUE if the probe could not be deployed/stowed
|
||||
*/
|
||||
bool Probe::set_deployed(const bool deploy) {
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_POS("set_probe_deployed", current_position);
|
||||
DEBUG_POS("Probe::set_deployed", current_position);
|
||||
DEBUG_ECHOLNPAIR("deploy: ", deploy);
|
||||
}
|
||||
|
||||
@ -378,7 +384,7 @@ bool set_probe_deployed(const bool deploy) {
|
||||
#endif
|
||||
|
||||
if (deploy_stow_condition && unknown_condition)
|
||||
do_probe_raise(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE));
|
||||
do_z_raise(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE));
|
||||
|
||||
#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
|
||||
if (axis_unhomed_error(
|
||||
@ -433,7 +439,7 @@ bool set_probe_deployed(const bool deploy) {
|
||||
|
||||
#ifdef Z_AFTER_PROBING
|
||||
// After probing move to a preferred Z position
|
||||
void move_z_after_probing() {
|
||||
void Probe::move_z_after_probing() {
|
||||
if (current_position.z != Z_AFTER_PROBING) {
|
||||
do_blocking_move_to_z(Z_AFTER_PROBING);
|
||||
current_position.z = Z_AFTER_PROBING;
|
||||
@ -450,11 +456,11 @@ bool set_probe_deployed(const bool deploy) {
|
||||
*/
|
||||
|
||||
#if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
|
||||
const char msg_wait_for_bed_heating[25] PROGMEM = "Wait for bed heating...\n";
|
||||
PGM_P Probe::msg_wait_for_bed_heating[25] PROGMEM = "Wait for bed heating...\n";
|
||||
#endif
|
||||
|
||||
static bool do_probe_move(const float z, const feedRate_t fr_mm_s) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> do_probe_move", current_position);
|
||||
bool Probe::move_to_z(const float z, const feedRate_t fr_mm_s) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::move_to_z", current_position);
|
||||
|
||||
#if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
|
||||
// Wait for bed to heat back up between probing points
|
||||
@ -482,7 +488,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) {
|
||||
#endif
|
||||
|
||||
#if QUIET_PROBING
|
||||
probing_pause(true);
|
||||
set_probing_paused(true);
|
||||
#endif
|
||||
|
||||
// Move down until the probe is triggered
|
||||
@ -504,7 +510,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) {
|
||||
;
|
||||
|
||||
#if QUIET_PROBING
|
||||
probing_pause(false);
|
||||
set_probing_paused(false);
|
||||
#endif
|
||||
|
||||
// Re-enable stealthChop if used. Disable diag1 pin on driver.
|
||||
@ -530,7 +536,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) {
|
||||
// Tell the planner where we actually are
|
||||
sync_plan_position();
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< do_probe_move", current_position);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< Probe::move_to_z", current_position);
|
||||
|
||||
return !probe_triggered;
|
||||
}
|
||||
@ -543,19 +549,19 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) {
|
||||
*
|
||||
* @return The Z position of the bed at the current XY or NAN on error.
|
||||
*/
|
||||
static float run_z_probe() {
|
||||
float Probe::run_z_probe() {
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::run_z_probe", current_position);
|
||||
|
||||
// Stop the probe before it goes too low to prevent damage.
|
||||
// If Z isn't known then probe to -10mm.
|
||||
const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -probe_offset.z + Z_PROBE_LOW_POINT : -10.0;
|
||||
const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -offset.z + Z_PROBE_LOW_POINT : -10.0;
|
||||
|
||||
// Double-probing does a fast probe followed by a slow probe
|
||||
#if TOTAL_PROBING == 2
|
||||
|
||||
// Do a first probe at the fast speed
|
||||
if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) {
|
||||
if (move_to_z(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) {
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOLNPGM("FAST Probe fail!");
|
||||
DEBUG_POS("<<< run_z_probe", current_position);
|
||||
@ -574,10 +580,10 @@ static float run_z_probe() {
|
||||
|
||||
// If the nozzle is well over the travel height then
|
||||
// move down quickly before doing the slow probe
|
||||
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (probe_offset.z < 0 ? -probe_offset.z : 0);
|
||||
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (offset.z < 0 ? -offset.z : 0);
|
||||
if (current_position.z > z) {
|
||||
// Probe down fast. If the probe never triggered, raise for probe clearance
|
||||
if (!do_probe_move(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST)))
|
||||
if (!move_to_z(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST)))
|
||||
do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
|
||||
}
|
||||
#endif
|
||||
@ -587,7 +593,7 @@ static float run_z_probe() {
|
||||
#endif
|
||||
|
||||
#if TOTAL_PROBING > 2
|
||||
float probes_total = 0;
|
||||
float probes_z_sum = 0;
|
||||
for (
|
||||
#if EXTRA_PROBING
|
||||
uint8_t p = 0; p < TOTAL_PROBING; p++
|
||||
@ -598,7 +604,7 @@ static float run_z_probe() {
|
||||
#endif
|
||||
{
|
||||
// Probe downward slowly to find the bed
|
||||
if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW))) {
|
||||
if (move_to_z(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW))) {
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOLNPGM("SLOW Probe fail!");
|
||||
DEBUG_POS("<<< run_z_probe", current_position);
|
||||
@ -622,7 +628,7 @@ static float run_z_probe() {
|
||||
}
|
||||
}
|
||||
#elif TOTAL_PROBING > 2
|
||||
probes_total += z;
|
||||
probes_z_sum += z;
|
||||
#else
|
||||
UNUSED(z);
|
||||
#endif
|
||||
@ -653,11 +659,11 @@ static float run_z_probe() {
|
||||
|
||||
// Return the average value of all remaining probes.
|
||||
for (uint8_t i = min_avg_idx; i <= max_avg_idx; i++)
|
||||
probes_total += probes[i];
|
||||
probes_z_sum += probes[i];
|
||||
|
||||
#endif
|
||||
|
||||
const float measured_z = probes_total * RECIPROCAL(MULTIPLE_PROBING);
|
||||
const float measured_z = probes_z_sum * RECIPROCAL(MULTIPLE_PROBING);
|
||||
|
||||
#elif TOTAL_PROBING == 2
|
||||
|
||||
@ -689,10 +695,10 @@ static float run_z_probe() {
|
||||
* - Raise to the BETWEEN height
|
||||
* - Return the probed Z position
|
||||
*/
|
||||
float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/) {
|
||||
float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/) {
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOLNPAIR(
|
||||
">>> probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
|
||||
">>> Probe::probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
|
||||
", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none",
|
||||
", ", int(verbose_level),
|
||||
", ", probe_relative ? "probe" : "nozzle", "_relative)"
|
||||
@ -702,9 +708,12 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_
|
||||
|
||||
// TODO: Adapt for SCARA, where the offset rotates
|
||||
xyz_pos_t npos = { rx, ry };
|
||||
if (probe_relative) {
|
||||
if (!position_is_reachable_by_probe(npos)) return NAN; // The given position is in terms of the probe
|
||||
npos -= probe_offset_xy; // Get the nozzle position
|
||||
if (probe_relative) { // The given position is in terms of the probe
|
||||
if (!position_is_reachable_by_probe(npos)) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
|
||||
return NAN;
|
||||
}
|
||||
npos -= offset_xy; // Get the nozzle position
|
||||
}
|
||||
else if (!position_is_reachable(npos)) return NAN; // The given position is in terms of the nozzle
|
||||
|
||||
@ -724,38 +733,38 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_
|
||||
do_blocking_move_to(npos);
|
||||
|
||||
float measured_z = NAN;
|
||||
if (!DEPLOY_PROBE()) {
|
||||
measured_z = run_z_probe() + probe_offset.z;
|
||||
if (!deploy()) {
|
||||
measured_z = run_z_probe() + offset.z;
|
||||
|
||||
const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
|
||||
if (big_raise || raise_after == PROBE_PT_RAISE)
|
||||
do_blocking_move_to_z(current_position.z + (big_raise ? 25 : Z_CLEARANCE_BETWEEN_PROBES), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
|
||||
else if (raise_after == PROBE_PT_STOW)
|
||||
if (STOW_PROBE()) measured_z = NAN;
|
||||
if (stow()) measured_z = NAN;
|
||||
}
|
||||
|
||||
if (verbose_level > 2) {
|
||||
SERIAL_ECHOPAIR_F("Bed X: ", LOGICAL_X_POSITION(rx), 3);
|
||||
SERIAL_ECHOPAIR_F(" Y: ", LOGICAL_Y_POSITION(ry), 3);
|
||||
SERIAL_ECHOLNPAIR_F(" Z: ", measured_z, 3);
|
||||
SERIAL_ECHOPAIR_F( " Y: ", LOGICAL_Y_POSITION(ry), 3);
|
||||
SERIAL_ECHOLNPAIR_F( " Z: ", measured_z, 3);
|
||||
}
|
||||
|
||||
feedrate_mm_s = old_feedrate_mm_s;
|
||||
|
||||
if (isnan(measured_z)) {
|
||||
STOW_PROBE();
|
||||
stow();
|
||||
LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED);
|
||||
SERIAL_ERROR_MSG(MSG_ERR_PROBING_FAILED);
|
||||
}
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< probe_at_point");
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< Probe::probe_at_point");
|
||||
|
||||
return measured_z;
|
||||
}
|
||||
|
||||
#if HAS_Z_SERVO_PROBE
|
||||
|
||||
void servo_probe_init() {
|
||||
void Probe::servo_probe_init() {
|
||||
/**
|
||||
* Set position of Z Servo Endstop
|
||||
*
|
||||
|
@ -22,132 +22,150 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* probe.h - Move, deploy, enable, etc.
|
||||
* module/probe.h - Move, deploy, enable, etc.
|
||||
*/
|
||||
|
||||
#include "../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_BED_PROBE
|
||||
|
||||
extern xyz_pos_t probe_offset;
|
||||
|
||||
#if HAS_PROBE_XY_OFFSET
|
||||
extern xyz_pos_t &probe_offset_xy;
|
||||
#else
|
||||
constexpr xy_pos_t probe_offset_xy{0};
|
||||
#endif
|
||||
|
||||
bool set_probe_deployed(const bool deploy);
|
||||
#ifdef Z_AFTER_PROBING
|
||||
void move_z_after_probing();
|
||||
#endif
|
||||
enum ProbePtRaise : unsigned char {
|
||||
PROBE_PT_NONE, // No raise or stow after run_z_probe
|
||||
PROBE_PT_STOW, // Do a complete stow after run_z_probe
|
||||
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
|
||||
enum ProbePtRaise : uint8_t {
|
||||
PROBE_PT_NONE, // No raise or stow after run_z_probe
|
||||
PROBE_PT_STOW, // Do a complete stow after run_z_probe
|
||||
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
|
||||
PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
|
||||
};
|
||||
float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true);
|
||||
inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true) {
|
||||
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative);
|
||||
}
|
||||
#define DEPLOY_PROBE() set_probe_deployed(true)
|
||||
#define STOW_PROBE() set_probe_deployed(false)
|
||||
#if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
|
||||
extern const char msg_wait_for_bed_heating[25];
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
constexpr xyz_pos_t probe_offset{0};
|
||||
constexpr xy_pos_t probe_offset_xy{0};
|
||||
|
||||
#define DEPLOY_PROBE()
|
||||
#define STOW_PROBE()
|
||||
|
||||
#endif
|
||||
|
||||
#if HAS_BED_PROBE || HAS_LEVELING
|
||||
#if IS_KINEMATIC
|
||||
constexpr float printable_radius = (
|
||||
#if ENABLED(DELTA)
|
||||
DELTA_PRINTABLE_RADIUS
|
||||
#elif IS_SCARA
|
||||
SCARA_PRINTABLE_RADIUS
|
||||
#endif
|
||||
);
|
||||
class Probe {
|
||||
public:
|
||||
|
||||
inline float probe_radius() {
|
||||
return printable_radius - _MAX(MIN_PROBE_EDGE, HYPOT(probe_offset_xy.x, probe_offset_xy.y));
|
||||
#if HAS_BED_PROBE
|
||||
|
||||
static xyz_pos_t offset;
|
||||
|
||||
// Use offset_xy for read only access
|
||||
// More optimal the XY offset is known to always be zero.
|
||||
#if HAS_PROBE_XY_OFFSET
|
||||
static const xyz_pos_t &offset_xy;
|
||||
#else
|
||||
static constexpr xy_pos_t offset_xy{0};
|
||||
#endif
|
||||
|
||||
static bool set_deployed(const bool deploy);
|
||||
|
||||
#ifdef Z_AFTER_PROBING
|
||||
static void move_z_after_probing();
|
||||
#endif
|
||||
static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true);
|
||||
static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true) {
|
||||
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative);
|
||||
}
|
||||
#if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
|
||||
static PGM_P msg_wait_for_bed_heating[25];
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
static constexpr xyz_pos_t offset{0};
|
||||
static constexpr xy_pos_t offset_xy{0};
|
||||
|
||||
static bool set_deployed(const bool) { return false; }
|
||||
|
||||
#endif
|
||||
|
||||
inline float probe_min_x() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(X_CENTER) - probe_radius()
|
||||
#else
|
||||
_MAX((X_MIN_BED) + (MIN_PROBE_EDGE_LEFT), (X_MIN_POS) + probe_offset_xy.x)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
inline float probe_max_x() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(X_CENTER) + probe_radius()
|
||||
#else
|
||||
_MIN((X_MAX_BED) - (MIN_PROBE_EDGE_RIGHT), (X_MAX_POS) + probe_offset_xy.x)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
inline float probe_min_y() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(Y_CENTER) - probe_radius()
|
||||
#else
|
||||
_MAX((Y_MIN_BED) + (MIN_PROBE_EDGE_FRONT), (Y_MIN_POS) + probe_offset_xy.y)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
inline float probe_max_y() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(Y_CENTER) + probe_radius()
|
||||
#else
|
||||
_MIN((Y_MAX_BED) - (MIN_PROBE_EDGE_BACK), (Y_MAX_POS) + probe_offset_xy.y)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
static inline bool deploy() { return set_deployed(true); }
|
||||
static inline bool stow() { return set_deployed(false); }
|
||||
|
||||
#if NEEDS_THREE_PROBE_POINTS
|
||||
// Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
|
||||
template <typename T>
|
||||
inline void get_three_probe_points(T points[3]) {
|
||||
#if ENABLED(HAS_FIXED_3POINT)
|
||||
points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y);
|
||||
points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y);
|
||||
points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y);
|
||||
#else
|
||||
#if IS_KINEMATIC
|
||||
constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025,
|
||||
COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5;
|
||||
points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0);
|
||||
points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120);
|
||||
points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240);
|
||||
#else
|
||||
points[0].set(probe_min_x(), probe_min_y());
|
||||
points[1].set(probe_max_x(), probe_min_y());
|
||||
points[2].set((probe_max_x() - probe_min_x()) / 2, probe_max_y());
|
||||
#if HAS_BED_PROBE || HAS_LEVELING
|
||||
#if IS_KINEMATIC
|
||||
static constexpr float printable_radius = (
|
||||
#if ENABLED(DELTA)
|
||||
DELTA_PRINTABLE_RADIUS
|
||||
#elif IS_SCARA
|
||||
SCARA_PRINTABLE_RADIUS
|
||||
#endif
|
||||
#endif
|
||||
);
|
||||
|
||||
static inline float probe_radius() {
|
||||
return printable_radius - _MAX(MIN_PROBE_EDGE, HYPOT(offset_xy.x, offset_xy.y));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline float min_x() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(X_CENTER) - probe_radius()
|
||||
#else
|
||||
_MAX((X_MIN_BED) + (MIN_PROBE_EDGE_LEFT), (X_MIN_POS) + offset_xy.x)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
static inline float max_x() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(X_CENTER) + probe_radius()
|
||||
#else
|
||||
_MIN((X_MAX_BED) - (MIN_PROBE_EDGE_RIGHT), (X_MAX_POS) + offset_xy.x)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
static inline float min_y() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(Y_CENTER) - probe_radius()
|
||||
#else
|
||||
_MAX((Y_MIN_BED) + (MIN_PROBE_EDGE_FRONT), (Y_MIN_POS) + offset_xy.y)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
static inline float max_y() {
|
||||
return (
|
||||
#if IS_KINEMATIC
|
||||
(Y_CENTER) + probe_radius()
|
||||
#else
|
||||
_MIN((Y_MAX_BED) - (MIN_PROBE_EDGE_BACK), (Y_MAX_POS) + offset_xy.y)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#if NEEDS_THREE_PROBE_POINTS
|
||||
// Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
|
||||
template <typename T>
|
||||
static inline void get_three_points(T points[3]) {
|
||||
#if ENABLED(HAS_FIXED_3POINT)
|
||||
points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y);
|
||||
points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y);
|
||||
points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y);
|
||||
#else
|
||||
#if IS_KINEMATIC
|
||||
constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025,
|
||||
COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5;
|
||||
points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0);
|
||||
points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120);
|
||||
points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240);
|
||||
#else
|
||||
points[0].set(min_x(), min_y());
|
||||
points[1].set(max_x(), min_y());
|
||||
points[2].set((max_x() - min_x()) / 2, max_y());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HAS_BED_PROBE
|
||||
|
||||
#if HAS_Z_SERVO_PROBE
|
||||
static void servo_probe_init();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAS_Z_SERVO_PROBE
|
||||
void servo_probe_init();
|
||||
#endif
|
||||
#if QUIET_PROBING
|
||||
static void set_probing_paused(const bool p);
|
||||
#endif
|
||||
|
||||
#if QUIET_PROBING
|
||||
void probing_pause(const bool p);
|
||||
#endif
|
||||
private:
|
||||
static bool move_to_z(const float z, const feedRate_t fr_mm_s);
|
||||
static void do_z_raise(const float z_raise);
|
||||
static float run_z_probe();
|
||||
};
|
||||
|
||||
extern Probe probe;
|
||||
|
Reference in New Issue
Block a user