TMC SPI Endstops and Improved Sensorless Homing (#14044)
This commit is contained in:
committed by
Scott Lahteine
parent
d493cafc4a
commit
d4974ea719
@ -227,10 +227,11 @@ void home_delta() {
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
sensorless_t stealth_states { false };
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
sensorless_t stealth_states {
|
||||
tmc_enable_stallguard(stepperX),
|
||||
tmc_enable_stallguard(stepperY),
|
||||
tmc_enable_stallguard(stepperZ)
|
||||
};
|
||||
#endif
|
||||
|
||||
// Move all carriages together linearly until an endstop is hit.
|
||||
|
@ -76,6 +76,13 @@ Endstops::esbits_t Endstops::live_state = 0;
|
||||
float Endstops::z3_endstop_adj;
|
||||
#endif
|
||||
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
Endstops::tmc_spi_homing_t Endstops::tmc_spi_homing; // = 0
|
||||
#endif
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
millis_t sg_guard_period; // = 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Class and Instance Methods
|
||||
*/
|
||||
@ -699,7 +706,7 @@ void Endstops::update() {
|
||||
// Now, we must signal, after validation, if an endstop limit is pressed or not
|
||||
if (stepper.axis_is_moving(X_AXIS)) {
|
||||
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
|
||||
#if HAS_X_MIN
|
||||
#if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
|
||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||
PROCESS_DUAL_ENDSTOP(X, X2, MIN);
|
||||
#else
|
||||
@ -708,7 +715,7 @@ void Endstops::update() {
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if HAS_X_MAX
|
||||
#if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
|
||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||
PROCESS_DUAL_ENDSTOP(X, X2, MAX);
|
||||
#else
|
||||
@ -720,7 +727,7 @@ void Endstops::update() {
|
||||
|
||||
if (stepper.axis_is_moving(Y_AXIS)) {
|
||||
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
||||
#if HAS_Y_MIN
|
||||
#if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
|
||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||
PROCESS_DUAL_ENDSTOP(Y, Y2, MIN);
|
||||
#else
|
||||
@ -729,7 +736,7 @@ void Endstops::update() {
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if HAS_Y_MAX
|
||||
#if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
|
||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||
PROCESS_DUAL_ENDSTOP(Y, Y2, MAX);
|
||||
#else
|
||||
@ -741,7 +748,7 @@ void Endstops::update() {
|
||||
|
||||
if (stepper.axis_is_moving(Z_AXIS)) {
|
||||
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
|
||||
#if HAS_Z_MIN
|
||||
#if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
|
||||
#if ENABLED(Z_TRIPLE_ENDSTOPS)
|
||||
PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MIN);
|
||||
#elif ENABLED(Z_DUAL_ENDSTOPS)
|
||||
@ -763,7 +770,7 @@ void Endstops::update() {
|
||||
#endif
|
||||
}
|
||||
else { // Z +direction. Gantry up, bed down.
|
||||
#if HAS_Z_MAX
|
||||
#if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
|
||||
#if ENABLED(Z_TRIPLE_ENDSTOPS)
|
||||
PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MAX);
|
||||
#elif ENABLED(Z_DUAL_ENDSTOPS)
|
||||
@ -778,6 +785,49 @@ void Endstops::update() {
|
||||
}
|
||||
} // Endstops::update()
|
||||
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
|
||||
#define X_STOP (X_HOME_DIR < 0 ? X_MIN : X_MAX)
|
||||
#define Y_STOP (Y_HOME_DIR < 0 ? Y_MIN : Y_MAX)
|
||||
#define Z_STOP (Z_HOME_DIR < 0 ? Z_MIN : Z_MAX)
|
||||
|
||||
bool Endstops::tmc_spi_homing_check() {
|
||||
bool hit = false;
|
||||
#if X_SPI_SENSORLESS
|
||||
if (tmc_spi_homing.x && stepperX.test_stall_status()) {
|
||||
SBI(live_state, X_STOP);
|
||||
hit = true;
|
||||
}
|
||||
#endif
|
||||
#if Y_SPI_SENSORLESS
|
||||
if (tmc_spi_homing.y && stepperY.test_stall_status()) {
|
||||
SBI(live_state, Y_STOP);
|
||||
hit = true;
|
||||
}
|
||||
#endif
|
||||
#if Z_SPI_SENSORLESS
|
||||
if (tmc_spi_homing.z && stepperZ.test_stall_status()) {
|
||||
SBI(live_state, Z_STOP);
|
||||
hit = true;
|
||||
}
|
||||
#endif
|
||||
return hit;
|
||||
}
|
||||
|
||||
void Endstops::clear_endstop_state() {
|
||||
#if X_SPI_SENSORLESS
|
||||
CBI(live_state, X_STOP);
|
||||
#endif
|
||||
#if Y_SPI_SENSORLESS
|
||||
CBI(live_state, Y_STOP);
|
||||
#endif
|
||||
#if Z_SPI_SENSORLESS
|
||||
CBI(live_state, Z_STOP);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // SPI_ENDSTOPS
|
||||
|
||||
#if ENABLED(PINS_DEBUGGING)
|
||||
|
||||
bool Endstops::monitor_flag = false;
|
||||
|
@ -161,6 +161,18 @@ class Endstops {
|
||||
static void monitor();
|
||||
static void run_monitor();
|
||||
#endif
|
||||
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
typedef struct {
|
||||
union {
|
||||
bool any;
|
||||
struct { bool x:1, y:1, z:1; };
|
||||
};
|
||||
} tmc_spi_homing_t;
|
||||
static tmc_spi_homing_t tmc_spi_homing;
|
||||
static void clear_endstop_state();
|
||||
static bool tmc_spi_homing_check();
|
||||
#endif
|
||||
};
|
||||
|
||||
extern Endstops endstops;
|
||||
|
@ -1121,6 +1121,26 @@ float get_homing_bump_feedrate(const AxisEnum axis) {
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
switch (axis) {
|
||||
#if X_SPI_SENSORLESS
|
||||
case X_AXIS: endstops.tmc_spi_homing.x = true; break;
|
||||
#endif
|
||||
#if Y_SPI_SENSORLESS
|
||||
case Y_AXIS: endstops.tmc_spi_homing.y = true; break;
|
||||
#endif
|
||||
#if Z_SPI_SENSORLESS
|
||||
case Z_AXIS: endstops.tmc_spi_homing.z = true; break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
sg_guard_period = millis() + default_sg_guard_duration;
|
||||
#endif
|
||||
|
||||
return stealth_states;
|
||||
}
|
||||
|
||||
@ -1170,6 +1190,21 @@ float get_homing_bump_feedrate(const AxisEnum axis) {
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
switch (axis) {
|
||||
#if X_SPI_SENSORLESS
|
||||
case X_AXIS: endstops.tmc_spi_homing.x = false; break;
|
||||
#endif
|
||||
#if Y_SPI_SENSORLESS
|
||||
case Y_AXIS: endstops.tmc_spi_homing.y = false; break;
|
||||
#endif
|
||||
#if Z_SPI_SENSORLESS
|
||||
case Z_AXIS: endstops.tmc_spi_homing.z = false; break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // SENSORLESS_HOMING
|
||||
@ -1383,9 +1418,24 @@ void homeaxis(const AxisEnum axis) {
|
||||
// Only Z homing (with probe) is permitted
|
||||
if (axis != Z_AXIS) { BUZZ(100, 880); return; }
|
||||
#else
|
||||
#define CAN_HOME(A) \
|
||||
#define _CAN_HOME(A) \
|
||||
(axis == _AXIS(A) && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0)))
|
||||
if (!CAN_HOME(X) && !CAN_HOME(Y) && !CAN_HOME(Z)) return;
|
||||
#if X_SPI_SENSORLESS
|
||||
#define CAN_HOME_X true
|
||||
#else
|
||||
#define CAN_HOME_X _CAN_HOME(X)
|
||||
#endif
|
||||
#if Y_SPI_SENSORLESS
|
||||
#define CAN_HOME_Y true
|
||||
#else
|
||||
#define CAN_HOME_Y _CAN_HOME(Y)
|
||||
#endif
|
||||
#if Z_SPI_SENSORLESS
|
||||
#define CAN_HOME_Z true
|
||||
#else
|
||||
#define CAN_HOME_Z _CAN_HOME(Z)
|
||||
#endif
|
||||
if (!CAN_HOME_X && !CAN_HOME_Y && !CAN_HOME_Z) return;
|
||||
#endif
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> homeaxis(", axis_codes[axis], ")");
|
||||
|
Reference in New Issue
Block a user