From bf87bae664649fcf819a404b794f161a4730a502 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 17 Jun 2022 06:44:13 +0200 Subject: [PATCH] Improve restart ToolChange -> FeedToFINDA It looks like we don't have to reset the whole ToolChange state machine when resolving an error with the middle button (Retry) - but jump straight into the feeding phase. The reasons are multiple: - If an error happens during the unload phase, it is handled separately in the UnloadFilament state machine - If an error happens during the feeding phase, the unload has been already successfully completed. And when restarted from the very beginning, the ToolChange does the last retract sequence from the UnloadFilament phase -> that is not healthy, because the filament gets pushed away from the Pulley and causes another error. --- src/logic/tool_change.cpp | 21 ++++++++++++++++----- src/logic/tool_change.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/logic/tool_change.cpp b/src/logic/tool_change.cpp index df21ba4..bc6bd2b 100644 --- a/src/logic/tool_change.cpp +++ b/src/logic/tool_change.cpp @@ -58,6 +58,13 @@ void logic::ToolChange::ToolChangeFinishedCorrectly() { FinishedOK(); } +void logic::ToolChange::GoToFeedingToFinda() { + state = ProgressCode::FeedingToFinda; + error = ErrorCode::RUNNING; + mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::AtPulley); + feed.Reset(true, false); +} + bool ToolChange::StepInner() { switch (state) { case ProgressCode::UnloadingFilament: @@ -65,10 +72,7 @@ bool ToolChange::StepInner() { // unloading sequence finished - basically, no errors can occurr here // as UnloadFilament should handle all the possible error states on its own // There is no way the UnloadFilament to finish in an error state - state = ProgressCode::FeedingToFinda; - error = ErrorCode::RUNNING; - mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::AtPulley); - feed.Reset(true, false); + GoToFeedingToFinda(); } break; case ProgressCode::FeedingToFinda: @@ -108,7 +112,14 @@ bool ToolChange::StepInner() { GoToErrEngagingIdler(); break; case mui::Event::Middle: // try again the whole sequence - Reset(mg::globals.ActiveSlot()); + // It looks like we don't have to reset the whole state machine but jump straight into the feeding phase. + // The reasons are multiple: + // - If an error happens during the unload phase, it is handled separately in the UnloadFilament state machine + // - If an error happens during the feeding phase, the unload has been already successfully completed. + // And when restarted from the very beginning, the ToolChange does the last retract sequence from the UnloadFilament phase + // -> that is not healthy, because the filament gets pushed away from the Pulley and causes another error. + //Reset(mg::globals.ActiveSlot()); + GoToFeedingToFinda(); break; case mui::Event::Right: // problem resolved - the user pushed the fillament by hand? // we should check the state of all the sensors and either report another error or confirm the correct state diff --git a/src/logic/tool_change.h b/src/logic/tool_change.h index 848f499..5e9b14a 100644 --- a/src/logic/tool_change.h +++ b/src/logic/tool_change.h @@ -29,6 +29,7 @@ public: private: #endif void GoToFeedingToBondtech(); + void GoToFeedingToFinda(); /// Common code for a correct completion of UnloadFilament void ToolChangeFinishedCorrectly();