-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Alternatives and fallback planners #451
Draft
sjahr
wants to merge
8
commits into
moveit:ros2
Choose a base branch
from
sjahr:pr-alternative_and_fallback_planners
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b79ec83
Merge PR #429: MultiPlanner
rhaschke bf58108
Port to ROS 2
sjahr dd7aa11
Rename multi-planner to fallback planner
sjahr b75338f
Add stopping criterion function
sjahr e53a063
Add alternatives planner
sjahr 06129ea
Minor variable renaming
sjahr 2fdce55
Format
sjahr 439e368
Check for nullptr and add missing headers
sjahr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
core/include/moveit/task_constructor/solvers/alternatives_planner.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2023, PickNik Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of PickNik Inc. nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
/* Authors: Sebastian Jahr, Robert Haschke | ||
Desc: Meta planner, running multiple planners in parallel | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <moveit/task_constructor/solvers/planner_interface.h> | ||
#include <moveit/planning_pipeline_interfaces/plan_responses_container.hpp> | ||
#include <moveit/planning_pipeline_interfaces/planning_pipeline_interfaces.hpp> | ||
#include <moveit/planning_pipeline_interfaces/solution_selection_functions.hpp> | ||
#include <moveit/robot_trajectory/robot_trajectory.h> | ||
#include <vector> | ||
|
||
namespace moveit { | ||
namespace task_constructor { | ||
namespace solvers { | ||
|
||
MOVEIT_CLASS_FORWARD(AlternativesPlanner); | ||
|
||
/** A meta planner that runs multiple alternative planners in parallel and returns the best solution. | ||
* | ||
* This is useful to try different planning strategies of increasing complexity, | ||
* e.g. Cartesian or joint-space interpolation and OMPL, and choose the most suitable solution out of the ones produced. | ||
*/ | ||
class AlternativesPlanner : public PlannerInterface, public std::vector<solvers::PlannerInterfacePtr> | ||
{ | ||
public: | ||
using PlannerList = std::vector<solvers::PlannerInterfacePtr>; | ||
using PlannerList::PlannerList; // inherit all std::vector constructors | ||
|
||
void init(const moveit::core::RobotModelConstPtr& robot_model) override; | ||
|
||
bool plan(const planning_scene::PlanningSceneConstPtr& from, const planning_scene::PlanningSceneConstPtr& to, | ||
const moveit::core::JointModelGroup* jmg, double timeout, robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override; | ||
|
||
bool plan(const planning_scene::PlanningSceneConstPtr& from, const moveit::core::LinkModel& link, | ||
const Eigen::Isometry3d& offset, const Eigen::Isometry3d& target, const moveit::core::JointModelGroup* jmg, | ||
double timeout, robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override; | ||
|
||
/** \brief Set solution selection function for parallel planning | ||
* \param [in] solution_selection_function New solution selection that will be used | ||
*/ | ||
void setSolutionSelectionFunction( | ||
const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function) { | ||
solution_selection_function_ = solution_selection_function; | ||
}; | ||
|
||
protected: | ||
moveit::planning_pipeline_interfaces::SolutionSelectionFunction solution_selection_function_ = | ||
&moveit::planning_pipeline_interfaces::getShortestSolution; | ||
}; | ||
} // namespace solvers | ||
} // namespace task_constructor | ||
} // namespace moveit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
core/include/moveit/task_constructor/solvers/fallback_planner.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2023, Bielefeld University | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of Bielefeld University nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
/* Authors: Robert Haschke, Sebastian Jahr | ||
Desc: Meta planner, running multiple MTC planners in sequence | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <moveit/task_constructor/solvers/planner_interface.h> | ||
#include <moveit/robot_trajectory/robot_trajectory.h> | ||
#include <vector> | ||
|
||
namespace moveit { | ||
namespace task_constructor { | ||
namespace solvers { | ||
|
||
/** \brief A stopping criterion which is evaluated after running a planner. | ||
* \param [in] result Most recent result of the last planner invoked | ||
* \param [in] path_constraints Set of path constraints passed to the solver | ||
* \return If it returns true, the corresponding trajectory is considered the solution, otherwise false is returned and | ||
* the next fallback planner is called. | ||
*/ | ||
typedef std::function<bool(const robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& path_constraints)> | ||
StoppingCriterionFunction; | ||
|
||
MOVEIT_CLASS_FORWARD(FallbackPlanner); | ||
|
||
/** A meta planner that runs multiple alternative planners in sequence and returns the first found solution. | ||
* | ||
* This is useful to sequence different planning strategies of increasing complexity, | ||
* e.g. Cartesian or joint-space interpolation first, then OMPL, ... | ||
* This is (slightly) different from the Fallbacks container, as the FallbackPlanner directly applies its planners to | ||
* each individual planning job. In contrast, the Fallbacks container first runs the active child to exhaustion before | ||
* switching to the next child, which possibly applies a different planning strategy. | ||
*/ | ||
class FallbackPlanner : public PlannerInterface, public std::vector<solvers::PlannerInterfacePtr> | ||
{ | ||
public: | ||
using PlannerList = std::vector<solvers::PlannerInterfacePtr>; | ||
using PlannerList::PlannerList; // inherit all std::vector constructors | ||
|
||
void init(const moveit::core::RobotModelConstPtr& robot_model) override; | ||
|
||
bool plan(const planning_scene::PlanningSceneConstPtr& from, const planning_scene::PlanningSceneConstPtr& to, | ||
const moveit::core::JointModelGroup* jmg, double timeout, robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override; | ||
|
||
bool plan(const planning_scene::PlanningSceneConstPtr& from, const moveit::core::LinkModel& link, | ||
const Eigen::Isometry3d& offset, const Eigen::Isometry3d& target, const moveit::core::JointModelGroup* jmg, | ||
double timeout, robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override; | ||
|
||
/** \brief Set stopping criterion function for parallel planning | ||
* \param [in] stopping_criterion_callback New stopping criterion function that will be used | ||
*/ | ||
void setStoppingCriterionFunction(const StoppingCriterionFunction& stopping_criterion_callback) { | ||
stopping_criterion_function_ = stopping_criterion_callback; | ||
} | ||
|
||
protected: | ||
StoppingCriterionFunction stopping_criterion_function_ = | ||
[](const robot_trajectory::RobotTrajectoryPtr& result, | ||
const moveit_msgs::msg::Constraints& /*path_constraints*/) { | ||
if (result != nullptr) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
}; | ||
} // namespace solvers | ||
} // namespace task_constructor | ||
} // namespace moveit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest implementing this default as a reusable standalone function.