lejos.navigation
Class CompassPilot

java.lang.Object
  extended by lejos.navigation.Pilot
      extended by lejos.navigation.CompassPilot

public class CompassPilot
extends Pilot

A Pilot that keeps track of direction using a CompassSensor.


Field Summary
protected  CompassSensor compass
           
 
Fields inherited from class lejos.navigation.Pilot
_degPerDistance, _left, _right, _speed, _trackWidth, _wheelDiameter
 
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()
           
 int getAngle()
          Returns the compass angle in degrees, Cartesian (increasing counter clockwise)
 CompassSensor getCompass()
          return the compass
 int getHeading()
          Returns target direction of 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 if the robot is travelling for a specific distance;
 void rotate(int 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(int angle, boolean immediateReturn)
          see rotate(angle)
 void rotateTo(int heading)
          robot rotates to the specified compass heading;
 void rotateTo(int angle, boolean immediateReturn)
          robot rotates to the specified compass heading;
 void setHeading(int angle)
          sets target direction of 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.Pilot
backward, forward, getLeft, getLeftActualSpeed, getLeftCount, getRight, getRightActualSpeed, getRightCount, getSpeed, getTravelDistance, getTurnRatio, regulateSpeed, resetTachoCount, setSpeed, steer, steer, steer, stop
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

compass

protected CompassSensor compass
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

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 if the robot is travelling for a specific distance;


getCompass

public CompassSensor getCompass()
return the compass

Returns:
the compass

getAngle

public int getAngle()
Returns the compass angle in degrees, Cartesian (increasing counter clockwise)

Overrides:
getAngle in class Pilot

getHeading

public int getHeading()
Returns target direction of robot facing


setHeading

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


calibrate

public void calibrate()

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. If immediateReturn is fale, this method calls updateXY(). If immediateReturn is true, method returns immidiately and your code MUST call updateXY() after the robot stops and before the robot moves again. Otherwise, the robot position is lost.

Overrides:
travel in class Pilot
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;

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

rotateTo

public void rotateTo(int 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(int heading)
robot rotates to the specified compass heading;

Parameters:
heading - Desired compass heading

rotate

public void rotate(int angle,
                   boolean immediateReturn)
see rotate(angle)

Overrides:
rotate in class Pilot
Parameters:
immediateReturn - - if true, method returns immediately.
Robot stops when specified angle is reached
angle - degrees. Positive angle rotates to the left; negative to the right.
Requires correct values for wheel diameter and track width.

rotate

public void rotate(int 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.

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

isMoving

public boolean isMoving()
returns TRUE if robot is moving

Overrides:
isMoving in class Pilot