Ask Your Question
1

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

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

brice rebsamen gravatar image

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

ngrennan gravatar image

This is a follow up on some discussion going on here: http://answers.ros.org/question/2826/simulating-sensor-data-problem-with-rosbag-and 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

Comments

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

1 Answer

Sort by » oldest newest most voted
0

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

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

vec_msg.erase(vec_msg.begin(),vec_msg.end());

//push back into the vector the geometry msg

vec_msg.push_back(msg);

//Set the tf::tfmessage transforms vector

tfmsg.set_transforms_vec(vec_msg);

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

tfmsg.set_transforms_size(1);

//write to the bag file

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

Hope this helps

Miguel

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

edit flag offensive delete link more

Comments

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 imageMiguel Riem de Oliveira ( 2011-11-26 02:23:42 -0600 )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

Stats

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

Seen: 2,599 times

Last updated: Nov 26 '11