文章目录
一、FastRTPS v1.8.0 安装运行
1.1 环境准备
- Linux:Ubuntu 16.04LTS
- Make:GNU Make V4.1
- JDK:1.8.0_201
- Gradle:Gradle V5.4.1
1.2 下载FastRTPS v1.8.0
进入/opt目录从github克隆项目:
cd /opt
sudo git clone https://github.com/eProsima/Fast-RTPS
- https://github.com/eProsima/Fast-RTPS 该源为最新的v1.8.0
下载完成后如图所示,并在/opt目录下出现/Fast-RTPS文件夹
Cloning into 'Fast-RTPS'...
remote: Enumerating objects: 58488, done.
remote: Total 58488 (delta 0), reused 0 (delta 0), pack-reused 58488
Receiving objects: 100% (58488/58488), 71.27 MiB | 3.10 MiB/s, done.
Resolving deltas: 100% (39336/39336), done.
Checking connectivity... done.
1.3 编译安装
进入/opt/Fast-RTPS/目录下,创建build文件夹
cd /opt/Fast-RTPS/
sudo mkdir build
输入如下命令,修改/Fast-RTPS权限,不修改权限会在编译时出现Permission denied的情况
sudo chmod -R 777 /opt/Fast-RTPS/
进入/opt/Fast-RTPS/build/目录下
cd /opt/Fast-RTPS/build/
依次输入如下命令进行编译
cmake -DTHIRDPARTY=ON -DBUILD_JAVA=ON -DCOMPILE_EXAMPLES=ON -DPERFORMANCE_TESTS=ON ..
make
sudo make install
- 如果需要编译fastrtpsgen java应用程序,调用CMake时添加参数
-DBUILD_JAVA=ON。 - 如果需要编译示例,调用CMake时添加参数
-DCOMPILE_EXAMPLES=ON。 - 如果需要编译性能测试,调用CMake时添加参数
-DPERFORMANCE_TESTS=ON。
至此,FastRTPS v1.8.0 已安装完成。
1.4 创建简单应用
1.4.1 编写简单程序
在~目录下创建testFastRTPS文件夹,进入~/testFastRTPS目录下
cd ~/testFastRTPS
创建HelloWorld.idl文件,并编写如下简单程序:
// HelloWorld.idl
struct HelloWorld
{
string msg;
};
1.4.2 编译简单程序
通过fastrtpsgen工具将IDL文件生成C++代码
fastrtpsgen -example CMake HelloWorld.idl
使用ls命令查看当前~/testFastRTPS目录下文件
ls
~/testFastRTPS目录下有如下文件:
CMakeLists.txt HelloWorldPublisher.cxx HelloWorldPubSubTypes.h
HelloWorld.cxx HelloWorldPublisher.h HelloWorldSubscriber.cxx
HelloWorld.h HelloWorldPubSubMain.cxx HelloWorldSubscriber.h
HelloWorld.idl HelloWorldPubSubTypes.cxx
在当前目录创建build文件夹,并进入build文件夹使用如下命令进行编译
mkdir build && cd build
cmake ..
make
使用ls命令查看当前~/testFastRTPS/build目录下文件
ls
~/testFastRTPS/build目录下有如下文件,其中HelloWorld即为执行程序
CMakeCache.txt cmake_install.cmake libHelloWorld_lib.a
CMakeFiles HelloWorld Makefile
1.4.3 运行简单示例
打开一个终端,进入~/testFastRTPS/build目录下,输入如下命令启动一个发布者
./HelloWorld publisher
显示如下,发布者创建成功,等待订阅者
Starting
Publisher created, waiting for Subscribers.
打开第二个终端,进入~/testFastRTPS/build目录下,输入如下命令启动一个订阅者
./HelloWorld subscriber
显示如下,订阅者创建成功,等待数据发布
Starting
Waiting for Data, press Enter to stop the Subscriber.
Subscriber matched
如下图所示,在publisher端按y发送sample,在subscriber端即可接收到sample。

二、FastRTPS v1.5.0 安装运行
在树莓派3B+上安装FastRTPS v1.5.0
2.1 环境准备
- Linux:Ubuntu MATE 16.04LTS
- Make:GNU Make V4.1
- JDK:1.8.0_211 【需下载
jdk-8u211-linux-arm32-vfp-hflt版本】 - Gradle:Gradle V5.4.1
2.2 下载FastRTPS v1.5.0
下载安装包eProsima_FastRTPS-1.5.0-Linux.tar.gz至~/Download目录下
在/opt目录下新建FastRTPS-1.5.0文件夹
sudo mkdir /opt/FastRTPS-1.5.0
将压缩包解压到FastRTPS-1.5.0文件夹下
sudo tar -zxvf eProsima_FastRTPS-1.5.0-Linux.tar.gz -C /opt/FastRTPS-1.5.0/
2.3 编译安装
参照README.txt进行编译安装
进入/requiredcomponents目录下将eProsima_FastCDR-1.0.7-Linux.tar.gz解压
cd requiredcomponents/
sudo tar -zxvf eProsima_FastCDR-1.0.7-Linux.tar.gz
执行如下命令:
cd eProsima_FastCDR-1.0.7-Linux
./configure --libdir=/usr/lib
make
sudo make install
返回至/opt/FastRTPS-1.5.0目录下执行如下命令:
cd eProsima_FastRTPS-1.5.0-Linux
./configure --libdir=/usr/lib
make
sudo make install
至此,FastRTPS v1.5.0 已安装完成。
2.4 创建简单应用
2.4.1 编写简单程序
在~目录下创建testFastRTPS文件夹,进入~/testFastRTPS目录下
cd ~/testFastRTPS
创建HelloWorld.idl文件,并编写如下简单程序:
// HelloWorld.idl
struct HelloWorld
{
string msg;
};
2.4.2 编译简单程序
通过fastrtpsgen工具将IDL文件生成C++代码【树莓派为32位系统】
fastrtpsgen -example i86Linux2.6gcc HelloWorld.idl
使用ls命令查看当前~/testFastRTPS目录下文件
ls
~/testFastRTPS目录下有如下文件:
HelloWorld.cxx HelloWorldPublisher.h HelloWorldSubscriber.cxx
HelloWorld.h HelloWorldPubSubMain.cxx HelloWorldSubscriber.h
HelloWorld.idl HelloWorldPubSubTypes.cxx makefile_i86Linux2.6gcc
HelloWorldPublisher.cxx HelloWorldPubSubTypes.h
将makefile_i86Linux2.6gcc文件重命名为makefile
sudo mv makefile_i86Linux2.6gcc makefile
使用pluma打开makefile文件,删掉其中所有-m32字串
执行make命令进行编译
make
2.4.3 运行简单示例
打开一个终端,进入~/testFastRTPS/bin/i86Linux2.6gcc/目录下,输入如下命令启动一个发布者
./HelloWorldPublisherSubscriber publisher
显示如下,发布者创建成功,等待订阅者
Starting
Publisher created, waiting for Subscribers.
打开第二个终端,进入~/testFastRTPS/bin/i86Linux2.6gcc/目录下,输入如下命令启动一个订阅者
./HelloWorldPublisherSubscriber subscriber
显示如下,订阅者创建成功,等待数据发布
Starting
Waiting for Data, press Enter to stop the Subscriber.
Subscriber matched
如下图所示,在publisher端按y发送sample,在subscriber端即可接收到sample。

三、参考来源
【1】https://eprosima-fast-rtps.readthedocs.io/en/latest/sources.html
【2】https://eprosima-fast-rtps.readthedocs.io/en/latest/introduction.html
【3】https://blog.youkuaiyun.com/JL_Gao/article/details/84023046
【4】https://www.cnblogs.com/yytlmm/p/10274218.html
6055





