Explain and fix the LED states while cutting filament
now the test is correct including LEDspull/44/head
parent
d81b00a0f8
commit
9efb127acb
|
|
@ -14,6 +14,7 @@ CutFilament cutFilament;
|
||||||
|
|
||||||
namespace mm = modules::motion;
|
namespace mm = modules::motion;
|
||||||
namespace mi = modules::idler;
|
namespace mi = modules::idler;
|
||||||
|
namespace ml = modules::leds;
|
||||||
namespace ms = modules::selector;
|
namespace ms = modules::selector;
|
||||||
namespace mg = modules::globals;
|
namespace mg = modules::globals;
|
||||||
|
|
||||||
|
|
@ -33,6 +34,8 @@ void CutFilament::SelectFilamentSlot() {
|
||||||
state = ProgressCode::SelectingFilamentSlot;
|
state = ProgressCode::SelectingFilamentSlot;
|
||||||
mi::idler.Engage(cutSlot);
|
mi::idler.Engage(cutSlot);
|
||||||
ms::selector.MoveToSlot(cutSlot);
|
ms::selector.MoveToSlot(cutSlot);
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0);
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CutFilament::Step() {
|
bool CutFilament::Step() {
|
||||||
|
|
@ -89,6 +92,8 @@ bool CutFilament::Step() {
|
||||||
case ProgressCode::ReturningSelector:
|
case ProgressCode::ReturningSelector:
|
||||||
if (ms::selector.Slot() == 5) { // selector returned to position, feed the filament back to FINDA
|
if (ms::selector.Slot() == 5) { // selector returned to position, feed the filament back to FINDA
|
||||||
state = ProgressCode::OK;
|
state = ProgressCode::OK;
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on);
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
|
||||||
feed.Reset(true);
|
feed.Reset(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ void CutSlot(uint8_t cutSlot) {
|
||||||
ForceReinitAllAutomata();
|
ForceReinitAllAutomata();
|
||||||
|
|
||||||
logic::CutFilament cf;
|
logic::CutFilament cf;
|
||||||
|
REQUIRE(VerifyState(cf, false, 5, 0, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
|
||||||
|
|
||||||
EnsureActiveSlotIndex(cutSlot);
|
EnsureActiveSlotIndex(cutSlot);
|
||||||
|
|
||||||
|
|
@ -41,19 +42,19 @@ void CutSlot(uint8_t cutSlot) {
|
||||||
cf.Reset(cutSlot);
|
cf.Reset(cutSlot);
|
||||||
|
|
||||||
// check initial conditions
|
// check initial conditions
|
||||||
REQUIRE(VerifyState(cf, false, 5, cutSlot, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::SelectingFilamentSlot));
|
REQUIRE(VerifyState(cf, false, 5, cutSlot, false, ml::blink0, ml::off, ErrorCode::OK, 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
|
||||||
REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, 5000));
|
REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, 5000));
|
||||||
|
|
||||||
// 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, ml::off, ml::off, ErrorCode::OK, ProgressCode::FeedingToFinda));
|
REQUIRE(VerifyState(cf, false, cutSlot, cutSlot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::FeedingToFinda));
|
||||||
|
|
||||||
// prepare for simulated finda trigger
|
// prepare for simulated finda trigger
|
||||||
REQUIRE(WhileCondition(
|
REQUIRE(WhileCondition(
|
||||||
cf,
|
cf,
|
||||||
[&](int step) -> bool {
|
[&](int step) -> bool {
|
||||||
if( step == 1000 ){ // simulate FINDA trigger - will get pressed in 100 steps (due to debouncing)
|
if( step == 100 ){ // simulate FINDA trigger - will get pressed in 100 steps (due to debouncing)
|
||||||
hal::adc::SetADC(1, 900);
|
hal::adc::SetADC(1, 900);
|
||||||
}
|
}
|
||||||
return cf.TopLevelState() == ProgressCode::FeedingToFinda; }, 5000));
|
return cf.TopLevelState() == ProgressCode::FeedingToFinda; }, 5000));
|
||||||
|
|
@ -76,19 +77,19 @@ void CutSlot(uint8_t cutSlot) {
|
||||||
|
|
||||||
// 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(VerifyState(cf, /*true*/ false, cutSlot, cutSlot + 1, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::PushingFilament));
|
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, cutSlot + 1, false, cutSlot, ml::blink0, ml::off, ErrorCode::OK, 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(VerifyState(cf, /*true*/ false, cutSlot, cutSlot + 1, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::PerformingCut));
|
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, cutSlot + 1, false, cutSlot, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::PerformingCut));
|
||||||
|
|
||||||
// cutting
|
// cutting
|
||||||
REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, 5000));
|
REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, 10000));
|
||||||
REQUIRE(VerifyState(cf, /*true*/ false, cutSlot, 0, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::ReturningSelector));
|
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, 0, false, cutSlot, ml::blink0, ml::off, ErrorCode::OK, 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, 5000));
|
REQUIRE(WhileTopState(cf, ProgressCode::ReturningSelector, 5000));
|
||||||
REQUIRE(VerifyState(cf, /*true*/ false, cutSlot, 5, false, ml::off, ml::off, ErrorCode::OK, ProgressCode::OK));
|
REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, 5, false, cutSlot, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("cut_filament::cut0", "[cut_filament]") {
|
TEST_CASE("cut_filament::cut0", "[cut_filament]") {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 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, 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) {
|
||||||
|
|
@ -7,8 +8,45 @@ bool VerifyState(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t se
|
||||||
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; }
|
||||||
CHECKED_ELSE(mf::finda.Pressed() == findaPressed) { return false; }
|
CHECKED_ELSE(mf::finda.Pressed() == findaPressed) { return false; }
|
||||||
|
|
||||||
|
for(uint8_t ledIndex = 0; ledIndex < 5; ++ledIndex){
|
||||||
|
if( ledIndex != selectorSlotIndex ){
|
||||||
|
// the other LEDs should be off
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledIndex, ml::red) == ml::off) { return false; }
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledIndex, ml::green) == ml::off) { return false; }
|
||||||
|
} else {
|
||||||
CHECKED_ELSE(ml::leds.Mode(selectorSlotIndex, ml::red) == redLEDMode) { return false; }
|
CHECKED_ELSE(ml::leds.Mode(selectorSlotIndex, ml::red) == redLEDMode) { return false; }
|
||||||
CHECKED_ELSE(ml::leds.Mode(selectorSlotIndex, ml::green) == greenLEDMode) { return false; }
|
CHECKED_ELSE(ml::leds.Mode(selectorSlotIndex, ml::green) == greenLEDMode) { return false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECKED_ELSE(uf.Error() == err) { return false; }
|
||||||
|
CHECKED_ELSE(uf.TopLevelState() == topLevelProgress) { return false; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LED checked at their own ledCheckIndex index
|
||||||
|
template<typename SM>
|
||||||
|
bool VerifyState2(SM &uf, bool filamentLoaded, uint8_t idlerSlotIndex, uint8_t selectorSlotIndex,
|
||||||
|
bool findaPressed, uint8_t ledCheckIndex, ml::Mode greenLEDMode, ml::Mode redLEDMode, ErrorCode err, ProgressCode topLevelProgress) {
|
||||||
|
CHECKED_ELSE(mg::globals.FilamentLoaded() == filamentLoaded) { return false; }
|
||||||
|
CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex)) { return false; }
|
||||||
|
CHECKED_ELSE(mi::idler.Engaged() == (idlerSlotIndex < 5)) { 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(mf::finda.Pressed() == findaPressed) { return false; }
|
||||||
|
|
||||||
|
for(uint8_t ledIndex = 0; ledIndex < 5; ++ledIndex){
|
||||||
|
if( ledIndex != ledCheckIndex ){
|
||||||
|
// the other LEDs should be off
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledIndex, ml::red) == ml::off) { return false; }
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledIndex, ml::green) == ml::off) { return false; }
|
||||||
|
} else {
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledCheckIndex, ml::red) == redLEDMode) { return false; }
|
||||||
|
CHECKED_ELSE(ml::leds.Mode(ledCheckIndex, ml::green) == greenLEDMode) { return false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CHECKED_ELSE(uf.Error() == err) { return false; }
|
CHECKED_ELSE(uf.Error() == err) { return false; }
|
||||||
CHECKED_ELSE(uf.TopLevelState() == topLevelProgress) { return false; }
|
CHECKED_ELSE(uf.TopLevelState() == topLevelProgress) { return false; }
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue