abdrive library
v0.9.84
Differential servo and encoder drive library for the Parallax ActivityBot
|
This library takes care of encoder monitoring and servo signaling, and provides a simple set of functions for making the ActivityBot go certain distances and speeds.
For more information, go here:
http://learn.parallax.com/activitybot/navigation-basics
More...
#include "simpletools.h"
#include "simpletext.h"
#include "fdserial.h"
Go to the source code of this file.
Macros | |
#define | ABD_RAMP_STEP 12 |
This default corresponds 600 ticks/second^2 acceleration and can be adjusted with the drive_setAcceleration function. | |
#define | ABD_SPEED_LIMIT 128 |
The default drive_speed limit is +/-128 ticks/second. This can be adjusted at runtime with the drive_setSpeed and drive_setMaxVelocity functions. | |
#define | ABD_GOTO_SPEED_LIMIT 64 |
This default defines the speed limit when the drive_goto function is called and can be adjusted with the drive_setMaxVelocity function. | |
#define | ABD_GOTO_RAMP_STEP 4 |
This default corresponds 200 ticks/second^2 acceleration and can be adjusted with the drive_setAcceleration function. | |
#define | ABD_NUDGE_SPEED 4 |
Ticks per second to nudge to the final position do complete a drive_goto call. | |
#define | ABD_STOP_50ths 5 |
This is the number of 50ths of a second that the ActivityBot delays when it crosses the zero speed threshold when executing drive_goto calls. | |
#define | _ActivityBot_EE_Start_ 63418 |
ActivityBot EEPROM calibration data start address. | |
#define | _ActivityBot_EE_End_ 63418 + 2052 |
ActivityBot EEPROM calibration data end address. | |
#define | FOR_GOTO 1 |
This constant can be used in place of 0 to tell drive_setAcceleration and drive_setMaxVelocity to set maximum velocity/acceleration for calls to drive_goto. | |
#define | FOR_SPEED 0 |
This constant can be used in place of 0 to tell drive_setAcceleration and drive_setMaxVelocity to set maximum velocity/acceleration for calls to drive_speed. | |
#define | OFF 0 |
OFF can be used in place of zero to enabled parameters in functions like drive_feedback and drive_trim. | |
#define | ON 1 |
ON can be used in place of a nonzero value to enabled parameters in functions like drive_feedback and drive_trim. | |
#define | SIDE_LEFT 0 |
Parameter option for drive_gotoStatus(int side). | |
#define | SIDE_RIGHT 1 |
Parameter option for drive_gotoStatus(int side). | |
#define | SIDE_BOTH 2 |
Parameter option for drive_gotoStatus(int side). |
Functions | |
void | drive_goto (int distLeft, int distRight) |
Make each wheel go a particular distance. Recommended for straight forward, backward, turns, pivots, and curves/arcs. This function ramps up to full speed if the distance is long enough. It holds that speed until it needs to ramp down. After ramping down it applies compensation. By default, this function does not return until the maneuver has completed. | |
void | drive_speed (int left, int right) |
Set wheel speeds in encoder ticks per second. An encoder tick is 1/64th of a revolution, and makes causes the wheel to roll 3.25 mm. | |
void | drive_getTicks (int *left, int *right) |
Get the measured number of ticks the have traveled. | |
void | drive_calibrationResults (void) |
Uses the calibration settings to find common circuit mistakes that prevent the ActivityBot from operating normally. This function will either display a success message or information about one or more problems. Make sure to re-run the ActivityBot calibration after fixing each problem. Do not try to continue with any of the ActivityBot tutorials until you have run the calibration, and then run a program with this function call and it displays a message that the ActivitiyBot has been successfully calibrated. Instructions: (BlocklyProp) http://learn.parallax.com/blockly/calibrate-your-activitybot Instructions: (Propeller C) http://learn.parallax.com/activitybot/test-and-tune-your-activitybot. | |
More Info | |
void | drive_displayInterpolation (void) |
Displays the interpolation table stored in EEPROM by the calibration step. For more info, see: http://learn.parallax.com/activitybot/test-and-tune-your-activitybot. | |
void | drive_getTicksCalc (int *left, int *right) |
Get the calculated number of ticks the encoders should have traveled. | |
int | drive_gotoStatus (int side) |
Can be used after drive_gotoMode(OFF) to check if a maneuver has been completed. | |
Settings | |
void | drive_encoderPins (int encPinLeft, int encPinRight) |
Set encoder pins to values other than the default P14 for left encoder and P15 for right encoder. Stores values in EEPROM, so you only need to call this function at the start of one program. Programs that are after that will get the values from EEPROM. | |
void | drive_feedback (int enabled) |
Enables or disables encoder feedback for speed control. | |
void | drive_gotoMode (int mode) |
Set the mode (blocking or interruptible) of the drive_goto call. For calls in interruptible mode, sufficient time must be allowed for the maneuver to complete. The drive_gotoStatus function can be polled to find when a maneuver is done. | |
void | drive_servoPins (int servoPinLeft, int servoPinRight) |
Set servo pins to values other than the default P12 for left servo and P13 for right servo. Stores values in EEPROM, so you only need to call this function at the start of one program. Programs that are after that will get the values from EEPROM. | |
void | drive_setAcceleration (int forGotoOrSpeed, int ticksPerSecSq) |
Set the acceleration used by either drive_goto or drive_speed. | |
void | drive_setMaxSpeed (int speed) |
Modifies the default maximum top speed for use with encoders. The default is 128 ticks/second = 2 revolutions per second (RPS). This is the full speed that drive_distance and drive_goto use. This value can currently be reduced, but not increased. Speeds faster than 128 ticks per second are "open loop" meaning the control system does not use the encoders to correct distance/speed. | |
void | drive_setMaxVelocity (int forGotoOrSpeed, int ticksPerSec) |
Set the maximum velocity used by either drive_goto or drive_speed. | |
Deprecated | |
void | drive_setRampStep (int stepsize) |
Overrides the default 12 ticks/second per 50th of a second for ramping. | |
void | drive_rampStep (int left, int right) |
This function allows your code to ask for a speed repeatedly in a loop, but each time your code asks for that speed, it takes a step toward the speed. This helps cushion sudden maneuvers in sensor navigation, where the conditions might change more rapidly than you would want your ActivityBot's speed to change. (Note: This is now built into drive_speed.) | |
void | drive_ramp (int left, int right) |
This function ramps up to a given speed and blocks execution until the speed is reached. In practice, a call to drive_speed followed by a pause to reach the desired speed will have the same affect but does not have practical applications. |
Private (used by abdrive library) | |
#define | _ActivityBot_EE_Pins_ 12 |
#define | _ActivityBot_EE_Trims_ 28 |
#define | _ActivityBot_EE_Left_ 52 |
#define | _ActivityBot_EE_Right_ 1052 |
#define | ABD_L 0 |
#define | ABD_R 1 |
#define | ABD_B 2 |
#define | ABD_T 3 |
#define | ABD_FOR_BOTH 2 |
#define | AB_RIGHT 1 |
#define | AB_LEFT -1 |
#define | AB_FORWARD 1 |
Text. | |
#define | AB_BACKWARD -1 |
Text. | |
void | monitor_start (int monitorReps) |
void | monitor_stop (void) |
This library takes care of encoder monitoring and servo signaling, and provides a simple set of functions for making the ActivityBot go certain distances and speeds.
For more information, go here:
http://learn.parallax.com/activitybot/navigation-basics
void drive_encoderPins | ( | int | encPinLeft, |
int | encPinRight | ||
) |
Set encoder pins to values other than the default P14 for left encoder and P15 for right encoder. Stores values in EEPROM, so you only need to call this function at the start of one program. Programs that are after that will get the values from EEPROM.
IMPORTANT This function should be called first, before any adbrive control functions (drive_speed, drive_goto, etc).
encPinLeft | I/O pin number for the left encoder signal connection. |
encPinRight | I/O pin number for the right encoder signal connection. |
void drive_feedback | ( | int | enabled | ) |
Enables or disables encoder feedback for speed control.
enabled | Set to 1 to enable feedback (default) or 0 to disable. |
void drive_getTicks | ( | int * | left, |
int * | right | ||
) |
Get the measured number of ticks the have traveled.
The system samples the encoders at 400 times per second.
*left | Pointer to variable to receive the measured left distance. |
*right | Pointer to variable to receive the measured right distance. |
void drive_getTicksCalc | ( | int * | left, |
int * | right | ||
) |
Get the calculated number of ticks the encoders should have traveled.
The system samples the encoders at 400 times per second.
*left | Pointer to variable to receive the calculated left distance. |
*right | Pointer to variable to receive the calculated right distance. |
void drive_goto | ( | int | distLeft, |
int | distRight | ||
) |
Make each wheel go a particular distance. Recommended for straight forward, backward, turns, pivots, and curves/arcs. This function ramps up to full speed if the distance is long enough. It holds that speed until it needs to ramp down. After ramping down it applies compensation. By default, this function does not return until the maneuver has completed.
distLeft | Left wheel distance in ticks (spoke to space and space to spoke transitions). Each "tick" transition is 1/64th of a wheel revolution, causing the wheel to roll approximately 3.25 mm. |
distRight | Right wheel distance in ticks. |
void drive_gotoMode | ( | int | mode | ) |
Set the mode (blocking or interruptible) of the drive_goto call. For calls in interruptible mode, sufficient time must be allowed for the maneuver to complete. The drive_gotoStatus function can be polled to find when a maneuver is done.
mode | interruptible (0) or blocking (1). By default the drive_goto function blocks until the maneuver has completed. |
int drive_gotoStatus | ( | int | side | ) |
Can be used after drive_gotoMode(OFF) to check if a maneuver has been completed.
side | with options of SIDE_LEFT, SIDE_RIGHT, or SIDE_BOTH. |
void drive_ramp | ( | int | left, |
int | right | ||
) |
This function ramps up to a given speed and blocks execution until the speed is reached. In practice, a call to drive_speed followed by a pause to reach the desired speed will have the same affect but does not have practical applications.
left | Left wheel speed in ticks per second. |
right | Left wheel speed in ticks per second. |
void drive_rampStep | ( | int | left, |
int | right | ||
) |
This function allows your code to ask for a speed repeatedly in a loop, but each time your code asks for that speed, it takes a step toward the speed. This helps cushion sudden maneuvers in sensor navigation, where the conditions might change more rapidly than you would want your ActivityBot's speed to change. (Note: This is now built into drive_speed.)
left | Left wheel speed in ticks per second. |
right | Left wheel speed in ticks per second. |
void drive_servoPins | ( | int | servoPinLeft, |
int | servoPinRight | ||
) |
Set servo pins to values other than the default P12 for left servo and P13 for right servo. Stores values in EEPROM, so you only need to call this function at the start of one program. Programs that are after that will get the values from EEPROM.
IMPORTANT This function should be called first, before any adbrive control functions (drive_speed, drive_goto, etc).
servoPinLeft | I/O pin number for the left servo signal connection. |
servoPinRight | I/O pin number for the right servo signal connection. |
void drive_setAcceleration | ( | int | forGotoOrSpeed, |
int | ticksPerSecSq | ||
) |
Set the acceleration used by either drive_goto or drive_speed.
forGotoOrSpeed | can be set to FOR_SPEED (0) or FOR_GOTO (1). |
ticksPerSecSq | The ticks per second squared value to set the acceleration speed and goto calls use. The default is 600 for drive_speed and 200 for drive_goto. Use increments of 50. |
void drive_setMaxSpeed | ( | int | speed | ) |
Modifies the default maximum top speed for use with encoders. The default is 128 ticks/second = 2 revolutions per second (RPS). This is the full speed that drive_distance and drive_goto use. This value can currently be reduced, but not increased. Speeds faster than 128 ticks per second are "open loop" meaning the control system does not use the encoders to correct distance/speed.
speed | Maximum cruising speed for drive_distance and drive_goto. |
void drive_setMaxVelocity | ( | int | forGotoOrSpeed, |
int | ticksPerSec | ||
) |
Set the maximum velocity used by either drive_goto or drive_speed.
forGotoOrSpeed | can be set to FOR_SPEED (0) or FOR_GOTO (1). |
ticksPerSec | The ticks per second value that limits the top velocity, regardless of what calls to drive_speed ask for. The default is 128 for drive_speed and 64 for drive_goto. |
void drive_setRampStep | ( | int | stepsize | ) |
Overrides the default 12 ticks/second per 50th of a second for ramping.
stepsize | The size of each step in ticks/second to change every 50th of a second |
void drive_speed | ( | int | left, |
int | right | ||
) |
Set wheel speeds in encoder ticks per second. An encoder tick is 1/64th of a revolution, and makes causes the wheel to roll 3.25 mm.
left | Left wheel speed in ticks per second. |
right | Left wheel speed in ticks per second. |