-
Notifications
You must be signed in to change notification settings - Fork 104
/
TryLoopOrNot.m
39 lines (35 loc) · 996 Bytes
/
TryLoopOrNot.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
31
32
33
34
35
36
37
38
39
function needLoopTrial = TryLoopOrNot(map)
% First of all, we don't want to detect loop closure too frequently.
%(At least 10 keyscans away from last trial)
trialInterval = 1;
for k = length(map.keyscans)-1 : -1 : 1
if ~map.keyscans(k).loopTried
trialInterval = trialInterval + 1;
else
break;
end
end
if trialInterval < 10
needLoopTrial = false;
return;
end
% Then we don't want to detect loop closure after a newly closed loop
% (At least 10 meters need to be traveled since last closure)
traveledDistance = 0;
for k = length(map.keyscans)-1 : -1 : 1
if ~map.keyscans(k).loopClosed
dT = DiffPose(map.keyscans(k).pose, map.keyscans(k+1).pose);
traveledDistance = traveledDistance + norm(dT(1:2));
if traveledDistance > 10
break;
end
else
break;
end
end
if traveledDistance < 10
needLoopTrial = false;
return;
end
% Now we see that a loop detection is wanted
needLoopTrial = true;