ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to transpose and rotate frames and get new coordinates

asked 2019-10-17 06:26:13 -0600

RobotsAreCool gravatar image

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?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-17 11:40:47 -0600

updated 2019-10-21 10:42:56 -0600

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.


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


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

tf1_listener = tf.TransformListener()

# give listeners time to receive required transforms

# make Pose in the 'b' frame
p_b = tf2_geometry_msgs.tf2_geometry_msgs.PoseStamped()
p_b.header.frame_id = 'frame_b'
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.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))
edit flag offensive delete link 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.

RobotsAreCool gravatar image RobotsAreCool  ( 2019-10-21 03:18:33 -0600 )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.

jarvisschultz gravatar image jarvisschultz  ( 2019-10-21 10:18:33 -0600 )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.

jarvisschultz gravatar image jarvisschultz  ( 2019-10-21 10:41:42 -0600 )edit

Question Tools



Asked: 2019-10-17 06:26:13 -0600

Seen: 1,153 times

Last updated: Oct 21 '19