Page 116 - Hacking Roomba
P. 116

Chapter 5 — Driving Roomba               97




                                      A Word about Writing Java Programs Continued

                              3. Run the code. For simple Java programs, typing java Drive would work. But again,
                                 because of the additional library, the command becomes:
                                   % java -Djava.library.path=rxtxlib
                                           -classpath .:rxtxlib/RXTXcomm.jar roombacomm.Drive

                          Everyone has his or her own preferred style for writing software. For this project, I made
                          simple scripts that wrap up the preceding commands to save typing and reduce typos.
                          There is makeit.sh, which encapsulates Step 2, and runit.sh, which encapsulates Step 3.
                          My workflow then looks something like:
                              % unzip roombacomm-latest.zip  // downloaded from
                              roombahacking.com
                              % cd roombacomm                // get into the directory
                              % emacs roombacomm/Drive.java  // edit the file
                              % ./makeit.sh                  // build it
                              % ./runit.sh roombacomm.Drive  // run it

                          The scripts will work on any Unix-like system (Mac OS X, Linux, Windows with Cygwin).
                          For vanilla Windows, you can use makeit.bat and runit.bat, which work the same way.





                             Command-Line Roomba Driving

                             The example program roombacomm.Drive enables you to play with the DRIVE command by
                             itself. Like all the example programs, run it with no arguments to get usage:
                             % ./runit.sh roombacomm.Drive
                             Usage:
                               roombacomm.Drive <serialportname> <velocity> <radius> <waittime>

                             You should know the serial port name from the previous chapters. The velocity and radius
                             values are direct arguments to DRIVE, as signed integers, and waittime is the number of mil-
                             liseconds to run before stopping. To go straight forward at 250 mm/s for two seconds, run the
                             program:
                             % ./runit.sh roombacomm.Drive /dev/cu.KeySerial1 250 32768 3000
                             There are many other simple example programs that are all run in the same manner (but with
                             different arguments after the serial port name).
                             The following sections show the evolution of the RoombaComm API and how the Drive pro-
                             gram is created.
   111   112   113   114   115   116   117   118   119   120   121