Page 115 - Hacking Roomba
P. 115
96 Part I — Interfacing
You will notice some differences in actual Roomba movements compared to the commands
issued. Mostly this is due to variable friction with the environment. If you want more accurate
movements, remove the bin and brushes and operate the Roomba on a low profile but high-
traction surface like office carpeting. Roomba is designed to vacuum home carpets, but the vari-
ability of home carpets can mess up trying to accurately move the robot.
Table 5-1 summarizes some common DRIVE commands. The byte sequence column is the
exact set of hex bytes that make up a particular command.
Table 5-1 Some Common and Special-Case DRIVE Commands
Description Velocity Radius Byte sequence
Straight forward, medium speed 250 32768 0x89,0x00,0xfa,0x80,0x00
Straight backward, slowly -50 32768 0x89,0xff,0xce,0x80,0x00
Spin left in place 500 1 0x89,0x01,0xf4,0x00,0x01
Spin right in place 500 -1 0x89,0x01,0xf4,0xff,0xff
Turn left forward (left wheel stopped) 200 129 0x89,0x00,0xc8,0x00,0x81
Turn right forward 200 -129 0x89,0x00,0xc8,0xff,0x7f
(right wheel stopped)
A Word about Writing Java Programs
Writing, compiling, and running Java programs is pretty easy, but it can be a little daunting
if you’ve never done it before. Java is a good language for learning the basics of object-
oriented programming. If you’re totally unfamiliar with Java, visit the main Java website
and check out some of the tutorials at http://java.sun.com/learning/tutorial/.
There are many ways of going about working with Java, from simple command-line com-
mands to large integrated development environments (IDEs) to professional Unix-build
script systems. This book assumes that you’ll be building and running code from the com-
mand line (Terminal.app in Mac OS X, CMD.EXE in Windows, and xterm in Linux). When
you have Java installed and have downloaded and unzipped the RoombaComm code, the
steps are:
1. Write code. Create or edit the source code files. Go into the roombacomm directory
and edit roombacomm/Drive.java. Make any changes you want or just poke around.
2. Compile code. For simple Java programs, just typing javac Drive.java would
work. RoombaComm uses an additional Java library called RXTX to allow serial port
access, so the compile line becomes a little more complicated:
% javac -classpath .:rxtxlib/RXTXcomm.jar
roombacomm/*.java