|
HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
|
#include <tmc51x0.hpp>
Public Member Functions | |
| Encoder (TMC51x0 &driver) noexcept | |
| Construct encoder subsystem. | |
| Result< void > | Configure (const EncoderConfig &config) noexcept |
| Configure encoder settings. | |
| Result< EncoderConfig > | GetEncoderConfig () noexcept |
| Get current encoder configuration. | |
| Result< void > | SetNChannelActiveLevel (ReferenceSwitchActiveLevel active_level) noexcept |
| Set N channel active level (determines polarity) | |
| Result< void > | SetNChannelSensitivity (EncoderNSensitivity sensitivity) noexcept |
| Set N channel sensitivity (edge/level detection) | |
| Result< void > | SetClearMode (EncoderClearMode clear_mode) noexcept |
| Set encoder clear mode. | |
| Result< void > | SetPrescalerMode (EncoderPrescalerMode prescaler_mode) noexcept |
| Set encoder prescaler mode. | |
| Result< void > | SetLatchXactualEnabled (bool enable) noexcept |
| Enable/disable latching XACTUAL with encoder position. | |
| Result< bool > | IsLatchXactualEnabled () noexcept |
| Check if XACTUAL latching is enabled. | |
| Result< int32_t > | GetPosition () noexcept |
| Get encoder position. | |
| Result< void > | SetResolution (int32_t motor_steps, int32_t enc_resolution, bool inverted=false) noexcept |
| Set encoder resolution. | |
| Result< void > | SetAllowedDeviation (int32_t steps) noexcept |
| Set encoder allowed deviation. | |
| Result< bool > | IsNEventDetected () noexcept |
| Check if an encoder N-event was detected (ENC_STATUS.n_event) | |
| Result< void > | ClearNEventFlag () noexcept |
| Clear the encoder N-event flag (ENC_STATUS.n_event, W1C) | |
| Result< int32_t > | GetLatchedPosition () noexcept |
| Get encoder latched position. | |
| Result< bool > | IsDeviationWarning () noexcept |
| Check if encoder deviation warning is active. | |
| Result< void > | ClearDeviationWarning () noexcept |
| Clear encoder deviation warning flag. | |
Private Attributes | |
| TMC51x0 & | driver_ |
| Reference to parent driver instance. | |
Encoder subsystem.
Provides methods for encoder configuration and reading encoder position.
|
inlineexplicitnoexcept |
Construct encoder subsystem.
| driver | Reference to parent TMC51x0 driver instance |
|
noexcept |
Clear encoder deviation warning flag.
Attempts to clear the deviation warning flag. The flag will only clear if the deviation is no longer present (X_ENC and XACTUAL are within ENC_DEVIATION steps).
|
noexcept |
Clear the encoder N-event flag (ENC_STATUS.n_event, W1C)
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Configure encoder settings.
| config | Encoder configuration structure |
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Get current encoder configuration.
| config | Reference to store current configuration |
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Get encoder latched position.
| position | Reference to store encoder position latched on N event |
Reads the encoder position that was latched on the last N channel event.
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Get encoder position.
| position | Reference to store encoder position in steps |
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Check if encoder deviation warning is active.
Deviation detection compares the encoder position (X_ENC) with the internal motor position (XACTUAL). If they differ by more than ENC_DEVIATION steps, a warning is triggered.
This is useful for:
|
noexcept |
Check if XACTUAL latching is enabled.
|
noexcept |
Check if an encoder N-event was detected (ENC_STATUS.n_event)
ENC_STATUS.n_event is a write-1-to-clear flag set by the hardware on an N-channel event (as configured by ENCMODE).
| INVALID_STATE | if called while in external STEP/DIR mode |
|
noexcept |
Set encoder allowed deviation.
| steps | Maximum number of steps deviation before warning |
|
noexcept |
Set encoder clear mode.
| clear_mode | Clear mode (DISABLED, ONCE, CONTINUOUS) |
Updates only clear mode, preserving other settings.
|
noexcept |
Enable/disable latching XACTUAL with encoder position.
| enable | true to latch XACTUAL together with X_ENC on N-event |
When enabled, the motor position (XACTUAL) is latched into X_LATCH simultaneously with the encoder position on N-channel events. This is useful for precise position verification and homing.
Updates only latch_x_act, preserving other ENCMODE settings.
|
noexcept |
Set N channel active level (determines polarity)
| active_level | Active level (ACTIVE_LOW or ACTIVE_HIGH) |
Updates only the active level, preserving other settings. Shares ReferenceSwitchActiveLevel enum with reference switches.
|
noexcept |
Set N channel sensitivity (edge/level detection)
| sensitivity | Sensitivity mode (ACTIVE_LEVEL, RISING_EDGE, FALLING_EDGE, BOTH_EDGES) |
Updates only sensitivity, preserving other settings.
|
noexcept |
Set encoder prescaler mode.
| prescaler_mode | Prescaler mode (BINARY or DECIMAL) |
Updates only prescaler mode, preserving other settings.
|
noexcept |
Set encoder resolution.
| motor_steps | Number of steps per turn for the motor |
| enc_resolution | Actual encoder resolution (pulses per turn) |
| inverted | Whether encoder and motor rotations are inverted |
|
private |
Reference to parent driver instance.