TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StepperMotor< T > Class Template Reference

Stepper motor driver using FastAccelStepper for Arduino. More...

#include <StepperMotor.h>

Inheritance diagram for StepperMotor< T >:
Inheritance graph
[legend]
Collaboration diagram for StepperMotor< T >:
Collaboration graph
[legend]

Public Member Functions

 StepperMotor (uint8_t id=0)
 
 StepperMotor (uint8_t id, uint16_t stepsPerRevolution, float maxSpeedStepsPerSec, uint16_t accelerationMs)
 
void setPins (int stepPin, int dirPin, int enablePin=-1)
 
void setMaxSpeed (float stepsPerSec)
 
void setAccelerationMs (uint16_t ms)
 Set acceleration time in milliseconds to reach max speed (e.g., 2000 ms)
 
void setStepsPerRevolution (int steps)
 
bool begin ()
 
bool setValuePercent (T percent) override
 
getValuePercent () const override
 
void end () override
 Stop the stepper motor.
 
bool isPinsSet () const override
 
- Public Member Functions inherited from IMotor< T >
virtual bool begin ()=0
 
virtual void end ()=0
 
virtual bool isPinsSet () const =0
 
virtual bool setValuePercent (T percent)=0
 
virtual T getValuePercent () const =0
 
void setID (uint8_t id)
 
uint8_t getID () const
 

Protected Member Functions

void callbackFastAccel (FastAccelStepper *s)
 
void setSpeedPercent (T percent)
 

Protected Attributes

lastValuePercent = 0.0f
 
FastAccelStepperEngine engine
 
FastAccelStepper * stepper = NULL
 
int pinStep = -1
 
int pinDir = -1
 
int pinEnable = -1
 
bool is_pins_set = false
 
float maxSpeedHz = 2000
 
uint16_t accelerationMs = 2000
 
uint16_t stepsPerRevolution = 200
 
void * ref = nullptr
 
void(* callback )(void *) = nullptr
 
- Protected Attributes inherited from IMotor< T >
uint8_t id = 0
 

Detailed Description

template<typename T = float>
class tinyrobotics::StepperMotor< T >

Stepper motor driver using FastAccelStepper for Arduino.

This class provides an interface to control stepper motors with acceleration and speed control. It supports:

You can set pins, maximum speed, acceleration, and steps per revolution. The motor can be started, stopped, or moved by distance or revolutions. Acceleration is handled automatically based on the configured accelerationMs.

The class uses FastAccelStepper's continuous mode for setSpeed(), and supports asynchronous notification via callback for move operations.

@dependencies

Main methods:

Usage notes:

Example usage:

Stepper stepper;
stepper.setPins(2, 3, 4);
stepper.setMaxSpeed(1000);
stepper.setStepsPerRevolution(200);
stepper.setAccelerationMs(2000);
stepper.begin();
stepper.setSpeed(50); // Move at 50% of max speed (continuous mode)
stepper.setSpeed(0); // Stop
stepper.end(); // Ensure motor is stopped

Member Function Documentation

◆ begin()

bool begin ( )
inlinevirtual

Initialize the stepper hardware. Must be called after setting pins and speed parameters.

Implements IMotor< T >.

◆ end()

void end ( )
inlineoverridevirtual

Stop the stepper motor.

Implements IMotor< T >.

◆ getValuePercent()

T getValuePercent ( ) const
inlineoverridevirtual

Implements IMotor< T >.

◆ isPinsSet()

bool isPinsSet ( ) const
inlineoverridevirtual

Implements IMotor< T >.

◆ setMaxSpeed()

void setMaxSpeed ( float  stepsPerSec)
inline

Set maximum speed in steps per second (e.g., 500 for 1.8 degree stepper, 1000

◆ setStepsPerRevolution()

void setStepsPerRevolution ( int  steps)
inline

Set the number of steps per full revolution (e.g., 200 for 1.8 degree stepper)

◆ setValuePercent()

bool setValuePercent ( percent)
inlineoverridevirtual

Set continuous speed as a percentage (-100 to 100). Positive for forward, negative for backward.

Implements IMotor< T >.


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