Package trclib.sensor

Class TrcAccelerometer

Direct Known Subclasses:
FtcAccelerometer, FtcAndroidAccel

public abstract class TrcAccelerometer extends TrcSensor<TrcAccelerometer.DataType>
This class implements a platform independent accelerometer. Typically, this class is extended by a platform dependent accelerometer class. The platform dependent accelerometer class must implement the abstract methods required by this class. The abstract methods allow this class to get raw data for each accelerometer axis. Depending on the options specified in the constructor, this class may create an integrator. The platform dependent accelerometer can specify how many axes it supports by setting the HAS_AXIS options. If it does not provide velocity or distance data, it can set the INTEGRATE and DOUBLE_INTEGRATE options and let the built-in integrator handle it.
  • Field Details

  • Constructor Details

    • TrcAccelerometer

      public TrcAccelerometer(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 accelerometer options. Multiple options can be OR'd together. ACCEL_HAS_X_AXIS - supports x-axis. ACCEL_HAS_Y_AXIS - supports y-axis. ACCEL_HAS_Z_AXIS - supports z-axis. ACCEL_INTEGRATE - do integration on all axes to get velocities. ACCEL_DOUBLE_INTEGRATE - do double integration on all axes to get distances.
      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.
    • TrcAccelerometer

      public TrcAccelerometer(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 accelerometer options. Multiple options can be OR'd together. ACCEL_HAS_X_AXIS - supports x-axis. ACCEL_HAS_Y_AXIS - supports y-axis. ACCEL_HAS_Z_AXIS - supports z-axis. ACCEL_INTEGRATE - do integration on all axes to get velocities. ACCEL_DOUBLE_INTEGRATE - do double integration on all axes to get distances.
  • Method Details

    • getRawXData

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

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

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

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

      public void setEnabled(boolean enabled)
      This method enables/disables the processing of accelerometer data. It is not automatically enabled when the TrcAccelerometer object is created. You need to explicitly enable the it before data processing will start. As part of enabling the accelerometer, calibrate() is also called. calibrate() may be overridden by the platform dependent accelerometer 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 if it 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 accelerometer 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 accelerometer 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 accelerometer 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.
    • getXAcceleration

      public TrcSensor.SensorData<Double> getXAcceleration()
      This method returns the acceleration on the x-axis.
      Returns:
      X acceleration.
    • getYAcceleration

      public TrcSensor.SensorData<Double> getYAcceleration()
      This method returns the acceleration on the y-axis.
      Returns:
      Y acceleration.
    • getZAcceleration

      public TrcSensor.SensorData<Double> getZAcceleration()
      This method returns the acceleration on the z-axis.
      Returns:
      Z acceleration.
    • getXVelocity

      public TrcSensor.SensorData<Double> getXVelocity()
      This method returns the velocity of the x-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.
      Returns:
      X velocity.
    • getYVelocity

      public TrcSensor.SensorData<Double> getYVelocity()
      This method returns the velocity of the y-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.
      Returns:
      Y velocity.
    • getZVelocity

      public TrcSensor.SensorData<Double> getZVelocity()
      This method returns the velocity of the z-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.
      Returns:
      Z velocity.
    • getXDistance

      public TrcSensor.SensorData<Double> getXDistance()
      This method returns the distance of the x-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.
      Returns:
      X distance.
    • getYDistance

      public TrcSensor.SensorData<Double> getYDistance()
      This method returns the distance of the y-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.
      Returns:
      Y distance.
    • getZDistance

      public TrcSensor.SensorData<Double> getZDistance()
      This method returns the distance of the z-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.
      Returns:
      Z distance.
    • 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, TrcAccelerometer.DataType dataType)
      This abstract method returns the raw sensor data for the specified axis and type.
      Specified by:
      getRawData in class TrcSensor<TrcAccelerometer.DataType>
      Parameters:
      index - specifies the axis index.
      dataType - specifies the data type.
      Returns:
      raw data for the specified axis.