-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsimple_planning_tutorial.cpp
More file actions
116 lines (91 loc) · 4.21 KB
/
simple_planning_tutorial.cpp
File metadata and controls
116 lines (91 loc) · 4.21 KB
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
#ifdef DOXYGEN_SHOULD_SKIP_THIS
/**
Tutorial for running the graspit planner on a given graspit world
Copyright (C) 2016 Jennifer Buehler
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#endif // DOXYGEN_SHOULD_SKIP_THIS
#include <grasp_planning_graspit/GraspItSceneManagerHeadless.h>
#include <grasp_planning_graspit/EigenGraspPlanner.h>
#include <grasp_planning_graspit/EigenGraspResult.h>
#include <string>
#include <vector>
/**
* \brief Tutorial on how to load a world and run the Eigengrasp planner.
*/
int main(int argc, char **argv)
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <world-filename> <output-directory>" << std::endl;
return 1;
}
std::string worldFilename = argv[1];
std::string outputDirectory = argv[2];
if (worldFilename.empty())
{
std::cerr << "You have to specify a world" << std::endl;
return 1;
}
// Create the graspit world manager.
SHARED_PTR<GraspIt::GraspItSceneManager> graspitMgr(new GraspIt::GraspItSceneManagerHeadless());
// Load the graspit world
graspitMgr->loadWorld(worldFilename);
// if the output directory does not exist yet, create it?
bool createDir = true;
// in case one wants to view the initial world before planning, save it:
graspitMgr->saveGraspItWorld(outputDirectory + "/worlds/startWorld.xml", createDir);
graspitMgr->saveInventorWorld(outputDirectory + "/worlds/startWorld.iv", createDir);
// Create the planner which accesses the graspit world.
std::string name = "EigenGraspPlanner1";
SHARED_PTR<GraspIt::EigenGraspPlanner> planner(new GraspIt::EigenGraspPlanner(name, graspitMgr));
// Number of iterations for the planning algorithm
int maxPlanningSteps = 70000;
// Number of times to repeat the planning process
int repeatPlanning = 1;
// Maximum number of planning results to keep (of each planning repeat)
int keepMaxPlanningResults = 3;
// Finalize each planning result with an "auto-grasp" to ensure there really are
// contacts between fingers and objects (sometimes, the grasp result is just very
// close to the object, but not really touching it).
bool finishWithAutograsp = false;
// By default, the last robot loaded and the last object loaded are to be used as the hand and the
// object to grasp for the planning process. You can use the other EigenGraspPlanner::plan()
// method with more parameters to change this.
if (!planner->plan(maxPlanningSteps, repeatPlanning, keepMaxPlanningResults, finishWithAutograsp))
{
std::cerr << "Error doing the planning." << std::endl;
return 1;
}
// Now, save the results as world files.
// specify where you want to save them:
std::string resultsWorldDirectory = outputDirectory + "/worlds";
// each result file will start with this prefix:
std::string filenamePrefix = "world";
// specify to save as inventor files:
bool saveInventor = true;
// specify to save as graspit world files:
bool saveGraspit = true;
// Now, save the results.
planner->saveResultsAsWorldFiles(resultsWorldDirectory, filenamePrefix, saveGraspit, saveInventor, createDir);
// Iterate through all results and print information about the grasps:
std::vector<GraspIt::EigenGraspResult> allGrasps;
planner->getResults(allGrasps);
std::cout << "Grasp results:" << std::endl;
std::vector<GraspIt::EigenGraspResult>::iterator it;
for (it = allGrasps.begin(); it != allGrasps.end(); ++it)
{
std::cout << *it << std::endl;;
}
return 0;
}