Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Sensorless homing/probing for G28, G33 #21899

Merged
merged 75 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
58bf83a
Mejora SENSORLESS en DELTA
lujios May 10, 2021
30164ed
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
lujios May 11, 2021
48ca5b2
Update probe.cpp
lujios May 11, 2021
350164d
Error versión actualizada
lujios May 11, 2021
e41f5f0
Error versión actualizada
lujios May 11, 2021
e7db472
DELTA with SENSORLESS_HOMING/PROBING.
lujios May 11, 2021
fc73ae5
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
lujios May 12, 2021
22671e0
Change description.
lujios May 13, 2021
e842e7a
Revert "Change description."
lujios May 13, 2021
30f47bc
Revert "Revert "Change description.""
lujios May 13, 2021
1b6f2b2
Delete Configuration.h
lujios May 13, 2021
49fed0b
Delete Configuration_adv.h
lujios May 13, 2021
f2d2397
Configuration.
lujios May 13, 2021
9b7a34c
Merge branch 'bugfix-2.0.x' of https://github.com/lujios/Marlin into …
lujios May 13, 2021
6ef7d75
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
lujios May 13, 2021
c343ee4
Change Configuration origin
lujios May 13, 2021
dd636ef
Merge branch 'bugfix-2.0.x' of https://github.com/lujios/Marlin into …
lujios May 13, 2021
fc1ec09
Update pins_RAMPS.h
lujios May 13, 2021
84d14c3
Update G28.cpp
lujios May 29, 2021
4041c88
Merge branch 'bugfix-2.0.x' into bugfix-2.0.x
lujios May 29, 2021
9adb045
Update G28.cpp
lujios May 29, 2021
5c31b99
Merge branch 'bugfix-2.0.x' into bugfix-2.0.x
lujios Jun 6, 2021
8a661be
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
lujios Jun 17, 2021
909ac8b
Update probe.cpp
lujios Jun 17, 2021
7ec77fc
Update probe.cpp
lujios Jun 17, 2021
4230664
Update probe.cpp
lujios Jun 17, 2021
58a0b19
Update pins_AZSMZ_MINI.h
lujios Jun 17, 2021
2e9bffd
initial review quick fixes
thinkyhead Jun 18, 2021
2824be1
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/21899
thinkyhead Jun 18, 2021
3d15bd3
non-delta slow homing
thinkyhead Jun 18, 2021
876be19
fewer static buffers
thinkyhead Jun 19, 2021
4fcee1e
style tweaks
thinkyhead Jun 19, 2021
0f05cd9
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/21899
thinkyhead Jun 19, 2021
7904673
Update set_homing_current
thinkyhead Jun 19, 2021
742653e
Always trigger MAX on DELTA
thinkyhead Jun 19, 2021
e77ba46
move some to planner
thinkyhead Jun 19, 2021
bb2569f
Update planner.cpp
lujios Jun 20, 2021
8869fa9
Typographic error. debug_current -> debug_current_on
lujios Jun 20, 2021
e59e05b
SENSORLESS_PROBING to SENSORLESS_HOMING
lujios Jun 20, 2021
93a5573
ENABLED(SENSORLESS_PROBING) or ENABLED(SENSORLESS_HOMING)
lujios Jun 20, 2021
f22adf2
ENABLED(SENSORLESS_PROBING) or ENABLED(SENSORLESS_HOMING)
lujios Jun 20, 2021
6deb5e0
Update probe.h
lujios Jun 20, 2021
17c3421
Update probe.cpp
lujios Jun 20, 2021
fa3f66a
Update probe.cpp
lujios Jun 21, 2021
0afa0b0
Update probe.cpp
lujios Jun 21, 2021
e194686
Update probe.cpp
lujios Jun 21, 2021
cccbb23
Update probe.cpp
lujios Jun 21, 2021
6591021
Update probe.cpp
lujios Jun 21, 2021
3ef49e9
Update probe.cpp
lujios Jun 23, 2021
a5960b6
Update probe.cpp
lujios Jun 23, 2021
b39dcc0
Update probe.cpp
lujios Jun 23, 2021
ac1595f
Update probe.cpp
lujios Jun 23, 2021
5598406
Update probe.cpp
lujios Jun 23, 2021
7f8e424
Update tmc_util.h
lujios Jul 10, 2021
46a1943
Update probe.h
lujios Jul 10, 2021
0b04316
Update probe.cpp
lujios Jul 10, 2021
f92fdd2
Update G33.cpp
lujios Jul 10, 2021
181808c
Update planner.h
lujios Jul 10, 2021
e4477b0
Update endstops.cpp
lujios Jul 10, 2021
b8e6477
Update delta.cpp
lujios Jul 10, 2021
f7ee2a2
Update probe.cpp
lujios Jul 10, 2021
8318e7a
Update tmc_util.h
lujios Jul 10, 2021
2b66a40
Update tmc_util.h
lujios Jul 10, 2021
40bda0c
Update tmc_util.h
lujios Jul 10, 2021
a7aa0db
Update tmc_util.h
lujios Jul 10, 2021
3689e97
Update G33.cpp
lujios Jul 10, 2021
0edbd14
Update planner.h
lujios Jul 10, 2021
85015e9
Update planner.cpp
lujios Jul 10, 2021
8762770
Update G28.cpp
lujios Jul 10, 2021
4fa184b
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
lujios Jul 10, 2021
6ccff86
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/21899
thinkyhead Jul 12, 2021
db829ea
Use bitfields for test_sensitivity
thinkyhead Jul 12, 2021
fe218b7
motion_state_t
thinkyhead Jul 12, 2021
c1f837b
Tweak some SPI_ENDSTOPS code
thinkyhead Jul 12, 2021
01a7477
Fix warning
thinkyhead Jul 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Marlin/src/feature/tmc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,6 @@ void test_tmc_connection(LOGICAL_AXIS_DECL(const bool, true));
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
extern millis_t sg_guard_period;
constexpr uint16_t default_sg_guard_duration = 400;

struct motion_state_t {
xy_ulong_t acceleration;
#if ENABLED(HAS_CLASSIC_JERK)
xy_float_t jerk_state;
#endif
};
#endif

bool tmc_enable_stallguard(TMC2130Stepper &st);
Expand Down
18 changes: 15 additions & 3 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,15 @@
motion_state_t begin_slow_homing() {
motion_state_t motion_state{0};
motion_state.acceleration.set(planner.settings.max_acceleration_mm_per_s2[X_AXIS],
planner.settings.max_acceleration_mm_per_s2[Y_AXIS]);
planner.settings.max_acceleration_mm_per_s2[Y_AXIS]
OPTARG(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS])
);
planner.settings.max_acceleration_mm_per_s2[X_AXIS] = 100;
planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = 100;
TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = 100);
#if HAS_CLASSIC_JERK
motion_state.jerk_state = planner.max_jerk;
planner.max_jerk.set(0, 0);
planner.max_jerk.set(0, 0 OPTARG(DELTA, 0));
#endif
planner.reset_acceleration_rates();
return motion_state;
Expand All @@ -181,6 +184,7 @@
void end_slow_homing(const motion_state_t &motion_state) {
planner.settings.max_acceleration_mm_per_s2[X_AXIS] = motion_state.acceleration.x;
planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = motion_state.acceleration.y;
TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = motion_state.acceleration.z);
TERN_(HAS_CLASSIC_JERK, planner.max_jerk = motion_state.jerk_state);
planner.reset_acceleration_rates();
}
Expand Down Expand Up @@ -259,7 +263,7 @@ void GcodeSuite::G28() {
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)
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2) || (ENABLED(DELTA) && HAS_CURRENT_HOME(Z))
#define HAS_HOMING_CURRENT 1
#endif

Expand Down Expand Up @@ -287,6 +291,11 @@ void GcodeSuite::G28() {
stepperY2.rms_current(Y2_CURRENT_HOME);
if (DEBUGGING(LEVELING)) debug_current(PSTR("Y2"), tmc_save_current_Y2, Y2_CURRENT_HOME);
#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(PSTR("Z"), tmc_save_current_Z, Z_CURRENT_HOME);
#endif
#endif

#if ENABLED(IMPROVE_HOMING_RELIABILITY)
Expand Down Expand Up @@ -497,6 +506,9 @@ void GcodeSuite::G28() {
#if HAS_CURRENT_HOME(Y2)
stepperY2.rms_current(tmc_save_current_Y2);
#endif
#if HAS_CURRENT_HOME(Z) && ENABLED(DELTA)
stepperZ.rms_current(tmc_save_current_Z);
#endif
#if HAS_CURRENT_HOME(I)
stepperI.rms_current(tmc_save_current_I);
#endif
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ float lcd_probe_pt(const xy_pos_t &xy);

void ac_home() {
endstops.enable(true);
TERN_(SENSORLESS_PROBING, probe.set_homing_current(true));
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
home_delta();
TERN_(SENSORLESS_PROBING, probe.set_homing_current(false));
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
endstops.not_homing();
}

Expand Down
12 changes: 9 additions & 3 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,15 @@ void _O2 Endstops::report_states() {
// The following routines are called from an ISR context. It could be the temperature ISR, the
// endstop ISR or the Stepper ISR.

#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
#if ENABLED(DELTA)
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_MAX
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_MAX_PIN
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_MAX_ENDSTOP_INVERTING
#else
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
#endif

// Check endstops - Could be called from Temperature ISR!
void Endstops::update() {
Expand Down
28 changes: 28 additions & 0 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,34 @@ void Planner::check_axes_activity() {
}
#endif

#if ENABLED(IMPROVE_HOMING_RELIABILITY)

void Planner::enable_stall_prevention(const bool onoff) {
static motion_state_t saved_motion_state;
if (onoff) {
saved_motion_state.acceleration.x = settings.max_acceleration_mm_per_s2[X_AXIS];
saved_motion_state.acceleration.y = settings.max_acceleration_mm_per_s2[Y_AXIS];
settings.max_acceleration_mm_per_s2[X_AXIS] = settings.max_acceleration_mm_per_s2[Y_AXIS] = 100;
#if ENABLED(DELTA)
saved_motion_state.acceleration.z = settings.max_acceleration_mm_per_s2[Z_AXIS];
settings.max_acceleration_mm_per_s2[Z_AXIS] = 100;
#endif
#if HAS_CLASSIC_JERK
saved_motion_state.jerk_state = max_jerk;
max_jerk.set(0, 0 OPTARG(DELTA, 0));
#endif
}
else {
settings.max_acceleration_mm_per_s2[X_AXIS] = saved_motion_state.acceleration.x;
settings.max_acceleration_mm_per_s2[Y_AXIS] = saved_motion_state.acceleration.y;
TERN_(DELTA, settings.max_acceleration_mm_per_s2[Z_AXIS] = saved_motion_state.acceleration.z);
TERN_(HAS_CLASSIC_JERK, max_jerk = saved_motion_state.jerk_state);
}
reset_acceleration_rates();
}

#endif

#if HAS_LEVELING

constexpr xy_pos_t level_fulcrum = {
Expand Down
13 changes: 13 additions & 0 deletions Marlin/src/module/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ typedef struct {
min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
} planner_settings_t;

#if ENABLED(IMPROVE_HOMING_RELIABILITY)
struct motion_state_t {
TERN(DELTA, xyz_ulong_t, xy_ulong_t) acceleration;
#if HAS_CLASSIC_JERK
TERN(DELTA, xyz_float_t, xy_float_t) jerk_state;
#endif
};
#endif

#if DISABLED(SKEW_CORRECTION)
#define XY_SKEW_FACTOR 0
#define XZ_SKEW_FACTOR 0
Expand Down Expand Up @@ -532,6 +541,10 @@ class Planner {
}
#endif

#if ENABLED(IMPROVE_HOMING_RELIABILITY)
void enable_stall_prevention(const bool onoff);
#endif

#if DISABLED(NO_VOLUMETRICS)

// Update multipliers based on new diameter measurements
Expand Down
87 changes: 85 additions & 2 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,12 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
#if ENABLED(SENSORLESS_PROBING)
sensorless_t stealth_states { false };
#if ENABLED(DELTA)
stealth_states.x = tmc_enable_stallguard(stepperX);
stealth_states.x = tmc_enable_stallguard(stepperX); // Delta watches all DIAG pins for a stall
stealth_states.y = tmc_enable_stallguard(stepperY);
#endif
stealth_states.z = tmc_enable_stallguard(stepperZ);
stealth_states.z = tmc_enable_stallguard(stepperZ); // All machines will check Z-DIAG for stall
endstops.enable(true);
set_homing_current(true); // The "homing" current also applies to probing
#endif

TERN_(HAS_QUIET_PROBING, set_probing_paused(true));
Expand All @@ -523,6 +524,7 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
tmc_disable_stallguard(stepperY, stealth_states.y);
#endif
tmc_disable_stallguard(stepperZ, stealth_states.z);
set_homing_current(false);
#endif

if (probe_triggered && TERN0(BLTOUCH_SLOW_MODE, bltouch.stow())) // Stow in LOW SPEED MODE on every trigger
Expand Down Expand Up @@ -814,4 +816,85 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai

#endif // HAS_Z_SERVO_PROBE

#if ENABLED(SENSORLESS_PROBING)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

/**
* Disable stealthChop if used. Enable diag1 pin on driver.
*/
sensorless_t stealth_states { false };
void Probe::enable_stallguard_diag1() {
#if ENABLED(DELTA)
stealth_states.x = tmc_enable_stallguard(stepperX);
stealth_states.y = tmc_enable_stallguard(stepperY);
#endif
stealth_states.z = tmc_enable_stallguard(stepperZ);
endstops.enable(true);
}
/**
* Re-enable stealthChop if used. Disable diag1 pin on driver.
*/
void Probe::disable_stallguard_diag1() {
endstops.not_homing();
#if ENABLED(DELTA)
tmc_disable_stallguard(stepperX, stealth_states.x);
tmc_disable_stallguard(stepperY, stealth_states.y);
#endif
tmc_disable_stallguard(stepperZ, stealth_states.z);
}

/**
* Change the current in the TMC drivers to N##_CURRENT_HOME. And we save the current configuration of each TMC driver.
*/
void Probe::set_homing_current(const bool onoff) {
#if ENABLED(DELTA)
static int16_t saved_current_X, saved_current_Y;
#endif
static int16_t saved_current_Z;
#define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Z)
auto debug_current_on = [](PGM_P const s, const int16_t a, const int16_t b) {
if (DEBUGGING(LEVELING)) { DEBUG_ECHOPGM_P(s); DEBUG_ECHOLNPAIR(" current: ", a, " -> ", b); }
};
if (onoff) {
#if ENABLED(DELTA)
#if HAS_CURRENT_HOME(X)
saved_current_X = stepperX.getMilliamps();
stepperX.rms_current(X_CURRENT_HOME);
debug_current_on(PSTR("X"), saved_current_X, X_CURRENT_HOME);
#endif
#if HAS_CURRENT_HOME(Y)
saved_current_Y = stepperY.getMilliamps();
stepperY.rms_current(Y_CURRENT_HOME);
debug_current_on(PSTR("Y"), saved_current_Y, Y_CURRENT_HOME);
#endif
#endif
#if HAS_CURRENT_HOME(Z)
saved_current_Z = stepperZ.getMilliamps();
stepperZ.rms_current(Z_CURRENT_HOME);
debug_current_on(PSTR("Z"), saved_current_Z, Z_CURRENT_HOME);
#endif
TERN_(IMPROVE_HOMING_RELIABILITY, planner.enable_stall_prevention(true));
}
else {
#if ENABLED(DELTA)
#if HAS_CURRENT_HOME(X)
stepperX.rms_current(saved_current_X);
debug_current_on(PSTR("X"), X_CURRENT_HOME, saved_current_X);
#endif
#if HAS_CURRENT_HOME(Y)
stepperY.rms_current(saved_current_Y);
debug_current_on(PSTR("Y"), Y_CURRENT_HOME, saved_current_Y);
#endif
#endif
#if HAS_CURRENT_HOME(Z)
stepperZ.rms_current(saved_current_Z);
debug_current_on(PSTR("Z"), Z_CURRENT_HOME, saved_current_Z);
#endif
TERN_(IMPROVE_HOMING_RELIABILITY, planner.enable_stall_prevention(false));
}
#endif
}

#endif // SENSORLESS_PROBING

#endif // HAS_BED_PROBE
7 changes: 7 additions & 0 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ class Probe {
static bool tare();
#endif

// Basic functions for Sensorless Homing and Probing
#if ENABLED(SENSORLESS_PROBING)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
static void enable_stallguard_diag1();
static void disable_stallguard_diag1();
static void set_homing_current(const bool onoff);
#endif

private:
static bool probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s);
static void do_z_raise(const float z_raise);
Expand Down