Class TiltState

java.lang.Object
frc.robot.subsystems.swerve.TiltState

public final class TiltState extends Object
What the Pigeon says about the robot's attitude and knocks, derived from logged inputs so it replays. Used by odometry (tilt scaling), vision gating (sources that assume a level robot), and available to shot gating (Swerve.isTilted(), Swerve.wasBumpedRecently()).
  • Tilt: the angle between the robot's up axis and vertical, from pitch and roll.
  • Impact: how far the total measured acceleration is from 1 g. Standing, driving smoothly or tilted it stays near 0 (gravity is 1 g in any orientation); a collision, a bump or landing off one shows as a spike, whatever the direction.
  • Odometry scale (6328's addOdometryObservation, issue #10 section 8g): 1 while level, falling linearly to 0 between TILT_DEADBAND_DEG and TILT_ZERO_DEG. On a bump the wheels slip, lift or roll up a slope, so their travel overstates the robot's motion across the floor.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Impact (g) above which the robot counts as bumped.
    static final double
    How long (seconds) a bump keeps counting as recent.
    static final double
    Below this tilt (degrees) the floor and the IMU's own noise; odometry is not scaled.
    static final double
    At this tilt (degrees) and beyond, wheel travel is not counted at all (6328: 25 deg).
    static final double
    Tilt (degrees) above which the robot counts as tilted, for gating.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    bumpedRecently(double nowSeconds)
    Whether an impact above BUMP_G happened in the last BUMP_HOLD_SECONDS.
    double
     
    double
     
    static double
    odometryScale(double tiltDeg)
    The odometry scale for a tilt: 1 level, 0 at TILT_ZERO_DEG and beyond.
    double
     
    static double
    tiltDegrees(double pitchDeg, double rollDeg)
    The angle between the robot's up axis and vertical, degrees.
    boolean
     
    double
     
    void
    update(double nowSeconds, double pitchDeg, double rollDeg, double pitchRateDegPerSec, double rollRateDegPerSec, double accelXG, double accelYG, double accelZG)
    Updates from this loop's inputs.

    Methods inherited from class Object

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

    • TILT_DEADBAND_DEG

      public static final double TILT_DEADBAND_DEG
      Below this tilt (degrees) the floor and the IMU's own noise; odometry is not scaled.
      See Also:
    • TILT_ZERO_DEG

      public static final double TILT_ZERO_DEG
      At this tilt (degrees) and beyond, wheel travel is not counted at all (6328: 25 deg).
      See Also:
    • TILTED_DEG

      public static final double TILTED_DEG
      Tilt (degrees) above which the robot counts as tilted, for gating.
      See Also:
    • BUMP_G

      public static final double BUMP_G
      Impact (g) above which the robot counts as bumped.
      See Also:
    • BUMP_HOLD_SECONDS

      public static final double BUMP_HOLD_SECONDS
      How long (seconds) a bump keeps counting as recent.
      See Also:
  • Constructor Details

    • TiltState

      public TiltState()
  • Method Details

    • update

      public void update(double nowSeconds, double pitchDeg, double rollDeg, double pitchRateDegPerSec, double rollRateDegPerSec, double accelXG, double accelYG, double accelZG)
      Updates from this loop's inputs.
      Parameters:
      nowSeconds - robot time
      pitchDeg - Pigeon pitch
      rollDeg - Pigeon roll
      pitchRateDegPerSec - Pigeon pitch rate
      rollRateDegPerSec - Pigeon roll rate
      accelXG - acceleration along the Pigeon's x, g
      accelYG - acceleration along y, g
      accelZG - acceleration along z, g
    • tiltDegrees

      public static double tiltDegrees(double pitchDeg, double rollDeg)
      The angle between the robot's up axis and vertical, degrees.
    • odometryScale

      public static double odometryScale(double tiltDeg)
      The odometry scale for a tilt: 1 level, 0 at TILT_ZERO_DEG and beyond.
    • tiltDeg

      public double tiltDeg()
    • tiltRateDegPerSec

      public double tiltRateDegPerSec()
    • impactG

      public double impactG()
    • tilted

      public boolean tilted()
    • bumpedRecently

      public boolean bumpedRecently(double nowSeconds)
      Whether an impact above BUMP_G happened in the last BUMP_HOLD_SECONDS.
    • odometryScale

      public double odometryScale()