Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
movable_base.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 #include "../config/axis.h"
5 #include "../hal/tmc2130.h"
6 
7 namespace modules {
8 namespace motion {
9 
11 class MovableBase {
12 public:
14  enum {
15  Ready = 0, // intentionally set as zero in order to allow zeroing the Idler structure upon startup -> avoid explicit initialization code
16  Moving = 1,
17  PlannedHome = 2,
18  HomeForward = 3,
19  HomeBack = 4,
20  TMCFailed = 5,
21  HomingFailed = 6,
22  OnHold = 0x80,
23  };
24 
26  enum class OperationResult : uint8_t {
27  Accepted,
28  Refused,
29  Failed
30  };
31 
32  inline constexpr MovableBase(config::Axis axis)
33  : state(Ready)
34  , plannedSlot(-1)
35  , currentSlot(-1)
36  , homingValid(false)
37  , axis(axis)
38  , axisStart(0) {}
39 
41 
46  inline uint8_t Slot() const { return currentSlot; }
47 
49  inline uint8_t State() const { return state; }
50 
51  inline hal::tmc2130::ErrorFlags TMCErrorFlags() const { return tmcErrorFlags; }
52 
63  inline void InvalidateHoming() { homingValid = false; }
64 
68 
69  inline bool HomingValid() const { return homingValid; }
70 
71  inline config::Axis Axis() const { return axis; }
72 
75  void SetCurrents(uint8_t iRun, uint8_t iHold);
76 
79  void HoldOn();
80 
82  bool IsOnHold() const { return state & OnHold; }
83 
85  void Resume() { state &= ~OnHold; }
86 
87 #ifndef UNITTEST
88 protected:
89 #endif
91  uint8_t state;
92 
94  uint8_t plannedSlot;
95 
97  uint8_t currentSlot;
98 
101 
103  hal::tmc2130::ErrorFlags tmcErrorFlags;
104 
105  config::Axis axis;
106 
107  int32_t axisStart;
108 
109  virtual void PrepareMoveToPlannedSlot() = 0;
110  virtual void PlanHomingMoveForward() = 0;
111  virtual void PlanHomingMoveBack() = 0;
114  virtual void FinishMove() = 0;
120  virtual bool StallGuardAllowed(bool forward) const { return true; }
121 
125 
128 
129  void PerformMove();
130 
131  void PerformHomeForward();
132  void PerformHomeBack();
133 
134  void HomeFailed();
135 
136  void CheckTMC();
137 
138  uint16_t AxisDistance(int32_t curPos) const;
139 };
140 
141 } // namespace motion
142 } // namespace modules
Base class for movable modules - modules::idler::Idler and modules::selector::Selector contains the c...
Definition: movable_base.h:11
uint8_t State() const
Definition: movable_base.h:49
virtual bool FinishHomingAndPlanMoveToParkPos()=0
void HoldOn()
Definition: movable_base.cpp:34
void InvalidateHoming()
Definition: movable_base.h:63
void SetCurrents(uint8_t iRun, uint8_t iHold)
bool IsOnHold() const
Definition: movable_base.h:82
OperationResult InitMovement()
Definition: movable_base.cpp:42
uint8_t currentSlot
current slot
Definition: movable_base.h:97
@ OnHold
needs to be a separate bit due to homing recovery infrastructure
Definition: movable_base.h:22
OperationResult InitMovementNoReinitAxis()
Initializes movement of a movable module without reinitializing the axis/TMC driver.
virtual bool StallGuardAllowed(bool forward) const
Definition: movable_base.h:120
OperationResult PlanHome()
Definition: movable_base.cpp:9
void Resume()
Allows the movable to move/home again after begin suspended by HoldOn.
Definition: movable_base.h:85
hal::tmc2130::ErrorFlags tmcErrorFlags
cached TMC2130 error flags - being read only if the axis is enabled and doing something (moving)
Definition: movable_base.h:103
uint8_t Slot() const
virtual ~MovableBase(); intentionally disabled, see description in logic::CommandBase
Definition: movable_base.h:46
bool homingValid
true if the axis is considered as homed
Definition: movable_base.h:100
uint8_t plannedSlot
planned slot - where to move to
Definition: movable_base.h:94
uint8_t state
internal state of the automaton
Definition: movable_base.h:91
OperationResult
Operation (Engage/Disengage/MoveToSlot) return values.
Definition: movable_base.h:26
@ Accepted
the operation has been successfully started
@ Failed
the operation could not been started due to HW issues
@ Refused
another operation is currently underway, cannot start a new one
Axis
List of available axes.
Definition: axis.h:35
The modules namespace contains models of MMU's components.
Definition: command_base.h:8