socrob / autonomous_systems

Material used for learning ROS and robotics, as part of the Autonomous Systems course at Instituto Superior Tecnico
34 stars 9 forks source link

tf problem #22

Open oscar-lima opened 6 years ago

oscar-lima commented 6 years ago

Question: We have some problems with the lookupTransform. We are asking the more recent position of the robot and upon a time it returns us an older position instead of the current one.

We have already used rospy.Time(0) and this doesn't solved our problem

oscar-lima commented 6 years ago

Thats weird, rospy.Time(0) should give you the latest tranform.

My advice is for you to check the code against this snippet:

import tf
import rospy

listener = tf.TransformListener()
wait_for_transform = 0.1
reference_frame = "my_reference_frame"
target_frame = "my_target_frame"

try:
    listener.waitForTransform(reference_frame, target_frame, rospy.Time(0), rospy.Duration(wait_for_transform))
    (translation, rotation) = self.listener.lookupTransform(reference_frame, target_frame, rospy.Time(0))
except tf.Exception, error:
    rospy.logwarn("Exception occurred: {0}".format(error))

# x, y, z

translation[0]
translation[1]
translation[2]
# quaternion

print rotation[0]
print rotation[1]
print rotation[2]
print rotation[3]