Search code examples
pythonroscoordinate-transformation

In ROS, how to transform pose from kinect frame to PR2's base_link frame?


I am having confusion with tf. I am working on a grasping project. My vision partner is giving me a pose of an object in the camera frame or when running a robot, the robot's Kinect frame (PR2 robot). Now, in order to grasp that object, I need to get the pose in the robot's base_link frame as this frame is used by the moveit interface.

Initially, my thinking was that I can do that using lookup transform method of tf but now I have come to know that this only gives transformation between different frames. In order to get what I need, which is the object's location in the base_link frame, I should use a transformListener method. I am still confused about the difference between the two. I am working with python. If anyone could give me a sample working transformListener code, that would be helpful as well.


Solution

  • I got the answer so this is how it is:

    import tf2_ros
    import tf2_geometry_msgs #import the packages first
    
    tf_buffer = tf2_ros.Buffer(rospy.Duration(1200.0)) #tf buffer length
    tf_listener = tf2_ros.TransformListener(tf_buffer)
    transform = tf_buffer.lookup_transform("base_link",
                                       poseStampedToTransform.header.frame_id, #source frame
                                       rospy.Time(0), #get the tf at first available time
                                       rospy.Duration(1.0))
    pose_transformed = tf2_geometry_msgs.do_transform_pose(poseStampedToTransform, transform)
    print("pose_transformed",pose_transformed.pose)