-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCloseLoop.m
86 lines (64 loc) · 1.66 KB
/
CloseLoop.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function newMap = CloseLoop(bestPose, map, dearIndex)
%{
-------------------------------------------------------
step 1: Find the closest point to dear
-------------------------------------------------------
%}
closestPoint = dearIndex;
minDT = Inf;
for idx = dearIndex : -1 : 1
dT = DiffPose(map.keyscans(idx).pose, bestPose);
if minDT > norm(dT(1:2))
minDT = norm(dT(1:2));
closestPoint = idx;
end
end
c = 1;
pause;
%}
%{
-------------------------------------------------------
step 2: create a PoseGraph
-------------------------------------------------------
%}
%{
poseGraph = robotics.PoseGraph;
N = size(path, 1);
addRelativePose(poseGraph, path{2}.');
for idx = 3 : N
past = nodes(poseGraph, idx-1);
vec = path{idx}.';
tx = past(1);
ty = past(2);
theta = - past(3);
ct = cos(theta);
st = sin(theta);
R = [ct, -st; st, ct];
xy = [(vec(1) - tx), (vec(2) - ty)];
xy = xy * (R');
newTheta = -angdiff(vec(3), past(3));
addRelativePose(poseGraph, [xy(1) xy(2) newTheta]);
end
%}
%{
-------------------------------------------------------
step 3: add a loop to PoseGraph
-------------------------------------------------------
%}
%{
addRelativePose(poseGraph,[0,0,0],[1 0 0 1 0 1],1,1365) ;
%{
-------------------------------------------------------
step 4: optimize the PoseGraph
-------------------------------------------------------
%}
poseGraph = optimizePoseGraph(poseGraph);
newPath = nodes(poseGraph);
%{
-------------------------------------------------------
step 5: fix the map
-------------------------------------------------------
%}
newMap
%}
end