RF-Positioning-System V0.1
by Max Heinekamp
Loading...
Searching...
No Matches
STEPPER Class Reference

The STEPPER class is used to manage stepper motor instances. It provides methods to control the motor's movement, direction, and configuration settings. More...

#include <stepper.h>

Public Member Functions

 STEPPER (int address, int step_pin, int enable_pin)
 Construct a new STEPPER object.
void setup ()
 Set up the stepper driver and configure it.
void step ()
 Step the motor one step.
void SetDirection (bool dir)
 Set the direction of the stepper motor.
bool GetDirection ()
 Get the current direction of the stepper motor.
void updateRMSCurrent ()
 Update the RMS current of the stepper driver from the current flash value.
void updateHoldCurrent ()
 Update the hold current of the stepper driver from the current flash value.
uint16_t getRMSCurrent ()
 Get the actual RMS current currently applied by the stepper driver.
uint8_t getHoldCurrent ()
 Get the actual hold current currently applied by the stepper driver.
void updateMicrosteps ()
 Update the microsteps of the stepper driver from the current flash value.
void move (float targetSpeed, float acceleration, float position, int steps_revolution)
 Move the motor a given angle with a given acceleration and distance.
void move (float targetSpeed, float acceleration, float position, int steps_revolution, STEPPER *stepper2, int stepper2_ratio)
 Move the motor a given angle with a given acceleration and distance.
void absoluteMove (float targetSpeed, float acceleration, float angle, int steps_revolution)
 Move the motor to a target location based on an absolute angle with a given speed and acceleration.
void absoluteMove (float targetSpeed, float acceleration, float angle, int steps_revolution, STEPPER *stepper2, int stepper2_ratio)
 Move the motor to a target location based on an absolute angle with a given speed and acceleration.
void runStepperSCurve (float targetSpeed, float maxJerk, int distance)
 Run the stepper motor using an S-curve profile.
float getCurrentPosition ()
 Get the current position of the motor in degrees.
int Debug ()

Private Attributes

TMC2209Stepper stepper
 Stepper driver object. This is the object that interfaces with the stepper driver library.
bool direction
 Direction of the motor. This is used to set the direction of the motor.
int address
 SPI address of the stepper driver.
int step_pin
 Pin that is connected to the step pin of the driver.
int enable_pin
 Pin that is connected to the enable pin of the driver.
float current_position = 0
 This stores the current position of the motor in degrees.
float steps_remainder = 0
 This stores the fractional step that needs to be carried over to the next move.

Detailed Description

The STEPPER class is used to manage stepper motor instances. It provides methods to control the motor's movement, direction, and configuration settings.

The STEPPER class uses teemutalut stepper library to interface with the stepper motor driver. It is currently setup to use TMC2209 stepper drivers, but can be adapted to work with other drivers as well.

Definition at line 20 of file stepper.h.

Constructor & Destructor Documentation

◆ STEPPER()

STEPPER::STEPPER ( int address,
int step_pin,
int enable_pin )

Construct a new STEPPER object.

Parameters
addressSPI address of the stepper driver
step_pinPin that is connected to the step pin of the driver
enable_pinPin that is connected to the enable pin of the driver

Definition at line 18 of file stepper.cpp.

Member Function Documentation

◆ absoluteMove() [1/2]

void STEPPER::absoluteMove ( float targetSpeed,
float acceleration,
float angle,
int steps_revolution )

Move the motor to a target location based on an absolute angle with a given speed and acceleration.

Note
the optimal direction will be selected automatically to minimize the travel distance.
Parameters
targetSpeedTarget speed in steps per second
accelerationAcceleration in steps per second squared
positionAbsolute target position in degrees
steps_revolutionNumber of steps per revolution

Definition at line 269 of file stepper.cpp.

◆ absoluteMove() [2/2]

void STEPPER::absoluteMove ( float targetSpeed,
float acceleration,
float angle,
int steps_revolution,
STEPPER * stepper2,
int stepper2_ratio )

Move the motor to a target location based on an absolute angle with a given speed and acceleration.

Note
the optimal direction will be selected automatically to minimize the travel distance.
Parameters
targetSpeedTarget speed in steps per second
accelerationAcceleration in steps per second squared
positionAbsolute target position in degrees
steps_revolutionNumber of steps per revolution
stepper2Second stepper motor to move (if motors are mechanically coupled)
steps_revolution2Number of steps per revolution for the second stepper motor

Definition at line 297 of file stepper.cpp.

◆ Debug()

int STEPPER::Debug ( )

Definition at line 385 of file stepper.cpp.

◆ getCurrentPosition()

float STEPPER::getCurrentPosition ( )
inline

Get the current position of the motor in degrees.

Returns
float Current position of the motor in degrees

Definition at line 152 of file stepper.h.

◆ GetDirection()

bool STEPPER::GetDirection ( )

Get the current direction of the stepper motor.

Returns
true if the motor is set to ccw, false if cw

Definition at line 59 of file stepper.cpp.

◆ getHoldCurrent()

uint8_t STEPPER::getHoldCurrent ( )

Get the actual hold current currently applied by the stepper driver.

Returns
uint8_t Applied raw IHOLD register value

Definition at line 78 of file stepper.cpp.

◆ getRMSCurrent()

uint16_t STEPPER::getRMSCurrent ( )

Get the actual RMS current currently applied by the stepper driver.

Returns
uint16_t Applied RMS current in mA, back-converted from the driver's CS register

Definition at line 74 of file stepper.cpp.

◆ move() [1/2]

void STEPPER::move ( float targetSpeed,
float acceleration,
float position,
int steps_revolution )

Move the motor a given angle with a given acceleration and distance.

Note
The direction is based on the current state of stepper.direction
Parameters
targetSpeedTarget speed in steps per second
accelerationAcceleration in steps per second squared
angleDistance to move in steps
steps_revolutionNumber of steps per revolution

Definition at line 87 of file stepper.cpp.

◆ move() [2/2]

void STEPPER::move ( float targetSpeed,
float acceleration,
float position,
int steps_revolution,
STEPPER * stepper2,
int stepper2_ratio )

Move the motor a given angle with a given acceleration and distance.

Note
The direction is based on the current state of stepper.direction
Parameters
targetSpeedTarget speed in steps per second
accelerationAcceleration in steps per second squared
angleDistance to move in steps
steps_revolutionNumber of steps per revolution
stepper2Second stepper motor to move (if motors are mechanically coupled)
steps_revolution2Number of steps per revolution for the second stepper motor

Definition at line 169 of file stepper.cpp.

◆ runStepperSCurve()

void STEPPER::runStepperSCurve ( float targetSpeed,
float maxJerk,
int distance )

Run the stepper motor using an S-curve profile.

Parameters
targetSpeedTarget speed in steps per second
maxJerkMaximum jerk in steps per second cubed
distanceDistance to move in steps

Definition at line 327 of file stepper.cpp.

◆ SetDirection()

void STEPPER::SetDirection ( bool dir)

Set the direction of the stepper motor.

Parameters
dirDirection to set (true for ccw, false for cw)

Definition at line 54 of file stepper.cpp.

◆ setup()

void STEPPER::setup ( )

Set up the stepper driver and configure it.

Definition at line 26 of file stepper.cpp.

◆ step()

void STEPPER::step ( )

Step the motor one step.

Definition at line 48 of file stepper.cpp.

◆ updateHoldCurrent()

void STEPPER::updateHoldCurrent ( )

Update the hold current of the stepper driver from the current flash value.

Definition at line 69 of file stepper.cpp.

◆ updateMicrosteps()

void STEPPER::updateMicrosteps ( )

Update the microsteps of the stepper driver from the current flash value.

Definition at line 82 of file stepper.cpp.

◆ updateRMSCurrent()

void STEPPER::updateRMSCurrent ( )

Update the RMS current of the stepper driver from the current flash value.

Definition at line 63 of file stepper.cpp.

Member Data Documentation

◆ address

int STEPPER::address
private

SPI address of the stepper driver.

Definition at line 175 of file stepper.h.

◆ current_position

float STEPPER::current_position = 0
private

This stores the current position of the motor in degrees.

Definition at line 194 of file stepper.h.

◆ direction

bool STEPPER::direction
private

Direction of the motor. This is used to set the direction of the motor.

Note
true for ccw, false for cw
this is set over the SPI inter, so the dir pin on the driver is not required.

Definition at line 170 of file stepper.h.

◆ enable_pin

int STEPPER::enable_pin
private

Pin that is connected to the enable pin of the driver.

Note
This pin is used to enable/disable the driver.

Definition at line 188 of file stepper.h.

◆ step_pin

int STEPPER::step_pin
private

Pin that is connected to the step pin of the driver.

Note
This pin is used to send step pulses to the driver.

Definition at line 181 of file stepper.h.

◆ stepper

TMC2209Stepper STEPPER::stepper
private

Stepper driver object. This is the object that interfaces with the stepper driver library.

Definition at line 163 of file stepper.h.

◆ steps_remainder

float STEPPER::steps_remainder = 0
private

This stores the fractional step that needs to be carried over to the next move.

As steps can only be taken in whole integer amounts, depending on the selected angle there may be a fractional step that needs to be carried over to the next move. This value is obtained by rounding down the number of steps to the nearest integer and storing the remainder here. It can then be added to the number of steps to be taken for the next move to ensure that these small errors do not build up over time, causing a drift in the position of the device.

Definition at line 206 of file stepper.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/RF-Positioning-System/RF-Positioning-System/Code/RF-Positioning-System/include/stepper.h
  • /home/runner/work/RF-Positioning-System/RF-Positioning-System/Code/RF-Positioning-System/src/stepper.cpp