Class AntiTipping
java.lang.Object
org.wpilib.math.controller.AntiTipping
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
- Instantiate with initial configuration parameters.
- Call
calculate(Rotation3d)periodically (e.g. once per control loop). - 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 iskp * sin(θ), sokpcontrols 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 Summary
ConstructorsConstructorDescriptionAntiTipping(double kp, double tippingThreshold, double maxCorrectionSpeed) Creates a newAntiTippinginstance. -
Method Summary
Modifier and TypeMethodDescriptioncalculate(Rotation3d attitude) Updates tipping detection and computes the proportional correction.doubleGets the maximum correction velocity.doublegetP()Gets the Proportional coefficient.doubleGets the tipping detection threshold.voidsetMaxCorrectionSpeed(double speed) Sets the maximum correction velocity.voidsetP(double kp) Sets the Proportional coefficient.voidsetTippingThreshold(double threshold) Sets the tipping detection threshold.
-
Constructor Details
-
AntiTipping
public AntiTipping(double kp, double tippingThreshold, double maxCorrectionSpeed) Creates a newAntiTippinginstance.- 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
Updates tipping detection and computes the proportional correction.- Parameters:
attitude- Current robot attitude as aRotation3d.- Returns:
- Correction
ChassisVelocitiesto counteract tipping. Returns zeros if below threshold.
-