Optical Odometry
In addition to using GPS to compute the distance to the next waypoint, it's useful to measure the distance the car travels in a particular unit of time and, in combination with the compass, use this to predict the cars position. This provides an independent check on the GPS reading, as we've seen, can vary depending on the quality of the signal lock the GPS module currently has. One way to measure the distance the car travels is to use a rotary encoder than measures wheel revolutions. This is what a full size car uses to compute both speed and distance travelled, and it's a technique that several other AVC competitors have used in past races. But, it has several that it can only measure distance accurately as long as the wheel to which the encoder is connected stays firmly in contact with the ground. If the wheel slips, the encoder will count more revolutions that the car has actually travelled.
A few years back I read an article on hacking an optical mouse sensor and learned how these devices work. In effect, they contain a very high speed camera that watches the surface of your desk and then uses sophisticated optical pattern matching algorithms to detect when the image it sees moves up, down, right or left. I was able to repeat the experiment using a salvaged HP optical mouse model M-SBF96 (actually made by Logitech) and discovered that the movement readings it produced were actually fairly repeatable and accurate. I remembered this experiment while thinking about how to add odometry to our car and wondered if I could fit the mouse sensor with a camera lens of some sort so that the sensor could look down from the car from a few inches above the ground and measure motion as the car moved.
I was busily trying to remember something about lenses and focal lengths from my HS physics class when a colleague pointed me toward a ready made product called an "Optical Flow Sensor" produced by DIYDrones that was exactly what I needed. Despite the fancy "optical flow" name, this product uses a somewhat updated version of the very same kind of optical mouse sensor I'd salvaged out of the HP mouse, the ADNS3080 made by Avago. But, it was already fitted with a standard M12 x 0.5 lens mount fitted with an 8mm lens (the kind used by web cams) that can be adjusted to different focal lengths. Better yet, it turned out that the DIYDrones operation was just a few blocks away from where I work. So, on my next lunch hour, I dropped by and picked one up. Here's what it looks like up close:
As you can see, the whole assembly is quite small (it almost fits in a 1x1x1 inch cube.) This interface is equally simple, as it's SPI-based and compatible with the Arduino's 5 volt logic levels (hooray, no need for level conversion!) And, to make it even better, the DIYDrones web page contains links to an Arduino library that handles all the complexities of the SPI protocol needed to get readings from the ADNS3080.
How Will it Work in a Car?
Even though my experience with the mouse sensor seemed to suggest an optical approach to odometry might work well, I decided to run some tests to find out more before committing to the idea. To do this I needed a test bench. Some sort of apparatus that would let me run the device over the kind of surface the car would run in the AVC event while, at the same time, measuring the distance travelled so I could compare to, and calibrate the distance indicated by the ADNS3080. What I settled on was a measuring wheel I purchased for $9 at my local Harbor Freight outlet. After gluing on a wooden wedge/adapter plate, I was able to attach an Arduino with breadboard shield, LCD readout, battery pack and the optical sensor in a compact package that looks like this:
The measuring wheel has a small mechanical counter (hidden by the battery pack in the photo) that counts out a measurement down to a resolution of 1/10 of a foot. The optical sensor (lower left) looks down at the ground from a height of about 2 inches and the LCD display just above it reads out in the distance, as measured by the sensor, in "ticks". With this setup, I made several test runs of 100 feet over blacktop and concrete surfaces in either full sunlight, or shaded sunlight and then calculated the ticks/foot at about 770, or so. And, in comparing one run to another, I found that the sensors seemed seemed to be within +/- 3% of each other except for one run that passed from sunlight into shadow. This mixed lighting run came in at about 6% of the other readings.