Finish EjectFilament operation

pull/257/head
D.R.racer 2022-12-28 12:20:59 +01:00 committed by DRracer
parent 88a489e3cb
commit 414ee1e0ca
3 changed files with 41 additions and 16 deletions

View File

@ -9,6 +9,7 @@
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/pulley.h" #include "../modules/pulley.h"
#include "../modules/selector.h" #include "../modules/selector.h"
#include "../modules/user_input.h"
#include "../debug.h" #include "../debug.h"
namespace logic { namespace logic {
@ -23,10 +24,7 @@ bool EjectFilament::Reset(uint8_t param) {
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
slot = param; slot = param;
if (mg::globals.FilamentLoaded() == mg::FilamentLoadState::NotLoaded) { if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::AtPulley) {
FinishedOK();
dbg_logic_P(PSTR("Already ejected"));
} else if (mg::globals.FilamentLoaded() >= mg::FilamentLoadState::AtPulley) {
state = ProgressCode::UnloadingFilament; state = ProgressCode::UnloadingFilament;
unl.Reset(param); //@@TODO probably act on active extruder only unl.Reset(param); //@@TODO probably act on active extruder only
} else { } else {
@ -38,8 +36,9 @@ bool EjectFilament::Reset(uint8_t param) {
void EjectFilament::MoveSelectorAside() { void EjectFilament::MoveSelectorAside() {
state = ProgressCode::ParkingSelector; state = ProgressCode::ParkingSelector;
const uint8_t selectorParkedPos = (slot <= 2) ? 4 : 0; const uint8_t selectorParkedPos = (slot <= 2) ? 4 : 0;
mi::idler.Engage(slot); if (ms::selector.MoveToSlot(selectorParkedPos) == ms::Selector::OperationResult::Refused) {
ms::selector.MoveToSlot(selectorParkedPos); GoToErrDisengagingIdler(ErrorCode::FINDA_FLICKERS);
}
} }
bool EjectFilament::StepInner() { bool EjectFilament::StepInner() {
@ -54,26 +53,46 @@ bool EjectFilament::StepInner() {
break; break;
case ProgressCode::ParkingSelector: case ProgressCode::ParkingSelector:
if (mm::motion.QueueEmpty()) { // selector parked aside if (mm::motion.QueueEmpty()) { // selector parked aside
state = ProgressCode::EngagingIdler;
mi::idler.Engage(slot);
}
break;
case ProgressCode::EngagingIdler:
if (mi::idler.Engaged()) {
state = ProgressCode::EjectingFilament; state = ProgressCode::EjectingFilament;
mpu::pulley.InitAxis(); mpu::pulley.InitAxis();
mpu::pulley.PlanMove(-config::filamentMinLoadedToMMU, config::pulleySlowFeedrate); mpu::pulley.PlanMove(config::ejectFromCuttingEdge, config::pulleySlowFeedrate);
} }
break; break;
case ProgressCode::EjectingFilament: case ProgressCode::EjectingFilament:
if (mm::motion.QueueEmpty()) { // filament ejected if (mm::motion.QueueEmpty()) { // filament ejected
state = ProgressCode::DisengagingIdler; GoToErrDisengagingIdler(ErrorCode::FILAMENT_EJECTED);
mi::idler.Disengage();
} }
break; break;
case ProgressCode::DisengagingIdler: case ProgressCode::ERRDisengagingIdler:
if (mi::idler.Disengaged()) { // idler disengaged ErrDisengagingIdler();
mpu::pulley.Disable(); return false;
mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::NotLoaded); case ProgressCode::ERRWaitingForUser: {
FinishedOK(); // waiting for user buttons and/or a command from the printer
mui::Event ev = mui::userInput.ConsumeEvent();
switch (ev) {
case mui::Event::Middle:
switch (error) {
case ErrorCode::FILAMENT_EJECTED: // the user clicked "Done", we can finish the Eject operation
FinishedOK();
break;
case ErrorCode::FINDA_FLICKERS:
MoveSelectorAside();
break;
default:
break;
}
default:
break;
} }
break; return false;
}
case ProgressCode::OK: case ProgressCode::OK:
dbg_logic_fP(PSTR("FilamentLoadState after Eject %d"), mg::globals.FilamentLoaded());
return true; return true;
default: // we got into an unhandled state, better report it default: // we got into an unhandled state, better report it
state = ProgressCode::ERRInternal; state = ProgressCode::ERRInternal;

View File

@ -19,7 +19,11 @@ static constexpr modules::motion::P_speed_t ejectSpeed = 1000.0_P_mm_s; //@@TODO
/// - If there is still some filament detected by PINDA unload it first. /// - If there is still some filament detected by PINDA unload it first.
/// - If we want to eject fil 0-2, move selector to position 4 (right). /// - If we want to eject fil 0-2, move selector to position 4 (right).
/// - If we want to eject fil 3-4, move selector to position 0 (left) /// - If we want to eject fil 3-4, move selector to position 0 (left)
/// - emit a message to the user: Filament ejected, press Continue to confirm removal and finish (or something like that)
/// Optionally, we can also move the selector to its service position in the future. /// Optionally, we can also move the selector to its service position in the future.
///
/// Technically, the hardest part is the UI - emitting a message. But, we have the MMU error screens.
/// The Eject message is not an error, but we'll leverage existing infrastructure of error screens + user input to model a nice UI dialog.
class EjectFilament : public CommandBase { class EjectFilament : public CommandBase {
public: public:
inline EjectFilament() inline EjectFilament()

View File

@ -49,6 +49,8 @@ enum class ErrorCode : uint_fast16_t {
FINDA_FLICKERS = 0x800a, ///< FINDA flickers - seems to be badly calibrated and happens to be pressed at spots where it used to be not pressed before. FINDA_FLICKERS = 0x800a, ///< FINDA flickers - seems to be badly calibrated and happens to be pressed at spots where it used to be not pressed before.
///< The user is obliged to inspect FINDA and tune its switching ///< The user is obliged to inspect FINDA and tune its switching
FILAMENT_EJECTED = 0x800b, ///< Filament was ejected, waiting for user input - technically, this is not an error
QUEUE_FULL = 0x802b, ///< E32811 internal logic error - attempt to move with a full queue QUEUE_FULL = 0x802b, ///< E32811 internal logic error - attempt to move with a full queue
VERSION_MISMATCH = 0x802c, ///< E32812 internal error of the printer - incompatible version of the MMU FW VERSION_MISMATCH = 0x802c, ///< E32812 internal error of the printer - incompatible version of the MMU FW