Loading...
Searching...
No Matches
CForestCircleGridBenchmark.cpp
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2014, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Javier V. Gomez, Mark Moll */
36
37#include <ompl/base/spaces/DubinsStateSpace.h>
38#include <ompl/base/spaces/ReedsSheppStateSpace.h>
39#include <ompl/geometric/planners/rrt/RRTstar.h>
40#include <ompl/geometric/planners/cforest/CForest.h>
41#include <ompl/base/objectives/PathLengthOptimizationObjective.h>
42#include <ompl/geometric/SimpleSetup.h>
43#include <ompl/tools/benchmark/Benchmark.h>
44#include <boost/program_options.hpp>
45
46namespace ob = ompl::base;
47namespace og = ompl::geometric;
48namespace ot = ompl::tools;
49namespace po = boost::program_options;
50
51bool isStateValid(double radiusSquared, const ob::State *state)
52{
53 const auto *s = state->as<ob::SE2StateSpace::StateType>();
54 double x = s->getX(), y = s->getY();
55 x = std::abs(x - std::floor(x));
56 y = std::abs(y - std::floor(y));
57 x = std::min(x, 1. - x);
58 y = std::min(y, 1. - y);
59 return x * x + y * y > radiusSquared;
60}
61
62int main(int argc, char **argv)
63{
64 int distance, gridLimit, runCount;
65 double obstacleRadius, turningRadius, runtimeLimit;
66
67 auto space(std::make_shared<ob::SE2StateSpace>());
68
69 po::options_description desc("Options");
70
71 desc.add_options()("help", "show help message")("dubins", "use Dubins state space")(
72 "dubinssym", "use symmetrized Dubins state space")("reedsshepp", "use Reeds-Shepp state space")(
73 "distance", po::value<int>(&distance)->default_value(3), "integer grid distance between start and goal")(
74 "obstacle-radius", po::value<double>(&obstacleRadius)->default_value(.25),
75 "radius of obstacles")("turning-radius", po::value<double>(&turningRadius)->default_value(.5),
76 "turning radius of robot (ignored for default point robot)")(
77 "grid-limit", po::value<int>(&gridLimit)->default_value(10), "size of the grid")(
78 "runtime-limit", po::value<double>(&runtimeLimit)->default_value(2), "time limit for every test")(
79 "run-count", po::value<int>(&runCount)->default_value(100), "number of times to run each planner");
80
81 po::variables_map vm;
82 po::store(po::parse_command_line(argc, argv, desc), vm);
83 po::notify(vm);
84
85 if (vm.count("help") != 0u)
86 {
87 std::cout << desc << "\n";
88 return 1;
89 }
90
91 if (vm.count("dubins") != 0u)
92 space = std::make_shared<ob::DubinsStateSpace>(turningRadius);
93 if (vm.count("dubinssym") != 0u)
94 space = std::make_shared<ob::DubinsStateSpace>(turningRadius, true);
95 if (vm.count("reedsshepp") != 0u)
96 space = std::make_shared<ob::ReedsSheppStateSpace>(turningRadius);
97
98 // set the bounds for the R^2 part of SE(2)
99 ob::RealVectorBounds bounds(2);
100 bounds.setLow(-.5 * gridLimit);
101 bounds.setHigh(.5 * gridLimit);
102 space->setBounds(bounds);
103
104 // define a simple setup class
105 og::SimpleSetup ss(space);
106
107 // set state validity checking for this space
108 double radiusSquared = obstacleRadius * obstacleRadius;
109 ss.setStateValidityChecker([radiusSquared](const ob::State *state) { return isStateValid(radiusSquared, state); });
110
111 // define start & goal states
112 ob::ScopedState<ob::SE2StateSpace> start(space), goal(space);
113 start->setXY(0., 0.5);
114 start->setYaw(0.);
115 goal->setXY(0., (double)distance + .5);
116 goal->setYaw(0);
117 ss.setStartAndGoalStates(start, goal);
118
119 // setting collision checking resolution to 0.05 (absolute)
120 ss.getSpaceInformation()->setStateValidityCheckingResolution(0.05 / gridLimit);
121 ss.getProblemDefinition()->setOptimizationObjective(
122 std::make_shared<ompl::base::PathLengthOptimizationObjective>(ss.getSpaceInformation()));
123
124 // by default, use the Benchmark class
125 double memoryLimit = 4096;
126 ot::Benchmark::Request request(runtimeLimit, memoryLimit, runCount);
127 ot::Benchmark b(ss, "CircleGrid");
128
129 b.addPlanner(std::make_shared<og::RRTstar>(ss.getSpaceInformation()));
130 b.addPlanner(std::make_shared<og::CForest>(ss.getSpaceInformation()));
131 b.benchmark(request);
132 b.saveResultsToFile("circleGrid.log");
133
134 exit(0);
135}
The lower and upper bounds for an Rn space.
A state in SE(2): (x, y, yaw).
Definition of a scoped state.
Definition ScopedState.h:57
Definition of an abstract state.
Definition State.h:50
const T * as() const
Cast this instance to a desired type.
Definition State.h:66
Create the set of classes typically needed to solve a geometric problem.
Definition SimpleSetup.h:63
Benchmark a set of planners on a problem instance.
Definition Benchmark.h:49
This namespace contains sampling based planning routines shared by both planning under geometric cons...
This namespace contains code that is specific to planning under geometric constraints.
Includes various tools such as self config, benchmarking, etc.
Representation of a benchmark request.
Definition Benchmark.h:152