Package trclib.sensor

Class TrcAnalogInput

Direct Known Subclasses:
FtcAnalogInput, TrcAnalogSensor

public abstract class TrcAnalogInput extends TrcSensor<TrcAnalogInput.DataType>
This class implements a platform independent AnalogInput. Typically, this class is extended by a platform dependent sensor class that produces value data. The sensor doesn't have to be connected to the AnalogInput port. It could be connected to an I2C port as long as it produces a value data. The platform dependent sensor class must implement the abstract methods required by this class. The abstract methods allow this class to get raw data from the sensor. Depending on the options specified in the constructor, this class may create an integrator. If it needs data integration, it can set the INTEGRATE or the DOUBLE_INTEGRATE options.
  • Field Details

  • Constructor Details

    • TrcAnalogInput

      public TrcAnalogInput(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.
      options - specifies the AnalogInput options. Multiple options can be OR'd together. ANALOGINPUT_INTEGRATE - do integration on sensor data. ANALOGINPUT_DOUBLE_INTEGRATE - do double integration on sensor data.
      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.
    • TrcAnalogInput

      public TrcAnalogInput(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.
      options - specifies the AnalogInput options. Multiple options can be OR'd together. ANALOGINPUT_INTEGRATE - do integration on sensor data. ANALOGINPUT_DOUBLE_INTEGRATE - do double integration on sensor data.
    • TrcAnalogInput

      public TrcAnalogInput(String instanceName, int numAxes)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numAxes - specifies the number of axes supporting by the analog input device.
  • Method Details

    • getRawData

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

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

      public void setEnabled(boolean enabled)
      The method enables/disables the processing of sensor data. It is not automatically enabled when the TrcAnalogInput object is created. You need to explicitly enable the it before data processing will start. As part of enabling the sensor, calibrate() is also called. calibrate() may be overridden by the platform dependent sensor 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 sensor involves enabling/disabling the integrator if it exists.
      Parameters:
      enabled - specifies true if enabling, false otherwise.
    • setElapsedTimerEnabled

      public static 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 static 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.
    • setInverted

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

      public void setScaleAndOffset(double scale, double offset)
      This method sets the scale factor on the sensor data.
      Parameters:
      scale - specifies the scale factor.
      offset - specifies the offset to be subtracted from the scaled data.
    • setScale

      public void setScale(double scale)
      This method sets the scale factor on the sensor data.
      Parameters:
      scale - specifies the scale factor.
    • getData

      public TrcSensor.SensorData<Double> getData(int index)
      This method returns the processed sensor data of the specified index.
      Parameters:
      index - specifies the data index.
      Returns:
      processed data.
    • getNormalizedData

      public TrcSensor.SensorData<Double> getNormalizedData(int index)
      This method returns the processed and normalized sensor data of the specified index.
      Parameters:
      index - specifies the data index.
      Returns:
      processed normalized data.
    • getIntegratedData

      public TrcSensor.SensorData<Double> getIntegratedData(int index)
      This method returns the integrated sensor data of the specified index.
      Parameters:
      index - specifies the data index.
      Returns:
      integrated sensor data.
    • getDoubleIntegratedData

      public TrcSensor.SensorData<Double> getDoubleIntegratedData(int index)
      This method returns the double integrated sensor data of the specified index.
      Parameters:
      index - specifies the data index.
      Returns:
      double integrated sensor data.
    • resetIntegrator

      public void resetIntegrator(int index)
      This method resets the integrator of the specified index.
      Parameters:
      index - specifies the data index.