← All writing

robotics · 2024-12-18

PID Controller Explained

P, I, D — what each term does, how to tune them, and where they show up.

PID (Proportional–Integral–Derivative) is a control algorithm that continuously calculates and adjusts its output to minimize the difference between a desired set point and the actual process value for stable and accurate control.

Example Use Case Of PID

Before we begin — key terms

Set point

The set point is a user-entered target value. For cruise control, it’s the desired vehicle speed. For a heating system, it’s the desired temperature.

Process value

The process value is the current value being controlled. In cruise control: the actual vehicle speed. In a heating system: the current temperature.

Error

The error is the difference between the set point and the process value. It determines how the controller should react to bring the process closer to the target.

Error = Set Point - Process Value

Let’s get dirty — the PID components

Proportional (P)

The Proportional term reacts immediately to the error value to reduce the gap between the process value and the set point.

P = Kp × Error

Example:
Kp = 20, Error = 100 → P = 20 × 100 = 2000

This causes the robot to overshoot and turn too hard. The proportional part applies a large correction when far from the target but doesn’t know when to stop.

Tuning:

Integral (I)

The Integral term continuously accumulates the error over time until the set point is reached. It helps eliminate steady-state error by adjusting output based on past performance.

I = Kᵢ × ∫ Error dt

It converts accumulated error into a usable correction that fine-tunes the system output.

Derivative (D)

The Derivative term predicts system behavior by measuring how quickly the error is changing — it acts as a brake to prevent overshooting.

D = Current Error - Last Error

Behavior:

Summary

Together, they form a balanced control system capable of precise, stable, and smooth adjustments.

Example use cases