ROS2- 接口-FastDDS的安装和体验-12


FastDDS的安装和体验

源码安装

apt upgrade
apt install python3-colcon-common-extensions zip openjdk-8-jdk -y
pip3 install vcstool
apt-get install libasio-dev -y

mkdir -p fastdds_ws/src
cd fastdds_ws && wget https://downloads.gradle-dn.com/distributions/gradle-6.4-bin.zip && unzip gradle-6.4-bin.zip

设置GRADLE_HOME

export GRADLE_HOME=$PWD/gradle-6.4

将gradle添加到PATH

export PATH=\(GRADLE_HOME/bin:\)PATH

验证配置

gradle --version

vi fastrtps.repos

repositories:
    foonathan_memory_vendor:
        type: git
        url: https://github.com/eProsima/foonathan_memory_vendor.git
        version: master
    fastcdr:
        type: git
        url: https://github.com/eProsima/Fast-CDR.git
        version: master
    fastrtps:
        type: git
        url: https://github.com/eProsima/Fast-DDS.git
        version: master
    fastddsgen:
        type: git
        url: https://github.com/eProsima/Fast-DDS-Gen.git
        version: master
    fastddsgen/thirdparty/idl-parser:
        type: git
        url: https://github.com/eProsima/IDL-Parser.git
        version: master

执行
vcs import src < fastrtps.repos

cd src && colcon build
cd fastddsgen/ && gradle assemble

xxx是你的目录前缀
echo 'source xxx/fastdds_ws/install/setup.bash' >> ~/.bashrc
echo 'export PATH=$PATH:xxx/fastdds_ws/gradle-6.4/bin/' >> ~/.bashrc
echo 'export DDSGEN=xxx/fastdds_ws/src/fastddsgen/scripts' >> ~/.bashrc

/home/stephen/chapt3/

echo 'source /root/stephen/chapt3/fastdds_ws/install/setup.bash' >> ~/.bashrc
echo 'export PATH=$PATH:/root/stephen/chapt3/fastdds_ws/gradle-6.4/bin/' >> ~/.bashrc
echo 'export DDSGEN=/root/stephen/chapt3/fastdds_ws/src/fastddsgen/scripts' >> ~/.bashrc

DDS使用的RTPS,就是Real-Time Publish Subscribe协议,
和ROS与ROS2中的发布订阅一样
跑一个例程来收发消息,消息内容就叫HelloFish

git clone https://github.com/fishros/dds_tutorial.git
cd dds_tutorial/examples/01-hellofishros
mkdir build && cd build
cmake ..
make

开一个终端
./DDSHelloFishRosPublisher
开另一个终端
./DDSHelloFishRosSubscribe

日志


root@ubuntu-16:~/stephen/chapt3/fastdds_ws# cd ~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# ./DDSHelloFishRosSubscribe
Starting subscriber.
Subscriber matched.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 1 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 2 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 3 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 4 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 5 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 6 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 7 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 8 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 9 RECEIVED.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 10 RECEIVED.
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# ^C
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build#


root@ubuntu-16:~/stephen/chapt3/fastdds_ws# cd ../
root@ubuntu-16:~/stephen/chapt3# ls -la
total 16
drwxr-xr-x 4 root root 4096 Jun 10 08:19 .
drwxr-xr-x 7 root root 4096 Jun  9 09:49 ..
drwxr-xr-x 6 root root 4096 Jun 10 02:14 chapt3_ws
drwxr-xr-x 8 root root 4096 Jun 10 08:59 fastdds_ws
root@ubuntu-16:~/stephen/chapt3# git clone https://github.com/fishros/dds_tutorial.git
Cloning into 'dds_tutorial'...
remote: Enumerating objects: 23, done.
remote: Total 23 (delta 0), reused 0 (delta 0), pack-reused 23 (from 1)
Receiving objects: 100% (23/23), 13.84 KiB | 125.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
root@ubuntu-16:~/stephen/chapt3# cd dds_tutorial/examples/01-hellofishros
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros# mkdir build && cd build
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# cmake ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
-- Performing Test SUPPORTS_CXX11
-- Performing Test SUPPORTS_CXX11 - Success
-- Configuring HelloFishRos publisher/subscriber example...
-- Configuring done
-- Generating done
-- Build files have been written to: /root/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# make
[ 12%] Building CXX object CMakeFiles/DDSHelloFishRosPublisher.dir/src/HelloFishRosPublisher.cpp.o
[ 25%] Building CXX object CMakeFiles/DDSHelloFishRosPublisher.dir/src/idl_generate/HelloFishRos.cxx.o
[ 37%] Building CXX object CMakeFiles/DDSHelloFishRosPublisher.dir/src/idl_generate/HelloFishRosPubSubTypes.cxx.o
[ 50%] Linking CXX executable DDSHelloFishRosPublisher
[ 50%] Built target DDSHelloFishRosPublisher
[ 62%] Building CXX object CMakeFiles/DDSHelloFishRosSubscribe.dir/src/HelloFishRosSubscribe.cpp.o
[ 75%] Building CXX object CMakeFiles/DDSHelloFishRosSubscribe.dir/src/idl_generate/HelloFishRos.cxx.o
[ 87%] Building CXX object CMakeFiles/DDSHelloFishRosSubscribe.dir/src/idl_generate/HelloFishRosPubSubTypes.cxx.o
[100%] Linking CXX executable DDSHelloFishRosSubscribe
[100%] Built target DDSHelloFishRosSubscribe
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# ls -la
total 536
drwxr-xr-x 3 root root   4096 Jun 10 09:59 .
drwxr-xr-x 4 root root   4096 Jun 10 09:59 ..
-rw-r--r-- 1 root root  17397 Jun 10 09:59 CMakeCache.txt
drwxr-xr-x 6 root root   4096 Jun 10 09:59 CMakeFiles
-rwxr-xr-x 1 root root 247088 Jun 10 09:59 DDSHelloFishRosPublisher
-rwxr-xr-x 1 root root 249384 Jun 10 09:59 DDSHelloFishRosSubscribe
-rw-r--r-- 1 root root  11526 Jun 10 09:59 Makefile
-rw-r--r-- 1 root root   1692 Jun 10 09:59 cmake_install.cmake
root@ubuntu-16:~/stephen/chapt3/dds_tutorial/examples/01-hellofishros/build# ./DDSHelloFishRosPublisher
Starting publisher.
Publisher matched.
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 1 SENT
...
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 9 SENT
Message: HelloFishRos!关注小鱼!学习机器人不迷路~ with index: 10 SENT
Publisher unmatched.

posted @ 2025-06-10 17:08  jack-chen666  阅读(9)  评论(0)    收藏  举报