Page 127 - Hacking Roomba
P. 127

108       Part I — Interfacing




                             One could even define functions to encapsulate behavior. The square above could be written as:
                             TO SQUARE
                             REPEAT 4[FORWARD 100 LEFT 90]
                             END

                             These RoombaComm commands to go specific distances and rotate specific angles mirror
                             Logo’s commands. You can create a Java version of the Logo square using RoombaComm like so:
                             public void square() {
                               for( int i=0; i<4; i++ ) {
                                 roombacomm.goForward(100);
                                 roombacomm.spinLeft(90);
                               }
                             }

                             Not as simple as Logo perhaps but still compact and understandable. And of course, like the
                             original turtle Irving, the Java code controls a real robot roaming around on the floor.


                     Summary

                             Making the Roomba move around is the most important and most fun part of controlling it as
                             a robot. From sending raw command bytes to high-level drive commands, you can now make
                             Roomba move along any conceivable path. The ROI protocol’s abstraction away from com-
                             manding each motor means you can easily move the Roomba in graceful circular curves, but
                             with the relevant equations you can subvert that and control each drive wheel independently.
                             You can even control the Roomba in real time with the cursor keys on a keyboard and can now
                             make any even your computer control the Roomba.
                             The idea of encapsulating paths as functions in Logo is a powerful one, and you can start build-
                             ing functions to draw all sorts of shapes with Roomba. Understanding how to implement some
                             of the existing paths performed by Roomba is the basis for creating alternative moves for it that
                             will work better in your environment.
   122   123   124   125   126   127   128   129   130   131   132