From 97b362f2b719b7915ab076657637aa07cbde2d44 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 25 Nov 2021 15:03:16 +0100 Subject: [PATCH] Join feedrates of Load-to-FINDA and Load-to-Nozzle MMU-105 --- src/config/config.h | 1 + src/logic/cut_filament.cpp | 4 ++-- src/logic/feed_to_finda.cpp | 10 ++++++---- src/logic/feed_to_finda.h | 4 +++- src/logic/load_filament.cpp | 2 +- src/logic/tool_change.cpp | 4 ++-- tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp | 6 +++--- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index 83ceca1..2d1bbf5 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -87,6 +87,7 @@ static constexpr U_mm defaultBowdenLength = 427.0_mm; /// ~427.0_mm /// Default static constexpr U_mm minimumBowdenLength = 341.0_mm; /// ~341.0_mm /// Minimum bowden length. @TODO Should be stored in EEPROM. static constexpr U_mm maximumBowdenLength = 792.0_mm; /// ~792.0_mm /// Maximum bowden length. @TODO Should be stored in EEPROM. static constexpr U_mm feedToFinda = cuttingEdgeToFindaMidpoint + filamentMinLoadedToMMU; +static constexpr U_mm maximumFeedToFinda = feedToFinda + 20.0_mm; ///< allow for some safety margin to load to FINDA static constexpr U_mm pulleyHelperMove = 10.0_mm; /// Helper move for Load/Unload error states - when the MMU should slowly move the filament a bit static constexpr U_mm cutLength = 8.0_mm; static constexpr U_mm fsensorToNozzle = 20.0_mm; /// ~20mm from MK4's filament sensor through extruder gears into nozzle diff --git a/src/logic/cut_filament.cpp b/src/logic/cut_filament.cpp index cd6c1e6..f790d52 100644 --- a/src/logic/cut_filament.cpp +++ b/src/logic/cut_filament.cpp @@ -49,7 +49,7 @@ bool CutFilament::StepInner() { case ProgressCode::SelectingFilamentSlot: if (mi::idler.Engaged() && ms::selector.Slot() == cutSlot) { // idler and selector finished their moves mg::globals.SetFilamentLoaded(cutSlot, mg::FilamentLoadState::AtPulley); - feed.Reset(true); + feed.Reset(true, true); state = ProgressCode::FeedingToFinda; } break; @@ -94,7 +94,7 @@ bool CutFilament::StepInner() { state = ProgressCode::OK; error = ErrorCode::OK; ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::on, ml::off); - feed.Reset(true); + feed.Reset(true, true); } break; case ProgressCode::OK: diff --git a/src/logic/feed_to_finda.cpp b/src/logic/feed_to_finda.cpp index 6192ae8..3d5152a 100644 --- a/src/logic/feed_to_finda.cpp +++ b/src/logic/feed_to_finda.cpp @@ -11,10 +11,11 @@ #include "../debug.h" namespace logic { -void FeedToFinda::Reset(bool feedPhaseLimited) { +void FeedToFinda::Reset(bool feedPhaseLimited, bool haltAtEnd) { dbg_logic_P(PSTR("\nFeed to FINDA\n\n")); state = EngagingIdler; this->feedPhaseLimited = feedPhaseLimited; + this->haltAtEnd = haltAtEnd; ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off); mi::idler.Engage(mg::globals.ActiveSlot()); // We can't get any FINDA readings if the selector is at the wrong spot - move it accordingly if necessary @@ -33,19 +34,20 @@ bool FeedToFinda::Step() { // if (mg::globals.FilamentLoaded() == mg::FilamentLoadState::NotLoaded) { // feed slowly filament to PTFE // mm::motion.PlanMove(config::filamentMinLoadedToMMU, config::pulleySlowFeedrate); // } - mm::motion.PlanMove(config::feedToFinda, config::pulleyFeedrate); + mm::motion.PlanMove(config::maximumFeedToFinda, config::pulleySlowFeedrate); mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::InSelector); mui::userInput.Clear(); // remove all buffered events if any just before we wait for some input } return false; case PushingFilament: { - if (mf::finda.Pressed() || (feedPhaseLimited && mui::userInput.AnyEvent())) { // @@TODO probably also a command from the printer - mm::motion.AbortPlannedMoves(); // stop pushing filament + if (mf::finda.Pressed() || (feedPhaseLimited && mui::userInput.AnyEvent())) { + mm::motion.AbortPlannedMoves(haltAtEnd); // stop pushing filament // FINDA triggered - that means it works and detected the filament tip mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::InSelector); dbg_logic_P(PSTR("Feed to Finda --> Idler disengaged")); dbg_logic_fP(PSTR("Pulley end steps %u"), mm::motion.CurPosition(mm::Pulley)); state = OK; + return true; // return immediately to allow for a seamless planning of another move (like feeding to bondtech) } else if (mm::motion.QueueEmpty()) { // all moves have been finished and FINDA didn't switch on state = Failed; ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0); diff --git a/src/logic/feed_to_finda.h b/src/logic/feed_to_finda.h index fd09ade..68c74cb 100644 --- a/src/logic/feed_to_finda.h +++ b/src/logic/feed_to_finda.h @@ -30,7 +30,8 @@ struct FeedToFinda { /// * true feed phase is limited, doesn't react on button press /// * false feed phase is unlimited, can be interrupted by any button press after blanking time /// Beware: the function returns immediately without actually doing anything if the FINDA is "pressed", i.e. the filament is already at the FINDA - void Reset(bool feedPhaseLimited); + /// @param haltAtEnd true if the Pulley's motion shall be brought into a halt (which is what LoadFilament wants, but not ToolChange) + void Reset(bool feedPhaseLimited, bool haltAtEnd); /// @returns true if the state machine finished its job, false otherwise bool Step(); @@ -43,6 +44,7 @@ struct FeedToFinda { private: uint8_t state; bool feedPhaseLimited; + bool haltAtEnd; }; } // namespace logic diff --git a/src/logic/load_filament.cpp b/src/logic/load_filament.cpp index e9765a9..09f7785 100644 --- a/src/logic/load_filament.cpp +++ b/src/logic/load_filament.cpp @@ -26,7 +26,7 @@ void LoadFilament::Reset(uint8_t param) { void logic::LoadFilament::Reset2() { state = ProgressCode::FeedingToFinda; error = ErrorCode::RUNNING; - feed.Reset(true); + feed.Reset(true, true); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off); } diff --git a/src/logic/tool_change.cpp b/src/logic/tool_change.cpp index 76eb82b..5ee773d 100644 --- a/src/logic/tool_change.cpp +++ b/src/logic/tool_change.cpp @@ -40,7 +40,7 @@ void ToolChange::Reset(uint8_t param) { error = ErrorCode::RUNNING; dbg_logic_P(PSTR("Filament is not loaded --> load")); mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::InSelector); - feed.Reset(true); + feed.Reset(true, false); } } @@ -67,7 +67,7 @@ bool ToolChange::StepInner() { state = ProgressCode::FeedingToFinda; error = ErrorCode::RUNNING; mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::AtPulley); - feed.Reset(true); + feed.Reset(true, false); } break; case ProgressCode::FeedingToFinda: diff --git a/tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp b/tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp index e53661c..bec2c47 100644 --- a/tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp +++ b/tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp @@ -31,7 +31,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { main_loop(); // restart the automaton - ff.Reset(false); + ff.Reset(false, true); REQUIRE(ff.State() == FeedToFinda::EngagingIdler); @@ -99,7 +99,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") { main_loop(); // restart the automaton - we want the limited version of the feed - ff.Reset(true); + ff.Reset(true, true); REQUIRE(ff.State() == FeedToFinda::EngagingIdler); @@ -128,7 +128,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") { REQUIRE(WhileCondition( ff, [&](uint32_t) { return ff.State() == FeedToFinda::PushingFilament; }, - 5000)); + 10000)); // the FINDA didn't trigger, we should be in the Failed state REQUIRE(ff.State() == FeedToFinda::Failed);