Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
logic::CommandBase Class Referenceabstract

Base class defining common API for high-level operations/commands/state machines. More...

#include <command_base.h>

Inheritance diagram for logic::CommandBase:
Inheritance graph
[legend]

Public Member Functions

virtual bool Reset (uint8_t param)=0
 
bool Step ()
 
virtual bool StepInner ()=0
 
virtual ProgressCode State () const
 
ProgressCode TopLevelState () const
 
virtual ErrorCode Error () const
 
virtual ResultCode Result () const
 
void Panic (ErrorCode ec)
 

Static Public Member Functions

static void InvalidateHoming ()
 Invalidates homing state on Idler and Selector - doesn't change anything about filament load status.
 
static void InvalidateHomingAndFilamentState ()
 
static void HoldIdlerSelector ()
 Put Idler and Selector on-hold - they shall not move (not even home) until ResumeIdlerSelector is called.
 
static void ResumeIdlerSelector ()
 Allow Idler and Selector to move/home again. Any move needs to be newly planned.
 

Protected Member Functions

bool CheckToolIndex (uint8_t index)
 
bool WaitForModulesErrorRecovery ()
 
bool WaitForOneModuleErrorRecovery (ErrorCode iState, modules::motion::MovableBase &m, uint8_t axisMask)
 
void ErrDisengagingIdler ()
 Perform disengaging idler in ErrDisengagingIdler state.
 
void GoToErrDisengagingIdler (ErrorCode deferredEC)
 Transit the state machine into ErrDisengagingIdler.
 
void GoToErrEngagingIdler ()
 Transit the state machine into ErrEngagingIdler.
 
void FinishedOK ()
 Process end of command which finished OK.
 

Protected Attributes

ProgressCode state
 current progress state of the state machine
 
ErrorCode error
 current error code
 
ErrorCode deferredErrorCode
 planned error code - occurs when doing GoToErrDisengagingIdler - after the idler disengaged, the error is set (not before)
 
ProgressCode stateBeforeModuleFailed
 saved state of the state machine before a common error happened
 
ErrorCode errorBeforeModuleFailed
 saved error of the state machine before a common error happened
 
uint8_t recoveringMovableErrorAxisMask
 

Detailed Description

Base class defining common API for high-level operations/commands/state machines.

Which state machines are high-level? Those which are being initiated either by a command over the serial line or from a button

Tasks derived from this base class are the top-level operations inhibited by the printer. These tasks report their progress and only one of these tasks is allowed to run at once.

Member Function Documentation

◆ CheckToolIndex()

bool logic::CommandBase::CheckToolIndex ( uint8_t  index)
protected
Returns
true if the slot/tool index is within specified range (0 - config::toolCount) If not, it returns false and sets the error to ErrorCode::INVALID_TOOL

◆ Error()

virtual ErrorCode logic::CommandBase::Error ( ) const
inlinevirtual
Returns
status of the operation - e.g. RUNNING, OK, or an error code if the operation failed.

Beware - the same rule about composite operations as with State() applies to Error() as well. Please see ErrorCode for more details

Reimplemented in logic::ToolChange, logic::EjectFilament, and logic::CutFilament.

◆ InvalidateHomingAndFilamentState()

void logic::CommandBase::InvalidateHomingAndFilamentState ( )
static

Invalidates homing state on Idler and Selector + resets the knowledge about filament presence according to known sensors (FINDA+FSensor)

◆ Panic()

void logic::CommandBase::Panic ( ErrorCode  ec)

Switches the state machine into an error state of code ec. It shall be used to halt the firmware while retaining the capability of reporting the error state to the printer

  • a kind of similar to runtime assertions. Called from main.cpp's global funtion Panic() . The derived state machines have no (implemented) way of getting out of this state (intentionally). The only way out is to reset the board.

◆ Reset()

virtual bool logic::CommandBase::Reset ( uint8_t  param)
pure virtual

resets the automaton

Parameters
paramnumerical parameter that comes with some commands (e.g. T1 for tool change 1)
Returns
true if the command was accepted and started (which may not be possible e.g. due to filament position)

Implemented in logic::StartUp, logic::NoCommand, logic::Home, logic::UnloadFilament, logic::ToolChange, logic::SetMode, logic::MoveSelector, logic::LoadFilament, logic::HWSanity, logic::EjectFilament, and logic::CutFilament.

◆ Result()

virtual ResultCode logic::CommandBase::Result ( ) const
inlinevirtual
Returns
result of a command - only valid after the command finished its work. Default returned value is OK for all commands. So far there is only one example usage: LoadFilament can be terminated with a button -> Result will be Cancelled. The printer then can display "Loading cancelled"

Reimplemented in logic::LoadFilament.

◆ State()

virtual ProgressCode logic::CommandBase::State ( ) const
inlinevirtual
Returns
progress of operation - each automaton consists of several internal states which should be reported to the user via the printer's LCD E.g. Tool change: first tries to unload filament, then selects another slot and then tries to load filament

Beware - derived automata report detailed states of underlying state machines if any E.g. Eject filament first tries to unload filament, which is a standalone automaton. Therefore until the unload is finished, this method will report the internal state of Unload filament. The reason for this is to be able to report exactly what is happening to the printer, especially loading and unloading sequences (and errors)

Reimplemented in logic::ToolChange, logic::EjectFilament, and logic::CutFilament.

◆ Step()

bool logic::CommandBase::Step ( )

Steps the state machine. This is the preferred way of stepping the machine as it handles the global HW error states uniformly (so that the derived classes do not have to deal with these error states on their own). Each derived class then only implements its own logic via the virtual StepInner method.

Returns
true if the automaton finished its work

◆ StepInner()

virtual bool logic::CommandBase::StepInner ( )
pure virtual

Each derived class shall implement its own state machine logic in this method It is being called from Step after the HW error states have been checked

Implemented in logic::UnloadFilament, logic::ToolChange, logic::StartUp, logic::SetMode, logic::NoCommand, logic::MoveSelector, logic::LoadFilament, logic::HWSanity, logic::Home, logic::EjectFilament, and logic::CutFilament.

◆ TopLevelState()

ProgressCode logic::CommandBase::TopLevelState ( ) const
inline
Returns
progress of operation of only this state machine - regardless of any underlying automata (if any) Therefore it is not a vitual method.

◆ WaitForModulesErrorRecovery()

bool logic::CommandBase::WaitForModulesErrorRecovery ( )
protected

Checks for errors of modules - that includes TMC errors, Idler and Selector errors and possibly more. The idea is to check blocking errors at one spot consistently. Some of the detected errors can be irrecoverable (i.e. need power cycling the MMU).

Returns
true if waiting for a recovery, false if the state machine can continue.

◆ WaitForOneModuleErrorRecovery()

bool logic::CommandBase::WaitForOneModuleErrorRecovery ( ErrorCode  iState,
modules::motion::MovableBase m,
uint8_t  axisMask 
)
protected
Returns
true when still waiting for a module to recover, false otherwise.

The documentation for this class was generated from the following files: