Extract timestamp from bag for some topics without the time
Hi to all,
unfortunately, I recorded a very long bag file containing some topics that have a timestamp and two topics that do not include it since I forgot to add it before to launch the ROS node. Unfortunately, all the topics have different sampling time, so I cannot find a valid method to reference the value recorded in the topics without the timestamp against the timestamp from the other topics.
Is there a way to add the timestamp also in the topics that do not include it?
I was hoping that when you launch "rosbag record -a
" the utility somehow keeps trace of the time acquisition. :)
This is the topic list and the topics without the timestamp are loadcell and steering. Hope you can help me, thank you!
topics: /diagnostics 692 msgs : diagnostic_msgs/DiagnosticArray
/joy 18326 msgs : sensor_msgs/Joy
/robo_explorer/cmd_vel 18326 msgs : geometry_msgs/Twist
/robo_explorer/enc 4537 msgs : std_msgs/String
/robo_explorer/io_status 18326 msgs : robo_explorer/robo_io
/robo_explorer/loadcell 7049 msgs : std_msgs/String
/robo_explorer/steering 9887 msgs : std_msgs/String
/robo_explorer/sys 4538 msgs : std_msgs/String
/robo_explorer/velocity 4537 msgs : std_msgs/String
/rosout 56497 msgs : rosgraph_msgs/Log (4 connections)
/rosout_agg 56484 msgs : rosgraph_msgs/Log
This is the test.bag file as reference.
quick comment: I'm not sure exactly what you're asking, but
rosbag
does store the reception time with each message it records. It will be wildly inaccurate though (well .. depends on your requirements) compared to stamps stored inheader.stamp
. See #q199941 and #q318536 for earlier questions, and wiki/rosbag/Cookbook for a collection of example Pythonrosbag
processing scripts.no, not without changing your
.msg
definition and completely rewriting/processing the.bag
file.You can figure out reception time for all messages recorded, but you wouldn't then "add it" like you seem to be asking.
Thank you a lot for your support. I already tried that links before opening the topic since I wasn't able to retrieve the time in any way by using that examples. The loadcell topic is just a string with values separated by a comma. I uploaded the bag file in the main topic just for reference.
The first example in the Cookbook () basically does this:
The
t
there is the time the message was received/recorded.Just to clarify: you will not somehow get a "timestamp" as part of the messages that were recorded. Rosbag does not change what it records (actually, it doesn't even deserialise the msgs it receives, so it only records a binary blob). The only thing you can do is ask Rosbag to give you the time at which it recorded the message.
That is what the
t
is in the snippet above.pedantic, but that's of course never a good idea in a strongly typed system such as ROS.
I already tried that specific example but it only gives me the original topic as output without any timestamp.
I'm confused.
The only time information you would have access to in case of a message stream in a
.bag
where the.msg
themselves don't contain astd_msgs/Header
would be the time at which each individual message got recorded.That time is what you have access to in the
t
variable in the line:Notice the
t
in thetopic, msg, t
(unpacked)tuple
.That
t
is not part of your.msg
definition. It's what Rosbag itself records, in addition to the message contents.