使用 RTI Recording Service 与 DDS 回放 ROS2 LiDAR 数据
真实世界测试对分布式和自主系统不可或缺,却可能成本高昂。通过捕获和回放传感器数据,团队可从每次测试会话中产生持久价值。
想象一辆配备 GPS、摄像头、LiDAR、雷达、惯性传感器和全套控制信号的半自动驾驶车辆。单次运行产生的数据量惊人,重复道路试验成本高昂。记录这些数据以供后续回放——本质上创建测试会话数字库——将显著提高测试可重复性和灵活性。
多年来,DDS 用户通过 RTI Recording Service 获得高带宽录制和回放。它支持在长期部署(如海上舰艇试验)期间连续 24/7 捕获所有系统数据。得益于 DDS 分布式架构,可启动多个 Recording Service 实例以跟上海量数据流。
ROS2 依赖 DDS 进行进程间通信,可利用同一经过实战检验的 Recording Service 捕获高带宽 ROS2 主题如 LiDAR 点云。在以下示例中,我们将设置中等带宽主题(ROS2 LiDAR 数据)并仅使用 DDS 工具将其回放回 ROS2。
记录器配置
RTI Recording Service 由 XML 配置文件驱动,指定记录哪些主题、期望 QoS 设置和存储选项。此设置中,我们指示记录器将 ROS2 PointCloud2 数据视为单列,避免对该大数据类型进行昂贵的反序列化。
以下是我们使用的 XML 文件,命名为 ros2_record.xml:
<dds xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/5.3.1/rti_record.xsd">
<recorder name="simple_example">
<!-- Enable remote access to RTI Recorder. The Recorder creates one
DataReader and one DataWriter in the specified domain. -->
<remote_access>
<enabled>true</enabled>
<remote_access_domain>0</remote_access_domain>
</remote_access>
<!-- Base name for the set of files that will store recorded data -->
<recorder_database>
<database_name>ros2_replay_example.dat</database_name>
<overwrite>true</overwrite>
</recorder_database>
<!-- Record data from one domain -->
<domain name="domain0">
<domain_id>0</domain_id>
<!-- Turn off deserialization for ROS2 ‘PointCloud2’ data type (over 5k elements) -->
<deserialize_mode>RTIDDS_DESERIALIZEMODE_NEVER</deserialize_mode>
</domain>
<!-- Create a TopicGroup that only records rt/velodyne_points topics -->
<topic_group name="ros-rt">
<topics><topic_expr>rt/velodyne_points</topic_expr></topics>
<field_expr>*</field_expr>
</topic_group>
<!-- Create a RecordGroup -->
<record_group name="RecordAll">
<!-- Specify which domains to record from -->
<domain_ref><element>domain0</element></domain_ref>
<!-- Specify which TopicGroups to record -->
<topic_ref><element>ros-rt</element></topic_ref>
</record_group>
<!-- Add domain and typecode info to record ROS2 ‘PointCloud2’ type -->
<domain_type_config>
<domain_group>
<element>
<domain_filter>
<element>domain0</element>
</domain_filter>
<type_config>
<xml>
<file_group>
<element>
<file_name>
<element>PointCloud2.xml</element>
</file_name>
<type>
<element>
<register_top_level>false</register_top_level>
<type_name>sensor_msgs::msg::dds_::PointCloud2_</type_name>
<registered_type_name>
<element>sensor_msgs::msg::dds_::PointCloud2_</element>
</registered_type_name>
<topics><element>rt/velodyne_points</element></topics>
</element>
</type>
<max_sequence>2147483647</max_sequence>
</element>
</file_group>
<path>
<element>.</element>
</path>
</xml>
</type_config>
</element>
</domain_group>
</domain_type_config>
</recorder>
</dds>
从包含 ros2_record.xml 的目录运行以下命令启动 Recording Service:
rtirecord -cfgFile ros2_record.xml -cfgName simple_example
服务订阅 LiDAR 主题并持续记录,直到您停止。输出为名为 ros2_replay_example.dat_0_0 的 SQLite 数据库。后续记录会话在文件名追加数字后缀,确保每个文件保持在用户定义大小限制内。
回放器配置
数据记录后,我们可将其回放到 ROS2 环境。早期博客强调 ROS2 为无缝互操作需要一些 QoS 调整。在此示例中,我们抑制类型代码传输以匹配 ROS2 “Bouncy Bolson”(或任何使用 rmw_connext_cpp 的 ROS2 版本)的默认配置。
以下 XML 文件 ros2_replay.xml 驱动 RTI Replay Service:
<?xml version="1.0"?>
<dds xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/5.3.1/rti_replay.xsd">
<!-- Example configuration for RTI Replay Service 2.0, tailored for ROS2 rt/* topics (PointCloud2) -->
<replay_service name="simple_example">
<annotation>
<documentation>Replay service example</documentation>
</annotation>
<time_control>
<rate>1</rate> <!-- Optional rate multiplier -->
<start_mode>AUTO</start_mode>
<start_offset><sec>5</sec></start_offset>
</time_control>
<!-- Source Database, Required -->
<replay_database name="simple_config">
<filename>ros2_replay_example.dat_0_0</filename>
<readonly>false</readonly>
<!-- Participant configuration. Suppress sending typeCode info (for ROS2) -->
<participant>
<domain_id>0</domain_id>
<participant_qos>
<resource_limits>
<type_code_max_serialized_length>0</type_code_max_serialized_length>
<type_object_max_serialized_length>0</type_object_max_serialized_length>
</resource_limits>
</participant_qos>
</participant>
<!-- Get typeCode info for playback (PointCloud2 type) -->
<type_config>
<xml>
<file_group>
<element>
<file_name>
<element>PointCloud2.xml</element>
</file_name>
<type>
<element>
<register_top_level>false</register_top_level>
<type_name>sensor_msgs::msg::dds_::PointCloud2_</type_name>
<registered_type_name>
<element>sensor_msgs::msg::dds_::PointCloud2_</element>
</registered_type_name>
<topics><element>rt/velodyne_points</element></topics>
</element>
</type>
<max_sequence>2147483647</max_sequence>
</element>
</file_group>
<path><element>.</element></path>
</xml>
</type_config>
<session name="A_Session">
<!-- Default values for <time_control> * -->
<replay_topic name="All_Topic">
<input>
<topic_name>*</topic_name>
<type_name>*</type_name>
<record_group_name>*</record_group_name>
<domain_name>*</domain_name>
</input>
</replay_topic>
</session>
</replay_database>
</replay_service>
</dds>
回放记录数据到 ROS2,执行:
rtireplay -cfgFile ros2_replay.xml -cfgName simple_example
结果
记录一系列 ROS2 LiDAR 会话后,数据可按需回放。以下截图演示 ROS2 环境中的回放点云:

此方法消除测试期间对专用汽车模拟器或实体车辆的需求。通过调整回放 XML 中的 <time_control><rate> 设置,可加速回放——在几分钟内有效模拟高速场景。
深入了解 ROS2 与 DDS 集成,请参阅我们之前的 RTI 博客文章,如 互操作性现场指南》和《生态系统融合时》。
物联网技术
- OpenDDS 与 RTI Connext DDS:选择正确的数据分发服务解决方案
- MQTT 与 DDS:为物联网选择正确的 M2M 协议
- Connext DDS 在工业物联网中的 5 大关键洞见:可靠性、安全性与可扩展性
- ROS 2 与 DDS 互操作性:无缝集成实用指南
- ROS2 Bouncy Bolson 免费捆绑 RTI Connext DDS:提升连接与诊断
- 第四次工业革命:工业 4.0 如何重塑制造业
- 确保物联网数据合规
- 可靠性互联网中的数据驾驭:高效管理策略
- 普惠物联网:新一代卫星物联网带来全球可负担连接
- 重塑现代工业的五大新兴连接趋势
- 2024 年十大工业物联网平台权威指南
- 数据中心未来:趋势、技术与可持续性