![]() |
Can Opener - ME 507
|
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. | |
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.
| 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
| new_id | The ID to be set to the object |
| stepsPerRev | The number of steps per revolution for the given stepper motor, which equals 360 degrees/degrees per step |
| pin1 | The pin that is connected to the positive side of the first loop - also known as Phase A. |
| pin2 | The pin that is connected to the negative side of the first loop - also known as Phase A-Bar. |
| pin3 | The pin that is connected to the positive side of the second loop - also known as Phase B. |
| pin4 | The pin that is connected to the negative side of the second loop - also known as Phase B-Bar. |
| enable | The pin that is connected to the enable pin of the motor driver. |
| new_speed | The speed in RPM that you want the stepper motor to spin at. |
| uint8_t StepperDriver::getID | ( | void | ) |
Returns the ID of the StepperDriver object.
| 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
| float StepperDriver::getSpeed | ( | void | ) |
Returns the speed of the stepper motor in RPM.
| 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()
| steps | The number of steps for the motor to rotate through. |
| 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.
| new_pos | The new position to be set |
| 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
| new_speed | The speed in RPM that the stepper motor will rotate at |