Gray Matter
WorkshopPID Tuning in Tuner X
WPILib 2027 is still in alpha: these pages change as the APIs settle.
LESSON 06

PID Tuning in Tuner X

The Talon FX runs the control loop itself. We can send it a setpoint from Tuner X, plot the response, and save the gains onto the motor.

13 minutes
You’ll need
  • Motor, encoder direction, and mechanism zero verified in Motor Setup & CAN IDs.
  • Tuner X connected to the CANivore, with CANivore USB on.
  • The mechanism, with a clear path to swing, and no obstacles.

What mechanism are you working on?

The lesson below is written for the one you pick. Switch back any time to read it for the other.

How to tune

CTRE has an excellent guide that explains how to tune a PID loop. We strongly suggest following it.

CTRE: Manual PID tuning

If that site is blocked, the steps on this page recreate the guide. CTRE tunes in torque current with FOC, and we rewrote it in volts. It is based on CTRE's dyno testing, so it should be fairly accurate.

Play with the gains

Drag a gain and watch what happens. Find out what too much kP looks like here, where it costs nothing, rather than on a real gearbox.

Choose mechanism
loading playground…

Units and sizes

Every gain is output per unit of input. Here the output is volts and the input is rotations. The numbers you tune can look nothing like a guide written for another unit.

Rotations are why an arm kP looks big. An error of 0.01 rotations is 3.6 degrees, so a kP of 20 answers it with only 0.2 V. A Kraken X44 needs about 0.093 V per rps of its own speed, so a flywheel kV in motor rotations lands near that.

Tune the gains

  1. Open Signal & Control and add the Talon FX you are tuning.
  2. Plot the target and the measured position, or velocity for a flywheel. Drag both into Group 1 under Enabled Signals so they share an axis, and set Timespan to about 0.25. It is in minutes, and the default of 10 squeezes a move into a sliver.
  3. On the Control tab, set Control Mode to PositionVoltageVelocityVoltage and select Slot 0. Enter a small target: 0.1 rotations for position, 10 rps for velocity. Changing Control Mode switches the device back to DISABLED, so enable it again.
Screenshot of the Tuner X plot with the Timespan box and Group 1, holding the target and measured position, circled.
Both signals in Group 1, with a short Timespan. The bottom axis is a timestamp in seconds; only the spacing matters.
Screenshot of the Control tab with the DISABLED button and the PositionVoltage control mode circled.
Control Mode on the Control tab. Click DISABLED to enable the device.

Run these steps on your actual mechanism. Press Apply, the arrow icon above the config list, after every gain change. A gain that was never applied never reaches the motor.

  1. Set every gain in Slot 0 to zero and press Apply. Set Gravity Type to Arm_Cosine.
  2. Feedforward first. Raise kG to find the smallest and the largest values that hold the arm level. Set kG to the midpoint and kS to half the gap between them.
  3. Feedforward first. At a low target, raise kS until the wheel just turns. At a high target, raise kV until the measured speed meets the target with kP still at zero.
  4. Raise kP, doubling it each run, until the mechanism overshoots or oscillates. Then back off to about half of that value.
  5. Add kD in small steps until the overshoot stops. If the arm starts to buzz, you have gone too far.
  6. Leave kI at zero. Fix a steady gap with feedforward or kP first, and you will rarely need it.
  7. Once short moves work, try longer ones. You may find the mechanism starts to overshoot. If it does, go back to the feedback steps above.
  8. Try other targets in both directions, then press Apply one last time.

Three failure shapes

Nearly everything that goes wrong on a mechanism looks like one of these. Read the plot, not the mechanism.

Runs away
Wrong direction
Error grows instead of shrinking and output pins. Disable now. The sensor or the motor is inverted, so go back to Motor Setup.
Buzzes
Too much gain
Voltage chatters and the mechanism hums at rest. Cut kP before reaching for kD. Damping will not fix a loop that is too stiff.
Falls short
Not enough output (position control)
Error settles at a constant gap. Increase your kP to correct this, likely followed by a kD to dampen the overshoot.

When the plot looks like none of these, check the setup before the gains.

  • The request and the gains must both be on Slot 0. Gains in another slot do nothing.
  • A gain from an amps or duty cycle guide is meaningless in a voltage request.
  • A tired battery cannot reach the voltage a fresh one can. Re-check your gains on a charged battery.
  • A current limit that clips the output looks like too little gain. Watch for current sitting flat at the limit.
  • A runaway means the sensor or motor direction changed since Motor Setup & CAN IDs. Fix it there.
  • Gains that were never applied are lost. Power cycle, reopen the config, and confirm the numbers are still there.

Check your work

Drive the mechanism to its target in both directions, from a standstill, three times. You are done when all three runs look alike.

Check

You should see

  • The measured trace meets the target and stays there.
  • Closed-loop error settles near zero and does not drift back out.
  • Voltage is steady at rest, not chattering.
  • The same gains behave across the full range of travel.

Check yourself

You set every gain to zero, send a position target, and enable. The arm does nothing. What is wrong?

Your arm holds its angle perfectly at 90 degrees and sags badly at 30. Which term is wrong?

What order do you tune an arm in?

The arm reaches its target and then buzzes, sitting still. What do you reach for first?

Pick an answer for each.