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

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



                 66     CHAPTER 3  ■  MOTION




                        ■Note   I have found that using millisecond resolution is just as accurate as wheel encoders over short
                        distances (<3 meters or <10 seconds). This is because the wheel slippage and time to stop accuracies are
                        at their low end with these distances and speeds. But even these shortcomings are overcome by distance
                        measurement sensors so as to eliminate the “practical” need for wheel encoders.



                        Example 3-7. TimedDiffDrive.java

                        package com.scottpreston.javarobot.chapter3;
                        import com.scottpreston.javarobot.chapter2.JSerialPort;
                        import com.scottpreston.javarobot.chapter2.SingleSerialPort;
                        import com.scottpreston.javarobot.chapter2.Utils;
                        public class TimedDiffDrive extends BasicDiffDrive {


                            // construct with JSerialPort
                            public TimedDiffDrive(JSerialPort serialPort) throws Exception {
                                super(serialPort);
                            }

                            // forward
                            public void forward(long ms) throws Exception {
                                // calls super
                                forward();
                                // pause
                                Utils.pause(ms);
                                // stop
                                stop();
                            }

                            // reverse
                            public void reverse(long ms) throws Exception {
                                reverse();
                                Utils.pause(ms);
                                stop();
                            }
                            // pivot left
                            public void pivotLeft(long ms) throws Exception {
                                pivotLeft();
                                Utils.pause(ms);
                                stop();
                            }






                   97022d2480fe4a63cfdfa123a6e70098
   80   81   82   83   84   85   86   87   88   89   90