From 6ebbfa832cfb9542d4998595394de31b5ff6a555 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 11 Apr 2023 18:43:18 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Clarify=20G?= =?UTF-8?q?28=20R=20/=20R0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/gcode/calibrate/G28.cpp | 35 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 0b6548a3e3fa..839e29ecc498 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -408,17 +408,40 @@ void GcodeSuite::G28() { #endif #endif + // Z may home first, e.g., when homing away from the bed TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS)); + // 'R' to specify a specific raise. 'R0' indicates no raise, e.g., for recovery.resume + // When 'R0' is used, there should already be adequate clearance, e.g., from homing Z to max. const bool seenR = parser.seenval('R'); - const float z_homing_height = seenR ? parser.value_linear_units() : Z_HOMING_HEIGHT; - if (z_homing_height && (seenR || NUM_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW))) { - // Raise Z before homing any other axes and z is not already high enough (never lower z) - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z (before homing) by ", z_homing_height); - do_z_clearance(z_homing_height); - TERN_(BLTOUCH, bltouch.init()); + // Use raise given by 'R' or Z_HOMING_HEIGHT (above the probe trigger point) + float z_homing_height = seenR ? parser.value_linear_units() : Z_HOMING_HEIGHT; + + // Check for any lateral motion that might require clearance + const bool may_skate = seenR || NUM_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW); + + if (seenR && z_homing_height == 0) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("R0 = No Z raise"); } + else { + bool with_probe = ENABLED(HOMING_Z_WITH_PROBE); + // Raise above the current Z (which should be synced in the planner) + // The "height" for Z is a coordinate. But if Z is not trusted/homed make it relative. + if (seenR || !TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(Z_AXIS)) { + z_homing_height += current_position.z; + with_probe = false; + } + + if (may_skate) { + // Apply Z clearance before doing any lateral motion + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:"); + do_z_clearance(z_homing_height, with_probe); + } + } + + // Init BLTouch ahead of any lateral motion, even if not homing with the probe + TERN_(BLTOUCH, if (may_skate) bltouch.init()); // Diagonal move first if both are homing TERN_(QUICK_HOME, if (doX && doY) quick_home_xy());