User Manual

Reference
C++ and Arduino methods are shown in red.
C functions are shown in green.
static void PololuWheelEncoders::init(unsigned char m1a, unsigned char m1b, unsigned char m2a,
unsigned char m2b)
void encoders_init(unsigned char m1a, unsigned char m1b, unsigned char m2a, unsigned char m2b)
Initializes the wheel encoders. The four arguments are the four pins that the wheel encoders are connected to.
Each pin is specified using the IO_* keywords provided by the library (e.g. IO_D1 for an encoder input on pin
PD1). The arguments are named m1a, m1b, etc. with the intention that when motor M1 is spinning forward,
pin m1a will change before pin m1b. However, it is difficult to get them all correct on the first try, and you
might have to experiment.
static int getCountsM1()
static int getCountsM2()
int encoders_get_counts_m1()
int encoders_get_counts_m2()
Returns the number of counts measured on M1 or M2. For the Pololu wheel encoders, the resolution is about
3mm/count, so this allows a maximum distance of 32767 × 3mm or about 100m. For longer distances, you
will need to occasionally reset the counts using the functions below.
static int getCountsAndResetM1()
static int getCountsAndResetM2()
int encoders_get_counts_and_reset_m1()
int encoders_get_counts_and_reset_m2()
Returns the number of counts measured on M1 or M2, and resets the stored value to zero.
static unsigned char checkErrorM1()
static unsigned char checkErrorM2()
unsigned char encoders_check_error_m1()
unsigned char encoders_check_error_m2()
These functions check whether there has been an error on M1 or M2; that is, if both m1a/m2b or m2a/m2b
changed simultaneously. They return 1 if there was an error, then reset the error flag automatically.
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
18. Wheel Encoders Page 62 of 65