机器人开发--Fast DDS
- 1 介绍
- 1.1 DDS概述
- 1.2 Fast DDS 介绍
- 域与域通信
- 跨网络通信
- 2 内容
- 要素与组件介绍
- IDL (Interface Definition Language)
- eProsima Fast DDS-Gen
- ?
- 3 安装步骤
- 3.1 安装选择(linux+源码+cmake+c++)
- 3.2 模块介绍
- 3.3 环境
- 工具
- 依赖
- 3.4 cmake 安装
- 创建安装文件夹
- 克隆依赖并编译(Foonathan memory + Fast CDR)
- 安装 eProsima Fast DDS
- 安装 Fast DDS-Gen(生成IDL文件的java应用)
- 3.5 安装目录 & 环境变量
- 4 应用
- 4.1 IDL
- 4.2 使用fastddsgen 生成文件
- 4.3 mkdir build & cmake
- 4.4 测试
- 参考
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环境变量免安装使用动态库