From 8d40d397017848a090087364df70fb392e3f8193 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 7 Mar 2023 11:10:19 +0100 Subject: [PATCH] Ignoring the diag pin (stallguard) completely in specified range This seems to greatly improve overall homing reliability of Idler on MMUs which couldn't home with inserted filaments at all. The only downside is the fact, that we may actually "home" a blocked Idler correctly. --- src/modules/idler.cpp | 5 +++++ src/modules/idler.h | 1 + src/modules/movable_base.cpp | 26 +++++++++++++++----------- src/modules/movable_base.h | 1 + 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 15382ea..63ae10c 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -74,6 +74,11 @@ void Idler::FinishMove() { } } +bool Idler::SGAllowed(bool forward) const { + const uint8_t checkDistance = forward ? 220 : 200; + return AxisDistance(mm::axisUnitToTruncatedUnit(mm::motion.CurPosition())) > checkDistance; +} + void Idler::UpdateAdaptiveSGTHRS(bool forward) { // return; const uint8_t checkDistance = forward ? 220 : 200; diff --git a/src/modules/idler.h b/src/modules/idler.h index 3c14cec..3021774 100644 --- a/src/modules/idler.h +++ b/src/modules/idler.h @@ -72,6 +72,7 @@ protected: virtual bool FinishHomingAndPlanMoveToParkPos() override; virtual void FinishMove() override; virtual void UpdateAdaptiveSGTHRS(bool forward) override; + virtual bool SGAllowed(bool forward) const override; private: enum class Operation : uint8_t { diff --git a/src/modules/movable_base.cpp b/src/modules/movable_base.cpp index cd67e97..164d0a1 100644 --- a/src/modules/movable_base.cpp +++ b/src/modules/movable_base.cpp @@ -69,9 +69,11 @@ void MovableBase::PerformHomeForward() { if (mm::motion.StallGuard(axis)) { // we have reached the front end of the axis - first part homed probably ok mm::motion.StallGuardReset(axis); - mm::motion.AbortPlannedMoves(axis, true); - PlanHomingMoveBack(); - state = HomeBack; + if (SGAllowed(true)) { + mm::motion.AbortPlannedMoves(axis, true); + PlanHomingMoveBack(); + state = HomeBack; + } } else if (mm::motion.QueueEmpty(axis)) { HomeFailed(); } else { @@ -83,14 +85,16 @@ void MovableBase::PerformHomeBack() { if (mm::motion.StallGuard(axis)) { // we have reached the back end of the axis - second part homed probably ok mm::motion.StallGuardReset(axis); - mm::motion.AbortPlannedMoves(axis, true); - mm::motion.SetMode(axis, mg::globals.MotorsStealth() ? mm::Stealth : mm::Normal); - if (!FinishHomingAndPlanMoveToParkPos()) { - // the measured axis' length was incorrect, something is blocking it, report an error, homing procedure terminated - HomeFailed(); - } else { - homingValid = true; - // state = Ready; // not yet - we have to move to our parking or target position after homing the axis + if (SGAllowed(false)) { + mm::motion.AbortPlannedMoves(axis, true); + mm::motion.SetMode(axis, mg::globals.MotorsStealth() ? mm::Stealth : mm::Normal); + if (!FinishHomingAndPlanMoveToParkPos()) { + // the measured axis' length was incorrect, something is blocking it, report an error, homing procedure terminated + HomeFailed(); + } else { + homingValid = true; + // state = Ready; // not yet - we have to move to our parking or target position after homing the axis + } } } else if (mm::motion.QueueEmpty(axis)) { HomeFailed(); diff --git a/src/modules/movable_base.h b/src/modules/movable_base.h index 23c337f..fdb39e0 100644 --- a/src/modules/movable_base.h +++ b/src/modules/movable_base.h @@ -112,6 +112,7 @@ protected: /// default implementation is empty virtual void UpdateAdaptiveSGTHRS(bool /*forward*/) {} + virtual bool SGAllowed(bool forward) const { return true; } /// Initializes movement of a movable module. /// Beware: this operation reinitializes the axis/TMC driver as well (may introduce axis creep as we have seen on the Idler)