diff --git a/tests/unit/logic/stubs/homing.cpp b/tests/unit/logic/stubs/homing.cpp index 13488e6..244333e 100644 --- a/tests/unit/logic/stubs/homing.cpp +++ b/tests/unit/logic/stubs/homing.cpp @@ -185,33 +185,40 @@ bool SimulateFailedHomeSelectorPostfix(logic::CommandBase &cb) { } bool SimulateFailedHomeFirstTime(logic::CommandBase &cb) { - if (mi::idler.HomingValid()) - return false; - if (ms::selector.HomingValid()) - return false; + REQUIRE(!mi::idler.HomingValid()); + REQUIRE(!ms::selector.HomingValid()); + + // Idler homing is successful + SimulateIdlerHoming(cb); + SimulateIdlerWaitForHomingValid(cb); + + // Selector homes once the idler homing is valid. + REQUIRE(mi::idler.HomingValid()); + REQUIRE(!ms::selector.HomingValid()); + + // The selector will only rehome once the idler homing is valid. At that moment + // the state will change to HomeForward. + REQUIRE(WhileCondition( + cb, + [&](uint32_t) { return ms::selector.State() != mm::MovableBase::HomeForward; }, + 5000)); constexpr uint32_t selectorSteps = mm::unitToSteps(config::selectorLimits.lenght) + 1; { // do 5 steps until we trigger the simulated StallGuard - constexpr uint32_t idlerStepsFwd = mm::unitToSteps(config::idlerLimits.lenght - 5.0_deg); - static_assert(idlerStepsFwd < selectorSteps); // beware, we expect that the Idler homes faster than Selector (less steps) - for (uint32_t i = 0; i < idlerStepsFwd; ++i) { + for (uint32_t i = 0; i < selectorSteps; ++i) { main_loop(); cb.Step(); } mm::TriggerStallGuard(mm::Selector); - mm::TriggerStallGuard(mm::Idler); main_loop(); cb.Step(); mm::motion.StallGuardReset(mm::Selector); - mm::motion.StallGuardReset(mm::Idler); } - // now do a correct amount of steps of each axis towards the other end - constexpr uint32_t idlerSteps = mm::unitToSteps(config::idlerLimits.lenght); - // now do LESS steps than expected to simulate something is blocking the selector - constexpr uint32_t selectorTriggerShort = std::min(idlerSteps, selectorSteps) / 2; + // now do LESS steps than expected to simulate something is blocking the selector + constexpr uint32_t selectorTriggerShort = selectorSteps / 2; constexpr uint32_t maxSteps = selectorTriggerShort + 1; { for (uint32_t i = 0; i < maxSteps; ++i) { @@ -225,17 +232,6 @@ bool SimulateFailedHomeFirstTime(logic::CommandBase &cb) { } } - // make sure the Idler finishes its homing procedure (makes further checks much easier) - for (uint32_t i = maxSteps; i < idlerSteps + 1; ++i) { - main_loop(); - cb.Step(); - if (i == idlerSteps) { - mm::TriggerStallGuard(mm::Idler); - } else { - mm::motion.StallGuardReset(mm::Idler); - } - } - while (!(ms::selector.State() & mm::MovableBase::OnHold)) { main_loop(); cb.Step();