Convert config::idlerSlotPositions to physical units

pull/71/head
Yuri D'Elia 2021-07-25 22:39:18 +02:00
parent b133c8b975
commit 6daf7fd060
8 changed files with 23 additions and 17 deletions

View File

@ -8,7 +8,9 @@ namespace config {
static constexpr const uint8_t toolCount = 5U; ///< Max number of extruders/tools/slots static constexpr const uint8_t toolCount = 5U; ///< Max number of extruders/tools/slots
// Idler's setup // 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 // 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 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

View File

@ -22,7 +22,7 @@ bool Idler::Disengage() {
mm::motion.InitAxis(mm::Idler); mm::motion.InitAxis(mm::Idler);
// plan move to idle position // plan move to idle position
mm::motion.PlanMove(mm::Idler, config::idlerSlotPositions[IdleSlotIndex()] - mm::motion.Position(mm::Idler), 1000); // @@TODO mm::motion.PlanMoveTo<mm::Idler>(SlotPosition(IdleSlotIndex()), 1000._I_deg_s); // @@TODO
state = Moving; state = Moving;
return true; return true;
} }
@ -38,7 +38,7 @@ bool Idler::Engage(uint8_t slot) {
return true; return true;
mm::motion.InitAxis(mm::Idler); mm::motion.InitAxis(mm::Idler);
mm::motion.PlanMove(mm::Idler, config::idlerSlotPositions[slot] - mm::motion.Position(mm::Idler), 1000); // @@TODO mm::motion.PlanMoveTo<mm::Idler>(SlotPosition(slot), 1000._I_deg_s); // @@TODO
state = Moving; state = Moving;
return true; return true;
} }

View File

@ -1,12 +1,14 @@
#pragma once #pragma once
#include "../config/config.h" #include "../config/config.h"
#include <stdint.h> #include "../modules/axisunit.h"
namespace modules { namespace modules {
/// The idler namespace provides all necessary facilities related to the logical model of the idler device of the MMU unit. /// The idler namespace provides all necessary facilities related to the logical model of the idler device of the MMU unit.
namespace idler { namespace idler {
namespace mm = modules::motion;
/// The Idler model handles asynchronnous Engaging / Disengaging operations and keeps track of idler's current state. /// The Idler model handles asynchronnous Engaging / Disengaging operations and keeps track of idler's current state.
class Idler { class Idler {
public: public:
@ -50,7 +52,9 @@ public:
inline uint8_t Slot() const { return currentSlot; } inline uint8_t Slot() const { return currentSlot; }
/// @returns predefined positions of individual slots /// @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<mm::I_pos_t>(config::idlerSlotPositions[slot]);
}
/// @returns the index of idle position of the idler, usually 5 in case of 0-4 valid indices of filament slots /// @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; } inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; }

View File

@ -41,7 +41,7 @@ TEST_CASE("eject_filament::eject0", "[eject_filament][.]") {
// it should have instructed the selector and idler to move to slot 1 // it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command // 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)); 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 // now cycle at most some number of cycles (to be determined yet) and then verify, that the idler and selector reached their target positions

View File

@ -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 // it should have instructed the selector and idler to move to slot 0
// check if the idler and selector have the right command // 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::Selector].targetPos == ms::Selector::SlotPosition(0));
CHECK(mm::axes[mm::Idler].enabled == true); 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(); }, [&](int) { return !mi::idler.Engaged(); },
5000)); 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)); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0));
// idler engaged, selector in position, we'll start pushing filament // idler engaged, selector in position, we'll start pushing filament

View File

@ -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 // it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command // 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::Selector].targetPos == ms::Selector::SlotPosition(0));
CHECK(mm::axes[mm::Idler].enabled == true); 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(); }, [&](int) { return !mi::idler.Engaged(); },
5000)); 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)); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0));
// idler engaged, selector in position, we'll start pushing filament // 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(); }, // [&](int) { return mi::idler.Engaged(); },
// 5000)); // 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)); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0));
// state machine finished ok, the green LED should be on // 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 // it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command // 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::Selector].targetPos == ms::Selector::SlotPosition(0));
// engaging idler // engaging idler
@ -120,7 +120,7 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") {
[&](int) { return !mi::idler.Engaged(); }, [&](int) { return !mi::idler.Engaged(); },
5000)); 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)); CHECK(mm::axes[mm::Selector].pos == ms::Selector::SlotPosition(0));
// idler engaged, we'll start pushing filament // idler engaged, we'll start pushing filament

View File

@ -3,7 +3,7 @@ template<typename SM>
bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex,
bool findaPressed, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) { bool findaPressed, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) {
CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; } 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(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)) { return false; }
CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; } CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; }
@ -30,7 +30,7 @@ template<typename SM>
bool VerifyState2(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, 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) { 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(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(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)) { return false; }
CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; } CHECKED_ELSE(ms::selector.Slot() == selectorSlotIndex) { return false; }

View File

@ -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 // it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command // 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::Selector].targetPos == ms::Selector::SlotPosition(0));
CHECK(mm::axes[mm::Idler].enabled == true); 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 // it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command // 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::Selector].targetPos == ms::Selector::SlotPosition(0));
CHECK(mm::axes[mm::Idler].enabled == true); CHECK(mm::axes[mm::Idler].enabled == true);