Skip to content

Commit 44800e9

Browse files
committed
PROBE_DOUBLE_TOUCH => MULTIPLE_PROBING
1 parent 6e85c06 commit 44800e9

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

Marlin/Configuration.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,16 @@
690690
// X and Y axis travel speed (mm/m) between probes
691691
#define XY_PROBE_SPEED 8000
692692

693-
// Speed for the first approach when double-probing (with PROBE_DOUBLE_TOUCH)
693+
// Speed for the first approach when double-probing (MULTIPLE_PROBING == 2)
694694
#define Z_PROBE_SPEED_FAST HOMING_FEEDRATE_Z
695695

696696
// Speed for the "accurate" probe of each point
697697
#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2)
698698

699-
// Use double touch for probing
700-
//#define PROBE_DOUBLE_TOUCH
699+
// The number of probes to perform at each point.
700+
// Set to 2 for a fast/slow probe, using the second probe result.
701+
// Set to 3 or more for slow probes, averaging the results.
702+
//#define MULTIPLE_PROBING 2
701703

702704
/**
703705
* Z probes require clearance when deploying, stowing, and moving between

Marlin/Configuration_adv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@
742742
//#define BEZIER_CURVE_SUPPORT
743743

744744
// G38.2 and G38.3 Probe Target
745-
// Enable PROBE_DOUBLE_TOUCH if you want G38 to double touch
745+
// Set MULTIPLE_PROBING if you want G38 to double touch
746746
//#define G38_PROBE_TARGET
747747
#if ENABLED(G38_PROBE_TARGET)
748748
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)

Marlin/Marlin_main.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ static void clean_up_after_endstop_or_probe_move() {
22152215
}
22162216

22172217
/**
2218-
* @details Used by probe_pt to do a single Z probe.
2218+
* @details Used by probe_pt to do a single Z probe at the current position.
22192219
* Leaves current_position[Z_AXIS] at the height where the probe triggered.
22202220
*
22212221
* @return The raw Z position where the probe was triggered
@@ -2229,7 +2229,8 @@ static void clean_up_after_endstop_or_probe_move() {
22292229
// Prevent stepper_inactive_time from running out and EXTRUDER_RUNOUT_PREVENT from extruding
22302230
refresh_cmd_timeout();
22312231

2232-
#if ENABLED(PROBE_DOUBLE_TOUCH)
2232+
// Double-probing does a fast probe followed by a slow probe
2233+
#if MULTIPLE_PROBING == 2
22332234

22342235
// Do a first probe at the fast speed
22352236
if (do_probe_move(-10, Z_PROBE_SPEED_FAST)) return NAN;
@@ -2257,22 +2258,49 @@ static void clean_up_after_endstop_or_probe_move() {
22572258
}
22582259
#endif
22592260

2260-
// move down slowly to find bed
2261-
if (do_probe_move(-10, Z_PROBE_SPEED_SLOW)) return NAN;
2262-
2263-
#if ENABLED(DEBUG_LEVELING_FEATURE)
2264-
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
2261+
#if MULTIPLE_PROBING > 2
2262+
float probes_total = 0;
2263+
for (uint8_t p = MULTIPLE_PROBING + 1; --p;) {
22652264
#endif
22662265

2267-
// Debug: compare probe heights
2268-
#if ENABLED(PROBE_DOUBLE_TOUCH) && ENABLED(DEBUG_LEVELING_FEATURE)
2269-
if (DEBUGGING(LEVELING)) {
2270-
SERIAL_ECHOPAIR("2nd Probe Z:", current_position[Z_AXIS]);
2271-
SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - current_position[Z_AXIS]);
2266+
// move down slowly to find bed
2267+
if (do_probe_move(-10, Z_PROBE_SPEED_SLOW)) return NAN;
2268+
2269+
#if MULTIPLE_PROBING > 2
2270+
probes_total += current_position[Z_AXIS];
2271+
if (p > 1) do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
22722272
}
22732273
#endif
22742274

2275-
return current_position[Z_AXIS];
2275+
#if MULTIPLE_PROBING > 2
2276+
2277+
// Return the average value of all probes
2278+
return probes_total * (1.0 / (MULTIPLE_PROBING));
2279+
2280+
#elif MULTIPLE_PROBING == 2
2281+
2282+
const float z2 = current_position[Z_AXIS];
2283+
2284+
#if ENABLED(DEBUG_LEVELING_FEATURE)
2285+
if (DEBUGGING(LEVELING)) {
2286+
SERIAL_ECHOPAIR("2nd Probe Z:", z2);
2287+
SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - z2);
2288+
}
2289+
#endif
2290+
2291+
// Return a weighted average of the fast and slow probes
2292+
return (z2 * 3.0 + first_probe_z * 2.0) * 0.2;
2293+
2294+
#else
2295+
2296+
// Return the single probe result
2297+
return current_position[Z_AXIS];
2298+
2299+
#endif
2300+
2301+
#if ENABLED(DEBUG_LEVELING_FEATURE)
2302+
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
2303+
#endif
22762304
}
22772305

22782306
/**
@@ -6005,7 +6033,7 @@ void home_all_axes() { gcode_G28(true); }
60056033

60066034
bool G38_pass_fail = false;
60076035

6008-
#if ENABLED(PROBE_DOUBLE_TOUCH)
6036+
#if MULTIPLE_PROBING > 1
60096037
// Get direction of move and retract
60106038
float retract_mm[XYZ];
60116039
LOOP_XYZ(i) {
@@ -6032,7 +6060,7 @@ void home_all_axes() { gcode_G28(true); }
60326060

60336061
G38_pass_fail = true;
60346062

6035-
#if ENABLED(PROBE_DOUBLE_TOUCH)
6063+
#if MULTIPLE_PROBING > 1
60366064
// Move away by the retract distance
60376065
set_destination_from_current();
60386066
LOOP_XYZ(i) destination[i] += retract_mm[i];

Marlin/SanityCheck.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@
224224
#error "UBL_GRANULAR_SEGMENTATION_FOR_CARTESIAN is now SEGMENT_LEVELED_MOVES. Please update your configuration."
225225
#elif HAS_PID_HEATING && (defined(K1) || !defined(PID_K1))
226226
#error "K1 is now PID_K1. Please update your configuration."
227+
#elif defined(PROBE_DOUBLE_TOUCH)
228+
#error "PROBE_DOUBLE_TOUCH is now MULTIPLE_PROBING. Please update your configuration."
227229
#endif
228230

229231
/**
@@ -698,6 +700,10 @@ static_assert(1 >= 0
698700
#error "Probes need Z_CLEARANCE_BETWEEN_PROBES >= 0."
699701
#endif
700702

703+
#if MULTIPLE_PROBING && MULTIPLE_PROBING < 2
704+
#error "MULTIPLE_PROBING must be >= 2."
705+
#endif
706+
701707
#else
702708

703709
/**

0 commit comments

Comments
 (0)