Transform a pose to another frame with tf2 in Python
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.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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.
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(100.0)) # tf buffer length
tf_listener = tf2_ros.TransformListener(self.tf_buffer)
Do the actual transformation:
transform = tf_buffer.lookup_transform(target_frame,
# source frame:
pose_stamped.header.frame_id,
# get the tf at the time the pose was valid
pose_stamped.header.stamp,
# wait for at most 1 second for transform, otherwise throw
rospy.Duration(1.0))
pose_transformed = tf2_geometry_msgs.do_transform_pose(pose_stamped, transform)
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...
Asked: 2015-12-10 07:10:08 -0500
Seen: 16,619 times
Last updated: Nov 18 '21
how to make end effector look at object?
Check if target joint position is valid
registering depth image on different image size
Quaternion multiplication for orientation update yielding incorrect values
Streaming point clouds to webservice with roslibjs
How to specify my own OpenCV3 for cv_bridge
Moving in Rviz opposite to reality