Class SparkFlexEncoderSwerve

java.lang.Object
swervelib.encoders.SwerveAbsoluteEncoder
swervelib.encoders.SparkFlexEncoderSwerve
All Implemented Interfaces:
AutoCloseable

public class SparkFlexEncoderSwerve extends SwerveAbsoluteEncoder
SparkFlex absolute encoder, attached through the data port.
  • Field Details

  • Constructor Details

    • SparkFlexEncoderSwerve

      public SparkFlexEncoderSwerve(SwerveMotor motor, int conversionFactor)
      Create the SparkFlexEncoderSwerve object as a duty cycle from the SparkFlex motor.
      Parameters:
      motor - Motor to create the encoder from.
      conversionFactor - The conversion factor to set if the output is not from 0 to 360.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class SwerveAbsoluteEncoder
    • factoryDefault

      public void factoryDefault()
      Reset the encoder to factory defaults.
      Specified by:
      factoryDefault in class SwerveAbsoluteEncoder
    • clearStickyFaults

      public void clearStickyFaults()
      Clear sticky faults on the encoder.
      Specified by:
      clearStickyFaults in class SwerveAbsoluteEncoder
    • configure

      public void configure(boolean inverted)
      Configure the absolute encoder to read from [0, 360) per second.
      Specified by:
      configure in class SwerveAbsoluteEncoder
      Parameters:
      inverted - Whether the encoder is inverted.
    • getAbsolutePosition

      public double getAbsolutePosition()
      Get the absolute position of the encoder.
      Specified by:
      getAbsolutePosition in class SwerveAbsoluteEncoder
      Returns:
      Absolute position in degrees from [0, 360).
    • getAbsoluteEncoder

      public Object getAbsoluteEncoder()
      Get the instantiated absolute encoder Object.
      Specified by:
      getAbsoluteEncoder in class SwerveAbsoluteEncoder
      Returns:
      Absolute encoder object.
    • setAbsoluteEncoderOffset

      public boolean setAbsoluteEncoderOffset(double offset)
      Sets the Absolute Encoder Offset inside of the SparkFlex's Memory.
      Specified by:
      setAbsoluteEncoderOffset in class SwerveAbsoluteEncoder
      Parameters:
      offset - the offset the Absolute Encoder uses as the zero point.
      Returns:
      if setting Absolute Encoder Offset was successful or not.
    • getVelocity

      public double getVelocity()
      Get the velocity in degrees/sec.
      Specified by:
      getVelocity in class SwerveAbsoluteEncoder
      Returns:
      velocity in degrees/sec.