Ask Your Question
1

How to use rosbag methods from within a C++ node? [closed]

asked 2013-12-04 07:24:12 -0600

randylewis7 gravatar image

updated 2013-12-04 07:44:37 -0600

lindzey gravatar image

Hello, I'm trying to create a node that will take a starting bagfile with turtlesim velocity data (like for the drawing of a square or something), then publish that data to turtlesim (like the command line usage of 'rosbag play') and rerecord the played data over the original bagfile. I want to put that process inside a loop, and then play and record over and over and over again to see if the final product bagfile is significantly different than than the original one (I remember reading that rosbag play does not always play the file exactly the same way, so I'm trying to get these changes to add up over time).

However, the problem I'm having is that I have no idea how to run rosbag methods from within a node (I'm using C++). For a previous beginning project, I was using these tutorials: http://www.cse.sc.edu/~jokane/teaching/574/notes-ros.pdf (especially sections 4 through 9) to help me with the syntax to make a node that published velocity to turtlesim such that the turtle would draw a specific shape. However, now that I look at section 10 (bagfiles), I am stuck because it doesn't give me any information on how to use bagfiles from within a node--only in the command line.

Does anyone know how to do this? Is it even possible? Help would be much appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by randylewis7
close date 2014-07-02 11:22:18.979623

1 Answer

Sort by » oldest newest most voted
3

answered 2013-12-04 20:43:45 -0600

The relevant info on how to read and write from bagfiles in C++ is here: rosbag C++ Code API.

The example programs on that page are not ROS nodes, but normal C++ programs in the sense that they don't communicate in any way with a roscore, but instead simply read and write bag files. But there's nothing to prevent you from using that code in a ROS node and publish the messages you just read from the bag file.

Make sure you publish the /clock topic, and that you publish the messages at the right time. If you somehow wish to improve on rosbag, it's probably a good idea to read and understand the rosbag source code first.

edit flag offensive delete link more

Comments

Thanks a lot! Very helpful.

randylewis7 gravatar imagerandylewis7 ( 2013-12-05 17:21:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-04 07:24:12 -0600

Seen: 1,930 times

Last updated: Dec 04 '13