lejos.robotics.navigation
Class CompassPilot

java.lang.Object
  extended by lejos.robotics.navigation.TachoPilot
      extended by lejos.robotics.navigation.CompassPilot
All Implemented Interfaces:
Pilot

public class CompassPilot
extends TachoPilot

A Pilot that keeps track of direction using a CompassSensor.


Field Summary
 int _angle0
           
protected  DirectionFinder compass
           
 
Fields inherited from class lejos.robotics.navigation.TachoPilot
_left, _leftDegPerDistance, _leftTurnRatio, _leftWheelDiameter, _motorSpeed, _right, _rightDegPerDistance, _rightTurnRatio, _rightWheelDiameter, _robotMoveSpeed, _robotTurnSpeed, _trackWidth
 
Constructor Summary
CompassPilot(DirectionFinder compass, float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor)
          Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
CompassPilot(DirectionFinder compass, float wheelDiameter, float trackWidth, TachoMotor leftMotor, TachoMotor rightMotor, boolean reverse)
          Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
 
Method Summary
 void calibrate()
          Rotates the robot 360 degrees while calibrating the compass resets compass zero to heading at end of calibration
 float getAngle()
          Returns the compass angle in degrees, Cartesian (increasing counter clockwise) i.e.
 DirectionFinder getCompass()
          Return the compass
 int getCompassHeading()
          Method returns the current compass heading
 int getHeading()
          Returns direction of desired robot facing
 boolean isMoving()
          returns TRUE if robot is moving
 boolean isRotating()
          returns true if robot is rotating to a specific direction
 boolean isTraveling()
          returns returns true if the robot is travelling for a specific distance;
 void reset()
          Resets tacho count for both motors.
 void resetCartesianZero()
           
 void rotate(float angle)
          Rotates the NXT robot through a specific angle; Rotates left if angle is positive, right if negative, Returns when angle is reached.
 void rotate(float angle, boolean immediateReturn)
          robot rotates to the specified compass heading;
 void rotateTo(float angle)
          Robot rotates to the specified compass heading.
 void rotateTo(float angle, boolean immediateReturn)
          robot rotates to the specified compass heading;
 void setHeading(int angle)
          sets direction of desired robot facing in degrees
 void stop()
          Stops the robot soon after the method is executed.
 void travel(float distance)
          Moves the NXT robot a specific distance;
A positive distance causes forward motion; negative distance moves backward.
 void travel(float distance, boolean immediateReturn)
          Moves the NXT robot a specific distance.
 
Methods inherited from class lejos.robotics.navigation.TachoPilot
arc, arc, arc, backward, forward, getLeft, getLeftActualSpeed, getLeftCount, getMoveMaxSpeed, getMoveSpeed, getRight, getRightActualSpeed, getRightCount, getTravelDistance, getTurnMaxSpeed, getTurnRatio, getTurnSpeed, regulateSpeed, setMoveSpeed, setSpeed, setTurnSpeed, stalled, steer, steer, steer, travelArc, travelArc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compass

protected DirectionFinder compass

_angle0

public int _angle0
Constructor Detail

CompassPilot

public CompassPilot(DirectionFinder compass,
                    float wheelDiameter,
                    float trackWidth,
                    TachoMotor leftMotor,
                    TachoMotor rightMotor)
Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
Assumes Motor.forward() causes the robot to move forward); Parameters

Parameters:
compass - : a compass sensor;
wheelDiameter - Diameter of the tire, in any convenient units. (The diameter in mm is usually printed on the tire).
trackWidth - Distance between center of right tire and center of left tire, in same units as wheelDiameter
leftMotor -
rightMotor -

CompassPilot

public CompassPilot(DirectionFinder compass,
                    float wheelDiameter,
                    float trackWidth,
                    TachoMotor leftMotor,
                    TachoMotor rightMotor,
                    boolean reverse)
Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
Assumes Motor.forward() causes the robot to move forward); Parameters

Parameters:
compass - : a compass sensor;
wheelDiameter - Diameter of the tire, in any convenient units. (The diameter in mm is usually printed on the tire).
trackWidth - Distance between center of right tire and center of left tire, in same units as wheelDiameter
leftMotor -
rightMotor -
reverse - if true of motor.forward() drives the robot backwards
Method Detail

isRotating

public boolean isRotating()
returns true if robot is rotating to a specific direction

Returns:
true iff robot is rotating to a specific direction

isTraveling

public boolean isTraveling()
returns returns true if the robot is travelling for a specific distance;


getCompass

public DirectionFinder getCompass()
Return the compass

Returns:
the compass

getAngle

public float getAngle()
Returns the compass angle in degrees, Cartesian (increasing counter clockwise) i.e. the actual robot heading

Specified by:
getAngle in interface Pilot
Overrides:
getAngle in class TachoPilot
Returns:
the angle of rotation of the robot since last call to reset of tacho count;

getHeading

public int getHeading()
Returns direction of desired robot facing


getCompassHeading

public int getCompassHeading()
Method returns the current compass heading

Returns:
Compass heading in degrees.

setHeading

public void setHeading(int angle)
sets direction of desired robot facing in degrees


calibrate

public void calibrate()
Rotates the robot 360 degrees while calibrating the compass resets compass zero to heading at end of calibration


resetCartesianZero

public void resetCartesianZero()

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. The robot steers to maintain its compass heading.

Specified by:
travel in interface Pilot
Overrides:
travel in class TachoPilot
Parameters:
distance - The positive or negative distance to move the robot, same units as _wheelDiameter
immediateReturn - iff true, the method returns immediately.

travel

public void travel(float distance)
Moves the NXT robot a specific distance;
A positive distance causes forward motion; negative distance moves backward. Robot steers to maintain its compass heading;

Specified by:
travel in interface Pilot
Overrides:
travel in class TachoPilot
Parameters:
distance - of robot movement. Unit of measure for distance must be same as wheelDiameter and trackWidth

rotateTo

public void rotateTo(float angle,
                     boolean immediateReturn)
robot rotates to the specified compass heading;

Parameters:
angle - Desired compass heading
immediateReturn - if TRUE, method returns immediately; Unfortunately, if you issue the stop(() command, the motion will run to completion.robot stops facing in specified direction

rotateTo

public void rotateTo(float angle)
Robot rotates to the specified compass heading.

Parameters:
angle - Desired compass heading

rotate

public void rotate(float angle,
                   boolean immediateReturn)
robot rotates to the specified compass heading;

Specified by:
rotate in interface Pilot
Overrides:
rotate in class TachoPilot
Parameters:
immediateReturn - - if true, method returns immediately. Unfortunately, if you issue the stop(() command, the motion will run to completion.
Robot stops when specified angle is reached
angle - The wanted angle of rotation in degrees. Positive angle rotate left (clockwise), negative right.

rotate

public void rotate(float angle)
Rotates the NXT robot through a specific angle; Rotates left if angle is positive, right if negative, Returns when angle is reached. Wheels turn in opposite directions producing a zero radius turn.

Specified by:
rotate in interface Pilot
Overrides:
rotate in class TachoPilot
Parameters:
angle - degrees. Positive angle rotates to the left (clockwise); negative to the right.
Requires correct values for wheel diameter and track width.

reset

public void reset()
Description copied from class: TachoPilot
Resets tacho count for both motors.

Specified by:
reset in interface Pilot
Overrides:
reset in class TachoPilot

isMoving

public boolean isMoving()
returns TRUE if robot is moving

Specified by:
isMoving in interface Pilot
Overrides:
isMoving in class TachoPilot
Returns:
true if the NXT robot is moving.

stop

public void stop()
Stops the robot soon after the method is executed. (It takes time for the motors to slow to a halt)

Specified by:
stop in interface Pilot
Overrides:
stop in class TachoPilot