Cruise Control: The Secret Math of Driving (PID Loops)

How does your car maintain exactly 65mph uphill? It uses a PID Loop. This is the single most important algorithm in robotics.

Cruise Control: The Secret Math of Driving (PID Loops)

You are driving on the highway. You set Cruise Control to 65 mph. You hit a steep hill. Gravity pulls the car back. Does the car slow down to 60mph? No. The engine roars, the RPMs go up, and the speedometer stays glued to 65. How? The car is using a Closed Loop Controller, specifically a PID Loop.

The Feedback Loop

Without feedback (Open Loop), you would just press the gas pedal down 50%.

  • Flat Road: 65 mph.
  • Uphill: 50 mph (Too slow).
  • Downhill: 80 mph (Speeding ticket).

With feedback (Closed Loop):

  1. Sensor: Measures Speed (Current = 60).
  2. Target: Setpoint = 65.
  3. Error: $$Error = Target - Current$$ (65 - 60 = 5).
  4. Action: The computer sees a positive error +5. It commands the engine to throttle up.

The Three Terms: P, I, D

But simply saying “Speed up” isn’t enough. How much do you speed up?

1. Proportional (P) - The “Now”

“The bigger the error, the harder I push.”

  • Error is 5mph? Push gas a little.
  • Error is 20mph? Floor it.
  • Problem: As you get close (Error = 0.1), you let off the gas. Friction slows you down. You never actually reach 65. You get stuck at 64. (This is Steady State Error).

2. Integral (I) - The “Past”

“I’ve been at 64mph for 10 seconds. I’m failing.”

  • The Integral sums up the error over time.
  • Even a tiny error, if it lasts too long, builds up a huge “I” capability.
  • This extra push nudges the car from 64 to exactly 65.

3. Derivative (D) - The “Future”

“Whoa! We are accelerating toward 65 really fast!”

  • The D term looks at the rate of change.
  • It predicts: “At this rate, we will overshoot to 70.”
  • It acts as a Brake. It dampens the system to prevent oscillation.

Robotics: The Omni-Tool

We use PID for everything.

  • Driving: Drive exactly 10 feet.
  • Arm: Hold the arm at 45 degrees against gravity.
  • Shooter: Spin the flywheel at exactly 2000 RPM. If you master PID, you master control. Without it, robots are just clumsy remote control cars.

Explore FIRST® Robotics

FIRST® (For Inspiration and Recognition of Science and Technology) is a global robotics community preparing young people for the future. Discover the ultimate sport for the mind and see how you can get involved in STEM and robotics!

Learn More at firstinspires.org