Home / Offseason / Week O5
Offseason · Week 5 of 8

PID Control

P, I, D terms, WPILib PIDController, feedforward, and tuning basics.

What is PID?

PID is a control algorithm that continuously adjusts an output (like motor speed) to reach and maintain a target (like a specific angle or RPM). Without it, motors overshoot, oscillate, or never reach their target accurately.

P — Proportional
React to current error
Output = kP × error. Bigger error = bigger correction. Too high → oscillation. Too low → slow.
I — Integral
React to accumulated error
Fixes steady-state error. Rarely needed in FRC. Start with 0 and only add if the mechanism never quite reaches target.
D — Derivative
React to rate of change
Dampens oscillation. Output = kD × (error change rate). Like a shock absorber. Add after P to smooth out oscillation.
Feedforward
Predict what's needed
kS (static friction), kV (velocity), kA (acceleration). Reduces the work PID has to do by predicting the right output.
java — WPILib PIDController
import edu.wpi.first.math.controller.PIDController;

PIDController pid = new PIDController(0.1, 0.0, 0.01); // kP, kI, kD
pid.setSetpoint(4000.0); // target RPM
pid.setTolerance(50.0);  // ±50 RPM counts as "at target"

// In execute() — call every 20ms with current measurement
double currentRPM = encoder.getVelocity();
double output = pid.calculate(currentRPM);
motor.set(output);

if (pid.atSetpoint()) {
    System.out.println("At target!");
}

Tuning Process

StepWhat to doWhat to look for
1. Start with P onlySet kI=0, kD=0. Increase kP until it movesReaches target but oscillates
2. Add DIncrease kD slowlyOscillation dampens without slowing response
3. Add I if neededOnly if it never quite reaches setpointSteady-state error eliminated
4. Add FeedforwardkS for static friction, kV for velocityFaster response, less PID correction needed

Knowledge Check