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

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



                                                                               CHAPTER 7  ■  NAVIGATION  223



                        Example 7-1. Vertex.java
                        package com.scottpreston.javarobot.chapter7;

                        public class Vertex {

                            public String name;

                            public Vertex() {}

                            public Vertex(String n) {
                                name = n;
                            }
                        }


                        Example 7-2. Edge.java
                        package com.scottpreston.javarobot.chapter7;

                        public class Edge {

                            public String name;
                            public Vertex v1;
                            public Vertex v2;
                            public int w;


                            public Edge() {}
                            // constructs with two vertices and a weight
                            public Edge(Vertex v1, Vertex v2, int w) {
                                this.v1 = v1;
                                this.v2 = v2;
                                this.w = w;
                            }
                            public String toString() {
                                return "{v1=" + v1.name +",v2=" + v2.name + ",w=" + w +"}";
                            }


                        }
                            In this chapter, I will create 19 classes and one basic Stamp program. There will be five
                        navigational classes:
                           • Navigation: Performs basic navigation (best in ideal regions)
                           • Localization: Provides a start point for a robot and gives it the ability to navigate to other
                             coordinates
                           • ObstacleNavigation: Provides for obstacle avoidance during navigation
   237   238   239   240   241   242   243   244   245   246   247