LeRobot documentation

Damiao Motors 与 CAN 总线

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Damiao Motors 与 CAN 总线

本指南介绍了如何通过 CAN 总线通信在 LeRobot 中设置和使用 Damiao 电机。

目前仅支持 Linux,因为 OpenArms CAN 适配器仅提供 Linux 驱动程序。

Linux CAN 设置

在使用 Damiao 电机之前,您需要在 Linux 系统上配置 CAN 接口。

安装 CAN 实用工具

sudo apt-get install can-utils

配置 CAN 接口(手动)

对于标准 CAN FD(推荐用于 OpenArms):

sudo ip link set can0 down
sudo ip link set can0 type can bitrate 1000000 dbitrate 5000000 fd on
sudo ip link set can0 up

对于标准 CAN(不带 FD):

sudo ip link set can0 down
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up

配置 CAN 接口(使用 LeRobot)

LeRobot 提供了一个实用脚本,用于设置和测试 CAN 接口:

# Setup multiple interfaces (e.g., OpenArms Followers with 2 CAN buses)
lerobot-setup-can --mode=setup --interfaces=can0,can1

调试 CAN 通信

使用内置的调试工具来测试电机通信:

# Test motors on all interfaces
lerobot-setup-can --mode=test --interfaces=can0,can1

# Run speed/latency test
lerobot-setup-can --mode=speed --interfaces=can0

测试模式将扫描电机(ID 0x01-0x08)并报告哪些电机有响应。输出示例:

can0: UP (CAN FD)
  Motor 0x01 (joint_1): ✓ FOUND
    → Response 0x11 [FD]: 00112233...
  Motor 0x02 (joint_2): ✓ FOUND
  Motor 0x03 (joint_3): ✗ No response
  ...
  Summary: 2/8 motors found

用法

基础设置

from lerobot.motors import Motor
from lerobot.motors.damiao import DamiaoMotorsBus

# Define your motors with send/receive CAN IDs
motors = {
    "joint_1": Motor(id=0x01, motor_type_str="dm8009", recv_id=0x11),
    "joint_2": Motor(id=0x02, motor_type_str="dm4340", recv_id=0x12),
    "joint_3": Motor(id=0x03, motor_type_str="dm4310", recv_id=0x13),
}

# Create the bus
bus = DamiaoMotorsBus(
    port="can0",  # Linux socketcan interface
    motors=motors,
)

# Connect
bus.connect()

读取电机状态

# Read single motor position (degrees)
position = bus.read("Present_Position", "joint_1")

# Read from multiple motors
positions = bus.sync_read("Present_Position")  # All motors
positions = bus.sync_read("Present_Position", ["joint_1", "joint_2"])

# Read all states at once (position, velocity, torque)
states = bus.sync_read_all_states()
# Returns: {'joint_1': {'position': 45.2, 'velocity': 1.3, 'torque': 0.5}, ...}

编写电机指令

# Enable torque
bus.enable_torque()

# Set goal position (degrees)
bus.write("Goal_Position", "joint_1", 45.0)

# Set positions for multiple motors
bus.sync_write("Goal_Position", {
    "joint_1": 45.0,
    "joint_2": -30.0,
    "joint_3": 90.0,
})

# Disable torque
bus.disable_torque()

配置选项

参数默认描述
port-CAN 接口(can0)或串行端口(/dev/cu.usbmodem*)
use_can_fdTrue启用 CAN FD 以实现更高的数据速率
bitrate1000000标称比特率 (1 Mbps)
data_bitrate5000000CAN FD 数据比特率 (5 Mbps)

电机配置

每个电机需要:

  • id:用于发送命令的 CAN ID
  • motor_type:受支持的电机类型之一(例如 "dm8009"、"dm4340")
  • recv_id:用于接收响应的 CAN ID

OpenArms 默认 ID 遵循以下模式:发送 ID 为 0x0N,接收 ID 为 0x1N,其中 N 为关节编号。

故障排除

电机无响应

  1. 检查电源
  2. Verify CAN wiring: Check CAN-H, CAN-L, and GND connections
  3. 检查电机 ID:使用 Damiao 调试工具来验证/配置 ID
  4. 测试 CAN 接口:运行 candump can0 以查看是否正在接收消息
  5. 运行诊断:lerobot-setup-can --mode=test --interfaces=can0

Motor 超时参数

如果电机配置为 timeout=0,它们将不会响应命令。请使用 Damiao 调试工具设置一个非零的超时值。

验证 CAN FD 状态

ip -d link show can0 | grep fd
Update on GitHub