Skip to content

Commit c599c93

Browse files
committed
πŸ§‘β€πŸ’» Modify try_to_probe sanity-checking
1 parent 8c0ae93 commit c599c93

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

β€ŽMarlin/src/module/probe.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -702,29 +702,35 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
702702
* @details Used by probe_at_point to get the bed Z height at the current XY.
703703
* Leaves current_position.z at the height where the probe triggered.
704704
*
705+
* @param sanity_check Flag to compare the probe result with the expected result
706+
* based on the probe Z offset. If the result is too far away
707+
* (more than 2mm too early) then consider it an error.
708+
*
705709
* @return The Z position of the bed at the current XY or NAN on error.
706710
*/
707711
float Probe::run_z_probe(const bool sanity_check/*=true*/) {
708712
DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));
709713

710714
const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z);
711715

712-
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 {
713-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ", scheck, ", ", clearance);
716+
auto try_to_probe = [&](PGM_P const plbl, const_float_t z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck) -> bool {
717+
constexpr float error_tolerance = 2.0f;
718+
if (DEBUGGING(LEVELING)) {
719+
DEBUG_ECHOPGM_P(plbl);
720+
DEBUG_ECHOLNPGM("> try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ...)");
721+
}
714722

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

718726
// Do a first probe at the fast speed
719-
const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger?
720-
early_fail = (scheck && current_position.z > zoffs + clearance); // Probe triggered too high?
727+
const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger?
728+
early_fail = (scheck && current_position.z > zoffs + error_tolerance); // Probe triggered too high?
721729
#if ENABLED(DEBUG_LEVELING_FEATURE)
722730
if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) {
723-
DEBUG_ECHOPGM_P(plbl);
724-
DEBUG_ECHOPGM(" Probe fail! -");
725-
if (probe_fail) DEBUG_ECHOPGM(" No trigger.");
726-
if (early_fail) DEBUG_ECHOPGM(" Triggered early.");
727-
DEBUG_EOL();
731+
DEBUG_ECHOPGM(" Probe fail! - ");
732+
if (probe_fail) DEBUG_ECHOLNPGM("No trigger.");
733+
if (early_fail) DEBUG_ECHOLNPGM("Triggered early (above ", zoffs + error_tolerance, "mm)");
728734
}
729735
#else
730736
UNUSED(plbl);
@@ -733,7 +739,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
733739
};
734740

735741
// Stop the probe before it goes too low to prevent damage.
736-
// If Z isn't known then probe to -10mm.
742+
// For known Z probe below the expected trigger point, otherwise -10mm.
737743
const float z_probe_low_point = axis_is_trusted(Z_AXIS) ? zoffs + Z_PROBE_LOW_POINT : -10.0f;
738744

739745
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point);
@@ -745,9 +751,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
745751
if (TERN0(PROBE_TARE, tare())) return NAN;
746752

747753
// Do a first probe at the fast speed
748-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Fast Probe:");
749-
if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
750-
sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;
754+
if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s, sanity_check)) return NAN;
751755

752756
const float z1 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
753757
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", z1);
@@ -787,8 +791,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
787791

788792
// Probe downward slowly to find the bed
789793
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Slow Probe:");
790-
if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW),
791-
sanity_check, Z_CLEARANCE_MULTI_PROBE) ) return NAN;
794+
if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW), sanity_check)) return NAN;
792795

793796
TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe());
794797

0 commit comments

Comments
Β (0)