Improve motion-based endstop triggering code
This commit is contained in:
parent
3a40e637cd
commit
25a61e9061
@ -278,12 +278,16 @@ void Endstops::update() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(COREXY) || ENABLED(COREXZ)
|
||||
#define CORE_X_CMP ==
|
||||
#elif ENABLED(COREYX) || ENABLED(COREZX)
|
||||
#define CORE_X_CMP !=
|
||||
/**
|
||||
* Define conditions for checking endstops
|
||||
*/
|
||||
|
||||
#if IS_CORE
|
||||
#define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
|
||||
#define D_(N) stepper.motor_direction(CORE_AXIS_##N)
|
||||
#endif
|
||||
|
||||
#if CORE_IS_XY || CORE_IS_XZ
|
||||
/**
|
||||
* Head direction in -X axis for CoreXY and CoreXZ bots.
|
||||
*
|
||||
@ -291,52 +295,16 @@ void Endstops::update() {
|
||||
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
|
||||
* If DeltaA == DeltaB, the movement is only in the 1st axis (X)
|
||||
*/
|
||||
#if CORE_IS_XY || CORE_IS_XZ
|
||||
if (stepper.current_block->steps[CORE_AXIS_1] != stepper.current_block->steps[CORE_AXIS_2]
|
||||
|| ( stepper.current_block->steps[CORE_AXIS_1] > 0
|
||||
&& stepper.motor_direction(CORE_AXIS_1) CORE_X_CMP stepper.motor_direction(CORE_AXIS_2)
|
||||
)
|
||||
) {
|
||||
if (stepper.motor_direction(X_HEAD))
|
||||
#if ENABLED(COREXY) || ENABLED(COREXZ)
|
||||
#define X_CMP ==
|
||||
#else
|
||||
if (stepper.current_block->steps[X_AXIS] > 0)
|
||||
if (stepper.motor_direction(X_AXIS)) // stepping along -X axis (regular Cartesian bot)
|
||||
#define X_CMP !=
|
||||
#endif
|
||||
{ // -direction
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ( (stepper.current_block->active_extruder == 0 && X_HOME_DIR < 0)
|
||||
|| (stepper.current_block->active_extruder != 0 && X2_HOME_DIR < 0)
|
||||
)
|
||||
#endif
|
||||
{
|
||||
#if HAS_X_MIN
|
||||
UPDATE_ENDSTOP(X, MIN);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else { // +direction
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ( (stepper.current_block->active_extruder == 0 && X_HOME_DIR > 0)
|
||||
|| (stepper.current_block->active_extruder != 0 && X2_HOME_DIR > 0)
|
||||
)
|
||||
#endif
|
||||
{
|
||||
#if HAS_X_MAX
|
||||
UPDATE_ENDSTOP(X, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if CORE_IS_XY || CORE_IS_XZ
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle swapped vs. typical Core axis order
|
||||
#if ENABLED(COREYX) || ENABLED(COREYZ)
|
||||
#define CORE_YZ_CMP ==
|
||||
#elif ENABLED(COREXY) || ENABLED(COREZY)
|
||||
#define CORE_YZ_CMP !=
|
||||
#define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
|
||||
#define X_AXIS_HEAD X_HEAD
|
||||
#else
|
||||
#define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
|
||||
#define X_AXIS_HEAD X_AXIS
|
||||
#endif
|
||||
|
||||
#if CORE_IS_XY || CORE_IS_YZ
|
||||
@ -347,35 +315,16 @@ void Endstops::update() {
|
||||
* If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
|
||||
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
|
||||
*/
|
||||
if (stepper.current_block->steps[CORE_AXIS_1] != stepper.current_block->steps[CORE_AXIS_2]
|
||||
|| ( stepper.current_block->steps[CORE_AXIS_1] > 0
|
||||
&& stepper.motor_direction(CORE_AXIS_1) CORE_YZ_CMP stepper.motor_direction(CORE_AXIS_2)
|
||||
)
|
||||
) {
|
||||
if (stepper.motor_direction(Y_HEAD))
|
||||
#if ENABLED(COREYX) || ENABLED(COREYZ)
|
||||
#define Y_CMP ==
|
||||
#else
|
||||
if (stepper.current_block->steps[Y_AXIS] > 0)
|
||||
if (stepper.motor_direction(Y_AXIS)) // -direction
|
||||
#define Y_CMP !=
|
||||
#endif
|
||||
{ // -direction
|
||||
#if HAS_Y_MIN
|
||||
UPDATE_ENDSTOP(Y, MIN);
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if HAS_Y_MAX
|
||||
UPDATE_ENDSTOP(Y, MAX);
|
||||
#endif
|
||||
}
|
||||
#if CORE_IS_XY || CORE_IS_YZ
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLED(COREZX) || ENABLED(COREZY)
|
||||
#define CORE_YZ_CMP ==
|
||||
#elif ENABLED(COREXZ) || ENABLED(COREYZ)
|
||||
#define CORE_YZ_CMP !=
|
||||
#define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
|
||||
#define Y_AXIS_HEAD Y_HEAD
|
||||
#else
|
||||
#define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
|
||||
#define Y_AXIS_HEAD Y_AXIS
|
||||
#endif
|
||||
|
||||
#if CORE_IS_XZ || CORE_IS_YZ
|
||||
@ -386,17 +335,62 @@ void Endstops::update() {
|
||||
* If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
|
||||
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
|
||||
*/
|
||||
if (stepper.current_block->steps[CORE_AXIS_1] != stepper.current_block->steps[CORE_AXIS_2]
|
||||
|| ( stepper.current_block->steps[CORE_AXIS_1] > 0
|
||||
&& stepper.motor_direction(CORE_AXIS_1) CORE_YZ_CMP stepper.motor_direction(CORE_AXIS_2)
|
||||
)
|
||||
) {
|
||||
if (stepper.motor_direction(Z_HEAD))
|
||||
#if ENABLED(COREZX) || ENABLED(COREZY)
|
||||
#define Z_CMP ==
|
||||
#else
|
||||
if (stepper.current_block->steps[Z_AXIS] > 0)
|
||||
if (stepper.motor_direction(Z_AXIS))
|
||||
#define Z_CMP !=
|
||||
#endif
|
||||
{ // Z -direction. Gantry down, bed up.
|
||||
#define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
|
||||
#define Z_AXIS_HEAD Z_HEAD
|
||||
#else
|
||||
#define Z_MOVE_TEST stepper.current_block->steps[Z_AXIS] > 0
|
||||
#define Z_AXIS_HEAD Z_AXIS
|
||||
#endif
|
||||
|
||||
// With Dual X, endstops are only checked in the homing direction for the active extruder
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
#define E0_ACTIVE stepper.current_block->active_extruder == 0
|
||||
#define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
|
||||
#define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
|
||||
#else
|
||||
#define X_MIN_TEST true
|
||||
#define X_MAX_TEST true
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Check and update endstops according to conditions
|
||||
*/
|
||||
|
||||
if (X_MOVE_TEST) {
|
||||
if (stepper.motor_direction(X_AXIS_HEAD)) {
|
||||
if (X_MIN_TEST) { // -direction
|
||||
#if HAS_X_MIN
|
||||
UPDATE_ENDSTOP(X, MIN);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (X_MAX_TEST) { // +direction
|
||||
#if HAS_X_MAX
|
||||
UPDATE_ENDSTOP(X, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (Y_MOVE_TEST) {
|
||||
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
||||
#if HAS_Y_MIN
|
||||
UPDATE_ENDSTOP(Y, MIN);
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if HAS_Y_MAX
|
||||
UPDATE_ENDSTOP(Y, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (Z_MOVE_TEST) {
|
||||
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
|
||||
#if HAS_Z_MIN
|
||||
#if ENABLED(Z_DUAL_ENDSTOPS)
|
||||
|
||||
@ -453,9 +447,7 @@ void Endstops::update() {
|
||||
#endif // !Z_MIN_PROBE_PIN...
|
||||
#endif // Z_MAX_PIN
|
||||
}
|
||||
#if CORE_IS_XZ || CORE_IS_YZ
|
||||
}
|
||||
#endif
|
||||
|
||||
old_endstop_bits = current_endstop_bits;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user