Add loose soft endstop state, apply to UBL fine-tune (#19681)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Earle F. Philhower, III
2020-10-12 14:48:04 -07:00
committed by GitHub
parent f5139f8bf4
commit 193c0a52d9
16 changed files with 106 additions and 133 deletions

View File

@ -534,12 +534,11 @@ void restore_feedrate_and_scaling() {
#if HAS_SOFTWARE_ENDSTOPS
bool soft_endstops_enabled = true;
// Software Endstops are based on the configured limits.
axis_limits_t soft_endstop = {
soft_endstops_t soft_endstop = {
{ X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
{ X_MAX_POS, Y_MAX_POS, Z_MAX_POS }
{ X_MAX_POS, Y_MAX_POS, Z_MAX_POS },
{ true, false }
};
/**
@ -624,9 +623,9 @@ void restore_feedrate_and_scaling() {
#endif
if (DEBUGGING(LEVELING))
SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]);
}
if (DEBUGGING(LEVELING))
SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]);
}
/**
* Constrain the given coordinates to the software endstops.
@ -636,7 +635,7 @@ void restore_feedrate_and_scaling() {
*/
void apply_motion_limits(xyz_pos_t &target) {
if (!soft_endstops_enabled) return;
if (!soft_endstop._enabled) return;
#if IS_KINEMATIC
@ -688,7 +687,11 @@ void restore_feedrate_and_scaling() {
}
}
#endif // HAS_SOFTWARE_ENDSTOPS
#else // !HAS_SOFTWARE_ENDSTOPS
soft_endstops_t soft_endstop;
#endif // !HAS_SOFTWARE_ENDSTOPS
#if !UBL_SEGMENTED

View File

@ -148,26 +148,61 @@ inline float home_bump_mm(const AxisEnum axis) {
constexpr xyz_pos_t hotend_offset[1] = { { 0 } };
#endif
typedef struct { xyz_pos_t min, max; } axis_limits_t;
#if HAS_SOFTWARE_ENDSTOPS
extern bool soft_endstops_enabled;
extern axis_limits_t soft_endstop;
typedef struct {
xyz_pos_t min, max;
struct {
bool _enabled:1;
bool _loose:1;
};
bool enabled() { return _enabled && !_loose; }
void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) {
amin = -100000; amax = 100000; // "No limits"
#if HAS_SOFTWARE_ENDSTOPS
if (enabled()) switch (axis) {
case X_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x);
TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x);
break;
case Y_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y);
TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y);
break;
case Z_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z);
TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z);
default: break;
}
#endif
}
} soft_endstops_t;
extern soft_endstops_t soft_endstop;
void apply_motion_limits(xyz_pos_t &target);
void update_software_endstops(const AxisEnum axis
#if HAS_HOTEND_OFFSET
, const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
#endif
);
#define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
#else
constexpr bool soft_endstops_enabled = false;
//constexpr axis_limits_t soft_endstop = {
// { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
// { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } };
#define apply_motion_limits(V) NOOP
#define SET_SOFT_ENDSTOP_LOOSE(loose) (soft_endstop._loose = loose)
#else // !HAS_SOFTWARE_ENDSTOPS
typedef struct {
bool enabled() { return false; }
void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) {
// No limits
amin = current_position[axis] - 1000;
amax = current_position[axis] + 1000;
}
} soft_endstops_t;
extern soft_endstops_t soft_endstop;
#define apply_motion_limits(V) NOOP
#define update_software_endstops(...) NOOP
#define TEMPORARY_SOFT_ENDSTOP_STATE(...) NOOP
#endif
#define SET_SOFT_ENDSTOP_LOOSE() NOOP
#endif // !HAS_SOFTWARE_ENDSTOPS
void report_real_position();
void report_current_position();

View File

@ -1017,14 +1017,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Raise by a configured distance to avoid workpiece, except with
// SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
if (!no_move) {
#if HAS_SOFTWARE_ENDSTOPS
const float maxz = _MIN(soft_endstop.max.z, Z_MAX_POS);
#else
constexpr float maxz = Z_MAX_POS;
#endif
const float newz = current_position.z + _MAX(-diff.z, 0.0);
// Check if Z has space to compensate at least z_offset, and if not, just abort now
const float newz = current_position.z + _MAX(-diff.z, 0.0);
const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS);
if (newz > maxz) return;
current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz);