5 from sensor_msgs.msg
import LaserScan
6 from nav_msgs.msg
import OccupancyGrid
7 from tf.transformations
import euler_from_quaternion
13 rospy.init_node(
'map_laser_filter')
14 self.
pub = rospy.Publisher(
'/base_scan_filter',
20 self.
sub = rospy.Subscriber(
'/scan_filtered',
24 self.
sub2 = rospy.Subscriber(
'/map', OccupancyGrid, self.
map_cb)
30 now = msg.header.stamp
31 f2 = msg.header.frame_id
33 self.
listener.waitForTransform(f1, f2, now, rospy.Duration(.15))
35 return self.
listener.lookupTransform(f1, f2, now)
39 for dx
in range(-N, N + 1):
40 for dy
in range(-N, N + 1):
41 index = (x + dx) + (y + dy) * self.
map.info.width
42 if index < 0
or index > len(self.
map.data):
44 value = self.
map.data[index]
45 if value > 50
or value < 0:
54 self.
save = (trans, rot)
58 (trans, rot) = self.
save
60 yaw = euler_from_quaternion(rot)[2]
64 for (i, d)
in enumerate(msg.ranges):
65 if math.isnan(d)
or d > msg.range_max
or d < msg.range_min:
66 nr.append(msg.range_max + 1.0)
68 angle = yaw + msg.angle_min + msg.angle_increment * i
69 dx = math.cos(angle) * d
70 dy = math.sin(angle) * d
74 grid_x = int((map_x - self.
map.info.origin.position.x) / self.
map.info.resolution)
75 grid_y = int((map_y - self.
map.info.origin.position.y) / self.
map.info.resolution)
78 nr.append(msg.range_max + 1.0)
86 if __name__ ==
'__main__':