FastDDS 从源码安装到Linux FastDDS Linux Installation from Sources

FastDDS Linux installation from sources

在这里插入图片描述

FastDDS是由位于西班牙马德里的eProsima公司推出的免费开源DDS中间件解决方案,并提供付费技术支持服务。它的源码基于C++,规范基于OMG DDS 1.4 and the OMG RTPS 2.2。本文的目的是根据官方的安装步骤进行整理,并记录自己在安装过程中遇到的实际问题和解决方法。

官方文档链接:https://fast-dds.docs.eprosima.com/en/latest/
在这个线上文档中除了由对FastDDS基本的介绍,安装的方法,还有丰富的入门指导和实例解释。

FastDDS的安装按系统分有三种:

  • Windows (from Binaries 或Sources)
  • Linux(from Binaries 或Sources)
  • MAC Os (from Sources)

    You can get either a binary distribution of eprosima Fast DDS or compile the library yourself from source.

这里我装的是Linux from Sources。

FastDDS的安装内容主要有三部分:

  • Fast DDS library (必须安装)
    • foonathan_memory_vendor : C++ memory allocator lib
    • fasdcdr: CDR serialization mechanism
    • fastrtps: Fast DDS core lib

    其中安装方式又分为两种,colcon安装或CMake安装。我用的是colcon。

  • Fast DDS Python bindings (可选)

    Fast DDS Python bindings is an extension of Fast DDS which provides access to the Fast DDS API through Python.

  • Fast DDS-Gen (必须安装)
    • Java application generates source code from IDL file。由IDL文件中定义的data type生成代码的脚本工具。在旧版本中脚本工具的名字叫fastrtpsgen,大概在21年后改名叫fastddsgen
1. 安装Fast DDS Library
  1. 链接:https://fast-dds.docs.eprosima.com/en/latest/installation/sources/sources_linux.html#fast-dds-library-installation
  2. 安装依赖项:
sudo apt install cmake g++ python3-pip wget git
sudo apt install libasio-dev libtinyxml2-dev
sudo apt install libssl-dev

libp11 and HSM libs:
//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

  1. 使用Colcon 安装Fast DDS lib

3.1 安装colcon, vcstool:

pip3 install -U colcon-common-extensions vcstool

vcstool安装不成功造成命令 vcs不能使用的话,可以尝试reboot之后重新安装,也可以尝试将-U 替换成–user安装
3.2 把repos下载下来,为后面的vcs import做准备:

mkdir ~/Fast-DDS
cd ~/Fast-DDS
wget https://raw.githubusercontent.com/eProsima/Fast-DDS/master/fastrtps.repos

注意:以上命令运行之后只有fastrtps.repos一个文件,下图中的其余文件时后面build生成的

这里可能会碰到连接失败的错:

Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|::|:443... failed: Connection refused.

参考了:https://blog.csdn.net/laoxuan2011/article/details/106177126/?utm_term=https://raw.githubusercontent.com/&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-0-106177126&spm=3001.4430

需要修改/etc/hosts,在末尾添加一行:
151.101.76.133(此IP是通过本机IP查询的值) raw.githubusercontent.com


3.3 下一步,把repos的内容导入到src文件夹:

mkdir src
vcs import src < fastrtps.repos

3.4 build packages:

colcon build

这里可能遇到CMake版本问题,因为colcon是依赖CMake build的。我用的ubuntu 18.04,用第一步依赖项安装的时候,cmake版本最高都没有达到colcon要求的版本。

CMake 3.8(具体3点几没记住) or higher is required. 

按照 https://www.cnblogs.com/jsdy/p/12689470.html 的方法卸载重新安装了3.16的CMake。

但是这里安装的路径到了/usr/local/bin/cmake,而不是colcon默认使用的/usr/bin/cmake路径。所以后面又碰到了这个错:

make: /usr/bin/cmake: Command not found

通过以下命令把两个路径关联了:

sudo ln -s /usr/local/bin/cmake /usr/bin/cmake

或者可以找方法,在安装的时候就指定路径到/usr/bin/cmake。

  1. 准备环境变量

4.1 每次新打开一个shell的时候可以运行source命令,设置局部环境变量:

source ~/Fast-DDS/install/setup.bash

4.2 或者设置永久环境变量:

echo 'source ~/Fast-DDS/install/setup.bash' >> ~/.bashrc

这样就可以使用fastdds命令了。


2. 安装Fast DDS-Gen
  1. 链接:https://fast-dds.docs.eprosima.com/en/latest/installation/sources/sources_linux.html#fast-dds-gen-installation

  2. 安装Java JDK:

    sudo apt install openjdk-8-jdk
    
  3. 安装Gradle:

    这一步不用装。Gradle是一个开源自动化build工具。我从Gradle下了安装包安装完发现不能用,看起来是版本问题。官方最新版是7.4.2。Fast DDS-gen用6.4就可以。后面会说到免安装的方法。

  4. 从git clone dds-gen的包:

    这一步按照官网说法,前面用colcon安装就不用git clone:

    If already installed FastDDS with colcon, you may skip the git clone command; fastddsgen can be found under the src directory of FastDDS colcon workspace.

    但是我的Fast-DDS/src/fastddsgen下面几乎是空的只有一个thirdparty文件夹,并不能成功build,所以我还是git clone了一下:

    执行git clone:

    cd ~
    git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
    
  5. 执行gradle编译

    cd Fast-DDS-Gen
    //gradle assemble   这一步是安装了gradle的情况下执行的。我没用,用了报错。
    ./gradlew assemble  这里我用免安装的方法编译了。就是下面说的executable script
    

    运行/gradlew assemble 之后才能生成如下图的share文件夹,否则调用fastddsgen工具时会报如下图的错误。
    在这里插入图片描述
    在这里插入图片描述

    If errors occur during compilation or you do not wish to install gradle, an executable script is included which will download a gradle temporarily for the compilation step.

  6. 把fastddsgen的命令放到环境变量

    cd /etc
    sudo gedit profile
    

    在profile末尾加入:

    export PATH="$PATH:~/Fast-DDS-Gen/scripts"
    

    重新登录
    可以看到fastddsgen的命令加进来了:

<think>好的,我现在需要帮助用户解决在ROS2中升级Fast DDS的问题。首先,用户提到了几个引用,我需要仔细看看这些引用内容,确保我的回答准确。 根据引用[1],Fast DDS是ROS2的默认DDS实现,可以通过apt安装特定版本的rmw-fastrtps包。用户可能已经安装了某个版本,现在想要升级。引用[3]提到了Fast DDS的官方文档,应该引导用户参考那里。 接下来,我需要考虑用户的实际操作步骤。升级通常有两种方法:通过包管理器升级,或者从源码编译安装。包管理器方法比较简单,适合大多数用户。但用户可能需要特定版本或最新功能,这时候源码安装更合适。另外,升级后需要重新配置ROS2的RMW设置,确保使用新版本的Fast DDS。 需要注意的依赖问题,比如ROS2发行版和Fast DDS版本的兼容性。用户需要确认他们的ROS2版本支持的Fast DDS版本,避免不兼容导致的问题。此外,如果用户之前从源码安装过,可能需要先卸载旧版本,再安装新版本。 用户可能遇到的问题包括安装失败、版本冲突或者运行时报错。这时候需要建议他们检查版本兼容性,清理旧安装,或者参考官方文档和社区资源。引用[2]提到小鱼写过相关教程,虽然链接不可见,但可以建议用户搜索这些资源获取更多帮助。 最后,生成相关问题时要覆盖安装后的验证、常见问题处理、不同DDS实现的比较,以及性能优化等方面。这样用户如果有其他疑问,可以自行查找答案。</think>### ROS2 中升级Fast DDS的详细方法 #### 1. **通过包管理器升级(推荐)** 若已通过`apt`安装Fast DDS(即`rmw-fastrtps`包),可执行以下步骤: ```bash # 更新软件包列表 sudo apt update # 升级所有已安装包(包含Fast DDS) sudo apt upgrade # 单独升级Fast DDS相关包 sudo apt install --only-upgrade ros-<ros2-distro>-rmw-fastrtps ``` **注意**:需将`<ros2-distro>`替换为实际ROS2发行版名称(如`humble`、`iron`等)[^1]。 --- #### 2. **源码编译升级(自定义版本)** 若需使用官方未发布的版本或最新特性,需从源码编译: ```bash # 下载Fast DDS源码 git clone --recursive https://github.com/eProsima/Fast-DDS.git cd Fast-DDS # 切换指定版本(如2.11.0) git checkout v2.11.0 # 编译安装 mkdir build && cd build cmake -DTHIRDPARTY=ON -DSECURITY=ON .. make -j$(nproc) sudo make install ``` **关键参数说明**: - `-DSECURITY=ON`:启用DDS安全功能(需ROS2支持) - `-DTHIRDPARTY=ON`:自动安装依赖库[^3] --- #### 3. **验证升级结果** ```bash # 查看Fast DDS版本 fastdds --version # 设置ROS2使用Fast DDS export RMW_IMPLEMENTATION=rmw_fastrtps_cpp ros2 run demo_nodes_cpp talker ``` 若需永久生效,可将`export`语句加入`~/.bashrc`文件。 --- #### 4. **官方文档参考** - **Fast DDS安装指南**:[Linux installation from binaries](https://fast-dds.docs.eprosima.com/en/latest/installation/sources/sources_linux.html) - **ROS2与DDS兼容性**:[ROS2 RMW Implementation](https://docs.ros.org/en/rolling/Concepts/About-DDS-implementations.html) ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值