LeRobot 文件
Damiao 馬達與 CAN 匯流排
立即開始
教學課程
機器人模仿學習使用自備策略 (Bring Your Own Policies)使用自備硬體 (Bring Your Own Hardware)以增強學習訓練機器人在模擬環境中訓練增強學習多 GPU 訓練人機協作 (Human-in-the-Loop) 資料收集使用 PEFT(例如 LoRA)進行訓練使用 Rename Map 與空白相機
資料集 (Datasets)
策略
獎勵模型
推論
模擬
基準測試 (Benchmarks)
機器人處理器
機器人
遙控操作員
感測器
支援的硬體
資源
關於
加入 Hugging Face 社群
並獲得增強的文件體驗
開始使用
大淼(Damiao)電機與 CAN Bus
本指南介紹如何透過 CAN bus 通訊將大淼(Damiao)電機與 LeRobot 進行設定與使用。
目前僅支援 Linux,因為 OpenArms CAN 轉接器目前僅提供 Linux 驅動程式。
Linux CAN 設定
在使用大淼電機前,您需要先在 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_fd | True | 啟用 CAN FD 以獲得更高的資料傳輸速率 |
bitrate (位元率) | 1000000 | 標稱位元率 (1 Mbps) |
data_bitrate (資料位元率) | 5000000 | CAN FD 資料位元率 (5 Mbps) |
電機設定
每個電機需要:
id: 用於發送指令的 CAN IDmotor_type: 支援的電機類型之一 (例如"dm8009","dm4340")recv_id: 用於接收回傳訊號的 CAN ID
OpenArms 預設 ID 遵循以下模式:發送 ID 為 0x0N,接收 ID 為 0x1N,其中 N 為關節編號。
疑難排解
電機無回應
- 檢查電源
- 確認 CAN 接線:檢查 CAN-H、CAN-L 和 GND 連接
- 檢查電機 ID:使用大淼除錯工具來驗證/配置 ID
- 測試 CAN 介面:執行
candump can0查看是否有訊息傳入 - 執行診斷:
lerobot-setup-can --mode=test --interfaces=can0
電機逾時參數
如果電機被設定為 timeout=0,它們將不會回應指令。請使用大淼除錯工具設定一個非零的逾時值。
驗證 CAN FD 狀態
ip -d link show can0 | grep fd