tf2 conversion of geometry message
Hi,
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:
Publisher:
gravity_pub = rospy.Publisher('gravity', geometry_msgs.msg.Vector3Stamped, queue_size = 1)
# TF Publisher:
g = geometry_msgs.msg.Vector3Stamped()
# Header:
g.header.stamp = rospy.Time.now()
g.header.frame_id = 'sensor'
# Data:
g.vector.x = 0
g.vector.y = 0
g.vector.z = 9.81
gravity_pub.publish(g)
Listener:
rospy.init_node('tf2_imu_listener')
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!
Felix
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.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.