43 #include <ompl/geometric/planners/rrt/RRT.h> 44 #include <ompl/geometric/planners/rrt/pRRT.h> 45 #include <ompl/geometric/planners/rrt/RRTConnect.h> 46 #include <ompl/geometric/planners/rrt/TRRT.h> 47 #include <ompl/geometric/planners/rrt/LazyRRT.h> 48 #include <ompl/geometric/planners/est/EST.h> 49 #include <ompl/geometric/planners/sbl/SBL.h> 50 #include <ompl/geometric/planners/sbl/pSBL.h> 51 #include <ompl/geometric/planners/kpiece/KPIECE1.h> 52 #include <ompl/geometric/planners/kpiece/BKPIECE1.h> 53 #include <ompl/geometric/planners/kpiece/LBKPIECE1.h> 54 #include <ompl/geometric/planners/rrt/RRTstar.h> 55 #include <ompl/geometric/planners/prm/PRM.h> 56 #include <ompl/geometric/planners/prm/PRMstar.h> 57 #include <ompl/geometric/planners/fmt/FMT.h> 58 #include <ompl/geometric/planners/fmt/BFMT.h> 59 #include <ompl/geometric/planners/pdst/PDST.h> 60 #include <ompl/geometric/planners/stride/STRIDE.h> 61 #include <ompl/geometric/planners/rrt/BiTRRT.h> 62 #include <ompl/geometric/planners/rrt/LBTRRT.h> 63 #include <ompl/geometric/planners/est/BiEST.h> 64 #include <ompl/geometric/planners/est/ProjEST.h> 65 #include <ompl/geometric/planners/prm/LazyPRM.h> 66 #include <ompl/geometric/planners/prm/LazyPRMstar.h> 67 #include <ompl/geometric/planners/prm/SPARS.h> 68 #include <ompl/geometric/planners/prm/SPARStwo.h> 81 boost::mutex::scoped_lock slock(
lock_);
85 void setContext(
const ModelBasedPlanningContextPtr& context)
87 boost::mutex::scoped_lock slock(
lock_);
93 boost::mutex::scoped_lock slock(
lock_);
105 std::map<std::pair<std::string, std::string>, std::vector<ModelBasedPlanningContextPtr> >
contexts_;
112 const robot_model::RobotModelConstPtr& kmodel,
const constraint_samplers::ConstraintSamplerManagerPtr& csm)
136 template <
typename T>
137 static ompl::base::PlannerPtr allocatePlanner(
const ob::SpaceInformationPtr& si,
const std::string& new_name,
140 ompl::base::PlannerPtr planner(
new T(si));
141 if (!new_name.empty())
142 planner->setName(new_name);
143 planner->params().setParams(spec.
config_,
true);
152 std::map<std::string, ConfiguredPlannerAllocator>::const_iterator it =
known_planners_.find(planner);
157 ROS_ERROR_NAMED(
"planning_context_manager",
"Unknown planner: '%s'", planner.c_str());
208 const std::string& config,
const std::string& factory_type)
const 210 planning_interface::PlannerConfigurationMap::const_iterator pc =
planner_configs_.find(config);
214 moveit_msgs::MotionPlanRequest req;
220 ROS_ERROR_NAMED(
"planning_context_manager",
"Planning configuration '%s' was not found", config.c_str());
221 return ModelBasedPlanningContextPtr();
229 const ompl_interface::ModelBasedStateSpaceFactoryPtr& factory = factory_selector(config.
group);
232 ModelBasedPlanningContextPtr context;
236 std::map<std::pair<std::string, std::string>, std::vector<ModelBasedPlanningContextPtr> >::const_iterator cc =
240 for (std::size_t i = 0; i < cc->second.size(); ++i)
241 if (cc->second[i].unique())
243 ROS_DEBUG_NAMED(
"planning_context_manager",
"Reusing cached planning context");
244 context = cc->second[i];
258 context_spec.
state_space_ = factory->getNewStateSpace(space_spec);
263 bool state_validity_cache =
true;
264 if (config.
config.find(
"subspaces") != config.
config.end())
266 context_spec.
config_.erase(
"subspaces");
268 state_validity_cache =
false;
269 boost::char_separator<char> sep(
" ");
270 boost::tokenizer<boost::char_separator<char> > tok(config.
config.at(
"subspaces"), sep);
271 for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin(); beg != tok.end(); ++beg)
273 const ompl_interface::ModelBasedStateSpaceFactoryPtr& sub_fact = factory_selector(*beg);
277 context_spec.
subspaces_.push_back(sub_fact->getNewStateSpace(sub_space_spec));
282 ROS_DEBUG_NAMED(
"planning_context_manager",
"Creating new planning context");
284 context->useStateValidityCache(state_validity_cache);
287 cached_contexts_->contexts_[std::make_pair(config.
name, factory->getType())].push_back(context);
299 context->setSpecificationConfig(config.
config);
306 const std::string& ,
const std::string& factory_type)
const 308 std::map<std::string, ModelBasedStateSpaceFactoryPtr>::const_iterator
f =
314 ROS_ERROR_NAMED(
"planning_context_manager",
"Factory of type '%s' was not found", factory_type.c_str());
315 static const ModelBasedStateSpaceFactoryPtr empty;
321 const std::string& group,
const moveit_msgs::MotionPlanRequest& req)
const 324 std::map<std::string, ModelBasedStateSpaceFactoryPtr>::const_iterator best =
state_space_factories_.end();
325 int prev_priority = -1;
326 for (std::map<std::string, ModelBasedStateSpaceFactoryPtr>::const_iterator it =
state_space_factories_.begin();
329 int priority = it->second->canRepresentProblem(group, req,
kmodel_);
334 prev_priority = priority;
340 ROS_ERROR_NAMED(
"planning_context_manager",
"There are no known state spaces that can represent the given planning " 342 static const ModelBasedStateSpaceFactoryPtr empty;
347 ROS_DEBUG_NAMED(
"planning_context_manager",
"Using '%s' parameterization for solving problem", best->first.c_str());
352 ompl_interface::ModelBasedPlanningContextPtr
354 const moveit_msgs::MotionPlanRequest& req,
355 moveit_msgs::MoveItErrorCodes& error_code)
const 357 if (req.group_name.empty())
359 ROS_ERROR_NAMED(
"planning_context_manager",
"No group specified to plan for");
360 error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME;
361 return ModelBasedPlanningContextPtr();
364 error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
368 ROS_ERROR_NAMED(
"planning_context_manager",
"No planning scene supplied as input");
369 return ModelBasedPlanningContextPtr();
373 planning_interface::PlannerConfigurationMap::const_iterator pc =
planner_configs_.end();
374 if (!req.planner_id.empty())
376 pc =
planner_configs_.find(req.planner_id.find(req.group_name) == std::string::npos ?
377 req.group_name +
"[" + req.planner_id +
"]" :
381 "Cannot find planning configuration for group '%s' using planner '%s'. Will use defaults instead.",
382 req.group_name.c_str(), req.planner_id.c_str());
390 ROS_ERROR_NAMED(
"planning_context_manager",
"Cannot find planning configuration for group '%s'",
391 req.group_name.c_str());
392 return ModelBasedPlanningContextPtr();
404 std::map<std::string, std::string>::const_iterator it = pc->second.config.find(
"enforce_joint_model_state_space");
406 if (it != pc->second.config.end() && boost::lexical_cast<
bool>(it->second))
412 ModelBasedPlanningContextPtr context =
getPlanningContext(pc->second, factory_selector, req);
418 robot_state::RobotStatePtr start_state = planning_scene->getCurrentStateUpdated(req.start_state);
421 context->setPlanningScene(planning_scene);
422 context->setMotionPlanRequest(req);
423 context->setCompleteInitialState(*start_state);
425 context->setPlanningVolume(req.workspace_parameters);
426 if (!context->setPathConstraints(req.path_constraints, &error_code))
427 return ModelBasedPlanningContextPtr();
429 if (!context->setGoalConstraints(req.goal_constraints, req.path_constraints, &error_code))
430 return ModelBasedPlanningContextPtr();
434 context->configure();
435 ROS_DEBUG_NAMED(
"planning_context_manager",
"%s: New planning context is set.", context->getName().c_str());
436 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
438 catch (ompl::Exception& ex)
440 ROS_ERROR_NAMED(
"planning_context_manager",
"OMPL encountered an error: %s", ex.what());
boost::function< ConfiguredPlannerAllocator(const std::string &planner_type)> ConfiguredPlannerSelector
ModelBasedStateSpacePtr state_space_
robot_model::RobotModelConstPtr kmodel_
The kinematic model for which motion plans are computed.
ModelBasedPlanningContextPtr getPlanningContext(const std::string &config, const std::string &factory_type="") const
#define ROS_WARN_NAMED(name,...)
void setContext(const ModelBasedPlanningContextPtr &context)
static const std::string PARAMETERIZATION_TYPE
ModelBasedPlanningContextPtr last_planning_context_solve_
og::SimpleSetupPtr ompl_simple_setup_
double max_solution_segment_length_
std::map< std::string, PlannerConfigurationSettings > PlannerConfigurationMap
std::map< std::pair< std::string, std::string >, std::vector< ModelBasedPlanningContextPtr > > contexts_
std::map< std::string, std::string > config
CachedContextsPtr cached_contexts_
The MoveIt! interface to OMPL.
PlanningContextManager(const robot_model::RobotModelConstPtr &kmodel, const constraint_samplers::ConstraintSamplerManagerPtr &csm)
std::map< std::string, ModelBasedStateSpaceFactoryPtr > state_space_factories_
const ModelBasedStateSpaceFactoryPtr & getStateSpaceFactory2(const std::string &group_name, const moveit_msgs::MotionPlanRequest &req) const
ModelBasedPlanningContextPtr getContext()
void registerDefaultStateSpaces()
unsigned int minimum_waypoint_count_
#define ROS_DEBUG_NAMED(name,...)
boost::function< ob::PlannerPtr(const ompl::base::SpaceInformationPtr &si, const std::string &name, const ModelBasedPlanningContextSpecification &spec)> ConfiguredPlannerAllocator
unsigned int max_state_sampling_attempts_
ConfiguredPlannerSelector getPlannerSelector() const
void registerPlannerAllocator(const std::string &planner_id, const ConfiguredPlannerAllocator &pa)
constraint_samplers::ConstraintSamplerManagerPtr constraint_sampler_manager_
planning_interface::PlannerConfigurationMap planner_configs_
All the existing planning configurations. The name of the configuration is the key of the map...
unsigned int max_planning_threads_
when planning in parallel, this is the maximum number of threads to use at one time ...
ConfiguredPlannerSelector planner_selector_
ConfiguredPlannerAllocator plannerSelector(const std::string &planner) const
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap &pconfig)
Specify configurations for the planners.
unsigned int max_goal_sampling_attempts_
maximum number of attempts to be made at sampling goals
void registerDefaultPlanners()
constraint_samplers::ConstraintSamplerManagerPtr constraint_sampler_manager_
void registerStateSpaceFactory(const ModelBasedStateSpaceFactoryPtr &factory)
const ModelBasedStateSpaceFactoryPtr & getStateSpaceFactory1(const std::string &group_name, const std::string &factory_type) const
unsigned int max_goal_samples_
maximum number of states to sample in the goal region for any planning request (when such sampling is...
#define ROS_ERROR_NAMED(name,...)
ModelBasedPlanningContextPtr getLastPlanningContext() const
LastPlanningContextPtr last_planning_context_
boost::function< const ModelBasedStateSpaceFactoryPtr &(const std::string &)> StateSpaceFactoryTypeSelector
std::map< std::string, ConfiguredPlannerAllocator > known_planners_
std::map< std::string, std::string > config_
std::vector< ModelBasedStateSpacePtr > subspaces_
~PlanningContextManager()