Skip to content

Commit 346861e

Browse files
committed
Add API to set parallel planning callbacks and deprecate functions
1 parent b6d49f2 commit 346861e

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

core/include/moveit/task_constructor/solvers/pipeline_planner.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
#include <moveit/task_constructor/solvers/planner_interface.h>
4242
#include <moveit/planning_pipeline_interfaces/planning_pipeline_interfaces.hpp>
43+
#include <moveit/planning_pipeline_interfaces/solution_selection_functions.hpp>
44+
#include <moveit/planning_pipeline_interfaces/stopping_criterion_functions.hpp>
4345
#include <rclcpp/node.hpp>
4446
#include <moveit/macros/class_forward.h>
4547

@@ -57,23 +59,34 @@ MOVEIT_CLASS_FORWARD(PipelinePlanner);
5759
class PipelinePlanner : public PlannerInterface
5860
{
5961
public:
60-
// TODO: Deprecate
62+
/** Simple Constructor to use only a single pipeline
63+
* \param [in] node ROS 2 node
64+
* \param [in] pipeline_name Name of the planning pipeline to be used. This is also the assumed namespace where the
65+
* parameters of this pipeline can be found \param [in] planner_id Planner id to be used for planning
66+
*/
6167
PipelinePlanner(const rclcpp::Node::SharedPtr& node, const std::string& pipeline_name = "ompl",
6268
const std::string& planner_id = "");
6369

70+
[[deprecated("Deprecated: Use new constructor implementations.")]] // clang-format off
71+
PipelinePlanner(const planning_pipeline::PlanningPipelinePtr& planning_pipeline){};
72+
6473
/** \brief Constructor
65-
* \param [in] node ROS 2 node handle
74+
* \param [in] node ROS 2 node
6675
* \param [in] pipeline_id_planner_id_map A map containing pairs of planning pipeline name and planner plugin name
6776
* for the planning requests
6877
* \param [in] planning_pipelines Optional: A map with the pipeline names and initialized corresponding planning
6978
* pipelines
79+
* \param [in] stopping_criterion_callback Callback function to stop parallel planning pipeline according to a user defined criteria
80+
* \param [in] solution_selection_function Callback function to choose the best solution when multiple pipelines are used
7081
*/
7182
PipelinePlanner(const rclcpp::Node::SharedPtr& node,
7283
const std::unordered_map<std::string, std::string>& pipeline_id_planner_id_map,
7384
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines =
74-
std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>());
85+
std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>(),
86+
const moveit::planning_pipeline_interfaces::StoppingCriterionFunction& stopping_criterion_callback = &moveit::planning_pipeline_interfaces::stopAtFirstSolution,
87+
const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function = &moveit::planning_pipeline_interfaces::getShortestSolution);
7588

76-
// TODO: Deprecate
89+
[[deprecated("Replaced with setPlannerId(pipeline_name, planner_id)")]] // clang-format off
7790
void setPlannerId(const std::string& /*planner*/) { /* Do nothing */
7891
}
7992

@@ -84,9 +97,20 @@ class PipelinePlanner : public PlannerInterface
8497
*/
8598
bool setPlannerId(const std::string& pipeline_name, const std::string& planner_id);
8699

100+
/** \brief Set stopping criterion function for parallel planning
101+
* \param [in] stopping_criterion_callback New stopping criterion function that will be used
102+
*/
103+
void setStoppingCriterionFunction(const moveit::planning_pipeline_interfaces::StoppingCriterionFunction& stopping_criterion_callback);
104+
105+
/** \brief Set solution selection function for parallel planning
106+
* \param [in] solution_selection_function New solution selection that will be used
107+
*/
108+
void setSolutionSelectionFunction(const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function);
109+
87110
/** \brief This function is called when an MTC task that uses this solver is initialized. If no pipelines are
88111
* configured when this function is invoked, the planning pipelines named in the 'pipeline_id_planner_id_map' are
89-
* initialized with the given robot model. \param [in] robot_model A robot model that is used to initialize the
112+
* initialized with the given robot model.
113+
* \param [in] robot_model A robot model that is used to initialize the
90114
* planning pipelines of this solver
91115
*/
92116
void init(const moveit::core::RobotModelConstPtr& robot_model) override;
@@ -156,6 +180,10 @@ class PipelinePlanner : public PlannerInterface
156180
/** \brief Map of pipelines names and planning pipelines. This map is used to quickly search for a requested motion
157181
* planning pipeline when during plan(..) */
158182
std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines_;
183+
184+
moveit::planning_pipeline_interfaces::StoppingCriterionFunction stopping_criterion_callback_;
185+
moveit::planning_pipeline_interfaces::SolutionSelectionFunction solution_selection_function_;
186+
159187
};
160188
} // namespace solvers
161189
} // namespace task_constructor

core/src/solvers/pipeline_planner.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
#include <moveit/task_constructor/task.h>
4141
#include <moveit/planning_scene/planning_scene.h>
4242
#include <moveit/planning_pipeline/planning_pipeline.h>
43-
#include <moveit/planning_pipeline_interfaces/planning_pipeline_interfaces.hpp>
44-
#include <moveit/planning_pipeline_interfaces/solution_selection_functions.hpp>
45-
#include <moveit/planning_pipeline_interfaces/stopping_criterion_functions.hpp>
4643
#include <moveit_msgs/msg/motion_plan_request.hpp>
4744
#include <moveit/kinematic_constraints/utils.h>
4845

@@ -70,8 +67,13 @@ PipelinePlanner::PipelinePlanner(const rclcpp::Node::SharedPtr& node, const std:
7067

7168
PipelinePlanner::PipelinePlanner(
7269
const rclcpp::Node::SharedPtr& node, const std::unordered_map<std::string, std::string>& pipeline_id_planner_id_map,
73-
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines)
74-
: node_(node), pipeline_id_planner_id_map_(pipeline_id_planner_id_map) {
70+
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines,
71+
const moveit::planning_pipeline_interfaces::StoppingCriterionFunction& stopping_criterion_callback,
72+
const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function)
73+
: node_(node)
74+
, pipeline_id_planner_id_map_(pipeline_id_planner_id_map)
75+
, stopping_criterion_callback_(stopping_criterion_callback)
76+
, solution_selection_function_(solution_selection_function) {
7577
// If the pipeline name - pipeline map is passed as constructor argument, use it. Otherwise, it will be created in
7678
// the init(..) function
7779
if (!planning_pipelines.empty()) {
@@ -94,11 +96,6 @@ PipelinePlanner::PipelinePlanner(
9496
planning_pipeline::PlanningPipeline::MOTION_PLAN_REQUEST_TOPIC);
9597
}
9698

97-
// PipelinePlanner::PipelinePlanner(const planning_pipeline::PlanningPipelinePtr& planning_pipeline)
98-
// : PipelinePlanner(rclcpp::Node::SharedPtr()) {
99-
// planning_pipelines_.at(0) = planning_pipeline;
100-
//}
101-
10299
bool PipelinePlanner::setPlannerId(const std::string& pipeline_name, const std::string& planner_id) {
103100
// Only set ID if pipeline exists. It is not possible to create new pipelines with this command.
104101
if (pipeline_id_planner_id_map_.count(pipeline_name) > 0) {
@@ -109,6 +106,15 @@ bool PipelinePlanner::setPlannerId(const std::string& pipeline_name, const std::
109106
return false;
110107
}
111108

109+
void PipelinePlanner::setStoppingCriterionFunction(
110+
const moveit::planning_pipeline_interfaces::StoppingCriterionFunction& stopping_criterion_function) {
111+
stopping_criterion_callback_ = stopping_criterion_function;
112+
}
113+
void PipelinePlanner::setSolutionSelectionFunction(
114+
const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function) {
115+
solution_selection_function_ = solution_selection_function;
116+
}
117+
112118
void PipelinePlanner::init(const core::RobotModelConstPtr& robot_model) {
113119
// If no planning pipelines exist, create them based on the pipeline names provided in pipeline_id_planner_id_map_.
114120
// The assumption here is that all parameters required by the planning pipeline can be found in a namespace that
@@ -200,8 +206,7 @@ bool PipelinePlanner::plan(const planning_scene::PlanningSceneConstPtr& planning
200206
// planWithParallelPipelines will return a vector with the single best solution
201207
std::vector<::planning_interface::MotionPlanResponse> responses =
202208
moveit::planning_pipeline_interfaces::planWithParallelPipelines(
203-
requests, planning_scene, planning_pipelines_, &moveit::planning_pipeline_interfaces::stopAtFirstSolution,
204-
&moveit::planning_pipeline_interfaces::getShortestSolution);
209+
requests, planning_scene, planning_pipelines_, stopping_criterion_callback_, solution_selection_function_);
205210

206211
// If solutions exist and the first one is successful
207212
if (!responses.empty() && responses.at(0)) {

0 commit comments

Comments
 (0)