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

Preston_5564C07.fm  Page 245  Monday, September 26, 2005  5:38 AM



                                                                               CHAPTER 7  ■  NAVIGATION  245



                                // converted to MotionVector
                                move(dVect);
                            }


                            // motion vector is in inches
                            public void move(MotionVector vect) throws Exception {
                                // change heading
                                Utils.log("MV=" + vect.toString());
                                changeHeading(vect.heading);
                                // move fwd or reverse
                                if (vect.magnitude > 0) {
                                    drive.forward((int) (vect.magnitude * 1000));
                                } else if (vect.magnitude < 0) {
                                    drive.reverse((int) (-vect.magnitude * 1000));
                                }
                            }

                            public void moveRaw(int dir, int ms) throws Exception {
                                if (dir == RAW_FWD) {
                                    drive.forward(ms);
                                }
                                if (dir == RAW_REV) {
                                    drive.reverse(ms);
                                }
                                if (dir == RAW_RGT) {
                                    drive.pivotRight(ms);
                                }
                                if (dir == RAW_LFT) {
                                    drive.pivotLeft(ms);
                                }
                            }


                            // surface rate when adjusting inches to seconds
                            public int getSurfaceRate(double inches) {
                                if (surface == SURFACE_CARPET) {
                                    return getMillisecondsCarpet(inches);
                                }
                                if (surface == SURFACE_CEMENT) {
                                    return getMillisecondsCement(inches);
                                }
                                return 0;
                            }

                            //  surface rate when adjusting inches to seconds
                            private int getMillisecondsCement(double inches) {
   259   260   261   262   263   264   265   266   267   268   269