Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

PID control is a feedback method used in robotics to make motors, arms, drivetrains, and sensors reach a target value smoothly. This cheat sheet helps students connect the formulas to real robot behavior such as overshoot, steady-state error, and oscillation. It is useful when tuning autonomous robots, line followers, balancing robots, and mechanisms that need precise motion.

A PID controller compares a desired setpoint to a measured process value and calculates an error. The control output is the sum of proportional, integral, and derivative actions: u(t) = Kp e(t) + Ki ∫e(t)dt + Kd de(t)/dt. The proportional term reacts to current error, the integral term reacts to accumulated error, and the derivative term reacts to how fast error is changing.

Good tuning balances quick response, stability, and low steady-state error.

Key Facts

  • The error is e(t) = setpoint - measured value, so the sign of the error determines the direction of correction.
  • The full continuous PID formula is u(t) = Kp e(t) + Ki ∫e(t)dt + Kd de(t)/dt.
  • The proportional term is P = Kp e(t), and increasing Kp usually makes the robot respond faster but can increase overshoot.
  • The integral term is I = Ki ∫e(t)dt, and it helps remove steady-state error by adding correction based on accumulated error.
  • The derivative term is D = Kd de(t)/dt, and it helps reduce overshoot by reacting to rapid changes in error.
  • A common discrete PID update is u = Kp e + Ki sum(e)Δt + Kd (e - previous error)/Δt.
  • Integral windup occurs when sum(e) grows too large while the actuator is saturated, so many systems clamp or limit the integral term.
  • A stable PID loop needs a consistent sample time Δt because changing Δt changes the size of the integral and derivative terms.

Vocabulary

Setpoint
The target value the robot is trying to reach, such as a desired speed, angle, distance, or position.
Process value
The measured current value from a sensor, such as encoder position, gyro angle, or motor speed.
Error
The difference between the setpoint and the process value, calculated as error = setpoint - process value.
Control output
The command sent to an actuator, such as motor power or servo position, after the PID terms are combined.
Gain
A tuning constant such as Kp, Ki, or Kd that changes how strongly a PID term affects the output.
Overshoot
A response where the robot passes beyond the target value before settling back toward it.

Common Mistakes to Avoid

  • Using error = measured value - setpoint without checking motor direction is wrong because it can make the controller drive farther away from the target.
  • Raising Kp too much is wrong because a fast response can become oscillation if the robot keeps overcorrecting around the setpoint.
  • Ignoring Δt in the integral and derivative terms is wrong because the controller output changes when the loop runs faster or slower.
  • Letting the integral term grow without limits is wrong because integral windup can cause a large delayed correction even after the robot reaches the target.
  • Adding derivative control to noisy sensor data without filtering is wrong because the derivative term can amplify sudden measurement jumps.

Practice Questions

  1. 1 A robot arm has a setpoint of 90 degrees and a measured angle of 74 degrees. What is the error if error = setpoint - measured value?
  2. 2 A motor speed controller has Kp = 0.4 and error = 25 rpm. What is the proportional output P?
  3. 3 A discrete controller has e = 8, previous error = 5, and Δt = 0.1 s. What is the derivative estimate (e - previous error)/Δt?
  4. 4 A robot reaches the target but keeps oscillating around it. Which PID terms might you adjust, and why?

Understanding PID Control Reference

A controller runs as a repeated cycle in robot code. It reads a sensor, calculates a motor command, sends that command, then waits for the next sample. This happens many times each second.

The sensor may be an encoder on a wheel, a gyroscope angle, an arm potentiometer, or a distance sensor. The command may be motor power, voltage, or a requested speed. The physical mechanism cannot respond instantly.

Motors have inertia, friction, battery limits, gear reduction, and load changes. PID values must work with these real limits, not with an ideal model.

The three terms have different jobs during a movement. Proportional control provides most of the push when the robot is far from its target. As the target gets closer, that push becomes smaller.

This can leave a small remaining gap because friction may stop the mechanism before it reaches the target. Integral control builds up enough extra command to overcome that friction or an uneven load. It should usually be added carefully.

If the motor is already at its maximum command, stored integral error can continue growing. When the mechanism finally moves, that stored value may cause a large jump past the target. Limiting the stored value, or clearing it in some situations, prevents this problem.

Derivative control depends strongly on sensor quality. It uses the change between recent readings, so random sensor noise can look like rapid motion. A noisy encoder, a vibrating gyro, or an irregular timing loop can make the derivative command jump around.

Filtering sensor readings can help, but heavy filtering adds delay. That delay can make a robot react too late. Students should log the setpoint, measured value, error, and output while testing.

A graph often reveals the real issue. Repeated swings show too much correction or too much delay.

A slow approach suggests weak proportional gain. A final gap that remains for a long time suggests that some integral action may be needed.

A practical tuning method starts with integral and derivative gains at zero. Increase proportional gain in small steps until the mechanism responds firmly. If it begins to swing back and forth or overshoots badly, reduce the gain.

Add derivative gain when the system needs braking near the target. Add a small integral gain only after the motion is mostly stable. Test more than one condition.

An arm behaves differently when raised than when lowered because gravity changes its load. A drivetrain can behave differently on carpet, tile, or a low battery. Use the same time step on every loop and use sensor units consistently.

If position is measured in degrees, all position targets and error limits should use degrees. Good PID code includes output limits, a safe stop condition, and a tolerance range so a robot does not keep hunting for an unreachable exact value.