37 #include <ompl/base/SpaceInformation.h> 38 #include <ompl/base/objectives/PathLengthOptimizationObjective.h> 39 #include <ompl/base/objectives/StateCostIntegralObjective.h> 40 #include <ompl/base/objectives/MaximizeMinClearanceObjective.h> 41 #include <ompl/base/spaces/RealVectorStateSpace.h> 46 #include <ompl/geometric/planners/bitstar/BITstar.h> 47 #include <ompl/geometric/planners/cforest/CForest.h> 48 #include <ompl/geometric/planners/fmt/FMT.h> 49 #include <ompl/geometric/planners/fmt/BFMT.h> 50 #include <ompl/geometric/planners/rrt/InformedRRTstar.h> 51 #include <ompl/geometric/planners/prm/PRMstar.h> 52 #include <ompl/geometric/planners/rrt/RRTstar.h> 56 #include <boost/program_options.hpp> 58 #include <boost/algorithm/string.hpp> 82 enum planningObjective
84 OBJECTIVE_PATHCLEARANCE,
86 OBJECTIVE_THRESHOLDPATHLENGTH,
87 OBJECTIVE_WEIGHTEDCOMBO
91 bool argParse(
int argc,
char** argv,
double *runTime, optimalPlanner *plannerPtr, planningObjective *objectivePtr, std::string *outputFilePtr);
101 ob::StateValidityChecker(si) {}
120 double x = state2D->values[0];
121 double y = state2D->values[1];
125 return sqrt((x-0.5)*(x-0.5) + (y-0.5)*(y-0.5)) - 0.25;
145 case PLANNER_BITSTAR:
147 return std::make_shared<og::BITstar>(si);
150 case PLANNER_CFOREST:
152 return std::make_shared<og::CForest>(si);
155 case PLANNER_FMTSTAR:
157 return std::make_shared<og::FMT>(si);
160 case PLANNER_BFMTSTAR:
162 return std::make_shared<og::BFMT>(si);
165 case PLANNER_INF_RRTSTAR:
167 return std::make_shared<og::InformedRRTstar>(si);
170 case PLANNER_PRMSTAR:
172 return std::make_shared<og::PRMstar>(si);
175 case PLANNER_RRTSTAR:
177 return std::make_shared<og::RRTstar>(si);
182 OMPL_ERROR(
"Planner-type enum is not implemented in allocation function.");
191 switch (objectiveType)
193 case OBJECTIVE_PATHCLEARANCE:
194 return getClearanceObjective(si);
196 case OBJECTIVE_PATHLENGTH:
197 return getPathLengthObjective(si);
199 case OBJECTIVE_THRESHOLDPATHLENGTH:
200 return getThresholdPathLengthObj(si);
202 case OBJECTIVE_WEIGHTEDCOMBO:
203 return getBalancedObjective1(si);
206 OMPL_ERROR(
"Optimization-objective enum is not implemented in allocation function.");
212 void plan(
double runTime, optimalPlanner plannerType, planningObjective objectiveType, std::string outputFile)
245 pdef->setStartAndGoalStates(start, goal);
249 pdef->setOptimizationObjective(allocateObjective(si, objectiveType));
253 ob::PlannerPtr optimizingPlanner = allocatePlanner(si, plannerType);
256 optimizingPlanner->setProblemDefinition(pdef);
257 optimizingPlanner->setup();
266 << optimizingPlanner->getName()
267 <<
" found a solution of length " 268 << pdef->getSolutionPath()->length()
269 <<
" with an optimization objective value of " 270 << pdef->getSolutionPath()->cost(pdef->getOptimizationObjective()) << std::endl;
274 if (!outputFile.empty())
276 std::ofstream outFile(outputFile.c_str());
278 printAsMatrix(outFile);
283 std::cout <<
"No solution found." << std::endl;
286 int main(
int argc,
char** argv)
290 optimalPlanner plannerType;
291 planningObjective objectiveType;
292 std::string outputFile;
295 if (argParse(argc, argv, &runTime, &plannerType, &objectiveType, &outputFile))
298 plan(runTime, plannerType, objectiveType, outputFile);
325 obj->setCostThreshold(
ob::Cost(1.51));
345 ob::StateCostIntegralObjective(si, true)
356 return ob::Cost(1 / si_->getStateValidityChecker()->clearance(s));
399 return 10.0*lengthObj + clearObj;
408 obj->setCostToGoHeuristic(&ob::goalRegionCostToGo);
413 bool argParse(
int argc,
char** argv,
double* runTimePtr, optimalPlanner *plannerPtr, planningObjective *objectivePtr, std::string *outputFilePtr)
415 namespace bpo = boost::program_options;
418 bpo::options_description desc(
"Allowed options");
420 (
"help,h",
"produce help message")
421 (
"runtime,t", bpo::value<double>()->default_value(1.0),
"(Optional) Specify the runtime in seconds. Defaults to 1 and must be greater than 0.")
422 (
"planner,p", bpo::value<std::string>()->default_value(
"RRTstar"),
"(Optional) Specify the optimal planner to use, defaults to RRTstar if not given. Valid options are BITstar, CForest, FMTstar, BFMTstar, InformedRRTstar, PRMstar, and RRTstar.")
423 (
"objective,o", bpo::value<std::string>()->default_value(
"PathLength"),
"(Optional) Specify the optimization objective, defaults to PathLength if not given. Valid options are PathClearance, PathLength, ThresholdPathLength, and WeightedLengthAndClearanceCombo.")
424 (
"file,f", bpo::value<std::string>()->default_value(
""),
"(Optional) Specify an output path for the found solution path.")
425 (
"info,i", bpo::value<unsigned int>()->default_value(0u),
"(Optional) Set the OMPL log level. 0 for WARN, 1 for INFO, 2 for DEBUG. Defaults to WARN.");
426 bpo::variables_map vm;
427 bpo::store(bpo::parse_command_line(argc, argv, desc), vm);
431 if (vm.count(
"help"))
433 std::cout << desc << std::endl;
438 unsigned int logLevel = vm[
"info"].as<
unsigned int>();
445 else if (logLevel == 1u)
449 else if (logLevel == 2u)
455 std::cout <<
"Invalid log-level integer." << std::endl << std::endl << desc << std::endl;
460 *runTimePtr = vm[
"runtime"].as<
double>();
463 if (*runTimePtr <= 0.0)
465 std::cout <<
"Invalid runtime." << std::endl << std::endl << desc << std::endl;
470 std::string plannerStr = vm[
"planner"].as<std::string>();
473 if (boost::iequals(
"BITstar", plannerStr))
475 *plannerPtr = PLANNER_BITSTAR;
477 else if (boost::iequals(
"CForest", plannerStr))
479 *plannerPtr = PLANNER_CFOREST;
481 else if (boost::iequals(
"FMTstar", plannerStr))
483 *plannerPtr = PLANNER_FMTSTAR;
485 else if (boost::iequals(
"BFMTstar", plannerStr))
487 *plannerPtr = PLANNER_BFMTSTAR;
489 else if (boost::iequals(
"InformedRRTstar", plannerStr))
491 *plannerPtr = PLANNER_INF_RRTSTAR;
493 else if (boost::iequals(
"PRMstar", plannerStr))
495 *plannerPtr = PLANNER_PRMSTAR;
497 else if (boost::iequals(
"RRTstar", plannerStr))
499 *plannerPtr = PLANNER_RRTSTAR;
503 std::cout <<
"Invalid planner string." << std::endl << std::endl << desc << std::endl;
508 std::string objectiveStr = vm[
"objective"].as<std::string>();
511 if (boost::iequals(
"PathClearance", objectiveStr))
513 *objectivePtr = OBJECTIVE_PATHCLEARANCE;
515 else if (boost::iequals(
"PathLength", objectiveStr))
517 *objectivePtr = OBJECTIVE_PATHLENGTH;
519 else if (boost::iequals(
"ThresholdPathLength", objectiveStr))
521 *objectivePtr = OBJECTIVE_THRESHOLDPATHLENGTH;
523 else if (boost::iequals(
"WeightedLengthAndClearanceCombo", objectiveStr))
525 *objectivePtr = OBJECTIVE_WEIGHTEDCOMBO;
529 std::cout <<
"Invalid objective string." << std::endl << std::endl << desc << std::endl;
534 *outputFilePtr = vm[
"file"].as<std::string>();
A shared pointer wrapper for ompl::base::ProblemDefinition.
This class allows for the definition of multiobjective optimal planning problems. Objectives are adde...
Definition of a scoped state.
A shared pointer wrapper for ompl::base::StateSpace.
void addObjective(const OptimizationObjectivePtr &objective, double weight)
Adds a new objective for this multiobjective. A weight must also be specified for specifying importan...
virtual double clearance(const State *) const
Report the distance to the nearest invalid state when starting from state. If the distance is negativ...
State StateType
Define the type of state allocated by this space.
A shared pointer wrapper for ompl::base::StateValidityChecker.
A shared pointer wrapper for ompl::base::Planner.
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
Defines optimization objectives where path cost can be represented as a path integral over a cost fun...
void setLogLevel(LogLevel level)
Set the minimum level of logging data to output. Messages with lower logging levels will not be recor...
Abstract definition for a class checking the validity of states. The implementation of this class mus...
A class to store the exit status of Planner::solve()
A state space representing Rn. The distance function is the L2 norm.
An optimization objective which corresponds to optimizing path length.
Definition of an abstract state.
This namespace contains sampling based planning routines shared by both planning under geometric cons...
virtual bool isValid(const State *state) const =0
Return true if the state state is valid. Usually, this means at least collision checking. If it is possible that ompl::base::StateSpace::interpolate() or ompl::control::ControlSpace::propagate() return states that are outside of bounds, this function should also make a call to ompl::base::SpaceInformation::satisfiesBounds().
Definition of a problem to be solved. This includes the start state(s) for the system and a goal spec...
A shared pointer wrapper for ompl::base::OptimizationObjective.
Definition of a geometric path.
const T * as() const
Cast this instance to a desired type.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
This namespace contains code that is specific to planning under geometric constraints.