Robowflex  v0.1
Making MoveIt Easy
ompl_interface.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_OMPL_
4 #define ROBOWFLEX_OMPL_
5 
6 #include <moveit/ompl_interface/ompl_interface.h>
7 
10 
11 #include <functional>
12 
13 namespace robowflex
14 {
15  /** \cond IGNORE */
18  /** \endcond */
19 
20  namespace OMPL
21  {
22  /** \cond IGNORE */
23  ROBOWFLEX_CLASS_FORWARD(OMPLInterfacePlanner);
24  /** \endcond */
25 
26  /** \class robowflex::OMPL::OMPLInterfacePlannerPtr
27  \brief A shared pointer wrapper for robowflex::OMPL::OMPLInterfacePlanner. */
28 
29  /** \class robowflex::OMPL::OMPLInterfacePlannerConstPtr
30  \brief A const shared pointer wrapper for robowflex::OMPL::OMPLInterfacePlanner. */
31 
32  /** \brief A planner that directly uses \a MoveIt!'s OMPL planning interface.
33  */
35  {
36  public:
37  /** \brief Constructor.
38  * \param[in] robot The robot to plan for.
39  * \param[in] name Optional namespace for planner.
40  */
41  OMPLInterfacePlanner(const RobotPtr &robot, const std::string &name = "");
42 
43  // non-copyable
45  void operator=(OMPLInterfacePlanner const &) = delete;
46 
47  /** \brief Initialize planning pipeline.
48  * \param[in] config_file A YAML file containing OMPL planner configurations.
49  * \param[in] settings Settings to set on the parameter server.
50  * \return True upon success, false on failure.
51  */
52  bool initialize(const std::string &config_file = "", const OMPL::Settings settings = Settings());
53 
54  /** \brief Plan a motion given a \a request and a \a scene.
55  * Uses the planning pipeline's generatePlan() method, which goes through planning adapters.
56  * \param[in] scene A planning scene for the same \a robot_ to compute the plan in.
57  * \param[in] request The motion planning request to solve.
58  * \return The motion planning response generated by the planner.
59  */
61  plan(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override;
62 
63  /** \brief Returns the planning context used for this motion planning request.
64  * \param[in] scene A planning scene for the same \a robot_ to compute the plan in.
65  * \param[in] request The motion planning request to solve.
66  * \return The motion planning context used by the planner.
67  */
68  ompl_interface::ModelBasedPlanningContextPtr getPlanningContext(
69  const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const;
70 
71  /** \brief Get the last OMPL simple setup used in planning.
72  * \return The last OMPL simple setup used.
73  */
74  ompl::geometric::SimpleSetupPtr getLastSimpleSetup() const;
75 
76  /** \brief Refreshes the internal planning context.
77  * \param[in] scene A planning scene for the same \a robot_ to compute the plan in.
78  * \param[in] request The motion planning request to solve.
79  * \param[in] force If true, forces a refresh of the context.
80  */
81  void refreshContext(const SceneConstPtr &scene, //
82  const planning_interface::MotionPlanRequest &request, //
83  bool force = false) const;
84 
87  const planning_interface::MotionPlanRequest &request) const override;
88 
90 
91  void preRun(const SceneConstPtr &scene,
92  const planning_interface::MotionPlanRequest &request) override;
93 
94  /** \brief Access the OMPLInterface directly, to customize the planning process.
95  */
96  ompl_interface::OMPLInterface &getInterface() const;
97 
98  /**
99  * \brief Type for the callback function to be called right before planning takes place, when the
100  * planning context is available.
101  *
102  * \param[in] context The planning context, contains SimpleSetup that will be used.
103  * \param[in] scene The planning scene being planned on.
104  * \param[in] request The request to plan a path for.
105  */
107  const ompl_interface::ModelBasedPlanningContextPtr &context, const SceneConstPtr &scene,
108  const planning_interface::MotionPlanRequest &request)>;
109 
110  /** \brief Set a callback, to be called right before a planning session for last-minute
111  * configuration or external bookkeeping.
112  *
113  * refreshContext() will already have been called, so the SimpleSetup obtained by
114  * getLastSimpleSetup() will be the one used for planning.
115  */
116  void setPrePlanCallback(const PrePlanCallback &prePlanCallback);
117 
118  private:
120  std::vector<std::string> configs_; ///< Planning configurations.
121  bool hybridize_; ///< Whether or not planner should hybridize solutions.
122  bool interpolate_; ///< Whether or not planner should interpolate solutions.
123 
124  mutable ID::Key last_scene_id_{ID::getNullKey()}; ///< ID of last scene.
125  mutable std::string last_request_hash_; ///< Hash of last request.
126 
127  mutable ompl_interface::ModelBasedPlanningContextPtr context_; ///< Last context.
128  mutable ompl::geometric::SimpleSetupPtr ss_; ///< Last OMPL simple setup used for
129  ///< planning.
130 
131  PrePlanCallback pre_plan_callback_; ///< Callback to be called just before planning.
132  };
133  } // namespace OMPL
134 } // namespace robowflex
135 
136 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
static Key getNullKey()
Get a null key for initialization.
Definition: id.cpp:27
A planner that directly uses MoveIt!'s OMPL planning interface.
bool hybridize_
Whether or not planner should hybridize solutions.
std::string last_request_hash_
Hash of last request.
std::vector< std::string > configs_
Planning configurations.
ompl_interface::OMPLInterface & getInterface() const
Access the OMPLInterface directly, to customize the planning process.
void setPrePlanCallback(const PrePlanCallback &prePlanCallback)
Set a callback, to be called right before a planning session for last-minute configuration or externa...
OMPLInterfacePlanner(OMPLInterfacePlanner const &)=delete
ID::Key last_scene_id_
ID of last scene.
void preRun(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
This function is called before benchmarking.
ompl::geometric::SimpleSetupPtr ss_
PrePlanCallback pre_plan_callback_
Callback to be called just before planning.
bool initialize(const std::string &config_file="", const OMPL::Settings settings=Settings())
Initialize planning pipeline.
ompl_interface::ModelBasedPlanningContextPtr getPlanningContext(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const
Returns the planning context used for this motion planning request.
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,...
std::map< std::string, Planner::ProgressProperty > getProgressProperties(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const override
Retrieve the planner progress property map for this planner given a specific request.
std::unique_ptr< ompl_interface::OMPLInterface > interface_
Planning interface.
void refreshContext(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request, bool force=false) const
Refreshes the internal planning context.
bool interpolate_
Whether or not planner should interpolate solutions.
void operator=(OMPLInterfacePlanner const &)=delete
std::vector< std::string > getPlannerConfigs() const override
Return all planner configurations offered by this planner. Any of the configurations returned can be ...
ompl::geometric::SimpleSetupPtr getLastSimpleSetup() const
Get the last OMPL simple setup used in planning.
ompl_interface::ModelBasedPlanningContextPtr context_
Last context.
OMPLInterfacePlanner(const RobotPtr &robot, const std::string &name="")
Constructor.
Settings descriptor for settings provided by the default MoveIt! OMPL planning pipeline.
An abstract interface to a motion planning algorithm.
A shared pointer wrapper for robowflex::Robot.
A const shared pointer wrapper for robowflex::Scene.
moveit_msgs::MotionPlanRequest MotionPlanRequest
Functions for loading and animating robots in Blender.
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
Functions for loading and animating scenes in Blender.