lejos.navigation
Class CompassPilot

java.lang.Object
  extended by lejos.navigation.TachoPilot
      extended by lejos.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  CompassSensor compass
           
 
Fields inherited from class lejos.navigation.TachoPilot
_left, _leftDegPerDistance, _leftTurnRatio, _leftWheelDiameter, _motorSpeed, _right, _rightDegPerDistance, _rightTurnRatio, _rightWheelDiameter, _robotMoveSpeed, _robotTurnSpeed, _trackWidth
 
Constructor Summary
CompassPilot(CompassSensor compass, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor)
          Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
CompassPilot(CompassSensor compass, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)
          Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
CompassPilot(SensorPort compassPort, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor)
          Allocates a CompasPilot object, and sets the physical parameters of the NXT robot.
CompassPilot(SensorPort compassPort, float wheelDiameter, float trackWidth, Motor leftMotor, Motor 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.
 CompassSensor getCompass()
          return the compass
 int getCompassHeading()
          returns 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 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.navigation.TachoPilot
backward, forward, getLeft, getLeftActualSpeed, getLeftCount, getMoveMaxSpeed, getMoveSpeed, getRight, getRightActualSpeed, getRightCount, getTravelDistance, getTurnMaxSpeed, getTurnRatio, getTurnSpeed, regulateSpeed, setMoveSpeed, setSpeed, setTurnSpeed, stalled, steer, steer, steer, stop, turn, turn, turn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compass

protected CompassSensor compass

_angle0

public int _angle0
Constructor Detail

CompassPilot

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

Parameters:
compassPort - the sensor port connected to the CompassSensor e.g. SensorPort.S1
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(SensorPort compassPort,
                    float wheelDiameter,
                    float trackWidth,
                    Motor leftMotor,
                    Motor 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:
compassPort - : the compass sensor is connected to this port;
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

CompassPilot

public CompassPilot(CompassSensor compass,
                    float wheelDiameter,
                    float trackWidth,
                    Motor leftMotor,
                    Motor 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(CompassSensor compass,
                    float wheelDiameter,
                    float trackWidth,
                    Motor leftMotor,
                    Motor 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 CompassSensor 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()
returns current compass heading

Returns:

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; robot stops facing in specified direction

rotateTo

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

Parameters:
heading - 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.
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.