simulated_range_sensors.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 from sensor_msgs.msg import *
20 
22 
23  def __init__(self, laser_topic, range_topic):
24  rospy.Subscriber(laser_topic, LaserScan, self.laser_callback)
25 # rospy.logdebug("subscribed to laser topic: %s", laser_topic)
26  self.pub = rospy.Publisher(range_topic, Range, queue_size=1)
27 # rospy.loginfo("topic '" + range_topic + "' advertised")
28  rospy.loginfo("adding sensor converting from topic '" + laser_topic + "' to topic '" + range_topic + "'")
29 
30  def laser_callback(self, msg):
31  sensor_range = Range()
32 
33  # set header
34  sensor_range.header = msg.header
35 
36  # set range from average out of laser message
37  if len(msg.ranges) > 0:
38  sensor_range.range = sum(msg.ranges)/len(msg.ranges)
39  else:
40  sensor_range.range = 0
41 
42  # set min and max range
43  sensor_range.min_range = msg.range_min
44  sensor_range.max_range = msg.range_max
45 
46  # set field of view
47  sensor_range.field_of_view = msg.angle_max - msg.angle_min
48 
49  # set radiation type to IR (=1)
50  sensor_range.radiation_type = 1
51 
52  # publish range
53  self.pub.publish(sensor_range)
54 
55 if __name__ == "__main__":
56  rospy.init_node('tactile_sensors')
57  rospy.sleep(0.5)
58 
59  if not rospy.has_param('~sensors'):
60  rospy.logerr("no sensors specified")
61  exit(1)
62 
63  sensors = rospy.get_param('~sensors')
64 
65  if type(sensors) != list:
66  rospy.logerr("sensors parameter not a list")
67  exit(1)
68 
69  for sensor in sensors:
70  GazeboVirtualRangeSensor(sensor['laser_topic'], sensor['range_topic'])
71 
72  rospy.spin()


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 02:11:43