Remove handling of left+right buttons in error states

Based on long-term test experience - saves some code + prevents the user from entering hard-to-understand states.
Only Retry remains as the one and only way of recovering from errors.
pull/258/head
D.R.racer 2022-11-09 18:00:28 +01:00 committed by DRracer
parent 2b5a129c7d
commit 75a0ebaf0e
7 changed files with 226 additions and 340 deletions

View File

@ -121,9 +121,6 @@ bool LoadFilament::StepInner() {
// waiting for user buttons and/or a command from the printer
mui::Event ev = mui::userInput.ConsumeEvent();
switch (ev) {
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
GoToErrEngagingIdler();
break;
case mui::Event::Middle: // try again the whole sequence
// however it depends on the state of FINDA - if it is on, we must perform unload first
if (!mf::finda.Pressed()) {
@ -132,40 +129,11 @@ bool LoadFilament::StepInner() {
GoToRetractingFromFinda();
}
break;
case mui::Event::Right: // problem resolved - the user pushed the fillament by hand?
// we should check the state of all the sensors and either report another error or confirm the correct state
// First invalidate homing flags as the user may have moved the Idler or Selector accidentally
InvalidateHoming();
if (!mf::finda.Pressed()) {
// FINDA is still NOT pressed - that smells bad
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
state = ProgressCode::ERRWaitingForUser; // stand still
} else {
// all sensors are ok - pull the filament back
GoToRetractingFromFinda();
}
break;
default: // no event, continue waiting for user input
break;
}
return false;
}
case ProgressCode::ERREngagingIdler:
if (mi::idler.Engaged()) {
state = ProgressCode::ERRHelpingFilament;
mpu::pulley.PlanMove(config::pulleyHelperMove, config::pulleySlowFeedrate);
}
return false;
case ProgressCode::ERRHelpingFilament:
if (mf::finda.Pressed()) {
// the help was enough to press the FINDA, we are ok, continue normally
GoToRetractingFromFinda();
} else if (mm::motion.QueueEmpty()) {
// helped a bit, but FINDA didn't trigger, return to the main error state
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON);
}
return false;
default: // we got into an unhandled state, better report it
state = ProgressCode::ERRInternal;
error = ErrorCode::INTERNAL;

View File

@ -19,10 +19,10 @@ enum class ProgressCode : uint_fast8_t {
FinishingMoves, // P9
ERRDisengagingIdler, // P10
ERREngagingIdler, // P11
ERREngagingIdler, // P11 - unused: intended for SlowLoad which is removed now
ERRWaitingForUser, // P12
ERRInternal, // P13
ERRHelpingFilament, // P14
ERRHelpingFilament, // P14 - unused: intended for SlowLoad which is removed now
ERRTMCFailed, // P15
UnloadingFilament, // P16

View File

@ -121,9 +121,6 @@ bool ToolChange::StepInner() {
// waiting for user buttons and/or a command from the printer
mui::Event ev = mui::userInput.ConsumeEvent();
switch (ev) {
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
GoToErrEngagingIdler();
break;
case mui::Event::Middle: // try again the whole sequence
// It looks like we don't have to reset the whole state machine but jump straight into the feeding phase.
// The reasons are multiple:
@ -165,53 +162,11 @@ bool ToolChange::StepInner() {
}
}
break;
case mui::Event::Right: // problem resolved - the user pushed the fillament by hand?
// we should check the state of all the sensors and either report another error or confirm the correct state
// First invalidate homing flags as the user may have moved the Idler or Selector accidentally
InvalidateHoming();
if (!mf::finda.Pressed()) {
// FINDA is still NOT pressed - that smells bad
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
state = ProgressCode::ERRWaitingForUser; // stand still
} else if (!mfs::fsensor.Pressed()) {
// printer's filament sensor is still NOT pressed - that smells bad
mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::InSelector); // only assume the filament is in selector
error = ErrorCode::FSENSOR_DIDNT_SWITCH_ON;
state = ProgressCode::ERRWaitingForUser; // stand still - we may even try loading the filament into the nozzle
} else {
// all sensors are ok, we assume the user pushed the filament into the nozzle
mg::globals.SetFilamentLoaded(plannedSlot, mg::FilamentLoadState::InNozzle);
ToolChangeFinishedCorrectly();
}
break;
default: // no event, continue waiting for user input
break;
}
return false;
}
case ProgressCode::ERREngagingIdler:
if (mi::idler.Engaged()) {
state = ProgressCode::ERRHelpingFilament;
mpu::pulley.PlanMove(config::pulleyHelperMove, config::pulleySlowFeedrate);
}
return false;
case ProgressCode::ERRHelpingFilament:
// @@TODO helping filament needs improvement - the filament should try to move forward as long as the button is pressed
if (mf::finda.Pressed()) {
// the help was enough to press the FINDA, we are ok, continue normally
GoToFeedingToBondtech();
} else if (mfs::fsensor.Pressed()) {
// the help was enough to press the filament sensor, we are ok, continue normally
GoToFeedingToBondtech();
// Beware, when the fsensor triggers, we still need to push the filament into the nozzle/gears
// which requires restarting James from its last stage
james.GoToPushToNozzle();
} else if (mm::motion.QueueEmpty()) {
// helped a bit, but FINDA/Fsensor didn't trigger, return to the main error state
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_ON);
}
return false;
default: // we got into an unhandled state, better report it
state = ProgressCode::ERRInternal;
error = ErrorCode::INTERNAL;

View File

@ -93,9 +93,6 @@ bool UnloadFilament::StepInner() {
// waiting for user buttons and/or a command from the printer
mui::Event ev = mui::userInput.ConsumeEvent();
switch (ev) {
case mui::Event::Left: // try to manually unload just a tiny bit - help the filament with the pulley
GoToErrEngagingIdler();
break;
case mui::Event::Middle: // try again the whole sequence
// First invalidate homing flags as the user may have moved the Idler or Selector accidentally
InvalidateHoming();
@ -110,45 +107,11 @@ bool UnloadFilament::StepInner() {
GoToRecheckFilamentAgainstFINDA();
}
break;
case mui::Event::Right: // problem resolved - the user pulled the fillament by hand
// we should check the state of all the sensors and either report another error or confirm the correct state
// First invalidate homing flags as the user may have moved the Idler or Selector accidentally
InvalidateHoming();
if (mfs::fsensor.Pressed()) {
// printer's filament sensor is still pressed - that smells bad
error = ErrorCode::FSENSOR_DIDNT_SWITCH_OFF;
state = ProgressCode::ERRWaitingForUser; // stand still
} else if (mf::finda.Pressed()) {
// FINDA is still pressed - that smells bad
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
state = ProgressCode::ERRWaitingForUser; // stand still
} else {
// all sensors are ok, but re-check the position of the filament against FINDA
GoToRecheckFilamentAgainstFINDA();
}
break;
default:
break;
}
return false;
}
case ProgressCode::ERREngagingIdler:
if (mi::idler.Engaged()) {
state = ProgressCode::ERRHelpingFilament;
mpu::pulley.PlanMove(-config::pulleyHelperMove, config::pulleySlowFeedrate);
}
return false;
case ProgressCode::ERRHelpingFilament:
if (!mf::finda.Pressed()) {
// the help was enough to depress the FINDA, we are ok, continue normally
state = ProgressCode::DisengagingIdler;
error = ErrorCode::RUNNING;
} else if (mm::motion.QueueEmpty()) {
// helped a bit, but FINDA didn't trigger, return to the main error state
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF);
}
return false;
case ProgressCode::FeedingToFinda:
// recovery mode - we assume the filament is somewhere between the idle position and FINDA - thus blocking the selector
if (feed.Step()) {

View File

@ -122,50 +122,50 @@ void FailedLoadToFinda(uint8_t slot, logic::LoadFilament &lf) {
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
}
void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) {
// Stage 3 - the user has to do something
// there are 3 options:
// - help the filament a bit
// - try again the whole sequence
// - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
//void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) {
// // Stage 3 - the user has to do something
// // there are 3 options:
// // - help the filament a bit
// // - try again the whole sequence
// // - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
// In this case we check the first option
PressButtonAndDebounce(lf, mb::Left, false);
// // In this case we check the first option
// PressButtonAndDebounce(lf, mb::Left, false);
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERREngagingIdler));
// REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERREngagingIdler));
if (!mi::idler.HomingValid()) {
SimulateIdlerHoming(lf);
}
// if (!mi::idler.HomingValid()) {
// SimulateIdlerHoming(lf);
// }
// Stage 4 - engage the idler
REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
// // Stage 4 - engage the idler
// REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
// REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
ClearButtons(lf);
}
// ClearButtons(lf);
//}
void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilament &lf) {
// Stage 5 - move the pulley a bit - simulate FINDA depress
REQUIRE(WhileCondition(
lf,
[&](uint32_t step) -> bool {
if(step == 100){ // on 100th step make FINDA trigger
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
}
return lf.TopLevelState() == ProgressCode::ERRHelpingFilament; },
5000));
//void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilament &lf) {
// // Stage 5 - move the pulley a bit - simulate FINDA depress
// REQUIRE(WhileCondition(
// lf,
// [&](uint32_t step) -> bool {
// if(step == 100){ // on 100th step make FINDA trigger
// hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
// }
// return lf.TopLevelState() == ProgressCode::ERRHelpingFilament; },
// 5000));
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, 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));
//}
void FailedLoadToFindaResolveHelpFindaDidntTrigger(uint8_t slot, logic::LoadFilament &lf) {
// Stage 5 - move the pulley a bit - no FINDA change
REQUIRE(WhileTopState(lf, ProgressCode::ERRHelpingFilament, 5000));
//void FailedLoadToFindaResolveHelpFindaDidntTrigger(uint8_t slot, logic::LoadFilament &lf) {
// // Stage 5 - move the pulley a bit - no FINDA change
// REQUIRE(WhileTopState(lf, ProgressCode::ERRHelpingFilament, 5000));
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
}
// REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
//}
void FailedLoadToFindaResolveManual(uint8_t slot, logic::LoadFilament &lf) {
// simulate the user fixed the issue himself
@ -240,25 +240,25 @@ void FailedLoadToFindaResolveTryAgain(uint8_t slot, logic::LoadFilament &lf) {
LoadFilamentSuccessfulWithRehomeSelector(slot, lf);
}
TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_ok", "[load_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::LoadFilament lf;
LoadFilamentCommonSetup(slot, lf, true);
FailedLoadToFinda(slot, lf);
FailedLoadToFindaResolveHelp(slot, lf);
FailedLoadToFindaResolveHelpFindaTriggered(slot, lf);
}
}
//TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_ok", "[load_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::LoadFilament lf;
// LoadFilamentCommonSetup(slot, lf, true);
// FailedLoadToFinda(slot, lf);
// FailedLoadToFindaResolveHelp(slot, lf);
// FailedLoadToFindaResolveHelpFindaTriggered(slot, lf);
// }
//}
TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_fail", "[load_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::LoadFilament lf;
LoadFilamentCommonSetup(slot, lf, true);
FailedLoadToFinda(slot, lf);
FailedLoadToFindaResolveHelp(slot, lf);
FailedLoadToFindaResolveHelpFindaDidntTrigger(slot, lf);
}
}
//TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_help_second_fail", "[load_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::LoadFilament lf;
// LoadFilamentCommonSetup(slot, lf, true);
// FailedLoadToFinda(slot, lf);
// FailedLoadToFindaResolveHelp(slot, lf);
// FailedLoadToFindaResolveHelpFindaDidntTrigger(slot, lf);
// }
//}
TEST_CASE("load_filament::invalid_slot", "[load_filament]") {
for (uint8_t activeSlot = 0; activeSlot < config::toolCount; ++activeSlot) {
@ -283,14 +283,14 @@ TEST_CASE("load_filament::state_machine_reusal", "[load_filament]") {
}
}
TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_manual", "[load_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::LoadFilament lf;
LoadFilamentCommonSetup(slot, lf, true);
FailedLoadToFinda(slot, lf);
FailedLoadToFindaResolveManual(slot, lf);
}
}
//TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_manual", "[load_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::LoadFilament lf;
// LoadFilamentCommonSetup(slot, lf, true);
// FailedLoadToFinda(slot, lf);
// FailedLoadToFindaResolveManual(slot, lf);
// }
//}
TEST_CASE("load_filament::failed_load_to_finda_0-4_resolve_manual_no_FINDA", "[load_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {

View File

@ -212,32 +212,32 @@ void ToolChangeFailLoadToFinda(logic::ToolChange &tc, uint8_t fromSlot, uint8_t
SimulateErrDisengagingIdler(tc, ErrorCode::FINDA_DIDNT_SWITCH_ON);
}
void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) {
// now waiting for user input
REQUIRE_FALSE(mui::userInput.AnyEvent());
PressButtonAndDebounce(tc, mb::Left, true);
//void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) {
// // now waiting for user input
// REQUIRE_FALSE(mui::userInput.AnyEvent());
// PressButtonAndDebounce(tc, mb::Left, true);
REQUIRE(WhileTopState(tc, ProgressCode::ERREngagingIdler, 5000UL));
ClearButtons(tc);
// REQUIRE(WhileTopState(tc, ProgressCode::ERREngagingIdler, 5000UL));
// ClearButtons(tc);
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, toSlot, toSlot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
// REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, toSlot, toSlot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
// try push more, if FINDA triggers, continue loading
REQUIRE(WhileCondition(
tc,
[&](uint32_t step) -> bool {
if(step == 20){ // on 20th step make FINDA trigger
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
}
return tc.TopLevelState() == ProgressCode::ERRHelpingFilament; },
2000UL));
// // try push more, if FINDA triggers, continue loading
// REQUIRE(WhileCondition(
// tc,
// [&](uint32_t step) -> bool {
// if(step == 20){ // on 20th step make FINDA trigger
// hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
// }
// return tc.TopLevelState() == ProgressCode::ERRHelpingFilament; },
// 2000UL));
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, 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));
FeedingToBondtech(tc, toSlot);
// FeedingToBondtech(tc, toSlot);
CheckFinishedCorrectly(tc, toSlot);
}
// CheckFinishedCorrectly(tc, toSlot);
//}
void ToolChangeFailLoadToFindaMiddleBtn(logic::ToolChange &tc, uint8_t toSlot) {
// now waiting for user input
@ -313,17 +313,17 @@ void ToolChangeFailLoadToFindaRightBtn(logic::ToolChange &tc, uint8_t toSlot) {
ClearButtons(tc);
}
TEST_CASE("tool_change::load_fail_FINDA_resolve_btnL", "[tool_change]") {
logic::ToolChange tc;
for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
if (fromSlot != toSlot) {
ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
ToolChangeFailLoadToFindaLeftBtn(tc, toSlot);
}
}
}
}
//TEST_CASE("tool_change::load_fail_FINDA_resolve_btnL", "[tool_change]") {
// logic::ToolChange tc;
// for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
// for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
// if (fromSlot != toSlot) {
// ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
// ToolChangeFailLoadToFindaLeftBtn(tc, toSlot);
// }
// }
// }
//}
TEST_CASE("tool_change::load_fail_FINDA_resolve_btnM", "[tool_change]") {
logic::ToolChange tc;
@ -337,29 +337,29 @@ TEST_CASE("tool_change::load_fail_FINDA_resolve_btnM", "[tool_change]") {
}
}
TEST_CASE("tool_change::load_fail_FINDA_resolve_btnR_FINDA_FSensor", "[tool_change]") {
logic::ToolChange tc;
for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
if (fromSlot != toSlot) {
ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
ToolChangeFailLoadToFindaRightBtnFINDA_FSensor(tc, toSlot);
}
}
}
}
//TEST_CASE("tool_change::load_fail_FINDA_resolve_btnR_FINDA_FSensor", "[tool_change]") {
// logic::ToolChange tc;
// for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
// for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
// if (fromSlot != toSlot) {
// ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
// ToolChangeFailLoadToFindaRightBtnFINDA_FSensor(tc, toSlot);
// }
// }
// }
//}
TEST_CASE("tool_change::load_fail_FINDA_resolve_btnR_FINDA", "[tool_change]") {
logic::ToolChange tc;
for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
if (fromSlot != toSlot) {
ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
ToolChangeFailLoadToFindaRightBtnFINDA(tc, toSlot);
}
}
}
}
//TEST_CASE("tool_change::load_fail_FINDA_resolve_btnR_FINDA", "[tool_change]") {
// logic::ToolChange tc;
// for (uint8_t fromSlot = 0; fromSlot < config::toolCount; ++fromSlot) {
// for (uint8_t toSlot = 0; toSlot < config::toolCount; ++toSlot) {
// if (fromSlot != toSlot) {
// ToolChangeFailLoadToFinda(tc, fromSlot, toSlot);
// ToolChangeFailLoadToFindaRightBtnFINDA(tc, toSlot);
// }
// }
// }
//}
void ToolChangeFailFSensor(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
using namespace std::placeholders;

View File

@ -164,92 +164,92 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, false, 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) {
// Stage 3 - the user has to do something
// there are 3 options:
// - help the filament a bit
// - try again the whole sequence
// - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
// // Stage 3 - the user has to do something
// // there are 3 options:
// // - help the filament a bit
// // - try again the whole sequence
// // - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
// In this case we check the first option
// // In this case we check the first option
REQUIRE_FALSE(mui::userInput.AnyEvent());
// Perform press on button 0 + debounce
PressButtonAndDebounce(uf, mb::Left, false);
REQUIRE_FALSE(mui::userInput.AnyEvent()); // button processed and nothing remains
// REQUIRE_FALSE(mui::userInput.AnyEvent());
// // Perform press on button 0 + debounce
// PressButtonAndDebounce(uf, mb::Left, false);
// REQUIRE_FALSE(mui::userInput.AnyEvent()); // button processed and nothing remains
// we still think we have filament loaded at this stage
// idler should have been disengaged
// no change in selector's position
// FINDA still on
// red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERREngagingIdler));
// // we still think we have filament loaded at this stage
// // idler should have been disengaged
// // no change in selector's position
// // FINDA still on
// // red LED should blink, green LED should be off
// REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERREngagingIdler));
if (!mi::idler.HomingValid()) {
SimulateIdlerHoming(uf);
}
// if (!mi::idler.HomingValid()) {
// SimulateIdlerHoming(uf);
// }
// Stage 4 - engage the idler
REQUIRE(WhileTopState(uf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
// // Stage 4 - engage the idler
// REQUIRE(WhileTopState(uf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps));
// we still think we have filament loaded at this stage
// idler should be engaged
// no change in selector's position
// FINDA still on
// red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
}
// // we still think we have filament loaded at this stage
// // idler should be engaged
// // no change in selector's position
// // FINDA still on
// // red LED should blink, green LED should be off
// REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament));
//}
void FindaDidntTriggerResolveHelpFindaTriggered(uint8_t slot, logic::UnloadFilament &uf) {
// Stage 5 - move the pulley a bit - simulate FINDA depress
REQUIRE(WhileCondition(
uf,
[&](uint32_t step) -> bool {
if(step == 100){ // on 100th step make FINDA trigger
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::low);
}
return uf.TopLevelState() == ProgressCode::ERRHelpingFilament; },
5000));
//void FindaDidntTriggerResolveHelpFindaTriggered(uint8_t slot, logic::UnloadFilament &uf) {
// // Stage 5 - move the pulley a bit - simulate FINDA depress
// REQUIRE(WhileCondition(
// uf,
// [&](uint32_t step) -> bool {
// if(step == 100){ // on 100th step make FINDA trigger
// hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::low);
// }
// return uf.TopLevelState() == ProgressCode::ERRHelpingFilament; },
// 5000));
// we still think we have filament loaded at this stage
// idler should be engaged
// no change in selector's position
// FINDA depressed
// red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::DisengagingIdler));
}
// // we still think we have filament loaded at this stage
// // idler should be engaged
// // no change in selector's position
// // FINDA depressed
// // red LED should blink, green LED should be off
// 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) {
// Stage 5 - move the pulley a bit - no FINDA change
REQUIRE(WhileTopState(uf, ProgressCode::ERRHelpingFilament, 5000));
//void FindaDidntTriggerResolveHelpFindaDidntTrigger(uint8_t slot, logic::UnloadFilament &uf) {
// // Stage 5 - move the pulley a bit - no FINDA change
// REQUIRE(WhileTopState(uf, ProgressCode::ERRHelpingFilament, 5000));
// we still think we have filament loaded at this stage
// idler should be engaged
// no change in selector's position
// FINDA still pressed
// red LED should blink, green LED should be off
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
}
// // we still think we have filament loaded at this stage
// // idler should be engaged
// // no change in selector's position
// // FINDA still pressed
// // red LED should blink, green LED should be off
// REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
//}
TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_ok", "[unload_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::UnloadFilament uf;
FindaDidntTriggerCommonSetup(slot, uf);
FindaDidntTriggerResolveHelp(slot, uf);
FindaDidntTriggerResolveHelpFindaTriggered(slot, uf);
}
}
//TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_ok", "[unload_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::UnloadFilament uf;
// FindaDidntTriggerCommonSetup(slot, uf);
// FindaDidntTriggerResolveHelp(slot, uf);
// FindaDidntTriggerResolveHelpFindaTriggered(slot, uf);
// }
//}
TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_fail", "[unload_filament]") {
// the same with different end scenario
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::UnloadFilament uf;
FindaDidntTriggerCommonSetup(slot, uf);
FindaDidntTriggerResolveHelp(slot, uf);
FindaDidntTriggerResolveHelpFindaDidntTrigger(slot, uf);
}
}
//TEST_CASE("unload_filament::finda_didnt_trigger_resolve_help_second_fail", "[unload_filament]") {
// // the same with different end scenario
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::UnloadFilament uf;
// FindaDidntTriggerCommonSetup(slot, uf);
// FindaDidntTriggerResolveHelp(slot, uf);
// FindaDidntTriggerResolveHelpFindaDidntTrigger(slot, uf);
// }
//}
void FindaDidntTriggerResolveTryAgain(uint8_t slot, logic::UnloadFilament &uf) {
// Stage 3 - the user has to do something
@ -348,13 +348,13 @@ void FailedUnloadResolveManualFSensorOn(uint8_t slot, logic::UnloadFilament &uf)
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::FSENSOR_DIDNT_SWITCH_OFF, ProgressCode::ERRWaitingForUser));
}
TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual", "[unload_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::UnloadFilament uf;
FindaDidntTriggerCommonSetup(slot, uf);
FailedUnloadResolveManual(slot, uf);
}
}
//TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual", "[unload_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::UnloadFilament uf;
// FindaDidntTriggerCommonSetup(slot, uf);
// FailedUnloadResolveManual(slot, uf);
// }
//}
TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual_FINDA_on", "[unload_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
@ -364,43 +364,43 @@ TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual_FINDA_on",
}
}
TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual_FSensor_on", "[unload_filament]") {
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
logic::UnloadFilament uf;
FindaDidntTriggerCommonSetup(slot, uf);
FailedUnloadResolveManualFSensorOn(slot, uf);
}
}
//TEST_CASE("unload_filament::failed_unload_to_finda_0-4_resolve_manual_FSensor_on", "[unload_filament]") {
// for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
// logic::UnloadFilament uf;
// FindaDidntTriggerCommonSetup(slot, uf);
// FailedUnloadResolveManualFSensorOn(slot, uf);
// }
//}
TEST_CASE("unload_filament::unload_homing_retry", "[unload_filament][homing]") {
uint8_t slot = 0;
logic::UnloadFilament uf;
FindaDidntTriggerCommonSetup(slot, uf);
//TEST_CASE("unload_filament::unload_homing_retry", "[unload_filament][homing]") {
// uint8_t slot = 0;
// logic::UnloadFilament uf;
// FindaDidntTriggerCommonSetup(slot, uf);
// simulate the user fixed the issue himself (not really important, we are after a failed homing of the selector)
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::low);
PressButtonAndDebounce(uf, mb::Right, false);
SimulateIdlerHoming(uf); // make Idler happy
// // simulate the user fixed the issue himself (not really important, we are after a failed homing of the selector)
// hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::low);
// PressButtonAndDebounce(uf, mb::Right, false);
// SimulateIdlerHoming(uf); // make Idler happy
REQUIRE(WhileCondition(uf, std::bind(SimulateFeedToFINDA, _1, 100), 5000));
// REQUIRE(WhileCondition(uf, std::bind(SimulateFeedToFINDA, _1, 100), 5000));
REQUIRE(WhileCondition(uf, std::bind(SimulateRetractFromFINDA, _1, 100), 5000));
REQUIRE(WhileCondition(
uf, [&](uint32_t) { return uf.State() == ProgressCode::RetractingFromFinda; }, 50000));
// REQUIRE(WhileCondition(uf, std::bind(SimulateRetractFromFINDA, _1, 100), 5000));
// REQUIRE(WhileCondition(
// uf, [&](uint32_t) { return uf.State() == ProgressCode::RetractingFromFinda; }, 50000));
REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps));
// REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps));
// now fail homing of the Selector
REQUIRE(SimulateFailedHomeSelectorRepeated(uf));
// // now fail homing of the Selector
// REQUIRE(SimulateFailedHomeSelectorRepeated(uf));
// REQUIRE(VerifyState(uf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::OK));
REQUIRE(uf.State() == ProgressCode::Homing);
REQUIRE(uf.Error() == ErrorCode::RUNNING);
// // REQUIRE(VerifyState(uf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::OK));
// REQUIRE(uf.State() == ProgressCode::Homing);
// REQUIRE(uf.Error() == ErrorCode::RUNNING);
// one retry
REQUIRE(SimulateFailedHomeSelectorRepeated(uf));
// // one retry
// REQUIRE(SimulateFailedHomeSelectorRepeated(uf));
// success
SimulateSelectorHoming(uf);
REQUIRE(VerifyState(uf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
}
// // success
// SimulateSelectorHoming(uf);
// REQUIRE(VerifyState(uf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
//}