Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
command_base.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 #include "error_codes.h"
5 #include "progress_codes.h"
6 #include "result_codes.h"
7 
8 namespace modules {
9 namespace motion {
10 class MovableBase;
11 }
12 }
13 
15 namespace logic {
16 
20 
29 class CommandBase {
30 public:
31  inline constexpr CommandBase()
35  , stateBeforeModuleFailed(ProgressCode::Empty)
37  , recoveringMovableErrorAxisMask(0) {}
38 
39  // Normally, a base class should (must) have a virtual destructor to enable correct deallocation of superstructures.
40  // However, in our case we don't want ANY destruction of these objects and moreover - adding a destructor like this
41  // makes the linker complain about missing operator delete(), which is really not something we want/need in our case.
42  // Without the destructor, the linker is "happy" ;)
43  // virtual ~CommandBase() = default;
44 
48  virtual bool Reset(uint8_t param) = 0;
49 
55  bool Step();
56 
59  virtual bool StepInner() = 0;
60 
69  virtual ProgressCode State() const { return state; }
70 
73  ProgressCode TopLevelState() const { return state; }
74 
79  virtual ErrorCode Error() const { return error; }
80 
85  virtual ResultCode Result() const { return ResultCode::OK; }
86 
93  void Panic(ErrorCode ec);
94 
96  static void InvalidateHoming();
97 
100  static void InvalidateHomingAndFilamentState();
101 
103  static void HoldIdlerSelector();
104 
106  static void ResumeIdlerSelector();
107 
108 #ifndef UNITTEST
109 protected:
110 #endif
113  bool CheckToolIndex(uint8_t index);
114 
120 
122  bool WaitForOneModuleErrorRecovery(ErrorCode iState, modules::motion::MovableBase &m, uint8_t axisMask);
123 
125  void ErrDisengagingIdler();
126 
128  void GoToErrDisengagingIdler(ErrorCode deferredEC);
129 
132 
134  void FinishedOK();
135 
141  uint8_t recoveringMovableErrorAxisMask;
142 };
143 
144 } // namespace logic
Base class defining common API for high-level operations/commands/state machines.
Definition: command_base.h:29
virtual ProgressCode State() const
Definition: command_base.h:69
ErrorCode errorBeforeModuleFailed
saved error of the state machine before a common error happened
Definition: command_base.h:140
ErrorCode deferredErrorCode
planned error code - occurs when doing GoToErrDisengagingIdler - after the idler disengaged,...
Definition: command_base.h:138
ProgressCode state
current progress state of the state machine
Definition: command_base.h:136
ProgressCode stateBeforeModuleFailed
saved state of the state machine before a common error happened
Definition: command_base.h:139
void Panic(ErrorCode ec)
Definition: command_base.cpp:145
ProgressCode TopLevelState() const
Definition: command_base.h:73
void FinishedOK()
Process end of command which finished OK.
ErrorCode error
current error code
Definition: command_base.h:137
bool WaitForOneModuleErrorRecovery(ErrorCode iState, modules::motion::MovableBase &m, uint8_t axisMask)
Definition: command_base.cpp:73
bool Step()
Definition: command_base.cpp:137
virtual bool Reset(uint8_t param)=0
static void InvalidateHoming()
Invalidates homing state on Idler and Selector - doesn't change anything about filament load status.
Definition: command_base.cpp:154
static void ResumeIdlerSelector()
Allow Idler and Selector to move/home again. Any move needs to be newly planned.
Definition: command_base.cpp:185
void GoToErrDisengagingIdler(ErrorCode deferredEC)
Transit the state machine into ErrDisengagingIdler.
Definition: command_base.cpp:212
static void HoldIdlerSelector()
Put Idler and Selector on-hold - they shall not move (not even home) until ResumeIdlerSelector is cal...
Definition: command_base.cpp:180
virtual bool StepInner()=0
virtual ResultCode Result() const
Definition: command_base.h:85
void ErrDisengagingIdler()
Perform disengaging idler in ErrDisengagingIdler state.
Definition: command_base.cpp:200
void GoToErrEngagingIdler()
Transit the state machine into ErrEngagingIdler.
bool WaitForModulesErrorRecovery()
Definition: command_base.cpp:130
virtual ErrorCode Error() const
Definition: command_base.h:79
static void InvalidateHomingAndFilamentState()
Definition: command_base.cpp:160
bool CheckToolIndex(uint8_t index)
Definition: command_base.cpp:190
Base class for movable modules - modules::idler::Idler and modules::selector::Selector contains the c...
Definition: movable_base.h:11
ErrorCode
Definition: error_codes.h:17
@ OK
the operation finished OK
The logic namespace handles the application logic on top of the modules.
Definition: application.h:8
ErrorCode AddErrorAxisBit(ErrorCode ec, uint8_t axis)
The modules namespace contains models of MMU's components.
Definition: command_base.h:8
ProgressCode
Definition: progress_codes.h:11
@ OK
finished ok
ResultCode
Definition: result_codes.h:10