Skip to main content
The lerobot-setup-can command helps setup and debug CAN (Controller Area Network) interfaces for Damiao motors used in robots like OpenArms.

Command

Location: src/lerobot/scripts/lerobot_setup_can.py

Overview

This utility:
  • Configures CAN interfaces with CAN FD support
  • Tests motor connectivity on CAN bus
  • Performs speed and latency benchmarks
  • Supports multiple CAN interfaces (can0, can1, can2, can3)
  • Validates Damiao motor communication

Key Options

str
default:"test"
Operation mode: setup, test, or speed.
str
default:"can0"
Comma-separated CAN interface names (e.g., "can0,can1,can2,can3").
int
default:"1000000"
CAN bitrate in bits/second (1 Mbps default).
int
default:"5000000"
CAN FD data bitrate in bits/second (5 Mbps default).
bool
default:"true"
Enable CAN FD (Flexible Data-rate).
list[int]
default:"[1,2,3,4,5,6,7,8]"
Motor IDs to test (0x01-0x08).
float
default:"1.0"
Motor response timeout in seconds.
int
default:"100"
Number of iterations for speed test.

Usage Examples

Setup CAN Interfaces

Configure CAN interfaces with CAN FD:
This:
  • Sets bitrate to 1 Mbps
  • Sets data bitrate to 5 Mbps (CAN FD)
  • Brings up all specified interfaces
  • Requires sudo permissions

Test Motors on Single Interface

Tests motors 0x01-0x08 on can0 and reports:
  • Which motors respond
  • Response data from each motor
  • Summary of found motors

Test Motors on All Interfaces

Tests all four CAN interfaces and shows motors on each bus.

Speed Test

Benchmark communication speed:
Reports:
  • Average latency (ms)
  • Success rate
  • Maximum achievable frequency (Hz)

Custom Configuration

Mode Details

Setup Mode

Configures CAN interfaces:
Executes:
  1. Brings down interface: sudo ip link set can0 down
  2. Configures CAN: sudo ip link set can0 type can bitrate 1000000 dbitrate 5000000 fd on
  3. Brings up interface: sudo ip link set can0 up
Output:

Test Mode

Tests motor connectivity:
For each motor:
  1. Sends enable command (0xFC)
  2. Waits for response
  3. Sends disable command (0xFD)
  4. Reports findings
Output:

Speed Mode

Benchmarks communication performance:
Output:

Motor Mapping

Default motor ID to joint mapping:

Troubleshooting

Interface Not Found

Output:
Causes:
  • CAN hardware not connected
  • Wrong interface name
  • Driver not loaded
Solutions:

Permission Denied

Error:
Solution: Run with sudo or configure sudo access:

No Motors Found

Output:
Solutions:
  1. Check Power: Ensure motors have 24V power
  2. Check Wiring:
    • CANH connected to CANH
    • CANL connected to CANL
    • GND connected
  3. Check Termination: 120Ω resistors at both cable ends
  4. Check Motor Configuration: Use Damiao software to verify:
    • Motor IDs are correct (0x01-0x08)
    • Timeout parameter > 0
    • Motors are in correct mode
  5. Test Interface:

Connection Timeouts

Cause: CAN interface configuration or hardware issues. Solutions:

Slow Communication

Speed test shows low frequency:
Solutions:
  • Use CAN FD: --use_fd=true
  • Increase data bitrate: --data_bitrate=5000000
  • Check cable quality (use short, high-quality cables)
  • Reduce number of motors per bus
  • Check CPU load during operation

Hardware Setup

CAN Bus Wiring

Termination Resistors

  • Place 120Ω resistors at both ends of the CAN bus
  • Required for signal integrity
  • Without termination: reflections cause errors

Cable Recommendations

  • Use twisted pair cable (CANH/CANL)
  • Keep cables short (under 5 meters ideal)
  • Use shielded cable in noisy environments
  • Connect shield to GND at one end only

Advanced Usage

Test Specific Motors

Tests only motors 0x01, 0x02, 0x05, 0x08.

Extended Speed Test

Runs 1000 iterations for more accurate benchmarking.

Disable CAN FD

For compatibility with older devices:

See Also