Skip to content

Commit

Permalink
🎨 Refine probe, more debug
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 30, 2023
1 parent a8ac83b commit 49f1cc8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
9 changes: 2 additions & 7 deletions Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,13 @@ void GcodeSuite::G34() {

TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));

// In BLTOUCH HS mode, the probe travels in a deployed state.
// Users of G34 might have a badly misaligned bed, so raise Z by the
// length of the deployed pin (BLTOUCH stroke < 7mm)
#define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance()))

// Compute a worst-case clearance height to probe from. After the first
// iteration this will be re-calculated based on the actual bed position
auto magnitude2 = [&](const uint8_t i, const uint8_t j) {
const xy_pos_t diff = z_stepper_align.xy[i] - z_stepper_align.xy[j];
return HYPOT2(diff.x, diff.y);
};
float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * SQRT(_MAX(0, magnitude2(0, 1)
float z_probe = Z_PROBE_SAFE_CLEARANCE + (G34_MAX_GRADE) * 0.01f * SQRT(_MAX(0, magnitude2(0, 1)
#if TRIPLE_Z
, magnitude2(2, 1), magnitude2(2, 0)
#if QUAD_Z
Expand Down Expand Up @@ -253,7 +248,7 @@ void GcodeSuite::G34() {
// Adapt the next probe clearance height based on the new measurements.
// Safe_height = lowest distance to bed (= highest measurement) plus highest measured misalignment.
z_maxdiff = z_measured_max - z_measured_min;
z_probe = Z_BASIC_CLEARANCE + z_measured_max + z_maxdiff;
z_probe = Z_PROBE_SAFE_CLEARANCE + z_measured_max + z_maxdiff;

#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
// Replace the initial values in z_measured with calculated heights at
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/gcode/calibrate/G76_M871.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "../../module/probe.h"
#include "../../feature/bedlevel/bedlevel.h"
#include "../../module/temperature.h"
#include "../../module/probe.h"
#include "../../feature/probe_temp_comp.h"
#include "../../lcd/marlinui.h"

Expand Down
11 changes: 8 additions & 3 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void do_blocking_move_to(const xyze_pos_t &raw, const_feedRate_t fr_mm_s/*=0.0f*
do_blocking_move_to(NUM_AXIS_ELEM(raw), fr_mm_s);
}
void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_x(", rx, ", ", fr_mm_s, ")");
do_blocking_move_to(
NUM_AXIS_LIST(rx, current_position.y, current_position.z, current_position.i, current_position.j, current_position.k,
current_position.u, current_position.v, current_position.w),
Expand All @@ -681,6 +682,7 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {

#if HAS_Y_AXIS
void do_blocking_move_to_y(const_float_t ry, const_feedRate_t fr_mm_s/*=0.0*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_y(", ry, ", ", fr_mm_s, ")");
do_blocking_move_to(
NUM_AXIS_LIST(current_position.x, ry, current_position.z, current_position.i, current_position.j, current_position.k,
current_position.u, current_position.v, current_position.w),
Expand All @@ -691,6 +693,7 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {

#if HAS_Z_AXIS
void do_blocking_move_to_z(const_float_t rz, const_feedRate_t fr_mm_s/*=0.0*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_z(", rz, ", ", fr_mm_s, ")");
do_blocking_move_to_xy_z(current_position, rz, fr_mm_s);
}
#endif
Expand Down Expand Up @@ -769,6 +772,7 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {

#if HAS_Y_AXIS
void do_blocking_move_to_xy(const_float_t rx, const_float_t ry, const_feedRate_t fr_mm_s/*=0.0*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_xy(", rx, ", ", ry, ", ", fr_mm_s, ")");
do_blocking_move_to(
NUM_AXIS_LIST(rx, ry, current_position.z, current_position.i, current_position.j, current_position.k,
current_position.u, current_position.v, current_position.w),
Expand All @@ -789,9 +793,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
);
}
void do_z_clearance(const_float_t zclear, const bool lower_allowed/*=false*/) {
float zdest = zclear;
if (!lower_allowed) NOLESS(zdest, current_position.z);
do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS)));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance(", zclear, ", ", lower_allowed, ")");
const float zdest = _MIN(zclear, Z_MAX_POS);
if (zdest == current_position.z || (!lower_allowed && zdest < current_position.z)) return;
do_blocking_move_to_z(zdest, TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS)));
}
#endif

Expand Down
46 changes: 30 additions & 16 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ void Probe::do_z_raise(const float z_raise) {
}

FORCE_INLINE void probe_specific_action(const bool deploy) {
DEBUG_SECTION(log_psa, "Probe::probe_specific_action", DEBUGGING(LEVELING));
#if ENABLED(PAUSE_BEFORE_DEPLOY_STOW)
do {
#if ENABLED(PAUSE_PROBE_DEPLOY_WHEN_TRIGGERED)
Expand Down Expand Up @@ -505,7 +506,6 @@ void Probe::probe_error_stop() {
* Return TRUE if the probe could not be deployed/stowed
*/
bool Probe::set_deployed(const bool deploy, const bool no_return/*=false*/) {

if (DEBUGGING(LEVELING)) {
DEBUG_POS("Probe::set_deployed", current_position);
DEBUG_ECHOLNPGM("deploy=", deploy, " no_return=", no_return);
Expand Down Expand Up @@ -688,12 +688,12 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
bool Probe::tare() {
#if BOTH(PROBE_ACTIVATION_SWITCH, PROBE_TARE_ONLY_WHILE_INACTIVE)
if (endstops.probe_switch_activated()) {
SERIAL_ECHOLNPGM("Cannot tare an active probe");
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Cannot tare an active probe");
return true;
}
#endif

SERIAL_ECHOLNPGM("Taring probe");
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Taring probe");
WRITE(PROBE_TARE_PIN, PROBE_TARE_STATE);
delay(PROBE_TARE_TIME);
WRITE(PROBE_TARE_PIN, !PROBE_TARE_STATE);
Expand All @@ -718,6 +718,8 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z);

auto try_to_probe = [&](PGM_P const plbl, const_float_t z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) -> bool {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ", scheck, ", ", clearance);

// Tare the probe, if supported
if (TERN0(PROBE_TARE, tare())) return true;

Expand All @@ -742,31 +744,34 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
// If Z isn't known then probe to -10mm.
const float z_probe_low_point = axis_is_trusted(Z_AXIS) ? zoffs + Z_PROBE_LOW_POINT : -10.0f;

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point);

// Double-probing does a fast probe followed by a slow probe
#if TOTAL_PROBING == 2

// Attempt to tare the probe
if (TERN0(PROBE_TARE, tare())) return NAN;

// Do a first probe at the fast speed
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Fast Probe:");
if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;

const float first_probe_z = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", first_probe_z);

// Raise to give the probe clearance
do_z_clearance(current_position.z + Z_CLEARANCE_MULTI_PROBE);
do_z_clearance(Z_CLEARANCE_MULTI_PROBE);

#elif Z_PROBE_FEEDRATE_FAST != Z_PROBE_FEEDRATE_SLOW

// If the nozzle is well over the travel height then
// move down quickly before doing the slow probe
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0f + (zoffs > 0 ? zoffs : 0);
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0f + _MAX(zoffs, 0.0f);
if (current_position.z > z) {
// Probe down fast. If the probe never triggered, raise for probe clearance
if (!probe_down_to_z(z, z_probe_fast_mm_s))
do_z_clearance(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
}
#endif

Expand All @@ -789,6 +794,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
if (TERN0(PROBE_TARE, tare())) return true;

// Probe downward slowly to find the bed
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Slow Probe:");
if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW),
sanity_check, Z_CLEARANCE_MULTI_PROBE) ) return NAN;

Expand All @@ -798,7 +804,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {

#if EXTRA_PROBING > 0
// Insert Z measurement into probes[]. Keep it sorted ascending.
LOOP_LE_N(i, p) { // Iterate the saved Zs to insert the new Z
LOOP_LE_N(i, p) { // Iterate the saved Zs to insert the new Z
if (i == p || probes[i] > z) { // Last index or new Z is smaller than this Z
for (int8_t m = p; --m >= i;) probes[m + 1] = probes[m]; // Shift items down after the insertion point
probes[i] = z; // Insert the new Z measurement
Expand All @@ -817,7 +823,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
#if EXTRA_PROBING > 0
< TOTAL_PROBING - 1
#endif
) do_z_clearance(z + Z_CLEARANCE_MULTI_PROBE);
) do_z_clearance(Z_CLEARANCE_MULTI_PROBE);
#endif
}

Expand Down Expand Up @@ -919,7 +925,7 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
#endif

// Use a safe Z height for the XY move
const float safe_z = _MAX(current_position.z, SUM_TERN(BLTOUCH, Z_CLEARANCE_BETWEEN_PROBES, bltouch.z_extra_clearance()));
const float safe_z = _MAX(current_position.z, Z_PROBE_SAFE_CLEARANCE);

// On delta keep Z below clip height or do_blocking_move_to will abort
xyz_pos_t npos = NUM_AXIS_ARRAY(
Expand All @@ -928,12 +934,16 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
current_position.u, current_position.v, current_position.w
);
if (!can_reach(npos, probe_relative)) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Not Reachable");
return NAN;
}

if (probe_relative) // Get the nozzle position, adjust for active hotend if not 0
if (DEBUGGING(LEVELING)) DEBUG_ECHOPGM("Move to probe");
if (probe_relative) { // Get the nozzle position, adjust for active hotend if not 0
if (DEBUGGING(LEVELING)) DEBUG_ECHOPGM("-relative");
npos -= DIFF_TERN(HAS_HOTEND_OFFSET, offset_xy, xy_pos_t(hotend_offset[active_extruder]));
}
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" point");

// Move the probe to the starting XYZ
do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
Expand All @@ -953,11 +963,15 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
// Raise and/or stow the probe depending on 'raise_after' and settings.
if (!isnan(measured_z)) {
const ProbePtRaise raise_type = (TERN0(BLTOUCH, !bltouch.high_speed_mode) && raise_after == PROBE_PT_RAISE) ? PROBE_PT_STOW : raise_after;
const bool big_raise = raise_type == PROBE_PT_BIG_RAISE;
if (big_raise || raise_type == PROBE_PT_RAISE)
do_z_clearance(current_position.z + (big_raise ? 25 : Z_CLEARANCE_BETWEEN_PROBES));
else if (raise_type == PROBE_PT_STOW || raise_type == PROBE_PT_LAST_STOW)
if (stow()) measured_z = NAN; // Error on stow?
switch (raise_type) {
default: break;
case PROBE_PT_RAISE:
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);

This comment has been minimized.

Copy link
@jamespearson04

jamespearson04 Apr 1, 2023

Contributor

This A: changes behaviour related to Z_CLEARANCE_BETWEEN_PROBES, so instead of moving to probe offset + clearance, it's just clearance. (breaking probing if it's set lower than the offset)

More importantly, B: If the measured z isn't used for correction before this call (as I suspect), it misbehaves.
For example, if Z_CLEARANCE_BETWEEN_PROBES = 1, and probe gets triggered at z=2, then it will attempt to move downwards, into the bed.

ETA: Was the intention to move the addition into the function?

This comment has been minimized.

Copy link
@jamespearson04

jamespearson04 Apr 1, 2023

Contributor

To add, my bad, it's blocked from going lower, but it would still remain at the trigger height, which breaks many situations

This comment has been minimized.

Copy link
@jamespearson04

jamespearson04 Apr 1, 2023

Contributor

For reference, I think this is what's causing #25560

break;
case PROBE_PT_STOW: case PROBE_PT_LAST_STOW:
if (stow()) measured_z = NAN; // Error on stow?
break;
}

if (verbose_level > 2)
SERIAL_ECHOLNPGM("Bed X: ", LOGICAL_X_POSITION(rx), " Y: ", LOGICAL_Y_POSITION(ry), " Z: ", measured_z);
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
PROBE_PT_NONE, // No raise or stow after run_z_probe
PROBE_PT_STOW, // Do a complete stow after run_z_probe
PROBE_PT_LAST_STOW, // Stow for sure, even in BLTouch HS mode
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
PROBE_PT_RAISE // Raise to "between" clearance after run_z_probe
};
#endif

Expand All @@ -59,6 +58,9 @@
#define Z_POST_CLEARANCE 10
#endif

// In BLTOUCH HS mode, the probe travels in a deployed state.
#define Z_PROBE_SAFE_CLEARANCE SUM_TERN(BLTOUCH, Z_CLEARANCE_BETWEEN_PROBES, bltouch.z_extra_clearance())

#if ENABLED(PREHEAT_BEFORE_LEVELING)
#ifndef LEVELING_NOZZLE_TEMP
#define LEVELING_NOZZLE_TEMP 0
Expand Down

0 comments on commit 49f1cc8

Please sign in to comment.