upm
0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
|
API for the Stepper Motor. More...
This module defines the Stepper Motor interface. It is compatible with stepper motor drivers that use 2 pins to control the motor, like an Easy Driver from Brian Schmalz or the STR driver series from Applied Motion. It can also control an enable pin if one is available and connected.
The implementation is synchronous and thus blocking while the stepper motor is in motion. However it is possible to send the commands via threading and the performance of the library will be very good given a low CPU load. On a busy system though you will notice some jitter especially at higher speeds. It is possible to reduce this effect to some extent by using smoothing and/or microstepping on stepper drivers that support such features.
EasyDriver Sensor image provided by SparkFun* under CC BY-NC-SA-3.0.
Public Member Functions | |
StepMotor (int dirPin, int stePin, int steps=200, int enPin=-1) | |
~StepMotor () | |
void | enable (bool flag) |
void | setSpeed (int speed) |
mraa::Result | step (int ticks) |
mraa::Result | stepForward (int ticks) |
mraa::Result | stepBackward (int ticks) |
void | setPosition (int pos) |
int | getPosition () |
int | getStep () |
StepMotor | ( | int | dirPin, |
int | stePin, | ||
int | steps = 200 , |
||
int | enPin = -1 |
||
) |
Instantiates a StepMotor object.
dirPin | Direction GPIO pin |
stePin | Stepper pulse GPIO pin |
steps | Number of steps per revolution (Default 200) |
enPin | Enable pin if connected (Optional) |
void enable | ( | bool | flag | ) |
Can be used to enable/disable the stepper driver if an enable pin is available and connected. Check your data sheet as some drivers might have the enable logic inverted.
flag | true to enable or false to disable |
void setSpeed | ( | int | speed | ) |
Sets the rotation speed in rpm. Default 60 rpm.
speed | Rotation speed in rpm |
mraa::Result step | ( | int | ticks | ) |
Rotates the motor by the specified number of steps. Positive values rotate clockwise and negative values rotate counter-clockwise.
ticks | Number of steps the motor moves |
mraa::Result stepForward | ( | int | ticks | ) |
Rotates the motor forward (clockwise).
ticks | Number of steps the motor moves |
mraa::Result stepBackward | ( | int | ticks | ) |
Rotates the motor backward (counter-clockwise).
ticks | Number of steps the motor moves |
void setPosition | ( | int | pos | ) |
Sets the current position. Useful if the motor is not at 0 when the driver is initialized.
step | Current position |
int getPosition | ( | ) |
Gets the current position. This is cumulative and the result of all the step commands sent to the motor.
int getStep | ( | ) |
Gets the current step. This is relative to one revolution.