Add finer filament loaded states and improve unit tests

We need to know better where the filament is, a simple "filament loaded true/false"
does not correspond to the reality.
pull/126/head
D.R.racer 2021-09-29 10:29:07 +02:00 committed by DRracer
parent 5af0125672
commit c26cc30185
18 changed files with 100 additions and 80 deletions

View File

@ -20,7 +20,7 @@ void CutFilament::Reset(uint8_t param) {
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
cutSlot = param; cutSlot = param;
if (mg::globals.FilamentLoaded()) { if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::InSelector) {
state = ProgressCode::UnloadingFilament; state = ProgressCode::UnloadingFilament;
unl.Reset(cutSlot); unl.Reset(cutSlot);
} else { } else {
@ -67,6 +67,7 @@ bool CutFilament::StepInner() {
if (mm::motion.QueueEmpty()) { // idler and selector finished their moves if (mm::motion.QueueEmpty()) { // idler and selector finished their moves
// move selector aside - prepare the blade into active position // move selector aside - prepare the blade into active position
state = ProgressCode::PreparingBlade; state = ProgressCode::PreparingBlade;
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::AtPulley);
ms::selector.MoveToSlot(cutSlot + 1); ms::selector.MoveToSlot(cutSlot + 1);
} }
case ProgressCode::PreparingBlade: case ProgressCode::PreparingBlade:

View File

@ -20,7 +20,7 @@ void EjectFilament::Reset(uint8_t param) {
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
slot = param; slot = param;
if (mg::globals.FilamentLoaded()) { if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::InSelector) {
state = ProgressCode::UnloadingFilament; state = ProgressCode::UnloadingFilament;
unl.Reset(param); //@@TODO probably act on active extruder only unl.Reset(param); //@@TODO probably act on active extruder only
} else { } else {

View File

@ -34,6 +34,7 @@ bool FeedToBondtech::Step() {
if (mfs::fsensor.Pressed()) { if (mfs::fsensor.Pressed()) {
mm::motion.AbortPlannedMoves(); // stop pushing filament mm::motion.AbortPlannedMoves(); // stop pushing filament
mi::idler.Disengage(); mi::idler.Disengage();
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
state = DisengagingIdler; state = DisengagingIdler;
} else if (mm::motion.StallGuard(mm::Pulley)) { } else if (mm::motion.StallGuard(mm::Pulley)) {
// stall guard occurred during movement - the filament got stuck // stall guard occurred during movement - the filament got stuck
@ -48,7 +49,6 @@ bool FeedToBondtech::Step() {
state = OK; state = OK;
mm::motion.Disable(mm::Pulley); mm::motion.Disable(mm::Pulley);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on);
mg::globals.SetFilamentLoaded(true);
} }
return false; return false;
case OK: case OK:

View File

@ -26,6 +26,7 @@ bool FeedToFinda::Step() {
state = PushingFilament; state = PushingFilament;
mm::motion.InitAxis(mm::Pulley); mm::motion.InitAxis(mm::Pulley);
mm::motion.PlanMove<mm::Pulley>(config::feedToFinda, config::pulleyFeedrate); mm::motion.PlanMove<mm::Pulley>(config::feedToFinda, config::pulleyFeedrate);
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InSelector);
mui::userInput.Clear(); // remove all buffered events if any just before we wait for some input mui::userInput.Clear(); // remove all buffered events if any just before we wait for some input
} }
return false; return false;

View File

@ -23,8 +23,9 @@ bool RetractFromFinda::Step() {
return false; return false;
case UnloadBackToPTFE: case UnloadBackToPTFE:
if (mm::motion.QueueEmpty()) { // all moves have been finished if (mm::motion.QueueEmpty()) { // all moves have been finished
if (!mf::finda.Pressed()) { // FINDA switched off correctly if (!mf::finda.Pressed()) { // FINDA switched off correctly while the move was performed
state = OK; state = OK;
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::AtPulley);
} else { // FINDA didn't switch off } else { // FINDA didn't switch off
state = Failed; state = Failed;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);

View File

@ -19,7 +19,7 @@ void ToolChange::Reset(uint8_t param) {
return; return;
} }
if (param == mg::globals.ActiveSlot() && mg::globals.FilamentLoaded()) { if (param == mg::globals.ActiveSlot() && mg::globals.FilamentLoaded() == mg::FilamentLoadState::InNozzle) {
// we are already at the correct slot and the filament is loaded - nothing to do // we are already at the correct slot and the filament is loaded - nothing to do
dbg_logic_P(PSTR("we are already at the correct slot and the filament is loaded - nothing to do\n")); dbg_logic_P(PSTR("we are already at the correct slot and the filament is loaded - nothing to do\n"));
return; return;
@ -29,7 +29,7 @@ void ToolChange::Reset(uint8_t param) {
// or we are standing at another slot ... // or we are standing at another slot ...
plannedSlot = param; plannedSlot = param;
if (mg::globals.FilamentLoaded()) { if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::InSelector) {
dbg_logic_P(PSTR("Filament is loaded --> unload")); dbg_logic_P(PSTR("Filament is loaded --> unload"));
state = ProgressCode::UnloadingFilament; state = ProgressCode::UnloadingFilament;
unl.Reset(mg::globals.ActiveSlot()); unl.Reset(mg::globals.ActiveSlot());
@ -77,7 +77,7 @@ bool ToolChange::StepInner() {
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
} else { } else {
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
} }

View File

@ -59,7 +59,7 @@ bool UnloadFilament::StepInner() {
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
mm::motion.Disable(mm::Pulley); mm::motion.Disable(mm::Pulley);
mg::globals.SetFilamentLoaded(false); // filament unloaded mg::globals.SetFilamentLoaded(mg::FilamentLoadState::AtPulley); // filament unloaded
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
} }

View File

@ -23,7 +23,7 @@ void UnloadToFinda::Reset(uint8_t maxTries) {
bool UnloadToFinda::Step() { bool UnloadToFinda::Step() {
switch (state) { switch (state) {
case EngagingIdler: case EngagingIdler:
if (mg::globals.FilamentLoaded()) { if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::InSelector) {
state = UnloadingToFinda; state = UnloadingToFinda;
mm::motion.InitAxis(mm::Pulley); mm::motion.InitAxis(mm::Pulley);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0);
@ -34,6 +34,7 @@ bool UnloadToFinda::Step() {
case UnloadingToFinda: case UnloadingToFinda:
if (mi::idler.Engaged()) { if (mi::idler.Engaged()) {
state = WaitingForFINDA; state = WaitingForFINDA;
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InSelector);
mm::motion.PlanMove<mm::Pulley>(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, config::pulleyFeedrate); // @@TODO constants mm::motion.PlanMove<mm::Pulley>(-config::defaultBowdenLength - config::feedToFinda - config::filamentMinLoadedToMMU, config::pulleyFeedrate); // @@TODO constants
} }
return false; return false;

View File

@ -20,11 +20,11 @@ void Globals::SetActiveSlot(uint8_t newActiveSlot) {
mps::FilamentLoaded::set(activeSlot); mps::FilamentLoaded::set(activeSlot);
} }
bool Globals::FilamentLoaded() const { FilamentLoadState Globals::FilamentLoaded() const {
return filamentLoaded; return filamentLoaded;
} }
void Globals::SetFilamentLoaded(bool newFilamentLoaded) { void Globals::SetFilamentLoaded(FilamentLoadState newFilamentLoaded) {
filamentLoaded = newFilamentLoaded; filamentLoaded = newFilamentLoaded;
} }

View File

@ -6,6 +6,24 @@ namespace modules {
/// The globals namespace provides all necessary facilities related to keeping track of global state of the firmware. /// The globals namespace provides all necessary facilities related to keeping track of global state of the firmware.
namespace globals { namespace globals {
/// Different stages of filament load.
/// Beware:
/// - the firmware depends on the order of these values to check for various situations.
/// - the unit tests abuse the bitmask-like values to check for multiple situations easily
enum FilamentLoadState : uint8_t {
// NotLoaded = 0, ///< not loaded in the MMU at all @@TODO still need to decide whether this state is of any use to us
AtPulley = 1, ///< loaded to mmu (idler and pulley can grab it)
InSelector = 2, ///< loaded in selector (i.e. unsure where the filament is while doing some operation)
InNozzle = 4, ///< loaded into printer's filament sensor/nozzle
};
static_assert(
/*(FilamentLoadState::NotLoaded < FilamentLoadState::AtPulley)
&&*/
(FilamentLoadState::AtPulley < FilamentLoadState::InSelector)
&& (FilamentLoadState::InSelector < FilamentLoadState::InNozzle),
"incorrect order of Slot Filament Load States");
/// Globals keep track of global state variables in the firmware. /// Globals keep track of global state variables in the firmware.
/// So far only Active slot and Filament loaded variables are used. /// So far only Active slot and Filament loaded variables are used.
class Globals { class Globals {
@ -23,15 +41,12 @@ public:
void SetActiveSlot(uint8_t newActiveSlot); void SetActiveSlot(uint8_t newActiveSlot);
/// @returns true if filament is considered as loaded /// @returns true if filament is considered as loaded
/// @@TODO this may change meaning slightly as the MMU is primarily concerned FilamentLoadState FilamentLoaded() const;
/// about whether a piece of filament is stock up of a PTFE tube.
/// If that's true, we cannot move the selector.
bool FilamentLoaded() const;
/// Sets the filament loaded flag value, usually after some command/operation. /// Sets the filament loaded flag value, usually after some command/operation.
/// Also updates the EEPROM records accordingly /// Also updates the EEPROM records accordingly
/// @param newFilamentLoaded new state /// @param newFilamentLoaded new state
void SetFilamentLoaded(bool newFilamentLoaded); void SetFilamentLoaded(FilamentLoadState newFilamentLoaded);
/// @returns the total number of MMU errors so far /// @returns the total number of MMU errors so far
/// Errors are stored in the EEPROM /// Errors are stored in the EEPROM
@ -51,7 +66,7 @@ public:
private: private:
uint8_t activeSlot; uint8_t activeSlot;
bool filamentLoaded; FilamentLoadState filamentLoaded;
bool stealthMode; bool stealthMode;
}; };

View File

@ -25,7 +25,7 @@ void CutSlot(logic::CutFilament &cf, uint8_t cutSlot) {
ForceReinitAllAutomata(); ForceReinitAllAutomata();
REQUIRE(VerifyEnvironmentState(false, mi::Idler::IdleSlotIndex(), 0, false, false, ml::off, ml::off)); REQUIRE(VerifyEnvironmentState(mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), 0, false, false, ml::off, ml::off));
EnsureActiveSlotIndex(cutSlot); EnsureActiveSlotIndex(cutSlot);
@ -33,14 +33,14 @@ void CutSlot(logic::CutFilament &cf, uint8_t cutSlot) {
cf.Reset(cutSlot); cf.Reset(cutSlot);
// check initial conditions // check initial conditions
REQUIRE(VerifyState(cf, false, mi::Idler::IdleSlotIndex(), cutSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::SelectingFilamentSlot)); REQUIRE(VerifyState(cf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), cutSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::SelectingFilamentSlot));
// 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
// Beware - with the real positions of the selector, the number of steps needed to finish some states grows, so the ~40K steps here has a reason // Beware - with the real positions of the selector, the number of steps needed to finish some states grows, so the ~40K steps here has a reason
REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, selectorMoveMaxSteps)); REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, selectorMoveMaxSteps));
// idler and selector reached their target positions and the CF automaton will start feeding to FINDA as the next step // idler and selector reached their target positions and the CF automaton will start feeding to FINDA as the next step
REQUIRE(VerifyState(cf, false, cutSlot, cutSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda)); REQUIRE(VerifyState(cf, mg::FilamentLoadState::AtPulley, cutSlot, cutSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda));
// prepare for simulated finda trigger // prepare for simulated finda trigger
REQUIRE(WhileCondition( REQUIRE(WhileCondition(
@ -52,9 +52,7 @@ void CutSlot(logic::CutFilament &cf, uint8_t cutSlot) {
return cf.TopLevelState() == ProgressCode::FeedingToFinda; }, 5000)); return cf.TopLevelState() == ProgressCode::FeedingToFinda; }, 5000));
// filament fed to FINDA // filament fed to FINDA
//@@TODO filament loaded flag - decide whether the filament loaded flag means really loaded into the printer or just a piece of filament REQUIRE(VerifyState(cf, mg::FilamentLoadState::InSelector, cutSlot, cutSlot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToPulley));
// stuck out of the pulley to prevent movement of the selector
REQUIRE(VerifyState(cf, /*true*/ false, cutSlot, cutSlot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToPulley));
// pull it back to the pulley + simulate FINDA depress // pull it back to the pulley + simulate FINDA depress
REQUIRE(WhileCondition( REQUIRE(WhileCondition(
@ -65,23 +63,23 @@ void CutSlot(logic::CutFilament &cf, uint8_t cutSlot) {
} }
return cf.TopLevelState() == ProgressCode::UnloadingToPulley; }, 5000)); return cf.TopLevelState() == ProgressCode::UnloadingToPulley; }, 5000));
REQUIRE(VerifyState(cf, /*true*/ false, cutSlot, cutSlot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PreparingBlade)); REQUIRE(VerifyState(cf, mg::FilamentLoadState::AtPulley, cutSlot, cutSlot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PreparingBlade));
// now move the selector aside, prepare for cutting // now move the selector aside, prepare for cutting
REQUIRE(WhileTopState(cf, ProgressCode::PreparingBlade, 5000)); REQUIRE(WhileTopState(cf, ProgressCode::PreparingBlade, 5000));
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, cutSlot + 1, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PushingFilament)); REQUIRE(VerifyState2(cf, mg::FilamentLoadState::AtPulley, cutSlot, cutSlot + 1, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PushingFilament));
// pushing filament a bit for a cut // pushing filament a bit for a cut
REQUIRE(WhileTopState(cf, ProgressCode::PushingFilament, 5000)); REQUIRE(WhileTopState(cf, ProgressCode::PushingFilament, 5000));
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, cutSlot + 1, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PerformingCut)); REQUIRE(VerifyState2(cf, mg::FilamentLoadState::AtPulley, cutSlot, cutSlot + 1, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::PerformingCut));
// cutting // cutting
REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, selectorMoveMaxSteps)); REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, selectorMoveMaxSteps));
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, 0, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::ReturningSelector)); REQUIRE(VerifyState2(cf, mg::FilamentLoadState::AtPulley, cutSlot, 0, false, true, cutSlot, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::ReturningSelector));
// moving selector to the other end of its axis // moving selector to the other end of its axis
REQUIRE(WhileTopState(cf, ProgressCode::ReturningSelector, selectorMoveMaxSteps)); REQUIRE(WhileTopState(cf, ProgressCode::ReturningSelector, selectorMoveMaxSteps));
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, ms::Selector::IdleSlotIndex(), false, true, cutSlot, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState2(cf, mg::FilamentLoadState::AtPulley, cutSlot, ms::Selector::IdleSlotIndex(), false, true, cutSlot, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::OK));
} }
TEST_CASE("cut_filament::cut0", "[cut_filament]") { TEST_CASE("cut_filament::cut0", "[cut_filament]") {

View File

@ -41,7 +41,7 @@ void FailingIdler(hal::tmc2130::ErrorFlags ef, ErrorCode ec) {
// change the startup to what we need here // change the startup to what we need here
EnsureActiveSlotIndex(0); EnsureActiveSlotIndex(0);
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
// set FINDA ON + debounce // set FINDA ON + debounce
SetFINDAStateAndDebounce(true); SetFINDAStateAndDebounce(true);
@ -49,12 +49,12 @@ void FailingIdler(hal::tmc2130::ErrorFlags ef, ErrorCode ec) {
logic::UnloadFilament uf; logic::UnloadFilament uf;
// verify startup conditions // verify startup conditions
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), 0, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), 0, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
// UnloadFilament starts by engaging the idler (through the UnloadToFinda state machine) // UnloadFilament starts by engaging the idler (through the UnloadToFinda state machine)
uf.Reset(0); uf.Reset(0);
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), 0, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), 0, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda));
int failingStep = 5; int failingStep = 5;
REQUIRE(WhileCondition( REQUIRE(WhileCondition(

View File

@ -1,6 +1,6 @@
bool VerifyEnvironmentState(bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool VerifyEnvironmentState(mg::FilamentLoadState fls, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex,
bool findaPressed, bool pulleyEnabled, ml::Mode greenLEDMode, ml::Mode redLEDMode) { bool findaPressed, bool pulleyEnabled, ml::Mode greenLEDMode, ml::Mode redLEDMode) {
CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { CHECKED_ELSE(mg::globals.FilamentLoaded() & fls) { // beware - abusing the values as bit masks to detect multiple situations at once
return false; return false;
} }
CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) { CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) {
@ -45,10 +45,10 @@ bool VerifyEnvironmentState(bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t
// LED checked at selector's index // LED checked at selector's index
template<typename SM> template<typename SM>
bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool VerifyState(SM &uf, mg::FilamentLoadState fls, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex,
bool findaPressed, bool pulleyEnabled, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) { bool findaPressed, bool pulleyEnabled, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) {
VerifyEnvironmentState(filamentLoaded, idlerSlotIndex, selectorSlotIndex, findaPressed, pulleyEnabled, greenLEDMode, redLEDMode); VerifyEnvironmentState(fls, idlerSlotIndex, selectorSlotIndex, findaPressed, pulleyEnabled, greenLEDMode, redLEDMode);
CHECKED_ELSE(uf.Error() == err) { CHECKED_ELSE(uf.Error() == err) {
return false; return false;
@ -61,9 +61,9 @@ bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t se
// LED checked at their own ledCheckIndex index // LED checked at their own ledCheckIndex index
template<typename SM> template<typename SM>
bool VerifyState2(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex, bool VerifyState2(SM &uf, mg::FilamentLoadState fls, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex,
bool findaPressed, bool pulleyEnabled, uint8_t ledCheckIndex, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) { bool findaPressed, bool pulleyEnabled, uint8_t ledCheckIndex, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) {
CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { CHECKED_ELSE(mg::globals.FilamentLoaded() & fls) {
return false; return false;
} }
CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) { CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) {
@ -117,10 +117,10 @@ template<typename SM>
void InvalidSlot(SM &logicSM, uint8_t activeSlot, uint8_t invSlot){ void InvalidSlot(SM &logicSM, uint8_t activeSlot, uint8_t invSlot){
ForceReinitAllAutomata(); ForceReinitAllAutomata();
REQUIRE(VerifyEnvironmentState(false, mi::Idler::IdleSlotIndex(), 0, false, false, ml::off, ml::off)); REQUIRE(VerifyEnvironmentState(mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), 0, false, false, ml::off, ml::off));
EnsureActiveSlotIndex(activeSlot); EnsureActiveSlotIndex(activeSlot);
logicSM.Reset(invSlot); logicSM.Reset(invSlot);
REQUIRE(VerifyState(logicSM, false, mi::Idler::IdleSlotIndex(), activeSlot, false, false, ml::off, ml::off, ErrorCode::INVALID_TOOL, ProgressCode::OK)); REQUIRE(VerifyState(logicSM, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), activeSlot, false, false, ml::off, ml::off, ErrorCode::INVALID_TOOL, ProgressCode::OK));
} }

View File

@ -28,7 +28,7 @@ void LoadFilamentCommonSetup(uint8_t slot, logic::LoadFilament &lf) {
EnsureActiveSlotIndex(slot); EnsureActiveSlotIndex(slot);
// verify startup conditions // verify startup conditions
REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
// restart the automaton // restart the automaton
lf.Reset(slot); lf.Reset(slot);
@ -39,11 +39,11 @@ void LoadFilamentCommonSetup(uint8_t slot, logic::LoadFilament &lf) {
// no change in selector's position // no change in selector's position
// FINDA off // FINDA off
// green LED should blink, red off // green LED should blink, red off
REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::EngagingIdler)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::EngagingIdler));
// Stage 1 - engaging idler // Stage 1 - engaging idler
REQUIRE(WhileTopState(lf, ProgressCode::EngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(lf, ProgressCode::EngagingIdler, idlerEngageDisengageMaxSteps));
REQUIRE(VerifyState(lf, false, slot, slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, slot, slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda));
} }
void LoadFilamentSuccessful(uint8_t slot, logic::LoadFilament &lf) { void LoadFilamentSuccessful(uint8_t slot, logic::LoadFilament &lf) {
@ -57,7 +57,7 @@ void LoadFilamentSuccessful(uint8_t slot, logic::LoadFilament &lf) {
} }
return lf.TopLevelState() == ProgressCode::FeedingToFinda; }, return lf.TopLevelState() == ProgressCode::FeedingToFinda; },
5000)); 5000));
REQUIRE(VerifyState(lf, false, slot, slot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda));
// Stage 3 - retracting from finda // Stage 3 - retracting from finda
// we'll assume the finda is working correctly here // we'll assume the finda is working correctly here
@ -69,11 +69,11 @@ void LoadFilamentSuccessful(uint8_t slot, logic::LoadFilament &lf) {
} }
return lf.TopLevelState() == ProgressCode::RetractingFromFinda; }, return lf.TopLevelState() == ProgressCode::RetractingFromFinda; },
5000)); 5000));
REQUIRE(VerifyState(lf, false, slot, slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::DisengagingIdler)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, slot, slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::DisengagingIdler));
// Stage 4 - disengaging idler // Stage 4 - disengaging idler
REQUIRE(WhileTopState(lf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(lf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps));
REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, false, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK));
} }
TEST_CASE("load_filament::regular_load_to_slot_0-4", "[load_filament]") { TEST_CASE("load_filament::regular_load_to_slot_0-4", "[load_filament]") {
@ -88,11 +88,11 @@ void FailedLoadToFinda(uint8_t slot, logic::LoadFilament &lf) {
// Stage 2 - feeding to finda // Stage 2 - feeding to finda
// we'll assume the finda is defective here and does not trigger // we'll assume the finda is defective here and does not trigger
REQUIRE(WhileTopState(lf, ProgressCode::FeedingToFinda, 5000)); REQUIRE(WhileTopState(lf, ProgressCode::FeedingToFinda, 5000));
REQUIRE(VerifyState(lf, false, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRDisengagingIdler)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRDisengagingIdler));
// Stage 3 - disengaging idler in error mode // Stage 3 - disengaging idler in error mode
REQUIRE(WhileTopState(lf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(lf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps));
REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
} }
void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) { void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) {
@ -111,12 +111,12 @@ void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) {
lf.Step(); lf.Step();
} }
REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERREngagingIdler)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERREngagingIdler));
// Stage 4 - engage the idler // Stage 4 - engage the idler
REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
REQUIRE(VerifyState(lf, false, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRHelpingFilament)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRHelpingFilament));
} }
void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilament &lf) { void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilament &lf) {
@ -130,14 +130,14 @@ void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilamen
return lf.TopLevelState() == ProgressCode::ERRHelpingFilament; }, return lf.TopLevelState() == ProgressCode::ERRHelpingFilament; },
5000)); 5000));
REQUIRE(VerifyState(lf, false, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::FeedingToBondtech)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::FeedingToBondtech));
} }
void FailedLoadToFindaResolveHelpFindaDidntTrigger(uint8_t slot, logic::LoadFilament &lf) { void FailedLoadToFindaResolveHelpFindaDidntTrigger(uint8_t slot, logic::LoadFilament &lf) {
// Stage 5 - move the pulley a bit - no FINDA change // Stage 5 - move the pulley a bit - no FINDA change
REQUIRE(WhileTopState(lf, ProgressCode::ERRHelpingFilament, 5000)); REQUIRE(WhileTopState(lf, ProgressCode::ERRHelpingFilament, 5000));
REQUIRE(VerifyState(lf, false, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRDisengagingIdler)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRDisengagingIdler));
} }
TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_ok", "[load_filament]") { TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_ok", "[load_filament]") {

View File

@ -65,7 +65,7 @@ void ForceReinitAllAutomata() {
mm::ReinitMotion(); mm::ReinitMotion();
// let's assume we have the filament NOT loaded and active slot 0 // let's assume we have the filament NOT loaded and active slot 0
mg::globals.SetFilamentLoaded(false); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::AtPulley);
mg::globals.SetActiveSlot(0); mg::globals.SetActiveSlot(0);
} }

View File

@ -31,7 +31,7 @@ void FeedingToFinda(logic::ToolChange &tc, uint8_t toSlot) {
} }
return tc.TopLevelState() == ProgressCode::FeedingToFinda; }, return tc.TopLevelState() == ProgressCode::FeedingToFinda; },
200000UL)); 200000UL));
REQUIRE(VerifyState(tc, false, toSlot, toSlot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToBondtech)); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, toSlot, toSlot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToBondtech));
} }
void FeedingToBondtech(logic::ToolChange &tc, uint8_t toSlot) { void FeedingToBondtech(logic::ToolChange &tc, uint8_t toSlot) {
@ -44,7 +44,7 @@ void FeedingToBondtech(logic::ToolChange &tc, uint8_t toSlot) {
} }
return tc.TopLevelState() == ProgressCode::FeedingToBondtech; }, return tc.TopLevelState() == ProgressCode::FeedingToBondtech; },
200000UL)); 200000UL));
REQUIRE(VerifyState(tc, true, mi::Idler::IdleSlotIndex(), toSlot, true, false, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), toSlot, true, false, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK));
} }
void ToolChange(logic::ToolChange tc, uint8_t fromSlot, uint8_t toSlot) { void ToolChange(logic::ToolChange tc, uint8_t fromSlot, uint8_t toSlot) {
@ -63,14 +63,14 @@ void ToolChange(logic::ToolChange tc, uint8_t fromSlot, uint8_t toSlot) {
} }
return tc.TopLevelState() == ProgressCode::UnloadingFilament; }, return tc.TopLevelState() == ProgressCode::UnloadingFilament; },
200000UL)); 200000UL));
REQUIRE(mg::globals.FilamentLoaded() == false); REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::AtPulley);
FeedingToFinda(tc, toSlot); FeedingToFinda(tc, toSlot);
FeedingToBondtech(tc, toSlot); FeedingToBondtech(tc, toSlot);
REQUIRE(tc.TopLevelState() == ProgressCode::OK); REQUIRE(tc.TopLevelState() == ProgressCode::OK);
REQUIRE(mg::globals.FilamentLoaded() == true); REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::InNozzle);
REQUIRE(mg::globals.ActiveSlot() == toSlot); REQUIRE(mg::globals.ActiveSlot() == toSlot);
} }
@ -78,11 +78,11 @@ void NoToolChange(logic::ToolChange tc, uint8_t fromSlot, uint8_t toSlot) {
ForceReinitAllAutomata(); ForceReinitAllAutomata();
// the filament is LOADED // the filament is LOADED
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
EnsureActiveSlotIndex(fromSlot); EnsureActiveSlotIndex(fromSlot);
REQUIRE(VerifyEnvironmentState(true, mi::Idler::IdleSlotIndex(), toSlot, false, false, ml::off, ml::off)); REQUIRE(VerifyEnvironmentState(mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), toSlot, false, false, ml::off, ml::off));
// restart the automaton // restart the automaton
tc.Reset(toSlot); tc.Reset(toSlot);
@ -98,7 +98,7 @@ void JustLoadFilament(logic::ToolChange tc, uint8_t slot) {
EnsureActiveSlotIndex(slot); EnsureActiveSlotIndex(slot);
// verify filament NOT loaded // verify filament NOT loaded
REQUIRE(VerifyEnvironmentState(false, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off)); REQUIRE(VerifyEnvironmentState(mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off));
// restart the automaton // restart the automaton
tc.Reset(slot); tc.Reset(slot);
@ -108,7 +108,7 @@ void JustLoadFilament(logic::ToolChange tc, uint8_t slot) {
FeedingToBondtech(tc, slot); FeedingToBondtech(tc, slot);
REQUIRE(tc.TopLevelState() == ProgressCode::OK); REQUIRE(tc.TopLevelState() == ProgressCode::OK);
REQUIRE(mg::globals.FilamentLoaded() == true); REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::InNozzle);
REQUIRE(mg::globals.ActiveSlot() == slot); REQUIRE(mg::globals.ActiveSlot() == slot);
} }

View File

@ -28,13 +28,13 @@ void RegularUnloadFromSlot04Init(uint8_t slot, logic::UnloadFilament &uf) {
// change the startup to what we need here // change the startup to what we need here
EnsureActiveSlotIndex(slot); EnsureActiveSlotIndex(slot);
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
// set FINDA ON + debounce // set FINDA ON + debounce
SetFINDAStateAndDebounce(true); SetFINDAStateAndDebounce(true);
// verify startup conditions // verify startup conditions
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
// restart the automaton // restart the automaton
uf.Reset(slot); uf.Reset(slot);
@ -47,7 +47,8 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA on // FINDA on
// green LED should blink, red off // green LED should blink, red off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda)); REQUIRE(VerifyState(uf, (mg::FilamentLoadState)(mg::FilamentLoadState::InNozzle | mg::FilamentLoadState::InSelector),
mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda));
// run the automaton // run the automaton
// Stage 1 - unloading to FINDA // Stage 1 - unloading to FINDA
@ -65,7 +66,7 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA triggered off // FINDA triggered off
// green LED should be off // green LED should be off
REQUIRE(VerifyState(uf, true, slot, slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::DisengagingIdler)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::DisengagingIdler));
// Stage 2 - idler was engaged, disengage it // Stage 2 - idler was engaged, disengage it
REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps));
@ -75,7 +76,7 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still triggered off // FINDA still triggered off
// green LED should be off // green LED should be off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::AvoidingGrind)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::AvoidingGrind));
// Stage 3 - avoiding grind (whatever is that @@TODO) // Stage 3 - avoiding grind (whatever is that @@TODO)
REQUIRE(WhileTopState(uf, ProgressCode::AvoidingGrind, 5000)); REQUIRE(WhileTopState(uf, ProgressCode::AvoidingGrind, 5000));
@ -85,7 +86,7 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still triggered off // FINDA still triggered off
// green LED should be off // green LED should be off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::FinishingMoves)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::FinishingMoves));
// Stage 4 - finishing moves and setting global state correctly // Stage 4 - finishing moves and setting global state correctly
REQUIRE(WhileTopState(uf, ProgressCode::FinishingMoves, 5000)); REQUIRE(WhileTopState(uf, ProgressCode::FinishingMoves, 5000));
@ -95,11 +96,11 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still triggered off // FINDA still triggered off
// green LED should be OFF // green LED should be OFF
REQUIRE(VerifyState(uf, false, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
// Stage 5 - repeated calls to TopLevelState should return "OK" // Stage 5 - repeated calls to TopLevelState should return "OK"
REQUIRE(uf.TopLevelState() == ProgressCode::OK); REQUIRE(uf.TopLevelState() == ProgressCode::OK);
REQUIRE(mg::globals.FilamentLoaded() == false); REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::AtPulley);
REQUIRE(mf::finda.Pressed() == false); REQUIRE(mf::finda.Pressed() == false);
REQUIRE(uf.Error() == ErrorCode::OK); // no error REQUIRE(uf.Error() == ErrorCode::OK); // no error
} }
@ -123,10 +124,10 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
// set FINDA ON + debounce // set FINDA ON + debounce
SetFINDAStateAndDebounce(true); SetFINDAStateAndDebounce(true);
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
// verify startup conditions // verify startup conditions
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
// restart the automaton // restart the automaton
uf.Reset(slot); uf.Reset(slot);
@ -138,7 +139,7 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
// FINDA triggered off // FINDA triggered off
// green LED should be off // green LED should be off
// no error so far // no error so far
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda));
// run the automaton // run the automaton
// Stage 1 - unloading to FINDA - do NOT let it trigger - keep it pressed, the automaton should finish all moves with the pulley // Stage 1 - unloading to FINDA - do NOT let it trigger - keep it pressed, the automaton should finish all moves with the pulley
@ -150,7 +151,7 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still on // FINDA still on
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRDisengagingIdler)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRDisengagingIdler));
// Stage 2 - idler should get disengaged // Stage 2 - idler should get disengaged
REQUIRE(WhileTopState(uf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(uf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps));
@ -161,7 +162,7 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
// FINDA still on // FINDA still on
// red LED should blink // red LED should blink
// green LED should be off // green LED should be off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRWaitingForUser)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRWaitingForUser));
} }
void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) { void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) {
@ -186,7 +187,7 @@ void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still on // FINDA still on
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERREngagingIdler)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERREngagingIdler));
// Stage 4 - engage the idler // Stage 4 - engage the idler
REQUIRE(WhileTopState(uf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(WhileTopState(uf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
@ -196,7 +197,7 @@ void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still on // FINDA still on
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRHelpingFilament)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRHelpingFilament));
} }
void FindaDidntTriggerResolveHelpFindaTriggered(uint8_t slot, logic::UnloadFilament &uf) { void FindaDidntTriggerResolveHelpFindaTriggered(uint8_t slot, logic::UnloadFilament &uf) {
@ -215,7 +216,7 @@ void FindaDidntTriggerResolveHelpFindaTriggered(uint8_t slot, logic::UnloadFilam
// no change in selector's position // no change in selector's position
// FINDA depressed // FINDA depressed
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::DisengagingIdler)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::DisengagingIdler));
} }
void FindaDidntTriggerResolveHelpFindaDidntTrigger(uint8_t slot, logic::UnloadFilament &uf) { void FindaDidntTriggerResolveHelpFindaDidntTrigger(uint8_t slot, logic::UnloadFilament &uf) {
@ -227,7 +228,7 @@ void FindaDidntTriggerResolveHelpFindaDidntTrigger(uint8_t slot, logic::UnloadFi
// no change in selector's position // no change in selector's position
// FINDA still pressed // FINDA still pressed
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRDisengagingIdler)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRDisengagingIdler));
} }
TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_ok", "[unload_filament]") { TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_ok", "[unload_filament]") {
@ -270,7 +271,7 @@ void FindaDidntTriggerResolveTryAgain(uint8_t slot, logic::UnloadFilament &uf) {
// no change in selector's position // no change in selector's position
// FINDA still on // FINDA still on
// red LED should blink, green LED should be off // red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda)); REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, true, ml::off, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingToFinda));
} }
TEST_CASE("unload_filament::finda_didnt_trigger_resolve_try_again", "[unload_filament]") { TEST_CASE("unload_filament::finda_didnt_trigger_resolve_try_again", "[unload_filament]") {

View File

@ -27,7 +27,7 @@ TEST_CASE("unload_to_finda::regular_unload", "[unload_to_finda]") {
// we need finda ON // we need finda ON
SetFINDAStateAndDebounce(true); SetFINDAStateAndDebounce(true);
// and MMU "thinks" it has the filament loaded // and MMU "thinks" it has the filament loaded
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
logic::UnloadToFinda ff; logic::UnloadToFinda ff;
@ -57,6 +57,7 @@ TEST_CASE("unload_to_finda::regular_unload", "[unload_to_finda]") {
50000)); 50000));
REQUIRE(ff.State() == logic::UnloadToFinda::OK); REQUIRE(ff.State() == logic::UnloadToFinda::OK);
REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::InSelector);
} }
TEST_CASE("unload_to_finda::no_sense_FINDA_upon_start", "[unload_to_finda]") { TEST_CASE("unload_to_finda::no_sense_FINDA_upon_start", "[unload_to_finda]") {
@ -78,7 +79,7 @@ TEST_CASE("unload_to_finda::unload_without_FINDA_trigger", "[unload_to_finda]")
// we need finda ON // we need finda ON
SetFINDAStateAndDebounce(true); SetFINDAStateAndDebounce(true);
// and MMU "thinks" it has the filament loaded // and MMU "thinks" it has the filament loaded
mg::globals.SetFilamentLoaded(true); mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
logic::UnloadToFinda ff; logic::UnloadToFinda ff;
@ -109,4 +110,5 @@ TEST_CASE("unload_to_finda::unload_without_FINDA_trigger", "[unload_to_finda]")
50000)); 50000));
REQUIRE(ff.State() == logic::UnloadToFinda::Failed); REQUIRE(ff.State() == logic::UnloadToFinda::Failed);
REQUIRE(mg::globals.FilamentLoaded() == mg::FilamentLoadState::InSelector);
} }