Go to the documentation of this file.00001
00002 '''
00003 compute_distance_traveled.py
00004 Mac Mason <mac@cs.duke.edu>
00005
00006 Just figure out how far a robot has gone, from /tf.
00007 '''
00008 import math
00009 import roslib
00010 roslib.load_manifest('semanticmodel')
00011 import rospy
00012 import tf
00013
00014 rospy.init_node('compute_distance_traveled')
00015 listener = tf.TransformListener()
00016
00017
00018 distance = 0.0
00019 old_trans = None
00020
00021 rate = rospy.Rate(100)
00022 while not rospy.is_shutdown():
00023 try:
00024 (trans, _) = listener.lookupTransform('/map',
00025 '/base_link',
00026 rospy.Time(0))
00027 if old_trans == None:
00028 old_trans = trans
00029
00030 delta = (trans[0] - old_trans[0], trans[1] - old_trans[1])
00031 distance += math.sqrt((delta[0] * delta[0]) + (delta[1] * delta[1]))
00032 rospy.loginfo("Distance: %f" % distance)
00033 old_trans = trans
00034
00035 except (tf.LookupException,
00036 tf.ConnectivityException,
00037 tf.ExtrapolationException):
00038 print "tf is whining!"
00039
00040 rate.sleep()