Random guessing wastes time and breaks mechanisms. Use a structured process and live telemetry.
Set up to see what you are doing#
Before touching gains, plot the setpoint and the measurement together on AdvantageScope, Glass, or Shuffleboard. You cannot tune what you cannot see. Make the gains editable live (e.g., via a tunable number) so you can adjust without redeploying.
A safe starting procedure#
Start with all gains at zero, then:
- Tune kP first. Raise kP until the mechanism reaches the setpoint reasonably quickly. Keep increasing until you see sustained oscillation, then back off to roughly half that value.
- Add kD. Increase kD to damp the overshoot and oscillation from kP. kD makes the approach smoother but too much causes jitter (it amplifies sensor noise) or sluggishness.
- Add kI last, sparingly. Only if a persistent steady-state error remains that kP/feedforward cannot remove. Use a small value and consider
setIZone()so integral only acts when you are already close. For most velocity/position control, a good feedforward removes the need for kI entirely.
What good tuning looks like#
You want a fast rise to the setpoint, little or no overshoot, and a quick, stable settle. A small overshoot that settles fast is usually better than a slow, creeping approach.
Practical cautions#
- Tune under realistic load. A flywheel with no game piece behaves differently than one shooting; an elevator behaves differently with and without an arm extended.
- Mind units. If your error is in meters but you expected encoder ticks, your kP will be wildly off. Always convert sensor output to real units first.
- Re-tune after mechanical changes. New gear ratios, belts, or weight change the dynamics.
- Combine with feedforward. PID is best at correcting error, not predicting motion. The next lesson shows how feedforward does the heavy lifting so PID only handles the leftover error.
Keep notes of the gains that work — and the units they assume — in your code or build log so they survive the season.
the part worth keeping
Key takeaways
- Always plot setpoint vs. measurement and make gains live-editable before tuning.
- Tune kP first (to half the oscillation point), then kD to damp, then kI sparingly only for steady-state error.
- Tune under realistic load and correct units; re-tune after any mechanical change.
Programming, Controls & SensorsClosed-Loop Control: PID, Feedforward, and SysIdlesson 2 of 4
Keep going
Take the quiz+10 XP with an accountMore in Closed-Loop Control: PID, Feedforward, and SysId
where this came from
Sources and corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgWPILib: Tuning a Flywheel Velocity Controller
- docs.wpilib.orgWPILib: Introduction to PID
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 8 min readHow to Tune PID on an FRC Robot: A Practical GuideA hands-on guide to tuning PID and feedforward on FRC mechanisms: a safe tuning order, fixing oscillation and steady-state error, and using WPILib SysId./blogread it
- 4 min readPID Control in FRC, Explained SimplyA beginner-friendly guide to PID control in FRC: what kP, kI, and kD actually do, how to tune them, and why most teams skip the I term./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01When tuning a PID controller methodically, which gain should you tune first, and how?
02What is the primary purpose of increasing the derivative gain (kD) during tuning?
03Why is integral gain (kI) generally used only sparingly on most FRC mechanisms?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensorsopenclose
01 / prerequisites
02 / foundations-tools-and-first-program
03 / robot-program-and-command-based
04 / motors-and-control
05 / autonomous-trajectories-simulation
06 / sensing-fundamentals
07 / encoders
08 / gyros-imus-orientation
09 / closed-loop-control
10 / vision-pose-estimation
11 / worked-examples-mini-projects
- Not read yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not read yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not read yet:Mini-Project: A Teleop Swerve Drive Subsystem
- Not read yet:Mini-Project: An Autonomous Routine with PathPlanner
- Not read yet:Mini-Project: Vision-Aligned Scoring with Limelight
12 / common-mistakes-troubleshooting
13 / advanced-techniques-case-studies
- Not read yet:State-Space Control and Kalman Filtering
- Not read yet:Log Replay Architecture with AdvantageKit
- Not read yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not read yet:Robot Coordination, Alerts, and Operator Feedback
- Not read yet:Case Study: Hardening Software Before an Event