ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
23

How to extract data from *.bag?

asked 2011-02-16 18:38:45 -0500

Changhyun Jun gravatar image

updated 2014-01-28 17:09:10 -0500

ngrennan gravatar image

How to extract data from *.bag?

I recorded my odomerty and laser data using rosbag. I want to extract (specific) data stream(text format) from recorded bagfiles. (time, step, odometry[x,y,...], laser data, ...) Becuase my unfinshied project are programed by matlab.

Question. 1) How to extract data from *.bag? (using matlab, C/C++ or ROS API...)

edit retag flag offensive close merge delete

Comments

when you see an answer you like, mark it as an accepted answer
mmwise gravatar image mmwise  ( 2011-02-17 09:32:40 -0500 )edit

Ok, is it possible to extract the contents of the bag file time, step, odometry[x,y..] and write our own customize code in cpp or java to move the robot through particular location of the map. Does we need to create the package with our customize code? How to combine all in built packages of ros and our own package?

RB gravatar image RB  ( 2013-10-27 19:40:10 -0500 )edit

The script worked well for me, but I didn't test for a bunch of different bags. I'd imagine it wouldn't work if the bag contains data of a type that is not just a simple number

mariakatosvich gravatar image mariakatosvich  ( 2016-09-09 01:49:54 -0500 )edit

@changhyun, did you find the relevant solution? I am also trying to retrieve the odom data in terms of each step , data and all. The below "highlighted" answer is not giving me the required output. Did you find the solution? Kindly help

Ayush Sharma gravatar image Ayush Sharma  ( 2017-03-12 08:18:09 -0500 )edit

13 Answers

Sort by ยป oldest newest most voted
0

answered 2019-12-20 06:00:13 -0500

convert a bag file to .csv format, use

$ rostopic echo /topicname -b bagFileName.bag -p > file.csv

Remember to replace topicname with your topic (/tactile). And bagFileName.bag need to be replace with your bag file that you need to convert. And finally file.csv will be your output file. Instead of having .csv you can try .txt also. But for the best practice .csv file is good.

edit flag offensive delete link more
0

answered 2014-11-13 21:42:00 -0500

aktaylor08 gravatar image

Here is a small python framework that extracts bag information from a bag file and puts it in a pandas dataframe in python. It also has two small scripts to dump it into a csv file or place graph information from a topic. https://github.com/aktaylor08/RosbagP...

edit flag offensive delete link more

Comments

Hi I have also used the standard way to extract bag data:

rostopic echo -b bag_name.bag -p/topic_desired > name_of_topic.csv

B I used the option:

rosbag record -a

Thus I have recorded about 200 topics of bag data not just one. And it would be very exhaustive type the 1st command above one by one to convert all the 200 topic's data to csv. It there a command or script that I run only once and convert all my topics to different csvs? For example something like this:

rostopic echo -b bag_name.bag -p/ALLTOPICS desired > Separated_topics_filenames.csv

And have:

planning.csv odometry.csv pose.csv etc

I have tried this:

$ rostopic echo -b all_topics_bag.bag -p / current_pose > current_pose.csv

Ok It works and created the csv, then I tried this to get all data

$ rostopic echo -b all_topics_bag.bag -p / current_pose > current_pose.csv ...
(more)
Vini71 gravatar image Vini71  ( 2021-09-22 14:07:49 -0500 )edit
-1

answered 2014-11-11 15:51:57 -0500

just type the following in the directory of bag file:

rostopic echo -b bagname.bag -p /topicname > filename.csv

the data will save into filename.csv then you can use it in matlab

edit flag offensive delete link more

Comments

This is already covered in the answer by @kwc

ahendrix gravatar image ahendrix  ( 2014-11-11 16:13:38 -0500 )edit

Question Tools

7 followers

Stats

Asked: 2011-02-16 18:38:45 -0500

Seen: 95,550 times

Last updated: Oct 11 '20