Class EasyCRT

java.lang.Object
yams.core.units.EasyCRT

public class EasyCRT extends Object
Finds the absolute angle of a gear that turns more than once, from two absolute encoders on pinions with different tooth counts that both mesh with it.

Each encoder only knows its angle within one of its own rotations, but the two readings together are unique over getUniqueRange(), which is lcm(encoderATeeth, encoderBTeeth) / sharedGearTeeth rotations of the shared gear.

Both encoders must be zeroed with the mechanism at zero, and both must read increasing angles when the mechanism moves in its positive direction. Set the offset and inversion on the encoders themselves, or adjust the readings before passing them in.

This is not a textbook Chinese Remainder Theorem solve. Every angle consistent with encoder A is tried, and the one whose predicted encoder B reading is closest to the real one wins, which stays stable with backlash and sensor noise. Created by team 6911.

// 100 tooth turret gear, 19 tooth pinion on encoder A, 21 tooth pinion on encoder B.
EasyCRT crt = new EasyCRT(100, 19, 21);

// Read once at startup, while the mechanism is not moving.
Optional<Angle> turretAngle = crt.solve(encoderA.get(), encoderB.get());
  • Constructor Summary

    Constructors
    Constructor
    Description
    EasyCRT(int sharedGearTeeth, int encoderATeeth, int encoderBTeeth)
    Create a solver from the tooth counts of the three gears.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.wpilib.units.measure.Angle
    Get how far the shared gear can turn before the pair of encoder readings repeats.
    Optional<org.wpilib.units.measure.Angle>
    solve(org.wpilib.units.measure.Angle encoderA, org.wpilib.units.measure.Angle encoderB)
    Solve for the angle of the shared gear, assuming its travel is centered on zero.
    Optional<org.wpilib.units.measure.Angle>
    solve(org.wpilib.units.measure.Angle encoderA, org.wpilib.units.measure.Angle encoderB, org.wpilib.units.measure.Angle minAngle, org.wpilib.units.measure.Angle maxAngle)
    Solve for the angle of the shared gear when its travel is not centered on zero.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EasyCRT

      public EasyCRT(int sharedGearTeeth, int encoderATeeth, int encoderBTeeth)
      Create a solver from the tooth counts of the three gears.
      Parameters:
      sharedGearTeeth - Teeth on the gear both encoder pinions mesh with. The solved angle is the angle of this gear.
      encoderATeeth - Teeth on encoder A's pinion.
      encoderBTeeth - Teeth on encoder B's pinion.
      Throws:
      IllegalArgumentException - if any tooth count is zero or negative.
  • Method Details

    • solve

      public Optional<org.wpilib.units.measure.Angle> solve(org.wpilib.units.measure.Angle encoderA, org.wpilib.units.measure.Angle encoderB)
      Solve for the angle of the shared gear, assuming its travel is centered on zero. The result is within half of getUniqueRange() either side of zero.
      Parameters:
      encoderA - Encoder A reading.
      encoderB - Encoder B reading.
      Returns:
      The shared gear's angle, or empty if the two readings do not agree on one.
    • solve

      public Optional<org.wpilib.units.measure.Angle> solve(org.wpilib.units.measure.Angle encoderA, org.wpilib.units.measure.Angle encoderB, org.wpilib.units.measure.Angle minAngle, org.wpilib.units.measure.Angle maxAngle)
      Solve for the angle of the shared gear when its travel is not centered on zero.
      Parameters:
      encoderA - Encoder A reading.
      encoderB - Encoder B reading.
      minAngle - Lowest angle the shared gear can be at.
      maxAngle - Highest angle the shared gear can be at.
      Returns:
      The shared gear's angle, or empty if the two readings do not agree on one.
      Throws:
      IllegalArgumentException - if the travel is longer than getUniqueRange(), or maxAngle is below minAngle.
    • getUniqueRange

      public org.wpilib.units.measure.Angle getUniqueRange()
      Get how far the shared gear can turn before the pair of encoder readings repeats.
      Returns:
      The unique range of the shared gear.