java.lang.Object
org.firstinspires.ftc.teamcode.subsystems.roadrunner.util.Encoder

public class Encoder extends Object
Wraps a motor instance to provide corrected velocity counts and allow reversing independently of the corresponding slot's motor direction
  • 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

      public Encoder.Direction getDirection()
    • setDirection

      public void setDirection(Encoder.Direction direction)
      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 See getCorrectedVelocity() 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 in getCurrentPosition() to estimate the upper bits of velocity that are lost in overflow due to velocity being transmitted as 16 bits. CAVEAT: must regularly call getCurrentPosition() for the compensation to work correctly.
      Returns:
      corrected velocity