Cleanup for dual endstops homing

This commit is contained in:
Scott Lahteine 2018-06-02 20:39:00 -05:00
parent 61181b7f24
commit ad8d3150aa
4 changed files with 58 additions and 62 deletions

View file

@ -396,7 +396,6 @@ void Endstops::M119() {
// Check endstops - Could be called from ISR! // Check endstops - Could be called from ISR!
void Endstops::update() { void Endstops::update() {
#define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
// UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX))) #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
// COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
@ -590,7 +589,7 @@ void Endstops::update() {
if (dual_hit) { \ if (dual_hit) { \
_ENDSTOP_HIT(AXIS1, MINMAX); \ _ENDSTOP_HIT(AXIS1, MINMAX); \
/* if not performing home or if both endstops were trigged during homing... */ \ /* if not performing home or if both endstops were trigged during homing... */ \
if (!stepper.performing_homing || dual_hit == 0x3) \ if (!stepper.homing_dual_axis || dual_hit == 0x3) \
planner.endstop_triggered(_AXIS(AXIS1)); \ planner.endstop_triggered(_AXIS(AXIS1)); \
} \ } \
}while(0) }while(0)

View file

@ -1052,9 +1052,14 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]); SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
SERIAL_ECHOPAIR(", ", distance); SERIAL_ECHOPAIR(", ", distance);
SERIAL_ECHOPAIR(", ", fr_mm_s); SERIAL_ECHOPGM(", ");
SERIAL_ECHOPAIR(" [", fr_mm_s ? fr_mm_s : homing_feedrate(axis)); if (fr_mm_s)
SERIAL_ECHOLNPGM("])"); SERIAL_ECHO(fr_mm_s);
else {
SERIAL_ECHOPAIR("[", homing_feedrate(axis));
SERIAL_CHAR(']');
}
SERIAL_ECHOLNPGM(")");
} }
#endif #endif
@ -1262,11 +1267,12 @@ void homeaxis(const AxisEnum axis) {
} }
#endif #endif
const int axis_home_dir = const int axis_home_dir = (
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
(axis == X_AXIS) ? x_home_dir(active_extruder) : axis == X_AXIS ? x_home_dir(active_extruder) :
#endif #endif
home_dir(axis); home_dir(axis)
);
// Homing Z towards the bed? Deploy the Z probe or endstop. // Homing Z towards the bed? Deploy the Z probe or endstop.
#if HOMING_Z_WITH_PROBE #if HOMING_Z_WITH_PROBE
@ -1274,14 +1280,20 @@ void homeaxis(const AxisEnum axis) {
#endif #endif
// Set flags for X, Y, Z motor locking // Set flags for X, Y, Z motor locking
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
switch (axis) {
#if ENABLED(X_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS)
if (axis == X_AXIS) stepper.set_homing_flag_x(true); case X_AXIS:
#endif #endif
#if ENABLED(Y_DUAL_ENDSTOPS) #if ENABLED(Y_DUAL_ENDSTOPS)
if (axis == Y_AXIS) stepper.set_homing_flag_y(true); case Y_AXIS:
#endif #endif
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) stepper.set_homing_flag_z(true); case Z_AXIS:
#endif
stepper.set_homing_dual_axis(true);
default: break;
}
#endif #endif
// Fast move towards endstop until triggered // Fast move towards endstop until triggered
@ -1321,37 +1333,32 @@ void homeaxis(const AxisEnum axis) {
const bool pos_dir = axis_home_dir > 0; const bool pos_dir = axis_home_dir > 0;
#if ENABLED(X_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS)
if (axis == X_AXIS) { if (axis == X_AXIS) {
const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0); const float adj = ABS(endstops.x_endstop_adj);
float adj = ABS(endstops.x_endstop_adj); if (pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
if (pos_dir) adj = -adj; do_homing_move(axis, pos_dir ? adj : -adj);
if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true); stepper.set_x_lock(false);
do_homing_move(axis, adj); stepper.set_x2_lock(false);
if (lock_x1) stepper.set_x_lock(false); else stepper.set_x2_lock(false);
stepper.set_homing_flag_x(false);
} }
#endif #endif
#if ENABLED(Y_DUAL_ENDSTOPS) #if ENABLED(Y_DUAL_ENDSTOPS)
if (axis == Y_AXIS) { if (axis == Y_AXIS) {
const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0); const float adj = ABS(endstops.y_endstop_adj);
float adj = ABS(endstops.y_endstop_adj); if (pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
if (pos_dir) adj = -adj; do_homing_move(axis, pos_dir ? adj : -adj);
if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true); stepper.set_y_lock(false);
do_homing_move(axis, adj); stepper.set_y2_lock(false);
if (lock_y1) stepper.set_y_lock(false); else stepper.set_y2_lock(false);
stepper.set_homing_flag_y(false);
} }
#endif #endif
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) { if (axis == Z_AXIS) {
const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0); const float adj = ABS(endstops.z_endstop_adj);
float adj = ABS(endstops.z_endstop_adj); if (pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
if (pos_dir) adj = -adj; do_homing_move(axis, pos_dir ? adj : -adj);
if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true); stepper.set_z_lock(false);
do_homing_move(axis, adj); stepper.set_z2_lock(false);
if (lock_z1) stepper.set_z_lock(false); else stepper.set_z2_lock(false);
stepper.set_homing_flag_z(false);
} }
#endif #endif
stepper.set_homing_dual_axis(false);
#endif #endif
#if IS_SCARA #if IS_SCARA
@ -1393,10 +1400,9 @@ void homeaxis(const AxisEnum axis) {
if (axis == Z_AXIS && STOW_PROBE()) return; if (axis == Z_AXIS && STOW_PROBE()) return;
#endif #endif
// Clear z_lift if homing the Z axis // Clear retracted status if homing the Z axis
#if ENABLED(FWRETRACT) #if ENABLED(FWRETRACT)
if (axis == Z_AXIS) if (axis == Z_AXIS) fwretract.hop_amount = 0.0;
fwretract.hop_amount = 0.0;
#endif #endif
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
@ -1470,7 +1476,7 @@ void homeaxis(const AxisEnum axis) {
#endif #endif
#if ENABLED(DELTA) #if ENABLED(DELTA)
switch(axis) { switch (axis) {
#if HAS_SOFTWARE_ENDSTOPS #if HAS_SOFTWARE_ENDSTOPS
case X_AXIS: case X_AXIS:
case Y_AXIS: case Y_AXIS:

View file

@ -87,7 +87,7 @@ Stepper stepper; // Singleton
block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
bool Stepper::performing_homing = false; bool Stepper::homing_dual_axis = false;
#endif #endif
#if HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_PWM
@ -166,7 +166,7 @@ bool Stepper::all_steps_done = false;
uint32_t Stepper::acceleration_time, Stepper::deceleration_time; uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 }; volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 };
volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; int8_t Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
#if ENABLED(MIXING_EXTRUDER) #if ENABLED(MIXING_EXTRUDER)
int32_t Stepper::counter_m[MIXING_STEPPERS]; int32_t Stepper::counter_m[MIXING_STEPPERS];
@ -183,7 +183,7 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ];
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
#define DUAL_ENDSTOP_APPLY_STEP(A,V) \ #define DUAL_ENDSTOP_APPLY_STEP(A,V) \
if (performing_homing) { \ if (homing_dual_axis) { \
if (A##_HOME_DIR < 0) { \ if (A##_HOME_DIR < 0) { \
if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \ if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \ if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
@ -1144,7 +1144,6 @@ void Stepper::set_directions() {
HAL_STEP_TIMER_ISR { HAL_STEP_TIMER_ISR {
HAL_timer_isr_prologue(STEP_TIMER_NUM); HAL_timer_isr_prologue(STEP_TIMER_NUM);
// Call the ISR
Stepper::isr(); Stepper::isr();
HAL_timer_isr_epilogue(STEP_TIMER_NUM); HAL_timer_isr_epilogue(STEP_TIMER_NUM);
@ -1175,7 +1174,7 @@ void Stepper::isr() {
// We need this variable here to be able to use it in the following loop // We need this variable here to be able to use it in the following loop
hal_timer_t min_ticks; hal_timer_t min_ticks;
do { do {
// Enable ISRs so the USART processing latency is reduced // Enable ISRs to reduce USART processing latency
ENABLE_ISRS(); ENABLE_ISRS();
// Run main stepping pulse phase ISR if we have to // Run main stepping pulse phase ISR if we have to
@ -1193,11 +1192,9 @@ void Stepper::isr() {
uint32_t interval = uint32_t interval =
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
// Select the closest interval in time MIN(nextAdvanceISR, nextMainISR) // Nearest time interval
MIN(nextAdvanceISR, nextMainISR)
#else #else
// The interval is just the remaining time to the stepper ISR nextMainISR // Remaining stepper ISR time
nextMainISR
#endif #endif
; ;

View file

@ -63,7 +63,7 @@ class Stepper {
static block_t* current_block; // A pointer to the block currently being traced static block_t* current_block; // A pointer to the block currently being traced
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
static bool performing_homing; static bool homing_dual_axis;
#endif #endif
#if HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_PWM
@ -143,7 +143,7 @@ class Stepper {
// //
// Current direction of stepper motors (+1 or -1) // Current direction of stepper motors (+1 or -1)
// //
static volatile signed char count_direction[NUM_AXIS]; static int8_t count_direction[NUM_AXIS];
// //
// Mixing extruder mix counters // Mixing extruder mix counters
@ -220,18 +220,18 @@ class Stepper {
static void microstep_readings(); static void microstep_readings();
#endif #endif
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_dual_axis(const bool state) { homing_dual_axis = state; }
#endif
#if ENABLED(X_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_x(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; } FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; }
FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; } FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; }
#endif #endif
#if ENABLED(Y_DUAL_ENDSTOPS) #if ENABLED(Y_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_y(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; } FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; }
FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; } FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; }
#endif #endif
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_z(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; } FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; }
FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; } FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; }
#endif #endif
@ -247,15 +247,9 @@ class Stepper {
// Set the current position in steps // Set the current position in steps
inline static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) { inline static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
planner.synchronize(); planner.synchronize();
// Disable stepper interrupts, to ensure atomic setting of all the position variables
const bool was_enabled = STEPPER_ISR_ENABLED(); const bool was_enabled = STEPPER_ISR_ENABLED();
if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT(); if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
// Set position
_set_position(a, b, c, e); _set_position(a, b, c, e);
// Reenable Stepper ISR
if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT(); if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
} }