机器人开发--Fast DDS

2 篇文章 1 订阅

1 介绍

1.1 DDS概述

数据分发服务DDS(DataDistributionService)是OMG对象管理组织在HLA及CORBA等标准的基础上制定的新一代分布式实时通信中间件技术规范,DDS采用发布/订阅体系架构,强调以数据为中心,提供丰富的QoS服务质量策略,能保障数据进行实时、高效、灵活地分发,可满足各种分布式实时通信应用需求。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1.2 Fast DDS 介绍

  • 开源
  • 是自动驾驶领域比较有影响力的开源DDS
  • 是由RTI原核心团队成员在欧洲创办的eProsima公司推出的FastDDS。
  • FastDDS使用起来比较麻烦,这个时候,用户就需要通过向eProsima支付费用来取得支持。

域与域通信

在这里插入图片描述

跨网络通信

在这里插入图片描述

2 内容

要素与组件介绍

IDL (Interface Definition Language)

要声明结构化数据,必须使用 IDL 格式。IDL (接口定义语言)是一种规范语言,由OMG(对象管理组织)制定,它以与语言无关的方式描述接口,允许不同语言的软件组件之间进行通信。

eProsima Fast DDS-Gen

eProsima Fast DDS-Gen是一个 Java 应用程序,它使用 IDL(接口定义语言)文件中定义的数据类型生成eProsima Fast DDS源代码。
eProsima Fast DDS-Gen生成的源代码使用Fast CDR,这是一个提供数据序列化和编码机制的 C++11 库。因此,正如RTPS 标准中所述,发送数据时,它们会使用相应的通用数据表示 (CDR) 进行序列化和编码。CDR 传输语法是代理间传输的低级表示,从 OMG IDL 数据类型映射到字节流。

eProsima Fast DDS通过两个类定义了 Topic 中交换的数据类型: theTypeSupport和 the TopicDataType。TopicDataType描述发布和订阅之间交换的数据类型,即Topic对应的数据;尽管TypeSupport封装了一个 TopicDataType 的实例,提供注册类型和与发布和订阅交互所需的功能。

3 安装步骤

3.1 安装选择(linux+源码+cmake+c++)

系统选择:

  • linux
  • windows(更麻烦)

安装方式:

  • 源码安装
  • 二进制安装

源码安装工具:

  • colcon(配套 ROS2)
  • cmake

语言:

  • C++
  • Python

3.2 模块介绍

src目录下包含如下几个模块:
foonathan_memory_vendor, an STL compatible C++ memory allocator library.
fastcdr, a C++ library for data serialization according to the CDR standard (Section 10.2.1.2 OMG CDR).
fastrtps, the core library of eProsima Fast DDS library.
fastddsgen, a Java application that generates source code using the data types defined in an IDL file.

3.3 环境

工具

  • CMake
  • g++
  • pip3
  • wget
  • git
sudo apt install cmake g++ python3-pip wget git

依赖

  • Asio and TinyXML2 libraries
  • OpenSSL
  • Libp11 and SoftHSM libraries
  • Gtest [optional]
  • XML validation tool [optional]
# Asio is a cross-platform C++ library for network and low-level I/O programming, which provides a consistent asynchronous model. TinyXML2 is a simple, small and efficient C++ XML parser. Install these libraries using the package manager of the appropriate Linux distribution. For example, on Ubuntu use the command:
sudo apt install libasio-dev libtinyxml2-dev

# OpenSSL is a robust toolkit for the TLS and SSL protocols and a general-purpose cryptography library. Install OpenSSL using the package manager of the appropriate Linux distribution. For example, on Ubuntu use the command:
sudo apt install libssl-dev

# Libp11 provides PKCS#11 support for OpenSSL. This is an optional dependency, that is needed only when eprosima Fast DDS is used with security and PKCS#11 URIs.
# Install libp11 using the package manager of the appropriate Linux distribution. For example, on Ubuntu use the command:
sudo apt install libp11-dev libengine-pkcs11-openssl

# SoftHSM is a software implementation of an HSM (Hardware Security Module). If eProsima Fast DDS tests are activated and libp11 is installed on the system, SoftHSM is additionally required to run tests of PKCS#11 features.
# Install SoftHSM using the package manager of the appropriate Linux distribution. For example, on Ubuntu use the command:
sudo apt install softhsm2

# Note that the softhsm2 package creates a new group called softhsm. In order to grant access to the HSM module a user must belong to this group.
sudo usermod -a -G softhsm <user>
示例:sudo usermod -a -G softhsm $USER

# OpenSSL access HSM and other hardware devices through its engine functionality. In order to set up a new engine the OpenSSL configuration files (usually /etc/ssl/openssl.cnf) must be updated specifying the libp11 and hardware module (here SoftHSM) dynamic libraries location.
# This configuration step can be avoided using p11kit which allows OpenSSL to find PKCS#11 devices on runtime without static configuration. This kit is often available through the Linux distribution package manager. On Ubuntu, for example:
sudo apt install libengine-pkcs11-openssl

# Once installed, to check p11kit is able to find the SoftHSM module use:
p11-kit list-modules

# In order to check if OpenSSL is able to access PKCS#11 engine use:
openssl engine pkcs11 -t

3.4 cmake 安装

创建安装文件夹

Create a Fast-DDS directory where to download and build eProsima Fast DDS and its dependencies:

mkdir ~/Fast-DDS

克隆依赖并编译(Foonathan memory + Fast CDR)

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

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

安装 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

安装 Fast DDS-Gen(生成IDL文件的java应用)

Fast DDS-Gen is a Java application that generates source code using the data types defined in an IDL file.

  • 安装Java JDK
sudo apt install openjdk-11-jdk
  • 源码编译
cd ~/Fast-DDS
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
./gradlew assemble
u20@u20:~/Fast-DDS/Fast-DDS-Gen$ sudo ./gradlew assemble
Downloading https://services.gradle.org/distributions/gradle-7.6-bin.zip
...........10%............20%...........30%............40%............50%...........60%............70%............80%...........90%............100%

Welcome to Gradle 7.6!

Here are the highlights of this release:
 - Added support for Java 19.
 - Introduced `--rerun` flag for individual task rerun.
 - Improved dependency block for test suites to be strongly typed.
 - Added a pluggable system for Java toolchains provisioning.

For more details see https://docs.gradle.org/7.6/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 2m 9s
6 actionable tasks: 3 executed, 3 up-to-date
u20@u20:~/Fast-DDS/Fast-DDS-Gen$ 

The Fast-DDS-Gen folder contains the following packages:

    • share/fastddsgen, where the generated Java application is.
    • scripts, containing some user friendly scripts.

3.5 安装目录 & 环境变量

u20@u20:~/Fast-DDS/install/lib$ ls
cmake          libfastcdr.so.1      libfastrtps.so       libfastrtps.so.2.11.0
libfastcdr.so  libfastcdr.so.1.1.0  libfastrtps.so.2.11
u20@u20:~/Fast-DDS/install/bin$ ls
fastdds  fast-discovery-server  fast-discovery-server-1.0.1  ros-discovery
u20@u20:~/Fast-DDS/Fast-DDS-Gen/scripts$ ls
fastddsgen  fastddsgen.bat  fastddsgen.in

vim .bashrc 文件末加入如下路径:

export PATH=$PATH:/home/u20/Fast-DDS/Fast-DDS-Gen/scripts
export PATH=$PATH:/home/u20/Fast-DDS/install/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/u20/Fast-DDS/install/lib

通过“source ~/.bashrc”命令使修改立即生效,或者重开终端窗口。

4 应用

4.1 IDL

以一个helloworld 为例,编写一个idl,helloworld.idl

struct HelloWorld
{
    unsigned long index;
    string message;
};

4.2 使用fastddsgen 生成文件

fastddsgen -example CMake helloworld.idl

生成文件如下:

CMakeLists.txt
helloworld.cxx
helloworld.h
helloworld.idl
helloworldPublisher.cxx
helloworldPublisher.h
helloworldPubSubMain.cxx
helloworldPubSubTypes.cxx
helloworldPubSubTypes.h
helloworldSubscriber.cxx
helloworldSubscriber.h

4.3 mkdir build & cmake

操作命令

mkdir build
cd build
cmake ..
make

生成如下

u20@u20:~/user/build$ ls
CMakeCache.txt  CMakeFiles  cmake_install.cmake  helloworld  libhelloworld_lib.a  Makefile

4.4 测试

  • 终端1:
u20@u20:~/user/build$ ./helloworld publisher
Starting 
HelloWorld DataWriter created.
HelloWorld DataWriter waiting for DataReaders.
DataWriter matched.
Sending sample, count=1, send another sample?(y-yes,n-stop): y
Sending sample, count=2, send another sample?(y-yes,n-stop): y
Sending sample, count=3, send another sample?(y-yes,n-stop): y
Sending sample, count=4, send another sample?(y-yes,n-stop): y
Sending sample, count=5, send another sample?(y-yes,n-stop): y
Sending sample, count=6, send another sample?(y-yes,n-stop): n
Stopping execution 
u20@u20:~/user/build$ 
  • 终端2:
u20@u20:~/user/build$ ./helloworld subscriber
Starting 
Waiting for Data, press Enter to stop the DataReader. 
Subscriber matched.
Sample received, count=1
Sample received, count=2
Sample received, count=3
Sample received, count=4
Sample received, count=5
Sample received, count=6
Subscriber unmatched.

Shutting down the Subscriber.
u20@u20:~/user/build$

参考

1、官方–FastDDS文档
2、机器人开发–DDS数据分发服务
3、fastdds router-3.开始
4、FastDDS-源码编译&安装&测试
5、fastdds交叉编译
6、官方–3. Linux installation from sources
7、FastDDS使用、原理和避坑
8、ubuntu查看和修改PATH环境变量的方法
9、Ubuntu/CentOS设置LD_LIBRARY_PATH环境变量免安装使用动态库

### 回答1: Fast-DDS是一个高性能的、基于数据发布-订阅模型的通信协议。它提供了丰富的QoS(服务质量)策略以及灵活的路由机制,以满足不同场景下的通信需求。 其中,QoS策略是指在数据传输的过程中,可以通过一定的配置方式来控制数据传输的质量、可靠性、延时等因素。Fast-DDS中提供了多种QoS策略,包括消息传输的可靠性、数据的存储方式、订阅者优先级等。 在Fast-DDS中,消息传输的可靠性可以通过以下几种QoS策略来控制: 1. RELIABILITY,即可靠性:用于控制消息的可靠性,包括发布者和订阅者之间的ack确认机制,以及网络连接中的重传机制。 2. DURABILITY,即持久性:用于控制消息的持久化方式,包括将消息写入本地磁盘或将消息存储在内存中。 3. HISTORY,即历史消息:用于控制订阅者在订阅之前是否可以获取历史消息,以及历史消息保存的方式(内存中、磁盘中、或通过文件传输)。 除了上述QoS策略,Fast-DDS还提供了很多其他的QoS选项,如数据传输的优先级、最大传输延迟、数据分发的方式等等,以满足不同的通信场景需求。 总体而言,Fast-DDS的QoS策略提供了丰富的选项和灵活的配置方式,能够帮助开发人员实现高性能、可靠的数据传输。 ### 回答2: Fast-DDS是一种高性能的DDS实现,可以用于构建实时和分布式系统。Fast-DDS支持多种QoS策略,这些策略允许用户在系统性能和资源利用率之间做出权衡。以下是Fast-DDS的QoS策略的几个关键点: 1. 可靠性:Fast-DDS支持可靠和非可靠的通信,通过配置可靠性参数,可以控制数据重传和丢失时间等方面的行为。 2. 带宽控制:Fast-DDS支持带宽限制,通过配置带宽参数,可以限制系统的带宽使用,从而避免因过度使用带宽导致的卡顿和延迟。 3. 时间同步:Fast-DDS支持时间同步,通过配置时间同步参数,可以在系统中确立一个统一的时间基准,从而避免因时间差异而导致的不一致性。 4. 优先级:Fast-DDS支持消息优先级,通过配置优先级参数,可以确保重要消息的优先传输,从而提高系统的响应能力。 5. QoS Inheritance: Fast-DDS支持QoS继承,它允许用户在不同级别的实体之间继承QoS属性。例如,可将主题级别的QoS继承到订阅者级别,从而确保所有订阅者都使用同一的QoS策略。 综上所述,Fast-DDS的QoS策略提供了一些非常有用的功能,可以帮助用户在不同的反应性和资源利用率需求之间做出权衡,从而优化系统的性能和可靠性。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

worthsen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值