lejos.robotics.navigation
Class SimpleNavigator

java.lang.Object
  extended by lejos.robotics.navigation.SimpleNavigator
Direct Known Subclasses:
TachoLocalizer

public class SimpleNavigator
extends Object

The SimpleNavigator class uses dead reckoning to keep track of its robot pose (the location in the plane and its heading - the direction in which it moves). While dead reckoning is relatively easy to implement and very quick to caolculate, its disadvantage is that errors in the estimated pose accumulate.
SimpleNavigator can perform three elementary movements in a plane: trvel in a straignt line, move in the arc of a circle, and a rotate in place. The movement commands have an immediate return option which is useful, for example, for a client class that uses s SimpleNavigataor to detect obstacles or monitor incoming messages while moving.
This class uses a private Pilot object to execute these moves. The Pilot directly controls the hardware, which must be able to turn in place, for example using 2 wheel differential steering. The Pilot is passed to the Navitator a the parameter of its constructor. After the Navigator is constructed, the client has no further need for the Pilot, but issues commands to the Navigator. If the client bypasses the navigator and issues commsnds directly to the Pilot, this will destroy the accuracy of the Navigataor's pose.
A note about coordinates: All angles are in degrees, distances in the units used to specify robot dimensions. Angles related to positions in the plane are relative to the X axis ; direction of the Y axis is 90 degrees. The x and y coordinate values and the direction angle are all initialized to 0, so if the first move is forward() the robot will run along the x axis.


Constructor Summary
SimpleNavigator(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor)
          Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about!
SimpleNavigator(float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor, boolean reverse)
          Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about!
SimpleNavigator(Pilot pilot)
          Allocates a SimpleNavigator with a Pilot that you supply.
 
Method Summary
 float angleTo(float x, float y)
          Returns the angle from robot current location to the point with coordinates x,y
 void arc(float radius)
          Starts the NXT robot moving in a circular path with a specified radius;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.
 void arc(float radius, int angle)
          Moves the NXT robot in a circular arc through the specified angle;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.
 void arc(float radius, int angle, boolean immediateReturn)
          Moves the NXT robot in a circular arc through a specific angle;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.
 void backward()
           
 float distanceTo(float x, float y)
          Returns the distance from robot current location to the point with coordinates x,y
 void forward()
           
 float getAngle()
          gets the current robot pose
 float getHeading()
          gets the current value of the robot heading
 Pose getPose()
           
 float getX()
          gets the current value of the X coordinate
 float getY()
          gets the current value of the Y coordinate
 void goTo(float x, float y)
          Robot moves to grid coordinates x,y.
 void goTo(float x, float y, boolean immediateReturn)
          Robot moves to grid coordinates x,y.
 boolean isMoving()
          returns true if the robot is moving
 void rotate(float angle)
          Rotates the NXT robot through a specific number of degrees in a direction (+ or -).
 void rotate(float angle, boolean immediateReturn)
          Rotates the NXT robot through a specific number of degrees in a direction (+ or -).
 void rotateLeft()
           
 void rotateRight()
           
 void rotateTo(float angle)
          Rotates the NXT robot to point in a specific direction, using the smallest rotation necessary
 void rotateTo(float angle, boolean immediateReturn)
          Rotates the NXT robot to point in a specific direction relative to the x axis.
 void setMoveSpeed(float speed)
          sets the robots movement speed - distance units/second
 void setPose(float x, float y, float heading)
          sets the robot pose to the new coordinates and heading
 void setPose(Pose pose)
          sets the robot pose
 void setPosition(float x, float y, float heading)
           
 void setTurnSpeed(float speed)
          sets the robot turn speed -degrees/second
 void steer(int turnRate)
          Starts the robot moving along a curved path.
 void steer(int turnRate, int angle)
          Moves the robot along a curved path through a specified turn angle.
 void steer(int turnRate, int angle, boolean immediateReturn)
          Moves the robot along a curved path for a specified angle of rotation.
 void stop()
          Stops the robot.
 void travel(float distance)
          Moves the NXT robot a specific distance.
 void travel(float distance, boolean immediateReturn)
          Moves the NXT robot a specific distance.
 void travelArc(float radius, float distance)
          Moves the NXT robot in a circular arc through a specific distance;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.
 void travelArc(float radius, float distance, boolean immediateReturn)
          Moves the NXT robot in a circular arc through a specific distance;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.
 void updatePose()
           
 void updatePosition()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleNavigator

public SimpleNavigator(Pilot pilot)
Allocates a SimpleNavigator with a Pilot that you supply.

Parameters:
pilot - can be any class that implements the pilot interface

SimpleNavigator

public SimpleNavigator(float wheelDiameter,
                       float trackWidth,
                       TachoMotor leftMotor,
                       TachoMotor rightMotor,
                       boolean reverse)
Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about!

Allocates a SimpleNavigator object and initializes it with a new TachoPilot
If you want to use a different Pilot class, use the single parameter constructor.

Parameters:
wheelDiameter - The diameter of the wheel, usually printed on the Lego tire. Use any units you wish (e.g. 56 mm = 5.6 cm = 2.36 in)
trackWidth - The distance from the center of the left tire to the center of the right tire, same units as wheel diameter
rightMotor - The motor used to drive the right wheel e.g. Motor.C.
leftMotor - The motor used to drive the left wheel e.g. Motor.A.
reverse - If motor.forward() dives the robot backwars, set this parameter true.

SimpleNavigator

public SimpleNavigator(float wheelDiameter,
                       float trackWidth,
                       TachoMotor leftMotor,
                       TachoMotor rightMotor)
Deprecated. The correct way is to create the Pilot in advance and to use that in construction of the SimpleNavigator. Otherwise the SimpleNavigator needs to know detail it should not care about!

Allocates a SimpleNavigator object and initializes it with a new TachoPilot.
If you want to use a different Pilot class, use the single parameter constructor.

Parameters:
wheelDiameter - The diameter of the wheel, usually printed on the Lego tire. Use any units you wish (e.g. 56 mm = 5.6 cm = 2.36 in)
trackWidth - The distance from the center of the left tire to the center of the right tire, sane units as wheel diameter
rightMotor - The motor used to drive the right wheel e.g. Motor.C.
leftMotor - The motor used to drive the left wheel e.g. Motor.A
Method Detail

getX

public float getX()
gets the current value of the X coordinate

Returns:
current x

getY

public float getY()
gets the current value of the Y coordinate

Returns:
current Y

getHeading

public float getHeading()
gets the current value of the robot heading

Returns:
current heading

getAngle

public float getAngle()
gets the current robot pose

Returns:
current pose

forward

public void forward()

backward

public void backward()

rotateLeft

public void rotateLeft()

rotateRight

public void rotateRight()

getPose

public Pose getPose()

updatePosition

public void updatePosition()

setPose

public void setPose(float x,
                    float y,
                    float heading)
sets the robot pose to the new coordinates and heading

Parameters:
x - coordinate
y - coordinate
heading - direction of robot forward movement

setPose

public void setPose(Pose pose)
sets the robot pose

Parameters:
pose - new pose

setPosition

public void setPosition(float x,
                        float y,
                        float heading)

setMoveSpeed

public void setMoveSpeed(float speed)
sets the robots movement speed - distance units/second

Parameters:
speed -

setTurnSpeed

public void setTurnSpeed(float speed)
sets the robot turn speed -degrees/second

Parameters:
speed -

stop

public void stop()
Stops the robot. Depending on the robot speed, it travels a bit before actually coming to a complete halt.


isMoving

public boolean isMoving()
returns true if the robot is moving

Returns:
true if it is moving

travel

public void travel(float distance)
Moves the NXT robot a specific distance. A positive value moves it forwards and a negative value moves it backwards.

Parameters:
distance - The positive or negative distance to move the robot, same units as _wheelDiameter

travel

public void travel(float distance,
                   boolean immediateReturn)
Moves the NXT robot a specific distance. A positive value moves it forwards and a negative value moves it backwards.

Parameters:
distance - The positive or negative distance to move the robot, same units as _wheelDiameter
immediateReturn - if true, the method returns immediately

rotate

public void rotate(float angle)
Rotates the NXT robot through a specific number of degrees in a direction (+ or -).

Parameters:
angle - Angle to rotate in degrees. A positive value rotates left, a negative value right.

rotate

public void rotate(float angle,
                   boolean immediateReturn)
Rotates the NXT robot through a specific number of degrees in a direction (+ or -). If immediateReturn is true, method returns immidiately.

Parameters:
angle - Angle to rotate in degrees. A positive value rotates left, a negative value right.
immediateReturn - if true, the method returns immediately

rotateTo

public void rotateTo(float angle)
Rotates the NXT robot to point in a specific direction, using the smallest rotation necessary

Parameters:
angle - The angle to rotate to, in degrees.

rotateTo

public void rotateTo(float angle,
                     boolean immediateReturn)
Rotates the NXT robot to point in a specific direction relative to the x axis. It make the smallest rotation necessary . If immediateReturn is true, method returns immidiately

Parameters:
angle - The angle to rotate to, in degrees.
immediateReturn - if true, method returns immediately

goTo

public void goTo(float x,
                 float y)
Robot moves to grid coordinates x,y. First it rotates to the proper direction then travels in a straight line to that point

Parameters:
x - destination X coordinate
y - destination Y coordinate

goTo

public void goTo(float x,
                 float y,
                 boolean immediateReturn)
Robot moves to grid coordinates x,y. First it rotates to the proper direction then travels in a straight line to that point

Parameters:
x - destination X coordinate
y - destination Y coordinate

distanceTo

public float distanceTo(float x,
                        float y)
Returns the distance from robot current location to the point with coordinates x,y

Parameters:
x - coordinate of destination
y - coordinate of destination
Returns:
the distance

angleTo

public float angleTo(float x,
                     float y)
Returns the angle from robot current location to the point with coordinates x,y

Parameters:
x - coordinate of destination
y - coordinate of destination
Returns:
angle

updatePose

public void updatePose()

arc

public void arc(float radius)
Starts the NXT robot moving in a circular path with a specified radius;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative.

Parameters:
radius - - the radius of the circular path. If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.

arc

public void arc(float radius,
                int angle)
Moves the NXT robot in a circular arc through the specified angle;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. Robot will stop when total rotation equals angle. If angle is negative, robot will move travel backwards.
See also travelArc(float radius, float distance)

Parameters:
radius - - the radius of the circular path. If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.

arc

public void arc(float radius,
                int angle,
                boolean immediateReturn)
Moves the NXT robot in a circular arc through a specific angle;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. Robot will stop when total rotation equals angle. If angle is negative, robot will travel backwards.
See also travelArc(float radius, float distance, boolean immedisteReturn)

Parameters:
radius - - the radius of the circular path. If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the outside.
angle - The sign of the angle determines the direction of robot motion
immediateReturn - if true, the method returns immediately

travelArc

public void travelArc(float radius,
                      float distance)
Moves the NXT robot in a circular arc through a specific distance;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. Robot will stop when distance traveled equals distance. If distance is negative, robot will travel backwards.
See also arc(float radius, int angle)

Parameters:
radius - of the turning circle; the sign determines if the center if the turn is left or right of the robot.
distance - The sign of the distance determines the direction of robot motion updatePosition() before the robot moves again.

travelArc

public void travelArc(float radius,
                      float distance,
                      boolean immediateReturn)
Moves the NXT robot in a circular arc through a specific distance;
The center of the turning circle is on the left side of the robot if parameter radius is positive and on the right if negative. Robot will stop when distance traveled equals distance. If distance is negative, robot will travel backwards.
See also arc(float radius, int angle, boolean immediateReturn)

Parameters:
radius - of the turning circle; the sign determines if the center if the turn is left or right of the robot.
distance - The sign of the distance determines the direction of robot motion
immediateReturn - if true, the method returns immediately.

steer

public void steer(int turnRate)
Starts the robot moving along a curved path. This method is similar to the arc(float radius) method except it uses a ratio of motor speeds to determine the curvature of the path and therefore has the ability to drive straight. This makes it useful for line following applications.

The turnRate specifies the sharpness of the turn, between -200 and +200.
The turnRate is used to calculate the ratio of inner wheel speed to outer wheel speed as a percent.
Formula: ratio = 100 - abs(turnRate).
When the ratio is negative, the outer and inner wheels rotate in opposite directions.

If turnRate is positive, the center of the turning circle is on the left side of the robot.
If turnRate is negative, the center of the turning circle is on the right side of the robot.
If turnRate is zero, the robot travels in a straight line

Examples of how the formula works:

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Parameters:
turnRate - If positive, the left side of the robot is on the inside of the turn. If negative, the left side is on the outside.

steer

public void steer(int turnRate,
                  int angle)
Moves the robot along a curved path through a specified turn angle. This method is similar to the arc(float radius , int angle) method except it uses a ratio of motor speeds to determine the curvature of the path and therefore has the ability to drive straight. This makes it useful for line following applications. This method does not return until the robot has completed moving angle degrees along the arc.
The turnRate specifies the sharpness of the turn, between -200 and +200.
For details about how this paramet works. see steer(int turnRate)

The robot will stop when the degrees it has moved along the arc equals angle.
If angle is positive, the robot will move travel forwards.
If angle is negative, the robot will move travel backwards. If angle is zero, the robot will not move and the method returns immediately.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Parameters:
turnRate - If positive, the left side of the robot is on the inside of the turn. If negative, the left side is on the outside.
angle - The angle through which the robot will rotate. If negative, robot traces the turning circle backwards.

steer

public void steer(int turnRate,
                  int angle,
                  boolean immediateReturn)
Moves the robot along a curved path for a specified angle of rotation. This method is similar to the arc(float radius, int angle, boolean immediateReturn) method except it uses a ratio of motor speeds to speeds to determine the curvature of the path and therefore has the ability to drive straight. This makes it useful for line following applications. This method has the ability to return immediately by using the immediateReturn parameter set to true.

The turnRate specifies the sharpness of the turn, between -200 and +200.
For details about how this paramet works, see steer(int turnRate)

The robot will stop when the degrees it has moved along the arc equals angle.
If angle is positive, the robot will move travel forwards.
If angle is negative, the robot will move travel backwards. If angle is zero, the robot will not move and the method returns immediately.

Note: If you have specified a drift correction in the constructor it will not be applied in this method.

Parameters:
turnRate - If positive, the left side of the robot is on the inside of the turn. If negative, the left side is on the outside.
angle - The angle through which the robot will rotate. If negative, robot traces the turning circle backwards.
immediateReturn - If immediateReturn is true then the method returns immediately.