2026-06-30 16:04:36 +08:00
|
|
|
|
# EtherCAT 电机接入教程
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
当前 EtherCAT CoE + CiA402 驱动包含意优和同川两种厂商适配:
|
|
|
|
|
|
|
|
|
|
|
|
| 厂商 | 配置枚举 | ESI 资料 | RxPDO / TxPDO |
|
|
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
|
|
| 意优 | `MOTOR_VENDOR_EYOU` | `docs/EYOU_ServoModule_ECAT_V145_no_slot.xml` | `0x1600 / 0x1A00` |
|
|
|
|
|
|
| 同川 TCHL | `MOTOR_VENDOR_TCHL` | `docs/TC-TECH_TC600E_TR_1.5.xml` | `0x1601 / 0x1A01` |
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
ESI XML 作为厂商通信说明和对照资料保存,运行时不直接解析 XML。实际 PDO 映射写在:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```text
|
|
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/vendor/eyou/eyou_cia402_pdo_mapping.h
|
2026-10-27 17:01:20 +08:00
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/vendor/tchl/tchl_cia402_pdo_mapping.h
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
## 1. 系统依赖
|
|
|
|
|
|
|
|
|
|
|
|
IgH EtherCAT userspace 已安装在:
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
dependency/x86/third_party/ethercat/v1.7.0
|
2026-06-30 16:04:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
真机运行前,系统里还需要安装/加载 IgH master 内核模块。使用仓库脚本启动 EtherCAT master:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```bash
|
2026-10-27 17:01:20 +08:00
|
|
|
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
|
|
|
|
|
scripts/ethercat/status_ethercat.sh
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
其中 `eno1` 是连接 EtherCAT 从站的网卡。脚本会读取该网卡 MAC,写入:
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
dependency/x86/third_party/ethercat/v1.7.0/etc/ethercat.conf
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
并通过 bundled IgH 的 `ethercatctl -c` 启动 master。确认目标从站的身份和位置后再启动程序。
|
2026-07-09 14:22:35 +08:00
|
|
|
|
|
|
|
|
|
|
停止 EtherCAT:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-10-27 17:01:20 +08:00
|
|
|
|
sudo scripts/ethercat/stop_ethercat.sh eno1
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
如果这张网卡要恢复给普通网络使用:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-10-27 17:01:20 +08:00
|
|
|
|
sudo scripts/ethercat/stop_ethercat.sh eno1 --restore-network
|
2026-07-09 14:22:35 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 2. 电机配置
|
|
|
|
|
|
|
|
|
|
|
|
新增或修改:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
cmvr-es/config/devices/motor/ethercat_motors.pb.txt
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
|
|
|
|
|
|
|
```proto
|
|
|
|
|
|
motor {
|
|
|
|
|
|
id: "ethercat_motors"
|
|
|
|
|
|
|
|
|
|
|
|
motor_groups {
|
|
|
|
|
|
id: "right_arm_ethercat"
|
|
|
|
|
|
bus_type: MOTOR_BUS_ETHERCAT
|
2026-07-09 14:22:35 +08:00
|
|
|
|
vendor: MOTOR_VENDOR_EYOU
|
2026-06-30 16:04:36 +08:00
|
|
|
|
protocol: MOTOR_PROTOCOL_ETHERCAT_CIA402
|
|
|
|
|
|
|
|
|
|
|
|
ethercat {
|
2026-07-09 14:22:35 +08:00
|
|
|
|
master_index: 0
|
2026-06-30 16:04:36 +08:00
|
|
|
|
cycle_us: 1000
|
2026-10-27 17:01:20 +08:00
|
|
|
|
slave_op_timeout_ms: 12000
|
|
|
|
|
|
slave_state_poll_period_ms: 10
|
2026-07-09 14:22:35 +08:00
|
|
|
|
|
|
|
|
|
|
cia402 {
|
|
|
|
|
|
state_transition_timeout_ms: 1200
|
|
|
|
|
|
velocity_stop_timeout_ms: 2000
|
|
|
|
|
|
status_poll_period_ms: 10
|
|
|
|
|
|
stopped_velocity_tolerance_rad_s: 0.001
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-30 14:11:38 +08:00
|
|
|
|
zero_calibration {
|
|
|
|
|
|
timeout_ms: 2000
|
|
|
|
|
|
poll_period_ms: 10
|
|
|
|
|
|
stable_sample_count: 5
|
|
|
|
|
|
position_tolerance_counts: 10000
|
|
|
|
|
|
stable_delta_counts: 1000
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
dc { enable: false }
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
slaves { motor_id: 1 alias: 0 position: 0 }
|
|
|
|
|
|
slaves { motor_id: 2 alias: 0 position: 1 }
|
|
|
|
|
|
slaves { motor_id: 3 alias: 0 position: 2 }
|
|
|
|
|
|
slaves { motor_id: 4 alias: 0 position: 3 }
|
|
|
|
|
|
slaves { motor_id: 5 alias: 0 position: 4 }
|
|
|
|
|
|
slaves { motor_id: 6 alias: 0 position: 5 }
|
|
|
|
|
|
slaves { motor_id: 7 alias: 0 position: 6 }
|
2026-06-30 16:04:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
joint_limits {
|
|
|
|
|
|
enable: true
|
|
|
|
|
|
source: JOINT_LIMIT_SOURCE_CUSTOM
|
|
|
|
|
|
joints { joint_name: "R_SHOULDER_P" q_lb: -3.14 q_ub: 3.14 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_SHOULDER_R" q_lb: -0.78 q_ub: 1.57 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_SHOULDER_Y" q_lb: -3.14 q_ub: 3.14 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_ELBOW_R" q_lb: 0 q_ub: 2.05 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_WRIST_P" q_lb: -3.14 q_ub: 3.14 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_WRIST_Y" q_lb: -0.78 q_ub: 0.78 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
joints { joint_name: "R_WRIST_R" q_lb: -0.57 q_ub: 1.57 qd: 5.0 qdd: 10.0 }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
motors {
|
2026-07-09 14:22:35 +08:00
|
|
|
|
motors { id: 1 joint_name: "R_SHOULDER_P" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 2 joint_name: "R_SHOULDER_R" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 3 joint_name: "R_SHOULDER_Y" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 4 joint_name: "R_ELBOW_R" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 5 joint_name: "R_WRIST_P" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 6 joint_name: "R_WRIST_Y" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
|
|
|
|
|
motors { id: 7 joint_name: "R_WRIST_R" encoder_counts_per_rev: 65536 gear_ratio: 101.0 }
|
2026-06-30 16:04:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
字段说明:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- `master_index`:IgH master 编号,第一张 EtherCAT master 是 `0`。
|
2026-10-27 17:01:20 +08:00
|
|
|
|
- `slave_op_timeout_ms`、`slave_state_poll_period_ms`:进入 OP 的等待超时和状态查询周期,均需显式配置正值。
|
|
|
|
|
|
- `dc`:必须显式配置是否启用;启用时还需提供参考从站、Sync0 周期和偏移、同步周期及 `assign_activate` 等字段。
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- `alias`:EtherCAT alias,一般为 `0`。
|
|
|
|
|
|
- `position`:slave 在 EtherCAT 链路上的顺序,从 `0` 开始。
|
|
|
|
|
|
- `motor_id`:系统内电机 id,必须和 `motors.motors.id` 对应。
|
2026-10-27 17:01:20 +08:00
|
|
|
|
- `encoder_counts_per_rev`、`gear_ratio`:两者乘积表示关节输出轴每转对应的驱动器位置单位数。驱动器使用电机端原始计数时,分别填写电机编码器每转计数和机械减速比;其他单位设置见下方同川说明。
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
## 3. 注册设备
|
|
|
|
|
|
|
|
|
|
|
|
修改:
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
cmvr-es/config/manager/device_manager.pb.txt
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
加入:
|
|
|
|
|
|
|
|
|
|
|
|
```proto
|
|
|
|
|
|
devices {
|
|
|
|
|
|
id: "ethercat_motors"
|
|
|
|
|
|
type: MOTOR_SYSTEM
|
|
|
|
|
|
enable: true
|
|
|
|
|
|
config_file: "devices/motor/ethercat_motors.pb.txt"
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
## 4. 机械臂使用 EtherCAT 电机
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
修改机械臂配置中的 motor backend:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```proto
|
|
|
|
|
|
motor {
|
|
|
|
|
|
motor_system_id: "ethercat_motors"
|
|
|
|
|
|
motor_group_ids: "right_arm_ethercat"
|
|
|
|
|
|
joint_names: "R_SHOULDER_P"
|
|
|
|
|
|
joint_names: "R_SHOULDER_R"
|
|
|
|
|
|
joint_names: "R_SHOULDER_Y"
|
|
|
|
|
|
joint_names: "R_ELBOW_R"
|
|
|
|
|
|
joint_names: "R_WRIST_P"
|
|
|
|
|
|
joint_names: "R_WRIST_Y"
|
|
|
|
|
|
joint_names: "R_WRIST_R"
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
### 七轴同川纯 MoveJ
|
|
|
|
|
|
|
|
|
|
|
|
使用以下配套配置:
|
|
|
|
|
|
|
|
|
|
|
|
- 电机:`cmvr-es/config/devices/motor/tchl_multi_motors.pb.txt`。
|
|
|
|
|
|
- 机械臂:`cmvr-es/config/devices/arm/tchl_arm.pb.txt`。
|
|
|
|
|
|
|
|
|
|
|
|
七个关节按 `TCHL_AXIS_1` 至 `TCHL_AXIS_7` 排列,对应从站 `position: 0` 至 `6`。
|
|
|
|
|
|
电机组及 MotorManager 的 ID 为 `tchl_joint_motors`,Arm 的 ID 为 `tchl_arm`。
|
|
|
|
|
|
DeviceManager 已登记这两个设备,默认 `enable: false`;启用前填写各轴实际换算参数及限位。
|
|
|
|
|
|
|
|
|
|
|
|
纯 MoveJ 配置可以省略 `kinematics`、`joint_path`、`move_l`、`speed_l`,无需加载 URDF。
|
|
|
|
|
|
省略整个 `joint_trajectory_smoother` 时,默认使用五次 B 样条,采样周期为 `0.001 s`,控制点间距为 `0.05 rad`。
|
|
|
|
|
|
没有运动学配置时,Arm 初始化会读取电机缓存的配置限位;MoveJ 使用其中的位置、速度上限,
|
|
|
|
|
|
并将请求加速度收紧至各轴已配置的正加速度上限中的最小值。限位不是从驱动器读回的值。
|
|
|
|
|
|
已有运动学配置继续使用原来的 IK 位置、速度限位。显式配置 `move_l`、`speed_l` 或 `joint_path` 时仍需提供运动学配置。
|
|
|
|
|
|
|
|
|
|
|
|
先初始化 MotorManager,再初始化 MotorRobotArm 并调用 `torqueOn()`。随后可调用:
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
MotionOptions options;
|
|
|
|
|
|
options.velocity = 0.2; // rad/s
|
|
|
|
|
|
options.acceleration = 0.5; // rad/s^2
|
|
|
|
|
|
options.jerk = 5.0; // rad/s^3
|
|
|
|
|
|
auto result = arm.moveJ(
|
|
|
|
|
|
JointPositionCommand{{0.1, -0.1, 0.1, -0.1, 0.1, -0.1, 0.1}}, options);
|
|
|
|
|
|
if (!result.ok()) {
|
|
|
|
|
|
std::cerr << result.message << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
目标为输出轴绝对角度,顺序与 Arm 的 `joint_names` 一致。MoveJ 通过批量 CSP 下发,调用会等待轨迹完成及反馈稳定。
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
## 5. 代码结构
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
EtherCAT 总线运行时:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
cmvr-es/devices/motor/bus_runtime/ethercat/include/ethercat_motor_bus_runtime.h
|
|
|
|
|
|
cmvr-es/devices/motor/bus_runtime/ethercat/src/ethercat_motor_bus_runtime.cpp
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
它负责:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- 打开 IgH master
|
|
|
|
|
|
- 创建 domain
|
2026-10-27 17:01:20 +08:00
|
|
|
|
- 使用 `MotorManager` 按 `vendor + protocol` 选定的 PDO mapping 配置从站
|
|
|
|
|
|
- 按 mapping 配置对应的 RxPDO / TxPDO
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- 注册每个非 padding PDO entry 的 offset
|
|
|
|
|
|
- 启动 cyclic loop
|
|
|
|
|
|
- 按 `motor_id + index + subindex` 提供通用 PDO 读写接口
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
公共电机层和 CiA402 协议层:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```text
|
2026-10-27 17:01:20 +08:00
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/ethercat_motor.h
|
|
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/src/ethercat_motor.cpp
|
2026-07-09 14:22:35 +08:00
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/cia402/cia402_protocol.h
|
|
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/cia402/cia402_objects.h
|
|
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/include/vendor/motor_vendor_adapter.h
|
|
|
|
|
|
cmvr-es/devices/motor/drivers/ethercat_motor/src/cia402/cia402_protocol.cpp
|
2026-06-30 16:04:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
继承与调用关系:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```text
|
2026-10-27 17:01:20 +08:00
|
|
|
|
AbstractMotor
|
|
|
|
|
|
└── EthercatMotor:公共配置、单位换算、多轴批量命令和反馈
|
|
|
|
|
|
├── EyouMotor:组合 EyouMotorAdapter
|
|
|
|
|
|
└── TchlMotor:组合 TchlMotorAdapter
|
|
|
|
|
|
|
|
|
|
|
|
厂家 Motor → 共享 Cia402Protocol → EthercatMotorBusRuntime
|
|
|
|
|
|
厂家 Motor → 厂家 Adapter → EthercatMotorBusRuntime
|
2026-06-30 16:04:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
`Cia402Protocol` 负责:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- CiA402 `6040/6041` 状态机
|
|
|
|
|
|
- 设置 `6060` 运行模式
|
2026-10-27 17:01:20 +08:00
|
|
|
|
- PP、PV、PT、CSP、CSV、CST 的目标值和模式切换
|
|
|
|
|
|
- 根据映射选择 CSP 速度前馈对象;PP/PV 轮廓参数通过 SDO 下发
|
2026-07-09 14:22:35 +08:00
|
|
|
|
- 读 `6064/606C/6077/603F`
|
|
|
|
|
|
- `rad` 和 encoder count 的换算
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
2026-10-27 17:01:20 +08:00
|
|
|
|
各厂家文件分别位于 `include/vendor/eyou`、`src/vendor/eyou` 和 `include/vendor/tchl`、`src/vendor/tchl`。按完整操作划分职责:通用控制由 Protocol 完成;厂家限位、抱闸、校准及同川使能/失能由 Adapter 完成。Adapter 内部可以访问标准对象,以保留厂家要求的步骤和顺序;Protocol 与 Adapter 都只依赖 Runtime,互不持有或调用。
|
|
|
|
|
|
|
|
|
|
|
|
Motor 负责加锁、参数换算和分发,同一个功能只调用其中一层。例如位置限位直接委托 Adapter,避免 Motor 先通过 Protocol 写一遍 `607D`。校准后的目标同步、软限位恢复和失败处理也由 Adapter 完成。Protocol 在后续标准控制入口根据实际模式和状态校验指令;周期控制只读取 PDO,不增加周期 SDO 访问。
|
|
|
|
|
|
|
|
|
|
|
|
`setLimitQ`、`setLimitQd`、`calibrateZeroQ` 和 `brakeRelease` 保留为 Motor 层业务接口,不再属于 `MotorProtocolInterface` 或 `Cia402Protocol`。意优和同川通过各自 Adapter 实现;TI5 保留具体驱动的转发实现。
|
|
|
|
|
|
|
|
|
|
|
|
`torqueOn()` 按驱动当前已配置的模式使能,不再强制切换到 PP,也不写 `6060`。驱动已有有效模式时,可先 `torqueOn()` 再 `setMode(...)`;模式尚未配置时,需要先 `setMode(...)` 再使能。单轴测试显式采用后一种顺序,确保初始模式明确。使能前准备安全目标,随后按 `0006→0007→000F` 等待 `OperationEnabled`;模式确认由 `setMode()` 完成,PP 的新目标及应答握手由 `commandProfilePosition()` 完成。同川额外完成厂家要求的等待。机械臂初始化时,仅为未配置模式的 EtherCAT 轴选择初始 CSP,已有模式保留。
|
|
|
|
|
|
|
|
|
|
|
|
## 6. 同川 TCHL 配置与联调
|
|
|
|
|
|
|
|
|
|
|
|
使用单轴模板 `cmvr-es/config/devices/motor/tchl_motors.pb.txt`。模板尚未注册为活动设备;按当前实机 `PrD.00=0`、电子齿轮 `1:1`,依据手册印刷第 2 页参数表及第 20 页换算,`encoder_counts_per_rev` 配置为 `131072`,当前 `gear_ratio` 配置为 `101`。接入其他模块时应读取 `PrD.06 / 3D06:00 UINT16` 确认减速比,并核对机械轴实际位置、速度和加速度限位,再按第 3、4 节关联设备与使用方;设备 id、组 id 和关节名需使用模板中的对应值。
|
|
|
|
|
|
|
|
|
|
|
|
映射按提供的 TC600E TR ESI 编写,Vendor ID 为 `0x00075500`,Product Code 为 `0x00000002`;实机身份仍需核对。默认 PDO 如下,所有子索引均为 `0`:
|
|
|
|
|
|
|
|
|
|
|
|
| 方向 | PDO / SM | 条目顺序(位宽) |
|
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
|
| 主站发送 | `0x1601 / SM2`,17 字节 | `6040(16), 607A(32), 60FF(32), 6071(16), 60B1(32), 6060(8)` |
|
|
|
|
|
|
| 主站接收 | `0x1A01 / SM3`,19 字节 | `6041(16), 6064(32), 606C(32), 6077(16), 60F4(32), 603F(16), 6061(8)` |
|
|
|
|
|
|
|
|
|
|
|
|
CSP 写目标位置 `607A` 和速度前馈 `60B1`;CSV 的目标速度写 `60FF`。`6081/6083/6084` 不放入此默认 PDO,PP/PV 参数使用 SDO。模板当前关闭 DC,通信周期为 1 ms;保留的 DC 配置为 Sync0 周期 1 ms、`assign_activate: 768`(`0x0300`)、偏移 0,开启前需核对实际同步要求。手册列出的 Sync0 周期为 1、2、3 ms。
|
|
|
|
|
|
|
|
|
|
|
|
目标力矩和反馈力矩均以额定力矩的千分比(‰)表示:`1000` 为额定力矩,`100` 为额定力矩的 10%。PT 的 `torque_slope` 按已确认的 **`0.1%/s`(‰/s)** 直接写入 `6087`;例如 `1000` 表示每秒变化一个额定力矩,不做额外的 1000 倍换算。
|
|
|
|
|
|
|
|
|
|
|
|
单位配置必须与驱动器当前设置一致,程序不自动修改全闭环、电子齿轮或绝对位置参数:
|
|
|
|
|
|
|
|
|
|
|
|
- `PrD.00=0` 且电子齿轮为 1:1 时,使用电机端每转计数和机械减速比。
|
|
|
|
|
|
- 手册第 2 页列出的 TCHL_11/14/17/20/25/32 电机端均为 17 bit,即每转 `131072`,输出端为 19 bit,即每转 `524288`。第 65 页说明 `PrD.04` 是输出端一圈计数除以 4,因此 `3D04=131072` 对应输出端 `524288`,不能将该寄存器当作电机端分辨率来源。
|
|
|
|
|
|
- `PrD.00=1` 时位置采用输出端编码器尺度,应填写输出端每转的驱动器位置单位数,并将换算用 `gear_ratio` 设为 `1`,避免重复乘机械减速比。
|
|
|
|
|
|
- 若设置了电子齿轮,应使用换算后的用户单位数;还需核对 `PrD.07` 对 `606C` 速度反馈来源的选择。当前协议按同一尺度处理位置和每秒速度,联调时通过小幅运动核对位置增量与速度反馈。
|
|
|
|
|
|
|
|
|
|
|
|
同川厂家操作的具体行为:
|
|
|
|
|
|
|
|
|
|
|
|
- 位置限位完整流程在 Adapter 中:写入 `607D:01/:02`,再设置 `3809:00 UINT16=1` 开启软限位,并读回验证。速度限位也由 Adapter 写入、读回 `607F` 和 `6081`;意优另外处理厂家限速对象 `2024`。
|
|
|
|
|
|
- 初始化读取 `3136:00`(Pr1.54)和 `3137:00`(Pr1.55),均为 UINT16 毫秒值,范围 0–500。同川 Adapter 完整执行使能/失能:使能后等待固定 PrF.44 的 200 ms 加 Pr1.54;失能后等待 Pr1.55,再允许后续使能。
|
|
|
|
|
|
- 强制释放抱闸调用 `motor->brakeRelease()`:Adapter 先确认 `6041` 的使能位 bit2 为 `0`,再写 `381E:00 UINT16=128` 并读回;Quick Stop Active 的 bit2 仍为 `1`,不能直接松闸。`torqueOff()` 确认失能后检查该对象;若仍为非零,写 `0` 取消强制松闸并读回验证。读回只确认命令值,不能作为物理抱闸状态反馈。
|
|
|
|
|
|
- 零位校准沿用 `motor->calibrateZeroQ()`,具体流程在 `TchlMotorAdapter::calibrateZero()` 中实现:停止并失能后,将 `6098:00 INT8` 设为 35、`607C:00 INT32` 设为 0,切换 `6060=6`,按 `0006→0007→000F→001F` 将当前位置定义为零。Adapter 内部处理使能/失能延迟、完成检查、最终失能、目标 PDO 同步和软限位恢复;`TchlMotor` 只调用 Adapter。意优仍由自己的 Adapter 实现完整校准,`Cia402Protocol` 不提供厂家校准流程。
|
|
|
|
|
|
- 同川手册还给出了写 `3801:00 UINT16=5` 后断电重启的置零方式;上述接口使用方法 35,其掉电保持尚未实机验证。
|
|
|
|
|
|
|
|
|
|
|
|
单轴用例保留 `TEST` 名称以便选择运行,公共 `initMotor()` 通过 `MotorManager` 初始化并取得电机,后续直接调用 Motor 接口。初始化或命令失败时抛出 `std::runtime_error`,不使用 `ASSERT/EXPECT`。反馈每 100 ms 分别调用 `getQ()`、`getQd()`、`getTau()`,不是同一个原子采样快照。
|
|
|
|
|
|
|
|
|
|
|
|
用例没有退出停车、失能或信号处理逻辑,也不调用 `manager->stop()`。正常返回或异常展开时,`EthercatMotorBusRuntime` 析构仅结束通信线程并释放 master,不下发电机停车或失能命令。
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴 PP 实机测试
|
|
|
|
|
|
|
|
|
|
|
|
`commandProfilePosition(target_q, max_qd, max_qdd)` 使用 `abs(max_qd)` 作为速度幅值,方向由目标位置决定,传入 `-1` 和 `1` 均按 `1 rad/s` 执行。`Cia402Protocol` 对 `0` 和非有限速度直接返回 `false`,不读取原有 `6081`,也不下发新目标;这不表示停止已在执行的运动。
|
|
|
|
|
|
|
|
|
|
|
|
测试入口为 `tchl_motor_real_test` 的 `TchlMotorRealTest.ProfilePosition`。默认读取同川单轴模板,可用环境变量 `TCHL_MOTOR_CONFIG` 指定配置文件。
|
|
|
|
|
|
|
|
|
|
|
|
测试设置 PP 模式、使能、下发一次目标、打印反馈。目标是绝对输出轴位置 `1.57 rad`,速度 `0.5 rad/s`,加减速度 `5.0 rad/s²`;修改测试文件顶部三个常量即可。目标打印一次,随后打印实际位置、速度和额定力矩千分比,共打印 10 秒。
|
|
|
|
|
|
|
|
|
|
|
|
构建和列举用例:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
cmake --build cmake-build-debug --target tchl_motor_real_test --parallel 4
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
|
|
|
|
|
cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test --gtest_list_tests
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
以下命令会使能并移动电机,需使用实际换算参数和机械限位:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
|
|
|
|
|
cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.ProfilePosition
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴 CSP 正弦往返测试
|
|
|
|
|
|
|
|
|
|
|
|
入口为同一测试程序的 `TchlMotorRealTest.CyclicPositionSin`,使用同一份同川配置。参考意优 CSP 用例,采用升余弦位置和正弦速度前馈:
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
q_target = q0 + Δq / 2 × (1 − cos(ωt))
|
|
|
|
|
|
qd_target = Δq / 2 × ω × sin(ωt)
|
|
|
|
|
|
ω = 2π / T
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
`q0` 取设置 CSP 并使能后的实际位置。当前 `Δq = 1.57 rad`、`T = 6 s`、运行两周期(12 秒),范围为 `q0` 到 `q0 + 1.57 rad`;可修改测试顶部的 `kCspExcursionRad`、`kCspPeriodS`、`kCspCycles`。
|
|
|
|
|
|
|
|
|
|
|
|
下发间隔使用测试常量 `kCommandPeriod = 1 ms`,独立于总线配置。`commandCyclicPosition()` 将目标位置写入 PDO `607A`,速度前馈写入同川的 `60B1`。轨迹按实际经过时间计算,延迟后跳过错过的时刻;每 100 ms 打印目标位置、目标速度及反馈,最后下发起点位置和零前馈。
|
|
|
|
|
|
|
|
|
|
|
|
以下命令会使能并移动电机:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
|
|
|
|
|
cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.CyclicPositionSin
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴 PV / CSV 速度测试
|
|
|
|
|
|
|
|
|
|
|
|
同一测试文件增加两个速度用例,继续使用 `TCHL_MOTOR_CONFIG` 指定配置:
|
|
|
|
|
|
|
|
|
|
|
|
| 用例 | 目标及持续时间 | 下发方式 |
|
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
|
| `TchlMotorRealTest.ProfileVelocity` | 设置 PV 模式并使能,目标速度 `-0.3 rad/s`,加减速度 `1.0 rad/s²`,持续打印反馈,直到进程结束 | 调用一次 `commandProfileVelocity` 下发目标 |
|
|
|
|
|
|
| `TchlMotorRealTest.CyclicVelocitySin` | `qd = 0.8 × sin(2πt/6) rad/s`,运行两周期(12 秒),最后下发零速度 | 按测试常量 `kCommandPeriod = 1 ms` 调用 `commandCyclicVelocity`,写入 PDO `60FF` |
|
|
|
|
|
|
|
|
|
|
|
|
PV 可修改测试顶部的 `kPvVelocityRadS`、`kPvAccelerationRadS2`;CSV 可修改 `kCsvVelocityAmplitudeRadS`、`kCsvPeriodS`、`kCsvCycles`。两个用例每 100 ms 打印实际位置、速度和力矩;PV 在下发时打印目标速度,CSV 随周期打印目标速度。
|
|
|
|
|
|
|
|
|
|
|
|
分别运行以下用例:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
|
|
|
|
|
cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.ProfileVelocity
|
|
|
|
|
|
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
|
|
|
|
|
cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.CyclicVelocitySin
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴运动中减速停车测试
|
|
|
|
|
|
|
|
|
|
|
|
`quickStop(double deceleration = 5.0)` 的减速度单位为输出轴 `rad/s²`,必须是有限正数。省略参数时使用 `5.0`,例如 `motor->quickStop()`;需要其他减速度时传入 `motor->quickStop(1.0)`。
|
|
|
|
|
|
|
|
|
|
|
|
`Cia402Protocol` 将减速度按编码器分辨率、减速比换算后,通过 SDO 写入 `6085:00 UINT32`,并设置 `605A:00 INT16=2`,然后通过 PDO 写 `6040=0x000B`,等待实际速度接近零。意优和同川的 PP/PV/CSP/CSV 模式都按快停减速度停车,停车后失能;力矩模式的停车斜坡另由驱动器定义,意优使用 `6087`。参数仅写入运行字典,不执行保存;参数下发失败仍尝试发送快停控制字,但接口返回 `false`。
|
|
|
|
|
|
|
|
|
|
|
|
入口为 `TchlMotorRealTest.QuickStopInProfileVelocity`。测试设置 PV 模式并使能,以 `±0.3 rad/s`、加减速度 `1 rad/s²` 运行 2 秒;当前位置大于零时取负速度,否则取正速度。随后调用 `motor->quickStop()`,使用默认快停减速度 `5.0 rad/s²`,再打印反馈 1 秒。测试只调用 Motor 接口,不直接读写 SDO 或断言预计行程。
|
|
|
|
|
|
|
|
|
|
|
|
`quickStop()` 阻塞到停车完成或配置的 `velocity_stop_timeout_ms` 超时,调用期间不打印反馈;100 ms 的打印间隔不能还原完整减速曲线。较小减速度需要相应增大等待超时。
|
|
|
|
|
|
|
|
|
|
|
|
下方命令优先加载 `output/lib`,接口修改后需先重新构建并 install,确保测试程序和运行库版本一致。
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
|
|
|
|
|
./cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.QuickStopInProfileVelocity
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴释放刹车测试
|
|
|
|
|
|
|
|
|
|
|
|
入口为 `TchlMotorRealTest.BrakeRelease`。先调用 `torqueOff()` 确认失能,再调用一次 `brakeRelease()`,保持总线运行 10 秒,每 100 ms 打印实际位置、速度和力矩。测试不发送使能或运动指令;松闸后轴可能因重力或外力运动,运行前需支撑好机械轴和负载。
|
|
|
|
|
|
|
|
|
|
|
|
退出时不调用 `torqueOff()`,也不主动清除强制松闸命令。
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
|
|
|
|
|
./cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.BrakeRelease
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 单轴当前位置置零测试
|
|
|
|
|
|
|
|
|
|
|
|
入口为 `TchlMotorRealTest.CalibrateZeroQ`。将机械轴放在希望定义为零点的位置后单独运行。测试调用一次 `motor->calibrateZeroQ()`,打印校准前后的实际位置、速度和力矩。方法 35 内部会暂时使能,成功后保持失能、模式为 Homing;后续运动需先设置所需模式,再重新使能。
|
|
|
|
|
|
|
|
|
|
|
|
Adapter 检查启动命令已经到达驱动、状态字 bit12/bit10 已置位、bit13 无错误且实际位置接近 0。等待默认超时 2000 ms、轮询 10 ms、位置容差 100 个计数,可通过已有 `ethercat.zero_calibration` 配置覆盖。配置中的软限位会按新零点重新应用。
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
|
|
|
|
|
./cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
|
|
|
|
|
--gtest_filter=TchlMotorRealTest.CalibrateZeroQ
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 7. 编译验证
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-07-09 14:22:35 +08:00
|
|
|
|
cmake -S . -B cmake-build-debug
|
|
|
|
|
|
cmake --build cmake-build-debug --target motor_manager
|
2026-06-30 16:04:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
真机验证顺序:
|
2026-06-30 16:04:36 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-10-27 17:01:20 +08:00
|
|
|
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
|
|
|
|
|
scripts/ethercat/status_ethercat.sh
|
2026-07-09 14:22:35 +08:00
|
|
|
|
cmake --build cmake-build-debug --target cmvr_es
|
2026-06-30 16:04:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-09 14:22:35 +08:00
|
|
|
|
第一次联调先不要大幅度运动。先看 master 是否打开、slave 是否进入 OP、状态字是否更新,再给单个电机小角度目标。
|