tests: homing: cleanup SimulateFailedHomeFirstTime

We never home Idler and Selector at the same time. I think we did early perhaps, but now the selector always waits
for the idler homing to be valid.
pull/337/head
Guðni Már Gilbert 2024-12-27 18:11:34 +00:00
parent 79b0d0bec0
commit c2bf5fc3e0
1 changed files with 20 additions and 24 deletions

View File

@ -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<mm::S_pos_t>(config::selectorLimits.lenght) + 1;
{
// do 5 steps until we trigger the simulated StallGuard
constexpr uint32_t idlerStepsFwd = mm::unitToSteps<mm::I_pos_t>(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<mm::I_pos_t>(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();