这个包作为中转站(Relay Hub),解决多个机器人运行相同 ROS2 项目代码时的话题冲突问题。
This package acts as a Relay Hub to resolve topic conflicts when multiple robots run the same ROS2 project code.
- 本地话题 → 全局话题(添加机器人命名空间)
Local topic → Global topic (adds robot namespace) - 全局话题 → 本地话题(移除命名空间)
Global topic → Local topic (removes namespace) - 无需修改原有代码
No need to modify existing code
- 自动为 TF 框架添加机器人名称前缀
Automatically adds robot prefix to TF frames - 保持本地 TF 不变
Keeps local TF unchanged - 支持多机器人可视化
Supports multi-robot visualization
- 处理不同机器人地图原点不一致问题
Handles map origin differences between robots - 支持位置偏移和旋转变换
Supports position offset and rotation transformation - 自动转换位置和目标点
Automatically transforms positions and goal poses
- 中央注册服务器
Central registry server - 心跳监控
Heartbeat monitoring - 机器人列表广播
Robot list broadcasting
multi_robot_relay/
├── config/
│ ├── relay_config.yaml # 中转站配置 | Relay configuration
│ └── robots_example.yaml # 机器人配置示例 | Example robot config
├── launch/
│ ├── robot_relay.launch.py # 单机器人中转站启动 | Single robot relay
│ ├── central_registry.launch.py # 中央注册服务器启动 | Central registry
│ └── multi_robot_system.launch.py # 多机器人系统启动 | Multi-robot system
└── multi_robot_relay/
├── topic_relay_node.py # 话题中转节点 | Topic relay node
├── tf_relay_node.py # TF中转节点 | TF relay node
├── coordinate_transformer_node.py # 坐标转换节点 | Coordinate transformer
└── robot_registry_node.py # 机器人注册节点 | Robot registry node
cd ~/ros2_ws
colcon build --packages-select multi_robot_relay
source install/setup.bash在每个机器人上运行: Run on each robot:
ros2 launch multi_robot_relay robot_relay.launch.py robot_name:=robot1
ros2 launch multi_robot_relay robot_relay.launch.py robot_name:=robot2
ros2 launch multi_robot_relay robot_relay.launch.py robot_name:=robot3中转站启动后,正常启动导航等功能(话题名保持不变): After launching the relay, start navigation as usual (topic names unchanged):
ros2 launch navigation navigation.launch.py从外部控制时使用带命名空间的话题: Use namespaced topics for external control:
ros2 topic pub /robot1/goal_pose geometry_msgs/PoseStamped "..."
ros2 topic pub /robot2/goal_pose geometry_msgs/PoseStamped "..."ros2 topic echo /robot1/odom
ros2 topic echo /robot2/odom
ros2 topic echo /robot3/odomCase 1: All robots share the same map origin
ros2 launch multi_robot_relay robot_relay.launch.py \
robot_name:=robot1 \
enable_coord_transform:=falseCase 2: Robots have different map origins
ros2 launch multi_robot_relay robot_relay.launch.py \
robot_name:=robot2 \
enable_coord_transform:=true \
map_offset_x:=1.5 \
map_offset_y:=0.5 \
map_offset_yaw:=0.0编辑 config/relay_config.yaml 自定义中转话题:
Edit config/relay_config.yaml to customize relayed topics:
uplink_topics: # 本地 → 全局 | Local → Global
- local_topic: "/odom"
global_topic: "/{robot_name}/odom"
msg_type: "nav_msgs/Odometry"
qos: 10
downlink_topics: # 全局 → 本地 | Global → Local
- global_topic: "/{robot_name}/goal_pose"
local_topic: "/goal_pose"
msg_type: "geometry_msgs/PoseStamped"
qos: 10| 本地话题 | 全局话题 | 说明 | Description |
|---|---|---|---|
/odom |
/robot1/odom |
里程计 | Odometry |
/scan |
/robot1/scan |
激光雷达 | Laser scan |
/amcl_pose |
/robot1/amcl_pose |
定位位姿 | Localization pose |
/controller/cmd_vel |
/robot1/cmd_vel_status |
速度指令状态 | Velocity status |
| 全局话题 | 本地话题 | 说明 | Description |
|---|---|---|---|
/robot1/goal_pose |
/goal_pose |
导航目标 | Navigation goal |
/robot1/initialpose |
/initialpose |
初始位姿 | Initial pose |
/robot1/cmd_vel_override |
/controller/cmd_vel |
速度覆盖 | Velocity override |
ros2 launch multi_robot_relay central_registry.launch.pyros2 service call /multi_robot/get_robots std_srvs/Triggerros2 topic echo /multi_robot/robot_listros2 run multi_robot_relay tf_relay --ros-args -p robot_name:=robot1 -p publish_rate:=100.0def transform_pose_local_to_global(self, x, y, yaw):
# 自定义转换逻辑 | Custom transformation logic
pass