All Engineering Guides (24)
Hardware & Actuators5 min read·2026-11-26·HUMANOIDS.ORG Engineering Desk

Real-Time Control Loops on Linux with PREEMPT_RT, EtherCAT and CAN FD

How to separate host deadlines from drive-clock alignment, qualify sub-microsecond synchronization, and budget CAN FD traffic.

Related reference blueprints

Table of contents
Executive Engineering Summary

A control loop needs three independently measured quantities. The Linux process must finish and transmit on time, distributed drives must latch their outputs close together, and feedback must return before it goes stale. This guide shows how to define those quantities, evaluate a sub-microsecond EtherCAT alignment target on a specified rig, and account for shared CAN FD arbitration and burst traffic.

Key Takeaways
  • Specify the time of the physical output event and the maximum permissible age of its sensor input.
  • Use PREEMPT_RT and latency tracing to diagnose the host path. Measure complete control-cycle timing with independent observations.
  • Treat a target below 1 µs as an acceptance threshold for calibrated, pairwise receiver events on the tested EtherCAT topology.
  • Budget both CAN FD transmission phases, arbitration blocking and peak traffic from every bus participant.

Define the events before choosing a loop frequency

Write a timing contract for one control iteration. Identify the physical sampling instant, when Linux receives the sample, when the controller computes a command, when the frame leaves the host and when the drive latches the output. Number samples and commands so a capture can associate all events with one cycle. Choose an age limit from the plant behavior and control design. Define separately how many missing or late updates the drive may accept before following its configured loss-of-communication behavior.

A periodic thread can meet its wake-up deadline while applying stale sensor data. Two drives can also latch commands together while the host sends those commands too late for their scheduled cycle. Log both outcomes under separate metric names. Allocate a refresh period explicitly and make room for bounded retries and recovery outside the cyclic fast path.

Sample-to-actuator age

A[k] = t_latch[k] − t_sample[k]

  • A[k] is the age of the input used for command k, in s.
  • t_sample[k] is the physical sampling instant and t_latch[k] is the output-latch instant on the same timebase.
Sequential deadline budget

D_cycle ≥ T_release + T_compute + T_egress + T_transport + T_apply + M

  • D_cycle is the allowed elapsed time from the scheduled release to the output event.
  • The T terms are distinct measured or bounded contributions for the chosen timing path, in s.
  • M is the reserved timing margin, including measurement uncertainty where applicable.

Measure the Linux control path under commissioned load

PREEMPT_RT changes interrupt and locking behavior so more kernel work can be preempted and selected locks inherit priority. Latency still depends on the board, kernel, driver, firmware and workload. Preallocate and prefault the control task’s working memory. Keep allocation, disk writes and blocking network services out of the cyclic path. Measure IRQ and thread response before and after pinning the control task and the relevant IRQs. Verify priority ordering and the actual CPU placement from the running system.

Use rtla timerlat to inspect timer interrupt latency and the wake-up latency of its test thread. Correlate threshold traces with the application’s own timestamped cycle sequence. Record software versions, CPU affinity, priorities, power profile and thermal state. Repeat under simultaneous camera acquisition, perception inference and expected device traffic. Keep a full histogram, observed maximum, deadline-miss count and duration with the raw trace. A test-thread latency result is evidence about that test thread, and the actuator latch still needs its own measurement.

ChannelMeasurementArtifact to keep
Kernel timer and threadIRQ latency and test-thread wake-up delay under operating loadrtla trace and affinity configuration
Application cycleScheduled release to command submission and missing releasesMonotonic timestamps keyed by cycle number
EtherCAT drive pathFrame arrival relative to drive latch and drive-reported faultsBus capture, drive diagnostics and scope trace
Physical outputOutput-event skew across drives on one independent timebaseCalibrated probe delay, scope settings and raw captures

Qualify EtherCAT distributed clock alignment at the drive

EtherCAT distributed clocks align supported SubDevice clocks to a reference clock. The MainDevice exchanges synchronization datagrams and compensates propagation delays. On compatible hardware, SYNC0 or SYNC1 can provide time-triggered events. Verify the selected drive’s synchronization mode and the documented relationship between the signal, the process-data update and the actual output latch. Record the reference-clock choice, cycle time, programmed shift time and every dual-purpose or non-DC node in the path.

Use a common oscilloscope or time interval analyzer to compare accessible receiver edges. Measure the far ends of the network and the devices with the longest or otherwise critical paths. Deskew leads against the same edge and include the instrument’s timing uncertainty. Compare matched cycle numbers and report both raw pairwise offset and the range of offset variation. If measured SYNC edges stand in for drive latches, identify that proxy explicitly.

With a strict 1 µs requirement, qualify the configured system only when the maximum observed pairwise absolute skew plus the applicable measurement uncertainty is below 1 µs, with sample count, duration, workload and excluded states declared. Record attainment after start-up, link disturbance and reconfiguration as separate tests. Inspect the working counter and drive diagnostics in the same runs. A synchronized clock can remain aligned while new process data misses its scheduled application window.

Pairwise alignment acceptance

maxₖ |t_A[k] − t_B[k]| + U_measure < 1 µs

  • A and B are matching physical receiver events for the same cycle.
  • U_measure is the elapsed-time measurement uncertainty for the test arrangement.
  • The result applies to the stated devices, operating envelope and test run.

Budget CAN FD from frame time and arbitration

CAN FD permits up to 64 data bytes. The nominal bit rate governs arbitration. Data-phase rate switching is available when the frame’s bit rate switch is enabled and the nodes and physical network support it. For every periodic or sporadic producer, record the identifier format, payload size, period or minimum inter-arrival time, transmit queue behavior and deadline. Account for frame overhead, stuffing appropriate to the frame format and bit rate phase, and the interframe interval. Model error handling and retry load separately within the stated fault envelope.

The illustrative calculation below uses deliberately assumed wire-bit counts to show sensitivity. With 45 nominal-rate bits at 500 kbit/s and 128 switched-rate bits at 4 Mbit/s, a modeled frame takes 122 µs. Twelve producers sending one such frame each at 500 Hz use 73.2% of the modeled bus interval. A second equal-rate frame per producer consumes another 73.2%, exceeding available time before diagnostic bursts. Replace the assumed bit counts with a frame-format bound or a validated CAN FD timing model before deciding how many nodes to install.

Prioritize by the CAN identifiers actually used and include host and adapter transmit queues. A lower-priority frame already on the wire can block a newly ready frame. Repeated higher-priority arrivals can delay it further. Utilization is a screening calculation. For each deadline-critical message, check response time under the worst stated burst and queue assumptions, then compare with hardware capture.

CAN FD wire-time decomposition

C_i = n_nom,i / R_nom + n_data,i / R_data

  • C_i is the modeled occupancy per frame, in s.
  • n_nom,i and n_data,i count wire bits at the nominal and switched data rates, including relevant overhead.
  • R_nom and R_data are in bit/s. Use the nominal rate throughout when the frame does not switch rate.
Periodic occupancy screen

U = Σ_i (C_i / T_i)

  • T_i is the period or minimum modeled inter-arrival interval, in s.
  • U is a dimensionless occupancy fraction for the selected traffic set.

Release checklist for timing and loss of communication

Build the traffic matrix from the firmware configuration, then verify it against the observed bus. Start with status and command traffic only, add startup bursts and service transactions, then repeat with recorded perception and compute workloads. Use a bus analyzer for wire timestamps. Verify the timestamp clock, adapter buffering behavior and any host-to-adapter offset before aligning the traces.

Keep a baseline configuration and compare every firmware, kernel, network topology or task-period change against it. Test interrupted feedback and a missed application deadline on an instrumented fixture with its independent protective system active under the site’s test procedure. Log loss detection time, commanded state, drive state and any restart authorization. Release only the stated configuration whose timing evidence and fault behavior satisfy its acceptance plan.

Test caseInspectDesign response when outside budget
Nominal periodic operationSample age, release misses, bus occupancy and latch skewReduce loop workload or redesign buffering and timing
Peak scheduled and service trafficWorst captured frame age and arbitration delay by identifierSeparate service traffic, change schedule or split buses
Long run at operating temperatureTail latency, timing faults and hardware state transitionsRecheck platform policy and measure again at the revised operating point
Loss and reacquisitionTimeout behavior, drive status, requalification and authorized resetCorrect loss handling and repeat the controlled test
Wired Hardware & Open-Source Reference Workbench

Parts, Repositories & Vendors Referenced in This Guide

Primary Technical & Institutional Sources (8)

Related engineering terms