Skip to content
Home
Robot Control Systems: PID, Model Predictive Control, and Feedback...

Robot Control Systems: PID, Model Predictive Control, and Feedback...

Robotics Robotics 8 min read 1505 words Beginner ExcellentWiki Editorial Team

Robot control systems convert sensor data into actuator commands to achieve desired behaviors. From simple PID loops for motor speed control to model predictive control for complex trajectory tracking, understanding control theory is essential for robotics.

Control Theory Fundamentals

Robot control systems are built on classical and modern control theory. PID control (Proportional-Integral-Derivative) is the most widely used feedback controller, with the proportional term responding to current error, the integral term eliminating steady-state error, and the derivative term predicting future error to reduce overshoot. Model Predictive Control (MPC) optimizes control actions over a future time horizon, making it ideal for systems with constraints on joint limits, velocity, and acceleration.

PID Control

The PID controller computes the control signal as: u(t) = Kp·e(t) + Ki·∫e(t)dt + Kd·de(t)/dt

class PIDController:
    def __init__(self, Kp, Ki, Kd, setpoint=0):
        self.Kp = Kp
        self.Ki = Ki
        self.Kd = Kd
        self.setpoint = setpoint
        self.integral = 0
        self.prev_error = 0
        
    def update(self, measurement, dt):
        error = self.setpoint - measurement
        
        # Proportional
        P = self.Kp * error
        
        # Integral with anti-windup
        self.integral += error * dt
        self.integral = max(min(self.integral, 100), -100)  # clamp
        I = self.Ki * self.integral
        
        # Derivative
        derivative = (error - self.prev_error) / dt if dt > 0 else 0
        D = self.Kd * derivative
        
        self.prev_error = error
        return P + I + D

Tuning PID Gains

The Ziegler-Nichols method provides starting gains: set Ki and Kd to zero, increase Kp until the system oscillates (ultimate gain Ku), measure the oscillation period Tu, then set Kp = 0.6·Ku, Ki = 1.2·Ku/Tu, Kd = 0.075·Ku·Tu. Fine-tune manually from there — reduce Kp for less overshoot, increase Ki to eliminate steady-state error, increase Kd to dampen oscillations.

Feedforward Control

Feedforward control anticipates system behavior and applies corrective action before errors occur. Combined with feedback (feedback + feedforward), the controller can reject disturbances while maintaining accurate tracking. For robotic arms, feedforward torque based on the robot dynamics model compensates for gravity and Coriolis forces, allowing lower feedback gains and smoother motion.

class FeedforwardPID:
    def __init__(self, Kp, Ki, Kd, model):
        self.pid = PIDController(Kp, Ki, Kd)
        self.model = model  # robot dynamics model
        
    def update(self, desired_state, current_state, dt):
        # Feedforward term from inverse dynamics
        ff = self.model.compute_feedforward(desired_state)
        
        # Feedback term from PID
        fb = self.pid.update(
            desired_state.position - current_state.position, dt
        )
        
        return ff + fb

State-Space Control

Modern control theory represents systems in state-space form: ẋ = Ax + Bu, y = Cx + Du. The state vector x contains all variables needed to describe the system (position, velocity, etc.). For a DC motor, the state might be [position, velocity, current]. The A matrix captures system dynamics, B maps inputs to states, C maps states to outputs.

Linear Quadratic Regulator (LQR)

LQR computes optimal state feedback gains by minimizing a cost function that penalizes state error and control effort. It requires a linear system model and produces gains that are optimal for the given cost weights.

import control as ct

# State-space model of a DC motor
A = [[0, 1], [0, -b/J]]  # b: damping, J: inertia
B = [[0], [1/J]]
C = [[1, 0]]
D = [[0]]

# LQR design
Q = [[100, 0], [0, 1]]  # State cost (position error weighted 100x)
R = [[0.1]]              # Control effort cost
K, S, E = ct.lqr(A, B, Q, R)

Model Predictive Control

MPC solves an optimization problem at each control step over a finite future horizon, respecting constraints on states and control inputs. It is computationally intensive but handles constraints naturally, making it ideal for systems with joint limits and obstacle avoidance requirements.

import cvxpy as cp

def mpc_control(x0, A, B, N=10):
    # x0: current state, N: prediction horizon
    n_x = A.shape[0]  # state dimension
    n_u = B.shape[1]  # control dimension
    
    x = cp.Variable((n_x, N+1))
    u = cp.Variable((n_u, N))
    
    cost = 0
    constraints = [x[:, 0] == x0]
    
    for t in range(N):
        cost += cp.quad_form(x[:, t], Q) + cp.quad_form(u[:, t], R)
        constraints += [x[:, t+1] == A @ x[:, t] + B @ u[:, t]]
        constraints += [u_min <= u[:, t], u[:, t] <= u_max]
        constraints += [x_min <= x[:, t], x[:, t] <= x_max]
    
    cost += cp.quad_form(x[:, N], Q_terminal)
    
    prob = cp.Problem(cp.Minimize(cost), constraints)
    prob.solve()
    return u[:, 0].value

Stability Analysis

A closed-loop system is stable if its eigenvalues (poles) have negative real parts. For linear systems, check the eigenvalues of (A - BK) where K is the feedback gain. For nonlinear systems, Lyapunov’s method provides stability certificates. Gain margin and phase margin from Bode plots indicate robustness — 6dB gain margin and 45° phase margin are typical targets.

Digital Twins and Simulation

Before deploying controllers on real hardware, test them in simulation using digital twins — virtual models that mirror the physical robot’s dynamics and environment. Gazebo and PyBullet provide physics simulation with realistic sensor noise and actuator dynamics. Controller testing in simulation catches stability issues, constraint violations, and unexpected behaviors without risking hardware damage. Use ROS 2’s ros2_control framework to swap between simulated and real hardware by changing the hardware interface configuration — the same controller code runs in both environments. This simulation-to-reality transfer (sim-to-real) is standard practice in modern robotics development.

Summary

PID control is simple and effective for basic tasks. Feedforward improves tracking by anticipating known dynamics. State-space methods (LQR) provide optimal gains for linear systems. MPC handles constraints and multi-variable systems. The right controller depends on the robot, task requirements, and computational resources available.

Adaptive and Learning-Based Control

Adaptive control adjusts controller parameters in real-time to handle changing system dynamics. Model reference adaptive control (MRAC) compares plant output to a reference model and adjusts parameters to minimize tracking error. Self-tuning regulators identify system parameters online and update controller gains. Reinforcement learning (RL) control trains a policy through trial and error using reward functions that encode desired behavior. Deep RL methods like PPO and SAC handle high-dimensional state spaces (camera images, joint angles) directly. These learning-based approaches are increasingly deployed for tasks where traditional model-based control is impractical due to complex, uncertain dynamics.

FAQ

What is the difference between open-loop and closed-loop control?

Open-loop control applies a precomputed command without feedback — it is simple but cannot correct errors from disturbances or model inaccuracies. Closed-loop control measures the output and adjusts the input to minimize error — it is more accurate but requires sensors and can become unstable if poorly tuned.

How do I choose between PID and MPC?

Use PID for simple single-input single-output systems (motor speed, heater temperature) where constraints are not critical. Use MPC for multi-input multi-output systems with constraints (robot arm with joint limits, drone with velocity limits). MPC is computationally heavier but handles constraints natively.

What causes PID instability?

High Kp causes oscillation. High Ki causes integral windup (large overshoot after saturation). High Kd amplifies measurement noise. Solutions: add anti-windup to integral term, filter the derivative term, and use a low-pass filter on noisy sensor measurements.

Modern Control Techniques

Linear quadratic regulator (LQR) provides optimal state feedback for linear systems by minimizing a cost function that balances state error and control effort. For nonlinear systems, gain scheduling switches between LQR controllers tuned at different operating points. Model predictive control (MPC) solves an optimization problem at each time step over a finite horizon, respecting actuator and state constraints. MPC is computationally expensive but handles complex constraints naturally. Reinforcement learning controllers learn control policies from experience, useful when accurate system models are unavailable. These advanced controllers increasingly run on embedded GPUs for real-time performance.

State Estimation and Observers

When full state measurement is unavailable, observers estimate internal states from sensor data. The Luenberger observer uses a linear model with a correction term proportional to output error. The Kalman filter optimally estimates states for linear systems with Gaussian noise — it predicts using the system model, then corrects based on measurements weighted by their uncertainty. The extended Kalman filter (EKF) and unscented Kalman filter (UKF) handle nonlinear systems. Particle filters represent arbitrary probability distributions with weighted samples. Good state estimation is often more impactful on controller performance than the control algorithm itself.

Tuning PID Controllers

The Ziegler-Nichols method provides initial PID gains: increase Kp until sustained oscillation (ultimate gain Ku), measure oscillation period Tu, then set Kp = 0.6 Ku, Ki = 2 Kp / Tu, Kd = Kp Tu / 8. Manual tuning iteratively adjusts gains: increase Kp until slight overshoot, add Ki to eliminate steady-state error, add Kd to dampen overshoot. Use step response tests to evaluate performance — measure rise time, overshoot, settling time, and steady-state error. Auto-tuning algorithms in modern controllers (PID autotune) automate this process through relay feedback tests.

How do I implement real-time control on a robot?

Use a real-time operating system (RTOS) or a Linux kernel with PREEMPT_RT patch. Set control loop frequency based on system dynamics — motor control runs at 1-10 kHz, balancing at 200-500 Hz, trajectory tracking at 50-100 Hz. Measure actual loop timing and add watchdog timers for safety.

For a comprehensive overview, read our article on Ai Robotics.

For a comprehensive overview, read our article on Autonomous Mobile Robots.

Section: Robotics 1505 words 8 min read Beginner 756 articles in section Report inaccuracy Back to top