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>
|
| | 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 () |
|
| 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.
|
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.
◆ STEPPER()
| STEPPER::STEPPER |
( |
int | address, |
|
|
int | step_pin, |
|
|
int | enable_pin ) |
Construct a new STEPPER object.
- Parameters
-
| address | SPI address of the stepper driver |
| step_pin | Pin that is connected to the step pin of the driver |
| enable_pin | Pin that is connected to the enable pin of the driver |
Definition at line 18 of file stepper.cpp.
◆ 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
-
| targetSpeed | Target speed in steps per second |
| acceleration | Acceleration in steps per second squared |
| position | Absolute target position in degrees |
| steps_revolution | Number 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
-
| targetSpeed | Target speed in steps per second |
| acceleration | Acceleration in steps per second squared |
| position | Absolute target position in degrees |
| steps_revolution | Number of steps per revolution |
| stepper2 | Second stepper motor to move (if motors are mechanically coupled) |
| steps_revolution2 | Number of steps per revolution for the second stepper motor |
Definition at line 297 of file stepper.cpp.
◆ Debug()
◆ 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
-
| targetSpeed | Target speed in steps per second |
| acceleration | Acceleration in steps per second squared |
| angle | Distance to move in steps |
| steps_revolution | Number 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
-
| targetSpeed | Target speed in steps per second |
| acceleration | Acceleration in steps per second squared |
| angle | Distance to move in steps |
| steps_revolution | Number of steps per revolution |
| stepper2 | Second stepper motor to move (if motors are mechanically coupled) |
| steps_revolution2 | Number 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
-
| targetSpeed | Target speed in steps per second |
| maxJerk | Maximum jerk in steps per second cubed |
| distance | Distance 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
-
| dir | Direction to set (true for ccw, false for cw) |
Definition at line 54 of file stepper.cpp.
◆ setup()
Set up the stepper driver and configure it.
Definition at line 26 of file stepper.cpp.
◆ 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.
◆ address
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
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
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
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