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

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



                 12     CHAPTER 1  ■  A PRIMER


                        Organizing Your Components

                        The first thing I did was model the physical connections between my PC and my robot. I found
                        that having three layers simplified the grouping. You can choose another arrangement for your
                        robot, but this is what worked for me. An outline of the layering is shown in Table 1-4.


                 Table 1-4. Layers in Robotics Programming
                 PC Layer                     Control Layer                 Device Layer
                 This is the layer you are most   This layer represents the third-party   This is the layer that represents
                 familiar with. It will contain your   controllers. These controllers allow   the hardware devices you’ve
                 interfaces to your peripherals like   you to communicate in both the   connected.
                 your serial port, parallel port,   language of a robot and the language
                 webcam, sound output or input   of a computer.
                 devices, etc.
                 Serial Port                  Parallax Stamp                Robot Arm
                 Webcam                       MiniSSC-II Servo Controller   Sonar
                 Sound Card                   Microcontroller               Compass
                 Database                                                   Differential Drive
                 Logic                                                      Robot Leg



                        Modeling Your Hardware and Behavior

                        Once you organize the components you have to work with, it’s time to create some “soft”
                        models of those hardware components.

                            • Pick a name (for example, PanTiltCamera).
                            • Model what you want it to do (move up/down, move left/right, take a picture, and so on).
                            • Stub out your class.

                            • Plan what can go wrong and how you want to deal with it.
                            After you’ve modeled your hardware and behavior, you should be ready to calculate the
                        synchronization between the two.

                        Timing
                        Timing in life is important; timing in robotics is mandatory. If you have a larger microcontroller,
                        I would suggest using flow control (for example, having your PC and microcontroller negotiate
                        when each are ready to talk). But since I only have 16 I/O ports with my BASIC Stamp 2, I’ll
                        manually synchronize the serial communication. You should be aware of how long things take
                        though.
                            For example, a 9600-baud communication rate with your microcontroller takes about 3 feet
                        per character. If you have three characters to transmit, like the bearing of your compass, it
                        could take less time to execute the command than it would to get the data back from your serial
                        connection.
   26   27   28   29   30   31   32   33   34   35   36