[CAN 01] - What is CAN?

What is CAN Bus and how is it used in robotics?

Introduction

This is the first note in the CAN Bus for Robotic Hardware series. The series walks through CAN from basic bus concepts to Linux SocketCAN setup, ESP32 communication, gripper motor control, PCAN drivers, ROS 2 Control integration, and practical hardware debugging.

What is Controller Area Network (CAN)?

CAN, short for Controller Area Network, is a communication protocol widely used in the automotive industry due to its robustness, safety, and reliability. It allows multiple electronic devices, such as sensors and motor controllers, to communicate in real time over a shared bus without a central master device.

CAN is designed for harsh environments and can transmit data over long distances, typically from tens of meters up to around one kilometer depending on bitrate, wiring quality, termination, and noise conditions.

How is it used in Robotics?

In robotics, the Controller Area Network (CAN) is widely adopted for real-time communication between a host computer and motor driver modules. For complex robots like multi-DOF manipulators or legged robots, each motor driver module typically includes a microcontroller running control algorithms, such as Field-Oriented Control (FoC), to accurately control BLDC (Brushless DC) motors. In this setup, the microcontroller in each motor module calculates the PWM (Pulse Width Modulation) signals needed to control motor phases and achieve the desired movements. These PWM signals are then sent to motor drivers, such as the DRV8313, which uses them to drive the motor’s three phases. The control loop for each motor typically runs at a high frequency over 1 kHz, and a lot of motor driver modules such as ODrive, Mjbots, etc. include CAN controller and transceiver to enable the communication between the microcontroller and host computer.

CAN Bus

The CAN bus can also support real-time, high-frequency impedance control by closing the control loop through the CAN bus itself, rather than solely relying on the control loop inside the microcontroller in the driver module. Impedance control plays a crucial role for robots that need to adapt their flexibility when interacting with dynamic environments or external forces. This adaptability is especially valuable for legged robots that frequently make and break contact with the environment. Impedance control allows these robots to safely absorb impact upon contact. Legged robots can navigate challenging terrains, avoid obstacles, and maintain balance by constantly adjusting their feed-forward torque and impedance gains.

\(\tau = M(q)\ddot{q} + D(\dot{q}_{d} - \dot{q}) + K(q_{d} - q) + g(q)\)

Joint Impedance Control Loop where M is the mass matrix, D is the damping matrix, K is the stiffness matrix, and g is the gravity vector with the generalized coordinates q. K and D are the impedance gains which determine the behavior of the joint when external forces are applied.

For example, MIT mini cheetah robot uses CAN bus to communicate with the motor driver modules to achieve real-time impedance control.

MIT Mini Cheetah

This awesome open-source quadruped robot’s communication structure have been adopted by many other actuators and robot companies.

Limitation of CAN Bus in Robotics

Mini Cheetah has 4 CAN channels while 3 motors are connected to each channel to control total 12 motors. This is one of the limitation of using CAN bus for real-time control robots. The maximum baudrate of CAN bus is 1 Mbps, and the bus can be easily overloaded when the number of motors increases in high control frequency. Assuming the control loop is running at 1 kHz with a tyical non-RTR standard CAN frame with 11 bits of data, the CAN bus is populated with 22,000 bps with command frame and response frame of a single actuator. This is approximately 22.2% of the 1 Mbps CAN bus. Since it’s recommended to keep the CAN bus load less than 70~80%, the maximum number of actuators that can be connected to a single CAN channel is 3. Decreasing the control loop frequencty will reduce the load on the CAN bus, but lower control loop frequency will not only reduce the performance but also increase the instability of the robot.