Package swervelib.encoders
Class SparkFlexEncoderSwerve
java.lang.Object
swervelib.encoders.SwerveAbsoluteEncoder
swervelib.encoders.SparkFlexEncoderSwerve
- All Implemented Interfaces:
AutoCloseable
SparkFlex absolute encoder, attached through the data port.
-
Field Summary
FieldsModifier and TypeFieldDescriptionTheAbsoluteEncoderrepresenting the duty cycle encoder attached to the SparkFlex.Fields inherited from class swervelib.encoders.SwerveAbsoluteEncoder
maximumRetries, readingError -
Constructor Summary
ConstructorsConstructorDescriptionSparkFlexEncoderSwerve(SwerveMotor motor, int conversionFactor) Create theSparkFlexEncoderSwerveobject as a duty cycle from theSparkFlexmotor. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear sticky faults on the encoder.voidclose()voidconfigure(boolean inverted) Configure the absolute encoder to read from [0, 360) per second.voidReset the encoder to factory defaults.Get the instantiated absolute encoder Object.doubleGet the absolute position of the encoder.doubleGet the velocity in degrees/sec.booleansetAbsoluteEncoderOffset(double offset) Sets the Absolute Encoder Offset inside of the SparkFlex's Memory.voidsetConversionFactor(double conversionFactor) Set the conversion factor of theSparkFlexEncoderSwerve.
-
Field Details
-
encoder
TheAbsoluteEncoderrepresenting the duty cycle encoder attached to the SparkFlex.
-
-
Constructor Details
-
SparkFlexEncoderSwerve
Create theSparkFlexEncoderSwerveobject as a duty cycle from theSparkFlexmotor.- 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:
closein interfaceAutoCloseable- Specified by:
closein classSwerveAbsoluteEncoder
-
factoryDefault
public void factoryDefault()Reset the encoder to factory defaults.- Specified by:
factoryDefaultin classSwerveAbsoluteEncoder
-
clearStickyFaults
public void clearStickyFaults()Clear sticky faults on the encoder.- Specified by:
clearStickyFaultsin classSwerveAbsoluteEncoder
-
configure
public void configure(boolean inverted) Configure the absolute encoder to read from [0, 360) per second.- Specified by:
configurein classSwerveAbsoluteEncoder- Parameters:
inverted- Whether the encoder is inverted.
-
setConversionFactor
public void setConversionFactor(double conversionFactor) Set the conversion factor of theSparkFlexEncoderSwerve.- Parameters:
conversionFactor- Position conversion factor from ticks to unit.
-
getAbsolutePosition
public double getAbsolutePosition()Get the absolute position of the encoder.- Specified by:
getAbsolutePositionin classSwerveAbsoluteEncoder- Returns:
- Absolute position in degrees from [0, 360).
-
getAbsoluteEncoder
Get the instantiated absolute encoder Object.- Specified by:
getAbsoluteEncoderin classSwerveAbsoluteEncoder- Returns:
- Absolute encoder object.
-
setAbsoluteEncoderOffset
public boolean setAbsoluteEncoderOffset(double offset) Sets the Absolute Encoder Offset inside of the SparkFlex's Memory.- Specified by:
setAbsoluteEncoderOffsetin classSwerveAbsoluteEncoder- 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:
getVelocityin classSwerveAbsoluteEncoder- Returns:
- velocity in degrees/sec.
-