Feed to FINDA unit tests : green
parent
d9b368bb92
commit
398181e26c
|
|
@ -36,9 +36,7 @@ bool FeedToFinda::Step() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case PushingFilament: {
|
case PushingFilament: {
|
||||||
bool fp = mf::finda.Pressed();
|
if (mf::finda.Pressed() || (feedPhaseLimited && mb::buttons.AnyButtonPressed())) { // @@TODO probably also a command from the printer
|
||||||
bool abp = mb::buttons.AnyButtonPressed();
|
|
||||||
if (fp || (feedPhaseLimited && abp)) { // @@TODO probably also a command from the printer
|
|
||||||
mm::motion.AbortPlannedMoves(); // stop pushing filament
|
mm::motion.AbortPlannedMoves(); // stop pushing filament
|
||||||
// FINDA triggered - that means it works and detected the filament tip
|
// FINDA triggered - that means it works and detected the filament tip
|
||||||
state = UnloadBackToPTFE;
|
state = UnloadBackToPTFE;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace leds {
|
||||||
|
|
||||||
LEDs leds;
|
LEDs leds;
|
||||||
|
|
||||||
void LED::SetMode(Mode mode) {
|
void LED::SetMode(leds::Mode mode) {
|
||||||
state.mode = mode;
|
state.mode = mode;
|
||||||
// set initial state of LEDs correctly - transition from one mode to another
|
// set initial state of LEDs correctly - transition from one mode to another
|
||||||
switch (state.mode) {
|
switch (state.mode) {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ class LED {
|
||||||
public:
|
public:
|
||||||
constexpr inline LED() = default;
|
constexpr inline LED() = default;
|
||||||
void SetMode(Mode mode);
|
void SetMode(Mode mode);
|
||||||
|
inline leds::Mode Mode() const { return (leds::Mode)state.mode; }
|
||||||
|
|
||||||
/// @returns true if the LED shines
|
/// @returns true if the LED shines
|
||||||
bool Step(bool oddPeriod);
|
bool Step(bool oddPeriod);
|
||||||
|
|
@ -67,6 +68,13 @@ public:
|
||||||
leds[index].SetMode(mode);
|
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 {
|
inline bool LedOn(uint8_t index) const {
|
||||||
return leds[index].On();
|
return leds[index].On();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,16 @@
|
||||||
|
|
||||||
using Catch::Matchers::Equals;
|
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>
|
template <typename COND>
|
||||||
bool WhileCondition(logic::FeedToFinda &ff, COND cond, uint32_t maxLoops = 5000) {
|
bool WhileCondition(logic::FeedToFinda &ff, COND cond, uint32_t maxLoops = 5000) {
|
||||||
while (cond() && --maxLoops) {
|
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
|
// it should have instructed the selector and idler to move to slot 1
|
||||||
// check if the idler and selector have the right command
|
// check if the idler and selector have the right command
|
||||||
CHECK(modules::motion::axes[modules::motion::Idler].targetPos == 0); // @@TODO constants
|
CHECK(mm::axes[mm::Idler].targetPos == 0); // @@TODO constants
|
||||||
CHECK(modules::motion::axes[modules::motion::Selector].targetPos == 0); // @@TODO constants
|
CHECK(mm::axes[mm::Selector].targetPos == 0); // @@TODO constants
|
||||||
CHECK(modules::motion::axes[modules::motion::Idler].enabled == true); // @@TODO constants
|
CHECK(mm::axes[mm::Idler].enabled == true); // @@TODO constants
|
||||||
CHECK(modules::motion::axes[modules::motion::Selector].enabled == true); // @@TODO constants
|
|
||||||
|
|
||||||
// engaging idler
|
// engaging idler
|
||||||
REQUIRE(WhileCondition(
|
REQUIRE(WhileCondition(
|
||||||
ff,
|
ff,
|
||||||
[&]() { return !modules::idler::idler.Engaged(); },
|
[&]() { return !mi::idler.Engaged(); },
|
||||||
5000));
|
5000));
|
||||||
|
|
||||||
// idler engaged, selector in position, we'll start pushing filament
|
// idler engaged, selector in position, we'll start pushing filament
|
||||||
REQUIRE(ff.State() == FeedToFinda::PushingFilament);
|
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)
|
// 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
|
// 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
|
// 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(
|
REQUIRE(WhileCondition(
|
||||||
ff,
|
ff,
|
||||||
|
|
@ -80,12 +89,12 @@ TEST_CASE("feed_to_finda::feed_phase_unlimited", "[feed_to_finda]") {
|
||||||
REQUIRE(ff.State() == FeedToFinda::DisengagingIdler);
|
REQUIRE(ff.State() == FeedToFinda::DisengagingIdler);
|
||||||
REQUIRE(WhileCondition(
|
REQUIRE(WhileCondition(
|
||||||
ff,
|
ff,
|
||||||
[&]() { return modules::idler::idler.Engaged(); },
|
[&]() { return mi::idler.Engaged(); },
|
||||||
5000));
|
5000));
|
||||||
|
|
||||||
// state machine finished ok, the green LED should be on
|
// state machine finished ok, the green LED should be on
|
||||||
REQUIRE(ff.State() == FeedToFinda::OK);
|
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
|
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
|
// it should have instructed the selector and idler to move to slot 1
|
||||||
// check if the idler and selector have the right command
|
// check if the idler and selector have the right command
|
||||||
CHECK(modules::motion::axes[modules::motion::Idler].targetPos == 0); // @@TODO constants
|
CHECK(mm::axes[mm::Idler].targetPos == 0); // @@TODO constants
|
||||||
CHECK(modules::motion::axes[modules::motion::Selector].targetPos == 0); // @@TODO constants
|
CHECK(mm::axes[mm::Selector].targetPos == 0); // @@TODO constants
|
||||||
|
|
||||||
// engaging idler
|
// engaging idler
|
||||||
REQUIRE(WhileCondition(
|
REQUIRE(WhileCondition(
|
||||||
ff,
|
ff,
|
||||||
[&]() { return !modules::idler::idler.Engaged(); },
|
[&]() { return !mi::idler.Engaged(); },
|
||||||
5000));
|
5000));
|
||||||
|
|
||||||
// idler engaged, we'll start pushing filament
|
// idler engaged, we'll start pushing filament
|
||||||
REQUIRE(ff.State() == FeedToFinda::PushingFilament);
|
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)
|
// 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
|
// 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(
|
REQUIRE(WhileCondition(
|
||||||
ff, // boo, this formatting is UGLY!
|
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
|
// the FINDA didn't trigger, we should be in the Failed state
|
||||||
REQUIRE(ff.State() == FeedToFinda::Failed);
|
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
|
REQUIRE(ff.Step() == true); // the automaton finished its work, any consecutive calls to Step must return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue