-
Notifications
You must be signed in to change notification settings - Fork 2
Reference
Note that library use one pre-declared object, StepperDriver (it looks like usage of Serial in Arduino).
- init()
- newAxis()
- enable()
- disable()
- setDir()
- setDelay()
- setSpeed()
- write()
- move()
- stop()
- busy()
- wait()
- getPath()
- resetPath()
Run this function once in the setup(). It performs initialization of hardware timer.
Arguments: No arguments.
Return value: Nothing.
Example:
void setup() {
StepperDriver.init();
}
Creates new axis which uses pins from arguments list. Returns the index of newly registered axis, you need to save it for control.
Arguments:
- int step: number of pin where STEP signal for axis is connected;
- int dir: number of pin where DIR signal is connected;
- int enable (optional): number of pin where ENABLE signal is connected (if driver has it).
_Return value: axis_t, index of registered axis.
Example:
axis_t my_motor;
void setup() {
StepperDriver.init();
my_motor = StepperDriver.newAxis(1, 2, 3);
}
Enable the axis on driver level (if driver has an ENABLE channel for the axis).
Arguments: axis_t axis - index of axis to enable.
Return value: Nothing.
Example:
axis_t my_motor;
void setup() {
... /* initialization */
StepperDriver.enable(my_motor);
}
Disable the axis on driver level (if driver has an ENABLE channel for the axis).
Arguments: axis_t axis - index of axis to disable.
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
... /* some profitful work */
if (need_to_disable)
StepperDriver.disable(my_motor);
}
Set rotation direction for this axis (variants are defined: FORWARD and BACKWARD).
Arguments:
- axis_t axis: index of axis to set direction;
- int dir: FORWARD or BACKWARD
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
StepperDriver.setDir(my_motor, FORWARD);
...
StepperDriver.setDir(my_motor, BACKWARD);
}
Set the step signal delay for the axis (in microseconds).
Arguments:
- axis_t axis: index of axis to set delay for;
- int delay: value of delay from 0 to 65535 in microseconds; 0 is for stop motor.
Return value: nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.setDelay(my_motor, 20000); /* step delay is 20 ms == 20000 us */
...
}
Set the motor speed (step signal frequency) for the axis
Arguments:
- axis_t axis: index of axis to set speed for;
- int speed: speed (frequency) value from 0 to 65535 (greater number for greater speed).
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.setSpeed(my_motor, 65535); /* rotate motor at maximum speed, delay is about 16 us */
...
}
Launch the motor using signed value of speed. Also, you can set path limit (in steps) for the engine if necessary.
Note: If you limit the path, function will return immediately. To wait for the end of movement, use wait() (or check the state of motor by using busy() to do something profitful while motor is in duty), or replace write() with move() - it will wait for motor to end the movement.
Arguments:
- axis_t axis: index of axis to write value to;
- int speed: value from -65535 to 65535, negative for backward, positive for forward direction;
- int path (optional): limit for path (positive 32-bit value).
Return value: Nothing;
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.write(my_motor, 32768); /* run the motor in infinite movement mode, speed 32768 */
...
StepperDriver.write(my_motor, -65535, 1000); /* run 1000 steps at maximum speed in backward direction */
...
}
Same as write(axis, speed, path), but waits for motor to end the limited movement. For unlimited movement, use write(axis, speed) instead.
Arguments:
- axis_t axis: index of axis to write value to;
- int speed: value from -65535 to 65535, negative for backward, positive for forward direction;
- int path: limit for path (positive 32-bit value).
Return value: Nothing;
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.move(my_motor, -65535, 1000); /* run 1000 steps at maximum speed in backward direction and wait for the end of movement */
...
}
Stop the motor immediately (after each kind of launch: setSpeed(), write() or move()).
Arguments: axis_t axis: index of axis to stop.
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.stop(my_motor);
...
}
Checks if motor is working. Note than this function returns true in both cases: if motor is in limited movement and unlimited movement. If motor is stopped, function returns false.
Arguments: axis_t axis: index of axis to check.
Return value: bool, state of motor: true if it's moving and false if not.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.write(my_motor, 32768, 5000);
while (StepperDriver.busy(my_motor)) {
/* do something while motor is moving */
}
...
}
Wait for motor to end movement. If the unlimited movement was set, it won't wait at all.
Arguments: axis_t axis: index of axis to wait for.
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
...
StepperDriver.write(my_motor, 32768, 5000);
StepperDriver.wait(my_motor); /* Right usage */
/* These lines are same as: StepperDriver.move(my_motor, 32768, 5000); */
}
Get the tracked path of motor (in steps). Note than path calculator hasn't got a feedback detector, so it just counts steps according to direction.
Arguments: axis_t axis: index of axis to get path from.
Return value: int, path (signed 32-bit value).
Example:
axis_t my_motor;
... /* initialization */
void loop() {
... /* some moves here */
int path = StepperDriver.getPath(my_motor);
/* If you work with large values, it's recommended to use
* int32_t path = StepperDriver.getPath(my_motor);
*/
...
}
Reset the path value for axis (set it to zero).
Arguments: axis_t axis: index of axis to get path from.
Return value: Nothing.
Example:
axis_t my_motor;
... /* initialization */
void loop() {
... /* some moves here */
int path = StepperDriver.getPath(my_motor);
StepperDriver.resetPath(my_motor); /* count from the beginning */
...
}