Package lejos.utility

Class GyroDirectionFinder

  • All Implemented Interfaces:
    Calibrate, DirectionFinder

    public class GyroDirectionFinder
    extends java.lang.Object
    implements DirectionFinder
    Implementation of the DirectionFinder interface 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 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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 gyro sensor instance
      • 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 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 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.
      • 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.
      • 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 Calibrate
      • stopCalibration

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