0
$\begingroup$

Rosanswers logo

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()

Originally posted by EdoardoSerri on ROS Answers with karma: 3 on 2020-11-17

Post score: 0


Original comments

Comment by NEngelhard on 2020-11-17:
Wouldn't fmsg._has_header have the same value for every message in the bag file?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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()

Originally posted by miura with karma: 1908 on 2020-11-18

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.