abdrive library  v0.9.84
Differential servo and encoder drive library for the Parallax ActivityBot
Macros | Functions
abdrive.h File Reference

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)

Detailed Description

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

Author
Andy Lindsay
Core Usage
A single additional core takes care of ActivityBot encoder monitoring, control system algorithm execution and servo control.
EEPROM Usage
Reads from addresses 63418..65470.
Memory Models
Use with CMM.
Version
0.9.82
  • Move most control logic into the control system cog.
  • Arc support with drive_goto(left, right), where left != right.
  • Background target calculation for better acceleration/deceleration.
  • drive_acceleration(forGotoOrSpeed, ticksPerSecondSquared).
  • drive_ramp can be interrupted with a new direction.
  • drive_goto can be interrupted after calling drive_gotoMode(0).
  • drive_gotoStatus added for monitoring when a maneuver is finished.
  • All acceleration (a.k.a. ramping) is done in the background.
  • Sampling rate increased from 400 to 800 Hz.
  • Default speed for drive_goto set to 64 ticks per second with a default acceleration of 200 ticks per second.
  • Default speed limit for drive_speed is 128 ticks per second, with a default acceleration of 600 ticks/second squared.
  • Trim support was removed.
0.5.6
  • Adjust drive_servoPins and drive_encoderPins documentation.
0.5.4
  • drive_getTicksCalc
  • drive_getTicks
  • drive_open
  • drive_encoderPins
  • drive_servoPins
  • Values outside interpolation table ranges do not result in rotation halt.
  • Turning off feedback now allows full servo speed operation
0.5.1
  • Trim enabled by default.
  • Clear trim settings during calibration. (v0.5.1)
  • Make trim for a direction mutually exclusive to one side. (v0.5.1)
Help Improve this Library
Please submit bug reports, suggestions, and improvements to this code to edito.nosp@m.r@pa.nosp@m.ralla.nosp@m.x.co.nosp@m.m.

Function Documentation

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).

Parameters
encPinLeftI/O pin number for the left encoder signal connection.
encPinRightI/O pin number for the right encoder signal connection.
void drive_feedback ( int  enabled)

Enables or disables encoder feedback for speed control.

Parameters
enabledSet 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.

Parameters
*leftPointer to variable to receive the measured left distance.
*rightPointer 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.

Parameters
*leftPointer to variable to receive the calculated left distance.
*rightPointer 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.

Parameters
distLeftLeft 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.
distRightRight 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.

Parameters
modeinterruptible (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.

Parameters
sidewith options of SIDE_LEFT, SIDE_RIGHT, or SIDE_BOTH.
Returns
value that corresponds to the 0, 1, 2 status of a maneuver
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.

Parameters
leftLeft wheel speed in ticks per second.
rightLeft 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.)

Parameters
leftLeft wheel speed in ticks per second.
rightLeft 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).

Parameters
servoPinLeftI/O pin number for the left servo signal connection.
servoPinRightI/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.

Parameters
forGotoOrSpeedcan be set to FOR_SPEED (0) or FOR_GOTO (1).
ticksPerSecSqThe 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.

Parameters
speedMaximum 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.

Parameters
forGotoOrSpeedcan be set to FOR_SPEED (0) or FOR_GOTO (1).
ticksPerSecThe 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.

Parameters
stepsizeThe 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.

Parameters
leftLeft wheel speed in ticks per second.
rightLeft wheel speed in ticks per second.