Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 from sensor_msgs.msg import *
00020
00021 class GazeboVirtualRangeSensor():
00022
00023 def __init__(self, laser_topic, range_topic):
00024 rospy.Subscriber(laser_topic, LaserScan, self.laser_callback)
00025
00026 self.pub = rospy.Publisher(range_topic, Range, queue_size=1)
00027
00028 rospy.loginfo("adding sensor converting from topic '" + laser_topic + "' to topic '" + range_topic + "'")
00029
00030 def laser_callback(self, msg):
00031 sensor_range = Range()
00032
00033
00034 sensor_range.header = msg.header
00035
00036
00037 if len(msg.ranges) > 0:
00038 sensor_range.range = sum(msg.ranges)/len(msg.ranges)
00039 else:
00040 sensor_range.range = 0
00041
00042
00043 sensor_range.min_range = msg.range_min
00044 sensor_range.max_range = msg.range_max
00045
00046
00047 sensor_range.field_of_view = msg.angle_max - msg.angle_min
00048
00049
00050 sensor_range.radiation_type = 1
00051
00052
00053 self.pub.publish(sensor_range)
00054
00055 if __name__ == "__main__":
00056 rospy.init_node('tactile_sensors')
00057 rospy.sleep(0.5)
00058
00059 if not rospy.has_param('~sensors'):
00060 rospy.logerr("no sensors specified")
00061 exit(1)
00062
00063 sensors = rospy.get_param('~sensors')
00064
00065 if type(sensors) != list:
00066 rospy.logerr("sensors parameter not a list")
00067 exit(1)
00068
00069 for sensor in sensors:
00070 GazeboVirtualRangeSensor(sensor['laser_topic'], sensor['range_topic'])
00071
00072 rospy.spin()