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 -0600
Seen: 17,437 times
Last updated: Nov 18 '21
Any good examples of using dynamic_reconfigure for a python node?
How to recieve an array over Publisher and Subscriber? (Python)
how is rosh's ok() different from rospy.is_shutdown()?
How can I use custom python functions in other ROS packages?
Do I need to know any specific computer language or framework to use ROS?
Is anybody in ROS community using PySide?
Retrieving pose of an object from an image or bag file
is there a python equivalent of fromROSMsg/toROSMsg (pcl stack)