From 6daf7fd060f5df7095b0c8be50a3d27ebcb3cc30 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 25 Jul 2021 22:39:18 +0200 Subject: [PATCH] Convert config::idlerSlotPositions to physical units --- src/config/config.h | 4 +++- src/modules/idler.cpp | 4 ++-- src/modules/idler.h | 8 ++++++-- .../unit/logic/eject_filament/test_eject_filament.cpp | 2 +- .../logic/feed_to_bondtech/test_feed_to_bondtech.cpp | 4 ++-- tests/unit/logic/feed_to_finda/test_feed_to_finda.cpp | 10 +++++----- tests/unit/logic/helpers/helpers.ipp | 4 ++-- .../logic/unload_to_finda/test_unload_to_finda.cpp | 4 ++-- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index ece5230..cdc9ce6 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -8,7 +8,9 @@ namespace config { static constexpr const uint8_t toolCount = 5U; ///< Max number of extruders/tools/slots // Idler's setup -static constexpr uint16_t idlerSlotPositions[toolCount + 1] = { 1, 2, 3, 4, 5, 0 }; ///< slots 0-4 are the real ones, the 5th is the idle position +static constexpr U_deg idlerSlotPositions[toolCount + 1] = { + 1.0_deg, 2.0_deg, 3.0_deg, 4.0_deg, 5.0_deg, 0 +}; ///< 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 diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index b04dd4b..ca7618d 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -22,7 +22,7 @@ bool Idler::Disengage() { mm::motion.InitAxis(mm::Idler); // plan move to idle position - mm::motion.PlanMove(mm::Idler, config::idlerSlotPositions[IdleSlotIndex()] - mm::motion.Position(mm::Idler), 1000); // @@TODO + mm::motion.PlanMoveTo(SlotPosition(IdleSlotIndex()), 1000._I_deg_s); // @@TODO state = Moving; return true; } @@ -38,7 +38,7 @@ bool Idler::Engage(uint8_t slot) { return true; mm::motion.InitAxis(mm::Idler); - mm::motion.PlanMove(mm::Idler, config::idlerSlotPositions[slot] - mm::motion.Position(mm::Idler), 1000); // @@TODO + mm::motion.PlanMoveTo(SlotPosition(slot), 1000._I_deg_s); // @@TODO state = Moving; return true; } diff --git a/src/modules/idler.h b/src/modules/idler.h index 93e7e54..79946cf 100644 --- a/src/modules/idler.h +++ b/src/modules/idler.h @@ -1,12 +1,14 @@ #pragma once #include "../config/config.h" -#include +#include "../modules/axisunit.h" namespace modules { /// The idler namespace provides all necessary facilities related to the logical model of the idler device of the MMU unit. namespace idler { +namespace mm = modules::motion; + /// The Idler model handles asynchronnous Engaging / Disengaging operations and keeps track of idler's current state. class Idler { public: @@ -50,7 +52,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::idlerSlotPositions[slot]; } + static constexpr mm::I_pos_t SlotPosition(uint8_t slot) { + return mm::unitToAxisUnit(config::idlerSlotPositions[slot]); + } /// @returns the index of idle position of the idler, 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 ab608b7..7fed93d 100644 --- a/tests/unit/logic/eject_filament/test_eject_filament.cpp +++ b/tests/unit/logic/eject_filament/test_eject_filament.cpp @@ -41,7 +41,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)); + 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)); // now cycle at most some number of cycles (to be determined yet) and then verify, that the idler and selector reached their target positions 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 f96fd81..cdc63ee 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 @@ -44,7 +44,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)); + 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::Idler].enabled == true); @@ -54,7 +54,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { [&](int) { return !mi::idler.Engaged(); }, 5000)); - CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0)); + CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); // idler engaged, selector in position, we'll start pushing filament 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 6d7fa0d..19184bf 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 @@ -44,7 +44,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)); + 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::Idler].enabled == true); @@ -54,7 +54,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { [&](int) { return !mi::idler.Engaged(); }, 5000)); - CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0)); + CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); // idler engaged, selector in position, we'll start pushing filament @@ -86,7 +86,7 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") { // [&](int) { return mi::idler.Engaged(); }, // 5000)); - CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0)); // @@TODO constants + CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); // @@TODO constants CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); // state machine finished ok, the green LED should be on @@ -111,7 +111,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)); + CHECK(mm::axes[mm::Idler].targetPos == mi::Idler::SlotPosition(0).v); CHECK(mm::axes[mm::Selector].targetPos == ms::Selector::SlotPosition(0)); // engaging idler @@ -120,7 +120,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") { [&](int) { return !mi::idler.Engaged(); }, 5000)); - CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0)); + CHECK(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(0).v); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0)); // idler engaged, we'll start pushing filament diff --git a/tests/unit/logic/helpers/helpers.ipp b/tests/unit/logic/helpers/helpers.ipp index 20d0d51..711f75e 100644 --- a/tests/unit/logic/helpers/helpers.ipp +++ b/tests/unit/logic/helpers/helpers.ipp @@ -3,7 +3,7 @@ template bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool findaPressed, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) { CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; } - CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex)) { 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(ms::selector.Slot() == selectorSlotIndex) { return false; } @@ -30,7 +30,7 @@ template bool VerifyState2(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool findaPressed, uint8_t ledCheckIndex, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) { CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; } - CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex)) { 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(ms::selector.Slot() == selectorSlotIndex) { return false; } 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 25c816a..a05973b 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 @@ -44,7 +44,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)); + 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::Idler].enabled == true); @@ -93,7 +93,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)); + 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::Idler].enabled == true);