赞
踩
@[TOC](PX4模块设计之六:PX4-Fast RTPS(DDS)简介)
基于PX4开源软件框架简明简介的框架设计,逐步分析内部模块功能设计。
PX4-Fast RTPS(DDS)具有实时发布/订阅uORB消息接口,用于AutoPilot内部组件或者offboard实时应用。其针对的主要应用是计算机视觉和传感器应用实时控制。Fast DDS的应用目标并非是替换MAVLink,目前,MAVLink仍然是地面站、平衡架、摄像头、offboard应用的主要通信接口;但是Fast DDS主要应用在搞通信带宽,高频率数据更新的场景。
DDS全称是Data Distribution Service,这是一套通信协议和API标准,它提供了以数据为中心的连接服务,基于发布者-订阅者模型。Fast-RTPS(DDS)是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)具有以下优点:
注1:Publisher-Subscriber层:RTPS上的简化抽象。
注2:Writer-Reader层:对于RTPS端点的直接控制。
microRTPS桥接器在PX4和DDS参与应用程序之间交换消息,在每个系统使用的uORB和RTPS/DDS消息之间无缝转换。
架构主要通过其客户端和代理组成。
microRTPS客户端是在飞行控制器上运行的PX4自动驾驶仪中间件守护进程。该客户端订阅由其他PX4自动驾驶仪组件发布的uORB主题,并向代理发送任何更新(通过UART或UDP端口),还从代理接收消息,并将其作为uORB消息发布到PX4自动驾驶仪。
microRTPS代理作为后台进程在伴飞计算机(飞行控制器外部)上运行。该代理监视来自客户端的uORB更新消息,并(重新)通过RTP发布这些消息,还订阅来自其他DDS参与者应用程序的“uORB”RTP/DDS消息,并将其转发给客户端。
代理和客户端通过串行链路(UART)或UDP网络连接,uORB信息通过CDR序列化机制,提供了在不同平台之间交换串行数据的通用格式。在典型配置中,它们将位于连接到客户端的同一系统(例如,开发计算机、Linux配套计算机或计算板)上,硬件上可以通过Wifi链接或USB进行。
eProsima Fast DDS是对象管理组(OMG)数据分发服务(DDS)规范和实时发布订阅(RTPS)协议的C++实现。
Fast DDS支持RTPS/DDS接口,允许PX4 uORB主题与参与同一DDS域的非车载组件共享,包括机器人和模拟器工具。特别是,快速DDS是机器人操作系统2(ROS 2)的默认中间件。
$ 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
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.
注:推荐采用二进制安装,一般发布的二进制版本都会进行比较完善的测试。除非您对这个源代码非常熟悉,那么可以忽略我们的担忧。
鉴于我们采用ubuntu20.04,以及官网最新二进制发布件为2.7.0,满足前提条件>=2.0.2要求。
使用下面命令进行安装
注:建议使用迅雷,速度快点,且文件名比较标准,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.
有windows/linux等版本可供下载,这个安装使用相对简单,请自行研究(详见eprosima官网)。
直接从源代码下载,但是安装命令做了调整(可能是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
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) 代码将允许通过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.
编译命令
$ 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
编译命令
$ 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/”解决问题。
构建示例监听应用
$ 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/”解决问题。
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.4和4.2.3.
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";
为了便于调试辨识,修改文件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.4和4.2.3.
这里通过一个Offboard–>PX4–>MAVLink–>QGroundControl来证明,消息已经从Offboard发送到PX4.
【1】Fast-DDS-Installation
【2】PX4-Fast RTPS(DDS) Bridge
【3】Fast-DDS Github
Fast DDS主要用于ROS通信,而ROS在Ubuntu 20.04通过repo方式进行安装方式,发现DNS无法查到这个raw.githubusercontent.com。真的不太清楚为什么国内的IP会这样,也许屏蔽太多国外的东西了,开放真的不是一天两天,要坚持啊!!!
不过我们做技术的还是有办法不是搞政治的,所以我们还是需要想办法解决问题:修改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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。