Class DetachedEncoder

java.lang.Object
com.revrobotics.NativeResourceCleaner
com.revrobotics.encoder.DetachedEncoder
All Implemented Interfaces:
RelativeEncoder, REVDevice
Direct Known Subclasses:
SplineEncoder

public abstract class DetachedEncoder extends NativeResourceCleaner implements REVDevice, RelativeEncoder
  • Field Details

  • Constructor Details

    • DetachedEncoder

      public DetachedEncoder(int id, DetachedEncoder.Model model)
      Create a new object to control a Detached Encoder
      Parameters:
      id - The device ID.
      model - The specific model of detached encoder
  • Method Details

    • getDeviceId

      public int getDeviceId()
      Get the configured Device ID of the Detached encoder.
      Returns:
      int device ID
    • getModel

      public DetachedEncoder.Model getModel()
      Get the Model of this Detached Encoder Device. Useful for determining if this is a MAXSpline, or other device
      Returns:
      the model of this encoder
    • getPosition

      public double getPosition()
      Get the position of the encoder. This returns the native units of 'rotations' by default, and can be changed by a scale factor using DetachedEncoderConfig.positionConversionFactor(float).
      Specified by:
      getPosition in interface RelativeEncoder
      Returns:
      Number of rotations of the encoder
    • getAngle

      public double getAngle()
      Get the absolute position of the encoder. This returns the native units of 'rotations' [0, 1) by default, and can be changed by a scale factor using DetachedEncoderConfig.positionConversionFactor(float).
      Returns:
      Number of rotations of the encoder
    • getRawAngle

      public double getRawAngle()
      Get the absolute position of the encoder. This returns the native units of 'rotations' [0, 1) without scaling from conversion factors.
      Returns:
      Number of rotations of the encoder
    • getVelocity

      public double getVelocity()
      Get the velocity of the encoder. This returns the native units of 'RPM' by default, and can be changed by a scale factor using DetachedEncoderConfig.velocityConversionFactor(float).
      Specified by:
      getVelocity in interface RelativeEncoder
      Returns:
      Number the RPM of the encoder
    • setPosition

      public REVLibError setPosition(double position)
      Set the position of the encoder. By default the units are 'rotations' and can be changed by a scale factor using DetachedEncoderConfig.positionConversionFactor(float).
      Specified by:
      setPosition in interface RelativeEncoder
      Parameters:
      position - Number of rotations of the motor
      Returns:
      REVLibError.kOk if successful
    • getFaults

      public DetachedEncoder.Faults getFaults()
      Get the active faults that are currently present on the detached encoder. Faults are fatal errors that prevent the encoder from functioning.
      Returns:
      A struct with each fault and their active value
    • getStickyFaults

      public DetachedEncoder.Faults getStickyFaults()
      Get the sticky faults that were present on the detached encoder at one point since the sticky faults were last cleared. Faults are fatal errors that prevent the encoder from functioning.

      Sticky faults can be cleared with clearFaults().

      Returns:
      A struct with each fault and their sticky value
    • clearFaults

      public void clearFaults()
      Clears all sticky faults.
    • getFirmwareVersion

      public DetachedEncoder.FirmwareVersion getFirmwareVersion()
      Get the firmware version of the detached encoder.
      Returns:
      Firmware version object
    • configure

      public void configure(DetachedEncoderConfig config, ResetMode resetMode)
      Set the configuration for the Detached encoder.

      If resetMode is {com.revrobotics.ResetMode#kResetSafeParameters}, this method will reset safe writable parameters to their default values before setting the given configuration.

      Parameters:
      config - The desired Detached encoder configuration
      resetMode - Whether to reset safe parameters before setting the configuration
    • getStatus0

      public DetachedEncoder.PeriodicStatus0 getStatus0()
      Returns:
      periodic status 0, or null if it's not found
    • getStatus1

      public DetachedEncoder.PeriodicStatus1 getStatus1()
      Returns:
      periodic status 1, or null if it's not found
    • getStatus2

      public DetachedEncoder.PeriodicStatus2 getStatus2()
      Returns:
      periodic status 2, or null if it's not found
    • getStatus3

      public DetachedEncoder.PeriodicStatus3 getStatus3()
      Returns:
      periodic status 3, or null if it's not found
    • getStatus4

      public DetachedEncoder.PeriodicStatus4 getStatus4()
      Returns:
      periodic status 4, or null if it's not found
    • close

      public void close()
      Closes the Detached encoder controller
    • getCleanAction

      protected NativeResourceCleaner.OnClean getCleanAction()
      Description copied from class: NativeResourceCleaner
      Note: it is important that no reference to 'this' is taken in the implementation.
      Specified by:
      getCleanAction in class NativeResourceCleaner
      Returns:
      an action to run on clean