Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
|
Classes | |
struct | Unit |
Generic unit type for compile-time conformability testing. More... | |
Typedefs | |
typedef Unit< long double, Millimeter, Lenght > | U_mm |
typedef Unit< long double, Millimeter, Speed > | U_mm_s |
typedef Unit< long double, Millimeter, Accel > | U_mm_s2 |
typedef Unit< long double, Degree, Lenght > | U_deg |
typedef Unit< long double, Degree, Speed > | U_deg_s |
typedef Unit< long double, Degree, Accel > | U_deg_s2 |
Enumerations | |
enum | UnitBase : uint8_t { Millimeter , Degree } |
Base units for conformability testing. | |
enum | UnitType : uint8_t { Lenght , Speed , Accel } |
Unit types for conformability testing. | |
Functions | |
template<typename T , UnitBase B, UnitType U> | |
constexpr Unit< T, B, U > | operator* (const long double f, const Unit< T, B, U > u) |
static constexpr U_mm | operator""_mm (long double mm) |
static constexpr U_mm_s | operator""_mm_s (long double mm_s) |
static constexpr U_mm_s2 | operator""_mm_s2 (long double mm_s2) |
static constexpr U_deg | operator""_deg (long double deg) |
static constexpr U_deg_s | operator""_deg_s (long double deg_s) |
static constexpr U_deg_s2 | operator""_deg_s2 (long double deg_s2) |
Introduce a minimal Unit class that can be used for conformability, type checking and conversion at compile time. Template parameters are abused to create unique types, which then can go through (explicit) overload and conversion. Despite looking daunting, usage is quite straightforward once the appropriate aliases and inline operators are defined:
U_mm distance = 10.0_mm; auto another = 20.5_mm; auto sum = distance + another; auto angle = 15.0_deg; auto test = distance + angle; // compile time error
Template parameters are only used for type checking. Unit contains a single value Unit<T>::v and is thus well suited for parameter passing and inline initialization.
Conversion to physical steps is done in modules::motion through the sister class modules::motion::AxisUnit, modules::motion::unitToAxisUnit and modules::motion::unitToSteps, which also ensures quantities from different axes are not mixed together. AxisUnit are the normal type that should be used at runtime.