Class SparkMaxEncoderWrapper
java.lang.Object
frc.team_8840_lib.utils.IO.IOLayer
frc.team_8840_lib.controllers.specifics.SparkMaxEncoderWrapper
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
ConstructorsConstructorDescriptionSparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax) Creates a new SparkMaxEncoderWrapperSparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax, String specificIdentifier) Creates a new SparkMaxEncoderWrapper -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculatePosition(double position) Calculates the position using the offset and conversion factor.doublecalculatePosition(double position, boolean ignoreOffset) Calculates the position using the offset and conversion factor.doublecalculateVelocity(double velocity) Calculates the velocity using the conversion factor.voiddoSubtractionOfStart(boolean subtractStartingPosition) Returns the "nickname" of the encoder for IO purposes.com.revrobotics.RelativeEncoderReturns the encoderdoubleReturns the offset of the encoderdoubleSets the offset of the encoderdoubleGets the velocity of the encodercom.revrobotics.REVLibErrorsetInverted(boolean inverted) Changes whether or not the encoder is inverted.voidsetManualConversion(boolean doManualConversion) Set whether to do manual conversion (true) or not (false) and use REV's API.voidsetManualOffset(boolean doManualOffset) Set whether to do manual offset (true) or not (false) and use REV's API.com.revrobotics.REVLibErrorsetPosition(double offset) Sets the position of the encoder.com.revrobotics.REVLibErrorsetPositionConversionFactor(double positionConversionFactor) Sets the position conversion factorcom.revrobotics.REVLibErrorsetVelocityConversionFactor(double velocityConversionFactor) Sets the velocity conversion factor
-
Constructor Details
-
SparkMaxEncoderWrapper
public SparkMaxEncoderWrapper(com.revrobotics.CANSparkMax sparkMax) Creates a new SparkMaxEncoderWrapper- Parameters:
sparkMax- The speed controller to get the encoder from
-
SparkMaxEncoderWrapper
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 calculateignoreOffset- 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
Returns the "nickname" of the encoder for IO purposes.- Overrides:
getBaseNamein classIOLayer- Returns:
- The "nickname" of the encoder for IO purposes.
-