Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/modules/selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void Selector::PrepareMoveToPlannedSlot() {

void Selector::PlanHomingMoveForward() {
state = PlannedHome;
plannedHomeTimer = 0; // reset timeout counter when entering PlannedHome
dbg_logic_P(PSTR("Plan Homing Selector Forward"));
}

Expand Down Expand Up @@ -110,6 +111,13 @@ bool Selector::Step() {
state = HomeForward;
mm::motion.PlanMove<mm::Selector>(mm::unitToAxisUnit<mm::S_pos_t>(-config::selectorLimits.lenght * 2),
mm::unitToAxisUnit<mm::S_speed_t>(mg::globals.SelectorHomingFeedrate_mm_s()));
} else if (++plannedHomeTimer >= 30000U) {
// Idler did not become homing-valid within ~30 000 main-loop iterations.
// This breaks a potential deadlock where the idler is stuck in a non-error
// state (e.g. Ready with homingValid==false) that WaitForModulesErrorRecovery
// cannot detect. HomeFailed() transitions selector to HomingFailed, which IS
// detected and surfaces an error screen to the user.
HomeFailed();
}
return false;
case HomeForward:
Expand Down
7 changes: 6 additions & 1 deletion src/modules/selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace mm = modules::motion;
class Selector : public mm::MovableBase {
public:
inline constexpr Selector()
: MovableBase(mm::Selector) {}
: MovableBase(mm::Selector)
, plannedHomeTimer(0) {}

/// Plan move of the selector to a specific filament slot
/// @param slot index to move to
Expand Down Expand Up @@ -49,6 +50,10 @@ class Selector : public mm::MovableBase {
virtual void FinishMove() override;

private:
/// Counts main-loop iterations spent in PlannedHome while waiting for the idler to become HomingValid.
/// Guards against indefinite deadlock: if the idler never becomes valid, HomeFailed() fires and the
/// WaitForModulesErrorRecovery path surfaces the error to the user.
uint16_t plannedHomeTimer;
};

/// The one and only instance of Selector in the FW
Expand Down
Loading