ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

How to add message field in a rosbag

asked 2018-11-15 10:03:59 -0500

thepirate16 gravatar image

updated 2018-11-15 10:05:59 -0500

I got a rosbag with a number of topics being played. I am interested in adding a Header (more specifically, a frame_id) to the message received so some 3d points in it are automatically displayed in RViz in the correct frame defined.

Is this possible? I know you can iterate a rosbag with the type of loop:

for topic, msg, t in inbag.read_messages():

        if topic == "/desired_topic":

            outbag.write(topic,msg.h,t)

        if topic not in ["/desired_topic"]:
            outbag.write(topic,msg,t)

    outbag.close()

But I don't know how to add a field to the incoming message and save it in a new bag.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-11-15 10:15:16 -0500

The rosbag_storage package described here allows you to access and modify the contents of a bag file without playing it back as you would normally have to. Using this you can look through all of the messages in a bag file and write messages into a bag file too.

However you cannot add a field into a message, the structure of messages is fixed and they can only contain the fields they are defined with. Some message types however include a normal type and 'Stamped' type which is the same message with an additional Header.

For example if your bag file contains geometry_msgs/pose messages then you could read these and create geometry_msgs/PoseStamped with the additional frame_id information in the header and write them back to the file. Only some messages have a stamped version though.

Hope this helps.

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

3 followers

Stats

Asked: 2018-11-15 10:03:59 -0500

Seen: 515 times

Last updated: Nov 15 '18