Package swervelib.encoders
Class CANCoderSwerve
java.lang.Object
swervelib.encoders.SwerveAbsoluteEncoder
swervelib.encoders.CANCoderSwerve
Swerve Absolute Encoder for CTRE CANCoders.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AlertAnAlertfor if the absolute encoder offset cannot be set.com.ctre.phoenix6.hardware.CANcoderCANCoder with WPILib sendable and support.private AlertAnAlertfor if the CANCoder magnet field is less than ideal.private AlertAnAlertfor if the CANCoder reading is faulty.private AlertAnAlertfor if the CANCoder reading is faulty and the reading is ignored.static doubleWait time for status frames to show up.Fields inherited from class swervelib.encoders.SwerveAbsoluteEncoder
maximumRetries, readingError -
Constructor Summary
ConstructorsConstructorDescriptionCANCoderSwerve(int id) Initialize the CANCoder on the standard CANBus.CANCoderSwerve(int id, String canbus) Initialize the CANCoder on the CANivore. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear sticky faults on the encoder.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 within the CANcoder's Memory.
-
Field Details
-
STATUS_TIMEOUT_SECONDS
public static double STATUS_TIMEOUT_SECONDSWait time for status frames to show up. -
encoder
public com.ctre.phoenix6.hardware.CANcoder encoderCANCoder with WPILib sendable and support. -
magnetFieldLessThanIdeal
AnAlertfor if the CANCoder magnet field is less than ideal. -
readingFaulty
AnAlertfor if the CANCoder reading is faulty. -
readingIgnored
AnAlertfor if the CANCoder reading is faulty and the reading is ignored. -
cannotSetOffset
AnAlertfor if the absolute encoder offset cannot be set.
-
-
Constructor Details
-
CANCoderSwerve
public CANCoderSwerve(int id) Initialize the CANCoder on the standard CANBus.- Parameters:
id- CAN ID.
-
CANCoderSwerve
Initialize the CANCoder on the CANivore.- Parameters:
id- CAN ID.canbus- CAN bus to initialize it on.
-
-
Method Details
-
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.
-
getAbsolutePosition
public double getAbsolutePosition()Get the absolute position of the encoder. SetsSwerveAbsoluteEncoder.readingErroron erroneous readings.- 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 within the CANcoder's Memory.- Specified by:
setAbsoluteEncoderOffsetin classSwerveAbsoluteEncoder- Parameters:
offset- the offset the Absolute Encoder uses as the zero point in degrees.- 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.
-