From dc487c36b6443994cc0bd81cd8a9aad8c8ef04d8 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 19 Oct 2022 10:58:46 +0200 Subject: [PATCH] Remove Enable/Disable TMC when reiniting Movable axes The previous commits by @leptun were correct but there has been one call to Disable axis (and TMC) hidden in `InitMovement`. Therefore `InitMovement` has been split into 2 separate functions - one is there to allow the original full axis reinit, but the other `InitMovementNoReinitAxis` now only prepares a move without reiniting the TMC driver. This approach seems to have the benefit of fixing the Idler creep over time. The disadvantage is the fact, that setting StallGuard threshold is no longer called. We may need to add a special piece of code to handle/apply SGTHRS change at runtime like before. --- src/modules/idler.cpp | 4 ++-- src/modules/movable_base.cpp | 10 +++++++--- src/modules/movable_base.h | 5 +++++ src/modules/selector.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 4eee6f9..55f254c 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -83,7 +83,7 @@ Idler::OperationResult Idler::Disengage() { } // disengaging - return InitMovement(); + return InitMovementNoReinitAxis(); } Idler::OperationResult Idler::PartiallyDisengage(uint8_t slot) { @@ -122,7 +122,7 @@ Idler::OperationResult Idler::PlanMoveInner(uint8_t slot, Operation plannedOp) { return OperationResult::Accepted; } - return InitMovement(); + return InitMovementNoReinitAxis(); } bool Idler::Step() { diff --git a/src/modules/movable_base.cpp b/src/modules/movable_base.cpp index 420e2c6..de2fb96 100644 --- a/src/modules/movable_base.cpp +++ b/src/modules/movable_base.cpp @@ -26,15 +26,19 @@ void MovableBase::PlanHome() { MovableBase::OperationResult MovableBase::InitMovement() { mm::motion.PlanStallGuardThreshold(axis, mg::globals.StallGuardThreshold(axis)); if (motion.InitAxis(axis)) { - PrepareMoveToPlannedSlot(); - state = Moving; - return OperationResult::Accepted; + return InitMovementNoReinitAxis(); } else { state = TMCFailed; return OperationResult::Failed; } } +MovableBase::OperationResult MovableBase::InitMovementNoReinitAxis() { + PrepareMoveToPlannedSlot(); + state = Moving; + return OperationResult::Accepted; +} + void MovableBase::PerformMove() { if (mm::motion.QueueEmpty(axis)) { // move finished diff --git a/src/modules/movable_base.h b/src/modules/movable_base.h index e258b47..f67e5dc 100644 --- a/src/modules/movable_base.h +++ b/src/modules/movable_base.h @@ -95,8 +95,13 @@ protected: virtual bool FinishHomingAndPlanMoveToParkPos() = 0; virtual void FinishMove() = 0; + /// 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) OperationResult InitMovement(); + /// Initializes movement of a movable module without reinitializing the axis/TMC driver + OperationResult InitMovementNoReinitAxis(); + void PerformMove(); void PerformHomeForward(); diff --git a/src/modules/selector.cpp b/src/modules/selector.cpp index 747be18..77e89ab 100644 --- a/src/modules/selector.cpp +++ b/src/modules/selector.cpp @@ -86,7 +86,7 @@ Selector::OperationResult Selector::MoveToSlot(uint8_t slot) { } // do the move - return InitMovement(); + return InitMovementNoReinitAxis(); } bool Selector::Step() {