def record_tf(self, event):
if self.active:
try:
self.listener.waitForTransform(self.root_frame,
self.measured_frame,
rospy.Time(0),
rospy.Duration.from_sec(1 / (2*self.tf_sampling_freq)))
(trans, rot) = self.listener.lookupTransform(self.root_frame, self.measured_frame, rospy.Time(0))
except (tf.Exception, tf.LookupException, tf.ConnectivityException) as e:
rospy.logwarn(e)
pass
else:
if self.first_value:
self.trans_old = trans
self.rot_old = rot
self.first_value = False
return
#print "transformations: \n", "trans[0]", trans[0], "self.trans_old[0]",self.trans_old[0], "trans[1]", trans[1], "self.trans_old[1]",self.trans_old[1], "trans[2]",trans[2], "self.trans_old[2]",self.trans_old[2], "\n ------------------------------------------------ "
path_increment = math.sqrt((trans[0] - self.trans_old[0]) ** 2 + (trans[1] - self.trans_old[1]) ** 2 +
(trans[2] - self.trans_old[2]) ** 2)
if(path_increment < 1):
#rospy.logwarn("Transformation: %s, Path Increment: %s",str(trans), str(path_increment))
self.path_length += path_increment
else:
rospy.logwarn("Transformation Failed! \n Transformation: %s, Path Increment: %s",str(trans), str(path_increment))
self.trans_old = trans
self.rot_old = rot
评论列表
文章目录