在Linux上通过CAN总线配置达妙电机

该资料介绍在LeRobot框架下通过CAN总线连接达妙电机的配置流程,涵盖Linux CAN接口初始化、调试工具使用、电机参数设置及常见无响应问题的排查方向,并说明当前仅支持Linux平台。

# 达米奥汽车和CAN型客车 本指南通过CAN公交车通信,涵盖了使用LeRobot的达米奥电动机的设置和使用. 目前,只支持Linux,因为OpenArms CAN适配器只有Linux的驱动程序. ## Linux CAN 设置 在使用达米奥电动机之前,需要在你的Linux系统上设置CAN接口. ### 安装 CAN 公用事业 ```bash sudo apt-get install can-utils ``` ### 配置 CAN 接口( 手工) 用于标准CAN FD(建议为OpenArms): ```bash 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): ```bash sudo ip link set can0 down sudo ip link set can0 type can bitrate 1000000 sudo ip link set can0 up ``` ### 配置 CAN 接口( Using LeRobot ) LeRobot提供了一个用于设置和测试CAN接口的实用脚本: ```bash # Setup multiple interfaces (e.g., OpenArms Followers with 2 CAN buses) lerobot-setup-can --mode=setup --interfaces=can0,can1 ``` ## 调试 CAN 通信 使用内置调试工具测试电动机通信: ```bash # Test motors on all interfaces lerobot-setup-can --mode=test --interfaces=can0,can1 # Run speed/latency test lerobot-setup-can --mode=speed --interfaces=can0 ``` 测试模式将扫描马达(IDs 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 ``` ## 使用量 ### 基本设置 ```python 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() ``` ### 读取汽车国家 ```python # 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}, ...} ``` ### 写入汽车命令 ```python # 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. **检查车牌**: 使用 Damio 调试工具验证/配置ID 4. **测试 CAN 接口**: 运行 `candump can0` 以查看是否收到信件 5. **运行诊断**: `lerobot-setup-can --mode=test --interfaces=can0` ### 汽车超时参数 如果马达被配置为超时=0,它们不会响应命令. 使用达米奥调试工具设置非零超时值. ### 验证 CAN FD 状态 ```bash ip -d link show can0 | grep fd ```

查看原始来源