Ask Your Question
0

Grep rosbag for the time a particular message was published?

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

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

Comments

1

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 imagegvdhoorn ( 2019-09-17 04:49:17 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

Rufus gravatar image

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

#!/usr/bin/python2

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 re.search(regex, msg.msg) or re.search(regex, msg.name):
            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

Stats

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

Seen: 211 times

Last updated: Sep 20