In open-loop control you command a motor a fixed output and hope it does the right thing. In closed-loop (feedback) control you measure the result with a sensor and continuously correct. PID is the most common feedback algorithm in FRC.
The PID idea
A PID controller computes an error = setpoint - measurement, then outputs a correction built from three terms:
- Proportional (kP): output proportional to current error. Bigger error, harder push. Too little kP is sluggish; too much causes overshoot and oscillation.
- Integral (kI): accumulates error over time to eliminate small, persistent steady-state error. Powerful but dangerous — it can 'wind up' and cause big overshoot. Many FRC mechanisms use little or no kI, preferring feedforward instead.
- Derivative (kD): responds to how fast the error is changing, damping oscillation and overshoot like a shock absorber.
Output = kPerror + kI(integral of error) + kD*(rate of change of error).
WPILib PIDController
PIDController pid = new PIDController(kP, kI, kD);
pid.setTolerance(0.5); // 'close enough' band
double out = pid.calculate(encoder.getDistance(), setpoint);
motor.setVoltage(out);
if (pid.atSetpoint()) { /* done */ }
Call calculate() every loop (the default TimedRobot loop is 20 ms, i.e. 50 Hz). Key features:
enableContinuousInput(-180, 180)for angular mechanisms (turrets, swerve steering) so the controller takes the shortest path around the circle instead of unwinding the long way.setTolerance()+atSetpoint()to know when you have arrived.setIZone()/setIntegratorRange()to tame integral windup.
A note on where PID runs
You can run PID in robot code (PIDController) or on the motor controller (Talon FX and Spark MAX both have onboard closed-loop control). On-controller PID runs at a much higher rate than your 50 Hz robot loop (on the order of 1 kHz), which is excellent for velocity and position control. The tuning concepts are the same either way.
Key takeaways
- Closed-loop control measures the result and corrects continuously; PID is the standard algorithm.
- kP drives toward the setpoint, kD damps oscillation, and kI removes steady-state error but can wind up.
- Use enableContinuousInput for angles, atSetpoint to detect arrival, and consider on-controller PID for high-rate loops.
Keep going
Take the quiz · +10 XP with an accountMore in Closed-Loop Control: PID, Feedforward, and SysId
Sources & 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 — publicly, in the corrections log.
Sources and further reading
Read next
Articles on this, for competition day
The lesson covers how it works. These cover what to do when it breaks.
- 4 min read
PID Control in FRC, Explained Simply
A 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.
Read - 8 min read
How to Tune PID on an FRC Robot: A Practical Guide
A 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.
Read - 7 min read
FRC "Loop Time of 0.02s Overrun" & Watchdog Not Fed: Causes and Fixes
What "Loop time of 0.02s overrun" and watchdog-not-fed warnings actually mean in FRC, how to read WPILib's epoch dump, and the usual causes.
Read
Lesson quiz
RequiredAll 3 right completes the lesson. Miss one and only that question comes back — anything you already answered correctly stays banked.
0 of 3 answered
01.What is the fundamental difference between open-loop and closed-loop control?
02.In a PID controller, how is the error defined?
03.Which statement correctly describes what each PID term responds to?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensors
- Not started:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not started:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not started:Mini-Project: A Teleop Swerve Drive Subsystem
- Not started:Mini-Project: An Autonomous Routine with PathPlanner
- Not started:Mini-Project: Vision-Aligned Scoring with Limelight
- Not started:State-Space Control and Kalman Filtering
- Not started:Log Replay Architecture with AdvantageKit
- Not started:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not started:Robot Coordination, Alerts, and Operator Feedback
- Not started:Case Study: Hardening Software Before an Event