How to use tf_remap?

I have a rosbag in which the /tf theme is recorded.

I need to reassign all the tf frames in this package that are related to the frame named /world in order to refer to the new frame named /vision . I tried the following, but it unfortunately does not work:

 rosrun tf tf_remap _mappings:='[{old: /world, new: /vision}]' 

Did I miss something?

I also tried to do this from the startup file:

 <launch> <node pkg="tf" type="tf_remap" name="tf_remapper" output="screen"> <rosparam param="mappings"> - {old: "/world", new: "/vision"} </rosparam> </node> </launch> 

The same result ...

I found that people say that in addition to running tf_remap node, rosbag should be launched as follows:

 rosbag play x.bag /tf:=/tf_old 

Also did it ... still not working.

tf_frame still refers to /world , not to /vision .

Any help would be greatly appreciated!


Edit

This is to clarify what I'm trying to achieve:

I want to reassign all the frames written in the bag and refer to /world , and make them refer to /vision . There should be no /world frame in the packet re-output. Somewhere else in the code, I define a frame named /world and its relation to /vision .

+5
source share
1 answer

You can edit the contents of the bag file using the rosbag python / C ++ API. Here is a python example that will simply replace any instance of / world / vision in your recorded / tf msgs bag.

 import rosbag from copy import deepcopy import tf bagInName = '___.bag' bagIn = rosbag.Bag(bagInName) bagOutName = '___fixed.bag' bagOut = rosbag.Bag(bagOutName,'w') with bagOut as outbag: for topic, msg, t in bagIn.read_messages(): if topic == '/tf': new_msg = deepcopy(msg) for i,m in enumerate(msg.transforms): # go through each frame->frame tf within the msg.transforms if m.header.frame_id == "/world": m.header.frame_id = "/vision" new_msg.transforms[i] = m if m.child_frame_id == "/world": m.child_frame_id = "/vision" new_msg.transforms[i] = m outbag.write(topic, new_msg, t) else: outbag.write(topic, msg, t) bagIn.close() bagOut.close() 
-1
source

All Articles