Robowflex  v0.1
Making MoveIt Easy
robowflex::OMPL::OMPLInterfacePlanner Class Reference

A planner that directly uses MoveIt!'s OMPL planning interface. More...

#include <ompl_interface.h>

+ Inheritance diagram for robowflex::OMPL::OMPLInterfacePlanner:

Public Types

using PrePlanCallback = std::function< void(const ompl_interface::ModelBasedPlanningContextPtr &context, const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request)>
 Type for the callback function to be called right before planning takes place, when the planning context is available. More...
 
- Public Types inherited from robowflex::Planner
using ProgressProperty = std::function< std::string()>
 A function that returns the value of a planner property over the course of a run. More...
 

Public Member Functions

 OMPLInterfacePlanner (const RobotPtr &robot, const std::string &name="")
 Constructor. More...
 
 OMPLInterfacePlanner (OMPLInterfacePlanner const &)=delete
 
void operator= (OMPLInterfacePlanner const &)=delete
 
bool initialize (const std::string &config_file="", const OMPL::Settings settings=Settings())
 Initialize planning pipeline. More...
 
planning_interface::MotionPlanResponse plan (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
 Plan a motion given a request and a scene. Uses the planning pipeline's generatePlan() method, which goes through planning adapters. More...
 
ompl_interface::ModelBasedPlanningContextPtr getPlanningContext (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const
 Returns the planning context used for this motion planning request. More...
 
ompl::geometric::SimpleSetupPtr getLastSimpleSetup () const
 Get the last OMPL simple setup used in planning. More...
 
void refreshContext (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request, bool force=false) const
 Refreshes the internal planning context. More...
 
std::map< std::string, Planner::ProgressPropertygetProgressProperties (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const override
 Retrieve the planner progress property map for this planner given a specific request. More...
 
std::vector< std::stringgetPlannerConfigs () const override
 Return all planner configurations offered by this planner. Any of the configurations returned can be set as the planner for a motion planning query sent to plan(). More...
 
void preRun (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
 This function is called before benchmarking. More...
 
ompl_interface::OMPLInterface & getInterface () const
 Access the OMPLInterface directly, to customize the planning process. More...
 
void setPrePlanCallback (const PrePlanCallback &prePlanCallback)
 Set a callback, to be called right before a planning session for last-minute configuration or external bookkeeping. More...
 
- Public Member Functions inherited from robowflex::Planner
 Planner (const RobotPtr &robot, const std::string &name="")
 Constructor. Takes in a robot description and an optional namespace name. If name is specified, planner parameters are namespaced under the namespace of robot. More...
 
 Planner (Planner const &)=delete
 
void operator= (Planner const &)=delete
 
const RobotPtr getRobot () const
 Return the robot for this planner. More...
 
const std::stringgetName () const
 Get the name of the planner. More...
 

Private Attributes

std::unique_ptr< ompl_interface::OMPLInterface > interface_ {nullptr}
 Planning interface. More...
 
std::vector< std::stringconfigs_
 Planning configurations. More...
 
bool hybridize_
 Whether or not planner should hybridize solutions. More...
 
bool interpolate_
 Whether or not planner should interpolate solutions. More...
 
ID::Key last_scene_id_ {ID::getNullKey()}
 ID of last scene. More...
 
std::string last_request_hash_
 Hash of last request. More...
 
ompl_interface::ModelBasedPlanningContextPtr context_
 Last context. More...
 
ompl::geometric::SimpleSetupPtr ss_
 
PrePlanCallback pre_plan_callback_
 Callback to be called just before planning. More...
 

Additional Inherited Members

- Protected Attributes inherited from robowflex::Planner
RobotPtr robot_
 The robot to plan for. More...
 
IO::Handler handler_
 The parameter handler for the planner. More...
 
const std::string name_
 Namespace for the planner. More...
 

Detailed Description

A planner that directly uses MoveIt!'s OMPL planning interface.

Definition at line 34 of file ompl_interface.h.

Member Typedef Documentation

◆ PrePlanCallback

using robowflex::OMPL::OMPLInterfacePlanner::PrePlanCallback = std::function<void( const ompl_interface::ModelBasedPlanningContextPtr &context, const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request)>

Type for the callback function to be called right before planning takes place, when the planning context is available.

Parameters
[in]contextThe planning context, contains SimpleSetup that will be used.
[in]sceneThe planning scene being planned on.
[in]requestThe request to plan a path for.

Definition at line 106 of file ompl_interface.h.

Constructor & Destructor Documentation

◆ OMPLInterfacePlanner() [1/2]

OMPL::OMPLInterfacePlanner::OMPLInterfacePlanner ( const RobotPtr robot,
const std::string name = "" 
)

Constructor.

Parameters
[in]robotThe robot to plan for.
[in]nameOptional namespace for planner.

Definition at line 14 of file ompl_interface.cpp.

15  : Planner(robot, name)
16 {
17 }
Planner(const RobotPtr &robot, const std::string &name="")
Constructor. Takes in a robot description and an optional namespace name. If name is specified,...
Functions for loading and animating robots in Blender.

◆ OMPLInterfacePlanner() [2/2]

robowflex::OMPL::OMPLInterfacePlanner::OMPLInterfacePlanner ( OMPLInterfacePlanner const &  )
delete

Member Function Documentation

◆ getInterface()

ompl_interface::OMPLInterface & OMPL::OMPLInterfacePlanner::getInterface ( ) const

Access the OMPLInterface directly, to customize the planning process.

Definition at line 148 of file ompl_interface.cpp.

149 {
150  if (!interface_)
151  {
152  RBX_WARN("Interface is not initialized before call to OMPLInterfacePlanner::initialize.");
153  }
154  return *interface_;
155 }
std::unique_ptr< ompl_interface::OMPLInterface > interface_
Planning interface.
#define RBX_WARN(fmt,...)
Output a warning logging message.
Definition: log.h:110

◆ getLastSimpleSetup()

ompl::geometric::SimpleSetupPtr OMPL::OMPLInterfacePlanner::getLastSimpleSetup ( ) const

Get the last OMPL simple setup used in planning.

Returns
The last OMPL simple setup used.

Definition at line 138 of file ompl_interface.cpp.

139 {
140  return ss_;
141 }
ompl::geometric::SimpleSetupPtr ss_

◆ getPlannerConfigs()

std::vector< std::string > OMPL::OMPLInterfacePlanner::getPlannerConfigs ( ) const
overridevirtual

Return all planner configurations offered by this planner. Any of the configurations returned can be set as the planner for a motion planning query sent to plan().

Returns
A vector of strings of planner configuration names.

Implements robowflex::Planner.

Definition at line 143 of file ompl_interface.cpp.

144 {
145  return configs_;
146 }
std::vector< std::string > configs_
Planning configurations.

◆ getPlanningContext()

ompl_interface::ModelBasedPlanningContextPtr OMPL::OMPLInterfacePlanner::getPlanningContext ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
) const

Returns the planning context used for this motion planning request.

Parameters
[in]sceneA planning scene for the same robot_ to compute the plan in.
[in]requestThe motion planning request to solve.
Returns
The motion planning context used by the planner.

Definition at line 47 of file ompl_interface.cpp.

49 {
50  return interface_->getPlanningContext(scene->getSceneConst(), request);
51 }
Functions for loading and animating scenes in Blender.

◆ getProgressProperties()

std::map< std::string, Planner::ProgressProperty > OMPL::OMPLInterfacePlanner::getProgressProperties ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
) const
overridevirtual

Retrieve the planner progress property map for this planner given a specific request.

Parameters
[in]sceneA planning scene for the same robot_ to compute the plan in.
[in]requestRequest to get progress properties for.
Returns
The map of progress properties.

Reimplemented from robowflex::Planner.

Definition at line 76 of file ompl_interface.cpp.

78 {
79  refreshContext(scene, request);
80  if (not ss_)
81  return {};
82 
83  const auto &planner = ss_->getPlanner();
84 
85 #if ROBOWFLEX_AT_LEAST_KINETIC
86  return planner->getPlannerProgressProperties();
87 
88  // As in Indigo they are boost::function
89 #else
91  for (const auto &pair : planner->getPlannerProgressProperties())
92  {
93  auto function = pair.second;
94  ret[pair.first] = [function] { return function(); };
95  }
96 
97  return ret;
98 #endif
99 }
void refreshContext(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request, bool force=false) const
Refreshes the internal planning context.

◆ initialize()

bool OMPL::OMPLInterfacePlanner::initialize ( const std::string config_file = "",
const OMPL::Settings  settings = Settings() 
)

Initialize planning pipeline.

Parameters
[in]config_fileA YAML file containing OMPL planner configurations.
[in]settingsSettings to set on the parameter server.
Returns
True upon success, false on failure.

Definition at line 19 of file ompl_interface.cpp.

20 {
21  if (!loadOMPLConfig(handler_, config_file, configs_))
22  return false;
23 
24  interface_.reset(new ompl_interface::OMPLInterface(robot_->getModel(), handler_.getHandle()));
25 
26  settings.setParam(handler_);
27 
28  interface_->simplifySolutions(settings.simplify_solutions);
31 
32  auto &pcm = interface_->getPlanningContextManager();
33  pcm.setMaximumSolutionSegmentLength(settings.maximum_waypoint_distance);
34  pcm.setMinimumWaypointCount(settings.minimum_waypoint_count);
35 
36  pcm.setMaximumPlanningThreads(settings.max_planning_threads);
37  pcm.setMaximumGoalSamples(settings.max_goal_samples);
38  pcm.setMaximumStateSamplingAttempts(settings.max_state_sampling_attempts);
39  pcm.setMaximumGoalSamplingAttempts(settings.max_goal_sampling_attempts);
40 
42  pcm.setMaximumSolutionSegmentLength(settings.max_solution_segment_length);
43 
44  return true;
45 }
const ros::NodeHandle & getHandle() const
Gets the node handle.
bool hybridize_
Whether or not planner should hybridize solutions.
bool interpolate_
Whether or not planner should interpolate solutions.
void setParam(IO::Handler &handler) const
Sets member variables on the parameter server using handler.
int minimum_waypoint_count
Minimum number of waypoints in output path.
int max_goal_samples
Maximum number of successful goal samples to keep.
int max_state_sampling_attempts
Maximum number of attempts to sample a new state.
int max_planning_threads
Maximum number of threads used to service a request.
bool interpolate_solutions
Whether or not planner should interpolate solutions.
bool hybridize_solutions
Whether or not planner should hybridize solutions.
double max_solution_segment_length
Maximum solution segment length.
double maximum_waypoint_distance
Maximum distance between waypoints in path.
bool simplify_solutions
Whether or not planner should simplify solutions.
int max_goal_sampling_attempts
Maximum number of attempts to sample a goal.
IO::Handler handler_
The parameter handler for the planner.
bool loadOMPLConfig(IO::Handler &handler, const std::string &config_file, std::vector< std::string > &configs)
Loads an OMPL configuration YAML file onto the parameter server.
T reset(T... args)

◆ operator=()

void robowflex::OMPL::OMPLInterfacePlanner::operator= ( OMPLInterfacePlanner const &  )
delete

◆ plan()

planning_interface::MotionPlanResponse OMPL::OMPLInterfacePlanner::plan ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
)
overridevirtual

Plan a motion given a request and a scene. Uses the planning pipeline's generatePlan() method, which goes through planning adapters.

Parameters
[in]sceneA planning scene for the same robot_ to compute the plan in.
[in]requestThe motion planning request to solve.
Returns
The motion planning response generated by the planner.

Implements robowflex::Planner.

Definition at line 59 of file ompl_interface.cpp.

61 {
63  response.error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
64 
65  refreshContext(scene, request);
66  if (not ss_)
67  return response;
68 
71 
72  context_->solve(response);
73  return response;
74 }
PrePlanCallback pre_plan_callback_
Callback to be called just before planning.
ompl_interface::ModelBasedPlanningContextPtr context_
Last context.
moveit_msgs::MoveItErrorCodes error_code_

◆ preRun()

void OMPL::OMPLInterfacePlanner::preRun ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
)
overridevirtual

This function is called before benchmarking.

Parameters
[in]sceneScene to plan for.
[in]requestPlanning request.

Reimplemented from robowflex::Planner.

Definition at line 53 of file ompl_interface.cpp.

55 {
56  refreshContext(scene, request, true);
57 }

◆ refreshContext()

void OMPL::OMPLInterfacePlanner::refreshContext ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request,
bool  force = false 
) const

Refreshes the internal planning context.

Parameters
[in]sceneA planning scene for the same robot_ to compute the plan in.
[in]requestThe motion planning request to solve.
[in]forceIf true, forces a refresh of the context.

Definition at line 101 of file ompl_interface.cpp.

104 {
105  const auto &scene_id = scene->getKey();
106  const auto &request_hash = IO::getMessageMD5(request);
107 
108  bool same_scene = compareIDs(scene_id, last_scene_id_);
109  bool same_request = request_hash == last_request_hash_;
110 
111  if (not force and ss_ and same_scene and same_request)
112  {
113  RBX_INFO("Reusing Cached Context!");
114  return;
115  }
116 
117  context_ = getPlanningContext(scene, request);
118  if (not context_)
119  {
120  RBX_ERROR("Context was not set!");
121  ss_ = nullptr;
122  return;
123  }
124 
125 #if ROBOWFLEX_AT_LEAST_MELODIC
126  context_->setInterpolation(interpolate_);
127  context_->setHybridize(hybridize_);
128 #endif
129 
130  ss_ = context_->getOMPLSimpleSetup();
131 
132  last_scene_id_ = scene_id;
133  last_request_hash_ = request_hash;
134 
135  RBX_INFO("Refreshed Context!");
136 }
std::string last_request_hash_
Hash of last request.
ID::Key last_scene_id_
ID of last scene.
ompl_interface::ModelBasedPlanningContextPtr getPlanningContext(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const
Returns the planning context used for this motion planning request.
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
std::string getMessageMD5(T &msg)
Compute MD5 hash of message.
bool compareIDs(const ID &a, const ID &b)
Compare two ID objects.
Definition: id.cpp:47

◆ setPrePlanCallback()

void OMPL::OMPLInterfacePlanner::setPrePlanCallback ( const PrePlanCallback prePlanCallback)

Set a callback, to be called right before a planning session for last-minute configuration or external bookkeeping.

refreshContext() will already have been called, so the SimpleSetup obtained by getLastSimpleSetup() will be the one used for planning.

Definition at line 157 of file ompl_interface.cpp.

158 {
159  pre_plan_callback_ = prePlanCallback;
160 }

Member Data Documentation

◆ configs_

std::vector<std::string> robowflex::OMPL::OMPLInterfacePlanner::configs_
private

Planning configurations.

Definition at line 120 of file ompl_interface.h.

◆ context_

ompl_interface::ModelBasedPlanningContextPtr robowflex::OMPL::OMPLInterfacePlanner::context_
mutableprivate

Last context.

Definition at line 127 of file ompl_interface.h.

◆ hybridize_

bool robowflex::OMPL::OMPLInterfacePlanner::hybridize_
private

Whether or not planner should hybridize solutions.

Definition at line 121 of file ompl_interface.h.

◆ interface_

std::unique_ptr<ompl_interface::OMPLInterface> robowflex::OMPL::OMPLInterfacePlanner::interface_ {nullptr}
private

Planning interface.

Definition at line 119 of file ompl_interface.h.

◆ interpolate_

bool robowflex::OMPL::OMPLInterfacePlanner::interpolate_
private

Whether or not planner should interpolate solutions.

Definition at line 122 of file ompl_interface.h.

◆ last_request_hash_

std::string robowflex::OMPL::OMPLInterfacePlanner::last_request_hash_
mutableprivate

Hash of last request.

Definition at line 125 of file ompl_interface.h.

◆ last_scene_id_

ID::Key robowflex::OMPL::OMPLInterfacePlanner::last_scene_id_ {ID::getNullKey()}
mutableprivate

ID of last scene.

Definition at line 124 of file ompl_interface.h.

◆ pre_plan_callback_

PrePlanCallback robowflex::OMPL::OMPLInterfacePlanner::pre_plan_callback_
private

Callback to be called just before planning.

Definition at line 131 of file ompl_interface.h.

◆ ss_

ompl::geometric::SimpleSetupPtr robowflex::OMPL::OMPLInterfacePlanner::ss_
mutableprivate

Last OMPL simple setup used for planning.

Definition at line 128 of file ompl_interface.h.


The documentation for this class was generated from the following files: