-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_completion.cpp
executable file
·146 lines (113 loc) · 4.09 KB
/
scan_completion.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "scan_completion.h"
/*******************************************************************************
*/
void ScanCompletion::completeScan(std::vector<double>* scan, const int& method)
{
if (method == 1)
completeScan1(scan);
else if (method == 3)
completeScan3(scan);
else if (method == 4)
completeScan4(scan);
else
completeScan1(scan);
}
/*******************************************************************************
* Symmetric to the line passing from the first and last scan points
*/
void ScanCompletion::completeScan1(std::vector<double>* scan)
{
std::vector<double> scan_copy = *scan;
for (int i = scan_copy.size()-2; i > 0; i--)
scan->push_back(scan_copy[i]);
// Rotate so that it starts from -M_PI rather than -M_PI / 2
int num_pos = scan->size() / 4;
std::rotate(scan->begin(),
scan->begin() + scan->size() - num_pos,
scan->end());
}
/*******************************************************************************
* Completes a circular arc around 'pose'
**/
void ScanCompletion::completeScan2(std::vector<double>* scan,
const std::tuple<double,double,double>& pose)
{
std::vector<double> scan_copy = *scan;
// Locate the first and last points of the scan in the 2D plane
std::vector< std::pair<double,double> > points;
Utils::scan2points(scan_copy, pose, &points);
std::pair<double,double> start_point = points[0];
std::pair<double,double> end_point = points[points.size()-1];
double dx = start_point.first - end_point.first;
double dy = start_point.second - end_point.second;
double d = sqrt(dx*dx + dy*dy);
double r = d/2;
for (int i = scan_copy.size()-2; i > 0; i--)
scan->push_back(r);
// Rotate so that it starts from -M_PI rather than -M_PI / 2
int num_pos = scan->size() / 4;
std::rotate(scan->begin(),
scan->begin() + scan->size() - num_pos,
scan->end());
}
/*******************************************************************************
* Mirrored
**/
void ScanCompletion::completeScan3(std::vector<double>* scan)
{
std::vector<double> scan_copy = *scan;
for (int i = 1; i < scan_copy.size()-1; i++)
scan->push_back(scan_copy[i]);
// Rotate so that it starts from -M_PI rather than -M_PI / 2
int num_pos = scan->size() / 4;
std::rotate(scan->begin(),
scan->begin() + scan->size() - num_pos,
scan->end());
}
/*******************************************************************************
* min range arc around true pose
**/
void ScanCompletion::completeScan4(std::vector<double>* scan)
{
// Find closest and furthest points in original scan
double min_range = *std::min_element(scan->begin(), scan->end());
double max_range = *std::max_element(scan->begin(), scan->end());
double fill_range = min_range;
unsigned int scan_size = scan->size();
for (int i = 1; i < scan_size-1; i++)
scan->push_back(fill_range);
// Rotate so that it starts from -M_PI rather than -M_PI / 2
assert(fmod(scan->size(), 2) == 0);
int num_pos = scan->size() / 4;
std::rotate(scan->begin(),
scan->begin() + scan->size() - num_pos,
scan->end());
}
/*******************************************************************************
* straight
**/
void ScanCompletion::completeScan5(
const std::tuple<double,double,double>& pose,
const std::vector<double>& scan_in,
const unsigned int& num_rays,
std::vector<double>* scan_out,
std::vector< std::pair<double,double> >* map,
std::tuple<double,double,double>* map_origin)
{
std::vector< std::pair<double,double> > scan_points;
Utils::scan2points(scan_in, pose, &scan_points, M_PI);
std::tuple<double,double,double> pose_within_points = pose;
double farther_than = 0.01;
bool is_farther_than = false;
while (!is_farther_than)
{
do Utils::generatePose(pose,
0.05, 0.0, &pose_within_points);
while(!Utils::isPositionInMap(pose_within_points, scan_points));
*map = X::find(pose_within_points, scan_points, num_rays);
is_farther_than =
Utils::isPositionFartherThan(pose_within_points, *map, farther_than);
}
*map_origin = pose_within_points;
Utils::points2scan(*map, *map_origin, scan_out);
}