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

Preston_5564C03.fm  Page 59  Wednesday, October 5, 2005  7:21 AM



                                                                                  CHAPTER 3  ■  MOTION    59



                                    // move from position 0 to 255, 5 per 100 ms
                                    for (int pos = 0; pos < 255; pos = pos + 5) {
                                        // move
                                        ssc.move(0, pos);
                                        // wait 100 milliseconds
                                        Utils.pause(100);
                                    }
                                    // close serial port
                                    sPort.close();
                                } catch (Exception e) {
                                    // print stack trace and exit
                                    e.printStackTrace();
                                    System.exit(1);
                                }
                            }


                        }

                        Section Summary
                        In this section, we showed a difficult way and an easy way to model a servo controller. We also
                        added an interface to ensure communication for different controllers and added an implementa-
                        tion for the MiniSSC-II. The classes discussed were the following:

                           • SerialSsc.java: A serial version of servo control (an example of a hard way)
                           • SSCProtocol.java: An interface designed to standardize communication to a servo
                             controller

                           • SSC.java: Super-class used by the MiniSSC and other classes for servo communication
                           • MiniSSC.java: Implementation class for the Scott Edwards MiniSSC-II

                            Now that you know how to control servos with your PC, you’re ready to get a robot to move.
                        In the next section, I’ll talk about differential drive robots (with two wheels) and there I’ll use
                        the MiniSSC and your PC’s serial port to make it move.

                        3.2 Wheeled Motion


                        Using a servo controller connected to an electronic speed controller or a pair of “hacked” or
                        continuous rotation servos is an excellent way to facilitate wheeled motion. Figure 3-5 shows a
                        picture of the differential drive of a CubeBot connected to a MiniSSC-II. Notice that the servo
                        wires are to the rear of the platform. This means the motors are inverted, so I’ll have to account
                        for this in the classes in this section.










                   97022d2480fe4a63cfdfa123a6e70098
   73   74   75   76   77   78   79   80   81   82   83