Package lejos.utility
Class GyroDirectionFinder
- java.lang.Object
-
- lejos.utility.GyroDirectionFinder
-
- All Implemented Interfaces:
Calibrate,DirectionFinder
public class GyroDirectionFinder extends java.lang.Object implements DirectionFinder
Implementation of theDirectionFinderinterface that integrates repeated rate-of-turn readings from a gyro sensor into a continuously updated heading. This class is very similar to the compass sensors, 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
-
-
Constructor Summary
Constructors Constructor Description GyroDirectionFinder(Gyroscope gyro)Creates and initializes a newGyroDirectionFinderusing passedGyroSensorGyroDirectionFinder(Gyroscope gyro, boolean calibrate)Creates and initializes a newGyroDirectionFinderusing passedGyroSensorand does theGyroSensor.recalibrateOffset()method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetAngularAcceleration()Returns the current rate at which the angular velocity is increasing or decreasing in degrees-per-second, per second.floatgetAngularVelocity()Returns the current rate-of-turn in degrees/second, as read by theGyroSensorinstance passed in the constructor.floatgetDegrees()Returns the directional heading in degrees.floatgetDegreesCartesian()Returns the current rate-of-turn in degrees, as read by theGyroSensor.voidresetCartesianZero()Resets the current heading to zero.voidsetDegrees(float heading)Resets the current heading to a desired value.voidsetDegreesCartesian(float heading)Resets the current heading to a desired value.voidstartCalibration()Find offset/bias of gyro while at rest (ensure it is at rest).voidstopCalibration()NO FUNCTIONALITY EQUIVALENT forGyroSensorso implemented just to satisfy theDirectionFinderinterface.
-
-
-
Constructor Detail
-
GyroDirectionFinder
public GyroDirectionFinder(Gyroscope gyro)
Creates and initializes a newGyroDirectionFinderusing passedGyroSensor- Parameters:
gyro- a gyro sensor instance
-
GyroDirectionFinder
public GyroDirectionFinder(Gyroscope gyro, boolean calibrate)
Creates and initializes a newGyroDirectionFinderusing passedGyroSensorand does theGyroSensor.recalibrateOffset()method.- Parameters:
gyro- A gyro sensor instance
-
-
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 toresetCartesianZero().- Returns:
- Heading in degrees.
- See Also:
setDegrees(float)
-
getAngularVelocity
public float getAngularVelocity()
Returns the current rate-of-turn in degrees/second, as read by theGyroSensorinstance passed in the constructor.- Returns:
- Angular velocity in degrees.
-
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 theGyroSensor.- Specified by:
getDegreesCartesianin interfaceDirectionFinder- 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:
resetCartesianZeroin interfaceDirectionFinder
-
startCalibration
public void startCalibration()
Find offset/bias of gyro while at rest (ensure it is at rest). This is done by calling therecalibrateOffset()method of theGyroSensorinstance passed in the constructor. This takes 3 seconds.- Specified by:
startCalibrationin interfaceCalibrate
-
stopCalibration
public void stopCalibration()
NO FUNCTIONALITY EQUIVALENT forGyroSensorso implemented just to satisfy theDirectionFinderinterface. Does nothing.- Specified by:
stopCalibrationin interfaceCalibrate
-
-