MyRoboPathOpen Robotics Lab
Control Systems & Dynamics17 min readUpdated 2026-03-30All Levels

Robot Control Systems: Open Loop, Closed Loop, PID & Feedback Explained

The Mathematical and Practical Guide to Deterministic Motion Control, Encoder Sensing, and Industrial PID Tuning

MyRoboPath Control Systems Lab
Motion Control & Dynamics Core Team
Robot Control Systems: Open Loop, Closed Loop, PID & Feedback Explained
Control Loop Rate
100 Hz - 20 kHz
From trajectory planners down to inner FOC current loops
Encoder Resolution
1,024 - 65,536 CPR
Counts per revolution for sub-millimeter precision
Steady-State Error
0.00% with Integral
Elimination of offset through continuous error accumulation
Anti-Windup Clamp
±100% PWM Limit
Strict bounding of integrator memory to prevent runaway

Core Engineering Takeaways

  • •Open-loop systems apply a fixed control effort assuming known physics, but fail completely when external disturbances (friction, load, incline) occur.
  • •Closed-loop feedback systems continuously compute the difference between desired state (setpoint) and measured state (process variable), generating corrective effort to drive error to zero.
  • •Quadrature encoders produce two 90-degree phase-shifted square waves (Channel A and B); decoding transitions yields 4x resolution and instantaneous direction detection.
  • •Proportional gain (Kp) reduces rise time but induces steady-state error; Integral gain (Ki) eliminates steady-state error but introduces overshoot; Derivative gain (Kd) dampens oscillations and prevents overshoot.
  • •Integral windup occurs when an actuator saturates (e.g., motor driver hits 100% PWM), causing the accumulator to grow unbounded and creating severe post-disturbance overshoot. Anti-windup clamping is mandatory.
  • •Industrial robotic arms and high-performance mobile robots utilize cascaded control loops: an inner high-speed current loop (10-20 kHz), an intermediate velocity loop (1-2 kHz), and an outer position loop (100-200 Hz).
Prerequisites
  • Basic algebra and familiarity with rates of change (derivatives and integrals)
  • Understanding of DC motors, PWM duty cycles, and microcontrollers

1. Open-Loop vs Closed-Loop Control: The Fundamental Difference

In robotics, every movement is an attempt to translate an abstract software command into physical motion. How the robot executes that command determines whether it is an open-loop or closed-loop system.

Open-Loop Control: Blind Execution

In an open-loop system, the controller sends an actuation signal to the plant (e.g., motor or valve) based entirely on a predefined assumption of how the system will react. There is no sensor verification.

Example: A hobby robot car programmed with drive_forward(speed=70%, duration=3.0s).

  • If the floor is smooth, it travels 1.5 meters.
  • If the floor is thick carpet, increased friction slows the wheels, and it travels only 0.9 meters.
  • If the battery voltage drops from 12.6V to 11.1V, the motor spins 12% slower.
  • If one wheel hits a loose cable, the robot veers 30 degrees off course.

Because the controller has no eyes on reality, it cannot detect or correct for these disturbances.

Closed-Loop Control: Reactive Adaptation

A closed-loop system pairs the actuator with a feedback sensor (such as an optical quadrature encoder, IMU, or resolver). The controller continuously compares what the robot is *actually doing* with what it was *commanded to do*. If a carpet slows the wheels down, the controller detects the drop in measured RPM and instantly increases the motor PWM voltage until the speed matches the target.

2. The Anatomy of a Feedback Loop: Setpoints and Error Signals

Every closed-loop feedback system consists of five distinct components:

  1. 1
    Setpoint (r(t)r(t)): The desired state (e.g., target motor speed = 250 RPM, or target arm angle = 45.0°).
  2. 2
    Process Variable (y(t)y(t)): The actual measured state from physical sensors (e.g., current encoder speed = 190 RPM).
  3. 3
    Error Signal (e(t)e(t)): The difference between desired and measured state:
e(t)=r(t)−y(t)e(t) = r(t) - y(t)
  1. 4
    Controller: The mathematical algorithm (such as PID) that evaluates e(t)e(t) and calculates a corrective command.
  2. 5
    Actuator & Plant: The physical system (motor driver, motor armature, gearbox, chassis, inertia) being driven by the controller output u(t)u(t).

3. Encoders: Transforming Physical Motion into Digital Truth

To build a closed-loop motor controller, you need precise rotational feedback. In robotics, Incremental Quadrature Encoders are the industry standard.

Quadrature Signal Encoding

An encoder disk spinning between optical or magnetic sensor pairs outputs two square waves: Channel A and Channel B. Crucially, these two channels are positioned in quadrature (electrically offset by 90°):

  • Clockwise Rotation: Channel A leads Channel B by 90°. (When A transitions from LOW to HIGH, B is still LOW).
  • Counter-Clockwise Rotation: Channel B leads Channel A by 90°. (When A transitions from LOW to HIGH, B is already HIGH).

1x, 2x, and 4x Decoding Modes

By decoding different edge transitions via microcontroller hardware interrupts or dedicated timer encoder inputs:

  • 1x Decoding: Counts only the rising edge of Channel A.
  • 2x Decoding: Counts rising and falling edges of Channel A (doubles resolution).
  • 4x Decoding: Counts all rising and falling edges of both Channel A and Channel B (quadruples resolution).

An inexpensive encoder with 100 physical lines per revolution yields 400 discrete counts per revolution (CPR) in 4x mode. Mounted before a 30:1 gearbox, this provides 400×30=12,000400 \times 30 = 12,000 counts per output wheel revolution (0.03° angular resolution).

4. The PID Algorithm Demystified: P, I, and D Deep Dive

The PID (Proportional-Integral-Derivative) controller is by far the most widely deployed control algorithm in robotics, industrial automation, and aerospace.

The Continuous Time Formula

u(t)=Kp⋅e(t)+Ki∫0te(τ)dτ+Kd⋅de(t)dtu(t) = K_p \cdot e(t) + K_i \int_0^t e(\tau) d\tau + K_d \cdot \frac{de(t)}{dt}

1. The Proportional Term (P=Kp⋅e(t)P = K_p \cdot e(t))

The proportional term acts like a virtual spring. The farther you are from your target, the harder the controller pushes.

  • High KpK_p: Fast rise time, aggressive response, but causes ringing oscillation and instability.
  • Low KpK_p: Sluggish, sluggish response.
  • The Steady-State Error Limitation: Pure proportional control *cannot* eliminate error in systems with opposing loads (e.g., gravity or friction). As e(t)e(t) approaches zero, u(t)u(t) drops until it can no longer overcome friction, stalling just short of the goal.

2. The Integral Term (I=Ki∫0te(τ)dτI = K_i \int_0^t e(\tau) d\tau)

The integral term acts as the controller's memory. It sums every microsecond of error over time. Even if the error is tiny, prolonged offset causes the integral sum to grow relentlessly until the motor overcomes static friction and reaches the exact setpoint.

  • Benefit: Guarantees zero steady-state error (ess=0e_{ss} = 0).
  • Risk: Introduces phase lag and overshoot.

3. The Derivative Term (D=Kd⋅de(t)dtD = K_d \cdot \frac{de(t)}{dt})

The derivative term acts as a damper or shock absorber. It measures the slope (rate of change) of the error. If the robot is closing in on its target very quickly, de(t)dt\frac{de(t)}{dt} becomes negative, applying reverse braking before the robot overshoots.

  • Benefit: Suppresses oscillation, enables higher KpK_p gains, and provides smooth settling.
  • Risk: Amplifies high-frequency sensor noise.

Discrete-Time Digital PID Controller Formulation

u[k]=Kpe[k]+Ki∑j=0ke[j]Δt+Kde[k]−e[k−1]Δtu[k] = K_p e[k] + K_i \sum_{j=0}^{k} e[j] \Delta t + K_d \frac{e[k] - e[k-1]}{\Delta t}
In Simple Words: In digital microcontrollers running at discrete sample periods Δt, integrals become numerical summations and derivatives become backward differences.
Variables Breakdown:
u[k]u[k]
Discrete controller output at sample step k (e.g., PWM duty cycle or motor current)Unit: volts / %
e[k]e[k]
Instantaneous error at sample step k (Setpoint minus Measured Variable)Unit: units
Δt\Delta t
Exact sample period between loop iterations (e.g., 0.005 s for 200 Hz)Unit: seconds
Kp,Ki,KdK_p, K_i, K_d
Proportional, Integral, and Derivative tuning gainsUnit: scalar
Worked Example:

For a loop running at 100 Hz (Δt = 0.01s) with Kp=1.2, Ki=0.4, Kd=0.05, and error moving from 10 to 8: u = 1.2(8) + 0.4(sum + 8*0.01) + 0.05((8-10)/0.01) = 9.6 + I_term - 10.0.

5. Practical PID Pitfalls: Integral Windup and Derivative Kick

A textbook mathematical PID formula will cause physical damage if deployed on a real robot without real-world engineering protections.

1. Integral Windup & Clamping

Physical actuators have hard saturation limits: a motor driver cannot output more than 100% PWM or draw more than the battery voltage. When a robot's wheel stalls against an obstacle, the motor sits at 100% power, but e(t)e(t) remains large. The integral term continues accumulating unbounded for seconds. When the obstacle is removed, the accumulated integral is so massive that the motor continues spinning at maximum speed long past the target, slamming violently into mechanical stops.

Solution: Integrator Clamping (Anti-Windup): Only accumulate e(t)⋅Δte(t) \cdot \Delta t into the integral sum when the controller output u[k]u[k] is *not saturated*. Clamp the integral state to a fixed maximum value:

if ∣u[k]∣≥umax and sign(e[k])==sign(u[k]), pause integration.\text{if } |u[k]| \ge u_{max} \text{ and } \text{sign}(e[k]) == \text{sign}(u[k]), \text{ pause integration.}

2. Derivative on Measurement & Low-Pass Filtering

If a user abruptly changes the setpoint from 0 to 100, the error step causes d(e)dt\frac{d(e)}{dt} to spike toward infinity—a violent phenomenon known as Derivative Kick. To eliminate this, compute the derivative of the process variable (measured state) instead of the error:

de(t)dt=d(r(t)−y(t))dt=−dy(t)dt(assuming constant setpoint r)\frac{de(t)}{dt} = \frac{d(r(t) - y(t))}{dt} = -\frac{dy(t)}{dt} \quad (\text{assuming constant setpoint } r)

Furthermore, raw encoder velocity signals contain high-frequency quantization noise. Pass the derivative term through a first-order digital low-pass filter (cutoff frequency ωc≈50 Hz\omega_c \approx 50\text{ Hz}) before multiplying by KdK_d.

RobustPID.hpp
cpp
#pragma once
#include <algorithm>

class RobustPID {
public:
  RobustPID(float kp, float ki, float kd, float outMin, float outMax)
    : kp_(kp), ki_(ki), kd_(kd), outMin_(outMin), outMax_(outMax),
      integrator_(0.0f), lastMeasurement_(0.0f), filteredDerivative_(0.0f) {}

  float compute(float setpoint, float measurement, float dt) {
    if (dt <= 0.0f) return 0.0f;

    float error = setpoint - measurement;

    // 1. Proportional term
    float pOut = kp_ * error;

    // 2. Integral term with Anti-Windup Clamping
    integrator_ += error * dt;
    float iOut = ki_ * integrator_;

    // 3. Derivative on Measurement with Low-Pass Filter (Alpha = 0.7)
    float rawDerivative = -(measurement - lastMeasurement_) / dt;
    filteredDerivative_ = (0.7f * filteredDerivative_) + (0.3f * rawDerivative);
    float dOut = kd_ * filteredDerivative_;

    // Raw total output
    float totalOut = pOut + iOut + dOut;

    // Output Saturation Clamping & Integrator Back-Calculation
    if (totalOut > outMax_) {
      totalOut = outMax_;
      // Prevent integrator from growing if pushing further into saturation
      if (error > 0.0f) integrator_ -= error * dt;
    } else if (totalOut < outMin_) {
      totalOut = outMin_;
      if (error < 0.0f) integrator_ -= error * dt;
    }

    lastMeasurement_ = measurement;
    return totalOut;
  }

  void reset() {
    integrator_ = 0.0f;
    lastMeasurement_ = 0.0f;
    filteredDerivative_ = 0.0f;
  }

private:
  float kp_, ki_, kd_;
  float outMin_, outMax_;
  float integrator_;
  float lastMeasurement_;
  float filteredDerivative_;
};

6. Tuning Methods: Ziegler-Nichols & Manual Heuristics

Tuning is the process of selecting KpK_p, KiK_i, and KdK_d to achieve fast rise time, zero steady-state error, minimal overshoot, and robustness against mechanical disturbances.

The Practical Manual Tuning Heuristic

For mobile robots and robotic joints, follow this systematic procedure:

  1. 1
    Set Ki=0K_i = 0 and Kd=0K_d = 0: Increase KpK_p from zero until the system begins oscillating continuously around the setpoint.
  2. 2
    Back off KpK_p by 30-50%: This establishes a stable proportional response.
  3. 3
    Introduce KdK_d: Gradually increase KdK_d to dampen the oscillations and eliminate overshoot. You will hear high-frequency motor buzzing if KdK_d is pushed too high (amplifying noise).
  4. 4
    Introduce KiK_i: Increase KiK_i in small increments until the system eliminates steady-state offset and holds position precisely under external load.
Table 1: Ziegler-Nichols Closed-Loop (Ultimate Gain) Tuning Rules
Controller TypeKp GainKi GainKd Gain
P Only0.50 · Ku——
PI Controller0.45 · Ku0.54 · Ku / Tu—
Classic PID0.60 · Ku1.20 · Ku / Tu0.075 · Ku · Tu
Pessen Integral (Low Overshoot)0.70 · Ku1.75 · Ku / Tu0.105 · Ku · Tu

7. Cascaded Loops & Feedforward Control in Real Robots

Why Single-Loop PID Falls Short in Industrial Robots

In a heavy robotic arm or autonomous mobile robot, inertia and motor inductance create phase delays. Controlling position directly by commanding motor voltage through a single PID loop results in either sluggish response or violent oscillations.

Cascaded Multi-Loop Architecture

Modern motor drives (such as ODrive, Elmo Motion, and Maxon EPOS) employ nested, cascaded control loops:

  1. 1
    Inner Loop: Current / Torque Control (10 kHz - 20 kHz): Measures motor phase current via shunts and runs Field-Oriented Control (FOC). Removes electrical time constant (L/RL/R) dynamics.
  2. 2
    Intermediate Loop: Velocity Control (1 kHz - 2 kHz): Measures encoder speed and outputs a torque command to the current loop.
  3. 3
    Outer Loop: Position Control (100 Hz - 500 Hz): Measures absolute joint position and outputs target velocity commands.

Feedforward (FFFF) Control

Feedback control is inherently *reactive*—it requires an error to occur before generating a command. Feedforward is *predictive*. If your arm knows it is holding a 2 kg gripper at a 90° horizontal angle, the physics model can calculate the exact gravity torque required (Tg=m⋅g⋅L⋅cos⁡(θ)T_g = m \cdot g \cdot L \cdot \cos(\theta)) and inject that torque directly into the actuator *before* the joint drops a millimeter. The PID loop then only has to handle minor unmodeled disturbances.

Frequently Asked Questions

Common Questions & Troubleshooting

Q:Why does my motor whine or buzz when I increase Kd?

Derivative control calculates the difference between successive sensor measurements. Optical encoders generate discrete pulses; at low speeds, the backward difference jumps discretely between zero and large values. This high-frequency sensor noise is multiplied by Kd, creating sharp voltage spikes that cause audible acoustic motor buzzing. Low-pass filter your velocity feedback to solve this.

Q:What is the ideal sample time (dt) for a robotics PID loop?

The sample period dt should be at least 10 to 20 times faster than the mechanical bandwidth of the system. For mobile robot wheels, 100 Hz to 200 Hz (dt = 5-10ms) is standard. For robotic arm joints and quadcopter flight controllers, 500 Hz to 1 kHz (dt = 1-2ms) is required. For brushless motor current loops, 10 kHz to 40 kHz is standard.

Q:What is the difference between Bang-Bang control and PID?

Bang-bang control applies maximum power in one direction if below the setpoint, and maximum power in reverse if above the setpoint (like a domestic thermostat). In physical robotics, bang-bang control causes destructive mechanical chatter, gear stripping, and continuous oscillation. PID smoothly modulates voltage proportional to error dynamics.