PX4模块设计之六:PX4-Fast RTPS(DDS)简介

@[TOC](PX4模块设计之六:PX4-Fast RTPS(DDS)简介)

基于PX4开源软件框架简明简介的框架设计,逐步分析内部模块功能设计。

PX4-Fast RTPS(DDS)具有实时发布/订阅uORB消息接口,用于AutoPilot内部组件或者offboard实时应用。其针对的主要应用是计算机视觉和传感器应用实时控制。Fast DDS的应用目标并非是替换MAVLink,目前,MAVLink仍然是地面站、平衡架、摄像头、offboard应用的主要通信接口;但是Fast DDS主要应用在搞通信带宽,高频率数据更新的场景。

1. DDS & Fast RTPS(DDS) 简介

DDS全称是Data Distribution Service,这是一套通信协议和API标准,它提供了以数据为中心的连接服务,基于发布者-订阅者模型。Fast-RTPS(DDS)是DDS的开源实现,借助它可以方便的开发出高效,可靠的分布式系统。
4thDDS发展历程

  • (第一代)点对点的CS(Client-Server)结构,这是大家最为熟悉的:一个服务器角色被许多的客户端使用,每次通信时,通信双方必须建立一条连接。当通信节点增多时,通信的连接数也会增多。并且,每个客户端都必须知道服务器的具体地址和所提供的服务。一旦服务器地址发生变化,所有客户端都会受到影响。
  • (第二代)Broker模型:存在一个中间人,它负责初步处理大家的请求,并进一步找到真正能响应服务的角色,这就好像存在一个经纪人。这为客户端提供了一层抽象,使得服务器的具体地址变得不重要了。服务端地址如果发生变化,只需要告诉Broker就可以了。但这个模型的问题在于,Broker变成了模型的中心,它的处理速度会影响所有人的效率,这就好像城市中心的路口,当系统规则增长到一定程度,Broker终究会成为瓶颈。更糟糕的是,如果Broker瘫痪了,可能整个系统都将无法运转。
  • (第三代)广播模型:所有人都可以在通道上广播消息,并且所有人都可以收到消息。这个模型解决了服务器地址的问题,且通信双方不用单独建立连接,但它存在的问题是:广播通道上的消息太多,太嘈杂,所有人都必须关心每条消息是否与自己有关。这就好像全公司一千号人坐在同一个房间里面办公一样。
  • (第四代)DDS模型:这种模型与广播模型有些类似,所有人都可以在DataBus上发布和读取消息。但它更进一步的是,通信中包含了很多并行的通路,每个人可以只关心自己感兴趣的消息,自动忽略自己不需要的消息。

DDS 在OSI的位置

2. PX4-Fast RTPS(DDS) 架构

Fast-RTPS(DDS)是eprosima对于RTPS的C++实现,这是一个免费开源软件,遵循Apache License 2.0。
Fast-RTPS(DDS)支持平台包括:Windows, Linux, Mac OS, QNX, VxWorks, iOS, Android, Raspbian。
Fast-RTPS(DDS)具有以下优点:

  • 对于实时应用程序来说,可以在Best-Effort和可靠通信两种策略上进行配置。
  • 即插即用的连接性,使得网络的所有成员自动发现其他新的成员。
  • 模块化和可扩展性允许网络中设备不断增长。
  • 可配置的网络行为和可互换的传输层:为每个部署选择最佳协议和系统输入/输出通道组合。
  • 两个API层:一个简单易用的发布者-订阅者层和一个提供对RTPS协议内部更好控制的Writer-Reader层。

注1:Publisher-Subscriber层:RTPS上的简化抽象。
注2:Writer-Reader层:对于RTPS端点的直接控制。

RTPS(DDS)设计框图RTPS(DDS)UML

2.1 microRTPS Bridge

microRTPS桥接器在PX4和DDS参与应用程序之间交换消息,在每个系统使用的uORB和RTPS/DDS消息之间无缝转换。

架构主要通过其客户端和代理组成。
PX4 Fast RTPS/DDS Architect

2.2 microRTPS Client

microRTPS客户端是在飞行控制器上运行的PX4自动驾驶仪中间件守护进程。该客户端订阅由其他PX4自动驾驶仪组件发布的uORB主题,并向代理发送任何更新(通过UART或UDP端口),还从代理接收消息,并将其作为uORB消息发布到PX4自动驾驶仪。

2.3 microRTPS Agent

microRTPS代理作为后台进程在伴飞计算机(飞行控制器外部)上运行。该代理监视来自客户端的uORB更新消息,并(重新)通过RTP发布这些消息,还订阅来自其他DDS参与者应用程序的“uORB”RTP/DDS消息,并将其转发给客户端。

2.4 microRTPS Agent/Client Communication

代理和客户端通过串行链路(UART)或UDP网络连接,uORB信息通过CDR序列化机制,提供了在不同平台之间交换串行数据的通用格式。在典型配置中,它们将位于连接到客户端的同一系统(例如,开发计算机、Linux配套计算机或计算板)上,硬件上可以通过Wifi链接或USB进行。

3. Fast RTPS(DDS)安装

eProsima Fast DDS是对象管理组(OMG)数据分发服务(DDS)规范和实时发布订阅(RTPS)协议的C++实现。
Fast DDS支持RTPS/DDS接口,允许PX4 uORB主题与参与同一DDS域的非车载组件共享,包括机器人和模拟器工具。特别是,快速DDS是机器人操作系统2(ROS 2)的默认中间件。

3.1 安装前提条件

3.1.1 基础环境

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal
$ java --version
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)

使用ubuntu下的gradle组件

$ sudo apt-get install gradle
$ gradle --version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------

Build time:   2012-12-21 00:00:00 UTC
Revision:     none

Groovy:       2.4.17
Ant:          Apache Ant(TM) version 1.10.7 compiled on October 24 2019
JVM:          11.0.15 (Private Build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OS:           Linux 5.13.0-52-generic amd64

安装Foonathan memory

$ git clone https://github.com/eProsima/foonathan_memory_vendor.git
$ cd foonathan_memory_vendor
$ mkdir build && cd build
$ cmake ..
$ sudo cmake --build . --target install

3.1.2 eProsima Fast DDS版本

  • Ubuntu 18.04: Fast RTPS 1.8.4 (or later) and Fast-RTPS-Gen 1.0.4 (not later!).
  • Ubuntu 20.04: Fast DDS 2.0.2 (or later) and Fast-RTPS-Gen 1.0.4 (not later!).

TIP
Remember (again) you only need to install Fast DDS if you are not using ROS 2 and just want to leverage non-ROS2 DDS networks and applications.

3.2 二进制安装eProsima Fast DDS v2.7.0版本

注:推荐采用二进制安装,一般发布的二进制版本都会进行比较完善的测试。除非您对这个源代码非常熟悉,那么可以忽略我们的担忧。

3.2.1 官网下载最新eProsima_Fast-DDS版本

鉴于我们采用ubuntu20.04,以及官网最新二进制发布件为2.7.0,满足前提条件>=2.0.2要求。
Fast DDS latest binary

3.2.2 安装eProsima_Fast-DDS

使用下面命令进行安装

注:建议使用迅雷,速度快点,且文件名比较标准,wget下来的文件名需要重命名。如果链接出现问题,请直接从官网下载链接进去。

$ mkdir eProsima_Fast-DDS-v2.7.0-Linux
$ wget https://www.eprosima.com/index.php/component/ars/repository/eprosima-fast-dds/eprosima-fast-dds-2-7-0/eprosima_fast-dds-v2-7-0-linux-tgz?format=raw 
$ tar zxvf eProsima_Fast-DDS-v2.7.0-Linux.tgz  //解压二进制
$ sudo ./install.sh  //需要一段时间,请耐心等待

安装完成可以简单测试下以下命令是否已经在系统中。

$ fastdds -h
usage: fastdds <command> [<command-args>]

    Commands:

        discovery     Server-Client discovery auxiliary generator

        shm           Shared-memory commands

    fastdds <command> [-h] shows command usage


positional arguments:
  command     Command to run

optional arguments:
  -h, --help  show this help message and exit

$ fastddsgen -help
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
fastddsgen usage:
        fastddsgen [options] <file> [<file> ...]
        where the options are:
                -help: shows this help
                -version: shows the current version of eProsima Fast DDS gen.
                -example <platform>: Generates a solution for a specific platform (example: x64Win64VS2015)
                        Supported platforms:
                         * i86Win32VS2013
                         * x64Win64VS2013
                         * i86Win32VS2015
                         * x64Win64VS2015
                         * i86Linux2.6gcc
                         * x64Linux2.6gcc
                         * armLinux2.6gcc
                         * CMake
                -replace: replaces existing generated files.
                -ppDisable: disables the preprocessor.
                -ppPath: specifies the preprocessor path.
                -typeros2: generates type naming compatible with ROS2.
                -I <path>: add directory to preprocessor include paths.
                -d <path>: sets an output directory for generated files.
                -t <temp dir>: sets a specific directory as a temporary directory.
                -typeobject: generates TypeObject files to automatically register the types as dynamic.
                -cs: IDL grammar apply case sensitive matching.
                -test: executes FastDDSGen tests.
                -python: generates python bindings for the generated types.
        and the supported input files are:
        * IDL files.

3.2.3 配合Debug下载 Fast DDS Monitor

有windows/linux等版本可供下载,这个安装使用相对简单,请自行研究(详见eprosima官网)。
Fast DDS Monitor

3.3 源代码安装eProsima Fast DDS Gen v1.0.4版本

直接从源代码下载,但是安装命令做了调整(可能是ubuntu的默认gradle的版本太高了(不兼容)

git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git -b v1.0.4 Fast-RTPS-Gen \
    && cd Fast-RTPS-Gen \
    && ./gradlew assemble \
    && sudo env "PATH=$PATH" ./gradlew install
$ git log -n 1
commit 56044ae7c493834f4789893a360c6df28642691e (HEAD, tag: v1.0.4)
Author: Miguel Company <miguelcompany@eprosima.com>
Date:   Wed Apr 1 09:52:58 2020 +0200

    Bump version to 1.0.4

$ /usr/local/bin/fastrtpsgen -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
fastrtpsgen version 1.0.4

4. Fast RTPS(DDS)应用

4.1 Fast RTPS(DDS) ROS 2应用

ROS 2应用涉及广泛,这里不展开讨论,后续有时间再做进一步研究 TBD。

For information about how to use this interface within the ROS 2 applications and development workflows, see PX4-ROS 2 bridge.

Fast RTPS(DDS)Application

4.2 Fast RTPS(DDS) 非ROS应用

4.2.1 配置uORB消息

生成的Fast RTPS(DDS) 代码将允许通过RTPS发布/订阅uORB主题的指定子集,无论是否部署ROS应用程序。

对于自动代码生成,PX4在PX4-Autopilot/msg/tools/uorb_rtps_message_ids.yaml定义了要与RTPS一起使用的uORB消息集,消息是要发送、接收还是两者都要发送,以及要在DDS/RTPS中间件中使用的消息的RTPS ID。

Note
It’s essential to note that every RTPS message needs an ID to be set in this file.

4.2.2 构建Client (PX4/PX4-Autopilot)

编译命令

$ make px4_sitl_rtps

启动环境

$ make px4_sitl_rtps jmavsim

模拟环境下,micrortps_client命令参数

pxh> micrortps_client 
Usage: micrortps_client <command> [arguments...]
 Commands:

   start
     [-t <val>]  Transport protocol
                 values: UART|UDP, default: UART
     [-d <val>]  Select Serial Device
                 values: <file:dev>, default: /dev/ttyACM0
     [-b <val>]  Baudrate (can also be p:<param_name>)
                 default: 460800
     [-m <val>]  Maximum sending data rate in B/s (0=not limited)
                 default: 0
     [-p <val>]  Poll timeout for UART in milliseconds
                 default: 1
     [-l <val>]  Limit number of iterations until the program exits (-1=infinite)
     [-w <val>]  Iteration time for data publishing to the uORB side, in microseconds
                 default: 1000
     [-r <val>]  Select UDP Network Port for receiving (local)
                 default: 2019
     [-s <val>]  Select UDP Network Port for sending (remote)
                 default: 2020
     [-i <val>]  Select IP address (remote)
                 values: <x.x.x.x>, default: 127.0.0.1
     [-f]        Activate UART link SW flow control
     [-h]        Activate UART link HW flow control
     [-v]        Add more verbosity

   stop

   status

4.2.3 构建Agent (Offboard)

编译命令

$ cd build/px4_sitl_rtps/src/modules/micrortps_bridge/micrortps_agent
$ mkdir -p build && cd build
$ cmake ..
$ make

Offboard环境(PC),micrortps_agent命令参数

$ ./micrortps_agent -h
--- MicroRTPS Agent ---
usage: ./micrortps_agent [options]

  -b <baudrate>           UART device baudrate. Defaults to 460800
  -d <device>             UART device. Defaults to /dev/ttyACM0
  -f <sw-flow-control>    Activates UART link SW flow control
  -g <hw-flow-control>    Activates UART link HW flow control
  -i <ip-address>         Target remote IP address for UDP. Defaults to 127.0.0.1
  -n <namespace>          Topics namespace. Identifies the vehicle in a multi-agent network
  -o <poll-ms>            UART polling timeout in milliseconds. Defaults to 1ms
  -r <reception-port>     UDP port for receiving (local). Defaults to 2020
  -s <sending-port>       UDP port for sending (remote). Defaults to 2019
  -t <transport>          [UART|UDP] Defaults to UART
  -v <increase-verbosity> Add more verbosity
  -w <sleep-time-us>      Iteration time for data publishing to the DDS world, in microseconds.
                           Defaults to 1us
     <ros-args>           (ROS2 only) Allows to pass arguments to the timesync ROS2 node.
                           Currently used for setting the usage of simulation time by the node using
                           '--ros-args -p use_sim_time:=true'

注:如果发现有so没有找到,请看下LD_LIBRARY_PATH是否正确。尝试使用“export LD_LIBRARY_PATH=/usr/local/lib/”解决问题。

4.2.4 构建Application (Offboard)

构建示例监听应用

$ cd build/px4_sitl_rtps/src/modules/micrortps_bridge
$ mkdir -p micrortps_listener
$ cd micrortps_listener
$ fastrtpsgen -example x64Linux2.6gcc ../micrortps_agent/idl/debug_vect.idl
$ make -f makefile_x64Linux2.6gcc

注:如果发现有so没有找到,请看下LD_LIBRARY_PATH是否正确。尝试使用“export LD_LIBRARY_PATH=/usr/local/lib/”解决问题。

4.2.5 测试验证(PX4 --> Offboard)

4.2.5.1 配置从PX4飞控板向Offboard发出uORB消息:
msg\tools\urtps_bridge_topics.yaml
39   - msg:     debug_vect
40     send:    true
build\px4_sitl_rtps\src\modules\micrortps_bridge\micrortps_listener\debug_vectSubscriber.cxx
59     Rparam.topic.topicName = "fmu/debug_vect/out";
4.2.5.2 重新编译Client和Agent

略,参考章节4.2.4和4.2.3.

4.2.5.3 验证结果

Px4_mavlink_debug

QGroundControlOffboard Subscriber

4.2.6 测试验证(Offboard --> PX4)

4.2.6.1 配置从Offboard向PX4飞控板发出uORB消息:
msg\tools\urtps_bridge_topics.yaml
39   - msg:     debug_vect
40     receive: true
build\px4_sitl_rtps\src\modules\micrortps_bridge\micrortps_listener\debug_vectPublisher.cxx
63     Wparam.topic.topicName = "fmu/debug_vect/in";
4.2.6.2 修改debug_vectPublisher.cxx文件

为了便于调试辨识,修改文件build\px4_sitl_rtps\src\modules\micrortps_bridge\micrortps_listener\debug_vectPublisher.cxx。新增三行代码,是的xyz值,跟随发送次数增加而增加。

111			st.x_( 7.0f * msgsent);
112			st.y_( 6.0f * msgsent);
113			st.z_( 5.0f * msgsent);
4.2.6.3 重新编译Client和Agent

略,参考章节4.2.4和4.2.3.

4.2.6.4 验证结果

这里通过一个Offboard–>PX4–>MAVLink–>QGroundControl来证明,消息已经从Offboard发送到PX4.
Offboard-->PX4

5.参考资料

【1】Fast-DDS-Installation
【2】PX4-Fast RTPS(DDS) Bridge
【3】Fast-DDS Github

6. 补充ROS安装无法获取key的问题

Fast DDS主要用于ROS通信,而ROS在Ubuntu 20.04通过repo方式进行安装方式,发现DNS无法查到这个raw.githubusercontent.com。真的不太清楚为什么国内的IP会这样,也许屏蔽太多国外的东西了,开放真的不是一天两天,要坚持啊!!!

raw.githubusercontent.com
不过我们做技术的还是有办法不是搞政治的,所以我们还是需要想办法解决问题:修改hosts Ubuntu,CentOS及macOS直接在终端输入

$ sudo vi /etc/hosts

添加以下内容保存即可,这里备注记录下,希望有缘人可以用到(技术无国界)。

# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值