Class TrcCardinalConverter<D>

java.lang.Object
trclib.archive.TrcCardinalConverter<D>

public class TrcCardinalConverter<D> extends Object
This class converts cardinal data to cartesian data for sensors such as gyro or compass. It can handle sensors that have one or more axes. Some value sensors such as the Modern Robotics gyro returns cardinal heading values between 0.0 and 360.0. When the gyro crosses the value range boundary, it wraps around. For example, if the current heading is 0.0 and the gyro turns 1 degree to the left, instead of giving you a value of -1.0, it wraps to the value of 359.0. Similarly, if the current heading is 359.0 and the gyro turns 1, 2, ... degrees to the right, instead of giving you a value of 360.0, 361.0, ... etc, it gives you 0.0, 1.0, ... This is undesirable especially when the heading value is used in PID controlled driving. For example, if the robot wants to go straight and maintain the heading of zero and the robot turned left slightly with a heading of 358.0, instead of turning right 2 degrees to get back to zero heading, the robot will turn left all the way around to get back to zero. This class implements a periodic task that monitor the sensor data. If it crosses the value range boundary, it will keep track of the number of crossovers and will adjust the value so it doesn't wrap in effect converting cardinal heading back to cartesian heading.
  • Constructor Details

    • TrcCardinalConverter

      public TrcCardinalConverter(String instanceName, TrcSensor<D> sensor, D dataType)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      sensor - specifies the sensor object that needs data unwrapping.
      dataType - specifies the data type to be unwrapped.
  • Method Details

    • toString

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

      public boolean isEnabled()
      This method returns the state of the cardinal converter task.
      Returns:
      true if converter task is enabled, false otherwise.
    • setEnabled

      public void setEnabled(boolean enabled)
      This method enables/disables the converter task. It is not automatically enabled when created. You must explicitly call this method to enable the converter.
      Parameters:
      enabled - specifies true for enabling the converter, disabling it otherwise.
    • reset

      public void reset(int index)
      This method resets the indexed converter.
      Parameters:
      index - specifies the axis index.
    • reset

      public void reset()
      This method resets the converter of all axes.
    • setCardinalRange

      public void setCardinalRange(int index, double rangeLow, double rangeHigh)
      This method sets the value range of the indexed converter.
      Parameters:
      index - specifies the axis index.
      rangeLow - specifies the low value of the range.
      rangeHigh - specifies the high value of the range.
    • getCartesianData

      public TrcSensor.SensorData<Double> getCartesianData(int index)
      This method returns the converted indexed cartesian data.
      Parameters:
      index - specifies the axis index.
      Returns:
      converted cartesian data.