ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
4

Extracting definition of customized messages from bag files

asked 2016-03-24 23:45:00 -0600

shihyuan gravatar image

TL;DR: How can write a node that subscribes to topics under customized messages that's published from a bag when I don't have access to the definition of the customized messages (the .msg files)?

I have a bag file containing topics in customized messages, for example dbw_mkz_msgs/SteeringReport. While I don't have access to the dbw_mkz_msgs or the definition of dbw_mkz_msgs/SteeringReport, I can use tools such as rqt_bag or rostopic echo -b to view them (their fields and values to be more specific). I can even use the rosbag python api to edit them and write to another bag.

However, what I cannot do is write a node that subscribes to one of these topics in dbw_mkz_msgs/SteeringReport since I cannot from dbw_mkz_msgs.msgs import SteeringReport. Is there a way to extract the definition of a customized message from a bag file?

edit retag flag offensive close merge delete

Comments

In python, have a look at the get_type_and_topic_info() function on the bag, http://wiki.ros.org/rosbag/Cookbook#G... and http://docs.ros.org/jade/api/rosbag/h...

ahendrix gravatar image ahendrix  ( 2016-03-25 00:15:50 -0600 )edit

Thanks for you response, @ahendrix. However, it seems like get_type_and_topic_info() will give me the type of the message (a string dbw_mkz_msg/SteeringReport), and its md5hash. It still doesn't give me the SteeringReport() class that I would get if I had access to the dbw_mkz_msgs package.

shihyuan gravatar image shihyuan  ( 2016-03-25 12:51:49 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-03-25 18:13:53 -0600

ahendrix gravatar image

So, the full message definitions are captured in the bag file, but there doesn't appear to be a direct API for extracting them.

This kind of does the trick:

#!/usr/bin/env python

import rosbag
import sys

types = {}

for bagname in sys.argv[1:]:
    bag = rosbag.Bag(bagname)
    for topic, msg, t in bag.read_messages():
        if not msg._type in types:
            types[msg._type] = msg._full_text


for t in types:
    print "Message type:", t
    print "Message text:"
    print types[t]
    print
edit flag offensive delete link more

Comments

Awesome! With the definition I can recreate a mock dbw_mkz_msgs pkg! Thanks a lot.

shihyuan gravatar image shihyuan  ( 2016-03-30 23:44:48 -0600 )edit

This should totally be in the ros_bag utility. Awesome!

vschmidt gravatar image vschmidt  ( 2021-09-21 14:34:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-03-24 23:45:00 -0600

Seen: 4,372 times

Last updated: Mar 25 '16