diff --git a/tests/unit/logic/stubs/homing.cpp b/tests/unit/logic/stubs/homing.cpp index 8f08af4..ff8d9ef 100644 --- a/tests/unit/logic/stubs/homing.cpp +++ b/tests/unit/logic/stubs/homing.cpp @@ -59,6 +59,18 @@ void SimulateIdlerAndSelectorHoming(logic::CommandBase &cb) { void SimulateIdlerHoming(logic::CommandBase &cb) { uint32_t idlerStepsFwd = mm::unitToSteps(config::idlerLimits.lenght - 5.0_deg); + + // Sometimes the initial idler state is Ready. Let's wait for the firmware to start + // homing. + REQUIRE(WhileCondition( + cb, + [&](uint32_t) { return mi::idler.State() == mm::MovableBase::Ready; }, + 5000)); + + // At this point the idler should always be homing forward. + REQUIRE((int)mi::idler.State() == (int)mm::MovableBase::HomeForward); + + // Simulate the idler steps in one direction (forward) for (uint32_t i = 0; i < idlerStepsFwd; ++i) { main_loop(); cb.Step(); @@ -69,6 +81,8 @@ void SimulateIdlerHoming(logic::CommandBase &cb) { cb.Step(); mm::motion.StallGuardReset(mm::Idler); + REQUIRE((int)mi::idler.State() == (int)mm::MovableBase::HomeBack); + // now do a correct amount of steps of each axis towards the other end uint32_t idlerSteps = mm::unitToSteps(config::idlerLimits.lenght); uint32_t maxSteps = idlerSteps + 1; @@ -83,6 +97,9 @@ void SimulateIdlerHoming(logic::CommandBase &cb) { mm::motion.StallGuardReset(mm::Idler); } } + + // If the homing has failed, the axis length was too short. + REQUIRE(!((mi::idler.State() & mm::MovableBase::HomingFailed) == mm::MovableBase::HomingFailed)); } void SimulateIdlerWaitForHomingValid(logic::CommandBase &cb) {