Add TMC2130 sensorless probing

This commit is contained in:
Thomas Moore
2018-09-09 15:59:12 -04:00
committed by Scott Lahteine
parent 7d5c336c56
commit 3286325044
16 changed files with 149 additions and 85 deletions

View File

@ -920,10 +920,10 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(tmc_hybrid_threshold);
//
// TMC2130 Sensorless homing threshold
// TMC2130 StallGuard threshold
//
int16_t tmc_sgt[XYZ] = {
#if ENABLED(SENSORLESS_HOMING)
#if USE_SENSORLESS
#if X_SENSORLESS
stepperX.sgt(),
#else
@ -1530,16 +1530,16 @@ void MarlinSettings::postprocess() {
#endif
/*
* TMC2130 Sensorless homing threshold.
* TMC2130 StallGuard threshold.
* X and X2 use the same value
* Y and Y2 use the same value
* Z, Z2 and Z3 use the same value
*/
int16_t tmc_sgt[XYZ];
EEPROM_READ(tmc_sgt);
#if ENABLED(SENSORLESS_HOMING)
#if USE_SENSORLESS
if (!validating) {
#ifdef X_HOMING_SENSITIVITY
#ifdef X_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(X)
stepperX.sgt(tmc_sgt[0]);
#endif
@ -1547,7 +1547,7 @@ void MarlinSettings::postprocess() {
stepperX2.sgt(tmc_sgt[0]);
#endif
#endif
#ifdef Y_HOMING_SENSITIVITY
#ifdef Y_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(Y)
stepperY.sgt(tmc_sgt[1]);
#endif
@ -1555,7 +1555,7 @@ void MarlinSettings::postprocess() {
stepperY2.sgt(tmc_sgt[1]);
#endif
#endif
#ifdef Z_HOMING_SENSITIVITY
#ifdef Z_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(Z)
stepperZ.sgt(tmc_sgt[2]);
#endif
@ -2120,7 +2120,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#if ENABLED(HYBRID_THRESHOLD)
void say_M913(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M913"); }
#endif
#if ENABLED(SENSORLESS_HOMING)
#if USE_SENSORLESS
void say_M914(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M914"); }
#endif
#endif
@ -2824,12 +2824,12 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HYBRID_THRESHOLD
/**
* TMC2130 Sensorless homing thresholds
* TMC2130 Sensorless homing thresholds
*/
#if ENABLED(SENSORLESS_HOMING)
#if USE_SENSORLESS
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM_P(port, "Sensorless homing threshold:");
SERIAL_ECHOLNPGM_P(port, "TMC2130 StallGuard threshold:");
}
CONFIG_ECHO_START;
#if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
@ -2846,10 +2846,10 @@ void MarlinSettings::reset(PORTARG_SOLO) {
SERIAL_EOL_P(port);
#endif
#define HAS_X2_SENSORLESS (defined(X_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(X2))
#define HAS_Y2_SENSORLESS (defined(Y_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y2))
#define HAS_Z2_SENSORLESS (defined(Z_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z2))
#define HAS_Z3_SENSORLESS (defined(Z_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z3))
#define HAS_X2_SENSORLESS (defined(X_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(X2))
#define HAS_Y2_SENSORLESS (defined(Y_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y2))
#define HAS_Z2_SENSORLESS (defined(Z_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z2))
#define HAS_Z3_SENSORLESS (defined(Z_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z3))
#if HAS_X2_SENSORLESS || HAS_Y2_SENSORLESS || HAS_Z2_SENSORLESS
say_M914(PORTVAR_SOLO);
SERIAL_ECHOPGM_P(port, " I1");
@ -2871,7 +2871,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
SERIAL_ECHOLNPAIR_P(port, " Z", stepperZ3.sgt());
#endif
#endif // SENSORLESS_HOMING
#endif // USE_SENSORLESS
#endif // HAS_TRINAMIC

View File

@ -981,31 +981,31 @@ inline float get_homing_bump_feedrate(const AxisEnum axis) {
default: break;
#if X_SENSORLESS
case X_AXIS:
tmc_sensorless_homing(stepperX, enable);
tmc_stallguard(stepperX, enable);
#if CORE_IS_XY && Y_SENSORLESS
tmc_sensorless_homing(stepperY, enable);
tmc_stallguard(stepperY, enable);
#elif CORE_IS_XZ && Z_SENSORLESS
tmc_sensorless_homing(stepperZ, enable);
tmc_stallguard(stepperZ, enable);
#endif
break;
#endif
#if Y_SENSORLESS
case Y_AXIS:
tmc_sensorless_homing(stepperY, enable);
tmc_stallguard(stepperY, enable);
#if CORE_IS_XY && X_SENSORLESS
tmc_sensorless_homing(stepperX, enable);
tmc_stallguard(stepperX, enable);
#elif CORE_IS_YZ && Z_SENSORLESS
tmc_sensorless_homing(stepperZ, enable);
tmc_stallguard(stepperZ, enable);
#endif
break;
#endif
#if Z_SENSORLESS
case Z_AXIS:
tmc_sensorless_homing(stepperZ, enable);
tmc_stallguard(stepperZ, enable);
#if CORE_IS_XZ && X_SENSORLESS
tmc_sensorless_homing(stepperX, enable);
tmc_stallguard(stepperX, enable);
#elif CORE_IS_YZ && Y_SENSORLESS
tmc_sensorless_homing(stepperY, enable);
tmc_stallguard(stepperY, enable);
#endif
break;
#endif

View File

@ -58,6 +58,11 @@ float zprobe_zoffset; // Initialized by settings.load()
#include "../module/servo.h"
#endif
#if ENABLED(SENSORLESS_PROBING)
#include "stepper.h"
#include "../feature/tmc_util.h"
#endif
#if ENABLED(Z_PROBE_SLED)
#ifndef SLED_DOCKING_OFFSET
@ -527,31 +532,58 @@ static bool do_probe_move(const float z, const float fr_mm_s) {
if (set_bltouch_deployed(true)) return true;
#endif
// Disable stealthChop if used. Enable diag1 pin on driver.
#if ENABLED(SENSORLESS_PROBING)
#if ENABLED(DELTA)
tmc_stallguard(stepperX);
tmc_stallguard(stepperY);
#endif
tmc_stallguard(stepperZ);
#endif
#if QUIET_PROBING
probing_pause(true);
#endif
endstops.enable(true);
// Move down until probe triggered
do_blocking_move_to_z(z, fr_mm_s);
// Check to see if the probe was triggered
const bool probe_triggered = TEST(endstops.trigger_state(),
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
Z_MIN
const bool probe_triggered =
#if ENABLED(DELTA) && ENABLED(SENSORLESS_PROBING)
endstops.trigger_state() & (_BV(X_MIN) | _BV(Y_MIN) | _BV(Z_MIN))
#else
Z_MIN_PROBE
TEST(endstops.trigger_state(),
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
Z_MIN
#else
Z_MIN_PROBE
#endif
)
#endif
);
;
#if QUIET_PROBING
probing_pause(false);
#endif
// Re-enable stealthChop if used. Disable diag1 pin on driver.
#if ENABLED(SENSORLESS_PROBING)
#if ENABLED(DELTA)
tmc_stallguard(stepperX, false);
tmc_stallguard(stepperY, false);
#endif
tmc_stallguard(stepperZ, false);
#endif
// Retract BLTouch immediately after a probe if it was triggered
#if ENABLED(BLTOUCH)
if (probe_triggered && set_bltouch_deployed(false)) return true;
#endif
// Clear endstop flags
endstops.hit_on_purpose();
// Get Z where the steppers were interrupted
@ -606,13 +638,11 @@ static float run_z_probe() {
// move up to make clearance for the probe
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_MULTI_PROBE, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
#else
#elif Z_PROBE_SPEED_FAST != Z_PROBE_SPEED_SLOW
// If the nozzle is well over the travel height then
// move down quickly before doing the slow probe
float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0;
if (zprobe_zoffset < 0) z -= zprobe_zoffset;
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (zprobe_zoffset < 0 ? -zprobe_zoffset : 0);
if (current_position[Z_AXIS] > z) {
// If we don't make it to the z position (i.e. the probe triggered), move up to make clearance for the probe
if (!do_probe_move(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST)))

View File

@ -273,33 +273,33 @@
{ constexpr uint8_t extruder = 5; _TMC2130_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
#endif
#if ENABLED(SENSORLESS_HOMING)
#define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_HOMING_SENSITIVITY);
#if USE_SENSORLESS
#define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_STALL_SENSITIVITY);
#if X_SENSORLESS
#if AXIS_DRIVER_TYPE(X, TMC2130)
stepperX.sgt(X_HOMING_SENSITIVITY);
stepperX.sgt(X_STALL_SENSITIVITY);
#endif
#if AXIS_DRIVER_TYPE(X2, TMC2130)
stepperX2.sgt(X_HOMING_SENSITIVITY);
stepperX2.sgt(X_STALL_SENSITIVITY);
#endif
#endif
#if Y_SENSORLESS
#if AXIS_DRIVER_TYPE(Y, TMC2130)
stepperY.sgt(Y_HOMING_SENSITIVITY);
stepperY.sgt(Y_STALL_SENSITIVITY);
#endif
#if AXIS_DRIVER_TYPE(Y2, TMC2130)
stepperY2.sgt(Y_HOMING_SENSITIVITY);
stepperY2.sgt(Y_STALL_SENSITIVITY);
#endif
#endif
#if Z_SENSORLESS
#if AXIS_DRIVER_TYPE(Z, TMC2130)
stepperZ.sgt(Z_HOMING_SENSITIVITY);
stepperZ.sgt(Z_STALL_SENSITIVITY);
#endif
#if AXIS_DRIVER_TYPE(Z2, TMC2130)
stepperZ2.sgt(Z_HOMING_SENSITIVITY);
stepperZ2.sgt(Z_STALL_SENSITIVITY);
#endif
#if ENABLED(Z3_IS_TMC2130)
stepperZ3.sgt(Z_HOMING_SENSITIVITY);
stepperZ3.sgt(Z_STALL_SENSITIVITY);
#endif
#endif
#endif