ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

tf2 conversion of geometry message

asked 2018-12-20 04:49:27 -0600

felix.behnke gravatar image


I am new to ROS and try to figure out how to use tf2 for my purpose.

I want to have a fixed map frame in which I publish a gravity vector with datatype Vector3Stamped: [0,0,9.81] Next I have a sensor frame which is rotated by TransformBroadcaster.

How can i now ask for the gravity vector in respect to the rotated sensor frame? If both frames are aligned it should also be [0,0,9.81] but should change with rotation.

The rotation of the sensor frame is working fine and I can watch it in RVIZ. It is just the part, getting the corresponding vector in my other frame which i cannot figure out by the tutorials and documentation.

How exactly do i have to publish the vector?

... my approach:


gravity_pub = rospy.Publisher('gravity', geometry_msgs.msg.Vector3Stamped, queue_size = 1)
# TF Publisher:
g = geometry_msgs.msg.Vector3Stamped()
# Header:
g.header.stamp =
g.header.frame_id = 'sensor'
# Data:
g.vector.x = 0
g.vector.y = 0
g.vector.z = 9.81



tfBuffer = tf2_ros.Buffer()
listener = tf2_ros.TransformListener(tfBuffer)
trans = tfBuffer.lookup_vector('map', 'imu', rospy.Time())
print trans

Thank you very much for your help!


edit retag flag offensive close merge delete


g.header.frame_id = 'sensor'

Wouldn't this make your "gravity frame" relative to your "sensor" frame? I would expect you to publish a gravity vector in some world/map/global frame and then transform that into the sensor frame, but I may be misunderstanding your question.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-20 05:41:29 -0600 )edit

I'd also note that gravity is a direction, so would be more meaningfully represented by the orientation of a pose. This way if it is rotated and translated to different frames the direction will still be correct. A vector defines a location, so a translation will alter the direction it's pointing.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-20 09:13:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-12-21 04:01:08 -0600

felix.behnke gravatar image

I already figured out, what i searched for. Its a built in function of tfBuffer:

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

acc_local = Vector3Stamped(header=imu_msg.header, vector=imu_msg.linear_acceleration)
acc_global = tfBuffer.transform(acc_local, 'fixed', timeout=rospy.Duration(0.1))

something like this. Thanks for the help!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-12-20 04:49:27 -0600

Seen: 410 times

Last updated: Dec 21 '18