From c352954882bc931377ece338b3f5fa459c55ea07 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 21 Mar 2018 01:01:43 -0500 Subject: [PATCH] Allow no raise after run_z_probe in probe_pt --- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 10 +++++----- Marlin/src/gcode/bedlevel/abl/G29.cpp | 6 +++--- Marlin/src/gcode/calibrate/G33.cpp | 2 +- Marlin/src/gcode/calibrate/M48.cpp | 6 +++--- Marlin/src/gcode/probe/G30.cpp | 6 +++--- Marlin/src/module/probe.cpp | 12 +++++++----- Marlin/src/module/probe.h | 7 ++++++- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 438a2b25d..b6b9486be 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -750,7 +750,7 @@ const float rawx = mesh_index_to_xpos(location.x_index), rawy = mesh_index_to_ypos(location.y_index); - const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling + const float measured_z = probe_pt(rawx, rawy, stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling z_values[location.x_index][location.y_index] = measured_z; } SERIAL_FLUSH(); // Prevent host M105 buffer overrun. @@ -1519,7 +1519,7 @@ incremental_LSF_reset(&lsf_results); if (do_3_pt_leveling) { - measured_z = probe_pt(PROBE_PT_1_X, PROBE_PT_1_Y, false, g29_verbose_level); + measured_z = probe_pt(PROBE_PT_1_X, PROBE_PT_1_Y, PROBE_PT_RAISE, g29_verbose_level); if (isnan(measured_z)) abort_flag = true; else { @@ -1533,7 +1533,7 @@ } if (!abort_flag) { - measured_z = probe_pt(PROBE_PT_2_X, PROBE_PT_2_Y, false, g29_verbose_level); + measured_z = probe_pt(PROBE_PT_2_X, PROBE_PT_2_Y, PROBE_PT_RAISE, g29_verbose_level); //z2 = measured_z; if (isnan(measured_z)) abort_flag = true; @@ -1548,7 +1548,7 @@ } if (!abort_flag) { - measured_z = probe_pt(PROBE_PT_3_X, PROBE_PT_3_Y, true, g29_verbose_level); + measured_z = probe_pt(PROBE_PT_3_X, PROBE_PT_3_Y, PROBE_PT_STOW, g29_verbose_level); //z3 = measured_z; if (isnan(measured_z)) abort_flag = true; @@ -1576,7 +1576,7 @@ const float ry = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); if (!abort_flag) { - measured_z = probe_pt(rx, ry, parser.seen('E'), g29_verbose_level); // TODO: Needs error handling + measured_z = probe_pt(rx, ry, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling abort_flag = isnan(measured_z); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 3d8a88c6b..33afac494 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -604,7 +604,7 @@ void GcodeSuite::G29() { #else // !PROBE_MANUALLY { - const bool stow_probe_after_each = parser.boolval('E'); + const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; measured_z = 0; @@ -650,7 +650,7 @@ void GcodeSuite::G29() { if (!position_is_reachable_by_probe(xProbe, yProbe)) continue; #endif - measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level); + measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, raise_after, verbose_level); if (isnan(measured_z)) { set_bed_leveling_enabled(abl_should_enable); @@ -687,7 +687,7 @@ void GcodeSuite::G29() { // Retain the last probe position xProbe = points[i].x; yProbe = points[i].y; - measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level); + measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, raise_after, verbose_level); if (isnan(measured_z)) { set_bed_leveling_enabled(abl_should_enable); break; diff --git a/Marlin/src/gcode/calibrate/G33.cpp b/Marlin/src/gcode/calibrate/G33.cpp index 626ba24c5..036b3425f 100644 --- a/Marlin/src/gcode/calibrate/G33.cpp +++ b/Marlin/src/gcode/calibrate/G33.cpp @@ -137,7 +137,7 @@ static void G33_cleanup( inline float calibration_probe(const float nx, const float ny, const bool stow) { #if HAS_BED_PROBE - return probe_pt(nx, ny, stow, 0, false); + return probe_pt(nx, ny, stow ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, false); #else UNUSED(stow); return lcd_probe_pt(nx, ny); diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index cc82a7fe3..14efec5e0 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -70,7 +70,7 @@ void GcodeSuite::M48() { return; } - const bool stow_probe_after_each = parser.boolval('E'); + const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; float X_current = current_position[X_AXIS], Y_current = current_position[Y_AXIS]; @@ -114,7 +114,7 @@ void GcodeSuite::M48() { double mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples]; // Move to the first point, deploy, and probe - const float t = probe_pt(X_probe_location, Y_probe_location, stow_probe_after_each, verbose_level); + const float t = probe_pt(X_probe_location, Y_probe_location, raise_after, verbose_level); bool probing_good = !isnan(t); if (probing_good) { @@ -190,7 +190,7 @@ void GcodeSuite::M48() { } // n_legs // Probe a single point - sample_set[n] = probe_pt(X_probe_location, Y_probe_location, stow_probe_after_each, 0); + sample_set[n] = probe_pt(X_probe_location, Y_probe_location, raise_after, 0); // Break the loop if the probe fails probing_good = !isnan(sample_set[n]); diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index 429e62648..ee668a83a 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -51,8 +51,8 @@ void GcodeSuite::G30() { setup_for_endstop_or_probe_move(); - const bool do_stow = parser.boolval('E'); - const float measured_z = probe_pt(xpos, ypos, do_stow, 1); + const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_NONE; + const float measured_z = probe_pt(xpos, ypos, raise_after, 1); if (!isnan(measured_z)) { SERIAL_PROTOCOLPAIR("Bed X: ", FIXFLOAT(xpos)); @@ -62,7 +62,7 @@ void GcodeSuite::G30() { clean_up_after_endstop_or_probe_move(); - if (do_stow) move_z_after_probing(); + if (raise_after == PROBE_PT_STOW) move_z_after_probing(); report_current_position(); } diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 7ed4d0e6a..0f3defbb2 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -631,13 +631,15 @@ static float run_z_probe() { * - Raise to the BETWEEN height * - Return the probed Z position */ -float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t verbose_level, const bool probe_relative/*=true*/) { +float probe_pt(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR(">>> probe_pt(", LOGICAL_X_POSITION(rx)); SERIAL_ECHOPAIR(", ", LOGICAL_Y_POSITION(ry)); - SERIAL_ECHOPAIR(", ", stow ? "" : "no "); - SERIAL_ECHOLNPGM("stow)"); + SERIAL_ECHOPAIR(", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none"); + SERIAL_ECHOPAIR(", ", int(verbose_level)); + SERIAL_ECHOPAIR(", ", probe_relative ? "probe" : "nozzle"); + SERIAL_ECHOLNPGM("_relative)"); DEBUG_POS("", current_position); } #endif @@ -670,9 +672,9 @@ float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t if (!DEPLOY_PROBE()) { measured_z = run_z_probe() + zprobe_zoffset; - if (!stow) + if (raise_after == PROBE_PT_RAISE) do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST)); - else + else if (raise_after == PROBE_PT_STOW) if (STOW_PROBE()) measured_z = NAN; } diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index a90020fe7..919602e98 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -37,7 +37,12 @@ #else inline void move_z_after_probing() {} #endif - float probe_pt(const float &rx, const float &ry, const bool, const uint8_t, const bool probe_relative=true); + enum ProbePtRaise : unsigned char { + PROBE_PT_NONE, // No raise or stow after run_z_probe + PROBE_PT_STOW, // Do a complete stow after run_z_probe + PROBE_PT_RAISE // Raise to "between" clearance after run_z_probe + }; + float probe_pt(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true); #define DEPLOY_PROBE() set_probe_deployed(true) #define STOW_PROBE() set_probe_deployed(false) #else