Feed to FINDA unit tests : green

pull/26/head
D.R.racer 2021-06-18 07:46:55 +02:00 committed by DRracer
parent d9b368bb92
commit 398181e26c
4 changed files with 35 additions and 18 deletions

View File

@ -36,9 +36,7 @@ bool FeedToFinda::Step() {
}
return false;
case PushingFilament: {
bool fp = mf::finda.Pressed();
bool abp = mb::buttons.AnyButtonPressed();
if (fp || (feedPhaseLimited && abp)) { // @@TODO probably also a command from the printer
if (mf::finda.Pressed() || (feedPhaseLimited && mb::buttons.AnyButtonPressed())) { // @@TODO probably also a command from the printer
mm::motion.AbortPlannedMoves(); // stop pushing filament
// FINDA triggered - that means it works and detected the filament tip
state = UnloadBackToPTFE;

View File

@ -6,7 +6,7 @@ namespace leds {
LEDs leds;
void LED::SetMode(Mode mode) {
void LED::SetMode(leds::Mode mode) {
state.mode = mode;
// set initial state of LEDs correctly - transition from one mode to another
switch (state.mode) {

View File

@ -32,6 +32,7 @@ class LED {
public:
constexpr inline LED() = default;
void SetMode(Mode mode);
inline leds::Mode Mode() const { return (leds::Mode)state.mode; }
/// @returns true if the LED shines
bool Step(bool oddPeriod);
@ -67,6 +68,13 @@ public:
leds[index].SetMode(mode);
}
inline leds::Mode Mode(uint8_t slot, Color color) {
return Mode(slot * 2 + color);
}
inline leds::Mode Mode(uint8_t index) {
return leds[index].Mode();
}
inline bool LedOn(uint8_t index) const {
return leds[index].On();
}

View File

@ -19,6 +19,16 @@
using Catch::Matchers::Equals;
namespace mm = modules::motion;
namespace mf = modules::finda;
namespace mi = modules::idler;
namespace ml = modules::leds;
namespace mb = modules::buttons;
namespace mg = modules::globals;
namespace ms = modules::selector;
namespace ha = hal::adc;
template <typename COND>
bool WhileCondition(logic::FeedToFinda &ff, COND cond, uint32_t maxLoops = 5000) {
while (cond() && --maxLoops) {
@ -43,25 +53,24 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") {
// it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command
CHECK(modules::motion::axes[modules::motion::Idler].targetPos == 0); // @@TODO constants
CHECK(modules::motion::axes[modules::motion::Selector].targetPos == 0); // @@TODO constants
CHECK(modules::motion::axes[modules::motion::Idler].enabled == true); // @@TODO constants
CHECK(modules::motion::axes[modules::motion::Selector].enabled == true); // @@TODO constants
CHECK(mm::axes[mm::Idler].targetPos == 0); // @@TODO constants
CHECK(mm::axes[mm::Selector].targetPos == 0); // @@TODO constants
CHECK(mm::axes[mm::Idler].enabled == true); // @@TODO constants
// engaging idler
REQUIRE(WhileCondition(
ff,
[&]() { return !modules::idler::idler.Engaged(); },
[&]() { return !mi::idler.Engaged(); },
5000));
// idler engaged, selector in position, we'll start pushing filament
REQUIRE(ff.State() == FeedToFinda::PushingFilament);
// at least at the beginning the LED should shine green (it should be blinking, but this mode has been already verified in the LED's unit test)
REQUIRE(modules::leds::leds.LedOn(modules::globals::globals.ActiveSlot(), modules::leds::Color::green));
REQUIRE(ml::leds.LedOn(mg::globals.ActiveSlot(), ml::Color::green));
// now let the filament be pushed into the FINDA - do 500 steps without triggering the condition
// and then let the simulated ADC channel 1 create a FINDA switch
hal::adc::ReinitADC(1, hal::adc::TADCData({ 600, 700, 800, 900 }), 1);
ha::ReinitADC(1, ha::TADCData({ 600, 700, 800, 900 }), 1);
REQUIRE(WhileCondition(
ff,
@ -80,12 +89,12 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") {
REQUIRE(ff.State() == FeedToFinda::DisengagingIdler);
REQUIRE(WhileCondition(
ff,
[&]() { return modules::idler::idler.Engaged(); },
[&]() { return mi::idler.Engaged(); },
5000));
// state machine finished ok, the green LED should be on
REQUIRE(ff.State() == FeedToFinda::OK);
REQUIRE(modules::leds::leds.LedOn(modules::globals::globals.ActiveSlot(), modules::leds::Color::green));
REQUIRE(ml::leds.LedOn(mg::globals.ActiveSlot(), ml::Color::green));
REQUIRE(ff.Step() == true); // the automaton finished its work, any consecutive calls to Step must return true
}
@ -105,22 +114,22 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") {
// it should have instructed the selector and idler to move to slot 1
// check if the idler and selector have the right command
CHECK(modules::motion::axes[modules::motion::Idler].targetPos == 0); // @@TODO constants
CHECK(modules::motion::axes[modules::motion::Selector].targetPos == 0); // @@TODO constants
CHECK(mm::axes[mm::Idler].targetPos == 0); // @@TODO constants
CHECK(mm::axes[mm::Selector].targetPos == 0); // @@TODO constants
// engaging idler
REQUIRE(WhileCondition(
ff,
[&]() { return !modules::idler::idler.Engaged(); },
[&]() { return !mi::idler.Engaged(); },
5000));
// idler engaged, we'll start pushing filament
REQUIRE(ff.State() == FeedToFinda::PushingFilament);
// at least at the beginning the LED should shine green (it should be blinking, but this mode has been already verified in the LED's unit test)
REQUIRE(modules::leds::leds.LedOn(modules::globals::globals.ActiveSlot(), modules::leds::Color::green));
REQUIRE(ml::leds.Mode(mg::globals.ActiveSlot(), ml::Color::green) == ml::blink0);
// now let the filament be pushed into the FINDA - but we make sure the FINDA doesn't trigger at all
hal::adc::ReinitADC(1, hal::adc::TADCData({ 0 }), 100);
ha::ReinitADC(1, ha::TADCData({ 0 }), 100);
REQUIRE(WhileCondition(
ff, // boo, this formatting is UGLY!
@ -129,6 +138,8 @@ TEST_CASE("feed_to_finda::FINDA_failed", "[feed_to_finda]") {
// the FINDA didn't trigger, we should be in the Failed state
REQUIRE(ff.State() == FeedToFinda::Failed);
REQUIRE(ml::leds.Mode(mg::globals.ActiveSlot(), ml::Color::green) == ml::off);
REQUIRE(ml::leds.Mode(mg::globals.ActiveSlot(), ml::Color::red) == ml::blink0);
REQUIRE(ff.Step() == true); // the automaton finished its work, any consecutive calls to Step must return true
}