Fast-RTPS调坑记录(linux源码安装)

4 篇文章 0 订阅

参考

官方安装手册 这里官网安装手册有点坑,大家伙多注意一下,官网的注意事项喜欢写在后面,前面巴拉巴拉安装一堆之后,失败了,跑到后面才发现要注意什么注意什么。也可以直接看我后面的步骤。
跑个实例看看

正文

1、背景

背景大概都知道了,Fast-RTPS 作为ros 2的底层通讯架构之一,这里不安装ros2,直接安装测试 Fast-RTPS。

FastDDS的安装有cmake 和 colcon两种安装方式

这里使用cmake 安装,安装的版本为 github版本,cmake 建议升级到3.11以上

使用命令 cmake --version 查看当前 cmake 版本,升级步骤如下

$ wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
$ mv cmake-3.18.0.tar.gz /usr/local/
$ cd /usr/local/
$ tar xf cmake-3.18.0.tar.gz
$ rm -rf cmake-3.18.0.tar.gz
$ cd cmake-3.18.0/
$ sudo ./configure
$ sudo make
$ sudo make install
$ cmake --version

安装 FastRTPS 前,先安装依赖库,如下

sudo apt install libasio-dev libtinyxml2-dev
sudo apt install libssl-dev
sudo apt install cmake g++ python3-pip wget git

//以下的我都没装
//sudo apt install libp11-dev libengine-pkcs11-openssl (可选,只有DDS用到security和PKCS#11 URI时才需要,我没装)
//sudo apt install softhsm2 (可选,我没装,装了libp11-dev才需要)
//sudo usermod -a -G softhsm <user> (可选,我没装,同上)
//sudo apt install libengine-pkcs11-openssl (同上)
//p11-kit list-modules(同上)
//openssl engine pkcs11 -t(同上)

Gtest: 可选,C++单元测试库,我还没装
//git clone https://github.com/google/googletest src/googletest-distribution

然后在 用户目录下,创建文件夹

mkdir ~/Fast-DDS

然后一项一项安装,首先是 Foonathan memory

cd ~/Fast-DDS
git clone https://github.com/eProsima/foonathan_memory_vendor.git
mkdir foonathan_memory_vendor/build
cd foonathan_memory_vendor/build
(先看下文)cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install -DBUILD_SHARED_LIBS=ON
(先看下文)cmake --build . --target install

这里有两个注意事项,如果 按官网如下安装,最后测试时会发现,找不到foonathan的一个库,第二句由于缺少权限导致失败

cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install -DBUILD_SHARED_LIBS=ON
cmake --build . --target install
#将上面修改成如下:
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/ -DBUILD_SHARED_LIBS=ON
sudo cmake --build . --target install

错误如下:

nxchannelone@nx:~/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build$ cmake .. 
CMake Error at CMakeLists.txt:29 (find_package):
  By not providing "Findfoonathan_memory.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "foonathan_memory", but CMake did not find one.

  Could not find a package configuration file provided by "foonathan_memory"
  with any of the following names:

    foonathan_memoryConfig.cmake
    foonathan_memory-config.cmake

  Add the installation prefix of "foonathan_memory" to CMAKE_PREFIX_PATH or
  set "foonathan_memory_DIR" to a directory containing one of the above
  files.  If "foonathan_memory" provides a separate development package or
  SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/home/nxchannelone/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build/CMakeFiles/CMakeOutput.log".

然后安装 Fast CDR

cd ~/Fast-DDS
git clone https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR/build
cd Fast-CDR/build
#cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install
#这里依然修改一下路径
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
sudo cmake --build . --target install

然后安装 Fast DDS,以前的版本应该叫 Fast RTPS,这里和 Fast DDS是一样的

cd ~/Fast-DDS
git clone https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS/build
cd Fast-DDS/build
#cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install
#这里依然修改一下路径
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
sudo cmake --build . --target install

然后添加一下环境变量

echo 'export LD_LIBRARY_PATH=/usr/local/lib/' >> ~/.bashrc

然后安装 Fast DDS Gen,由于我也是才刚刚安装,不太知道具体是干啥的,先装
先安装依赖

sudo apt install openjdk-8-jdk
cd ~/Fast-DDS
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
gradle assemble
# 这里没下载 gradle 会失败,可以直接使用中间件,不用下载
./gradlew assemble

然后将环境添加

echo 'export PATH=~/Fast-DDS/Fast-DDS-Gen/scripts:$PATH' >> ~/.bashrc
source ~/.bashrc

在终端 打 fast 按 Tab 键,出现 fastddsgen ,就安装成功了。
在这里插入图片描述
最后找到测试文件,进行测试

cd ~/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build
./HelloWorldExample publisher
# 开启另一个终端
./HelloWorldExample subscriber

结果如图
在这里插入图片描述

完成

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fast-RTPS 是一个高性能的实时通信协议,用于在分布式系统中传输实时数据。在 Fast-RTPS 中,每个消息都由头部和数据组成。在本示例中,我们将展示如何解析 Fast-RTPS 消息的头部字段以及 topic name。 首先,我们需要了解 Fast-RTPS 消息头部字段的含义。Fast-RTPS 消息头部包括以下字段: - `protocolId`:Fast-RTPS 协议的版本号。 - `vendorId`:Fast-RTPS 实现的厂商 ID。 - `guidPrefix`:全局唯一标识符的前缀,用于识别 Fast-RTPS 实例。 - `guidEntityId`:Fast-RTPS 实体的唯一标识符。 - `sequenceNumber`:消息的序列号。 - `sourceTimestamp`:消息的时间戳。 - `destinationGuidPrefix`:消息的目标实体的 GUID 前缀。 其中,`guidPrefix` 和 `guidEntityId` 组成了消息的唯一标识符 GUID,用于在 Fast-RTPS 网络中识别消息。 接下来,我们可以通过以下代码示例解析 Fast-RTPS 消息的头部字段和 topic name: ```c++ #include <fastrtps/fastrtps.h> #include <fastrtps/attributes/TopicAttributes.h> void parseFastRTPSMessageHeader(const void* buffer, size_t size) { // Deserialize the message header using Fast-RTPS library eprosima::fastcdr::FastBuffer cdrbuffer(reinterpret_cast<char*>(const_cast<void*>(buffer)), size); eprosima::fastrtps::rtps::CDRMessage_t cdrm(cdrbuffer); eprosima::fastcdr::Cdr cdr_des(cdrm, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); // Parse the fields in the header eprosima::fastrtps::rtps::Header_t header; header.readFromCDRMessage(cdrm); std::cout << "protocolId: " << std::to_string(header.protocolId) << std::endl; std::cout << "vendorId: " << std::to_string(header.vendorId) << std::endl; std::cout << "guidPrefix: " << header.guidPrefix << std::endl; std::cout << "guidEntityId: " << header.guidEntityId << std::endl; std::cout << "sequenceNumber: " << std::to_string(header.sequenceNumber.to64long()) << std::endl; std::cout << "sourceTimestamp: " << header.sourceTimestamp.to_string() << std::endl; std::cout << "destinationGuidPrefix: " << header.destinationGuidPrefix << std::endl; // Deserialize the topic name from the message payload eprosima::fastrtps::TopicAttributes topic_attr; topic_attr.deserialize(&cdr_des); std::cout << "topic name: " << topic_attr.getTopicName() << std::endl; } ``` 在上述示例中,我们使用了 Fast-RTPS 库中的 `Header_t` 类和 `TopicAttributes` 类来解析消息头部和 topic name。首先,我们将消息头部反序列化为 `Header_t` 类型,并读取其中的各个字段。然后,我们从消息负载中反序列化出 `TopicAttributes` 类型,以获取 topic name。 该示例代码可以在 Fast-RTPS 库提供的各种平台和语言中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值