Fiveable

🤖Intro to Autonomous Robots Unit 4 Review

QR code for Intro to Autonomous Robots practice questions

4.5 PID control

4.5 PID control

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🤖Intro to Autonomous Robots
Unit & Topic Study Guides

PID control fundamentals

PID control is one of the most common feedback control techniques you'll encounter in autonomous robotics. The controller continuously measures the difference between where the system is and where you want it to be, then calculates a control signal to close that gap. PID stands for Proportional-Integral-Derivative, referring to the three terms that work together to generate that control signal.

Proportional, integral, derivative terms

Each term in a PID controller handles a different aspect of the error:

  • Proportional (KpK_p): Produces output proportional to the current error. A larger error means a stronger corrective response. This gives you fast reaction, but on its own it typically leaves behind some residual steady-state error.
  • Integral (KiK_i): Accumulates error over time. Even a small persistent error will build up, and the integral term generates a corrective output to eliminate it. The tradeoff: too much integral gain causes overshoot and oscillations.
  • Derivative (KdK_d): Responds to the rate of change of the error. If the error is shrinking quickly, the derivative term eases off the correction to prevent overshooting. It improves stability and damping, but it's sensitive to sensor noise and can produce large spikes from sudden error changes.

Feedback control loop

The PID feedback loop works in a continuous cycle:

  1. Measure the process variable (PV) using a sensor.
  2. Compare PV to the desired setpoint (SP) to calculate the error.
  3. Feed the error into the PID controller, which computes a control output from the P, I, and D terms.
  4. Apply that control output to the system (the "plant").
  5. Repeat.

The controller keeps running this loop, constantly nudging the system toward the setpoint.

Error signal calculation

The error signal e(t)e(t) is simply the difference between the desired setpoint r(t)r(t) and the measured process variable y(t)y(t):

e(t)=r(t)y(t)e(t) = r(t) - y(t)

The entire goal of the PID controller is to drive this error toward zero over time.

Setpoint vs process variable

  • The setpoint (SP) is your target value: a desired motor speed of 1500 RPM, a target temperature of 50°C, or a heading angle of 90°.
  • The process variable (PV) is the actual measured value from your sensor: the encoder reading, the thermocouple output, the GPS position.

The PID controller works to make PV track SP as closely as possible, minimizing the error between them.

PID controller design

Designing a PID controller means selecting gains KpK_p, KiK_i, and KdK_d that give you the performance you need: fast response, minimal overshoot, and good disturbance rejection.

Transfer function representation

In the Laplace domain, the PID controller's transfer function is:

Gc(s)=Kp+Kis+KdsG_c(s) = K_p + \frac{K_i}{s} + K_d s

where ss is the Laplace variable. This representation lets you analyze the closed-loop system's stability and performance using tools like root locus, Bode plots, and Nyquist diagrams.

Tuning PID gains

Tuning is the process of finding the right values for KpK_p, KiK_i, and KdK_d. Poor tuning leads to sluggish response, excessive overshoot, or outright instability. There are several approaches.

Manual tuning methods

Manual tuning follows a structured trial-and-error process:

  1. Set Ki=0K_i = 0 and Kd=0K_d = 0.
  2. Increase KpK_p until the system starts to oscillate consistently.
  3. Add KiK_i gradually to eliminate steady-state error.
  4. Add KdK_d to reduce overshoot and improve damping.
  5. Fine-tune all three gains iteratively, aiming for something like 10–20% overshoot or a quarter-decay ratio.

Ziegler-Nichols tuning

The Ziegler-Nichols method provides a more systematic starting point:

  1. Set Ki=0K_i = 0 and Kd=0K_d = 0.
  2. Increase KpK_p until the system oscillates with constant amplitude. This value is the critical gain KcrK_{cr}.
  3. Measure the critical period TcrT_{cr} of those oscillations.
  4. Calculate the PID gains using these formulas:
    • Kp=0.6KcrK_p = 0.6 \, K_{cr}
    • Ki=2KpTcrK_i = \frac{2 \, K_p}{T_{cr}}
    • Kd=KpTcr8K_d = \frac{K_p \, T_{cr}}{8}

These values are a starting point. You'll almost always need further fine-tuning for your specific application.

Simulink (MATLAB's graphical simulation environment) is a common tool for prototyping PID controllers before deploying them on hardware. You can use the built-in PID Controller block or wire up individual P, I, and D blocks. Simulink makes it straightforward to connect plant models, sensor models, and actuator models so you can test and optimize controller performance in simulation first.

Discrete vs continuous time

  • Continuous-time PID controllers work with analog signals and are described by differential equations or Laplace-domain transfer functions.
  • Discrete-time PID controllers work with sampled signals and are described by difference equations or Z-domain transfer functions.

Since most real implementations run on microcontrollers or computers, you'll typically need to discretize the continuous-time design. Common discretization methods include Euler (forward or backward), Tustin (bilinear), and matched pole-zero.

PID control applications

PID control shows up across a wide range of robotic systems wherever precise setpoint tracking is needed.

Proportional, integral, derivative terms, Proportional–integral–derivative controller - Wikipedia

Motor speed control

A PID controller can regulate the speed of a DC or brushless DC (BLDC) motor. The setpoint is the desired speed in RPM, and the process variable comes from an encoder or hall sensor. The controller adjusts the PWM duty cycle sent to the motor driver, compensating for load changes or friction so the motor holds its target speed.

Temperature regulation

In systems like heat exchangers, ovens, or thermal chambers, PID control maintains a target temperature. A thermocouple or RTD provides the process variable, and the controller adjusts heating or cooling power. Temperature systems tend to have slow dynamics, so PI control (without the derivative term) is often sufficient here.

Autonomous vehicle steering

For lateral control of autonomous cars or mobile robots, a PID controller can minimize deviation from a desired path. The setpoint might be a target lateral position or steering angle, measured by cameras, GPS, or encoders. The controller outputs a steering command to keep the vehicle on track.

Drone altitude stabilization

Drones use PID control to hold a target altitude or follow a vertical trajectory. Barometers, ultrasonic sensors, or GPS provide altitude measurements. The controller adjusts propeller thrust to counteract disturbances like wind gusts and maintain stable flight.

PID limitations and variations

PID control is effective in many situations, but it has well-known failure modes. Understanding these helps you choose the right controller structure and avoid common pitfalls.

Integral windup

Integral windup happens when the actuator saturates (hits its physical limit) but the integral term keeps accumulating error. When the error finally changes sign, the built-up integral causes large overshoot and slow recovery.

Anti-windup techniques address this by:

  • Clamping the integral term so it stops accumulating when the actuator is saturated
  • Using a tracking scheme that resets the integrator based on the difference between the commanded and actual actuator output

Derivative kick

When the setpoint changes abruptly (a step change), the error signal jumps instantly, and the derivative term produces a large spike in the control output. This "derivative kick" can saturate actuators and destabilize the system.

Two common fixes:

  • Setpoint weighting: Apply the derivative term only to the process variable, not the full error signal. Since PV changes smoothly, the derivative stays well-behaved.
  • Derivative filtering: Add a low-pass filter on the derivative term to smooth out sudden spikes.

PI vs PID control

The derivative term isn't always helpful. In systems with noisy sensors or slow dynamics, KdK_d can amplify noise and degrade performance. PI control (setting Kd=0K_d = 0) is simpler to tune, less noise-sensitive, and provides good setpoint tracking and disturbance rejection for many practical systems.

Feedforward control

Feedforward control uses knowledge of the system model or expected disturbances to generate a proactive control signal, rather than waiting for an error to appear. For example, if you know a robot arm is about to pick up a heavy object, feedforward can increase motor torque before the arm sags.

Feedforward is typically combined with PID feedback. The feedforward handles predictable disturbances, and the PID corrects for everything else. The downside is that feedforward requires a reasonably accurate system model.

Cascade PID control

Cascade control uses two (or more) PID controllers in a nested structure. The outer loop controller sets the target for the inner loop controller, which directly drives the actuator.

For example, in a robot arm position controller:

  • The outer loop controls position and outputs a desired motor current.
  • The inner loop controls motor current directly.

Because the inner loop responds faster, it can reject disturbances quickly before they affect the outer loop. This improves both response time and robustness.

Proportional, integral, derivative terms, PID controller - Wikipedia

PID robustness and performance

A well-tuned PID controller needs to perform reliably despite uncertainties, disturbances, and nonlinearities in the real system.

Disturbance rejection

Disturbance rejection measures how well the controller suppresses the effect of external disturbances (load changes, friction, wind) on the system output. Proper tuning of KiK_i and KdK_d is key: the integral term eliminates persistent offset from disturbances, while the derivative term dampens transient effects. Performance can be quantified with metrics like the integral of absolute error (IAE) or the sensitivity function.

Steady-state error

Steady-state error is the residual difference between the setpoint and process variable after the system settles. The integral term is responsible for driving this to zero: it keeps accumulating even a tiny error until the output corrects it. Increasing KiK_i reduces steady-state error faster, but too much integral gain introduces overshoot and oscillations.

Rise time and settling time

  • Rise time: The time for the output to go from 10% to 90% of its final value after a step input. Increasing KpK_p generally reduces rise time.
  • Settling time: The time for the output to stay within a tolerance band (typically ±2% or ±5%) around the final value. The derivative gain KdK_d helps reduce settling time by adding damping.

There's a fundamental tradeoff: faster rise time (higher KpK_p) often means more overshoot, which increases settling time. Tuning is about finding the right balance.

Overshoot and oscillations

Overshoot is how far the output exceeds its final value during the transient response, expressed as a percentage. Oscillations are repeated fluctuations around the final value, caused by insufficient damping or aggressive gain settings.

Increasing KdK_d adds damping and reduces overshoot. Reducing KiK_i can also help, since excessive integral gain is a common cause of oscillatory behavior. The Ziegler-Nichols method, for instance, tends to produce aggressive tuning with ~25% overshoot, so you'll often need to back off the gains.

Stability analysis

A PID-controlled system is stable if its output remains bounded for bounded inputs. You can assess stability using:

  • Root locus: Shows how the system's poles move as gain changes. All closed-loop poles must be in the left-half plane (continuous time) or inside the unit circle (discrete time).
  • Bode plots: Show gain and phase margins. Adequate margins (typically >6 dB gain margin and >30° phase margin) ensure the system tolerates modeling errors and delays.
  • Nyquist diagrams: Provide a graphical stability criterion based on encirclements of the critical point.

PID implementation considerations

Moving from theory to a real system introduces practical challenges that can make or break your controller's performance.

Analog vs digital controllers

  • Analog PID controllers use op-amps, resistors, and capacitors. They offer continuous control with no sampling delay, but they're susceptible to component drift and noise, and they're hard to reconfigure.
  • Digital PID controllers run on microcontrollers, FPGAs, or PLCs. They're flexible, programmable, and easy to integrate with other algorithms, but they introduce quantization error and sampling delay.

For most robotics applications, digital implementation is the standard choice.

Sensor noise filtering

Sensor noise is especially problematic for the derivative term, which amplifies high-frequency fluctuations. A low-pass filter on the sensor signal (or specifically on the derivative path) attenuates this noise. Choose the filter's cutoff frequency carefully: too low and you'll add phase lag that hurts stability; too high and you won't filter enough noise.

Actuator saturation

When the PID controller demands more than the actuator can deliver (e.g., requesting 15V from a 12V motor driver), the actuator saturates. This directly causes integral windup, as discussed above. Always implement anti-windup logic, and consider clamping the controller output to the actuator's known limits.

Sampling rate selection

For digital PID controllers, the sampling rate (control loop frequency) must be fast enough to capture the system's dynamics. A common rule of thumb: sample at least 10–20 times faster than the system's dominant time constant or closed-loop bandwidth. Undersampling causes aliasing and poor control. Oversampling improves resolution but increases computational load, so find the practical sweet spot for your hardware.

Code optimization techniques

On resource-constrained embedded systems, a few techniques keep PID execution efficient:

  • Fixed-point arithmetic instead of floating-point speeds up calculations and reduces memory use. Watch for overflow and precision loss.
  • Lookup tables for expensive functions (trig, exponential) avoid costly runtime computation.
  • Inline functions and compiler optimizations (loop unrolling, constant folding) reduce overhead and improve execution speed.

These optimizations matter most when you're running multiple control loops at high frequency on a small microcontroller.