WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation


Provides generic support for all stepper motor controllers to set continuous rotation speeds or the (servo - like) movement to a given location.
This driver allows you to build a list of stepper motor controllers and then attach the list to a timer to generate the necessary pulses for each motor. The list can contain any mixture of different stepper motor controllers.
Assuming we have two Pololu A4983 stepper motor controllers then we can define each motor as follows:
#include <Stepper/Pololu/A4983.h>
POLOLU_A4983 motorA = MAKE_POLOLU_A4983(false,200,127,1,A0,A1,null,null);
POLOLU_A4983 motorB = MAKE_POLOLU_A4983(false,200,127,1,A2,A3,null,null);
The detail of the parameters for MAKE_POLOLU_A4983 is described in the section for that controller.
We can now combine them into a list, in PROGMEM, called 'bank':
STEPPER_LIST PROGMEM bank[] = { &motorA.stepper, &motorB.stepper};
Then we can pass the list to a driver:
Finally you need to initialise the driver from 'appInitHardware':
You can now use the motors via the functions described in this section.




MAKE_STEPPER_DRIVER(STEPPER_LIST* motors, uin16_t frequency)

Create a driver to communicate with one, or more, stepper motor controllers.
The first parameter is the list of motor controllers.
The second parameter specifies the maximum step frequency in Hertz. ie a value of 200 would mean that the maximum speed for the motors is set at 200 steps per second. Check the datasheets for the motors you are using to see if they specify this value. If they don't then you will need to find it by trial error. If the number is too low then you will be restricting the maximum speed of the motor and if it is too high then the motor may ignore some of the pulses as it is unable to keep up.

stepper_init(STEPPER_DRIVER* driver, const Timer* timer)

Initialises the driver and connects it to a timer. This should be called from appInitHardware.
The first parameter is the address of the driver and the second parameter is an available 16 bit timer.

stepper_setSpeed(STEPPER_MOTOR* motor, DRIVE_SPEED speed)

Set the continuous rotation speed to a value between DRIVE_SPEED_MIN and DRIVE_SPEED_MAX.
If the motor has been disconnected then nothing will happen until it is reconnected. The motor will accelerate, or decelerate, from its current speed to the specified speed.

DRIVE_SPEED stepper_getSpeed(const STEPPER_MOTOR* motor)

Returns the last value from 'stepper_setSpeed'.
NB This is not necessarily the actual speed that the motor is moving at - it is the target speed.

stepper_setConnected(STEPPER_MOTOR* motor,boolean connected)

Connect or disconnect the motor. The second parameter should be TRUE to connect, or FALSE to disconnect.
When a motor is disconnected it stops receiving commands and, if the motor controller allows it, the current to the motor is removed.

boolean stepper_isConnected(const STEPPER_MOTOR* motor)

Test if a motor is connected. Returns TRUE if it is, and FALSE if it is not.

boolean stepper_isInverted(const STEPPER_MOTOR* motor)

Test if the motor is inverted. Returns TRUE if it is, FALSE if it is not.
You cannot change the inverted state except when creating the motor.

DRIVE_SPEED stepper_getActualSpeed(const STEPPER_MOTOR* motor)

Returns the actual rotation speed of the motor.

uint16_t stepper_getPosition(const STEPPER_MOTOR* motor)

Returns the current position of the motor.
The returned value will be between 0 and the (number_of_steps_per_revolution - 1). eg if the stepper motor has 200 steps per revolution then it will be a number between 0 and 199.

stepper_move(STEPPER_MOTOR* motor, int16_t steps)

Tell the motor to move by the specified number of steps and then stop.
A positive number will make the motor turn clockwise, and a negative number will make the motor turn anti-clockwise.
The motor will accelerate in the required direction and then slow down as it approaches the goal.

int16_t stepper_getStepsRemaining(const STEPPER_MOTOR* motor)

Returns the number of remaining steps from the last stepper_move command.
This can be used to test if a stepper_move command has finished by checking if the returned value is zero.

Valid XHTML 1.0 Transitional