It is possible to use rosbag2
to record and replay traffic generated by a Fast DDS application.
In order to do so, the next steps need to be taken:
- Generate a message type using ROS 2 format (
.msg
) - Generate a ROS 2 compatible IDL from the ROS 2
.msg
using Fast DDS-gen - Name the topic following ROS 2 topic naming conventions.
This example constitutes a step-by-step guide on how to use rosbag2
to record and replay Fast DDS data.
It will modify Fast DDS' HelloWorld
example to publish a ROS 2 compatible type that will be recorded and replayed using rosbag2
.
It assumes that there is a functional ROS 2 Foxy installation containing rosbag2
, that is possible to build Fast DDS from sources, and that there is a functional Fast DDS-gen installation.
- Generate IDL from msg
- Generate ROS 2 compatible type support using Fast DDS-gen
- Patch example to include use the String type
- Record data from HelloWorld example
- Replay the recorded data
IMPORTANT: This demo has been tested using Fast DDS' commit fddbe1168ad980e39969a643f49638bbe10ea460.
Using a different commit may require modification on the patch applied to the HelloWorld
example.
For this example, the ROS 2 standard String.msg message has been used.
source <path_to_ros2_installation>/setup.bash
ros2 run rosidl_adapter msg2idl.py <path_to_msg>/String.msg
This will output a String.idl
file.
This file will then be used to generate the appropriate type support for the HelloWorld
example.
This step assumes that Fast DDS is built from sources.
cp String.idl <path_to_fastdds_repository>/examples/C++/DDS/HelloWorldExample/
cd <path_to_fastdds_repository>/examples/C++/DDS/HelloWorldExample/
fastddsgen String.idl -typeros2
This will generate the following type support files:
- String.cxx
- String.h
- StringPubSubTypes.cxx
- StringPubSubTypes.h
rosbag2.patch
modifies the example to use the ROS 2 compatible String
type.
It is important to note that the topic name has been modified to rt/HelloWorldTopic
following ROS 2 topic naming mangling conventions.
cd <path_to_fastdds_repository>
git apply rosbag2.patch
After this step, Fast DDS needs to be rebuilt with flags -DCOMPILE_EXAMPLES=ON -DINSTALL_EXAMPLES=ON
For this step, two terminals are needed:
Start a publisher that publishes 100 messages on the topic
<path_to_fastdds_installation>/examples/C++/DDS/HelloWorldExample/bin/DDSHelloWorldExample publisher 100
Start a recording of /HelloWorldTopic
topic
source <path_to_ros2_installation>/setup.bash
ros2 bag record /HelloWorldTopic -o rosbag_demo
Once the publisher has finished, stop the recording with CTRL-C.
This generates a rosbag_demo
directory that contains a sqlite3 database rosbag_demo_0.db3
with the data.
Finally, you can replay the rosbag2
data and subscribe to it using the HelloWorld
example.
Start a subscriber that will receive the date replayed by rosbag2
<path_to_fastdds_installation>/examples/C++/DDS/HelloWorldExample/bin/DDSHelloWorldExample subscriber
Once the rosbag2
replay is finished, you can stop the subscriber pressing enter.
Start a recording of /HelloWorldTopic
topic
source <path_to_ros2_installation>/setup.bash
ros2 bag play rosbag_demo/rosbag_demo_0.db3