Skip to content

Commit

Permalink
🎨 Misc. probe-related cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 8, 2024
1 parent 39e42eb commit 580a35b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void GcodeSuite::G34() {

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

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

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

Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/gcode/probe/M401_M402.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void GcodeSuite::M401() {
*/
void GcodeSuite::M402() {
probe.stow();
probe.move_z_after_probing();
#ifdef Z_AFTER_PROBING
do_z_clearance(Z_AFTER_PROBING);
#endif
report_current_position();
}

Expand Down
11 changes: 5 additions & 6 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
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)));
}
void do_z_clearance_by(const_float_t zclear) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance_by(", zclear, ")");
do_z_clearance(current_position.z + zclear);
}
#endif

//
Expand Down Expand Up @@ -2340,15 +2344,10 @@ void set_axis_is_at_home(const AxisEnum axis) {
#if HAS_BED_PROBE && Z_HOME_TO_MIN
if (axis == Z_AXIS) {
#if HOMING_Z_WITH_PROBE

current_position.z -= probe.offset.z;

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z);

#else

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z homed to ENDSTOP ***");

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***");
#endif
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ void restore_feedrate_and_scaling();

#if HAS_Z_AXIS
void do_z_clearance(const_float_t zclear, const bool lower_allowed=false);
void do_z_clearance_by(const_float_t zclear);
#else
inline void do_z_clearance(float, bool=false) {}
inline void do_z_clearance_by(float) {}
#endif

/**
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
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);
const float z1 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj);
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", z1);

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

// 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.0 + (offset.z < 0 ? -offset.z : 0);
const float z = (Z_CLEARANCE_DEPLOY_PROBE) + 5.0f + (offset.z < 0 ? -offset.z : 0);
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))
Expand Down Expand Up @@ -839,10 +839,10 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {

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

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

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

#else

Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "../lcd/e3v2/proui/dwin.h"
#endif

#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../core/debug_out.h"

#if HAS_BED_PROBE
enum ProbePtRaise : uint8_t {
PROBE_PT_NONE, // No raise or stow after run_z_probe
Expand Down Expand Up @@ -139,6 +142,7 @@ class Probe {
#endif // !IS_KINEMATIC

static void move_z_after_probing() {
DEBUG_SECTION(mzah, "move_z_after_probing", DEBUGGING(LEVELING));
#ifdef Z_AFTER_PROBING
do_z_clearance(Z_AFTER_PROBING, true); // Move down still permitted
#endif
Expand All @@ -159,6 +163,7 @@ class Probe {
#endif // !HAS_BED_PROBE

static void move_z_after_homing() {
DEBUG_SECTION(mzah, "move_z_after_homing", DEBUGGING(LEVELING));
#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) || defined(Z_AFTER_HOMING)
do_z_clearance(Z_POST_CLEARANCE, true);
#elif HAS_BED_PROBE
Expand Down

0 comments on commit 580a35b

Please sign in to comment.