lerobot-setup-can command helps setup and debug CAN (Controller Area Network) interfaces for Damiao motors used in robots like OpenArms.
Command
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:- 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
- Which motors respond
- Response data from each motor
- Summary of found motors
Test Motors on All Interfaces
Speed Test
Benchmark communication speed:- Average latency (ms)
- Success rate
- Maximum achievable frequency (Hz)
Custom Configuration
Mode Details
Setup Mode
Configures CAN interfaces:- Brings down interface:
sudo ip link set can0 down - Configures CAN:
sudo ip link set can0 type can bitrate 1000000 dbitrate 5000000 fd on - Brings up interface:
sudo ip link set can0 up
Test Mode
Tests motor connectivity:- Sends enable command (0xFC)
- Waits for response
- Sends disable command (0xFD)
- Reports findings
Speed Mode
Benchmarks communication performance:Motor Mapping
Default motor ID to joint mapping:Troubleshooting
Interface Not Found
Output:- CAN hardware not connected
- Wrong interface name
- Driver not loaded
Permission Denied
Error:No Motors Found
Output:- Check Power: Ensure motors have 24V power
- Check Wiring:
- CANH connected to CANH
- CANL connected to CANL
- GND connected
- Check Termination: 120Ω resistors at both cable ends
- Check Motor Configuration: Use Damiao software to verify:
- Motor IDs are correct (0x01-0x08)
- Timeout parameter > 0
- Motors are in correct mode
- Test Interface:
Connection Timeouts
Cause: CAN interface configuration or hardware issues. Solutions:Slow Communication
Speed test shows low frequency:- 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
Extended Speed Test
Disable CAN FD
For compatibility with older devices:See Also
- OpenArm Documentation
- Damiao Motor Documentation
- Linux SocketCAN
- Robot API - Robot control interface