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

Back-and-forth motion controller using positioning mode. More...

Collaboration diagram for BackAndForthMotion:
[legend]

Public Member Functions

 BackAndForthMotion (tmc51x0::TMC51x0< Esp32SPI > *driver)
 Construct a back-and-forth motion controller.
 
void Config (float max_vel_rpm, float accel_rev_s2, float travel_dist_deg, int max_cycles=-1)
 Configure back-and-forth motion parameters.
 
void Start ()
 Initialize and start back-and-forth motion.
 
bool Update ()
 Update back-and-forth motion (call periodically).
 
void Stop ()
 Stop back-and-forth motion.
 
uint32_t GetCyclesCompleted () const
 Get number of completed back-and-forth cycles.
 

Private Attributes

tmc51x0::TMC51x0< Esp32SPI > * driver_
 Pointer to TMC51x0 driver instance.
 
float max_velocity_rpm_
 Maximum velocity in RPM.
 
float acceleration_rev_s2_
 Acceleration in rev/s²
 
float travel_distance_deg_
 Distance to travel in each direction (degrees)
 
float center_position_deg_
 Center position (starting point) in degrees.
 
float target_position_deg_
 Current target position in degrees.
 
bool moving_forward_
 Direction flag (true = forward, false = backward)
 
bool initialized_
 Whether motion has been initialized.
 
uint32_t cycles_completed_
 Number of complete back-and-forth cycles.
 
int max_cycles_
 Maximum cycles (-1 for infinite)
 

Detailed Description

Back-and-forth motion controller using positioning mode.

Simple back-and-forth motion using TMC51x0's positioning mode. Sets target position to one end, waits until reached, then sets target to other end. Repeats continuously until max_cycles is reached (if specified).

Constructor & Destructor Documentation

◆ BackAndForthMotion()

BackAndForthMotion::BackAndForthMotion ( tmc51x0::TMC51x0< Esp32SPI > * driver)
inline

Construct a back-and-forth motion controller.

Parameters
driverPointer to TMC51x0 driver instance (must remain valid for lifetime)

Member Function Documentation

◆ Config()

void BackAndForthMotion::Config ( float max_vel_rpm,
float accel_rev_s2,
float travel_dist_deg,
int max_cycles = -1 )
inline

Configure back-and-forth motion parameters.

Parameters
max_vel_rpmMaximum velocity in RPM
accel_rev_s2Acceleration in rev/s²
travel_dist_degDistance to travel in each direction (in degrees)
max_cyclesMaximum number of back-and-forth cycles (-1 for infinite)
Here is the caller graph for this function:

◆ GetCyclesCompleted()

uint32_t BackAndForthMotion::GetCyclesCompleted ( ) const
inline

Get number of completed back-and-forth cycles.

Returns
Number of cycles completed since last Start() call

◆ Start()

void BackAndForthMotion::Start ( )
inline

Initialize and start back-and-forth motion.

Here is the caller graph for this function:

◆ Stop()

void BackAndForthMotion::Stop ( )
inline

Stop back-and-forth motion.

Stops the motor and sets ramp mode to HOLD. Motion can be restarted by calling Start() again.

Here is the caller graph for this function:

◆ Update()

bool BackAndForthMotion::Update ( )
inline

Update back-and-forth motion (call periodically).

Checks if target position has been reached and switches direction. Should be called from a periodic task or main loop.

Returns
true if motion is active, false if completed (max_cycles reached)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ acceleration_rev_s2_

float BackAndForthMotion::acceleration_rev_s2_
private

Acceleration in rev/s²

◆ center_position_deg_

float BackAndForthMotion::center_position_deg_
private

Center position (starting point) in degrees.

◆ cycles_completed_

uint32_t BackAndForthMotion::cycles_completed_
private

Number of complete back-and-forth cycles.

◆ driver_

tmc51x0::TMC51x0<Esp32SPI>* BackAndForthMotion::driver_
private

Pointer to TMC51x0 driver instance.

◆ initialized_

bool BackAndForthMotion::initialized_
private

Whether motion has been initialized.

◆ max_cycles_

int BackAndForthMotion::max_cycles_
private

Maximum cycles (-1 for infinite)

◆ max_velocity_rpm_

float BackAndForthMotion::max_velocity_rpm_
private

Maximum velocity in RPM.

◆ moving_forward_

bool BackAndForthMotion::moving_forward_
private

Direction flag (true = forward, false = backward)

◆ target_position_deg_

float BackAndForthMotion::target_position_deg_
private

Current target position in degrees.

◆ travel_distance_deg_

float BackAndForthMotion::travel_distance_deg_
private

Distance to travel in each direction (degrees)


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