Class SparkMaxEncoderWrapper

java.lang.Object
frc.team_8840_lib.utils.IO.IOLayer
frc.team_8840_lib.controllers.specifics.SparkMaxEncoderWrapper

public class SparkMaxEncoderWrapper extends IOLayer
A wrapper to stop issues with the SparkMax encoder. We've had a lot of issues with REV's api, so this is a wrapper to help with that.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax)
    Creates a new SparkMaxEncoderWrapper
    SparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax, String specificIdentifier)
    Creates a new SparkMaxEncoderWrapper
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    calculatePosition(double position)
    Calculates the position using the offset and conversion factor.
    double
    calculatePosition(double position, boolean ignoreOffset)
    Calculates the position using the offset and conversion factor.
    double
    calculateVelocity(double velocity)
    Calculates the velocity using the conversion factor.
    void
    doSubtractionOfStart(boolean subtractStartingPosition)
     
    Returns the "nickname" of the encoder for IO purposes.
    com.revrobotics.RelativeEncoder
    Returns the encoder
    double
    Returns the offset of the encoder
    double
    Sets the offset of the encoder
    double
    Gets the velocity of the encoder
    com.revrobotics.REVLibError
    setInverted(boolean inverted)
    Changes whether or not the encoder is inverted.
    void
    setManualConversion(boolean doManualConversion)
    Set whether to do manual conversion (true) or not (false) and use REV's API.
    void
    setManualOffset(boolean doManualOffset)
    Set whether to do manual offset (true) or not (false) and use REV's API.
    com.revrobotics.REVLibError
    setPosition(double offset)
    Sets the position of the encoder.
    com.revrobotics.REVLibError
    setPositionConversionFactor(double positionConversionFactor)
    Sets the position conversion factor
    com.revrobotics.REVLibError
    setVelocityConversionFactor(double velocityConversionFactor)
    Sets the velocity conversion factor

    Methods inherited from class frc.team_8840_lib.utils.IO.IOLayer

    close, isReal, setReal

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SparkMaxEncoderWrapper

      public SparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax)
      Creates a new SparkMaxEncoderWrapper
      Parameters:
      sparkMax - The speed controller to get the encoder from
    • SparkMaxEncoderWrapper

      public SparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax, String specificIdentifier)
      Creates a new SparkMaxEncoderWrapper
      Parameters:
      sparkMax - The speed controller to get the encoder from
  • Method Details

    • getEncoder

      public com.revrobotics.RelativeEncoder getEncoder()
      Returns the encoder
      Returns:
      relative encoder
    • setInverted

      public com.revrobotics.REVLibError setInverted(boolean inverted)
      Changes whether or not the encoder is inverted.
      Parameters:
      inverted - Whether or not the encoder is inverted
      Returns:
      REVLibError
    • getPosition

      public double getPosition()
      Sets the offset of the encoder
      Returns:
      The position of the encoder
    • getVelocity

      public double getVelocity()
      Gets the velocity of the encoder
      Returns:
      The velocity of the encoder
    • setManualConversion

      public void setManualConversion(boolean doManualConversion)
      Set whether to do manual conversion (true) or not (false) and use REV's API.
      Parameters:
      doManualConversion - Whether to do manual conversion (true) or not (false)
    • setManualOffset

      public void setManualOffset(boolean doManualOffset)
      Set whether to do manual offset (true) or not (false) and use REV's API.
      Parameters:
      doManualOffset - Whether to do manual offset (true) or not (false)
    • doSubtractionOfStart

      public void doSubtractionOfStart(boolean subtractStartingPosition)
    • setPositionConversionFactor

      public com.revrobotics.REVLibError setPositionConversionFactor(double positionConversionFactor)
      Sets the position conversion factor
      Parameters:
      positionConversionFactor - The position conversion factor
      Returns:
      REVLibError
    • setVelocityConversionFactor

      public com.revrobotics.REVLibError setVelocityConversionFactor(double velocityConversionFactor)
      Sets the velocity conversion factor
      Parameters:
      velocityConversionFactor - The velocity conversion factor
      Returns:
      REVLibError
    • setPosition

      public com.revrobotics.REVLibError setPosition(double offset)
      Sets the position of the encoder. Note: In conversion, this is subtracted from the position, not added3
      Parameters:
      offset - The offset of the encoder (the new position)
      Returns:
      REVLibError
    • calculatePosition

      public double calculatePosition(double position)
      Calculates the position using the offset and conversion factor. Uses the booleans to determine whether to use REV's API or not.
      Returns:
      Calculated position
    • calculatePosition

      public double calculatePosition(double position, boolean ignoreOffset)
      Calculates the position using the offset and conversion factor. Uses the preset booleans for REV's API, and an argument for the offset.
      Parameters:
      position - The position to calculate
      ignoreOffset - Whether to ignore the offset or not
      Returns:
      Calculated position
    • calculateVelocity

      public double calculateVelocity(double velocity)
      Calculates the velocity using the conversion factor. Uses the booleans to determine whether to use REV's API or not.
      Returns:
      Calculated velocity
    • getOffset

      public double getOffset()
      Returns the offset of the encoder
      Returns:
      The offset of the encoder
    • getBaseName

      public String getBaseName()
      Returns the "nickname" of the encoder for IO purposes.
      Overrides:
      getBaseName in class IOLayer
      Returns:
      The "nickname" of the encoder for IO purposes.