Package trclib.sensor

Class TrcSensor<D>

java.lang.Object
trclib.sensor.TrcSensor<D>
Direct Known Subclasses:
FtcAndroidSensor, FtcColorSensor, FtcDistanceSensor, FtcMRColorSensor, FtcMRRangeSensor, FtcOpticalDistanceSensor, FtcUltrasonicSensor, TrcAccelerometer, TrcAnalogInput, TrcGyro

public abstract class TrcSensor<D> extends Object
This class implements a platform independent value sensor that has one or more axes or data type. Typically, this class is extended by a platform dependent value sensor class. The platform dependent sensor class must implement the abstract methods required by this class. The abstract methods allow this class to get raw data for each axis. This class also allows the caller to register an array of DataProcessors. The data processors will be called one at a time in the array order to filter/process the sensor data.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    This interface will be implemented by sensor classes that provide multiple data types.
    static class 
    This class implements the SensorData object that consists of the sensor value as well as a timestamp when the data sample is taken.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
     
     
    private final TrcFilter[]
     
    protected final String
     
    private static final int
     
    private final int
     
    private final double[]
     
    private final double[]
     
    private final int[]
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TrcSensor(String instanceName, int numAxes)
    Constructor: Creates an instance of the object.
    TrcSensor(String instanceName, int numAxes, TrcFilter[] filters)
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    calibrate(int numCalSamples, long calInterval, D dataType)
    This method calibrates the sensor by creating a calibrator if none exist yet.
    protected void
    calibrate(D dataType)
    This method calibrates the sensor by creating a calibrator if none exist yet.
    int
    This method returns the number of axes of the sensor.
    getProcessedData(int index, D dataType)
    This method returns the processed data for the specified axis and type.
    getRawData(int index, D dataType)
    This method returns the selected raw sensor data.
    boolean
    This method always returns false because the built-in calibrator is synchronous.
    void
    setInverted(int index, boolean inverted)
    This method inverts the specified axis of the sensor.
    void
    setScale(int index, double scale)
    This method sets the scale factor for the data of the specified axis.
    void
    setScaleAndOffset(int index, double scale, double offset)
    This method sets the scale factor and offset for the data of the specified axis.
    This method returns the instance name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • NUM_CAL_SAMPLES

      private static final int NUM_CAL_SAMPLES
      See Also:
    • CAL_INTERVAL

      private static final long CAL_INTERVAL
      See Also:
    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      protected final String instanceName
    • numAxes

      private final int numAxes
    • filters

      private final TrcFilter[] filters
    • signs

      private final int[] signs
    • scales

      private final double[] scales
    • offsets

      private final double[] offsets
    • calibrator

      private TrcSensorCalibrator<D> calibrator
  • Constructor Details

    • TrcSensor

      public TrcSensor(String instanceName, int numAxes, TrcFilter[] filters)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numAxes - specifies the number of axes.
      filters - specifies an array of filter objects, one for each axis, to filter sensor data. If no filter is used, this can be set to null.
    • TrcSensor

      public TrcSensor(String instanceName, int numAxes)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numAxes - specifies the number of axes.
  • Method Details

    • getRawData

      public abstract TrcSensor.SensorData<?> getRawData(int index, D dataType)
      This method returns the selected raw sensor data.
      Parameters:
      index - specifies the index if the sensor provides some sort of array data (e.g. the axis index of a 3-axis gyro).
      dataType - specifies the data type to return (e.g. rotation rate or heading of a gyro axis).
      Returns:
      selected sensor data.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • getNumAxes

      public int getNumAxes()
      This method returns the number of axes of the sensor.
      Returns:
      number of axes.
    • setInverted

      public void setInverted(int index, boolean inverted)
      This method inverts the specified axis of the sensor. This is useful if the orientation of the sensor axis is such that the data goes the wrong direction, if the sensor is mounted up-side-down, for example.
      Parameters:
      index - specifies the axis index.
      inverted - specifies true to invert the axis, false otherwise.
    • setScaleAndOffset

      public void setScaleAndOffset(int index, double scale, double offset)
      This method sets the scale factor and offset for the data of the specified axis.
      Parameters:
      index - specifies the axis index.
      scale - specifies the scale factor for the axis.
      offset - specifies the offset to be subtracted from the scaled data.
    • setScale

      public void setScale(int index, double scale)
      This method sets the scale factor for the data of the specified axis.
      Parameters:
      index - specifies the axis index.
      scale - specifies the scale factor for the axis.
    • calibrate

      protected void calibrate(int numCalSamples, long calInterval, D dataType)
      This method calibrates the sensor by creating a calibrator if none exist yet. It then calls the calibrator to do the calibration.
      Parameters:
      numCalSamples - specifies the number of calibration sample to take.
      calInterval - specifies the interval between each calibration sample in msec.
      dataType - specifies the data type needed calibration.
    • calibrate

      protected void calibrate(D dataType)
      This method calibrates the sensor by creating a calibrator if none exist yet. It then calls the calibrator to do the calibration.
      Parameters:
      dataType - specifies the data type needed calibration.
    • isCalibrating

      public boolean isCalibrating()
      This method always returns false because the built-in calibrator is synchronous.
      Returns:
      false.
    • getProcessedData

      public TrcSensor.SensorData<Double> getProcessedData(int index, D dataType)
      This method returns the processed data for the specified axis and type. The data will go through a filter if a filter is supplied for the axis. The calibration data will be applied to the sensor data if applicable. The sign and scale will also be applied.
      Parameters:
      index - specifies the axis index.
      dataType - specifies the data type object.
      Returns:
      processed sensor data for the axis.