Skip to content

Commit

Permalink
Multi-stepper homing / probing current
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 1, 2023
1 parent df8f1f0 commit a7245fd
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 104 deletions.
58 changes: 29 additions & 29 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2855,10 +2855,10 @@
#endif

#if AXIS_IS_TMC_CONFIG(X2)
#define X2_CURRENT 800
#define X2_CURRENT X_CURRENT
#define X2_CURRENT_HOME X2_CURRENT
#define X2_MICROSTEPS X_MICROSTEPS
#define X2_RSENSE 0.11
#define X2_MICROSTEPS X_MICROSTEPS
#define X2_RSENSE X_RSENSE
#define X2_CHAIN_POS -1
//#define X2_INTERPOLATE true
//#define X2_HOLD_MULTIPLIER 0.5
Expand All @@ -2875,10 +2875,10 @@
#endif

#if AXIS_IS_TMC_CONFIG(Y2)
#define Y2_CURRENT 800
#define Y2_CURRENT Y_CURRENT
#define Y2_CURRENT_HOME Y2_CURRENT
#define Y2_MICROSTEPS Y_MICROSTEPS
#define Y2_RSENSE 0.11
#define Y2_MICROSTEPS Y_MICROSTEPS
#define Y2_RSENSE Y_RSENSE
#define Y2_CHAIN_POS -1
//#define Y2_INTERPOLATE true
//#define Y2_HOLD_MULTIPLIER 0.5
Expand All @@ -2895,30 +2895,30 @@
#endif

#if AXIS_IS_TMC_CONFIG(Z2)
#define Z2_CURRENT 800
#define Z2_CURRENT Z_CURRENT
#define Z2_CURRENT_HOME Z2_CURRENT
#define Z2_MICROSTEPS Z_MICROSTEPS
#define Z2_RSENSE 0.11
#define Z2_MICROSTEPS Z_MICROSTEPS
#define Z2_RSENSE Z_RSENSE
#define Z2_CHAIN_POS -1
//#define Z2_INTERPOLATE true
//#define Z2_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(Z3)
#define Z3_CURRENT 800
#define Z3_CURRENT Z_CURRENT
#define Z3_CURRENT_HOME Z3_CURRENT
#define Z3_MICROSTEPS Z_MICROSTEPS
#define Z3_RSENSE 0.11
#define Z3_MICROSTEPS Z_MICROSTEPS
#define Z3_RSENSE Z_RSENSE
#define Z3_CHAIN_POS -1
//#define Z3_INTERPOLATE true
//#define Z3_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(Z4)
#define Z4_CURRENT 800
#define Z4_CURRENT Z_CURRENT
#define Z4_CURRENT_HOME Z4_CURRENT
#define Z4_MICROSTEPS Z_MICROSTEPS
#define Z4_RSENSE 0.11
#define Z4_MICROSTEPS Z_MICROSTEPS
#define Z4_RSENSE Z_RSENSE
#define Z4_CHAIN_POS -1
//#define Z4_INTERPOLATE true
//#define Z4_HOLD_MULTIPLIER 0.5
Expand Down Expand Up @@ -2994,63 +2994,63 @@
#endif

#if AXIS_IS_TMC_CONFIG(E1)
#define E1_CURRENT 800
#define E1_CURRENT E0_CURRENT
#define E1_MICROSTEPS E0_MICROSTEPS
#define E1_RSENSE 0.11
#define E1_RSENSE E0_RSENSE
#define E1_CHAIN_POS -1
//#define E1_INTERPOLATE true
//#define E1_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E2)
#define E2_CURRENT 800
#define E2_CURRENT E0_CURRENT
#define E2_MICROSTEPS E0_MICROSTEPS
#define E2_RSENSE 0.11
#define E2_RSENSE E0_RSENSE
#define E2_CHAIN_POS -1
//#define E2_INTERPOLATE true
//#define E2_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E3)
#define E3_CURRENT 800
#define E3_CURRENT E0_CURRENT
#define E3_MICROSTEPS E0_MICROSTEPS
#define E3_RSENSE 0.11
#define E3_RSENSE E0_RSENSE
#define E3_CHAIN_POS -1
//#define E3_INTERPOLATE true
//#define E3_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E4)
#define E4_CURRENT 800
#define E4_CURRENT E0_CURRENT
#define E4_MICROSTEPS E0_MICROSTEPS
#define E4_RSENSE 0.11
#define E4_RSENSE E0_RSENSE
#define E4_CHAIN_POS -1
//#define E4_INTERPOLATE true
//#define E4_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E5)
#define E5_CURRENT 800
#define E5_CURRENT E0_CURRENT
#define E5_MICROSTEPS E0_MICROSTEPS
#define E5_RSENSE 0.11
#define E5_RSENSE E0_RSENSE
#define E5_CHAIN_POS -1
//#define E5_INTERPOLATE true
//#define E5_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E6)
#define E6_CURRENT 800
#define E6_CURRENT E0_CURRENT
#define E6_MICROSTEPS E0_MICROSTEPS
#define E6_RSENSE 0.11
#define E6_RSENSE E0_RSENSE
#define E6_CHAIN_POS -1
//#define E6_INTERPOLATE true
//#define E6_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC_CONFIG(E7)
#define E7_CURRENT 800
#define E7_CURRENT E0_CURRENT
#define E7_MICROSTEPS E0_MICROSTEPS
#define E7_RSENSE 0.11
#define E7_RSENSE E0_RSENSE
#define E7_CHAIN_POS -1
//#define E7_INTERPOLATE true
//#define E7_HOLD_MULTIPLIER 0.5
Expand Down
90 changes: 50 additions & 40 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,69 +265,70 @@ void GcodeSuite::G28() {
// Count this command as movement / activity
reset_stepper_timeout();

#define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2) || (ENABLED(DELTA) && HAS_CURRENT_HOME(Z)) || HAS_CURRENT_HOME(I) || HAS_CURRENT_HOME(J) || HAS_CURRENT_HOME(K) || HAS_CURRENT_HOME(U) || HAS_CURRENT_HOME(V) || HAS_CURRENT_HOME(W)
#define _OR_HAS_CURR_HOME(N) HAS_CURRENT_HOME(N) ||
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Z) \
|| HAS_CURRENT_HOME(I) || HAS_CURRENT_HOME(J) || HAS_CURRENT_HOME(K) \
|| HAS_CURRENT_HOME(U) || HAS_CURRENT_HOME(V) || HAS_CURRENT_HOME(W) \
|| HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y2) || HAS_CURRENT_HOME(Z2) || HAS_CURRENT_HOME(Z3) || HAS_CURRENT_HOME(Z4)
#define HAS_HOMING_CURRENT 1
#endif

#if HAS_HOMING_CURRENT
auto debug_current = [](FSTR_P const s, const int16_t a, const int16_t b) {
DEBUG_ECHOF(s); DEBUG_ECHOLNPGM(" current: ", a, " -> ", b);
};

#if ENABLED(DEBUG_LEVELING_FEATURE)
auto debug_current = [](FSTR_P const s, const int16_t a, const int16_t b) {
if (DEBUGGING(LEVELING)) { DEBUG_ECHOF(s); DEBUG_ECHOLNPGM(" current: ", a, " -> ", b); }
};
#else
#define debug_current(...)
#endif

#define _SAVE_SET_CURRENT(A) \
const int16_t tmc_save_current_##A = stepper##A.getMilliamps(); \
stepper##A.rms_current(A##_CURRENT_HOME); \
debug_current(F(STR_##A), tmc_save_current_##A, A##_CURRENT_HOME)

#if HAS_CURRENT_HOME(X)
const int16_t tmc_save_current_X = stepperX.getMilliamps();
stepperX.rms_current(X_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_X), tmc_save_current_X, X_CURRENT_HOME);
_SAVE_SET_CURRENT(X);
#endif
#if HAS_CURRENT_HOME(X2)
const int16_t tmc_save_current_X2 = stepperX2.getMilliamps();
stepperX2.rms_current(X2_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_X2), tmc_save_current_X2, X2_CURRENT_HOME);
_SAVE_SET_CURRENT(X2);
#endif
#if HAS_CURRENT_HOME(Y)
const int16_t tmc_save_current_Y = stepperY.getMilliamps();
stepperY.rms_current(Y_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_Y), tmc_save_current_Y, Y_CURRENT_HOME);
_SAVE_SET_CURRENT(Y);
#endif
#if HAS_CURRENT_HOME(Y2)
const int16_t tmc_save_current_Y2 = stepperY2.getMilliamps();
stepperY2.rms_current(Y2_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_Y2), tmc_save_current_Y2, Y2_CURRENT_HOME);
_SAVE_SET_CURRENT(Y2);
#endif
#if HAS_CURRENT_HOME(Z) && ENABLED(DELTA)
const int16_t tmc_save_current_Z = stepperZ.getMilliamps();
stepperZ.rms_current(Z_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_Z), tmc_save_current_Z, Z_CURRENT_HOME);
#if HAS_CURRENT_HOME(Z)
_SAVE_SET_CURRENT(Z);
#endif
#if HAS_CURRENT_HOME(Z2)
_SAVE_SET_CURRENT(Z2);
#endif
#if HAS_CURRENT_HOME(Z3)
_SAVE_SET_CURRENT(Z3);
#endif
#if HAS_CURRENT_HOME(Z4)
_SAVE_SET_CURRENT(Z4);
#endif
#if HAS_CURRENT_HOME(I)
const int16_t tmc_save_current_I = stepperI.getMilliamps();
stepperI.rms_current(I_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_I), tmc_save_current_I, I_CURRENT_HOME);
_SAVE_SET_CURRENT(I);
#endif
#if HAS_CURRENT_HOME(J)
const int16_t tmc_save_current_J = stepperJ.getMilliamps();
stepperJ.rms_current(J_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_J), tmc_save_current_J, J_CURRENT_HOME);
_SAVE_SET_CURRENT(J);
#endif
#if HAS_CURRENT_HOME(K)
const int16_t tmc_save_current_K = stepperK.getMilliamps();
stepperK.rms_current(K_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_K), tmc_save_current_K, K_CURRENT_HOME);
_SAVE_SET_CURRENT(K);
#endif
#if HAS_CURRENT_HOME(U)
const int16_t tmc_save_current_U = stepperU.getMilliamps();
stepperU.rms_current(U_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_U), tmc_save_current_U, U_CURRENT_HOME);
_SAVE_SET_CURRENT(U);
#endif
#if HAS_CURRENT_HOME(V)
const int16_t tmc_save_current_V = stepperV.getMilliamps();
stepperV.rms_current(V_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_V), tmc_save_current_V, V_CURRENT_HOME);
_SAVE_SET_CURRENT(V);
#endif
#if HAS_CURRENT_HOME(W)
const int16_t tmc_save_current_W = stepperW.getMilliamps();
stepperW.rms_current(W_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(F(STR_W), tmc_save_current_W, W_CURRENT_HOME);
_SAVE_SET_CURRENT(W);
#endif
#if SENSORLESS_STALLGUARD_DELAY
safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
Expand Down Expand Up @@ -595,9 +596,18 @@ void GcodeSuite::G28() {
#if HAS_CURRENT_HOME(Y2)
stepperY2.rms_current(tmc_save_current_Y2);
#endif
#if HAS_CURRENT_HOME(Z) && ENABLED(DELTA)
#if HAS_CURRENT_HOME(Z)
stepperZ.rms_current(tmc_save_current_Z);
#endif
#if HAS_CURRENT_HOME(Z2)
stepperZ2.rms_current(tmc_save_current_Z2);
#endif
#if HAS_CURRENT_HOME(Z3)
stepperZ3.rms_current(tmc_save_current_Z3);
#endif
#if HAS_CURRENT_HOME(Z4)
stepperZ4.rms_current(tmc_save_current_Z4);
#endif
#if HAS_CURRENT_HOME(I)
stepperI.rms_current(tmc_save_current_I);
#endif
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ void GcodeSuite::G33() {
#if HAS_DELTA_SENSORLESS_PROBING
if (verbose_level > 0 && do_save_offset_adj) {
offset_sensorless_adj.reset();

auto caltower = [&](Probe::sense_bool_t s){
auto caltower = [&](Probe::sense_bool_t s) {
float z_at_pt[NPP + 1];
LOOP_CAL_ALL(rad) z_at_pt[rad] = 0.0f;
probe.test_sensitivity = s;
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@
#endif
#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
#define USE_SENSORLESS 1
#define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
#endif
// Disable Z axis sensorless homing if a probe is used to home the Z axis
#if HOMING_Z_WITH_PROBE
Expand Down
Loading

0 comments on commit a7245fd

Please sign in to comment.