Package trclib.sensor

Class TrcGyro

All Implemented Interfaces:
TrcOdometrySensor
Direct Known Subclasses:
FtcAnalogGyro, FtcAndroidGyro, FtcImu, FtcMRGyro

public abstract class TrcGyro extends TrcSensor<TrcGyro.DataType> implements TrcOdometrySensor
This class implements a platform independent gyro. Typically, this class is extended by a platform dependent gyro class. The platform dependent gyro class must implement the abstract methods required by this class. The abstract methods allow this class to get raw data for each gyro axis. Depending on the options specified in the constructor, this class creates an integrator or a CardinalConverter. The platform dependent gyro can specify how many axes it supports by setting the HAS_AXIS options. If it does not provide heading data, it can set the INTEGRATE option and let the built-in integrator handle it. Or if it provides a Cardinal heading instead of Cartesian, it can set the CONVERT_TO_CARTESIAN option to enable the CardinalConverter to do the conversion.
  • Field Details

  • Constructor Details

    • TrcGyro

      public TrcGyro(String instanceName, int numAxes, int options, TrcFilter[] filters)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numAxes - specifies the number of axes of the gyro.
      options - specifies the gyro options. Multiple options can be OR'd together. GYRO_HAS_X_AXIS - supports x-axis. GYRO_HAS_Y_AXIS - supports y-axis. GYRO_HAS_Z_AXIS - supports z-axis. GYRO_INTEGRATE - do integration on all axes to get headings.
      filters - specifies an array of filter objects one for each supported axis. It is assumed that the order of the filters in the array is x, y and then z. If an axis is specified in the options but no filter will be used on that axis, the corresponding element in the array should be set to null. If no filter is used at all, filters can be set to null.
    • TrcGyro

      public TrcGyro(String instanceName, int numAxes, int options)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numAxes - specifies the number of axes of the gyro.
      options - specifies the gyro options. Multiple options can be OR'd together. GYRO_HAS_X_AXIS - supports x-axis. GYRO_HAS_Y_AXIS - supports y-axis. GYRO_HAS_Z_AXIS - supports z-axis. GYRO_INTEGRATE - do integration on all axes to get headings. GYRO_CONVERT_TO_CARTESIAN - converts the Cardinal heading to Cartesian heading.
  • Method Details

    • getRawXData

      public abstract TrcSensor.SensorData<Double> getRawXData(TrcGyro.DataType dataType)
      This abstract method returns the raw data with the specified type of the x-axis.
      Parameters:
      dataType - specifies the data type.
      Returns:
      raw data with the specified type of the x-axis.
    • getRawYData

      public abstract TrcSensor.SensorData<Double> getRawYData(TrcGyro.DataType dataType)
      This abstract method returns the raw data with the specified type of the y-axis.
      Parameters:
      dataType - specifies the data type.
      Returns:
      raw data with the specified type of the y-axis.
    • getRawZData

      public abstract TrcSensor.SensorData<Double> getRawZData(TrcGyro.DataType dataType)
      This abstract method returns the raw data with the specified type of the z-axis.
      Parameters:
      dataType - specifies the data type.
      Returns:
      raw data with the specified type of the z-axis.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class TrcSensor<TrcGyro.DataType>
      Returns:
      instance name.
    • setEnabled

      public void setEnabled(boolean enabled)
      This method enables/disables the processing of gyro data. It is not automatically enabled when the TrcGyro object is created. You need to explicitly enable the it before data processing will start. As part of enabling the gyro, calibrate() is also called. calibrate() may be overridden by the platform dependent gyro if it is capable of doing its own. Otherwise, calibrate will call the built-in calibrator to do the calibration. Enabling/disabling data processing for the gyro involves enabling/disabling the Integrator and the CardinalConverter if they exist.
      Parameters:
      enabled - specifies true if enabling, false otherwise.
    • setElapsedTimerEnabled

      public void setElapsedTimerEnabled(boolean enabled)
      This method enables/disables the elapsed timers for performance monitoring.
      Parameters:
      enabled - specifies true to enable elapsed timers, false to disable.
    • printElapsedTime

      public void printElapsedTime(TrcDbgTrace tracer)
      This method prints the elapsed time info using the given tracer.
      Parameters:
      tracer - specifies the tracer to be used to print the info.
    • setXInverted

      public void setXInverted(boolean inverted)
      This method inverts the x-axis. This is useful if the orientation of the gyro x-axis is such that the data goes the wrong direction.
      Parameters:
      inverted - specifies true to invert x-axis, false otherwise.
    • setYInverted

      public void setYInverted(boolean inverted)
      This method inverts the y-axis. This is useful if the orientation of the gyro y-axis is such that the data goes the wrong direction.
      Parameters:
      inverted - specifies true to invert y-axis, false otherwise.
    • setZInverted

      public void setZInverted(boolean inverted)
      This method inverts the z-axis. This is useful if the orientation of the gyro z-axis is such that the data goes the wrong direction.
      Parameters:
      inverted - specifies true to invert z-axis, false otherwise.
    • setXScale

      public void setXScale(double scale)
      This method sets the scale factor for the data of the x-axis.
      Parameters:
      scale - specifies the x scale factor.
    • setYScale

      public void setYScale(double scale)
      This method sets the scale factor for the data of the y-axis.
      Parameters:
      scale - specifies the y scale factor.
    • setZScale

      public void setZScale(double scale)
      This method sets the scale factor for the data of the z-axis.
      Parameters:
      scale - specifies the z scale factor.
    • setXValueRange

      public void setXValueRange(double valueRangeLow, double valueRangeHigh)
      This method sets the heading value range of the x-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.
      Parameters:
      valueRangeLow - specifies the low value of the x-axis range.
      valueRangeHigh - specifies the high value of the x-axis range.
    • setYValueRange

      public void setYValueRange(double valueRangeLow, double valueRangeHigh)
      This method sets the heading value range of the y-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.
      Parameters:
      valueRangeLow - specifies the low value of the y-axis range.
      valueRangeHigh - specifies the high value of the y-axis range.
    • setZValueRange

      public void setZValueRange(double valueRangeLow, double valueRangeHigh)
      This method sets the heading value range of the z-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.
      Parameters:
      valueRangeLow - specifies the low value of the z-axis range.
      valueRangeHigh - specifies the high value of the z-axis range.
    • resetXWrapValueConverter

      public void resetXWrapValueConverter()
      This method resets the WrapValueConverter on the x-axis.
    • resetYWrapValueConverter

      public void resetYWrapValueConverter()
      This method resets the WrapValueConverter on the y-axis.
    • resetZWrapValueConverter

      public void resetZWrapValueConverter()
      This method resets the WrapValueConverter on the z-axis.
    • getRawXHeading

      private double getRawXHeading()
      This method reads the raw X Heading.
      Returns:
      raw X Heading.
    • getRawYHeading

      private double getRawYHeading()
      This method reads the raw Y Heading.
      Returns:
      raw Y Heading.
    • getRawZHeading

      private double getRawZHeading()
      This method reads the raw Z Heading.
      Returns:
      raw Z Heading.
    • getXRotationRate

      public TrcSensor.SensorData<Double> getXRotationRate()
      This method returns the rotation rate on the x-axis.
      Returns:
      X rotation rate.
    • getYRotationRate

      public TrcSensor.SensorData<Double> getYRotationRate()
      This method returns the rotation rate on the y-axis.
      Returns:
      Y rotation rate.
    • getZRotationRate

      public TrcSensor.SensorData<Double> getZRotationRate()
      This method returns the rotation rate on the z-axis.
      Returns:
      Z rotation rate.
    • getXHeading

      public TrcSensor.SensorData<Double> getXHeading()
      This method returns the heading of the x-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.
      Returns:
      X heading.
    • getYHeading

      public TrcSensor.SensorData<Double> getYHeading()
      This method returns the heading of the y-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.
      Returns:
      Y heading.
    • getZHeading

      public TrcSensor.SensorData<Double> getZHeading()
      This method returns the heading of the z-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.
      Returns:
      Z heading.
    • resetXIntegrator

      public void resetXIntegrator()
      This method resets the integrator on the x-axis.
    • resetYIntegrator

      public void resetYIntegrator()
      This method resets the integrator on the y-axis.
    • resetZIntegrator

      public void resetZIntegrator()
      This method resets the integrator on the z-axis.
    • getRawData

      public TrcSensor.SensorData<Double> getRawData(int index, TrcGyro.DataType dataType)
      This abstract method returns the raw sensor data for the specified axis and type.
      Specified by:
      getRawData in class TrcSensor<TrcGyro.DataType>
      Parameters:
      index - specifies the axis index.
      dataType - specifies the data type.
      Returns:
      raw data for the specified axis and type.
    • updateOdometry

      private void updateOdometry()
      This method reads the raw gyro Z data and updates the odometry with it.
    • getName

      public String getName()
      This method returns the instance name.
      Specified by:
      getName in interface TrcOdometrySensor
      Returns:
      instance name.
    • resetOdometry

      public void resetOdometry(boolean resetHardware)
      This method resets the odometry data and sensor. TODO: need to support multiple axes.
      Specified by:
      resetOdometry in interface TrcOdometrySensor
      Parameters:
      resetHardware - specifies true to do a hardware reset, false to do a software reset. Hardware reset may require some time to complete and will block this method from returning until finish.
    • getOdometry

      public TrcOdometrySensor.Odometry getOdometry(int axisIndex)
      This method returns a copy of the odometry data of the specified axis. It must be a copy so it won't change while the caller is accessing the data fields.
      Specified by:
      getOdometry in interface TrcOdometrySensor
      Parameters:
      axisIndex - specifies the axis index if it is a multi-axes sensor, 0 if it is a single axis sensor.
      Returns:
      a copy of the odometry data of the specified axis.