Go to the documentation of this file.00001
00002 import rospy
00003 from geometry_msgs.msg import Vector3, Quaternion, TransformStamped, Transform
00004 import tf
00005 import numpy
00006
00007 class OdometryTfManager:
00008 def __init__(self):
00009 rospy.init_node("SlamMapTfToOdometry", anonymous=True)
00010 self.map_frame = rospy.get_param("~map_frame", "map")
00011 self.particle_frame = rospy.get_param("~particle_frame", "biped_odom_particle")
00012 self.odom_frame = rospy.get_param("~odom_frame", "odom")
00013 self.base_frame = rospy.get_param("~base_frame", "BODY")
00014 self.scan_frame = rospy.get_param("~scan_frame", "pointcloud_to_laserscan_base")
00015 self.map_to_prt_pub = rospy.Publisher("~map_to_particle", TransformStamped, queue_size = 1)
00016 self.prt_to_odom_pub = rospy.Publisher("~particle_to_odom", TransformStamped, queue_size = 1)
00017 self.base_to_scan_pub = rospy.Publisher("~base_to_scan", TransformStamped, queue_size = 1)
00018 self.rate = rospy.get_param("~rate", 50)
00019 self.listener = tf.TransformListener()
00020 self.r = rospy.Rate(self.rate)
00021
00022 def execute(self):
00023 while not rospy.is_shutdown():
00024 self.publish_transform_stamped()
00025 self.r.sleep()
00026
00027 def publish_transform_stamped(self):
00028 stamp = rospy.Time.now()
00029 map_to_prt_tf = self.make_transform_stamped(stamp, self.map_frame, self.particle_frame)
00030 if map_to_prt_tf != None:
00031 self.map_to_prt_pub.publish(map_to_prt_tf)
00032 prt_to_odom_tf = self.make_transform_stamped(stamp, self.particle_frame, self.odom_frame)
00033 if prt_to_odom_tf != None:
00034 self.prt_to_odom_pub.publish(prt_to_odom_tf)
00035 base_to_scan_tf = self.make_transform_stamped(stamp, self.base_frame, self.scan_frame)
00036 if base_to_scan_tf != None:
00037 self.base_to_scan_pub.publish(base_to_scan_tf)
00038
00039 def make_transform_stamped(self, stamp, parent_frame, child_frame):
00040 try:
00041 (trans,rot) = self.listener.lookupTransform(parent_frame, child_frame, rospy.Time(0))
00042 except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
00043 rospy.logwarn("[%s]" + " Failed to solve tf: %s to %s", rospy.get_name(), parent_frame, child_frame)
00044 return None
00045 tf_stamped = TransformStamped()
00046 tf_stamped.header.stamp = stamp
00047 tf_stamped.header.frame_id = parent_frame
00048 tf_stamped.child_frame_id = child_frame
00049 tf_stamped.transform = Transform(Vector3(*trans), Quaternion(*rot))
00050 return tf_stamped
00051
00052 if __name__ == '__main__':
00053 try:
00054 node = OdometryTfManager()
00055 node.execute()
00056 except rospy.ROSInterruptException: pass