AntiTipping

class wpimath.AntiTipping(kp: wpimath.units.meters_per_second_per_radian, tipping_threshold: wpimath.units.radians, max_correction_speed: wpimath.units.meters_per_second)

Bases: pybind11_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.

<h2>Usage</h2>

<ol> - Instantiate with initial configuration parameters. - Call Calculate() periodically (e.g. once per control loop). - Add the resulting correction to your drive command. </ol>

<h2>Tuning</h2>

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.

Creates a new AntiTipping instance.

Parameters:
  • kp – The proportional coefficient in meters per second per radian. The P controller input is the sine of the inclination angle, and the output is in meters per second.

  • tipping_threshold – Tipping detection threshold.

  • max_correction_speed – Maximum correction velocity.

calculate(attitude: wpimath._wpimath.Rotation3d) wpimath._wpimath.ChassisVelocities

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.

get_max_correction_speed() wpimath.units.meters_per_second

Gets the maximum correction velocity.

Returns:

The maximum correction speed.

get_p() wpimath.units.meters_per_second_per_radian

Gets the proportional coefficient.

Returns:

The proportional coefficient in meters per second per radian.

get_tipping_threshold() wpimath.units.radians

Gets the tipping detection threshold.

Returns:

The tipping threshold.

set_max_correction_speed(speed: wpimath.units.meters_per_second) None

Sets the maximum correction velocity.

Parameters:

speed – The maximum correction speed.

set_p(kp: wpimath.units.meters_per_second_per_radian) None

Sets the proportional coefficient.

Parameters:

kp – The proportional coefficient in meters per second per radian.

set_tipping_threshold(threshold: wpimath.units.radians) None

Sets the tipping detection threshold.

Parameters:

threshold – The tipping threshold.