Class AntiTipping

java.lang.Object
org.wpilib.math.controller.AntiTipping

public class AntiTipping extends Object
AntiTipping provides a proportional correction system to prevent the robot from tipping over during operation.

It uses pitch and roll measurements to detect excessive inclination and computes a correction velocity in the opposite direction of the tilt. The resulting correction can be added to the robot’s translational velocity to help stabilize it.

Usage

  1. Instantiate with initial configuration parameters.
  2. Call calculate(Rotation3d) periodically (e.g. once per control loop).
  3. Add the resulting correction to your drive command.

Tuning

All three parameters depend on the robot's center of gravity and drivetrain, so they are best found empirically:

  • tippingThreshold: Drive the robot normally, including hard acceleration, braking, and turning, and record the largest pitch/roll magnitude observed. Set the threshold a few degrees above that worst case so normal driving does not trigger a correction, but well below the angle at which the robot actually tips.
  • kp: The correction speed is kp * sin(θ), so kp controls how aggressively the robot drives out from under a tilt. Start small and increase until recovery is brisk without overshooting or oscillating.
  • maxCorrectionSpeed: Cap the correction at a fraction of the drivetrain's maximum speed so the anti-tip response stays controllable and never overpowers the driver.
  • Constructor Details

    • AntiTipping

      public AntiTipping(double kp, double tippingThreshold, double maxCorrectionSpeed)
      Creates a new AntiTipping instance.
      Parameters:
      kp - The proportional coefficient in meters per second. The P controller input is the sine of the inclination angle, and the output is in meters per second.
      tippingThreshold - Tipping detection threshold in radians.
      maxCorrectionSpeed - Maximum correction velocity in meters per second.
  • Method Details

    • setP

      public void setP(double kp)
      Sets the Proportional coefficient.
      Parameters:
      kp - The proportional coefficient in meters per second.
    • getP

      public double getP()
      Gets the Proportional coefficient.
      Returns:
      The proportional coefficient in meters per second.
    • setTippingThreshold

      public void setTippingThreshold(double threshold)
      Sets the tipping detection threshold.
      Parameters:
      threshold - The tipping threshold in radians.
    • getTippingThreshold

      public double getTippingThreshold()
      Gets the tipping detection threshold.
      Returns:
      The tipping threshold in radians.
    • setMaxCorrectionSpeed

      public void setMaxCorrectionSpeed(double speed)
      Sets the maximum correction velocity.
      Parameters:
      speed - The maximum correction speed in meters per second.
    • getMaxCorrectionSpeed

      public double getMaxCorrectionSpeed()
      Gets the maximum correction velocity.
      Returns:
      The maximum correction speed in meters per second.
    • calculate

      public ChassisVelocities calculate(Rotation3d attitude)
      Updates tipping detection and computes the proportional correction.
      Parameters:
      attitude - Current robot attitude as a Rotation3d.
      Returns:
      Correction ChassisVelocities to counteract tipping. Returns zeros if below threshold.