Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
modules::motion::AxisUnit< T, A, U > Struct Template Reference

#include <axisunit.h>

Collaboration diagram for modules::motion::AxisUnit< T, A, U >:
Collaboration graph
[legend]

Public Types

typedef T type_t
 
typedef AxisUnit< T, A, U > self_t
 

Public Member Functions

constexpr self_t operator+ (const self_t r) const
 
constexpr self_t operator- (const self_t r) const
 
constexpr self_t operator- () const
 
constexpr self_t operator* (const self_t r) const
 
constexpr self_t operator/ (const self_t r) const
 
constexpr self_t operator* (const long double f) const
 
constexpr self_t operator/ (const long double f) const
 

Public Attributes

v
 

Static Public Attributes

static constexpr Axis axis = A
 
static constexpr config::UnitType unit = U
 

Detailed Description

template<typename T, Axis A, config::UnitType U>
struct modules::motion::AxisUnit< T, A, U >

Specialized axis unit type for compile-time conformability testing. Like for unit::Unit this is done ensure quantities are not mixed between types, while also providing convenience methods to convert from physical units to AxisUnits directly at compile time. AxisUnits are just as efficient as the non-checked pulse_gen::pos_t and pulse_gen::steps_t.

Each axis provides separate types for each quantity, since the low-level count is also not directly comparable across each (depending on the configuration settings). Quantities are normally defined through the literal operators. Types and base axes are prefixed with a single letter identifier for the axis: P=pulley, S=selector, I=idler.

P_pos_t pulley_position = 10.0_P_mm;
auto pulley_zero = 0.0_P_mm; // implicit type
P_speed_ pulley_feedrate = 30.0_P_mm_s;
I_pos_t idler_position = 15.0_I_deg;
pulley_position + idler_position; // compile time error

motion::Motion.PlanMove (and related functions) support both physical and AxisUnit natively. This is done by specifying the axis through the first template parameter, which ensures related units are also conforming:

motion.PlanMoveTo<Pulley>(10.0_mm, 100._mm_s); // using physical units
motion.PlanMoveTo<Pulley>(10.0_P_mm, 100._P_mm_s); // using AxisUnit

Physical units are always represented with the largest floating point type, so they should only preferably be used at compile-time only.

If runtime manipulation is necessary, AxisUnit should be used instead. Conversion from physical to AxisUnit can be done through motion::unitToAxisUnit:

unitToAxisUnit<final_type>(physical_type)

Examples:

P_pos_t pulley_pos = unitToAxisUnit<P_pos_t>(10.0_mm);
P_speed_t pulley_speed = unitToAxisUnit<P_speed_t>(100.0_mm_s);

Conversion to pos_t or steps_t works the same using motion::unitToSteps instead.

The low-level step count can be accessed when necessary through AxisUnit::v, which should be avoided as it bypasses all type checks. AxisUnit can also be constructed without checks by providing a counter as the first initializer.

The scaling factor is stored with the pair config::AxisConfig::uSteps and config::AxisConfig::stepsPerUnit.


The documentation for this struct was generated from the following file: