Move reachable test to Probe class

This commit is contained in:
Scott Lahteine
2020-02-27 06:16:33 -06:00
parent 9f8ee31144
commit be62ab2d02
9 changed files with 69 additions and 77 deletions

View File

@ -30,10 +30,6 @@
#include "../inc/MarlinConfig.h"
#if HAS_BED_PROBE
#include "probe.h"
#endif
#if IS_SCARA
#include "scara.h"
#endif
@ -58,7 +54,7 @@ FORCE_INLINE bool homing_needed() {
}
// Error margin to work around float imprecision
constexpr float slop = 0.0001;
constexpr float fslop = 0.0001;
extern bool relative_mode;
@ -306,7 +302,7 @@ void homeaxis(const AxisEnum axis);
// Return true if the given point is within the printable area
inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
#if ENABLED(DELTA)
return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + slop);
return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
#elif IS_SCARA
const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
return (
@ -322,67 +318,24 @@ void homeaxis(const AxisEnum axis);
return position_is_reachable(pos.x, pos.y, inset);
}
#if HAS_BED_PROBE
#if HAS_PROBE_XY_OFFSET
// 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_xy.x, ry - probe.offset_xy.y)
&& position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
}
#else
FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) {
return position_is_reachable(rx, ry, MIN_PROBE_EDGE);
}
#endif
#endif // HAS_BED_PROBE
#else // CARTESIAN
// Return true if the given position is within the machine bounds.
inline bool position_is_reachable(const float &rx, const float &ry) {
if (!WITHIN(ry, Y_MIN_POS - slop, Y_MAX_POS + slop)) return false;
if (!WITHIN(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
#if ENABLED(DUAL_X_CARRIAGE)
if (active_extruder)
return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop);
return WITHIN(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
else
return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop);
return WITHIN(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
#else
return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop);
return WITHIN(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
#endif
}
inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }
#if HAS_BED_PROBE
/**
* Return whether the given position is within the bed, and whether the nozzle
* can reach the position required to put the probe at the given position.
*
* Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
* 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);
}
#endif // HAS_BED_PROBE
#endif // CARTESIAN
#if !HAS_BED_PROBE
FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
#endif
FORCE_INLINE bool position_is_reachable_by_probe(const xy_pos_t &pos) { return position_is_reachable_by_probe(pos.x, pos.y); }
/**
* Duplication mode
*/

View File

@ -89,7 +89,7 @@ Probe probe;
xyz_pos_t Probe::offset; // Initialized by settings.load()
#if HAS_PROBE_XY_OFFSET
const xyz_pos_t &Probe::offset_xy = probe.offset;
const xyz_pos_t &Probe::offset_xy = Probe::offset;
#endif
#if ENABLED(Z_PROBE_SLED)
@ -727,7 +727,7 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
// TODO: Adapt for SCARA, where the offset rotates
xyz_pos_t npos = { rx, ry };
if (probe_relative) { // The given position is in terms of the probe
if (!position_is_reachable_by_probe(npos)) {
if (!can_reach(npos)) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
return NAN;
}

View File

@ -27,6 +27,8 @@
#include "../inc/MarlinConfig.h"
#include "motion.h"
#if HAS_BED_PROBE
enum ProbePtRaise : uint8_t {
PROBE_PT_NONE, // No raise or stow after run_z_probe
@ -45,6 +47,39 @@ public:
static bool set_deployed(const bool deploy);
#if IS_KINEMATIC
#if HAS_PROBE_XY_OFFSET
// 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.
static inline bool can_reach(const float &rx, const float &ry) {
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
&& position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE)); // Can the nozzle also go near there?
}
#else
FORCE_INLINE static bool can_reach(const float &rx, const float &ry) {
return position_is_reachable(rx, ry, MIN_PROBE_EDGE);
}
#endif
#else
/**
* Return whether the given position is within the bed, and whether the nozzle
* can reach the position required to put the probe at the given position.
*
* Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
* nozzle must be be able to reach +10,-10.
*/
static inline bool can_reach(const float &rx, const float &ry) {
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
&& WITHIN(rx, min_x() - fslop, max_x() + fslop)
&& WITHIN(ry, min_y() - fslop, max_y() + fslop);
}
#endif
#ifdef Z_AFTER_PROBING
static void move_z_after_probing();
#endif
@ -62,8 +97,22 @@ public:
static bool set_deployed(const bool) { return false; }
FORCE_INLINE static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
#endif
FORCE_INLINE static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
FORCE_INLINE static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
return (
#if IS_KINEMATIC
can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
#else
can_reach(lf) && can_reach(rb)
#endif
);
}
// Use offset_xy for read only access
// More optimal the XY offset is known to always be zero.
#if HAS_PROBE_XY_OFFSET