Ask Your Question
0

How to create a rosbag file with messages with an header

asked 2020-11-17 10:10:20 -0500

EdoardoSerri gravatar image

updated 2020-11-17 10:40:51 -0500

Hi,

As I wrote on the title I'm trying to create a rosbag file from another one changing message types and using only some topics from the original one. The problem is, when I play the new rosbag the messages type is Float32, thus headerless.

Does someone know how can I write messages with an header (Float32Stamped or what else) in the new rosbag, without any error? I read that the last parameter of the write function is connection_header, but I didn't find anything that explain something about it. In the following, the code.

Thank you for the help

#!/usr/bin/env python3
import rosbag
from marti_common_msgs.msg import Float32Stamped


with rosbag.Bag('try.bag', 'w') as outbag:
    for topic, msg, t in rosbag.Bag('20180810150607_bus_signals.bag').read_messages():
        if '/value' in topic:
            fmsg = Float32Stamped()
            fmsg.header = t
            fmsg.value = msg
            outbag.write(topic,fmsg.value, fmsg.header if fmsg._has_header else t)
        else:
            continue    
outbag.close()
edit retag flag offensive close merge delete

Comments

Wouldn't fmsg._has_header have the same value for every message in the bag file?

NEngelhard gravatar image NEngelhard  ( 2020-11-17 12:36:25 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-11-18 09:56:15 -0500

updated 2020-11-18 23:46:34 -0500

lindzey gravatar image

header is not timestamp. header contains seq, timesamp, and frame_id.

#!/usr/bin/env python3
import rosbag
from marti_common_msgs.msg import Float32Stamped

with rosbag.Bag('try.bag', 'w') as outbag:
    for topic, msg, t in rosbag.Bag('20180810150607_bus_signals.bag').read_messages():
        if '/value' in topic:
            fmsg = Float32Stamped()
            fmsg.header.stamp = t  # <== This line changed to use fmsg.header.stamp
            fmsg.value = msg
            outbag.write(topic, fmsg, t)
        else:
            continue    
outbag.close()
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

2 followers

Stats

Asked: 2020-11-17 10:10:20 -0500

Seen: 162 times

Last updated: Nov 18 '20