8 from sensor_msgs.msg
import LaserScan
9 from nav_msgs.msg
import OccupancyGrid, MapMetaData
25 self.
pub = rospy.Publisher(
'scan', LaserScan, queue_size = 1)
28 self.
pi2 = math.pi * 2
29 self.
pih = math.pi / 2
35 self.scan.header.frame_id =
'wheels_base_laser_link' 36 self.scan.angle_min = -1.57079637051
37 self.scan.angle_max = 1.57079637051
38 self.scan.angle_increment = 0.00436332309619
39 self.scan.time_increment = 1.73611151695e-05
40 self.scan.scan_time = 0.0250000003725
41 self.scan.range_min = 0.019999999553
42 self.scan.range_max = 30.0
45 (self.scan.angle_max - self.scan.angle_min)
46 / self.scan.angle_increment)
49 self.
sub_map = rospy.Subscriber(
'map', OccupancyGrid,
55 self.scan.ranges.append(10.0)
61 cr = math.cos(math.acos(map_info.origin.orientation.w) * 2.0)
62 sr = math.sqrt(1.0 - cr * cr)
64 for y
in range(map_info.height):
65 yidx = y * map_info.width
66 my = y * map_info.resolution + map_info.origin.position.y
67 for x
in range(map_info.width):
68 val = msg.data[x + yidx]
70 mx = x * map_info.resolution + map_info.origin.position.x
71 pt = [mx * cr - my * sr,
74 self.mapgrid_list.append(pt)
76 self.sub_map.unregister()
84 laser_pos, null = self.tf_listener.lookupTransform(
86 'wheels_base_laser_link',
89 base_pos, null = self.tf_listener.lookupTransform(
93 laser_theta = math.atan2(laser_pos[1] - base_pos[1], laser_pos[0] - base_pos[0])
101 self.scan.ranges = []
103 self.scan.ranges.append(0.0)
106 lx = mp[0] - laser_pos[0]
107 ly = mp[1] - laser_pos[1]
108 lrange = math.sqrt(lx * lx + ly * ly)
109 ltheta = math.atan2(ly, lx) - laser_theta
111 ltheta = ltheta - self.
pi2 112 elif ltheta < -math.pi:
113 ltheta = ltheta + self.
pi2 115 if ltheta >= self.scan.angle_min
and ltheta <= self.scan.angle_max:
116 li = int((ltheta - self.scan.angle_min) / self.scan.angle_increment)
117 if self.scan.ranges[li] < 1e-5:
118 self.scan.ranges[li] = lrange
119 elif self.scan.ranges[li] > lrange:
120 self.scan.ranges[li] = lrange
125 self.scan.header.stamp = rospy.get_rostime()
126 self.pub.publish(self.
scan)
128 if __name__ ==
'__main__':
129 rospy.init_node(
'dummy_scan', anonymous =
True)
132 rate = rospy.Rate(40)
133 while not rospy.is_shutdown():
def make_constant_range(self)
make constant range, if map and tf have not been recieved
def make_map_range(self)
make range data from map and current pose
def map_to_points(self, msg)
map to points
publiush dummy scan range