使用集群通信swarm_ros_bridge实现ros1多机通信
参考链接:
swarm_ros_bridge官方网址
集群多机ROS通信中间件:swarm_ros_bridge
ROS多机集群组网通信(二)——ROS多机通信功能包-Multibotnet
ROS局域网下主从机多机通讯方法
ROS多机通信操作个人总结
swarm_ros_bridge介绍
主要基于 ZeroMQ 的轻量级中间接口 ROS 包。它使 swarm 机器人之间通过 socket 通信传输指定的 ROS 消息。这个包的目的是取代 ROS1 中跨多台机器运行 ROS 的传统方式,这种方式在集群机器人情况下有一些缺点。
两个 ROS 机器人通过 swarm_ros_bridge 相互通信的示例如下所示:
与 ROS1 多机器人无线通信相比,它具有以下优势:
- 稳健:无需先启动基站 ROS 主站。支持每个机器人随机启动并自主连接。
- 灵活:您可以选择发送/接收 ROS 主题,而不是像 ROS1 那样传输所有主题(名称)。
- 易于使用:在一个配置文件中指定所有 IP 和 ROS 主题。
与 ROS2 DDS 通信相比,它可能具有以下优势:
- 轻量级:它是一个小型的 ROS 桥接节点,用于订阅和发送远程 ROS 主题,因此与其他 ROS 节点连接很容易。
- 可靠:使用基于 TCP 协议的 ZeroMQ 套接字通信,而 ROS2 基于 DDS,默认协议为 UDP(不可靠)。DDS 主要是为有线通信下原生进程之间的数据交换而设计的,而不是远程无线通信。
ROS wiki 页面:https://wiki.ros.org/swarm_ros_bridge
源代码: https://github.com/shupx/swarm_ros_bridge.git
csdn 博客 (中文):https://blog.csdn.net/benchuspx/article/details/128576723
安装过程
## clone this package
mkdir -p swarm_ros_bridge_ws/src # or your own ros workspace
cd swarm_ros_bridge_ws/src
git clone https://gitee.com/shu-peixuan/swarm_ros_bridge.git
# or 'git clone https://github.com/shupx/swarm_ros_bridge.git'
## install dependencies
sudo apt install libzmqpp-dev
# or 'rosdep install --from-path swarm_ros_bridge/'
## build
cd ../
catkin_make
source devel/setup.bash
使用方法
确保所有机器人都连接到同一个网段。
step 1:配置yaml文件
1.在两台机器的config/ros_topic.yaml中指定IP和ROS话题
机器1(192.168.6.73)
### list all <IPname: IP> here (IPname can be set arbitrarily) ###
IP:
self: '*' # '*' stands for all self IPs
robot1: 192.168.6.70
####### Send these ROS messages to remote robots #######
## if no send_topics needed, comment all these out
send_topics:
- topic_name: /string # send the messages of this ROS topic
msg_type: std_msgs/String # ROS message type (rosmsg style)
max_freq: 10 # max sending frequency (Hz) int
srcIP: self # self IP
srcPort: 3003 # ports of send_topics should be different
####### receive these ROS messages from remote robots #######
## if no recv_topics needed, comment all these out
recv_topics:
- topic_name: /string_recv # the received messages will be published in this topic
msg_type: std_msgs/String # ROS message type (rosmsg style)
srcIP: robot1 # message source IPname
srcPort: 3003 # message source port
机器2(192.168.6.70)
### list all <IPname: IP> here (IPname can be set arbitrarily) ###
IP:
self: '*' # '*' stands for all self IPs
robot1: 192.168.6.73
####### Send these ROS messages to remote robots #######
## if no send_topics needed, comment all these out
send_topics:
- topic_name: /string # send the messages of this ROS topic
msg_type: std_msgs/String # ROS message type (rosmsg style)
max_freq: 10 # max sending frequency (Hz) int
srcIP: self # self IP
srcPort: 3003 # ports of send_topics should be different
####### receive these ROS messages from remote robots #######
## if no recv_topics needed, comment all these out
recv_topics:
- topic_name: /string_recv # the received messages will be published in this topic
msg_type: std_msgs/String # ROS message type (rosmsg style)
srcIP: robot1 # message source IPname
srcPort: 3003 # message source port
- self:本机IP
- robot1:接收方IP
- send_topics:本机发出的话题
- recv_topics:robot1接收方接收话题
总结来说就是由self发布send_topics,由另一台机器的recv_topics接收话题
step 2:启动bridge节点
启动 bridge_node:
roslaunch swarm_ros_bridge test.launch # local machine test
step 3:发布与查看话题信息
将消息发布到 send_topics 中,并检查远程recv_topics是否正在接收这些消息。
在机器1(192.168.6.73)启动话题发布命令
rostopic pub -r 1 /string std_msgs/String "data: 'Hello from ROS1'"
在机器2(192.168.6.70)查看是否收到机器1发布的话题信息
rostopic echo /string_recv