lejos.nxt.addon
Class GyroDirectionFinder

java.lang.Object
  extended by lejos.nxt.addon.GyroDirectionFinder
All Implemented Interfaces:
DirectionFinder

public class GyroDirectionFinder
extends java.lang.Object
implements DirectionFinder

Implementation of the DirectionFinder interface that integrates repeated rate-of-turn readings from a GyroSensor into a continuously updated heading. This class is very similar to CompassMindSensor, except that the direction returned does not convey true heading (north, south, etc) but rather relative heading change since the last time setDegrees() or resetCartesianZero() was called.

Author:
Brent Gardner, Kirk P. Thompson
See Also:
GyroSensor

Constructor Summary
GyroDirectionFinder(Gyroscope gyro)
          Creates and initializes a new GyroDirectionFinder using passed GyroSensor
GyroDirectionFinder(Gyroscope gyro, boolean calibrate)
          Creates and initializes a new GyroDirectionFinder using passed GyroSensor and does the GyroSensor.recalibrateOffset() method.
 
Method Summary
 float getAngularAcceleration()
          Returns the current rate at which the angular velocity is increasing or decreasing in degrees-per-second, per second.
 float getAngularVelocity()
          Returns the current rate-of-turn in degrees/second, as read by the GyroSensor instance passed in the constructor.
 float getDegrees()
          Returns the directional heading in degrees.
 float getDegreesCartesian()
          Returns the current rate-of-turn in degrees, as read by the GyroSensor.
 void resetCartesianZero()
          Resets the current heading to zero.
 void setDegrees(float heading)
          Resets the current heading to a desired value.
 void setDegreesCartesian(float heading)
          Resets the current heading to a desired value.
 void startCalibration()
          Find offset/bias of gyro while at rest (ensure it is at rest).
 void stopCalibration()
          NO FUNCTIONALITY EQUIVALENT for GyroSensor so implemented just to satisfy the DirectionFinder interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GyroDirectionFinder

public GyroDirectionFinder(Gyroscope gyro)
Creates and initializes a new GyroDirectionFinder using passed GyroSensor

Parameters:
gyro - A GyroSensor instance
See Also:
GyroSensor

GyroDirectionFinder

public GyroDirectionFinder(Gyroscope gyro,
                           boolean calibrate)
Creates and initializes a new GyroDirectionFinder using passed GyroSensor and does the GyroSensor.recalibrateOffset() method.

Parameters:
gyro - A GyroSensor instance
See Also:
GyroSensor.recalibrateOffset(), startCalibration()
Method Detail

setDegrees

public void setDegrees(float heading)
Resets the current heading to a desired value.

See Also:
getDegrees()

getDegrees

public float getDegrees()
Returns the directional heading in degrees. Includes "winding", so the value could be greater than 360 or less than 0 if the robot has done multiple rotations since the last call to resetCartesianZero().

Returns:
Heading in degrees.
See Also:
setDegrees(float)

getAngularVelocity

public float getAngularVelocity()
Returns the current rate-of-turn in degrees/second, as read by the GyroSensor instance passed in the constructor.

Returns:
Angular velocity in degrees.
See Also:
GyroSensor

getAngularAcceleration

public float getAngularAcceleration()
Returns the current rate at which the angular velocity is increasing or decreasing in degrees-per-second, per second.

Returns:
Angular acceleration in degrees-per-second per second.

getDegreesCartesian

public float getDegreesCartesian()
Returns the current rate-of-turn in degrees, as read by the GyroSensor.

Specified by:
getDegreesCartesian in interface DirectionFinder
Returns:
Heading in degrees.

setDegreesCartesian

public void setDegreesCartesian(float heading)
Resets the current heading to a desired value.


resetCartesianZero

public void resetCartesianZero()
Resets the current heading to zero.

Specified by:
resetCartesianZero in interface DirectionFinder

startCalibration

public void startCalibration()
Find offset/bias of gyro while at rest (ensure it is at rest). This is done by calling the recalibrateOffset() method of the GyroSensor instance passed in the constructor. This takes 3 seconds.

Specified by:
startCalibration in interface DirectionFinder
See Also:
GyroSensor.recalibrateOffset()

stopCalibration

public void stopCalibration()
NO FUNCTIONALITY EQUIVALENT for GyroSensor so implemented just to satisfy the DirectionFinder interface. Does nothing.

Specified by:
stopCalibration in interface DirectionFinder