Page 143 - Hacking Roomba
P. 143
124 Part I — Interfacing
Measuring Distance and Angle
The distance and angle values in the sensor data are odometry data, just like your car’s odometer.
Unlike a car odometer, the values can be either positive or negative. For distance, that’s forward
and backward; for angle, that’s counter-clockwise and clockwise.
Distance
The distance is obtained from the optical interrupter sensor on the wheels. The value comes
from counting the number of beam interruptions caused from the toothed interrupter disc. In
Roomba the disc has 32 slots (shown in Figure 5-2) and you know from Chapter 5 that the
gearing provides a 25:1 reduction between wheel and disc. Thus the sensor’s angular and dis-
tance resolution of the turning wheel is:
360 degrees / (32 teeth × 25 gearing reduction) = 0.45 degrees
(68 mm diameter × pi) / (32 teeth × 25 gearing reduction) = 0.27 mm
The ROI specification gives a distance resolution of 1 mm, and that’s probably because 1 mm
is the standard distance unit inside the Roomba and the distance value has been averaged to
give a more stable (but lower resolution) value. In any case, getting actually 1 mm of precision
from any real-world electromechanical device is tough, let alone a consumer-grade vacuuming
robot moving on variable surfaces. In practice, don’t expect anything below 100 mm resolution.
Even with that you can have a lot of fun.
Angle
Although the distance value is a straightforward measurement like a normal odometer, the
angle value is an odometrical difference. Roomba has a distance sensor on each wheel, and
the angle value in the sensor data is the difference in the distance traveled by each wheel.
Specifically, it is the right wheel difference minus the left wheel difference.
This difference describes a rotation around the center point between the two wheels. It’s as if
the wheels are moving partially along a circumference determined by the distance between the
wheels. If this sounds a lot like that millimetersPerDegree stuff from Chapter 5, you’re
right. It’s the same thing. The angle sensor value is a fraction of the entire number of milli-
meters per degree:
Angle in degrees = angle value / millimetersPerDegree, or
Angle in degrees = angle value × (360 degrees / (258 mm × pi))
Measuring Velocity
Both the distance and angle values returned in the sensor data are based on the last time the
sensors were read. Each time they are read, they are reset to zero. This makes the values relative
measurements (as opposed to absolute measurements). It also makes velocity calculations easier.
By reading the sensors at a time interval, you can determine the velocity (both translational and
angular) by simply dividing the distance and angle by the time interval.