Ask Your Question

Grep rosbag for the time a particular message was published?

asked 2019-09-17 04:31:12 -0600

Rufus gravatar image

If I have a huge rosbag of which I only wish to examine the time at which a particular message was published to a particular topic, how would I do that?

Currently, I have to play through the entire rosbag and wait for that message to appear and note down the timestamp.

Is there a smarter way to get the timestamp directly from the bag?

edit retag flag offensive close merge delete



Whenever you're not actually interested in replaying .bag files to feed "old" information to a running ROS application, use the rosbag Python/C++ API.

gvdhoorn gravatar image gvdhoorn  ( 2019-09-17 04:49:17 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-09-20 01:22:12 -0600

Rufus gravatar image

Thx to gvdhoorn's comment, I managed to write the following simple script to do what I want


import yaml
import rosbag
import argparse
import re

parser = argparse.ArgumentParser(description="Greps /rosout for a specific message and reports its timestamps")
parser.add_argument("bagfile", nargs=1, help="input bag file")
parser.add_argument("regex", nargs=1, help="regex pattern to search for")
args = parser.parse_args()

bagfile = args.bagfile[0]
regex = args.regex[0]

info_dict = yaml.load(rosbag.Bag(bagfile, 'r')._get_yaml_info())

for topic, msg, t in rosbag.Bag(bagfile).read_messages():
    if topic == "rosout":
        if, msg.msg) or,
            seconds_from_start = t.to_sec() - info_dict["start"]
            print("[" + str(seconds_from_start) + "] " + msg.msg)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-09-17 04:31:12 -0600

Seen: 330 times

Last updated: Sep 20 '19