37#include <ompl/base/spaces/DubinsStateSpace.h>
38#include <ompl/base/spaces/ReedsSheppStateSpace.h>
39#include <ompl/base/spaces/TrochoidStateSpace.h>
40#include <ompl/base/ScopedState.h>
41#include <ompl/geometric/SimpleSetup.h>
42#include <boost/program_options.hpp>
46namespace po = boost::program_options;
56 double x = s->getX(), y = s->getY();
57 return si->satisfiesBounds(s) && (x < 5 || x > 13 || (y > 8.5 && y < 9.5));
62 return si->satisfiesBounds(state);
65void plan(
const ob::StateSpacePtr &space,
bool easy)
84 auto isStateValid = easy ? isStateValidEasy : isStateValidHard;
90 start[0] = start[1] = 1.;
92 goal[0] = goal[1] = 17;
93 goal[2] = -.99 * boost::math::constants::pi<double>();
97 start[0] = start[1] = .5;
98 start[2] = .5 * boost::math::constants::pi<double>();
102 goal[2] = .5 * boost::math::constants::pi<double>();
104 ss.setStartAndGoalStates(start, goal);
107 ss.getSpaceInformation()->setStateValidityCheckingResolution(0.005);
116 std::vector<double> reals;
118 std::cout <<
"Found solution:" << std::endl;
119 ss.simplifySolution();
121 path.interpolate(1000);
122 path.printAsMatrix(std::cout);
125 std::cout <<
"No solution found" << std::endl;
128void printTrajectory(
const ob::StateSpacePtr &space,
const std::vector<double> &pt)
132 const unsigned int num_pts = 50;
134 std::vector<double> reals;
136 from[0] = from[1] = from[2] = 0.;
142 std::cout <<
"distance: " << space->distance(from(), to()) <<
"\npath:\n";
143 for (
unsigned int i = 0; i <= num_pts; ++i)
145 space->interpolate(from(), to(), (
double)i / num_pts, s());
147 std::cout <<
"path " << reals[0] <<
' ' << reals[1] <<
' ' << reals[2] <<
' ' << std::endl;
151void printDistanceGrid(
const ob::StateSpacePtr &space)
163 const unsigned int num_pts = 200;
165 from[0] = from[1] = from[2] = 0.;
167 for (
unsigned int i = 0; i < num_pts; ++i)
168 for (
unsigned int j = 0; j < num_pts; ++j)
169 for (
unsigned int k = 0; k < num_pts; ++k)
171 to[0] = 5. * (2. * (double)i / num_pts - 1.);
172 to[1] = 5. * (2. * (double)j / num_pts - 1.);
173 to[2] = boost::math::constants::pi<double>() * (2. * (double)k / num_pts - 1.);
174 std::cout << space->distance(from(), to()) <<
'\n';
178int main(
int argc,
char *argv[])
182 po::options_description desc(
"Options");
183 desc.add_options()(
"help",
"show help message")(
"dubins",
"use Dubins state space")(
184 "dubinssym",
"use symmetrized Dubins state space")(
185 "trochoid",
"use trochoid state space (default wind ratio: 0.3)")(
"reedsshepp",
186 "use Reeds-Shepp state space (default)")(
187 "easyplan",
"solve easy planning problem and print path")(
"hardplan",
188 "solve hard planning problem and print path")(
189 "trajectory", po::value<std::vector<double>>()->multitoken(),
190 "print trajectory from (0,0,0) to a user-specified x, y, and theta")(
"distance",
"print distance grid");
192 po::variables_map vm;
193 po::store(po::parse_command_line(argc, argv, desc,
194 po::command_line_style::unix_style ^ po::command_line_style::allow_short),
198 if ((vm.count(
"help") != 0u) || argc == 1)
200 std::cout << desc <<
"\n";
204 ob::StateSpacePtr space(std::make_shared<ob::ReedsSheppStateSpace>());
206 if (vm.count(
"dubins") != 0u)
207 space = std::make_shared<ob::DubinsStateSpace>();
208 if (vm.count(
"dubinssym") != 0u)
209 space = std::make_shared<ob::DubinsStateSpace>(1.,
true);
210 if (vm.count(
"trochoid") != 0u)
211 space = std::make_shared<ob::TrochoidStateSpace>(1., 0.3);
212 if (vm.count(
"easyplan") != 0u)
214 if (vm.count(
"hardplan") != 0u)
216 if (vm.count(
"trajectory") != 0u)
217 printTrajectory(space, vm[
"trajectory"].as<std::vector<double>>());
218 if (vm.count(
"distance") != 0u)
219 printDistanceGrid(space);
221 catch (std::exception &e)
223 std::cerr <<
"error: " << e.what() <<
"\n";
228 std::cerr <<
"Exception of unknown type!\n";
The exception type for ompl.
The lower and upper bounds for an Rn space.
A state in SE(2): (x, y, yaw).
A state space representing SE(2).
Definition of a scoped state.
Definition of an abstract state.
const T * as() const
Cast this instance to a desired type.
Definition of a geometric path.
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...
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.