Real-time control system

On this page 7

A real-time control system is a control system whose correctness depends not only on the computed command but also on when that command is delivered. In robotics, it reads sensors, runs a control law and writes actuator commands in a fixed, bounded cycle, typically every 1 ms or faster for joint torque loops, so that a late answer counts as a wrong answer.

Among control systems, the real-time property is what turns a correct algorithm such as PID or model predictive control into a physically safe behavior. The defining metric is not average speed but the worst-case response time, together with how much the cycle period varies from one iteration to the next.

How a real-time control loop works

A real-time control loop repeats a sense, compute, actuate cycle at a fixed period. A hardware timer or a fieldbus frame triggers each iteration, the controller samples encoders and force sensors, executes the control law, and publishes new setpoints or torques before the deadline that ends the period.

The loop is usually organized as a cascade of nested loops. The innermost current loop in the motor drive runs at 10 to 40 kHz, the velocity and position loops run at 1 to 8 kHz, and higher layers such as trajectory generation or whole-body control run at 100 Hz to 1 kHz. Each outer loop must be several times slower than the loop inside it, which keeps the layers dynamically decoupled.

The table below lists the typical layers of a robot controller and the timing each one needs.

Control layerTypical rateUsual location
Motor current loop10-40 kHzServo drive firmware or FPGA
Joint position and velocity loop1-8 kHzDrive or real-time host
Impedance or force control500 Hz-4 kHzReal-time host process
Whole-body or model predictive control100 Hz-1 kHzReal-time host, multicore
Motion planning and perception1-30 HzGeneral-purpose computer
Typical loop rates in a robot control stack

Hard, firm and soft real-time requirements

Real-time requirements are classified by the consequence of a missed deadline. The class decides which operating system, hardware and verification effort a design needs, so it should be fixed before any code is written.

ClassEffect of a missed deadlineRobotics example
Hard real-timeSystem failure or safety hazardJoint torque loop of a collaborative arm
Firm real-timeLate result is useless but tolerable if rareVisual servoing frame from a camera
Soft real-timeQuality degrades gracefullyPath replanning or map updates
Classes of real-time requirements

Two timing quantities dominate every analysis. Latency is the delay from a sensor event to the corresponding actuator output, and jitter is the variation of the actual cycle start around its nominal time. A loop with low average latency but occasional spikes of several milliseconds is worse for control than a slightly slower loop that is perfectly regular, because the control law assumes a constant sampling period.

Engineers therefore measure the worst-case execution time (WCET) of the control task and verify that WCET plus input and output overhead stays well below the period. A common design margin keeps CPU utilization of the real-time core under 50 to 70 percent so that interrupts and cache effects cannot push the loop past its deadline.

Platforms that provide real-time guarantees

Determinism comes from the whole platform, not from the control code alone. The scheduler, interrupt handling, memory management and communication bus must all have bounded timing, and a single non-deterministic component breaks the guarantee for the entire loop.

The following table compares the platforms most often used to host robot control loops.

PlatformTypical worst-case jitterStrengthsLimitations
Microcontroller with RTOSBelow 10 µsSimple, highly deterministicLimited compute and memory
Linux with PREEMPT_RTAbout 20-100 µsFull Linux ecosystem, multicoreNeeds careful tuning and isolation
Dual-kernel systems such as XenomaiAbout 5-30 µsVery low latency on PC hardwareSeparate API, smaller community
PLC runtimeAbout 10-100 µsCertified tools, industrial supportRestricted languages and libraries
FPGA logicNanosecondsFully parallel, cycle-exactHard to modify and debug
Common real-time platforms in robotics

Communication must be deterministic as well. Fieldbuses such as EtherCAT, CANopen and PROFINET IRT deliver frames on a fixed schedule with distributed clocks, which keeps drives sampling in step. In ROS 2, the real-time path relies on a real-time capable executor, preallocated memory and a suitable DDS configuration, and the ros2_control framework runs hardware interfaces inside a dedicated real-time thread.

How it relates to neighboring control concepts

A real-time control system is an execution property, not a control algorithm. Feedback control, open-loop control, LQR, impedance control and state estimation with a Kalman filter all describe what is computed, while real-time execution describes whether the result arrives in time to be valid.

ConceptMain question it answersLink to real-time execution
Feedback controlHow the error drives the commandNeeds a constant sampling period
Model predictive controlWhich input sequence is optimalSolver must finish within the period
State estimationWhat the true robot state isEstimator delay adds to loop latency
Motion controlHow axes follow a trajectoryUsually the hard real-time core
PLCHow industrial logic is executedA common real-time execution platform
Real-time execution compared with related concepts

Delay matters because it erodes phase margin. A pure time delay adds phase lag that grows linearly with frequency, so a loop tuned for 1 ms of latency can oscillate or become unstable when latency rises to 3 ms. Discrete control design assumes a known, constant delay, which is why designers often compensate a full sample of delay explicitly in the model.

Common failure modes and design practices

Most real-time failures come from hidden sources of non-determinism rather than from slow algorithms. The table pairs typical symptoms with their usual cause and an accepted remedy.

SymptomLikely causeTypical fix
Periodic latency spikesDynamic memory allocation in the loopPreallocate all buffers at startup
Random overruns under loadShared CPU with non-real-time tasksIsolate cores and pin threads
Priority inversion stallsMutex shared with a low-priority threadLock-free queues or priority inheritance
Audible vibration in jointsJitter in the sampling periodHardware-timed triggers and bus clocks
First cycles miss deadlinesPage faults and cold cachesLock memory and warm up the loop
Symptoms, causes and fixes in real-time control
  • Never log, print or perform file input and output inside the hard real-time thread; pass data to a non-real-time thread through a lock-free buffer.
  • Monitor every overrun with a counter and define a safe reaction, such as holding position or triggering a controlled stop.
  • Test under worst-case load, including network traffic and disk activity, because average-case benchmarks hide the spikes that cause failures.
  • Separate safety functions such as safe torque off onto certified hardware rather than relying on the main control computer.

Put simply

A real-time control system is a robot brain that must answer on time, every time. Many times per second it checks where the robot is, decides how to correct the movement, and sends new orders to the motors. If an answer comes too late, it is already out of date, because the robot has moved in the meantime.

Think of steering a bicycle. You make small corrections constantly, and you have to make them at the right moment. A correct correction that comes half a second late can still make you fall. Robots work the same way, which is why predictable timing matters more than raw speed.

In practice

An integration team builds a seven-axis collaborative arm for screwdriving on an assembly line. The joint drives are connected over EtherCAT, and an industrial PC running Linux with PREEMPT_RT hosts the impedance controller at 1 kHz. Two CPU cores are isolated for the control thread, and all memory is locked and preallocated at startup.

During early tests, the arm produced a faint buzz whenever the vision computer streamed images over the same network. Latency measurements showed cycle jitter of up to 400 µs caused by interrupt handling on the shared core. After moving network interrupts to a non-isolated core and separating the camera traffic, worst-case jitter fell to about 40 µs, the buzz disappeared, and the arm passed its contact force limits for human collaboration with a comfortable margin.