-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLaserScan_fitness.m
30 lines (23 loc) · 998 Bytes
/
LaserScan_fitness.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function score = LaserScan_fitness(pose, map, laserscan)
score = zeros(size(pose,1),1);
for i = 1:size(pose,1)
% Convert laser ranges to map coordinate frame
[x y] = laserscan.translate(pose(i,:));
% Find the pixel at each laser hit
q_x = round(map.pixel_from_x(x));
q_y = round(map.pixel_from_y(y));
% Find all 'hits' inside the map
idx = (x > map.left & x < map.right) & (y > map.bottom & y < map.top);
% Gather the distances from each hit to the nearest object
map_ind = sub2ind(size(map.dist), q_y(idx), q_x(idx) );
z = map.dist(map_ind);
% Score the Result
a = sum(z);
% b = sqrt((map.right - map.left)^2 + (map.top - map. bottom)^2);
% c = length(z);
% d = length(laserscan.ranges);
e = length(idx(not(idx)));
% Mean disatance between each hit and the nearest object
score(i) = 1 / (a + e);
end
end