forked from atenpas/gpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcem_detect_grasps.cpp
99 lines (85 loc) · 2.94 KB
/
cem_detect_grasps.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
#include <string>
#include <gpd/sequential_importance_sampling.h>
namespace gpd {
namespace apps {
namespace detect_grasps {
bool checkFileExists(const std::string &file_name) {
std::ifstream file;
file.open(file_name.c_str());
if (!file) {
std::cout << "File " + file_name + " could not be found!\n";
return false;
}
file.close();
return true;
}
int DoMain(int argc, char *argv[]) {
// Read arguments from command line.
if (argc < 3) {
std::cout << "Error: Not enough input arguments!\n\n";
std::cout
<< "Usage: cem_detect_grasps CONFIG_FILE PCD_FILE [NORMALS_FILE]\n\n";
std::cout << "Detect grasp poses for a point cloud, PCD_FILE (*.pcd), "
"using parameters from CONFIG_FILE (*.cfg).\n\n";
std::cout << "[NORMALS_FILE] (optional) contains a surface normal for each "
"point in the cloud (*.csv).\n";
return (-1);
}
std::string config_filename = argv[1];
std::string pcd_filename = argv[2];
if (!checkFileExists(config_filename)) {
printf("Error: config file not found!\n");
return (-1);
}
if (!checkFileExists(pcd_filename)) {
printf("Error: PCD file not found!\n");
return (-1);
}
// View point from which the camera sees the point cloud.
Eigen::Matrix3Xd view_points(3, 1);
view_points.setZero();
// Load point cloud from file
util::Cloud cloud(pcd_filename, view_points);
if (cloud.getCloudOriginal()->size() == 0) {
std::cout << "Error: Input point cloud is empty or does not exist!\n";
return (-1);
}
// Load surface normals from file.
if (argc > 3) {
std::string normals_filename = argv[3];
cloud.setNormalsFromFile(normals_filename);
std::cout << "Loaded surface normals from file: " << normals_filename
<< "\n";
}
// Read parameters from configuration file.
const double VOXEL_SIZE = 0.003;
util::ConfigFile config_file(config_filename);
config_file.ExtractKeys();
std::vector<double> workspace =
config_file.getValueOfKeyAsStdVectorDouble("workspace", "-1 1 -1 1 -1 1");
int num_threads = config_file.getValueOfKey<int>("num_threads", 1);
bool sample_above_plane =
config_file.getValueOfKey<int>("sample_above_plane", false);
double normals_radius =
config_file.getValueOfKey<double>("normals_radius", 0.03);
printf("num_threads: %d\n", num_threads);
printf("sample_above_plane: %d\n", sample_above_plane);
printf("normals_radius: %.3f\n", normals_radius);
// Preprocess the point cloud.
cloud.filterWorkspace(workspace);
cloud.voxelizeCloud(VOXEL_SIZE);
cloud.calculateNormals(num_threads, normals_radius);
if (sample_above_plane) {
cloud.sampleAbovePlane();
}
// Detect grasp affordances.
SequentialImportanceSampling detector(config_filename);
detector.detectGrasps(cloud);
return 0;
}
} // namespace detect_grasps
} // namespace apps
} // namespace gpd
int main(int argc, char *argv[]) {
return gpd::apps::detect_grasps::DoMain(argc, argv);
}