LeRobot documentation

Damiao Motors와 CAN Bus

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Damiao Motors와 CAN Bus

이 가이드는 CAN 버스 통신을 통해 LeRobot으로 Damiao 모터를 설정하고 사용하는 방법을 다룹니다.

현재 OpenArms CAN 어댑터에 Linux용 드라이버만 제공되므로 Linux만 지원됩니다.

Linux CAN 설정

Damiao 모터를 사용하기 전에 Linux 시스템에서 CAN 인터페이스를 설정해야 합니다.

CAN Utilities 설치

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 Debugging Tools를 사용하여 ID를 확인/구성합니다
  4. CAN 인터페이스 테스트: candump can0를 실행하여 메시지가 수신되는지 확인합니다
  5. 진단 실행: lerobot-setup-can --mode=test --interfaces=can0

Motor Timeout 매개변수

모터가 timeout=0으로 설정된 경우, 명령에 응답하지 않습니다. Damiao Debugging Tools를 사용하여 0이 아닌 timeout 값을 설정하세요.

CAN FD 상태 확인

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