From 4f81366325502249ccc40a965dd465ec9e73a06e Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 10 Aug 2023 09:10:02 +0200 Subject: [PATCH] Perform up to maximumBowdenLength while unloading to FINDA + update unit tests to match the changed implementation --- src/config/config.h | 8 ++++---- src/logic/unload_to_finda.cpp | 8 +++++++- tests/unit/logic/unload_to_finda/test_unload_to_finda.cpp | 5 +++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index 896026d..e991d2f 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -91,13 +91,13 @@ static constexpr U_mm cuttingEdgeToFindaMidpoint = 22.85_mm; /// Cutting edge to static constexpr U_mm findaToCoupler = 12.0_mm; /// FINDA Coupler side to coupler screw. static constexpr U_mm couplerToBowden = 3.5_mm; /// FINDA Coupler screw to bowden mmu2s side (in coupling). -// @@TODO this is very tricky - the same MMU, same PTFE, -// just another piece of PLA (probably having more resistance in the tubes) -// and we are at least 40mm off! It looks like this really depends on the exact position -// We'll probably need to check for StallGuard while pushing the filament to avoid ginding the filament +// Min, max and default bowden length setup static constexpr U_mm defaultBowdenLength = 360.0_mm; /// ~360.0_mm - Default Bowden length. static constexpr U_mm minimumBowdenLength = 341.0_mm; /// ~341.0_mm - Minimum bowden length. static constexpr U_mm maximumBowdenLength = 792.0_mm; /// ~792.0_mm - Maximum bowden length. +static_assert(minimumBowdenLength.v <= defaultBowdenLength.v); +static_assert(maximumBowdenLength.v > defaultBowdenLength.v); + 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 diff --git a/src/logic/unload_to_finda.cpp b/src/logic/unload_to_finda.cpp index f24754b..2e7e1b4 100644 --- a/src/logic/unload_to_finda.cpp +++ b/src/logic/unload_to_finda.cpp @@ -39,7 +39,13 @@ bool UnloadToFinda::Step() { state = WaitingForFINDA; mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::InSelector); unloadStart_mm = mpu::pulley.CurrentPosition_mm(); - mpu::pulley.PlanMove(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, mg::globals.PulleyUnloadFeedrate_mm_s()); + // We can always plan the unload move for the maximum allowed bowden length, + // it should be even more reliable than doing just the specified bowden length: + // - if the filament is slipping for some reason, planning a longer move will not stop in the middle of the bowden tube + // - a faster unload (shorter than the specified bowden length) will be interrupted by FINDA turning off + // - if FINDA is misaligned or faulty, the only issue will be, that the filament will be thrown behind the pulley + // which could have happened with the previous implementation as well, because default bowden length was set to 42cm + mpu::pulley.PlanMove(-config::maximumBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, mg::globals.PulleyUnloadFeedrate_mm_s()); } return false; case WaitingForFINDA: { diff --git a/tests/unit/logic/unload_to_finda/test_unload_to_finda.cpp b/tests/unit/logic/unload_to_finda/test_unload_to_finda.cpp index 2f2370d..7360f2c 100644 --- a/tests/unit/logic/unload_to_finda/test_unload_to_finda.cpp +++ b/tests/unit/logic/unload_to_finda/test_unload_to_finda.cpp @@ -111,7 +111,8 @@ TEST_CASE("unload_to_finda::unload_without_FINDA_trigger", "[unload_to_finda]") // no changes to FINDA during unload - we'll pretend it never triggers // but set FSensor correctly - REQUIRE_FALSE(WhileCondition(ff, std::bind(SimulateUnloadToFINDA, _1, 10, 150000), 50000)); + uint32_t unlSteps = 10 + mm::unitToSteps(config::maximumBowdenLength + config::feedToFinda + config::filamentMinLoadedToMMU); + REQUIRE_FALSE(WhileCondition(ff, std::bind(SimulateUnloadToFINDA, _1, 10, 150000), unlSteps)); REQUIRE(ff.State() == logic::UnloadToFinda::FailedFINDA); REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::InSelector); @@ -195,7 +196,7 @@ TEST_CASE("unload_to_finda::unload_repeated", "[unload_to_finda]") { // but set FSensor correctly // In this case it is vital to correctly compute the amount of steps // to make the unload state machine restart after the 1st attempt - uint32_t unlSteps = 1 + mm::unitToSteps(config::defaultBowdenLength + config::feedToFinda + config::filamentMinLoadedToMMU); + uint32_t unlSteps = 1 + mm::unitToSteps(config::maximumBowdenLength + config::feedToFinda + config::filamentMinLoadedToMMU); REQUIRE_FALSE(WhileCondition(ff, std::bind(SimulateUnloadToFINDA, _1, 10, 150000), unlSteps)); main_loop();