ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Creating a rosbag from images and imu data using bag.write

asked 2021-09-20 13:10:49 -0500

quantum guy 123 gravatar image

I have seen some examples of how to make a rosbag from images (, but I don't know how to do this with imu data (or any other type of data). I don't want to use the rosbag record feature, I want to create the rosbag using data already on my computer and the bag.write method. Can someone please show me how to do this for imu data? I don't know what format the rosbag wants the imu data in. The documentation for rosbag is very limited.

I prefer using python, but if someone could show how to do it for both python and C++ that would be extra helpful.

Thank you so much in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-09-21 18:58:05 -0500

janindu gravatar image

All you need to do is to create a message instance with data, a topic name and a time stamp for bag, and write it to the bag.

Eg Python :

from sensor_msgs.msg import Imu
import rosbag as bag

# get your imu data here (I assume N data points)
# open rosbag to write here
for i in range(N):
    imuMsg = Imu()
    imuMsg.header.stamp = # your time
    imuMsg.orientation = # your data
    # fill your other data
    bag.write("/imu", msg, msg.header.stamp)


C++ example can be found here

edit flag offensive delete link more


Thanks. How do I know what format the rosbag wants the imu data in?

Also, can you see my other question here:

quantum guy 123 gravatar image quantum guy 123  ( 2021-09-23 17:05:08 -0500 )edit

is there any documentation for rospy that shows which fields are available to populate on the Imu() object?... And what format they are supposed to be in?...

quantum guy 123 gravatar image quantum guy 123  ( 2021-09-23 17:06:08 -0500 )edit

The imu data is inside a sensor_msgs.msg.Imuobject, which is imported on this script in the first line. The data structure definition can be found here :

janindu gravatar image janindu  ( 2021-09-23 18:36:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-09-20 13:07:31 -0500

Seen: 438 times

Last updated: Sep 21 '21