7#include <boost/program_options.hpp>
10#include <ompl/base/PlannerTerminationCondition.h>
11#include <ompl/base/ProblemDefinition.h>
12#include <ompl/base/SpaceInformation.h>
13#include <ompl/base/spaces/RealVectorStateSpace.h>
14#include <ompl/geometric/SimpleSetup.h>
17#include <ompl/geometric/planners/rrt/RRTConnect.h>
18#include <ompl/geometric/planners/rrt/RRT.h>
19#include <ompl/geometric/planners/kpiece/KPIECE1.h>
20#include <ompl/geometric/planners/kpiece/LBKPIECE1.h>
23#include <ompl/tools/benchmark/Benchmark.h>
26#include <ompl/vamp/Utils.h>
27#include <ompl/vamp/VampStateValidityChecker.h>
28#include <ompl/vamp/VampMotionValidator.h>
29#include <ompl/vamp/VampStateSpace.h>
31#include <vamp/collision/factory.hh>
32#include <vamp/robots/panda.hh>
37namespace po = boost::program_options;
39using Robot = vamp::robots::Panda;
40using Environment = vamp::collision::Environment<vamp::FloatVector<vamp::FloatVectorWidth>>;
43std::vector<std::array<float, 3>> obstacles = {
44 {0.55, 0, 0.25}, {0.35, 0.35, 0.25}, {0, 0.55, 0.25}, {-0.55, 0, 0.25}, {-0.35, -0.35, 0.25},
45 {0, -0.55, 0.25}, {0.35, -0.35, 0.25}, {0.35, 0.35, 0.8}, {0, 0.55, 0.8}, {-0.35, 0.35, 0.8},
46 {-0.55, 0, 0.8}, {-0.35, -0.35, 0.8}, {0, -0.55, 0.8}, {0.35, -0.35, 0.8},
52 vamp::collision::Environment<float> env_float;
54 constexpr float radius = 0.2f;
55 for (
const auto &obs : obstacles)
57 env_float.spheres.emplace_back(vamp::collision::factory::sphere::array(obs, radius));
62 Environment env(env_float);
65 auto space = std::make_shared<ompl::vamp::VampStateSpace<Robot>>();
68 std::cout <<
"Robot bounds:" << std::endl;
69 for (std::size_t i = 0; i < Robot::dimension; ++i)
71 std::cout << i <<
": " << space->getBounds().low[i] <<
" to " << space->getBounds().high[i] << std::endl;
77 auto si = ss.getSpaceInformation();
87 std::array<double, 7> start_config = {0., -0.785, 0., -2.356, 0., 1.571, 0.785};
88 std::array<double, 7> goal_config = {2.35, 1., 0., -0.8, 0., 2.5, 0.785};
90 for (std::size_t i = 0; i < Robot::dimension; ++i)
92 start[i] = start_config[i];
93 goal[i] = goal_config[i];
97 auto planner = std::make_shared<og::RRTConnect>(si);
98 ss.setPlanner(planner);
101 ss.setStartAndGoalStates(start, goal);
104 auto start_time = std::chrono::steady_clock::now();
106 auto end_time = std::chrono::steady_clock::now();
108 auto duration_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count();
109 auto duration_ms = duration_ns / 1e6;
110 std::cout <<
"Planning time: " << duration_ms <<
" ms" << std::endl;
114 std::cout <<
"Found solution!" << std::endl;
115 auto path = ss.getSolutionPath();
116 std::cout <<
"Path has " << path.getStateCount() <<
" states" << std::endl;
117 path.print(std::cout);
121 std::cout <<
"No solution found" << std::endl;
125void planBenchmark(
int runCount = 100)
128 vamp::collision::Environment<float> env_float;
130 constexpr float radius = 0.2f;
131 for (
const auto &obs : obstacles)
133 env_float.spheres.emplace_back(vamp::collision::factory::sphere::array(obs, radius));
138 Environment env(env_float);
141 auto space = std::make_shared<ompl::vamp::VampStateSpace<Robot>>();
143 std::cout <<
"Robot bounds:" << std::endl;
144 for (std::size_t i = 0; i < Robot::dimension; ++i)
146 std::cout << i <<
": " << space->getBounds().low[i] <<
" to " << space->getBounds().high[i] << std::endl;
152 auto si = ss.getSpaceInformation();
161 std::array<double, 7> start_config = {0., -0.785, 0., -2.356, 0., 1.571, 0.785};
162 std::array<double, 7> goal_config = {2.35, 1., 0., -0.8, 0., 2.5, 0.785};
164 for (std::size_t i = 0; i < Robot::dimension; ++i)
166 start[i] = start_config[i];
167 goal[i] = goal_config[i];
171 ss.setStartAndGoalStates(start, goal);
174 double memoryLimit = 4096;
175 double runtimeLimit = 5.0;
179 b.addPlanner(std::make_shared<og::RRTConnect>(si));
180 b.addPlanner(std::make_shared<og::RRT>(si));
181 b.addPlanner(std::make_shared<og::KPIECE1>(si));
182 b.addPlanner(std::make_shared<og::LBKPIECE1>(si));
184 b.benchmark(request);
185 b.saveResultsToFile(
"vamp_cage_planning_benchmark_cpp.log");
188 std::cout <<
"Results saved to vamp_cage_planning_benchmark_cpp.log" << std::endl;
189 std::cout <<
"Use python script 'ompl/scripts/ompl_benchmark_statistics.py' to transfer .log to .db" << std::endl;
194int main(
int argc,
char **argv)
196 po::options_description desc(
"Options");
199 desc.add_options()(
"help",
"show help message")(
"benchmark", po::value<int>(&runCount)->default_value(0),
200 "Benchmark Planners for this number of trials");
201 po::variables_map vm;
202 po::store(po::parse_command_line(argc, argv, desc), vm);
205 if (vm.count(
"help"))
207 std::cout << desc << std::endl;
213 std::cout <<
"Running benchmark with " << runCount <<
" trials." << std::endl;
214 planBenchmark(runCount);
218 std::cout <<
"Running single planning instance." << std::endl;
Definition of a scoped state.
Create the set of classes typically needed to solve a geometric problem.
This namespace contains sampling based planning routines shared by both planning under geometric cons...
PlannerTerminationCondition timedPlannerTerminationCondition(double duration)
Return a termination condition that will become true duration seconds in the future (wall-time).
This namespace contains code that is specific to planning under geometric constraints.
A class to store the exit status of Planner::solve().
@ EXACT_SOLUTION
The planner found an exact solution.