From 9bf2b401e4a409ca335100365baf4b8f7005c922 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 19 Nov 2021 11:12:32 +0100 Subject: [PATCH] Avoid homing the idler at start when printing --- src/main.cpp | 4 ++-- src/modules/idler.cpp | 19 +++++++++++++++++-- src/modules/idler.h | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ec79219..7132fdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,8 +113,8 @@ void setup() { } ml::leds.Step(); - // Idler will home on its own by default - // Selector decides whether homing is possible + // Idler and Selector decide whether homing is possible/safe + mi::idler.Init(); ms::selector.Init(); } diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 3f757a7..bc6b923 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -1,6 +1,7 @@ /// @file idler.cpp #include "idler.h" #include "buttons.h" +#include "globals.h" #include "leds.h" #include "motion.h" #include "permanent_storage.h" @@ -76,7 +77,10 @@ Idler::OperationResult Idler::Engage(uint8_t slot) { } // coordinates invalid, first home, then engage - if (!homingValid) { + // avoid homing if filament in fsensor or in nozzle + // - the printer may be printing right now and holding the filament + // against the pulley even for a short period of time may not be healthy + if (!homingValid && mg::globals.FilamentLoaded() < mg::InFSensor) { PlanHome(mm::Idler); return OperationResult::Accepted; } @@ -102,7 +106,7 @@ bool Idler::Step() { PerformHome(mm::Idler); return false; case Ready: - if (!homingValid) { + if (!homingValid && mg::globals.FilamentLoaded() < mg::InFSensor) { PlanHome(mm::Idler); return false; } @@ -114,5 +118,16 @@ bool Idler::Step() { } } +void Idler::Init() { + if (mg::globals.FilamentLoaded() < mg::InFSensor) { + // home the Idler only in case we don't have filament loaded in the printer (or at least we think we don't) + PlanHome(mm::Idler); + } else { + // otherwise set selector's position according to know slot positions (and pretend it is correct) + mm::motion.SetPosition(mm::Idler, SlotPosition(mg::globals.ActiveSlot()).v); + InvalidateHoming(); // and plan homing sequence ASAP + } +} + } // namespace idler } // namespace modules diff --git a/src/modules/idler.h b/src/modules/idler.h index bdae406..7f75ef6 100644 --- a/src/modules/idler.h +++ b/src/modules/idler.h @@ -45,6 +45,12 @@ public: /// @returns the index of idle position of the idler, usually 5 in case of 0-4 valid indices of filament slots inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; } + /// Initializes the idler after restart/cold boot + /// Reads the active slot from the EEPROM and decides if the idler is safe to move (not hold the filament while printing) + /// - free -> home the idler + /// - blocked -> set idler's position according to the active filament slot + void Init(); + protected: virtual void PrepareMoveToPlannedSlot() override; virtual void PlanHomingMove() override;