feat(level1): ROS2 完全体 12 包 / 80 测试 / 23 文档 / 工程化 / Docker 分组
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
# cpp_custom_interface
|
||||
|
||||
ROS2 自定义接口演示包(C++)。属于 Level 1 基础机制第 10 块。
|
||||
|
||||
## 自定义接口
|
||||
|
||||
| 类型 | 文件 | 字段 |
|
||||
|---|---|---|
|
||||
| `msg` | `SensorReading.msg` | header + sensor_id + unit + value |
|
||||
| `srv` | `GetCalibration.srv` | req: sensor_id / resp: intrinsic_matrix[9] + bias[3] + date + valid |
|
||||
| `action` | `MoveArm.action` | goal: target_pose + joint_names + scaling / feedback: progress + state / result: success + time |
|
||||
|
||||
## 节点
|
||||
|
||||
- **`sensor_publisher_cpp`**: 周期性发布 `SensorReading`(正弦曲线模拟传感器读数)
|
||||
- **`calibration_server_cpp`**: 提供 `GetCalibration` 服务(返回模拟相机内参)
|
||||
- **`move_arm_server_cpp`**: 提供 `MoveArm` Action(5 阶段模拟移动)
|
||||
|
||||
## 关键概念
|
||||
|
||||
| 概念 | 用途 |
|
||||
|---|---|
|
||||
| `rosidl_generate_interfaces` | 自动生成 C++ / Python 接口代码 |
|
||||
| `.msg` / `.srv` / `.action` | 接口定义文件 |
|
||||
| `rosidl_default_generators` | 构建时依赖 |
|
||||
| `rosidl_default_runtime` | 运行时依赖 |
|
||||
| `ament_cmake` | C++ 包构建类型 |
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
# 启动所有自定义接口节点
|
||||
ros2 launch cpp_custom_interface custom_launch.py
|
||||
|
||||
# CLI 调用服务
|
||||
ros2 service call /get_calibration cpp_custom_interface/srv/GetCalibration "{sensor_id: 'lidar_front'}"
|
||||
|
||||
# CLI 发 Action goal
|
||||
ros2 action send_goal /move_arm cpp_custom_interface/action/MoveArm "{
|
||||
target_pose: {header: {frame_id: 'base_link'}, pose: {position: {x: 0.3, y: 0.0, z: 0.2}, orientation: {w: 1.0}}},
|
||||
joint_names: ['joint1','joint2','joint3'],
|
||||
max_velocity_scaling: 0.5,
|
||||
max_acceleration_scaling: 0.5
|
||||
}" --feedback
|
||||
|
||||
# CLI 看自定义消息
|
||||
ros2 topic echo /sensor_reading
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
colcon test --packages-select cpp_custom_interface
|
||||
```
|
||||
|
||||
测试覆盖:
|
||||
|
||||
| 用例 | 内容 |
|
||||
|---|---|
|
||||
| `SensorReadingFields` | msg 字段构造正确 |
|
||||
| `GetCalibrationRequestResponse` | srv 字段 + 长度正确 |
|
||||
| `MoveArmGoalFeedbackResult` | action 三段都正确 |
|
||||
|
||||
## 深度学习
|
||||
|
||||
- 编程规范:[`doc/CODING_STYLE.md`](../doc/CODING_STYLE.md)
|
||||
- 自定义接口:[`doc/16-custom-interfaces.md`](../doc/16-custom-interfaces.md)
|
||||
Reference in New Issue
Block a user