How do you Tune the PID Values?

Hi I am on a second year frc team from New York. We have been trying to program an autonomous program in java using motor encoders and a PID controller to move forward a specific distance. However, in order to uses the PID controller we need the proportionality, integral, and differential constants, and we do not know how to find them. We tried using the smart dashboard but nothing shows up in the window to edit. If someone could give us some help it would be greatly appreciated. Thanks!

We are using Command based Java code and we are having trouble getting a PIDSubsystem to show up in the SmartDashboard LiveWindow when we put the robot in Test mode.

This link shows the PIDSubsystem showing up in LiveWindow and allowing you to edit all the PID controller values but we don’t seem to be able to get this to work.

For the original poster, when we put the robot into teleop mode and made the SmartDashboard editable we were able to right-click the PIDSubsystem and select PID editor. This looked like it would allow you to edit the PID constants at least. This was after using SmartDashboard.putData() to send the PIDSubsystem to the SmartDashboard.

I was able to get the PID controller in livewindow using this line in the OI:

LiveWindow.addActuator("drivetrain", "Drivetrain", Robot.drivetrain.getPIDController());

EDIT: This is for test mode, I don’t know about getting it in teleop.

For teleop, just do this:

SmartDashboard.putData("PID Controller",controller);

controller can be replaced by subsystem.getPIDController().

Also, in terms of actual tuning techniques, here’s the procedure I use:

  • Raise the P constant until your controller oscillates. If the oscillations are too big, lower the constant a little bit.
  • Raise the D constant to damp the oscillation, causing it to converge. D also slows down the controller’s approach to the setpoint, so striking a balance between P and D can take some tweaking.
  • If you have P and D tuned, and it oscillates & converges, but not to the correct setpoint, increase I. This is called “steady-state error” and a positive, non-zero integral constant will cause the controller to correct for it.

In general, P makes approach faster, but can cause larger oscillations; D causes oscillations to converge, but slows approach; and I can correct for steady-state error and causes faster approach, but can lead to intense oscillations if set too high (search “integral windup” for more details).

1 Like