OdometryTfBroadcaster.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 import rospy
00003 from geometry_msgs.msg import Vector3, Quaternion, TransformStamped, Transform
00004 import tf
00005 from tf.msg import tfMessage
00006 import numpy
00007 import threading
00008 import copy
00009 
00010 class OdometryTfBroadcaster:
00011     def __init__(self):
00012         rospy.init_node("OdometryTfBroadcaster", anonymous=True)
00013         self.map_to_prt_sub = rospy.Subscriber("~map_to_particle", TransformStamped, self.append_transform_stamped_to_buffer, queue_size = 1)
00014         self.prt_to_odom_sub = rospy.Subscriber("~particle_to_odom", TransformStamped, self.append_transform_stamped_to_buffer, queue_size = 1)
00015         self.base_to_scan_sub = rospy.Subscriber("~base_to_scan", TransformStamped, self.append_transform_stamped_to_buffer, queue_size = 1)
00016         self.tf_lock = threading.Lock()
00017         self.tf_buffer = []
00018         self.rate = rospy.get_param("~rate", 50)
00019         self.r = rospy.Rate(self.rate)
00020         self.broadcaster = rospy.Publisher("/tf", tfMessage, queue_size = 100) # Make publisher for tfMessage because tf.broadcaster in python cannot receive transfomation msg list
00021 
00022     def execute(self):
00023         while not rospy.is_shutdown():
00024             with self.tf_lock:
00025                 if len(self.tf_buffer) > 0:
00026                     self.tf_buffer.sort(key = lambda msg: msg.header.stamp.to_sec()) # It seems that transformations in tfMessage needs to be sorted by timestamp
00027                     self.broadcaster.publish(tfMessage(self.tf_buffer))
00028                     self.tf_buffer = []
00029             self.r.sleep()
00030 
00031     def append_transform_stamped_to_buffer(self, msg):
00032         with self.tf_lock:
00033             self.tf_buffer.append(msg)
00034                 
00035 if __name__ == '__main__':
00036     try:
00037         node = OdometryTfBroadcaster()
00038         node.execute()
00039     except rospy.ROSInterruptException: pass


jsk_robot_startup
Author(s):
autogenerated on Sat Jul 1 2017 02:42:18