Blog

Agility6

快速探索Fast-DDS

Tech

前言

本篇文章主要介绍,我在第一次接触FastDDS所遇到的问题。对于一个陌生的知识,我认为应该去初步了解它是做什么的、并且跑通一个最小DEMO。

参考资料 https://cloud.tencent.com/developer/article/1999079 https://fast-dds.docs.eprosima.com/en/latest/

初步了解

通过参考资料的介绍,这几个概念是比较关键的

对于DEMO的实现,重点关注PublisherSubscriber也就是发送和接收这两步

DEMO实现

mkdir ~/Fast-DDS
  1. 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
  1. 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 --build . --target install
  1. install eProsima 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 --build . --target install

Diagram

  1. 接下来我们需要使用Fast DDS Gen,这个工具是帮助我们实现idl文件 --> c++代码

    请确保环境中有jdk! Fast DDS-Gen supports Java versions from 11 to 19.

cd ~
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
./gradlew assemble

Create DEMO

cd ~
mkdir Test && cd Test
  1. 创建Test.idl
struct Test {
  string msg;
};
  1. Fast DDS Gen转化为c++代码。在Test目录下找到Fast-DDS-Gen/scripts/执行fastddsgen -example CMake Text.idl
../Fast-DDS-Gen/scripts/fastddsgen -example CMake Text.idl

Diagram

  1. 添加分别在TestPublisher.cxxTestSubscriber.cxx。分别代表了要输出什么 和 怎么输出
  1. 构建
mkdir build && cd build
cmake ..
make
  1. 执行publisher | subscriber
~/FastDDS-Test/build$ ./Test publisher
~/FastDDS-Test/build$ ./Test subscriber

DEMO

DOME