Page 32 - The Definitive Guide to Building Java Robots
P. 32

Preston_5564C01.fm  Page 13  Friday, September 16, 2005  6:36 AM



                                                                                 CHAPTER 1  ■  A PRIMER   13



                            But timing is not just important for synchronization. It also defines the resolution at which
                        your robot can get data from its environment. For example, if you have a sensor that reads
                        sonar every 200 milliseconds, then you have a maximum number of readings per second of 5.
                        If your robot travels 1 meter per second (a slow walking pace), then the resolution of your robot
                        will be 7 inches.

                        Summary

                        By now, you should be ready to start using Java with your robotics. Your PC should have its
                        software installed and you should have a working serial connection and microcontroller. While
                        you don’t need a robot for the next chapter, make sure to order one soon so that when you’re
                        ready for Chapter 3, you can hook up your robot and get it moving with some of your own Java
                        programs.
                            Hopefully, your programs will do more than just avoid the sofa or move in circles. So take
                        some time to figure out what you want your robot to do. Then, to make it easier follow these
                        steps: First, organize what you want your robot to do. Second, choose events that trigger action.
                        Third, create tasks that organize behavior. Fourth, create subtasks that perform the details.
                        Finally, model data packets that represent the information moving from your hardware and PC.
                            It might also help to arrange your programs in such a way that when you move from subtask to
                        subtask or task to task you create a state transition diagram like Figure 1-2 shown earlier. I would
                        not worry too much about the Java concepts right now, but come back to them if you get stuck
                        at some point later in the book. What you don’t find listed here can be uncovered in numerous
                        Apress books which do an excellent job explaining these concepts.
                            Finally, once your behavioral model is defined, you should start modeling your hardware.
                        So starting from your PC and moving to your peripherals, if needed create simple models of
                        your hardware that map easily to the behavior you want your robot to perform.
                            For example, if I want my robot to move, I would map a serial port to a servo controller and
                        that would be it. But if I want it to face a specific direction, I would have a serial port mapped
                        to a servo controller as well as a microcontroller, which would be mapped to a compass.
                            Just one tip before proceeding: start simple, and then increase the complexity of your
                        model only after you have tested a simple version of it. You will run into many problems along
                        the way and nothing is worse than troubleshooting your own complicated do-everything code.
   27   28   29   30   31   32   33   34   35   36   37