HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::TMC51x0< CommType >::RampControl Struct Reference

Ramp control subsystem. More...

#include <tmc51x0.hpp>

Collaboration diagram for tmc51x0::TMC51x0< CommType >::RampControl:
[legend]

Public Member Functions

 RampControl (TMC51x0 &driver) noexcept
 Construct ramp control subsystem.
 
Result< void > SetRampMode (RampMode mode) noexcept
 Set the ramp mode.
 
Result< RampModeGetRampMode () noexcept
 Get current ramp mode.
 
Result< bool > IsPositionReached () noexcept
 Check if position target has been reached.
 
Result< bool > IsVelocityReached () noexcept
 Check if velocity target has been reached.
 
Result< bool > IsStandstill () noexcept
 Check if motor is in standstill.
 
Result< void > SetTargetPosition (float value, Unit unit) noexcept
 Set target position (absolute)
 
Result< void > MoveRelative (float offset, Unit unit) noexcept
 Move relative to current position.
 
Result< float > GetCurrentPosition (Unit unit) noexcept
 Get current position.
 
Result< float > GetTargetPosition (Unit unit) noexcept
 Get target position.
 
Result< int32_t > GetCurrentPositionMicrosteps () noexcept
 Get current position in raw driver microsteps (XACTUAL)
 
Result< int32_t > GetTargetPositionMicrosteps () noexcept
 Get target position in raw driver microsteps (XTARGET)
 
Result< void > SetCurrentPosition (float value, Unit unit, bool update_encoder=false) noexcept
 Set current position.
 
Result< void > SetMaxSpeed (float value, Unit unit) noexcept
 Set maximum speed.
 
Result< void > SetAcceleration (float value, Unit unit) noexcept
 Set acceleration and deceleration.
 
Result< void > SetAccelerations (float accel_val, float decel_val, Unit unit) noexcept
 Set acceleration and deceleration separately.
 
Result< void > SetDeceleration (float value, Unit unit) noexcept
 Set deceleration only (DMAX register)
 
Result< void > SetRampSpeeds (float start_speed, float stop_speed, float transition_speed, Unit unit) noexcept
 Set ramp speeds.
 
Result< float > GetCurrentSpeed (Unit unit) noexcept
 Get current speed.
 
Result< bool > IsTargetReached () noexcept
 Check if target position is reached.
 
Result< bool > IsTargetVelocityReached () noexcept
 Check if target velocity is reached.
 
Result< void > Stop () noexcept
 Stop the motor.
 
Result< void > SetPowerDownDelay (uint8_t tpowerdown) noexcept
 Set power down delay (raw register value)
 
Result< void > SetPowerDownDelayMs (float delay_ms) noexcept
 Set power down delay in milliseconds.
 
Result< void > SetZeroWaitTime (uint16_t tzerowait) noexcept
 Set zero wait time (raw register value)
 
Result< void > SetZeroWaitTimeMs (float delay_ms) noexcept
 Set zero wait time in milliseconds.
 
Result< void > ConfigureRamp (const RampConfig &config) noexcept
 Configure ramp generator from RampConfig structure.
 
Result< void > SetFirstAcceleration (float a1, Unit unit) noexcept
 Set first acceleration phase.
 
Result< void > SetFinalDeceleration (float d1, Unit unit) noexcept
 Set final deceleration phase.
 

Private Member Functions

Result< void > SetTargetPosition (int32_t position) noexcept
 Set XTARGET directly in register units.
 
Result< void > SetCurrentPosition (int32_t position, bool update_encoder=false) noexcept
 

Private Attributes

TMC51x0driver_
 Reference to parent driver instance.
 

Detailed Description

template<typename CommType>
struct tmc51x0::TMC51x0< CommType >::RampControl

Ramp control subsystem.

Provides methods for controlling motor motion including positioning, velocity control, and hold modes.

Constructor & Destructor Documentation

◆ RampControl()

template<typename CommType >
tmc51x0::TMC51x0< CommType >::RampControl::RampControl ( TMC51x0 & driver)
inlineexplicitnoexcept

Construct ramp control subsystem.

Parameters
driverReference to parent TMC51x0 driver instance

Member Function Documentation

◆ ConfigureRamp()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::ConfigureRamp ( const RampConfig & config)
noexcept

Configure ramp generator from RampConfig structure.

Parameters
configRamp configuration structure with all ramp parameters
Returns
Result<void> indicating success or error

Configures all ramp parameters including velocities, accelerations, and timing using the unit specifications from the config.

◆ GetCurrentPosition()

template<typename CommType >
Result< float > tmc51x0::TMC51x0< CommType >::RampControl::GetCurrentPosition ( Unit unit)
noexcept

Get current position.

Parameters
unitUnit to return the position in (default: Steps)
Returns
Result<float> containing the current position or error

Returns the current position relative to the zero/home position set via SetCurrentPosition(). If home is unknown, call SetCurrentPosition(0.0f) at the current physical position first.

Note
Internally, XACTUAL is in microsteps (depends on CHOPCONF.MRES). When requesting Unit::Steps, the returned value is in motor full steps (microsteps are converted back using the current MRES).

◆ GetCurrentPositionMicrosteps()

template<typename CommType >
Result< int32_t > tmc51x0::TMC51x0< CommType >::RampControl::GetCurrentPositionMicrosteps ( )
noexcept

Get current position in raw driver microsteps (XACTUAL)

Returns
Result<int32_t> containing XACTUAL in microsteps (native register unit)

Use this when you want to inspect the exact microstep-level position used by the ramp generator. This avoids any conversion/rounding to degrees/full-steps.

◆ GetCurrentSpeed()

template<typename CommType >
Result< float > tmc51x0::TMC51x0< CommType >::RampControl::GetCurrentSpeed ( Unit unit)
noexcept

Get current speed.

Parameters
speedReference to store the current speed
unitUnit to return the speed in (default: Steps)
Returns
Result<float> containing the value or error

◆ GetRampMode()

template<typename CommType >
Result< RampMode > tmc51x0::TMC51x0< CommType >::RampControl::GetRampMode ( )
noexcept

Get current ramp mode.

Returns
Result<RampMode> containing the current ramp mode or error

◆ GetTargetPosition()

template<typename CommType >
Result< float > tmc51x0::TMC51x0< CommType >::RampControl::GetTargetPosition ( Unit unit)
noexcept

Get target position.

Parameters
unitUnit to return the position in (default: Steps)
Returns
Result<float> containing the target position or error

◆ GetTargetPositionMicrosteps()

template<typename CommType >
Result< int32_t > tmc51x0::TMC51x0< CommType >::RampControl::GetTargetPositionMicrosteps ( )
noexcept

Get target position in raw driver microsteps (XTARGET)

Returns
Result<int32_t> containing XTARGET in microsteps (native register unit)

◆ IsPositionReached()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::RampControl::IsPositionReached ( )
noexcept

Check if position target has been reached.

Returns
Result<bool> containing true if position reached, false otherwise

◆ IsStandstill()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::RampControl::IsStandstill ( )
noexcept

Check if motor is in standstill.

Returns
Result<bool> containing true if motor is in standstill, false otherwise

◆ IsTargetReached()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::RampControl::IsTargetReached ( )
noexcept

Check if target position is reached.

Returns
Result<bool> containing true if target position reached, false otherwise

◆ IsTargetVelocityReached()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::RampControl::IsTargetVelocityReached ( )
noexcept

Check if target velocity is reached.

Returns
Result<bool> containing true if target velocity reached, false otherwise

◆ IsVelocityReached()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::RampControl::IsVelocityReached ( )
noexcept

Check if velocity target has been reached.

Returns
Result<bool> containing true if velocity reached, false otherwise

◆ MoveRelative()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::MoveRelative ( float offset,
Unit unit )
noexcept

Move relative to current position.

Parameters
offsetRelative movement offset (positive = forward, negative = backward)
unitUnit of the offset value (default: Steps)
Returns
Result<void> indicating success or error

Moves relative to the current position. Automatically calculates the new target position by adding the offset to the current position. No need to manually calculate steps.

Example: MoveRelative(90.0f, Unit::Deg); // Move 90 degrees from current position MoveRelative(-45.0f, Unit::Deg); // Move 45 degrees backward

◆ SetAcceleration()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetAcceleration ( float value,
Unit unit )
noexcept

Set acceleration and deceleration.

Parameters
valueAcceleration value
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

◆ SetAccelerations()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetAccelerations ( float accel_val,
float decel_val,
Unit unit )
noexcept

Set acceleration and deceleration separately.

Parameters
accel_valAcceleration value
decel_valDeceleration value
unitUnit of the values (default: Steps)
Returns
Result<void> indicating success or error

◆ SetCurrentPosition() [1/2]

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetCurrentPosition ( float value,
Unit unit,
bool update_encoder = false )
noexcept

Set current position.

Parameters
valuePosition value
unitUnit of the value (default: Steps)
update_encoderIf true, also update encoder position
Returns
Result<void> indicating success or error

◆ SetCurrentPosition() [2/2]

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetCurrentPosition ( int32_t position,
bool update_encoder = false )
privatenoexcept

◆ SetDeceleration()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetDeceleration ( float value,
Unit unit )
noexcept

Set deceleration only (DMAX register)

Parameters
valueDeceleration value
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

Sets only the deceleration rate (DMAX register) without affecting acceleration (AMAX).

◆ SetFinalDeceleration()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetFinalDeceleration ( float d1,
Unit unit )
noexcept

Set final deceleration phase.

Parameters
d1Deceleration value
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

Sets the final deceleration phase (D1). Attention: Do not set 0 in positioning mode (datasheet 6.3.1). If set to 0, the driver might behave unexpectedly in positioning mode. A safe minimum (e.g., 100) is recommended if unsure.

◆ SetFirstAcceleration()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetFirstAcceleration ( float a1,
Unit unit )
noexcept

Set first acceleration phase.

Parameters
a1First acceleration value
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

Sets the first acceleration phase. If 0.0f, AMAX is used for this phase.

◆ SetMaxSpeed()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetMaxSpeed ( float value,
Unit unit )
noexcept

Set maximum speed.

Parameters
valueMaximum speed value
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

◆ SetPowerDownDelay()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetPowerDownDelay ( uint8_t tpowerdown)
noexcept

Set power down delay (raw register value)

Parameters
tpowerdownPower down delay (0-255, time range ~0 to 5.6 seconds)
Returns
Result<void> indicating success or error

Sets the delay before power down when motor enters standstill. Minimum setting of 2 is required to allow automatic tuning of stealthChop PWM_OFFS_AUTO.

Note
For user-friendly API, use SetPowerDownDelayMs() instead.

◆ SetPowerDownDelayMs()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetPowerDownDelayMs ( float delay_ms)
noexcept

Set power down delay in milliseconds.

Parameters
delay_msPower down delay in milliseconds (0.0 = instant, automatically converted to register value 0-255)
Returns
Result<void> indicating success or error

Sets the delay before power down when motor enters standstill. The delay is automatically converted from milliseconds to register value based on f_clk.

Conversion: tpowerdown = round((delay_ms × f_clk) / (1000 × 2^18))

Note
Minimum setting of 2 register units is required to allow automatic tuning of stealthChop PWM_OFFS_AUTO.
At 12 MHz: 1 register unit ≈ 21.85 ms, range ≈ 0-5.6 seconds

◆ SetRampMode()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetRampMode ( RampMode mode)
noexcept

Set the ramp mode.

Parameters
modeRamp mode (POSITIONING, VELOCITY_POS, VELOCITY_NEG, HOLD)
Returns
Result<void> indicating success or error

◆ SetRampSpeeds()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetRampSpeeds ( float start_speed,
float stop_speed,
float transition_speed,
Unit unit )
noexcept

Set ramp speeds.

Parameters
start_speedStart speed value
stop_speedStop speed value
transition_speedTransition speed value
unitUnit of the speed values (default: Steps)
Returns
Result<void> indicating success or error

◆ SetTargetPosition() [1/2]

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetTargetPosition ( float value,
Unit unit )
noexcept

Set target position (absolute)

Parameters
valueTarget position value (absolute position from current zero/home)
unitUnit of the value (default: Steps)
Returns
Result<void> indicating success or error

Sets an absolute target position. The position is relative to the current zero/home position set via SetCurrentPosition(). If home is unknown, call SetCurrentPosition(0.0f) at the current physical position to establish a reference point.

Note
Internally, XTARGET/XACTUAL are in microsteps and therefore depend on the configured microstep resolution (CHOPCONF.MRES). When using Unit::Steps here, the value is interpreted as motor full steps and will be converted to microsteps using the current MRES setting.

◆ SetTargetPosition() [2/2]

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetTargetPosition ( int32_t position)
privatenoexcept

Set XTARGET directly in register units.

Parameters
positionTarget position in microsteps (XTARGET register units)
Note
This bypasses unit conversion. XTARGET units depend on CHOPCONF.MRES (microstep resolution). Prefer the public float+Unit overload unless you intentionally work in raw register units.

◆ SetZeroWaitTime()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetZeroWaitTime ( uint16_t tzerowait)
noexcept

Set zero wait time (raw register value)

Parameters
tzerowaitWaiting time after ramping down to zero velocity in clock cycles (0-65535)
Returns
Result<void> indicating success or error

Sets the waiting time after ramping down to zero velocity before next movement or direction inversion can start.

Note
For user-friendly API, use SetZeroWaitTimeMs() instead.

◆ SetZeroWaitTimeMs()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::SetZeroWaitTimeMs ( float delay_ms)
noexcept

Set zero wait time in milliseconds.

Parameters
delay_msVelocity-zero wait time in milliseconds (0.0 = no waiting, automatically converted to register value 0-65535)
Returns
Result<void> indicating success or error

Sets the waiting time after ramping down to zero velocity before next movement or direction inversion can start.

The delay is automatically converted from milliseconds to register value based on f_clk.

Conversion: tzerowait = round((delay_ms × f_clk) / (1000 × 2^18))

Note
Used only with the internal ramp generator (positioning / velocity mode).
Has no effect in external Step/Dir mode (SD_MODE=1).
At 12 MHz: 1 register unit ≈ 21.85 ms, maximum ≈ 1430 seconds (~23.8 minutes)

◆ Stop()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::RampControl::Stop ( )
noexcept

Stop the motor.

Returns
Result<void> indicating success or error

Stops the motor by setting VSTART and VMAX to 0.

Member Data Documentation

◆ driver_

template<typename CommType >
TMC51x0& tmc51x0::TMC51x0< CommType >::RampControl::driver_
private

Reference to parent driver instance.


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