ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# From transform to pose?

Hi all, I'm very new to Python and the TF package. Given a transform, I am trying to calculate its pose. How would I do that?

I've seen this link and saw the code

  tf::Transform grasp_tf(gripperRotation, gripperOrigin);
tf::Stamped<tf::Pose> grasp_tf_pose(grasp_tf);
geometry_msgs::PoseStamped msg;
tf::poseStampedTFToMsg    (grasp_tf_pose, msg);


However, I don't know how I should convert this into Python code. Is there more documentation than the one given in the wiki?

edit retag close merge delete

Sort by » oldest newest most voted You actually linked to the API documentation, which you should definitely read through AFTER going through the tutorials http://wiki.ros.org/tf/Tutorials .

A transform represents a transformation from frame A to frame B. So could you be more specific about what you mean by 'calculating its pose'. If you mean get the vectors representing the translation and rotation from A to B, there's a few ways (in C++ anyways, python will be somewhat similar):

1&2) First waitForTransform, to make sure the transform is available.

1) lookupTransform, then getOrigin and getRotation on the transform object

2) Initialize a Stamped<pose> in frame B with a position vector of (0,0,0), and a quaternion of (0,0,0,1), then transformPose to frame A.

tf::poseStampedTFToMsg and similar are helper methods in C++ to convert between the tf and ROS message representation of various objects. A tf representation is used to perform actual mathematical operations, while the ROS message representation is used for communication (publishing/subscribing/broadcasting tf).

A Pose contains a position and an orientation, a Stamped<pose> also contains frame and time information needed to transform the pose from one frame to another. Similar pattern applies to vectors, quaternions etc.

more

Yes. What I meant was if I had an original Pose information and then a Transform information, how would I use these two information to calculate its resulting Pose?

transformPose(target_frame, pose_msg) -> pose_msg

However, I dont understand how exactly to calculate the transform which can be used later as in the question. I have two messages coming to me from two different topics. Both of geometry_msgs/poseStamped type. I need to calculate the transform. The tf function you're looking for is

lookupTransform(target_frame, source_frame, time) -> (position, quaternion)


The function returns the translation and rotation of the transformation between the two frames:

(translation,rotation) = t.lookupTransform("tf_1", "tf_2", rospy.Time())


Now, you have the translation and rotation values, you can construct the pose msg.

more

Yes, this is it. I think this is the correct answer. If it is a Pose to a Goal in an autonomous base, just set "Z" to 0, for example