# Transform timestamped messages recorded in a bag file using tf messages

Note: this question was also asked in the ROS official Q&A website, but even after one week nobody has given me an answer.

I have a .bag which contains recorded messages on topics /topic1 and /topic2. The messages have /world as frame_id, so both of the messages associated with these topics are stamped, i.e. they have a header.

The same .bag file also contains recorded messages on the topic /tf (of type tf2_msgs/TFMessage). These transform messages have the frame_id set to /world and the child_frame_id set to the local frames associated with the IMUs from which the messages are being sent over respectively topic /topic1 and /topic2.

Now, I need the messages sent over the /topic1 and /topic2 to be converted to their corresponding local frame (i.e. the child frame or child_frame_id) from the (fixed) frame /world. Since both the /tf messages and the messages of the topics /topic1 and /topic2 are stamped, I thought we could do this without much trouble, but I'm not sure since I'm very new to ROS.

I've looked around for various solutions, but I didn't find an exact solution for my problem, maybe because I didn't recognize it as such, given my limited knowledge of ROS, as I said.

I would appreciate a step by step description of the approach and, if you don't want to write a full solution with code (preferably in Python), at least point me to the similar examples. Please, do not suggest me to read the tutorials of /tf, I've partially done it, and it didn't help much.

• It may be easier to answer your question if you edited it to provide details of what you actually want to achieve (why you want those topics converted to the local frame), what you tried, what you saw & what you expected to see. – Mark Booth May 18 '17 at 15:52
• This question is pretty old but, in case the OP comes back, we would need to know the message types being published on /topic1 and /topic2 to help with transforms. Knowing that messages are being published in the "/world" frame and wanting to transform them to a different frame doesn't help if we don't know /what/ we're transforming. – Joshua Whitley Aug 30 '17 at 4:35
• @JoshuaWhitley I think you can at least give a general idea of the process, even though you don't know exactly how the messages look like. You can, for example, give more than one example of doing it by inventing structures of the messages (just for the purposes of showing how you would do it!). – nbro Aug 30 '17 at 10:45

As far I understand, you have a topic /topic and an associated transformation on the tf topic. You then want to move the pose according to the tf transformation.
If you want to transform /topic to its actual pose in tf, you'll need first to read the transformation from the tf topic from frame_id to child_frame_id. Then apply this transformation to the pose in topic at the same time. An efficient way to get messages at the same time is to use message filter. I'm sure you'll find plenty of example to do just that, for example here.