Page 49 - Hacking Roomba
P. 49
30 Part I — Interfacing
■ Straight: 32768 (0x8000)
■ Spin counter-clockwise: 1 (0x0001)
■ Spin clockwise: -1 (0xFFFF)
The turn radius is the radius in millimeters of an imaginary circle upon whose edge Roomba
would drive along. So, larger radii make Roomba drive straighter, and shorter radii make
Roomba turn more quickly. When going forward, a positive radius turns Roomba to the right,
and a negative radius turns Roomba to the left.
In addition to the radius values, there are three special values for direction. The direction value
of 32768 is the special value to make the Roomba drive straight. And instead of using -1 and
+1 to represent a radius of -1mm and +1mm, they’re used to mean spin clockwise or counter-
clockwise.
Taken together, the velocity and direction describe what direction a Roomba should go and
how fast. The hexadecimal representation above makes it easy to turn these values into a byte
sequence to send to the Roomba. For instance, to drive straight at 500 mm/s, the complete
DRIVE command would be: 0x89,0x01,0xF4,0x80,0x00. Or, to spin clockwise at -500
mm/s, the complete command would be: 0x89,0xFE,0x0C,0xFF,0xFF.
It’s interesting that iRobot chose to expose the drive functionality as a combination of velocity
and direction instead of the presumably simpler velocity of each wheel. Apparently it was pre-
sented this way, because this is how the robot’s algorithms use the drive wheels. The typical
spiral the Roomba does is certainly easier with the above abstraction: Set the drive speed once
and then slowly increment the radius value over time.
In Chapter 5 you’ll learn more about DRIVE command and create code to abstract out these
special values.
Cleaning Motors
The MOTORS command controls Roomba’s three cleaning motors. Unlike the drive motors, only
on/off control is available for them. Each motor’s state is represented by a bit in the single data
byte (hexadecimal bit values in parentheses):
Main brush: bit 2 (0x04)
Vacuum: bit 1 (0x02)
Side brush: bit 0 (0x01)
To turn on a motor, set the bit. To turn off the motor, clear the bit, as explained in the side-
bar “Setting and Clearing Bits.” All other bits of the data byte are not used and should be set
to zero.
For example, to turn all cleaning motors off, the full ROI command is: 0x8A,0x00. To turn
them all on, the full command is: 0x8A,0x07.