Can Opener - ME 507
StepperDriver Class Reference

Class for driving a stepper motor. More...

#include <StepperDriver.h>

Public Member Functions

 StepperDriver (uint8_t new_id, uint8_t stepsPerRev, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t enable, uint8_t new_speed)
 Constructor for the StepperDriver object. More...
 
void move (int16_t steps)
 Moves the stepper motor a specified number of steps. More...
 
int32_t getPosition (void)
 Gets the current position of the stepper motor. More...
 
void setPosition (int32_t new_pos)
 Sets the current position of the stepper motor. More...
 
void setSpeed (float new_speed)
 Sets the speed of the stepper motor in RPM. More...
 
float getSpeed (void)
 Returns the speed of the stepper motor in RPM. More...
 
uint8_t getID (void)
 Returns the ID of the StepperDriver object. More...
 

Protected Attributes

int32_t curr_pos
 The current position of the motor.
 
uint8_t id
 The ID of the StepperDriver object.
 
uint8_t pin_A
 The pin connected to the positive side of the A coil.
 
uint8_t pin_Abar
 The pin connected to the negative side of the A coil.
 
uint8_t pin_B
 The pin connected to the positive side of the B coil.
 
uint8_t pin_Bbar
 The pin connected to the negative side of the A coil.
 
uint8_t pin_enable
 The enable pin.
 
float speed
 The speed in RPM the motor rotates at.
 
Stepper * p_Stepper
 A pointer to a Stepper object.
 

Detailed Description

Class for driving a stepper motor.

This class uses the Arduino Stepper module and adds some functionality on top of that class. The driver also has the ability to track the position of the stepper motor.

Constructor & Destructor Documentation

◆ StepperDriver()

StepperDriver::StepperDriver ( uint8_t  new_id,
uint8_t  stepsPerRev,
uint8_t  pin1,
uint8_t  pin2,
uint8_t  pin3,
uint8_t  pin4,
uint8_t  enable,
uint8_t  new_speed 
)

Constructor for the StepperDriver object.

In the constructor, the pins for the stepper are defined, and the enable pin. In the constructor, the position is initialized to 0, the enable pin is set high, and a new Stepper object is created from the Arduino library. The object also contains an id that can be read from the object

Parameters
new_idThe ID to be set to the object
stepsPerRevThe number of steps per revolution for the given stepper motor, which equals 360 degrees/degrees per step
pin1The pin that is connected to the positive side of the first loop - also known as Phase A.
pin2The pin that is connected to the negative side of the first loop - also known as Phase A-Bar.
pin3The pin that is connected to the positive side of the second loop - also known as Phase B.
pin4The pin that is connected to the negative side of the second loop - also known as Phase B-Bar.
enableThe pin that is connected to the enable pin of the motor driver.
new_speedThe speed in RPM that you want the stepper motor to spin at.

Member Function Documentation

◆ getID()

uint8_t StepperDriver::getID ( void  )

Returns the ID of the StepperDriver object.

Returns
The ID of the StepperDriver object

◆ getPosition()

int32_t StepperDriver::getPosition ( void  )

Gets the current position of the stepper motor.

The position that is returned is returned in terms of total steps, so it will need to be converted to other units

Returns
The number of steps that the motor has rotated through.

◆ getSpeed()

float StepperDriver::getSpeed ( void  )

Returns the speed of the stepper motor in RPM.

Returns
The speed of the motor in RPM

◆ move()

void StepperDriver::move ( int16_t  steps)

Moves the stepper motor a specified number of steps.

This function moves the stepper the number of steps, which correlates to the number of degrees equal to degrees/step * steps. The motor moves at the speed according to StepperDriver::setSpeed()

Parameters
stepsThe number of steps for the motor to rotate through.

◆ setPosition()

void StepperDriver::setPosition ( int32_t  new_pos)

Sets the current position of the stepper motor.

This method takes in an input argument and changes the position that will be returned when StepperDriver::getPosition() is called. This is called in the constructor to set the position to 0.

Parameters
new_posThe new position to be set

◆ setSpeed()

void StepperDriver::setSpeed ( float  new_speed)

Sets the speed of the stepper motor in RPM.

This is a wrapper method for the Stepper.h setSpeed() function

Parameters
new_speedThe speed in RPM that the stepper motor will rotate at

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