Page 53 - Hacking Roomba
P. 53
34 Part I — Interfacing
To choose which group of sensor data to receive, set the packet code data byte to one of the
following:
0: All data (26 bytes)
1: Physical sensors (10 bytes)
2: Buttons and internal sensors (6 bytes)
3: Power sensors (10 bytes)
For example, to have Roomba send just the power sensors data packet, the full ROI command
is: 0x8E,0x03.
In most of the code presented in this book, the full 26-byte sensor packet (group 0) will be
fetched.
However, there are also situations where you might want to receive only a portion of the data
if the application has critical timing or if receiving the entire 26 bytes takes too long due to a
reduced serial port baud rate. For instance, if the ROI is set to 1,200 bps because of a slow
microcontroller, then transmitting 26 bytes would take at best (2+26 bytes × 10 bit-times/byte)
/ 1,200 bit-times/second = 0.233 seconds. A quarter-second is a long time if Roomba is head-
ing toward the stairs. By only getting the physical sensors, the time to know about the stairs is
reduced to about 0.10 seconds, perhaps time enough to not drive off the cliff. This constructed
example shows one of the problems of systems with high communication time costs. In such a
low-speed system, the likely solution would be to move the robot at a slower speed to compen-
sate for the slower sensor update rate. Controlling Roomba with the Basic Stamp, as you’ll see
in Chapter 13, is an example of a low-speed system that gets smaller data packets.
Physical Sensors
Figure 2-5 shows the arrangement of the 10 bytes that make up the physical sensors packet
group.
There are two bytes (16 bits) of digital sensor data, and two bytes of analog data. That is a total
of four bytes of data, optimally packed. Then why is this packet 10 bytes?
Although the wheel drop and bump sensors are implemented as bits in a single bit field, all the
wall and cliff sensors are given a byte each, even though they are all just binary on/off sensors.
This seems strange and rather wasteful, especially considering the aforementioned rationale of
dividing up the sensor data into groups.
One possible reason for this distinction might be that the Roomba firmware wants to do the
minimum calculation necessary to determine if it detects a cliff or a wall, and perhaps testing
an entire byte being non-zero is easier or faster than testing a bit within a byte. This is one of
those examples where the ROI could have offered a little more abstraction of the data but
didn’t.