• Stars
    star
    272
  • Rank 151,235 (Top 3 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

rosbag2

License GitHub Action Status

Repository for implementing rosbag2 as described in its corresponding design article.

Installation instructions

Debian packages

rosbag2 packages are available via debian packages and thus can be installed via

$ export CHOOSE_ROS_DISTRO=crystal # rosbag2 is available starting from crystal
$ sudo apt-get install ros-$CHOOSE_ROS_DISTRO-ros2bag ros-$CHOOSE_ROS_DISTRO-rosbag2*

Note that the above command installs all packages related to rosbag2. This also includes the plugin for reading ROS1 bag files, which brings a hard dependency on the ros1_bridge with it and therefore ROS1 packages. If you want to install only the ROS2 related packages for rosbag, please use the following command:

$ export CHOOSE_ROS_DISTRO=crystal # rosbag2 is available starting from crystal
$ sudo apt-get install ros-$CHOOSE_ROS_DISTRO-ros2bag ros-$CHOOSE_ROS_DISTRO-rosbag2-transport

Build from source

It is recommended to create a new overlay workspace on top of your current ROS 2 installation.

$ mkdir -p ~/rosbag_ws/src
$ cd ~/rosbag_ws/src

Clone this repository into the source folder:

$ git clone https://github.com/ros2/rosbag2.git

[Note]: if you are only building rosbag2 on top of a Debian Installation of ROS2, please git clone the branch following your current ROS2 distribution.

Then build all the packages with this command:

$ colcon build [--merge-install]

The --merge-install flag is optional and installs all packages into one folder rather than isolated folders for each package.

Executing tests

The tests can be run using the following commands:

$ colcon test [--merge-install]
$ colcon test-result --verbose

The first command executes the test and the second command displays the errors (if any).

Using rosbag2

rosbag2 is part of the ROS 2 command line interfaces. This repo introduces a new verb called bag and thus serves as the entry point of using rosbag2. As of the time of writing, there are three commands available for ros2 bag:

  • record
  • play
  • info

Recording data

In order to record all topics currently available in the system:

$ ros2 bag record -a

The command above will record all available topics and discovers new topics as they appear while recording. This auto-discovery of new topics can be disabled by given the command line argument --no-discovery.

To record a set of predefined topics, one can specify them on the command line explicitly.

$ ros2 bag record <topic1> <topic2> … <topicN>

The specified topics don't necessarily have to be present at start time. The discovery function will automatically recognize if one of the specified topics appeared. In the same fashion, this auto discovery can be disabled with --no-discovery.

If not further specified, ros2 bag record will create a new folder named to the current time stamp and stores all data within this folder. A user defined name can be given with -o, --output.

Simulation time

In ROS 2, "simulation time" refers to publishing a clock value on the /clock topic, instead of using the system clock to tell time. By passing --use-sim-time argument to ros2 bag record, we turn on this option for the recording node. Messages written to the bag will use the latest received value of /clock for the timestamp of the recorded message.

Note: Until the first /clock message is received, the recorder will not write any messages. Before that message is received, the time is 0, which leads to a significant time jump once simulation time begins, making the bag essentially unplayable if messages are written first with time 0 and then time N from /clock.

Splitting recorded bag files

rosbag2 offers the capability to split bag files when they reach a maximum size or after a specified duration. By default rosbag2 will record all data into a single bag file, but this can be changed using the CLI options.

Splitting by size: ros2 bag record -a -b 100000 will split the bag files when they become greater than 100 kilobytes. Note: the batch size's units are in bytes and must be greater than 86016. This option defaults to 0, which means data is written to a single file.

Splitting by time: ros2 bag record -a -d 9000 will split the bag files after a duration of 9000 seconds. This option defaults to 0, which means data is written to a single file.

If both splitting by size and duration are enabled, the bag will split at whichever threshold is reached first.

Recording with compression

By default rosbag2 does not record with compression enabled. However, compression can be specified using the following CLI options.

For example, ros2 bag record -a --compression-mode file --compression-format zstd will record all topics and compress each file using the zstd compressor.

Currently, the only compression-format available is zstd. Both the mode and format options default to none. To use a compression format, a compression mode must be specified, where the currently supported modes are compress by file or compress by message.

It is recommended to use this feature with the splitting options.

Recording with a storage configuration

Storage configuration can be specified in a YAML file passed through the --storage-config-file option. This can be used to optimize performance for specific use cases.

See storage plugin documentation for more detail:

Replaying data

After recording data, the next logical step is to replay this data:

$ ros2 bag play <bag_file>

The bag file is by default set to the folder name where the data was previously recorded in.

Analyzing data

The recorded data can be analyzed by displaying some meta information about it:

$ ros2 bag info <bag_file>

You should see something along these lines:

Files:             demo_strings.db3
Bag size:          44.5 KiB
Storage id:        sqlite3
Duration:          8.501s
Start:             Nov 28 2018 18:02:18.600 (1543456938.600)
End                Nov 28 2018 18:02:27.102 (1543456947.102)
Messages:          27
Topic information: Topic: /chatter | Type: std_msgs/String | Count: 9 | Serialization Format: cdr
                   Topic: /my_chatter | Type: std_msgs/String | Count: 18 | Serialization Format: cdr

Converting bags

Rosbag2 provides a tool ros2 bag convert (or, rosbag2_transport::bag_rewrite in the C++ API). This allows the user to take one or more input bags, and write them out to one or more output bags with new settings. This flexible feature enables the following features:

  • Merge (multiple input bags, one output bag)
  • Split top-level bags (one input bag, multiple output bags)
  • Split internal files (by time or size - one input bag with fewer internal files, one output bag with more, smaller, internal files)
  • Compress/Decompress (output bag(s) with different compression settings than the input(s))
  • Serialization format conversion
  • ... and more!

Here is an example command:

ros2 bag convert --input /path/to/bag1 --input /path/to/bag2 storage_id --output-options output_options.yaml

The --input argument may be specified any number of times, and takes 1 or 2 values. The first value is the URI of the input bag. If a second value is supplied, it specifies the storage implementation of the bag. If no storage implementation is specified, rosbag2 will try to determine it automatically from the bag.

The --output-options argument must point to the URI of a YAML file specifying the full recording configuration for each bag to output (StorageOptions + RecordOptions). This file must contain a top-level key output_bags, which contains a list of these objects.

The only required value in the output bags is uri and storage_id. All other values are options (however, if no topic selection is specified, this output bag will be empty!).

This example notes all fields that can have an effect, with a comment on the required ones.

output_bags:
- uri: /output/bag1  # required
  storage_id: ""  # will use the default storage plugin, if unspecified
  max_bagfile_size: 0
  max_bagfile_duration: 0
  storage_preset_profile: ""
  storage_config_uri: ""
  all: false
  topics: []
  rmw_serialization_format: ""  # defaults to using the format of the input topic
  regex: ""
  exclude: ""
  compression_mode: ""
  compression_format: ""
  compression_queue_size: 1
  compression_threads: 0
  include_hidden_topics: false
  include_unpublished_topics: false

Example merge:

$ ros2 bag convert -i bag1 -i bag2 -o out.yaml

# out.yaml
output_bags:
- uri: merged_bag
  all: true

Example split:

$ ros2 bag convert -i bag1 -o out.yaml

# out.yaml
output_bags:
- uri: split1
  topics: [/topic1, /topic2]
- uri: split2
  topics: [/topic3]

Example compress:

$ ros2 bag convert -i bag1 -o out.yaml

# out.yaml
output_bags:
- uri: compressed
  all: true
  compression_mode: file
  compression_format: zstd

Overriding QoS Profiles

When starting a recording or playback workflow, you can pass a YAML file that contains QoS profile settings for a specific topic. The YAML schema for the profile overrides is a dictionary of topic names with key/value pairs for each QoS policy. Below is an example profile set to the default ROS2 QoS settings.

/topic_name:
  history: keep_last
  depth: 10
  reliability: reliable
  durability: volatile
  deadline:
    # unspecified/infinity
    sec: 0
    nsec: 0
  lifespan:
    # unspecified/infinity
    sec: 0
    nsec: 0
  liveliness: system_default
  liveliness_lease_duration:
    # unspecified/infinity
    sec: 0
    nsec: 0
  avoid_ros_namespace_conventions: false

You can then use the override by specifying the --qos-profile-overrides-path argument in the CLI:

# Record
ros2 bag record --qos-profile-overrides-path override.yaml -a -o my_bag
# Playback
ros2 bag play --qos-profile-overrides-path override.yaml my_bag

See the official QoS override tutorial and "About QoS Settings" for more detail.

Using in launch

We can invoke the command line tool from a ROS launch script as an executable (not a node action). For example, to launch the command to record all topics you can use the following launch script:

<launch>
  <executable cmd="ros2 bag record -a" output="screen" />
</launch>

Here's the equivalent Python launch script:

import launch


def generate_launch_description():
    return launch.LaunchDescription([
        launch.actions.ExecuteProcess(
            cmd=['ros2', 'bag', 'record', '-a'],
            output='screen'
        )
    ])

Use the ros2 launch command line tool to launch either of the above launch scripts. For example, if we named the above XML launch script, record_all.launch.xml:

$ ros2 launch record_all.launch.xml

Storage format plugin architecture

Looking at the output of the ros2 bag info command, we can see a field Storage id:. Rosbag2 was designed to support multiple storage formats to adapt to individual use cases. This repository provides two storage plugins, mcap and sqlite3. The default is mcap, which is provided to code by rosbag2_storage::get_default_storage_id() and defined in default_storage_id.cpp

If not specified otherwise, rosbag2 will write data using the default plugin.

In order to use a specified (non-default) storage format plugin, rosbag2 has a command line argument --storage:

$ ros2 bag record --storage <storage_id>

Bag reading commands can detect the storage plugin automatically, but if for any reason you want to force a specific plugin to read a bag, you can use the --storage option on any ros2 bag verb.

To write your own Rosbag2 storage implementation, refer to this document describing that process

Serialization format plugin architecture

Looking further at the output of ros2 bag info, we can see another field attached to each topic called Serialization Format. By design, ROS 2 is middleware agnostic and thus can leverage multiple communication frameworks. The default middleware for ROS 2 is DDS which has cdr as its default binary serialization format. However, other middleware implementation might have different formats. If not specified, ros2 bag record -a will record all data in the middleware specific format. This however also means that such a bag file can't easily be replayed with another middleware format.

rosbag2 implements a serialization format plugin architecture which allows the user the specify a certain serialization format. When specified, rosbag2 looks for a suitable converter to transform the native middleware protocol to the target format. This also allows to record data in a native format to optimize for speed, but to convert or transform the recorded data into a middleware agnostic serialization format.

By default, rosbag2 can convert from and to CDR as it's the default serialization format for ROS 2.

More Repositories

1

ros2

The Robot Operating System, is a meta operating system for robots.
3,426
star
2

examples

Example packages for ROS 2
C++
683
star
3

ros2_documentation

ROS 2 docs repository
Python
541
star
4

rclcpp

rclcpp (ROS Client Library for C++)
C++
536
star
5

demos

C++
491
star
6

ros1_bridge

ROS 2 package that provides bidirectional communication between ROS 1 and ROS 2
C++
435
star
7

rclpy

rclpy (ROS Client Library for Python)
Python
288
star
8

rviz

ROS 3D Robot Visualizer
C++
287
star
9

design

Design documentation for ROS 2.0 effort
JavaScript
224
star
10

common_interfaces

A set of packages which contain common interface files (.msg and .srv).
C++
220
star
11

ros2cli

ROS 2 command line interface tools
Python
173
star
12

rmw_zenoh

RMW for ROS 2 using Zenoh as the middleware
C++
171
star
13

rmw_fastrtps

Implementation of the ROS Middleware (rmw) Interface using eProsima's Fast RTPS.
C++
155
star
14

rmw_iceoryx

rmw implementation for iceoryx
C++
153
star
15

ros2_tracing

Tracing tools for ROS 2.
Python
137
star
16

rcl

Library to support implementation of language specific ROS Client Libraries.
C++
128
star
17

launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Python
123
star
18

geometry2

A set of ROS packages for keeping track of coordinate transforms.
C++
120
star
19

rclc

ROS Client Library for the C language.
C
113
star
20

rmw_cyclonedds

ROS 2 RMW layer for Eclipse Cyclone DDS
C++
112
star
21

turtlebot2_demo

C++
95
star
22

rmw

The ROS Middleware (rmw) Interface.
C
95
star
23

sros2

tools to generate and distribute keys for SROS 2
Python
89
star
24

freertps

a free, portable, minimalist, work-in-progress RTPS implementation
C
89
star
25

rosidl

Packages which provide the ROS IDL (.msg) definition and code generation.
C++
74
star
26

ros2_embedded_nuttx

This repository isn't actively being worked on. If you would like to take over maintainership please open a ticket on https://github.com/ros2/ros2
C
72
star
27

message_filters

C++
70
star
28

realtime_support

Minimal real-time testing utility for measuring jitter and latency.
C++
61
star
29

rcutils

Common C functions and data structures used in ROS 2
C
56
star
30

launch_ros

Tools for launching ROS nodes and for writing tests involving ROS nodes.
Python
55
star
31

domain_bridge

Bridge communication across different ROS 2 domains.
C++
52
star
32

ci

ROS 2 CI Infrastructure
Python
48
star
33

rmw_connextdds

ROS 2 RMW layer for RTI Connext DDS Professional and RTI Connext DDS Micro.
C++
47
star
34

example_interfaces

Msg, Srv, etc. ROS interfaces used in examples
CMake
47
star
35

system_tests

C++
38
star
36

rcl_interfaces

A repository for messages and services used by the ROS client libraries
C++
38
star
37

rcpputils

C++
31
star
38

tutorials

C++
30
star
39

ros2_embedded_freertos

This repository isn't actively being worked on. If you would like to take over maintainership please open a ticket on https://github.com/ros2/ros2 -- ROS 2 for embedded devices.
C
29
star
40

rmw_connext

Implementation of the ROS Middleware (rmw) Interface using RTI's Connext DDS.
C++
26
star
41

choco-packages

Chocolatey package configurations for upstream dependencies
PowerShell
25
star
42

rosbag2_bag_v2

rosbag2 plugin for replaying ros1 version2 bag files
C++
24
star
43

rmw_dps

Implementation of the ROS Middleware (rmw) Interface using Intel's Distributed Publish & Subscribe.
C++
23
star
44

buildfarm_perf_tests

Performance tests which run regularly on the buildfarm
C++
23
star
45

rmw_implementation

CMake infrastructure and dependencies for rmw implementations
C++
21
star
46

openrobotics_darknet_ros

ROS 2 interface to darknet, an open source neural network library.
C++
20
star
47

rosidl_python

rosidl support for Python
EmberScript
19
star
48

ros_core_documentation

Documentation for the Core ROS 2 packages which does not fit into one of the individual packages' documentation.
Python
17
star
49

ros_network_viz

Python
17
star
50

rcl_logging

Logging implementations for ROS 2.
C++
16
star
51

rmw_gurumdds

Implementation of the ROS middleware interface using GurumNetworks GurumDDS.
C++
13
star
52

ros_testing

Single point of entry for writing tests which involve Nodes in ROS 2.
Python
13
star
53

rosidl_typesupport

Packages which provide the typesupport for ROS messages and services
C++
13
star
54

eigen3_cmake_module

Adds a custom find module for Eigen3
CMake
12
star
55

rmw_dds_common

C++
11
star
56

rmw_opensplice

Implementation of the ROS Middleware (rmw) interface using PrismTech's OpenSplice DDS.
C++
11
star
57

variants

Variants for ROS 2 (implemented as ament packages)
CMake
9
star
58

cookbook

A set of recipes for doing common tasks in ROS 2
C++
9
star
59

ros_workspace

Package to set ROS environment and configuration variables for ROS 2.
CMake
7
star
60

performance_test_fixture

Test fixture and CMake macro for using osrf_testing_tools_cpp with Google Benchmark
C++
7
star
61

tsc_working_group_governance_template

7
star
62

unique_identifier_msgs

CMake
6
star
63

rosidl_dds

Python
6
star
64

tlsf

Snapshot of TLSF allocator
C
6
star
65

detection_visualizer

ROS 2 package with a node that draws bound boxes for debugging computer vision nodes.
Python
6
star
66

rosidl_runtime_py

Runtime utilities for working with generated ROS interfaces in Python
Python
5
star
67

ros2_dds_profiles_examples

Example dds profiles to configure DDS correctly for different use cases
Python
5
star
68

rosidl_typesupport_gurumdds

Typesupport package which generates interfaces used by rmw_gurumdds.
EmberScript
4
star
69

python_cmake_module

CMake module for finding Python in a consistent way for all ROS 2 packages.
CMake
4
star
70

ament_cmake_ros

Python
4
star
71

darknet_vendor

CMake wrapper around darknet, an open source neural network framework.
CMake
4
star
72

ros2_generate_interface_docs

Python
4
star
73

middleware_working_group

Working group focused on functionality provided by the communication middleware and the language specific client libraries.
4
star
74

test_interface_files

CMake
3
star
75

rosidl_typesupport_opensplice

rosidl typesupport for PrismTech's OpenSplice DDS.
EmberScript
3
star
76

pybind11_vendor

Vendor package for pybind11.
CMake
3
star
77

tinyxml_vendor

Vendor package for providing tinyxml within a cmake package
CMake
2
star
78

rosidl_typesupport_fastrtps

rosidl typesupport for eProsima's FastRTPS
EmberScript
2
star
79

spdlog_vendor

Vendor package for spdlog
CMake
2
star
80

rosidl_dynamic_typesupport

Unified Interface for Dynamic (Runtime) Typesupport and Serialization
C
2
star
81

tinyxml2_vendor

temporary vendor package for tinyxml2
CMake
2
star
82

libyaml_vendor

CMake wrapper downloading and building libyaml
C++
2
star
83

orocos_kdl_vendor

CMake
2
star
84

unique_identifier

ROS 2 support for Universally Unique Identifiers
C++
1
star
85

rmw_freertps

rmw implementation using freertps
C++
1
star
86

netperf

C++
1
star
87

ros2.github.io

website for ros2.org
HTML
1
star
88

mimick_vendor

CMake
1
star
89

yaml_cpp_vendor

Vendor package for providing yaml cpp within a cmake package
CMake
1
star
90

ros2doc

i can haz docs?
Python
1
star
91

ros2cli_common_extensions

CMake
1
star
92

poco_vendor

CMake shim over the poco library: https://github.com/pocoproject/poco
CMake
1
star
93

rosidl_typesupport_connext

rosidl typesupport for RTI's Connext DDS.
EmberScript
1
star
94

docs.ros2.org

HTML
1
star