1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-23 20:18:52 +00:00

Tweaks to motion.h reachable tests

This commit is contained in:
Scott Lahteine 2018-08-21 23:33:55 -05:00
parent 2d3317a35b
commit f0dbe61692

View File

@ -36,6 +36,9 @@
#include "../module/scara.h"
#endif
// Error margin to work around float imprecision
constexpr float slop = 0.0001;
extern bool relative_mode;
extern float current_position[XYZE], // High-level current tool position
@ -265,22 +268,16 @@ void homeaxis(const AxisEnum axis);
#else // CARTESIAN
// Return true if the given position is within the machine bounds.
// 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 ENABLED(DUAL_X_CARRIAGE)
if (active_extruder == 0) {
// Add 0.001 margin to deal with float imprecision
return WITHIN(rx, X1_MIN_POS - 0.001f, X1_MAX_POS + 0.001f)
&& WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
} else {
// Add 0.001 margin to deal with float imprecision
return WITHIN(rx, X2_MIN_POS - 0.001f, X2_MAX_POS + 0.001f)
&& WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
}
if (active_extruder)
return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop);
else
return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop);
#else
// Add 0.001 margin to deal with float imprecision
return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f)
&& WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop);
#endif
}
@ -294,8 +291,8 @@ void homeaxis(const AxisEnum axis);
*/
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
&& WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f)
&& WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f);
&& WITHIN(rx, MIN_PROBE_X - slop, MAX_PROBE_X + slop)
&& WITHIN(ry, MIN_PROBE_Y - slop, MAX_PROBE_Y + slop);
}
#endif