From 678fc096f0a965508b7912ba4b83e8ede2b56041 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 12 Apr 2023 13:20:46 +0200 Subject: [PATCH] Code size optimization --- src/logic/unload_to_finda.cpp | 17 +++++++++++------ .../unload_to_finda/test_unload_to_finda.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/logic/unload_to_finda.cpp b/src/logic/unload_to_finda.cpp index 01a5f24..6b7039a 100644 --- a/src/logic/unload_to_finda.cpp +++ b/src/logic/unload_to_finda.cpp @@ -37,15 +37,20 @@ bool UnloadToFinda::Step() { unloadStart_mm = mpu::pulley.CurrentPosition_mm(); // plan both moves to keep the unload smooth mpu::pulley.InitAxis(); - mpu::pulley.PlanMove(-mg::globals.FSensorUnloadCheck_mm(), mg::globals.PulleySlowFeedrate_mm_s()); - mpu::pulley.PlanMove(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU // standard lenght where FINDA is expected to trigger - + mg::globals.FSensorUnloadCheck_mm(), // but subtract the slow unload phase distance - mg::globals.PulleyUnloadFeedrate_mm_s()); + mm::P_pos_t unloadCheck = mm::unitToAxisUnit(-mg::globals.FSensorUnloadCheck_mm()); + mm::P_speed_t pulleyUnloadFR = mm::unitToAxisUnit(mg::globals.PulleyUnloadFeedrate_mm_s()); + mm::P_speed_t pulleyUnloadSlowFR = mm::unitToAxisUnit(mg::globals.PulleySlowFeedrate_mm_s()); + mpu::pulley.PlanMove(unloadCheck, pulleyUnloadSlowFR, pulleyUnloadFR); + constexpr mm::P_pos_t distance = mm::unitToAxisUnit(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU); // standard lenght where FINDA is expected to trigger + //+ mg::globals.FSensorUnloadCheck_mm(); // but subtract the slow unload phase distance + // damn, this addition is heavy :( + // mpu::pulley.PlanMove(distance + mg::globals.FSensorUnloadCheck_mm(), + // mg::globals.PulleyUnloadFeedrate_mm_s()); + mpu::pulley.PlanMove(distance - unloadCheck, pulleyUnloadFR); } return false; case UnloadingFromFSensor: { - int32_t mpucp = mpu::pulley.CurrentPosition_mm(); - if ((abs(unloadStart_mm - mpucp) > mm::truncatedUnit(mg::globals.FSensorUnloadCheck_mm()))) { + if ((abs(unloadStart_mm - mpu::pulley.CurrentPosition_mm()) > mm::truncatedUnit(mg::globals.FSensorUnloadCheck_mm()))) { // passed the slow unload distance, check fsensor if (mfs::fsensor.Pressed()) { // fsensor didn't trigger within the first fsensorUnloadCheckDistance mm -> stop pulling, something failed, report an error 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 0fd3bbb..c74f764 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 @@ -210,7 +210,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 = 2 + mm::unitToSteps(config::defaultBowdenLength + config::feedToFinda + config::filamentMinLoadedToMMU - mg::globals.FSensorUnloadCheck_mm()); + uint32_t unlSteps = 3 + mm::unitToSteps(config::defaultBowdenLength + config::feedToFinda + config::filamentMinLoadedToMMU - mg::globals.FSensorUnloadCheck_mm()); REQUIRE_FALSE(WhileCondition( ff, std::bind(SimulateUnloadToFINDA, _1,