From d95589782957ed305fedfd9d715c7695c26e217b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 25 Jul 2021 23:13:28 +0200 Subject: [PATCH] Convert config::selectorSlotPositions to physical units --- src/config/config.h | 4 +++- src/modules/selector.cpp | 2 +- src/modules/selector.h | 8 ++++++-- .../unit/logic/eject_filament/test_eject_filament.cpp | 2 +- .../logic/feed_to_bondtech/test_feed_to_bondtech.cpp | 6 +++--- tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp | 10 +++++----- tests/unit/logic/helpers/helpers.ipp | 4 ++-- tests/unit/logic/stubs/stub_motion.cpp | 4 +++- .../logic/unload_to_finda/test_unload_to_finda.cpp | 4 ++-- 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index cdc9ce6..11cfdd7 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -13,7 +13,9 @@ static constexpr U_deg idlerSlotPositions[toolCount + 1] = { }; ///< slots 0-4 are the real ones, the 5th is the idle position // Selector's setup -static constexpr uint16_t selectorSlotPositions[toolCount + 1] = { 1, 2, 3, 4, 5, 6 }; ///< slots 0-4 are the real ones, the 5th is the farthest parking positions +static constexpr U_mm selectorSlotPositions[toolCount + 1] = { + 1.0_mm, 2.0_mm, 3.0_mm, 4.0_mm, 5.0_mm, 6.0_mm +}; ///< slots 0-4 are the real ones, the 5th is the farthest parking positions // Printer's filament sensor setup static constexpr const uint16_t fsensorDebounceMs = 10; diff --git a/src/modules/selector.cpp b/src/modules/selector.cpp index 67605e0..6ad25b1 100644 --- a/src/modules/selector.cpp +++ b/src/modules/selector.cpp @@ -21,7 +21,7 @@ bool Selector::MoveToSlot(uint8_t slot) { return true; mm::motion.InitAxis(mm::Selector); - mm::motion.PlanMove(mm::Selector, config::selectorSlotPositions[slot] - mm::motion.Position(mm::Selector), 1000); // @@TODO + mm::motion.PlanMoveTo(SlotPosition(slot), 1000.0_S_mm_s); // @@TODO state = Moving; return true; } diff --git a/src/modules/selector.h b/src/modules/selector.h index 61bc807..8f6b347 100644 --- a/src/modules/selector.h +++ b/src/modules/selector.h @@ -1,12 +1,14 @@ #pragma once #include "../config/config.h" -#include +#include "../modules/axisunit.h" namespace modules { /// The selector namespace provides all necessary facilities related to the logical model of the selector device of the MMU unit. namespace selector { +namespace mm = modules::motion; + /// The selector model - handles asynchronnous move operations between filament individual slots and keeps track of selector's current state. class Selector { public: @@ -41,7 +43,9 @@ public: inline uint8_t Slot() const { return currentSlot; } /// @returns predefined positions of individual slots - inline static uint16_t SlotPosition(uint8_t slot) { return config::selectorSlotPositions[slot]; } + static constexpr mm::S_pos_t SlotPosition(uint8_t slot) { + return mm::unitToAxisUnit(config::selectorSlotPositions[slot]); + } /// @returns the index of idle position of the selector, usually 5 in case of 0-4 valid indices of filament slots inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; } diff --git a/tests/unit/logic/eject_filament/test_eject_filament.cpp b/tests/unit/logic/eject_filament/test_eject_filament.cpp index 7fed93d..54f0f43 100644 --- a/tests/unit/logic/eject_filament/test_eject_filament.cpp +++ b/tests/unit/logic/eject_filament/test_eject_filament.cpp @@ -42,7 +42,7 @@ TEST_CASE("eject_filament::eject0", "[eject_filament][.]") { // it should have instructed the selector and idler to move to slot 1 // check if the idler and selector have the right command CHECK(modules::motion::axes[modules::motion::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(modules::motion::axes[modules::motion::Selector].targetPos == ms::Selector::SlotPosition(4)); + CHECK(modules::motion::axes[modules::motion::Selector].targetPos == ms::Selector::SlotPosition(4).v); // now cycle at most some number of cycles (to be determined yet) and then verify, that the idler and selector reached their target positions REQUIRE(WhileTopState(ef, ProgressCode::SelectingFilamentSlot, 5000)); diff --git a/tests/unit/logic/feed_to_bondtech/test_feed_to_bondtech.cpp b/tests/unit/logic/feed_to_bondtech/test_feed_to_bondtech.cpp index cdc63ee..a57ac4b 100644 --- a/tests/unit/logic/feed_to_bondtech/test_feed_to_bondtech.cpp +++ b/tests/unit/logic/feed_to_bondtech/test_feed_to_bondtech.cpp @@ -45,7 +45,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { // it should have instructed the selector and idler to move to slot 0 // check if the idler and selector have the right command CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0).v); CHECK(mm::axes[mm::Idler].enabled == true); // engaging idler @@ -55,7 +55,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { 5000)); CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0).v); // idler engaged, selector in position, we'll start pushing filament REQUIRE(fb.State() == FeedToBondtech::PushingFilament); @@ -81,7 +81,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { // 5000)); // CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(5)); // @@TODO constants - CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0).v); // state machine finished ok, the green LED should be on REQUIRE(fb.State() == FeedToBondtech::OK); 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 19184bf..b379035 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 @@ -45,7 +45,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { // it should have instructed the selector and idler to move to slot 1 // check if the idler and selector have the right command CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0).v); CHECK(mm::axes[mm::Idler].enabled == true); // engaging idler @@ -55,7 +55,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { 5000)); CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0).v); // idler engaged, selector in position, we'll start pushing filament REQUIRE(ff.State() == FeedToFinda::PushingFilament); @@ -87,7 +87,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { // 5000)); CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); // @@TODO constants - CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0).v); // state machine finished ok, the green LED should be on REQUIRE(ff.State() == FeedToFinda::OK); @@ -112,7 +112,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") { // it should have instructed the selector and idler to move to slot 1 // check if the idler and selector have the right command CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0).v); // engaging idler REQUIRE(WhileCondition( @@ -121,7 +121,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") { 5000)); CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0).v); // idler engaged, we'll start pushing filament REQUIRE(ff.State() == FeedToFinda::PushingFilament); diff --git a/tests/unit/logic/helpers/helpers.ipp b/tests/unit/logic/helpers/helpers.ipp index 711f75e..9ab5d4e 100644 --- a/tests/unit/logic/helpers/helpers.ipp +++ b/tests/unit/logic/helpers/helpers.ipp @@ -5,7 +5,7 @@ bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t se CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; } CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) { return false; } CHECKED_ELSE(mi::idler.Engaged() == (idlerSlotIndex < config::toolCount)) { return false; } - CHECKED_ELSE(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(selectorSlotIndex)) { return false; } + CHECKED_ELSE(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(selectorSlotIndex).v) { return false; } CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; } CHECKED_ELSE(mf::finda.Pressed() == findaPressed) { return false; } @@ -32,7 +32,7 @@ bool VerifyState2(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t s CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; } CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) { return false; } CHECKED_ELSE(mi::idler.Engaged() == (idlerSlotIndex < config::toolCount)) { return false; } - CHECKED_ELSE(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(selectorSlotIndex)) { return false; } + CHECKED_ELSE(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(selectorSlotIndex).v) { return false; } CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; } CHECKED_ELSE(mf::finda.Pressed() == findaPressed) { return false; } diff --git a/tests/unit/logic/stubs/stub_motion.cpp b/tests/unit/logic/stubs/stub_motion.cpp index b22ec88..de6bb0b 100644 --- a/tests/unit/logic/stubs/stub_motion.cpp +++ b/tests/unit/logic/stubs/stub_motion.cpp @@ -70,9 +70,11 @@ void Motion::AbortPlannedMoves() { } void ReinitMotion() { + const pos_t selector_pos = unitToSteps(config::selectorSlotPositions[0]); + // reset the simulation data to defaults axes[0] = AxisSim({ 0, 0, false, false, false }); // pulley - axes[1] = AxisSim({ 1, 1, false, false, false }); // selector //@@TODO proper selector positions once defined + axes[1] = AxisSim({ selector_pos, selector_pos, false, false, false }); // selector //@@TODO proper selector positions once defined axes[2] = AxisSim({ 0, 0, false, false, false }); // idler } 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 a05973b..82cf86d 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 @@ -45,7 +45,7 @@ TEST_CASE("unload_to_finda::regular_unload", "[unload_to_finda]") { // it should have instructed the selector and idler to move to slot 1 // check if the idler and selector have the right command CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0).v); CHECK(mm::axes[mm::Idler].enabled == true); // engaging idler @@ -94,7 +94,7 @@ TEST_CASE("unload_to_finda::unload_without_FINDA_trigger", "[unload_to_finda]") // it should have instructed the selector and idler to move to slot 1 // check if the idler and selector have the right command CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); - CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); + CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0).v); CHECK(mm::axes[mm::Idler].enabled == true); // engaging idler