LeRobot 文件

Damiao 馬達與 CAN 匯流排

Hugging Face's logo
加入 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 ID
  • motor_type: 支援的電機類型之一 (例如 "dm8009", "dm4340")
  • recv_id: 用於接收回傳訊號的 CAN ID

OpenArms 預設 ID 遵循以下模式:發送 ID 為 0x0N,接收 ID 為 0x1N,其中 N 為關節編號。

疑難排解

電機無回應

  1. 檢查電源
  2. 確認 CAN 接線:檢查 CAN-H、CAN-L 和 GND 連接
  3. 檢查電機 ID:使用大淼除錯工具來驗證/配置 ID
  4. 測試 CAN 介面:執行 candump can0 查看是否有訊息傳入
  5. 執行診斷lerobot-setup-can --mode=test --interfaces=can0

電機逾時參數

如果電機被設定為 timeout=0,它們將不會回應指令。請使用大淼除錯工具設定一個非零的逾時值。

驗證 CAN FD 狀態

ip -d link show can0 | grep fd
在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.