无人驾驶笔记系列(四):Fast-RTPS初体验
背景介绍
ROS1在节点启动前,必须通过roscore
启动一个master节点,通过master管理节点之间的通信。这样master节点如果出现问题,其他节点之间的通信也会出现问题。同时,通讯的实时性也不是很好。因此,ROS2和apollo框架都用上了DDS通讯。
关于什么是DDS,英文全称(Data Distribution Service for Real-Time Systems)我也不在此啰嗦了,推荐读下这篇博客。
DDS简要介绍
总结下特点:
- DDS采用发布/订阅体系架构,强调以数据为中心。
- DDS使应用在需要进行数据访问的时候提供一个虚拟的全局数据池概念,事实上并没有一个存储所有数据的全局设备。每个应用仅在本地存储它需要的数据,当整个网络内的任何应用需要他们时,提供给对应应用。所有的数据分发工作全部都由DDS代劳了。
- 网络中的数据对象用主题做标识,分布式节点在全局数据空间中发布或订阅感兴趣的主题信息。各个节点在逻辑上无主从关系,点与点之间都是对等关系,通信方式可以是点对点,点对多,多对多,在Qos策略的控制下建立连接,自动发现和配置网络参数。
当然DDS之前一种协议,具体实现有好多版本,如:
RTI公司的DDS方案
:美国海上战争中心(NSWC)高性能分布式计算系统(HiPer-D),美军都在用,应该很牛吧。OpenDDS
:OpenDDS是使用C++语言针对OMG数据分发服务(DDS)的一种开源实现。由OCI公司设计和维护,http://www.opendds.org 官网。尽管本身OpenDDS采用C++语言实现,但也提供JAVA和JMS的开发接口,这意味着JAVA程序开发也可以使用OpenDDS。eProsima Fast RTPS
:Fast RTPS是eProsima公司对RTPS标准的一个实现。那RTPS是什么东东?RTPS是DDS标准中的一个子集。英文名字是Real Time Publish Subscribe,是DDS标准中的通讯协议部分。
安装eProsima Fast RTPS
推荐用官网的安装包安装,源码安装比较复杂,需要你安装很多依赖。
安装包解压后,查看下文件结构:
xx:~/fastrtps$ ls
doc install.sh java README.txt src uninstall.sh
xx:~/fastrtps$ cd src
xx:~/fastrtps/src$ ls
fastcdr fastrtps fastrtpsgen foonathan_memory
可以看到,其实文件还是包含了依赖包的源码,这样保证我们安装不会出问题。
一行命令,即可完成安装
sudo bash install.sh
成功安装后,查看下安装目录
#include文件目录
/usr/local/include/fastrtps
#库文件目录
/usr/local/lib/libfastrtps.so
#cmake文件目录
/usr/local/share/fastrtps/cmake/fastrtps-targets.cmake
跑个实例试试看
你可以在github主要上把源码拉取下来。
在源码中,可以看到有个helloworld实例
cd Fast-RTPS/examples/C++/HelloWorldExample
编译
mkdir build && cd build
cmake ..
make
编译后,要在两个窗口运行。
先运行发布者
./HelloWorldExample publisher
打印结果如下:
Starting
Publisher running 10 samples.
Publisher matched
# 在subscriber启动后打印
Message: HelloWorld with index: 1 SENT
Message: HelloWorld with index: 2 SENT
Message: HelloWorld with index: 3 SENT
Message: HelloWorld with index: 4 SENT
Message: HelloWorld with index: 5 SENT
Message: HelloWorld with index: 6 SENT
Message: HelloWorld with index: 7 SENT
Message: HelloWorld with index: 8 SENT
Message: HelloWorld with index: 9 SENT
Message: HelloWorld with index: 10 SENT
启动订阅者
./HelloWorldExample subscriber
打印结果如下:
Starting
Subscriber running. Please press enter to stop the Subscriber
Subscriber matched
Message HelloWorld 1 RECEIVED
Message HelloWorld 2 RECEIVED
Message HelloWorld 3 RECEIVED
Message HelloWorld 4 RECEIVED
Message HelloWorld 5 RECEIVED
Message HelloWorld 6 RECEIVED
Message HelloWorld 7 RECEIVED
Message HelloWorld 8 RECEIVED
Message HelloWorld 9 RECEIVED
Message HelloWorld 10 RECEIVED
Subscriber unmatched
我们稀里糊涂的跑了官方例子,具体是怎么运行的,还是完全不明白。
原理解析
未完待续