[Documentation] [TitleIndex] [WordIndex

See Also:

  1. ROS/Tutorials/reading msgs from a bag file - learn how to use the ros_readbagfile command-line tool. General format: ros_readbagfile <mybagfile.bag> [topic1] [topic2] [topic3] [...] [topic1000]

rosbag command-line tool:

The rosbag command-line tool provides functionality for ROS bags.

It can record a bag, republish the messages from one or more bags, summarize the contents of a bag, check a bag's message definitions, filter a bag's messages based on a Python expression, compress and decompress a bag and rebuild a bag's index.

This is the current list of supported rosbag subcommands:

IMPORTANT: This wiki page quickly goes out-of-date. To ensure you are fully aware of all command-line options available in your version of ROS, simply run rosbag -h to see what subcommands are available for the rosbag command, then run rosbag <subcommand> -h to see what options are available for a given subcommand. Ex: rosbag play -h will show you the most up-to-date list of all options available for your installation for the rosbag play subcommand.

These are described in greater detail in the following sections.

rosbag record

rosbag record subscribes to topics and writes a bag file with the contents of all messages published on those topics. The file contains interlaced, serialized ROS messages dumped directly to a single file as they come in over the wire. This is the most performance and disk-friendly recording format possible. To further reduce disk usage, you can compress bag files as they are created.

If you are recording messages at a high bandwidth, such as from cameras, it is strongly recommended you run rosbag record on the same machine as the camera, and specify the file destination as being on the local machine disk.

-tcpnodelay

--udp

rosbag info

rosbag info displays a human-readable summary of the contents of the bag files, including start and end times, topics with their types, message counts and median frequency, and compression statistics.

To output a machine-readable representation, use --yaml. See the cookbook for an example of how to load this representation in code.

Example usage:

$ rosbag info foo.bag
path:        foo.bag
version:     2.0
duration:    1.2s
start:       Jun 17 2010 14:24:58.83 (1276809898.83)
end:         Jun 17 2010 14:25:00.01 (1276809900.01)
size:        14.2 KB
messages:    119
compression: none [1/1 chunks]
types:       geometry_msgs/Point [4a842b65f413084dc2b10fb484ea7f17]
topics:      /points   119 msgs @ 100.0 Hz : geometry_msgs/Point

rosbag play

rosbag play reads the contents of one or more bag file, and plays them back in a time-synchronized fashion. Time synchronization occurs based on the global timestamps at which messages were received. Playing will begin immediately, and then future messages will be published according to the relative offset times. If two separate bag files are used, they are treated as a single bag with interlaced times according to the timestamps. This means if you record one bag, wait an hour, and record a second bag, when you play them back together you will have an hour-long dead period in the middle of your playback.

If you do not want to observe playback timing, the -i option will playback all messages from the file as fast as possible. Note that for large files this will often lead to exceeding your incoming buffers.

Additionally, during playing, you can pause at any time by pressing space. When paused, you can step through messages by pressing s.

rosbag check

See more instructions and usage examples on the rosbag migration page.

If a bag is currently unplayable and non-migratable, it may be necessary to generate rules to bring the bag up to date. See Migrating Messages for the preferred approaches to doing this.

rosbag fix

See more instructions and usage examples on the rosbag migration page.

rosbag filter

The Python expression can access any of the Python builtins plus:

Example output:

NO MATCH hello world 68
NO MATCH hello world 69
NO MATCH hello world 70
MATCH hello world 71
NO MATCH hello world 72
NO MATCH hello world 73

To filter based on time, convert the time to a floating point number (use UNIX time, to get this value, use rosbag info):

rosbag filter input.bag output.bag "t.to_sec() <= 1284703931.86"

rosbag compress

rosbag compress is a command-line tool for compressing bag files.

A backup of each bag file (with the extension .orig.bag) is made before the bag is compressed. If the backup file already exists (and the -f option isn't specified) then the tool will not compress the file.

Currently, there are two supported formats:BZ2 and LZ4. BZ2 is selected by default. Which should you prefer? BZ2 generally produces smaller bags than LZ4, so use it if disk usage is your primary concern. However, BZ2 is typically much slower than LZ4, both during compression and later when a bag's chunks are decompressed for reading, so use it if you're willing to tolerate slightly larger bags. Look here a more detailed discussion and some benchmarks.

The bag format supports interleaving compressed data chunks with uncompressed chunks in a single bag. Running rosbag compress on a bag with compressed data chunks will decompress and compress the bag using the specified compression format.

rosbag decompress

rosbag decompress is a command-line tool for decompressing bag files. It automatically determines which compression format a bag uses.

A backup of each bag file (with the extension .orig.bag) is made before the bag is decompressed. If the backup file already exists (and the -f option isn't specified) then the tool will not decompress the file.

rosbag reindex

rosbag reindex is a command-line tool for repairing broken bag files (or bag files recorded prior to ROS version 0.11.) If a bag was not closed cleanly for any reason, then the index information may be corrupted. Use this tool to reread the message data and rebuild the index.

A backup of each bag file (with the extension .orig.bag) is made before the bag is reindexed. If the backup file already exists (and the -f option isn't specified) then the tool will not reindex the file.


2022-05-28 12:57