HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
FatigueTest::FatigueTestMotion Class Reference

Unified fatigue test motion controller. More...

#include <fatigue_motion.hpp>

Collaboration diagram for FatigueTest::FatigueTestMotion:
[legend]

Classes

struct  Status
 Status structure containing current motion controller state. More...
 

Public Member Functions

 FatigueTestMotion (tmc51x0::TMC51x0< Esp32SPI > *driver, Esp32TmcMutex &driver_mutex) noexcept
 Construct a motion controller bound to a TMC51x0 driver instance.
 
 ~FatigueTestMotion () noexcept
 Destructor.
 
void SetGlobalBounds (float min_bound_degrees, float max_bound_degrees) noexcept
 Set global (hardware) bounds in degrees.
 
void GetGlobalBoundsDegrees (float &min_degrees, float &max_degrees) const noexcept
 Read current global bounds (degrees).
 
void SetUnbounded (float current_position_degrees, float default_range_degrees=175.0f) noexcept
 Mark the system as unbounded and establish a default travel window.
 
bool SetLocalBoundsFromCenterDegrees (float min_degrees_from_center, float max_degrees_from_center, float edge_backoff_deg=3.5f) noexcept
 Set local oscillation bounds (degrees) relative to the center.
 
void GetLocalBoundsFromCenterDegrees (float &min_degrees, float &max_degrees) const noexcept
 Read local bounds (degrees).
 
bool SetMaxVelocity (float vmax_rpm) noexcept
 Set maximum velocity for oscillation (direct TMC5160 VMAX control).
 
float GetMaxVelocity () const noexcept
 Get configured maximum velocity (RPM).
 
bool SetAcceleration (float amax_rev_s2) noexcept
 Set acceleration for oscillation (direct TMC5160 AMAX control).
 
float GetAcceleration () const noexcept
 Get configured acceleration (rev/s²).
 
float GetEstimatedCycleFrequency () const noexcept
 Get estimated cycle frequency based on current velocity/accel/distance.
 
bool SetDwellTimes (uint32_t dwell_at_min_ms, uint32_t dwell_at_max_ms) noexcept
 Set dwell times at local bounds.
 
void GetDwellTimes (uint32_t &dwell_at_min_ms, uint32_t &dwell_at_max_ms) const noexcept
 Get dwell times at local bounds.
 
bool SetTargetCycles (uint32_t cycles) noexcept
 Set target cycle count (0 = infinite).
 
uint32_t GetCurrentCycles () const noexcept
 Get current completed cycles.
 
uint32_t GetTargetCycles () const noexcept
 Get configured target cycles.
 
bool IsCycleComplete () const noexcept
 Check whether the configured target cycle count has been reached.
 
void ResetCycles () noexcept
 Reset cycle counter and completion flags.
 
bool Start () noexcept
 Start active motion.
 
void Pause () noexcept
 Pause active motion (stops movement but keeps motor energized for resume).
 
void Stop () noexcept
 Stop active motion and command driver stop.
 
bool IsRunning () const noexcept
 Whether the motion controller is currently active.
 
void Update () noexcept
 Periodic update tick.
 
Status GetStatus () const noexcept
 Snapshot current controller status.
 
bool IsBounded () const noexcept
 Whether the controller is in bounded mode (mechanical stops found).
 

Private Types

enum class  MotionState {
  MOVING_TO_MIN , MOVING_TO_MAX , DWELL_AT_MIN , DWELL_AT_MAX ,
  PAUSED , STOPPED
}
 

Private Member Functions

void RecalculateEstimatedFrequency () noexcept
 
void ClipLocalBoundsToGlobal () noexcept
 

Private Attributes

tmc51x0::TMC51x0< Esp32SPI > * driver_
 
float global_min_bound_
 
float global_max_bound_
 
float local_min_bound_
 
float local_max_bound_
 
float home_position_
 
bool bounded_
 
float amplitude_
 
float vmax_rpm_
 
float amax_rev_s2_
 
uint32_t dwell_at_min_ms_
 
uint32_t dwell_at_max_ms_
 
bool running_
 
uint64_t start_time_us_
 
uint32_t target_cycles_
 
uint32_t current_cycles_
 
bool cycle_complete_
 
MotionState state_
 
uint32_t dwell_start_time_ms_
 
float estimated_frequency_hz_
 
Esp32TmcMutexdriver_mutex_
 

Detailed Description

Unified fatigue test motion controller.

Provides point-to-point back-and-forth motion between bounds for fatigue testing. Supports global bounds (hardware limits) and local bounds (oscillation range).

Member Enumeration Documentation

◆ MotionState

Enumerator
MOVING_TO_MIN 
MOVING_TO_MAX 
DWELL_AT_MIN 
DWELL_AT_MAX 
PAUSED 
STOPPED 

Constructor & Destructor Documentation

◆ FatigueTestMotion()

FatigueTest::FatigueTestMotion::FatigueTestMotion ( tmc51x0::TMC51x0< Esp32SPI > * driver,
Esp32TmcMutex & driver_mutex )
noexcept

Construct a motion controller bound to a TMC51x0 driver instance.

Parameters
driverPointer to an initialized driver (must remain valid for the lifetime of this object).
driver_mutexReference to a mutex that protects ALL driver SPI access. This same mutex must be used by any code that directly accesses the driver.
Note
Thread safety: The provided mutex is used to serialize all SPI transactions. Callers MUST use the same mutex for any direct driver access outside this class.

◆ ~FatigueTestMotion()

FatigueTest::FatigueTestMotion::~FatigueTestMotion ( )
defaultnoexcept

Destructor.

Note
Does not implicitly stop the motor; callers should call Stop() as part of application shutdown/state transitions.

Member Function Documentation

◆ ClipLocalBoundsToGlobal()

void FatigueTest::FatigueTestMotion::ClipLocalBoundsToGlobal ( )
privatenoexcept

◆ GetAcceleration()

float FatigueTest::FatigueTestMotion::GetAcceleration ( ) const
noexcept

Get configured acceleration (rev/s²).

◆ GetCurrentCycles()

uint32_t FatigueTest::FatigueTestMotion::GetCurrentCycles ( ) const
noexcept

Get current completed cycles.

Here is the caller graph for this function:

◆ GetDwellTimes()

void FatigueTest::FatigueTestMotion::GetDwellTimes ( uint32_t & dwell_at_min_ms,
uint32_t & dwell_at_max_ms ) const
noexcept

Get dwell times at local bounds.

Parameters
dwell_at_min_msOutput dwell at min (ms).
dwell_at_max_msOutput dwell at max (ms).

◆ GetEstimatedCycleFrequency()

float FatigueTest::FatigueTestMotion::GetEstimatedCycleFrequency ( ) const
noexcept

Get estimated cycle frequency based on current velocity/accel/distance.

Returns
Estimated frequency in Hz (informational only).
Note
This is derived from the motion parameters, not a setpoint.

◆ GetGlobalBoundsDegrees()

void FatigueTest::FatigueTestMotion::GetGlobalBoundsDegrees ( float & min_degrees,
float & max_degrees ) const
noexcept

Read current global bounds (degrees).

Parameters
min_degreesOutput min bound.
max_degreesOutput max bound.
Here is the caller graph for this function:

◆ GetLocalBoundsFromCenterDegrees()

void FatigueTest::FatigueTestMotion::GetLocalBoundsFromCenterDegrees ( float & min_degrees,
float & max_degrees ) const
noexcept

Read local bounds (degrees).

Parameters
min_degreesOutput min local bound.
max_degreesOutput max local bound.
Here is the caller graph for this function:

◆ GetMaxVelocity()

float FatigueTest::FatigueTestMotion::GetMaxVelocity ( ) const
noexcept

Get configured maximum velocity (RPM).

◆ GetStatus()

FatigueTestMotion::Status FatigueTest::FatigueTestMotion::GetStatus ( ) const
noexcept

Snapshot current controller status.

Here is the caller graph for this function:

◆ GetTargetCycles()

uint32_t FatigueTest::FatigueTestMotion::GetTargetCycles ( ) const
noexcept

Get configured target cycles.

◆ IsBounded()

bool FatigueTest::FatigueTestMotion::IsBounded ( ) const
noexcept

Whether the controller is in bounded mode (mechanical stops found).

◆ IsCycleComplete()

bool FatigueTest::FatigueTestMotion::IsCycleComplete ( ) const
noexcept

Check whether the configured target cycle count has been reached.

◆ IsRunning()

bool FatigueTest::FatigueTestMotion::IsRunning ( ) const
noexcept

Whether the motion controller is currently active.

Here is the caller graph for this function:

◆ Pause()

void FatigueTest::FatigueTestMotion::Pause ( )
noexcept

Pause active motion (stops movement but keeps motor energized for resume).

Sets ramp mode to HOLD to maintain position. Motion can be resumed with Start().

Here is the caller graph for this function:

◆ RecalculateEstimatedFrequency()

void FatigueTest::FatigueTestMotion::RecalculateEstimatedFrequency ( )
privatenoexcept
Here is the caller graph for this function:

◆ ResetCycles()

void FatigueTest::FatigueTestMotion::ResetCycles ( )
noexcept

Reset cycle counter and completion flags.

Here is the caller graph for this function:

◆ SetAcceleration()

bool FatigueTest::FatigueTestMotion::SetAcceleration ( float amax_rev_s2)
noexcept

Set acceleration for oscillation (direct TMC5160 AMAX control).

Parameters
amax_rev_s2Acceleration in rev/s².
Returns
true if accepted (value clamped to safe limits).
Here is the caller graph for this function:

◆ SetDwellTimes()

bool FatigueTest::FatigueTestMotion::SetDwellTimes ( uint32_t dwell_at_min_ms,
uint32_t dwell_at_max_ms )
noexcept

Set dwell times at local bounds.

Parameters
dwell_at_min_msDwell at min (ms).
dwell_at_max_msDwell at max (ms).
Returns
true if accepted; false otherwise.
Here is the caller graph for this function:

◆ SetGlobalBounds()

void FatigueTest::FatigueTestMotion::SetGlobalBounds ( float min_bound_degrees,
float max_bound_degrees )
noexcept

Set global (hardware) bounds in degrees.

These bounds represent the full allowed travel range and are typically produced by bounds finding.

Parameters
min_bound_degreesMinimum bound (degrees).
max_bound_degreesMaximum bound (degrees).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetLocalBoundsFromCenterDegrees()

bool FatigueTest::FatigueTestMotion::SetLocalBoundsFromCenterDegrees ( float min_degrees_from_center,
float max_degrees_from_center,
float edge_backoff_deg = 3.5f )
noexcept

Set local oscillation bounds (degrees) relative to the center.

Local bounds are clipped to global bounds (if bounded) and define the oscillation range. An optional edge_backoff_deg parameter specifies how far inside the mechanical bounds to stay during oscillation.

Parameters
min_degrees_from_centerMinimum local bound.
max_degrees_from_centerMaximum local bound.
edge_backoff_degHow far inside bounds to stay (default 3.5°, like bounds_finding_test).
Returns
true if accepted; false if rejected.
Here is the caller graph for this function:

◆ SetMaxVelocity()

bool FatigueTest::FatigueTestMotion::SetMaxVelocity ( float vmax_rpm)
noexcept

Set maximum velocity for oscillation (direct TMC5160 VMAX control).

Parameters
vmax_rpmMaximum velocity in RPM.
Returns
true if accepted (value clamped to safe limits).
Here is the caller graph for this function:

◆ SetTargetCycles()

bool FatigueTest::FatigueTestMotion::SetTargetCycles ( uint32_t cycles)
noexcept

Set target cycle count (0 = infinite).

Parameters
cyclesTarget cycles.
Returns
true if accepted.
Here is the caller graph for this function:

◆ SetUnbounded()

void FatigueTest::FatigueTestMotion::SetUnbounded ( float current_position_degrees,
float default_range_degrees = 175.0f )
noexcept

Mark the system as unbounded and establish a default travel window.

Used when no mechanical stops are detected. Sets a default global range around the current position and establishes home/zero at the current position.

Parameters
current_position_degreesCurrent position (degrees).
default_range_degreesDefault travel range to assume (degrees).
Here is the caller graph for this function:

◆ Start()

bool FatigueTest::FatigueTestMotion::Start ( )
noexcept

Start active motion.

Requires local bounds to be set. Configures the driver for positioning mode.

Returns
true on success; false on failure (e.g., bounds not set, driver not standstill).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stop()

void FatigueTest::FatigueTestMotion::Stop ( )
noexcept

Stop active motion and command driver stop.

Here is the caller graph for this function:

◆ Update()

void FatigueTest::FatigueTestMotion::Update ( )
noexcept

Periodic update tick.

Intended to be called from a periodic task. Generates and applies updated target positions and handles dwell/cycle completion logic.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ amax_rev_s2_

float FatigueTest::FatigueTestMotion::amax_rev_s2_
private

◆ amplitude_

float FatigueTest::FatigueTestMotion::amplitude_
private

◆ bounded_

bool FatigueTest::FatigueTestMotion::bounded_
private

◆ current_cycles_

uint32_t FatigueTest::FatigueTestMotion::current_cycles_
private

◆ cycle_complete_

bool FatigueTest::FatigueTestMotion::cycle_complete_
private

◆ driver_

tmc51x0::TMC51x0<Esp32SPI>* FatigueTest::FatigueTestMotion::driver_
private

◆ driver_mutex_

Esp32TmcMutex& FatigueTest::FatigueTestMotion::driver_mutex_
private

◆ dwell_at_max_ms_

uint32_t FatigueTest::FatigueTestMotion::dwell_at_max_ms_
private

◆ dwell_at_min_ms_

uint32_t FatigueTest::FatigueTestMotion::dwell_at_min_ms_
private

◆ dwell_start_time_ms_

uint32_t FatigueTest::FatigueTestMotion::dwell_start_time_ms_
private

◆ estimated_frequency_hz_

float FatigueTest::FatigueTestMotion::estimated_frequency_hz_
private

◆ global_max_bound_

float FatigueTest::FatigueTestMotion::global_max_bound_
private

◆ global_min_bound_

float FatigueTest::FatigueTestMotion::global_min_bound_
private

◆ home_position_

float FatigueTest::FatigueTestMotion::home_position_
private

◆ local_max_bound_

float FatigueTest::FatigueTestMotion::local_max_bound_
private

◆ local_min_bound_

float FatigueTest::FatigueTestMotion::local_min_bound_
private

◆ running_

bool FatigueTest::FatigueTestMotion::running_
private

◆ start_time_us_

uint64_t FatigueTest::FatigueTestMotion::start_time_us_
private

◆ state_

MotionState FatigueTest::FatigueTestMotion::state_
private

◆ target_cycles_

uint32_t FatigueTest::FatigueTestMotion::target_cycles_
private

◆ vmax_rpm_

float FatigueTest::FatigueTestMotion::vmax_rpm_
private

The documentation for this class was generated from the following files: