Class Encoder
java.lang.Object
org.firstinspires.ftc.teamcode.subsystems.roadrunner.util.Encoder
Wraps a motor instance to provide corrected velocity counts and allow reversing independently of the corresponding
slot's motor direction
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
Uses velocity estimates gathered ingetCurrentPosition()
to estimate the upper bits of velocity that are lost in overflow due to velocity being transmitted as 16 bits.int
Gets the position from the underlying motor and adjusts for the set direction.double
Gets the velocity directly from the underlying motor and compensates for the direction SeegetCorrectedVelocity()
for high (>2^15) counts per second velocities (such as on REV Through Bore)void
setDirection
(Encoder.Direction direction) Allows you to set the direction of the counts and velocity without modifying the motor's direction state
-
Constructor Details
-
Encoder
public Encoder(com.qualcomm.robotcore.hardware.DcMotorEx motor, com.acmerobotics.roadrunner.util.NanoClock clock) -
Encoder
public Encoder(com.qualcomm.robotcore.hardware.DcMotorEx motor)
-
-
Method Details
-
getDirection
-
setDirection
Allows you to set the direction of the counts and velocity without modifying the motor's direction state- Parameters:
direction
- either reverse or forward depending on if encoder counts should be negated
-
getCurrentPosition
public int getCurrentPosition()Gets the position from the underlying motor and adjusts for the set direction. Additionally, this method updates the velocity estimates used for compensated velocity- Returns:
- encoder position
-
getRawVelocity
public double getRawVelocity()Gets the velocity directly from the underlying motor and compensates for the direction SeegetCorrectedVelocity()
for high (>2^15) counts per second velocities (such as on REV Through Bore)- Returns:
- raw velocity
-
getCorrectedVelocity
public double getCorrectedVelocity()Uses velocity estimates gathered ingetCurrentPosition()
to estimate the upper bits of velocity that are lost in overflow due to velocity being transmitted as 16 bits. CAVEAT: must regularly callgetCurrentPosition()
for the compensation to work correctly.- Returns:
- corrected velocity
-