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

how to write TF broadcasts in a bag (with the rosbag API)

asked 2011-11-10 12:00:08 -0500

brice rebsamen gravatar image

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

ngrennan gravatar image

This is a follow up on some discussion going on here: Since the discussion has drifted away from the original topic I am posting a new question...

I am writing a simulation that simulates a moving vehicle and outputs ground truth position (as an Odometry message on topic "ground_truth" and as a TF: ground_truth -> base_link), and simulated sensor data with a controllable amount of noise. I want to use it to test my localization algorithms (EKF).

The simulator can run both in real time and in bag mode. In real time mode, it publishes the messages on topics, and everything is fine. In bag mode, it runs as fast as possible and writes the messages directly into a bag file, using the rosbag C++ API.

The only thing that is missing is how to write TF messages in the rosbag. I tried writing them to the bag on topic /tf but I got the following problems:

1) Writing tf/StamedTransform (same as what I broadcast in real time mode) I get the following error at compilation: ‘const class tf::StampedTransform’ has no member named ‘__getDataType’

2) Writing geometry_msgs::TransformStamped I convert using tf::transformStampedTFToMsg. No compilation errors. But in rviz, after setting the Fixed Frame to /ground_truth, I get the following warning: "no tf data. Fixed Frame [/ground_truth] does not exist." And the drop down menu to choose the fixed frame is empty.

So I do I proceed to store TF messages / transforms into the bag?

edit retag flag offensive close merge delete


I'd really much appreciate an answer. Come on, nobody knows the answer?
brice rebsamen gravatar image brice rebsamen  ( 2011-11-24 12:36:04 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2011-11-26 02:15:11 -0500

Miguel Riem de Oliveira gravatar image

Hi Brice

I think I found a way to do this.

You must write to the bag file a tf:tfmessage instead of a geometry_msgs::TransformStamped.

Here's a piece of code that works for me (although I need to restart rviz after recording the bag file, before playing it back, in order to visualize, perhaps a problem with the timestamps, don't know)

I assume there is a tf::Transform tr, as well as a rosbag::bag bag variables

//declare a geometry msg

geometry_msgs::TransformStamped msg;

//declare a std::vector of geometry msgs std::vector< geometry_msgs::TransformStamped > vec_msg;

//declare the tf:tfmessage, this is what is actually written to the bag file

tf::tfMessage tfmsg;

//convert the tf::transform (variable tr) to a geometry msg

tf::transformStampedTFToMsg(tf::StampedTransform(tr, ros::Ti me::now(), "/world","/tf_vehicle"),msg);

//erase all value from the std::vector


//push back into the vector the geometry msg


//Set the tf::tfmessage transforms vector


//set the size (don't know if its actually needed)


//write to the bag file

bag.write("/tf", ros::Time::now(),tfmsg);

Hope this helps


PS: If you find why rviz needs to be restarted please let me know.

edit flag offensive delete link more


Just an update. I tested just now and there is no need to restart rviz, just to reset it. Miguel
Miguel Riem de Oliveira gravatar image Miguel Riem de Oliveira  ( 2011-11-26 02:23:42 -0500 )edit

Question Tools


Asked: 2011-11-10 12:00:08 -0500

Seen: 3,694 times

Last updated: Nov 26 '11