ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
5

Transform a pose to another frame with tf2 in Python

asked 2015-12-10 07:10:08 -0500

fivef gravatar image

I have a pose stamped given in camera frame. Now I want to transform the pose to get its coordinates in the base_link frame.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
8

answered 2015-12-10 07:33:15 -0500

fivef gravatar image

Import the needed modules

import tf2_ros
import tf2_geometry_msgs

Initialize the tf buffer and listener somewhere in your init function

tf_buffer = tf2_ros.Buffer(rospy.Duration(1200.0)) #tf buffer length
tf_listener = tf2_ros.TransformListener(self.tf_buffer)

Do the actual transformation

transform = tf_buffer.lookup_transform(target_frame,
                                       pose_stamped_to_transform.header.frame_id, #source frame
                                       rospy.Time(0), #get the tf at first available time
                                       rospy.Duration(1.0)) #wait for 1 second

pose_transformed = tf2_geometry_msgs.do_transform_pose(pose_stamped, transform)
edit flag offensive delete link more

Comments

3

The lookup should better be wrapped inside a try-except block in case the transform is not found: http://wiki.ros.org/tf2/Tutorials/Wri...

bit-pirate gravatar imagebit-pirate ( 2016-03-22 03:03:46 -0500 )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

2 followers

Stats

Asked: 2015-12-10 07:10:08 -0500

Seen: 5,229 times

Last updated: Dec 10 '15