diff --git a/src/logic/unload_to_finda.cpp b/src/logic/unload_to_finda.cpp index 0209e43..6620a5f 100644 --- a/src/logic/unload_to_finda.cpp +++ b/src/logic/unload_to_finda.cpp @@ -36,7 +36,7 @@ bool UnloadToFinda::Step() { if (mi::idler.Engaged()) { state = WaitingForFINDA; mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::InSelector); - mm::motion.PlanMove(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, config::pulleyFeedrate); // @@TODO constants + mm::motion.PlanLongMove(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, config::pulleyFeedrate); } return false; case WaitingForFINDA: diff --git a/src/modules/motion.h b/src/modules/motion.h index 1d634e2..b81086e 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -170,12 +170,22 @@ public: constexpr void PlanLongMove(config::Unit delta, config::Unit feed_rate, config::Unit end_rate = { 0 }) { auto steps = unitToAxisUnit>(delta); - while (steps.v > 32767) { - PlanMove( - { 32767 }, - unitToAxisUnit>(feed_rate), - unitToAxisUnit>(feed_rate)); // keep the end feedrate the same to continue with the next segment - steps.v -= 32767; + if (steps.v < 0) { + while (steps.v > 32767) { + PlanMove( + { 32767 }, + unitToAxisUnit>(feed_rate), + unitToAxisUnit>(feed_rate)); // keep the end feedrate the same to continue with the next segment + steps.v -= 32767; + } + } else { + while (steps.v < -32767) { + PlanMove( + { -32767 }, + unitToAxisUnit>(feed_rate), + unitToAxisUnit>(feed_rate)); // keep the end feedrate the same to continue with the next segment + steps.v += 32767; + } } PlanMove( // last segment steps, diff --git a/tests/unit/logic/tool_change/test_tool_change.cpp b/tests/unit/logic/tool_change/test_tool_change.cpp index fd7d4f7..c448cda 100644 --- a/tests/unit/logic/tool_change/test_tool_change.cpp +++ b/tests/unit/logic/tool_change/test_tool_change.cpp @@ -39,7 +39,7 @@ void FeedingToBondtech(logic::ToolChange &tc, uint8_t toSlot) { REQUIRE(WhileCondition( tc, [&](int step) -> bool { - if(step == 2000){ // on 5000th step make filament sensor trigger + if(step == 2000){ // on 2000th step make filament sensor trigger mfs::fsensor.ProcessMessage(true); } return tc.TopLevelState() == ProgressCode::FeedingToBondtech; },