Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## lejos.navigation
Class CompassNavigator

    java.lang.Object
      lejos.navigation.TachoNavigator
          lejos.navigation.CompassNavigator

All Implemented Interfaces:
  Navigator

    public class CompassNavigator

extends TachoNavigator

The CompassNavigatort class, like its superclass, can keep track of the robot position and the direction angle it faces. It uses a CompassPilot object to control NXT robot movements.
The position and direction angle values are updated automatically when the movement command returns after the movement is complete and and after stop() command is issued. However, some commands optionally return immediately, to permit sensor monitoring in the main thread. It is then the programmers responsibility to call updateXY() when the robot motion is completed. All angles are in degrees, distances in the units used to specify robot dimensions. As with pilot, the robot must be have two independently controlled drive wheels. Uses the Compass Sensor to determine the robot heading.

Field Summary

Fields inherited from class lejos.navigation.TachoNavigator
`_heading, _left0, _pilot, _right0`

Constructor Summary
`CompassNavigator(CompassPilot compassPilot)` To use this constructor, you must first create a compass pilot.
`CompassNavigator(CompassSensor compass, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)`
`CompassNavigator(SensorPort compassPort, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor)` Allocates a CompassNavigator objects and its CompassPilot object and initializes it with the proper motors and dimensions.
`CompassNavigator(SensorPort compassPort, float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)`

Method Summary
`void` | `calibrateCompass()` Robot rotates 360 degrees while calibrating the compass sensor
`void` | `rotate(float angle, boolean immediateReturn)` Rotates the NXT robot by a specified angle.
`void` | `rotateTo(float angle, boolean immediateReturn)` Rotates the NXT robot to point in a specific direction.
`void` | `stop()` Halts the NXT robot and calculates new x, y coordinates.
`void` | `travel(float distance, boolean immediateReturn)` Moves the NXT robot a specific distance.
`void` | `updateHeading()` Direction of robot facing is set equal to the current compass reading
`void` | `updateXY()` Updates x,y coordinates; assumes last compass angle was constant during travel

Methods inherited from class lejos.navigation.TachoNavigator
`angleTo, backward, distanceTo, forward, getAngle, getPilot, getX, getY, goTo, goTo, isMoving, rotate, rotateLeft, rotateRight, rotateTo, setPosition, setSpeed, travel, turn, turn, turn, updatePosition`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Constructor Detail

### CompassNavigator

    public CompassNavigator(SensorPort compassPort,
                            float wheelDiameter,
                            float trackWidth,
                            Motor leftMotor,
                            Motor rightMotor)

  Allocates a CompassNavigator objects and its CompassPilot object and initializes it with the proper motors and dimensions. This is a subclass of TachoNavigator (see that API for other methods). The x and y 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.

  Parameters:
    `compassPort` - the sensor port connected to the compass sensor e.g SensorPort.S1
    `wheelDiameter` - The diameter of the wheel, usually printed right on the wheel, in centimeters (e.g. 49.6 mm = 4.96 cm = 1.95 in)
    `trackWidth` - The distance from the center of the left tire to the center of the right tire, in units of your choice
    `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.

### CompassNavigator

    public CompassNavigator(SensorPort compassPort,
                            float wheelDiameter,
                            float trackWidth,
                            Motor leftMotor,
                            Motor rightMotor,
                            boolean reverse)

### CompassNavigator

    public CompassNavigator(CompassSensor compass,
                            float wheelDiameter,
                            float trackWidth,
                            Motor leftMotor,
                            Motor rightMotor,
                            boolean reverse)

### CompassNavigator

    public CompassNavigator(CompassPilot compassPilot)

  To use this constructor, you must first create a compass pilot.

  Parameters:
    `compassPilot` -

Method Detail

### calibrateCompass

    public void calibrateCompass()

  Robot rotates 360 degrees while calibrating the compass sensor

### rotateTo

    public void rotateTo(float angle,
                         boolean immediateReturn)

  Rotates the NXT robot to point in a specific direction. It will take the shortest path necessary to point to the desired angle. If immediateReturnis true, method returns immidiately and your code MUST call updatePostion() when the robot has stopped. Otherwise, the robot position is lost.

  Specified by:
    `rotateTo` in interface `Navigator`
  Overrides:
    `rotateTo` in class `TachoNavigator`
  Parameters:
    `angle` - The angle to rotate to, in degrees.
    `immediateReturn` - iff true, method returns immediately and the programmer is responsible for calling updatePosition() before the robot moves again.

### rotate

    public void rotate(float angle,
                       boolean immediateReturn)

  Rotates the NXT robot by a specified angle. If immediateReturnis true, method returns immidiately and your code MUST call updatePostion() when the robot has stopped. Otherwise, the robot position is lost.

  Specified by:
    `rotate` in interface `Navigator`
  Overrides:
    `rotate` in class `TachoNavigator`
  Parameters:
    `angle` - The angle to rotate to, in degrees.
    `immediateReturn` - iff true, method returns immediately and the programmer is responsible for calling updatePosition() before the robot moves again.

### 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 immediateReturnis true, method returns immidiately and your code MUST call updatePostion() when the robot has stopped. Otherwise, the robot position is lost.

  Specified by:
    `travel` in interface `Navigator`
  Overrides:
    `travel` in class `TachoNavigator`
  Parameters:
    `distance` - The positive or negative distance to move the robot, same units as _wheelDiameter
    `immediateReturn` - iff true, the method returns immediately, in which case the programmer
    is responsible for calling updatePosition() before the robot moves again.

### stop

    public void stop()

  Halts the NXT robot and calculates new x, y coordinates.

  Specified by:
    `stop` in interface `Navigator`
  Overrides:
    `stop` in class `TachoNavigator`
  See Also:
    `Navigator.forward().`

### updateHeading

    public void updateHeading()

  Direction of robot facing is set equal to the current compass reading

### updateXY

    public void updateXY()

  Updates x,y coordinates; assumes last compass angle was constant during travel

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD