Help with waypoint following

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Help with waypoint following

Postby fishergreen » Wed Jul 27, 2011 2:23 pm

I'm new to coding and I am trying to get my robot to follow a path. I can't seem to get it to follow the collection of waypoints properly and I think I am missing something very obvious
Here is my main method class:


import java.util.Collection;

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.navigation.Pose;
import lejos.robotics.navigation.WayPoint;

public class PathFollower {

public static void main(String[] args) {
PathUtils.generatePath1();
DifferentialPilot pilot = new DifferentialPilot(2.17f, 4.75f, Motor.C,
Motor.B);
pilot.setRotateSpeed(10); // in inches
pilot.setTravelSpeed(9);
Collection<WayPoint> path = PathUtils.generatePath1();
WayPoint[] a = new WayPoint[path.size()];
a = path.toArray(a);
Pose curpose = a[0].getPose();
curpose.setHeading(0);
for (int i = 1; i < a.length; i++) {
curpose.setHeading(0);
WayPoint p = a[i];
LCD.drawString(p.getX()+ " "+p.getY(),0,0);
Button.waitForPress();
pilot.rotate(-curpose.relativeBearing(p));
pilot.travel(curpose.distanceTo(p));


}

}



}


and here is the array listprovided by my teacher that I cannot modify, thanks for the help:



import java.util.ArrayList;
import java.util.Collection;

import lejos.geom.Line;
import lejos.geom.Point;
import lejos.geom.Rectangle;
import lejos.robotics.mapping.LineMap;
import lejos.robotics.navigation.WayPoint;


public class PathUtils {

public static Collection<WayPoint> generatePath1(){
ArrayList<WayPoint> points = new ArrayList<WayPoint>();
points.add(new WayPoint(0,0));
points.add(new WayPoint(15,0));
points.add(new WayPoint(15,15));
points.add(new WayPoint(30,15));
return points;
}

public static Collection<WayPoint> generatePath2(){
ArrayList<WayPoint> points = new ArrayList<WayPoint>();
points.add(new WayPoint(0,0));
points.add(new WayPoint(15,15));
points.add(new WayPoint(30,15));
return points;
}

public static Collection<WayPoint> generatePath3(){
ArrayList<WayPoint> points = new ArrayList<WayPoint>();
points.add(new WayPoint(0,0));
points.add(new WayPoint(0,30));
points.add(new WayPoint(15,15));
points.add(new WayPoint(30,30));
points.add(new WayPoint(30,0));
return points;
}
}
fishergreen
New User
 
Posts: 1
Joined: Wed Jul 27, 2011 2:19 pm

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff