How to transpose and rotate frames and get new coordinates

Hi everyone,

I am new in the ROS world and still don't get some concepts. Could anyone explain me how to use the transformPose?

Let's assume I have a global frame A and an end-of-efector frame B. Let's assume that in the frame B I have a point P_b. I want to get P_b's coordinates in the frame A (P_b->a). Mathematically speaking, it's really simple. But what are those steps in ROS? I know I can get a translation vector and quaternions using lookupTransform applied to my frames. What comes next? Do I have to calculate P_b->a manually or can call a function to get the new coordinates (transformPose or transformQuaterions?

Best,

edit retag close merge delete

Sort by ยป oldest newest most voted

Presumably, you are using C++. If that is the case, you'd likely want to look to the doTransform methods of tf2. For example, there is an overload of doTransform specifically for geometry_msgs/Point types. So if you had your point expressed in the B frame P_b, you could lookup the transform from A to B, and then apply that to B to get the point in the A frame.

EDIT

Adding a small Python example that assumes the tf tree already has a frame_a and a frame_b available.

#!/usr/bin/env python

import rospy
import tf
import tf2_ros
import tf2_geometry_msgs

rospy.init_node("demo_lookup")

tfbuffer = tf2_ros.Buffer()
listener = tf2_ros.TransformListener(tfbuffer)

tf1_listener = tf.TransformListener()

# give listeners time to receive required transforms
rospy.sleep(1.0)

# make Pose in the 'b' frame
p_b = tf2_geometry_msgs.tf2_geometry_msgs.PoseStamped()
p_b.pose.position.y = 0.5
p_b.pose.orientation.w = 1.0

# Use tf2 to transform pose to the 'a' frame and print results. Best practice
# would wrap this in a try-except:
t_a_b = tfbuffer.lookup_transform('frame_a', 'frame_b', rospy.Time.now(), rospy.Duration(1.0))
p_a = tf2_geometry_msgs.do_transform_pose(p_b, t_a_b)
rospy.loginfo("Pose expressed in 'frame_a' using tf2: \n%s\n", str(p_a))

# Use tf to transform pose to the 'a' frame and print results. Best practice
# would wrap this in a try-except:
p_a_tf1 = tf1_listener.transformPose('frame_a', p_b)
rospy.loginfo("Pose expressed in 'frame_a' using tf: \n%s\n", str(p_a_tf1))

more

Hi @jarvischultz and thank you for you comment. I have to use python. I think that transformPose does exactly what I need and I don't even need to call lookupTransform. However I cannot find any confirmation, which makes me unsure.

( 2019-10-21 03:18:33 -0500 )edit

transformPose should do exactly what you want. I will point out that that uses the old tf API instead of the newer tf2 API. While the old API doesn't seem to be going away any time soon, I generally prefer using the new API.

( 2019-10-21 10:18:33 -0500 )edit

Sorry.. I didn't read your comment closely enough. I still thought you were in C++. I'll add a little code snippet to my answer illustrating how to do this in both APIs in Python.

( 2019-10-21 10:41:42 -0500 )edit