Page 159 - Hacking Roomba
P. 159

140       Part II — Fun Things to Do




                             When programming with RoombaComm, this means you should not use any of the API
                             that contains pause() commands. This is actually fine because the only time you’ll find
                             yourself working in animation mode is when you are dealing with Roomba in real-time and
                             don’t want your code to just hang out for a few seconds when it should be doing something.
                             You’ll find in Chapters 8 and 10 that when using Roomba’s sound capability, you normally
                             will use pause() to wait for the sound to play. In this case you can either use pause() but
                             set the framerate of your sketch to be slow enough that small pauses do not affect it, or you
                             can check the time periodically with the millis() Processing function to see when enough
                             time has elapsed.

                             Creating Applications with Export
                             When you have a Processing sketch you like, you may want to share it or even just make it
                             runnable outside the context of Processing. Normally turning a Java program into an executable
                             program for a particular operating system is difficult and time consuming. Generating an
                             executable for three different operating systems is even more difficult. Processing has figured
                             out all the issues with turning Java programs into applications on Windows, Mac OS X, and
                             Linux. All that is required of the user is to select File ➪ Export Application, and the current
                             sketch is converted to three applications, one for each OS. These applications are completely
                             stand-alone and do not require Processing to run.

                             When developing your sketch, it’s easy to forget to re-export the applications. When you are fin-
                             ished and attempt to run the application you just built, you will find that you are running an
                             older version if you don’t export the application you just built first. Be sure to select Export
                             Application when done with your sketch.

                             Normally Processing will also create an applet, but since RoombaComm uses native code via
                             RXTX, Java applets will not work.





                     Designing RoombaView


                             Processing makes graphical interactive programs easy to create, and RoombaComm allows easy
                             access to controlling Roomba. The two can be combined in a number of ways to create inter-
                             esting gadgets. The rest of this chapter will focus on creating RoombaView, a program to let
                             one view graphically the robot’s sensors while it goes about its business or while you control it.

                             What Features to Include
                             For RoombaView to be a usable Roomba instrument panel, it should show the main sensors
                             the robot uses to do its job:

                                 Distance and angle odometry
                                 Bump and cliff sensors state
   154   155   156   157   158   159   160   161   162   163   164