What is PID?
PID is a way to make a robot reach a target smoothly and stop right on it, instead of overshooting, stopping short or wobbling. It's one of the most useful ideas in all of engineering, and it's the reason good VEX autons look so smooth.
Why does PID exist?
Telling a motor "full power for 2 seconds" only works if nothing changes. But batteries drain, motors heat up, and robots get heavier when they carry game pieces. A robot that only follows a timer can't notice it's off. PID gives the robot a way to check and correct itself the whole time it moves. Engineers call this a feedback loop.
Where does the name come from?
PID stands for Proportional, Integral, Derivative, the three parts that each add a piece of the motor power. The names come from math, but the jobs are easy to picture:
The idea is about a hundred years old. One of the first people to write down the math was the engineer Nicolas Minorsky in 1922, while working on automatic steering for ships. A helmsman doesn't just turn the wheel by how far off course the ship is; they also think about how fast it's turning and whether it keeps drifting. That's P, D and I.
Who and what uses PID?
Why use it on a VEX robot?
- Accuracy: the robot stops on the target, not "about there."
- Consistency: it corrects for battery level, warm motors and extra weight, so the auton works match after match.
- Speed: tuned PID lets you drive fast and still stop cleanly, instead of crawling to be safe.
- Mechanisms too: lifts, arms and flywheels can hold a height or speed with PID.
What do you need to use PID?
- 📏A sensorSomething that measures where you are: motor encoders, a rotation sensor on a tracking wheel, or the inertial sensor for turns.
- 🎯A targetA distance, an angle, a lift height or a speed.
- ⚙️MotorsSomething PID can push harder or softer.
- 🔁A loopCode that repeats every 10 milliseconds or so. LemLib and JAR-Template already include this.
- 🎛️Three numberskP, kI and kD, which you tune for your robot.
What PID looks like in code
You usually don't write PID from scratch: LemLib and JAR-Template have it built in, and you just set the numbers. But here's the whole idea in a few lines, so it isn't magic:
while (not at target) {
error = target - position; // how far away am I?
integral = integral + error; // add up what's left over
derivative = error - lastError; // how fast am I closing in?
power = kP*error + kI*integral + kD*derivative;
motors.move(power);
lastError = error;
wait 10 ms;
}
How to start tuning (the safe way)
- Set kI and kD to 0. Start with a small kP.
- Raise kP until the robot reaches the target quickly and just starts to overshoot a little.
- Add kD a bit at a time until the overshoot and wobble go away.
- Only add a tiny kI if it always stops a little short.
- Change one number at a time, run it a few times, and write each change in your engineering notebook.
Learn it hands-on
autonomy.school's Tuning with PID mission (part of the odometry track) has a PID tuner lab where you slide kP and kD and watch a virtual robot react, then tune the real one with LemLib or JAR-Template.
Questions people ask
What does PID stand for?
Proportional, Integral, Derivative: the three parts that together decide how much power to give a motor based on how far it is from the target.
Do I need PID for a VEX robot?
For accurate, repeatable autonomous routines, yes. LemLib and JAR-Template include PID, so you mostly tune three numbers instead of writing it.
What should I tune first, P, I or D?
P first, with I and D at zero. Then add D to stop overshoot and wobble. Add a little I only if the robot always stops a bit short.
What sensor does PID need?
Anything that measures progress: motor encoders or a rotation sensor for distance, the inertial sensor for turning, or a rotation sensor on a lift for height.
Who invented PID?
PID grew out of early 1900s control engineering. Nicolas Minorsky published one of the first analyses in 1922 for automatic ship steering.
Try it free. The first autonomy.school missions run in your browser. No sign-up, nothing to install, and there's a virtual robot if yours is at school or the lab.
Start the free missions