From 2c6f8a30f3b06a5a9a5343af04ccf0531ddc9698 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 5 Sep 2024 12:07:17 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Fix=20extra=20Z=20raises=20(#273?= =?UTF-8?q?95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/gcode/calibrate/G28.cpp | 2 +- Marlin/src/inc/Conditionals-3-etc.h | 3 +++ Marlin/src/module/motion.cpp | 5 +++++ Marlin/src/module/motion.h | 4 ++++ Marlin/src/module/stepper.cpp | 1 + Marlin/src/module/stepper.h | 10 ++++++++++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index fb52a30690..56b4761e25 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -371,7 +371,7 @@ void GcodeSuite::G28() { 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)) { + if (seenR || !(z_min_trusted || axis_should_home(Z_AXIS))) { z_homing_height += current_position.z; with_probe = false; } diff --git a/Marlin/src/inc/Conditionals-3-etc.h b/Marlin/src/inc/Conditionals-3-etc.h index a70582657a..3c685ad587 100644 --- a/Marlin/src/inc/Conditionals-3-etc.h +++ b/Marlin/src/inc/Conditionals-3-etc.h @@ -652,6 +652,9 @@ #if DISABLED(DELTA) #undef DELTA_HOME_TO_SAFE_ZONE #endif +#if ANY(DELTA, AXEL_TPARA) + #define Z_CAN_FALL_DOWN +#endif /** * This setting is also used by M109 when trying to calculate diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index c4502673fc..abac117719 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -80,6 +80,11 @@ // Relative Mode. Enable with G91, disable with G90. bool relative_mode; // = false +#if HAS_Z_AXIS + // If Z has been powered on trust that the real Z is >= current_position.z + bool z_min_trusted; // = false +#endif + /** * Cartesian Current Position * Used to track the native machine position as moves are queued. diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 2dcc8202e8..420b18f32a 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -433,6 +433,10 @@ void restore_feedrate_and_scaling(); typedef bits_t(NUM_AXES) main_axes_bits_t; constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1; +#if HAS_Z_AXIS + extern bool z_min_trusted; // If Z has been powered on trust that the real Z is >= current_position.z +#endif + void set_axis_is_at_home(const AxisEnum axis); #if HAS_ENDSTOPS diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 400be38181..81e1d0404e 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -580,6 +580,7 @@ bool Stepper::disable_axis(const AxisEnum axis) { // and keep a count of how many times each ENA pin has been set. // If all the axes that share the enabled bit are disabled + // toggle the ENA state that they all share. const bool can_disable = can_axis_disable(axis); if (can_disable) { #define _CASE_DISABLE(N) case N##_AXIS: DISABLE_AXIS_##N(); break; diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 208303f47f..c678b9dca3 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -44,6 +44,7 @@ #include "../inc/MarlinConfig.h" #include "planner.h" +#include "motion.h" #include "stepper/indirection.h" #include "stepper/cycles.h" #ifdef __AVR__ @@ -633,9 +634,18 @@ class Stepper { } static void mark_axis_enabled(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) { SBI(axis_enabled.bits, INDEX_OF_AXIS(axis, eindex)); + TERN_(HAS_Z_AXIS, if (axis == Z_AXIS) z_min_trusted = true); + // TODO: DELTA should have "Z" state affect all (ABC) motors and treat "XY" on/off as meaningless } static void mark_axis_disabled(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) { CBI(axis_enabled.bits, INDEX_OF_AXIS(axis, eindex)); + #if HAS_Z_AXIS + if (TERN0(Z_CAN_FALL_DOWN, axis == Z_AXIS)) { + z_min_trusted = false; + current_position.z = 0; + } + #endif + // TODO: DELTA should have "Z" state affect all (ABC) motors and treat "XY" on/off as meaningless } static bool can_axis_disable(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) { return !any_enable_overlap() || !(axis_enabled.bits & enable_overlap[INDEX_OF_AXIS(axis, eindex)]);