Real-Time Control for Multi-Bus Joint Motor Drives

    Joint modules on mobile robots, collaborative arms, and legged platforms often mix EtherCAT and CAN. This article describes a practical stack—from the industrial PC and real-time OS baseline, through a bus-agnostic hardware abstraction layer, to cyclic scheduling, fault handling, and field observability—so position, velocity, and torque commands stay consistent across buses.

    1. Why Mixed Buses Are a Real Engineering Problem

    Integrated joint motors are now the default on mobile robots, collaborative arms, and legged platforms. Modules from different vendors and production batches often use different field buses: some use industrial real-time Ethernet (EtherCAT), others use CAN. EtherCAT offers high bandwidth and distributed clock synchronization, which suits high-rate closed loops. CAN is simpler to wire and cheaper, which suits slower joints and end effectors.

    The practical question is not whether the buses can be translated, but how to run them as one control system:

    • Cycle time, time base, and error models differ completely. Both must fit one control loop.
    • When several axes move together, commands issued at different instants cause jitter and mechanical shock.
    • Higher-level logic should see only position, velocity, and torque, not the bus.
    • The field system needs observability, replay, and remote diagnosis.

    The rest of this article follows one path: platform, abstraction, scheduling, then diagnostics.

    2. Hardware and System Baseline

    2.1 Industrial PC Selection

    Take a typical industrial PC with dual Ethernet ports, multiple CAN channels, serial ports, and USB. Four points matter when selecting it: whether each NIC can be bound to its own interrupt; whether the CAN controller is on-chip or PCIe and attached directly to the CPU rather than through a USB adapter; whether the CPU has enough cores and stable turbo behavior; and whether power and cooling hold up under sustained full load.

    A USB-to-CAN adapter is acceptable in the lab. Under multi-axis, high-rate control, USB scheduling jitter shows up directly on joint commands. Production designs should prefer onboard or add-in-card interfaces.

    2.2 Minimal OS Install

    A long-term-support server edition of a mainstream Linux distribution is enough. A graphical desktop is not required. Prefer a minimal image, disable unused services, pin stable names for NICs and CAN interfaces, and reserve a separate partition for logs and packet captures.

    2.3 Bringing Up CAN

    Some industrial PCs leave onboard CAN disabled in the BIOS by default. Press Del at boot, open the I/O or Onboard Devices menu, set the CAN channels to Enabled, save, and reboot. The corresponding network interfaces should then appear. Set the bit rate and termination (termination is a hardware jumper or DIP switch and must be set with power off), then bring the interface up.

    2.4 Real-Time Tuning

    Real-time behavior is the foundation. A practical order is:

    1. Install a real-time kernel patch, or the distribution’s real-time kernel variant.
    2. Isolate two or three CPU cores for the control loop; leave the rest for application work.
    3. Pin bus interrupts and the control thread to the isolated cores, and disable power-saving frequency scaling on those cores.
    4. Turn off latency-sensitive power management and background indexing.
    5. Measure cyclic latency as a baseline and confirm worst-case wake-up delay is acceptable—typically stable on the order of tens of microseconds.

    Numbers depend on hardware and load. Measure them. Do not copy someone else’s results.

    3. Layered Architecture: Keep Bus Differences in the Driver

    A four-layer stack with one-way dependencies works well:

    1. Application / business layer (task scheduling, trajectory planning)
    2. ↓
    3. Robot middleware (topics/services, parameter management)
    4. ↓
    5. Hardware abstraction layer, HAL (unified joint command and state)
    6. ↓
    7. Bus drivers (EtherCAT master / CAN driver / their own cyclic tasks)

    The HAL exposes only bus-independent semantics. The sketch below shows structure, not a real API:

    1. struct JointCommand {
    2. float position; // rad
    3. float velocity; // rad/s
    4. float torque; // N·m
    5. uint8_t control_mode;
    6. };
    7. struct JointState {
    8. float position, velocity, torque;
    9. float temperature;
    10. uint16_t error_code;
    11. bool enabled;
    12. };
    13. class IJointBus {
    14. public:
    15. virtual bool init() = 0;
    16. virtual void cyclicExchange(const JointCommand* cmd,
    17. JointState* state,
    18. size_t n) = 0;
    19. virtual uint64_t lastCycleTimestampNs() const = 0;
    20. };

    EtherCAT and CAN each implement this interface. Upper layers can switch or mix buses without code changes.

    4. How the Two Buses Differ

    4.1 EtherCAT

    Use an open-source master. The NIC must be dedicated to the master. Organize the loop as send, wait, receive. Map process data (PDOs) once during initialization; at runtime the cycle is a memory-copy exchange. For many axes, map every slave’s inputs and outputs into one contiguous buffer to cut copy and traversal cost.

    4.2 CAN

    CAN has no built-in distributed clock, so the time base has to be designed. Use the control thread’s monotonic clock as the only time base and transmit each joint’s command frame at a fixed phase. For joints that must stay in sync, use a soft scheme: a broadcast sync frame plus local phase lock on each joint. Bus load must be managed so arbitration does not push the cycle past its deadline.

    4.3 One Time Base

    Both buses are normalized to the control thread’s monotonic clock. Record a timestamp at the end of every cycle so higher layers can analyze latency and align recordings.

    5. Cyclic Scheduling and the Joint State Machine

    Prefer a timed wait that advances an absolute deadline. Relative sleep accumulates drift:

    1. auto next = steady_clock::now();
    2. while (running) {
    3. auto now = steady_clock::now();
    4. if (now < next) sleep_until(next);
    5. next += period; // advance absolute time to avoid drift
    6. if (now - next > period) { // too far behind: count an overrun
    7. stats.overrun++;
    8. }
    9. hal->cyclicExchange(cmd, state, n);
    10. publish(state); // async publish into the middleware
    11. }

    Each joint keeps a state machine: uninitialized, powered, enabled, running, fault, reset. Every illegal transition must be logged. Do not drop it silently.

    6. Fault Handling and Safety

    • Watchdogs: timeout checks on both master and slave. On timeout, cut torque to a safe state immediately.
    • Error classes: recoverable (communication jitter), reset required (slave drop), stop required (over-temperature, over-current).
    • Reconnect: on CAN, automatically resend the init sequence; on EtherCAT, rebuild the process-data map.
    • Logs and captures: write through a ring buffer on the local machine so disk I/O never blocks the control thread.

    7. Observability and Cloud Support

    After deployment, aggregate joint state, cycle overrun rate, bus load, and temperature locally, then upload only what is needed. Generic cloud building blocks fit this role: a message queue for buffering and decoupling, object storage for capture archives, a container platform for analysis services, and logging plus monitoring for threshold alerts. General-purpose products from vendors such as Baidu AI Cloud can serve as that base. Choose them from measurement and cost, not from a default.

    8. Common Pitfalls

    1. Allocating memory, printing logs, or doing file I/O on the control thread.
    2. Using relative sleep and letting the cycle drift.
    3. Missing or duplicated CAN termination, which causes intermittent frame loss.
    4. Leaving CPUs unisolated so background tasks preempt the loop.
    5. Leaking bus differences into upper layers and coupling business code to hardware.
    6. Testing function only, and skipping worst-case latency and long-run stability tests.

    9. Closing

    The method for multi-bus joint drives is short: put real-time behavior in the platform, confine differences to the driver layer, and build observability into the architecture. Follow that path and the same framework extends from two buses to more heterogeneous ones.