Skip to content

Commit 580a35b

Browse files
committed
🎨 Misc. probe-related cleanup
1 parent 39e42eb commit 580a35b

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

Marlin/src/gcode/calibrate/G34_M422.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void GcodeSuite::G34() {
244244

245245
// Add height to each value, to provide a more useful target height for
246246
// the next iteration of probing. This allows adjustments to be made away from the bed.
247-
z_measured[iprobe] = z_probed_height + Z_CLEARANCE_BETWEEN_PROBES;
247+
z_measured[iprobe] = z_probed_height + (Z_CLEARANCE_BETWEEN_PROBES);
248248

249249
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", iprobe + 1, " measured position is ", z_measured[iprobe]);
250250

@@ -446,7 +446,7 @@ void GcodeSuite::G34() {
446446
// Use the probed height from the last iteration to determine the Z height.
447447
// z_measured_min is used, because all steppers are aligned to z_measured_min.
448448
// Ideally, this would be equal to the 'z_probe * 0.5f' which was added earlier.
449-
current_position.z -= z_measured_min - (float)Z_CLEARANCE_BETWEEN_PROBES;
449+
current_position.z -= z_measured_min - float(Z_CLEARANCE_BETWEEN_PROBES);
450450
sync_plan_position();
451451
#endif
452452

Marlin/src/gcode/probe/M401_M402.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ void GcodeSuite::M401() {
6262
*/
6363
void GcodeSuite::M402() {
6464
probe.stow();
65-
probe.move_z_after_probing();
65+
#ifdef Z_AFTER_PROBING
66+
do_z_clearance(Z_AFTER_PROBING);
67+
#endif
6668
report_current_position();
6769
}
6870

Marlin/src/module/motion.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
783783
if (!lower_allowed) NOLESS(zdest, current_position.z);
784784
do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS)));
785785
}
786+
void do_z_clearance_by(const_float_t zclear) {
787+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance_by(", zclear, ")");
788+
do_z_clearance(current_position.z + zclear);
789+
}
786790
#endif
787791

788792
//
@@ -2340,15 +2344,10 @@ void set_axis_is_at_home(const AxisEnum axis) {
23402344
#if HAS_BED_PROBE && Z_HOME_TO_MIN
23412345
if (axis == Z_AXIS) {
23422346
#if HOMING_Z_WITH_PROBE
2343-
23442347
current_position.z -= probe.offset.z;
2345-
23462348
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z);
2347-
23482349
#else
2349-
2350-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z homed to ENDSTOP ***");
2351-
2350+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***");
23522351
#endif
23532352
}
23542353
#endif

Marlin/src/module/motion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,10 @@ void restore_feedrate_and_scaling();
400400

401401
#if HAS_Z_AXIS
402402
void do_z_clearance(const_float_t zclear, const bool lower_allowed=false);
403+
void do_z_clearance_by(const_float_t zclear);
403404
#else
404405
inline void do_z_clearance(float, bool=false) {}
406+
inline void do_z_clearance_by(float) {}
405407
#endif
406408

407409
/**

Marlin/src/module/probe.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,8 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
744744
if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
745745
sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;
746746

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

750750
// Raise to give the probe clearance
751751
do_blocking_move_to_z(current_position.z + Z_CLEARANCE_MULTI_PROBE, z_probe_fast_mm_s);
@@ -754,7 +754,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
754754

755755
// If the nozzle is well over the travel height then
756756
// move down quickly before doing the slow probe
757-
const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (offset.z < 0 ? -offset.z : 0);
757+
const float z = (Z_CLEARANCE_DEPLOY_PROBE) + 5.0f + (offset.z < 0 ? -offset.z : 0);
758758
if (current_position.z > z) {
759759
// Probe down fast. If the probe never triggered, raise for probe clearance
760760
if (!probe_down_to_z(z, z_probe_fast_mm_s))
@@ -839,10 +839,10 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
839839

840840
const float z2 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
841841

842-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", first_probe_z - z2);
842+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", z1 - z2);
843843

844844
// Return a weighted average of the fast and slow probes
845-
const float measured_z = (z2 * 3.0 + first_probe_z * 2.0) * 0.2;
845+
const float measured_z = (z2 * 3.0f + z1 * 2.0f) * 0.2f;
846846

847847
#else
848848

Marlin/src/module/probe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "../lcd/e3v2/proui/dwin.h"
3434
#endif
3535

36+
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
37+
#include "../core/debug_out.h"
38+
3639
#if HAS_BED_PROBE
3740
enum ProbePtRaise : uint8_t {
3841
PROBE_PT_NONE, // No raise or stow after run_z_probe
@@ -139,6 +142,7 @@ class Probe {
139142
#endif // !IS_KINEMATIC
140143

141144
static void move_z_after_probing() {
145+
DEBUG_SECTION(mzah, "move_z_after_probing", DEBUGGING(LEVELING));
142146
#ifdef Z_AFTER_PROBING
143147
do_z_clearance(Z_AFTER_PROBING, true); // Move down still permitted
144148
#endif
@@ -159,6 +163,7 @@ class Probe {
159163
#endif // !HAS_BED_PROBE
160164

161165
static void move_z_after_homing() {
166+
DEBUG_SECTION(mzah, "move_z_after_homing", DEBUGGING(LEVELING));
162167
#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) || defined(Z_AFTER_HOMING)
163168
do_z_clearance(Z_POST_CLEARANCE, true);
164169
#elif HAS_BED_PROBE

0 commit comments

Comments
 (0)