Improve motion-based endstop triggering code

This commit is contained in:
Scott Lahteine 2017-04-15 04:23:20 -05:00
parent 3a40e637cd
commit 25a61e9061

View file

@ -278,12 +278,16 @@ void Endstops::update() {
} }
#endif #endif
#if ENABLED(COREXY) || ENABLED(COREXZ) /**
#define CORE_X_CMP == * Define conditions for checking endstops
#elif ENABLED(COREYX) || ENABLED(COREZX) */
#define CORE_X_CMP !=
#if IS_CORE
#define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
#define D_(N) stepper.motor_direction(CORE_AXIS_##N)
#endif #endif
#if CORE_IS_XY || CORE_IS_XZ
/** /**
* Head direction in -X axis for CoreXY and CoreXZ bots. * 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 2nd axis (Y or Z, handled below)
* If DeltaA == DeltaB, the movement is only in the 1st axis (X) * If DeltaA == DeltaB, the movement is only in the 1st axis (X)
*/ */
#if CORE_IS_XY || CORE_IS_XZ #if ENABLED(COREXY) || ENABLED(COREXZ)
if (stepper.current_block->steps[CORE_AXIS_1] != stepper.current_block->steps[CORE_AXIS_2] #define X_CMP ==
|| ( 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))
#else #else
if (stepper.current_block->steps[X_AXIS] > 0) #define X_CMP !=
if (stepper.motor_direction(X_AXIS)) // stepping along -X axis (regular Cartesian bot)
#endif #endif
{ // -direction #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
#if ENABLED(DUAL_X_CARRIAGE) #define X_AXIS_HEAD X_HEAD
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder #else
if ( (stepper.current_block->active_extruder == 0 && X_HOME_DIR < 0) #define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
|| (stepper.current_block->active_extruder != 0 && X2_HOME_DIR < 0) #define X_AXIS_HEAD X_AXIS
)
#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 !=
#endif #endif
#if CORE_IS_XY || CORE_IS_YZ #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 1st axis (X or Y)
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z) * 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] #if ENABLED(COREYX) || ENABLED(COREYZ)
|| ( stepper.current_block->steps[CORE_AXIS_1] > 0 #define Y_CMP ==
&& stepper.motor_direction(CORE_AXIS_1) CORE_YZ_CMP stepper.motor_direction(CORE_AXIS_2)
)
) {
if (stepper.motor_direction(Y_HEAD))
#else #else
if (stepper.current_block->steps[Y_AXIS] > 0) #define Y_CMP !=
if (stepper.motor_direction(Y_AXIS)) // -direction
#endif #endif
{ // -direction #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
#if HAS_Y_MIN #define Y_AXIS_HEAD Y_HEAD
UPDATE_ENDSTOP(Y, MIN); #else
#endif #define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
} #define Y_AXIS_HEAD Y_AXIS
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 !=
#endif #endif
#if CORE_IS_XZ || CORE_IS_YZ #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 1st axis (X or Y, already handled above)
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z) * 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] #if ENABLED(COREZX) || ENABLED(COREZY)
|| ( stepper.current_block->steps[CORE_AXIS_1] > 0 #define Z_CMP ==
&& stepper.motor_direction(CORE_AXIS_1) CORE_YZ_CMP stepper.motor_direction(CORE_AXIS_2)
)
) {
if (stepper.motor_direction(Z_HEAD))
#else #else
if (stepper.current_block->steps[Z_AXIS] > 0) #define Z_CMP !=
if (stepper.motor_direction(Z_AXIS))
#endif #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 HAS_Z_MIN
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
@ -453,9 +447,7 @@ void Endstops::update() {
#endif // !Z_MIN_PROBE_PIN... #endif // !Z_MIN_PROBE_PIN...
#endif // Z_MAX_PIN #endif // Z_MAX_PIN
} }
#if CORE_IS_XZ || CORE_IS_YZ
} }
#endif
old_endstop_bits = current_endstop_bits; old_endstop_bits = current_endstop_bits;