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,622 times
Last updated: Nov 18 '21
how to make end effector look at object?
replacement for rospy.Time(0) in ROS2?
Own nav path has closed loop in rviz
Check if target joint position is valid
Publish ROSBAG in synch with /clock by roscpp
How to display only selected topics in rqt topic monitor
How do I remove a dependency of a package?
How to start a roscore at system boot so that nodes run automatically when system is up?