ROS 2 Learning Path  ยท  Illustrated Educational Book

Chapter 17: CAN Bus and EtherCAT โ€” ARCHO's Communication Vessels

When WiFi and USB are no longer enough
Prerequisite: Chapter 8 (ros2_control), Chapter 16 (Hardware)
Ongoing project: ARCHO's real hardware
Industrial networks: CAN Bus, EtherCAT
Reading time: 90 to 110 minutes
What we'll cover in this chapter 17.1Why industrial robots use special-purpose networks 17.2CAN Bus: the rugged industrial network 17.3The structure of a CAN message 17.4CAN in ros2_control 17.5Common CAN errors 17.6EtherCAT: when tighter timing is required 17.7CAN or EtherCAT: which one for what job 17.8Summary, glossary, and exercises

17.1Why industrial robots use special-purpose networks

In the previous chapter we saw that ARCHO is built from three hardware layers: the Jetson, the Raspberry Pi, and a microcontroller. But how do these layers actually connect to each other and to the motor drivers? USB and WiFi aren't well suited for this job โ€” neither in terms of resistance to industrial electrical noise, nor in terms of timing reliability.

17.2CAN Bus: the rugged industrial network

๐Ÿ“– What is CAN

Controller Area Network โ€” a rugged industrial network used in automotive and robotics applications for communication between controllers.

FeatureMeaning
Differential SignalingSending the signal over two wires with opposite polarity, which creates high resistance to electrical noise
ArbitrationEvery message has a priority; if two devices send at the same time, the more important message wins
Error detectionTransmission errors are detected quickly and the message is resent
flowchart TB J["Jetson / Raspberry Pi"] --> U["USB-to-CAN"] U --> CB["CAN Bus"] CB --> M1["Motor Driver 1"] CB --> M2["Motor Driver 2"] CB --> BMS["Battery BMS"] CB --> SC["Safety Controller"] CB --> IO["IO Controller"] style CB fill:#eef0ff,stroke:#3d4bf5

17.3The structure of a CAN message

A CAN message (Frame) is usually made up of three parts:

PartMeaning
CAN IDThe message identifier, which determines both the message type and its priority
DLC (Data Length Code)The number of data bytes in this message
Data BytesThe actual payload of the message
# Sample CAN message for a motor velocity command
ID: 0x201
Data:
  [Velocity Low]
  [Velocity High]
  [Current Low]
  [Current High]
  ...

17.4CAN in ros2_control

Remember in Chapter 8 we saw that diff_drive_controller sends commands through controller_manager? On real hardware, this chain has one more layer:

flowchart TB A["diff_drive_controller"] --> B["controller_manager"] B --> C["Hardware Interface"] C --> D["SocketCAN"] D --> E["CAN Bus"] E --> F["Motor Drivers"] style C fill:#eef0ff,stroke:#3d4bf5

The Hardware Interface (which we briefly saw in Chapter 8) has two main conceptual functions on real hardware:

FunctionResponsibility
read()Reads Encoder, Velocity, Current, and Fault data from the motor driver
write()Sends Velocity Command, Torque Command, Enable, and Brake to the motor driver

17.5Common CAN errors

ErrorConsequence
Incorrect terminationSignal reflection and communication errors
Mismatched baud rate between devicesNo device can understand other devices' messages
Improper groundingExcessive noise and random errors
Duplicate IDMessage collisions and unpredictable behavior
High bus loadDelays in the delivery of critical messages
Long or unsuitable cablingSignal degradation and bit errors
Missing heartbeatThe system fails to notice when a device disconnects
Unmanaged Bus-OffThe entire network goes down after repeated errors

17.6EtherCAT: when tighter timing is required

CAN is sufficient for most mobile robots like ARCHO. But if ARCHO had a multi-axis industrial arm that needed very precise timing coordination, EtherCAT would typically be used instead.

Well suited for
Servo Drives
Multi-axis robotic arms
Simultaneous coordination of multiple axes
Precise control with very low cycle time
flowchart TB IPC["Industrial PC"] --> EM["EtherCAT Master"] EM --> D1["Servo Drive 1"] EM --> D2["Servo Drive 2"] EM --> IO["IO Module"] EM --> SM["Safety Module"] style EM fill:#f4effe,stroke:#8b5cf6

In ROS 2:

flowchart LR A["ros2_control"] --> B["EtherCAT Hardware Interface"] --> C["EtherCAT Master"] --> D["Servo Drives"]
๐Ÿ”ง Distributed Clocks: timing coordination across multiple axes

One of EtherCAT's key features is that it can synchronize the internal clocks of all drives together โ€” every axis follows a common, synchronized clock. This is essential for motions where several axes must move precisely and simultaneously in coordination (such as a multi-axis welding arm).

17.7CAN or EtherCAT: which one for what job

CAN BusEtherCAT
Speed and timing precisionSuitable for most mobile robotsMuch higher timing precision
ComplexitySimpler and cheaperMore complex and more expensive
Common use caseWheel motors, sensors, BMSIndustrial servo drives, multi-axis arms
Example in ARCHODifferential-drive wheels, Battery BMSMulti-axis coordinated pick arm

17.8Chapter 17 summary

Now you know that behind every motion command that Nav2 or MoveIt issues for ARCHO, a real industrial network โ€” CAN Bus for the wheels and sensors, or EtherCAT for a multi-axis arm โ€” delivers that command reliably and on time to the motor drivers.

โœ… Learning checkpoint
  • I can explain why CAN Bus is resistant to industrial noise.
  • I know what Arbitration does in CAN.
  • I can name at least four common CAN errors.
  • I know why EtherCAT is better suited than CAN for multi-axis coordination.
๐ŸŒ Connection to the main project

ARCHO Project now uses CAN Bus to connect the wheel drivers and Battery BMS to the Jetson, with a complete Hardware Interface that implements read() and write() over SocketCAN.

What the next chapter adds

In Chapter 18 we bring all of these layers together and see how we move from a simulated ARCHO in Gazebo to a real ARCHO running on hardware.

Chapter 17 glossary

CAN Bus
A rugged industrial network for communication between controllers, using differential signaling.
Arbitration
The mechanism for determining message priority when multiple messages are sent on CAN at the same time.
SocketCAN
The standard Linux interface for working with CAN networks like an ordinary network socket.
EtherCAT
An industrial network with very precise timing, suited for coordinated multi-axis servo control.
Distributed Clocks
EtherCAT's mechanism for synchronizing the internal clocks of multiple devices.
Bus-Off
A severe CAN error state in which a node is completely disconnected from the network.

Chapter 17 common mistakes โ€” summary