Class SwerveEncoder<AbsoluteEncoderType>
- java.lang.Object
-
- frc.robot.subsystems.swervedrive.swerve.SwerveEncoder<AbsoluteEncoderType>
-
- Direct Known Subclasses:
CTRECANCoder,PWMAnalogEncoder,PWMDutyCycleEncoder,REVAbsoluteEncoder
public abstract class SwerveEncoder<AbsoluteEncoderType> extends java.lang.ObjectSwerve Encoder class definition for common interfaces.
-
-
Field Summary
Fields Modifier and Type Field Description AbsoluteEncoderTypem_encoderThe encoder can be directly referenced for configuration purposes of onboard PIDs.
-
Constructor Summary
Constructors Constructor Description SwerveEncoder()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidconfigure()Configure the absolute encoder if possible.abstract voidfactoryDefault()Reset encoder to factory default settings, if possible.static <AbsoluteEncoderType>
SwerveEncoder<?>fromEncoder(AbsoluteEncoderType encoder)Get the SwerveEncoder class from the given encoder typesabstract doublegetAbsolutePosition()Get the absolute position in degrees.abstract com.ctre.phoenix.sensors.MagnetFieldStrengthgetMagnetFieldStrength()Get the magnetic field strength, if available.abstract doublegetVelocity()Get the velocity of the absolute encoder in degrees per second.abstract booleanreachable()Is the encoder reachable?abstract voidsetInverted(boolean isInverted)Configure the sensor directionabstract voidsetOffset(double offset)Configure the magnetic offset for the AbsoluteEncoder.
-
-
-
Field Detail
-
m_encoder
public AbsoluteEncoderType m_encoder
The encoder can be directly referenced for configuration purposes of onboard PIDs.
-
-
Method Detail
-
fromEncoder
public static <AbsoluteEncoderType> SwerveEncoder<?> fromEncoder(AbsoluteEncoderType encoder)
Get the SwerveEncoder class from the given encoder types- Type Parameters:
AbsoluteEncoderType- One of DutyCycleEncoder, AnalogEncoder, AbsoluteEncoder, and CANCoder- Parameters:
encoder- Encoder- Returns:
- SwerveEncoder subclass
-
configure
public abstract void configure()
Configure the absolute encoder if possible.
-
factoryDefault
public abstract void factoryDefault()
Reset encoder to factory default settings, if possible.
-
getMagnetFieldStrength
public abstract com.ctre.phoenix.sensors.MagnetFieldStrength getMagnetFieldStrength()
Get the magnetic field strength, if available.- Returns:
- CTRE MagneticFieldStrength Enum.
-
getAbsolutePosition
public abstract double getAbsolutePosition()
Get the absolute position in degrees.- Returns:
- Absolute position (0, 360]
-
getVelocity
public abstract double getVelocity()
Get the velocity of the absolute encoder in degrees per second.- Returns:
- Velocity in degrees per second.
-
setOffset
public abstract void setOffset(double offset)
Configure the magnetic offset for the AbsoluteEncoder.- Parameters:
offset- Offset in degrees.
-
reachable
public abstract boolean reachable()
Is the encoder reachable?- Returns:
- True if reachable, false otherwise.
-
setInverted
public abstract void setInverted(boolean isInverted)
Configure the sensor direction- Parameters:
isInverted- Inverted or not.
-
-