Package swervelib.encoders
Class PWMDutyCycleEncoderSwerve
java.lang.Object
swervelib.encoders.SwerveAbsoluteEncoder
swervelib.encoders.PWMDutyCycleEncoderSwerve
DutyCycle encoders such as "US Digital MA3 with PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag
Encoder." attached via a PWM lane.
Credits to p2reneker25 for building this.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final edu.wpi.first.wpilibj.DutyCycleEncoder
Duty Cycle Encoder.private Alert
AnAlert
for if the encoder cannot report accurate velocities.private boolean
Inversion state.Fields inherited from class swervelib.encoders.SwerveAbsoluteEncoder
maximumRetries, readingError
-
Constructor Summary
ConstructorDescriptionPWMDutyCycleEncoderSwerve
(int pin) Constructor for the PWM duty cycle encoder. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear sticky faults on the encoder.void
configure
(boolean inverted) Configure the inversion state of the encoder.void
Reset the encoder to factory defaults.Get the encoder object.double
Get the absolute position of the encoder.double
Get the velocity in degrees/sec.boolean
setAbsoluteEncoderOffset
(double offset) Sets the offset of the Encoder in the WPILib Encoder Library.
-
Field Details
-
encoder
private final edu.wpi.first.wpilibj.DutyCycleEncoder encoderDuty Cycle Encoder. -
isInverted
private boolean isInvertedInversion state. -
inaccurateVelocities
AnAlert
for if the encoder cannot report accurate velocities.
-
-
Constructor Details
-
PWMDutyCycleEncoderSwerve
public PWMDutyCycleEncoderSwerve(int pin) Constructor for the PWM duty cycle encoder.- Parameters:
pin
- PWM lane for the encoder.
-
-
Method Details
-
configure
public void configure(boolean inverted) Configure the inversion state of the encoder.- Specified by:
configure
in classSwerveAbsoluteEncoder
- Parameters:
inverted
- Whether the encoder is inverted.
-
getAbsolutePosition
public double getAbsolutePosition()Get the absolute position of the encoder.- Specified by:
getAbsolutePosition
in classSwerveAbsoluteEncoder
- Returns:
- Absolute position in degrees from [0, 360).
-
getAbsoluteEncoder
Get the encoder object.- Specified by:
getAbsoluteEncoder
in classSwerveAbsoluteEncoder
- Returns:
DutyCycleEncoder
from the class.
-
getVelocity
public double getVelocity()Get the velocity in degrees/sec.- Specified by:
getVelocity
in classSwerveAbsoluteEncoder
- Returns:
- velocity in degrees/sec.
-
factoryDefault
public void factoryDefault()Reset the encoder to factory defaults.- Specified by:
factoryDefault
in classSwerveAbsoluteEncoder
-
clearStickyFaults
public void clearStickyFaults()Clear sticky faults on the encoder.- Specified by:
clearStickyFaults
in classSwerveAbsoluteEncoder
-
setAbsoluteEncoderOffset
public boolean setAbsoluteEncoderOffset(double offset) Sets the offset of the Encoder in the WPILib Encoder Library.- Specified by:
setAbsoluteEncoderOffset
in classSwerveAbsoluteEncoder
- Parameters:
offset
- the offset the Absolute Encoder uses as the zero point.- Returns:
- Always true due to no external device commands.
-