Pedro Pathing 2.0.0 has released! If you haven't already, migrate now.
Pedro Pathing LogoPedro Pathing
Tuning/Drive Algorithm/Predictive

Tuning Predictive Braking

PIDFs vs. Predictive Braking

You may either use PIDFs or Predictive Braking to control your robot.
However, swerve is currently not compatible with Predictive Braking. All further steps are for Predictive Braking users only.

Prerequisites

  • Mecanum wheels (support for swerve and tank coming soon)
  • Accurate Localization (drive encoders alone are insufficient due to wheel slip)
  • Works best with robots with a balanced center of mass and robots that do not lift off the ground or turn dramatically when braking. Do not worry if your robot does these things. This algorithm will still work. Just consider adding more weight to your robot.

Tuning

  1. Run the Tuning.java OpMode -> Automatic -> PredictiveBrakingTuner. This will give you values for kQuadratic and kLinear. In FollowerConstants, add .predictiveBrakingCoefficients(new PredictiveBrakingCoefficients(kP, kLinear, kQuadratic)). Insert the values given from the tuner into the method. Use a starting kP value around 0.1.
  • kQuadratic represents the braking distance proportional to velocity squared. This is caused by constant forces such as sliding friction.
  • kLinear represents braking distance roughly proportional to velocity. This is caused by velocity-proportional forces such as back-EMF voltage and viscous friction.
  1. Run LineTest and adjust kP to your liking. kP usually ranges from 0.05-0.3. kP changes are harder to notice and have minimal effects due to kP accounting for predicted error. However, tune kP as high as possible to maximize holding strength and accuracy, without jittering the robot. If you want smoother or sooner deceleration, try experimenting with kP of 0.05 or lower and increasing the kQuadratic term, as this will act more like a motion profile.
  2. Currently, it is recommended to turn off centripetal forces in auto, as predictive braking naturally accounts for this. This can be done by adding the following in FollowerConstants.
Constants.java
.centripetalScaling(0)
  1. Lower the parametric end constraint. Set it to a value like 0.97 or 0.95. PIDFs often overshoot and hit the parametric end early, but predictive braking fully stops in time, delaying when actions can trigger. Lowering the constraint lets actions trigger sooner and speeds up overall execution.

At the end of tuning, you should have at least this in FollowerConstants.

Constants.java
 public static FollowerConstants followerConstants = new FollowerConstants()
     .headingPIDFCoefficients(new PIDFCoefficients(1.5, 0, 0.1, 0)) // tuned constants
     .predictiveBrakingCoefficients(new PredictiveBrakingCoefficients(0.1, 0.04, 0.0016)) // (kP, kLinear, kQuadratic)
     .centripetalScaling(0)

After tuning, the LineTest should look like this video

Effective Predictive Braking with Pathing

If you run a previously constructed autonomous, you will see that predictive braking effectively eliminates overshoot, but it may slow down your auto if you do not continue pathchains. This is because predictive braking comes to a complete stop when using individual paths. If you instead use pathchains wherever you do not need to fully stop, the robot will maintain its momentum. Future updates will allow smooth handling of sharp angles without stopping by predicting the next path automatically.

Last updated on