Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
OMPLPlanner.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ompl/base/SpaceInformation.h>
4#include <ompl/base/objectives/MaximizeMinClearanceObjective.h>
5#include <ompl/base/objectives/PathLengthOptimizationObjective.h>
6#include <ompl/base/objectives/StateCostIntegralObjective.h>
7#include <ompl/base/spaces/DubinsStateSpace.h>
8#include <ompl/base/spaces/RealVectorStateSpace.h>
9#include <ompl/base/spaces/ReedsSheppStateSpace.h>
10#include <ompl/base/spaces/SE2StateSpace.h>
11#include <ompl/geometric/PathGeometric.h>
12#include <ompl/geometric/PathSimplifier.h>
13#include <ompl/geometric/SimpleSetup.h>
14
15#include <ompl/control/planners/est/EST.h>
16#include <ompl/control/planners/kpiece/KPIECE1.h>
17#include <ompl/control/planners/pdst/PDST.h>
18#include <ompl/control/planners/rrt/RRT.h>
19#include <ompl/control/planners/sst/SST.h>
20
21#include <ompl/geometric/planners/informedtrees/BITstar.h>
22#include <ompl/geometric/planners/cforest/CForest.h>
23#include <ompl/geometric/planners/est/EST.h>
24#include <ompl/geometric/planners/fmt/BFMT.h>
25#include <ompl/geometric/planners/fmt/FMT.h>
26#include <ompl/geometric/planners/kpiece/KPIECE1.h>
27#include <ompl/geometric/planners/pdst/PDST.h>
28#include <ompl/geometric/planners/prm/PRMstar.h>
29#include <ompl/geometric/planners/prm/SPARS.h>
30#include <ompl/geometric/planners/prm/SPARStwo.h>
31#include <ompl/geometric/planners/rrt/InformedRRTstar.h>
32#include <ompl/geometric/planners/rrt/RRT.h>
33#include <ompl/geometric/planners/rrt/RRTsharp.h>
34#include <ompl/geometric/planners/rrt/RRTstar.h>
35#include <ompl/geometric/planners/rrt/SORRTstar.h>
36#include <ompl/geometric/planners/sbl/SBL.h>
37#include <ompl/geometric/planners/sst/SST.h>
38#include <ompl/geometric/planners/stride/STRIDE.h>
39
40#include <memory>
41
45#include "utils/Stopwatch.hpp"
46
47namespace ob = ompl::base;
48namespace og = ompl::geometric;
49namespace oc = ompl::control;
50
51template <class PLANNER>
53 public:
55 _omplPlanner = ob::PlannerPtr(new PLANNER(ss->getSpaceInformation()));
57 }
58
59 ob::PlannerStatus run() override {
61
62 ss->setPlanner(_omplPlanner);
63 ss->setup();
64
65 Stopwatch watch;
66 auto problem = _omplPlanner->getProblemDefinition();
67 problem->setIntermediateSolutionCallback(
68 [&](const ob::Planner *planner,
69 const std::vector<const ob::State *> &states, const ob::Cost cost) {
70 og::PathGeometric solution(global::settings.ompl.space_info);
71 // the OMPL intermediary solution doesn't include the start state
72 solution.append(global::settings.environment->startState());
73 for (const auto *state : states) solution.append(state);
74 // the OMPL intermediary solution doesn't include the goal state
75 solution.append(global::settings.environment->goalState());
76 IntermediarySolution is(watch.elapsed(), cost.value(), solution);
77 intermediarySolutions.emplace_back(is);
78 });
79
80 watch.start();
81 auto solved = ss->solve(global::settings.max_planning_time);
82 OMPL_INFORM("OMPL %s planning status: %s", _omplPlanner->getName().c_str(),
83 solved.asString().c_str());
84
85 if (solved) {
86 // Output the length of the path found
87 _solution.clear();
88 _solution.append(global::settings.environment->startState());
89 const auto &path = ss->getSolutionPath();
90 for (std::size_t i = 0; i < path.getStateCount(); ++i) {
91 _solution.append(path.getState(i));
92 }
93
94 OMPL_INFORM(
95 "%s found a solution of length %f with an optimization objective "
96 "value of %f",
97 _omplPlanner->getName().c_str(), _solution.length(),
98 _solution.cost(ss->getOptimizationObjective()));
99 } else
100 OMPL_WARN("No solution found.");
101 return solved;
102 }
103
104 std::string name() const override { return _omplPlanner->getName(); }
105
106 og::PathGeometric solution() const override {
107 og::PathGeometric path(_solution);
108 return og::PathGeometric(_solution);
109 }
110
111 bool hasReachedGoalExactly() const override {
112 return ss->haveExactSolutionPath();
113 }
114
115 double planningTime() const override {
116 return ss->getLastPlanComputationTime();
117 }
118
119 ob::Planner *omplPlanner() override { return _omplPlanner.get(); }
120
121 virtual nlohmann::json getSettings() const override {
122 nlohmann::json settings;
123 const auto &param_map = _omplPlanner->params().getParams();
124 for (const auto &[key, value_ptr] : param_map) {
125 settings[key] = value_ptr->getValue();
126 }
127 return settings;
128 }
129
130 private:
131 ob::PlannerPtr _omplPlanner;
132 og::PathGeometric _solution{global::settings.ompl.space_info};
133};
134
135// geometry space
OMPLPlanner< og::EST > ESTPlanner
Definition: OMPLPlanner.hpp:149
OMPLPlanner< og::SORRTstar > SORRTstarPlanner
Definition: OMPLPlanner.hpp:141
OMPLPlanner< og::PRMstar > PRMstarPlanner
Definition: OMPLPlanner.hpp:147
OMPLPlanner< og::PDST > PDSTPlanner
Definition: OMPLPlanner.hpp:154
OMPLPlanner< og::STRIDE > STRIDEPlanner
Definition: OMPLPlanner.hpp:151
OMPLPlanner< og::KPIECE1 > KPIECEPlanner
Definition: OMPLPlanner.hpp:150
OMPLPlanner< og::SPARS > SPARSPlanner
Definition: OMPLPlanner.hpp:152
OMPLPlanner< og::PRM > PRMPlanner
Definition: OMPLPlanner.hpp:145
OMPLPlanner< og::InformedRRTstar > InformedRRTstarPlanner
Definition: OMPLPlanner.hpp:140
OMPLPlanner< og::SPARStwo > SPARS2Planner
Definition: OMPLPlanner.hpp:153
OMPLPlanner< og::RRT > RRTPlanner
Definition: OMPLPlanner.hpp:136
OMPLPlanner< og::BFMT > BFMTPlanner
Definition: OMPLPlanner.hpp:144
OMPLPlanner< og::SST > SSTPlanner
Definition: OMPLPlanner.hpp:137
OMPLPlanner< og::RRTstar > RRTstarPlanner
Definition: OMPLPlanner.hpp:138
OMPLPlanner< og::SBL > SBLPlanner
Definition: OMPLPlanner.hpp:146
OMPLPlanner< og::BITstar > BITstarPlanner
Definition: OMPLPlanner.hpp:142
OMPLPlanner< og::RRTsharp > RRTsharpPlanner
Definition: OMPLPlanner.hpp:139
OMPLPlanner< og::CForest > CForestPlanner
Definition: OMPLPlanner.hpp:148
OMPLPlanner< og::FMT > FMTPlanner
Definition: OMPLPlanner.hpp:143
Definition: AbstractPlanner.h:29
std::vector< IntermediarySolution > intermediarySolutions
Definition: AbstractPlanner.h:56
og::SimpleSetup * ss
Definition: AbstractPlanner.h:114
static std::string LastCreatedPlannerName
Stores the name of the planner created last.
Definition: AbstractPlanner.h:38
Definition: OMPLPlanner.hpp:52
double planningTime() const override
Definition: OMPLPlanner.hpp:115
ob::Planner * omplPlanner() override
Definition: OMPLPlanner.hpp:119
virtual nlohmann::json getSettings() const override
Definition: OMPLPlanner.hpp:121
OMPLPlanner()
Definition: OMPLPlanner.hpp:54
std::string name() const override
Definition: OMPLPlanner.hpp:104
ob::PlannerStatus run() override
Definition: OMPLPlanner.hpp:59
og::PathGeometric solution() const override
Returns the solution of the planner, which is a sparse PathGeometric.
Definition: OMPLPlanner.hpp:106
bool hasReachedGoalExactly() const override
Definition: OMPLPlanner.hpp:111
Stopwatch implementation to measure elapsed time.
Definition: Stopwatch.hpp:8
void start()
Starts the timer.
Definition: Stopwatch.hpp:15
double elapsed() const
Elapsed time in seconds.
Definition: Stopwatch.hpp:41
Planner
Definition: PlannerSettings.h:16
Definition: AbstractPlanner.h:47
ompl::base::SpaceInformationPtr space_info
Definition: PlannerSettings.h:407
PlannerSettings::GlobalSettings::OmplSettings ompl
static PlannerSettings::GlobalSettings settings
Definition: PlannerSettings.h:699