Page 55 - Hacking Roomba
P. 55
36 Part I — Interfacing
To test a single bit in a byte (like the bumps wheeldrops sensor byte), don’t use an equality test
like if(bumps==2) to test for bump left. This is because if more than one bit is set, the value is
the combination of those bits. This is similar to the setting and clearing bits issue mentioned ear-
lier. For example if both left and right bump sensors are triggered, then bumps equals 3. Instead
use a bit mask and bit shifts to get only the bit you want. The proper way to test for bump left
would be if(((bumps&0x02)>>1)==1).Such math-heavy bit manipulation is often hard to
read, so the RoombaComm API introduced below abstracts these tests out to a set of methods
like bumpLeft(). In Chapter 6 you’ll explore how to create these methods for all sensor bits.
Buttons and Internal Sensors
Figure 2-6 shows the details of the six bytes that make up the buttons and internal sensors
packet group.
Buttons and Remote Control Codes
The buttons sensor byte is a bit field with only four of the bits used. Not all Roombas have all
buttons. For those Roombas (like Roomba Red with no Max button), the corresponding miss-
ing button bits will always read as zero.
byte 10 7 6 5 4 3 2 1 0
remote range 0–255
control
byte 11 7 6 5 4 3 2 1 0
buttons n/a n/a n/a n/a Power Spot Clean Max
byte 12 7 6 5 4 3 2 1 0
distance range -32768 to 32767 mm
(high byte)
byte 13 7 6 5 4 3 2 1 0
distance range -32768 to 32767 mm
(low byte)
byte 14 7 6 5 4 3 2 1 0
angle range -32768 to 32767 mm
(high byte)
byte 15 7 6 5 4 3 2 1 0
angle range -32768 to 32767 mm
(low byte)
FIGURE 2-6: ROI sensor packet group 2, buttons and internal sensors