I have created a program in Java SE, which send coordinates and angles to the NXT by bluetooth (screen)
Everything works right if I don't use the navigator class.
- Code: Select all
for (int i = 0; i < distances.length; i ++ ) {
robot.travel(distances[i]); // cm
robot.rotate(degress[i]); // degrees
}
field distances contains four distances which robot has to travel in centimeters. (result of point1.distance(point2));
field degrees contains four angles which robot has to rotate after he travelled the distance from previous step.
Distances and angles are counted on the client (PC part) of the program and send to the NXT, so NXT just travel pre-counted "path".
for example, field "distances" based on the screenshot will contain: (distances[0] = (int) (point1.distance(point2) * 2) / 10;)
200, 100, 200, 100
field degrees will contain:
90,90,90,90
Everything what i described until here works fine, but I have to use Navigation (Navigator class) in my project instead of counting distances and angles myself, but I'm not sure how does Navigator class (http://lejos.sourceforge.net/nxt/nxj/api/index.html) works. Can someone please put here how to set waypoints to travel rectangle 1m x 2m?
I know how to use waypoints ( navigator.addWaypoint(new Waypoint(100, 0)); ), but don't know how to set coordinates to travel rectangle of 2x1m (at the end robot should be on the spot where its travel begins).
I have tried this:
- Code: Select all
DifferentialPilot pilot = new DifferentialPilot(12.8, 8.2, Motor.B, Motor.C, true);
Navigator navigator = new Navigator(pilot);
navigator.addWaypoint(new Waypoint(200, 0));
navigator.addWaypoint(new Waypoint(200, 100));
navigator.addWaypoint(new Waypoint(0, 100));
navigator.addWaypoint(new Waypoint(0,0));
navigator.followPath();
Button.ENTER.waitForPressAndRelease();

And the result you can see here: (the rectangle from ducktape on carpet is 2x1m and the robot should stay on black lines)
http://www.youtube.com/watch?v=GUM-zsys ... uYDpd_VV4=
And how to set initial position from 0,0 to for example 5,5? There were a method for this (i think) in the class TachoNavigatorsetPosition(float x, float y, float directionAngle) but the whole class seems to be gone.
Thanks for answer.
