-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add state cost function to planning context Add clearance cost function Add OMPL objective Make use of custom cost function in OMPL objective Apply suggestions from code review Co-authored-by: Mark Moll <Mark.Moll@gmail.com> Make accessible with moveit_cpp TMP: Debugging prints Format! Update stomp planning interface Update cost function API Update use_config Cleanup function signature Cleanups Cost function interface for STOMP Update function signature to Eigen Pass cost function with motion plan request to planners Set state cost function in PlanningInterfaceObjective constructor
- Loading branch information
Showing
31 changed files
with
528 additions
and
56 deletions.
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
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,20 @@ | ||
add_library(moveit_cost_functions SHARED | ||
src/cost_functions.cpp | ||
) | ||
target_include_directories(moveit_cost_functions PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include/moveit_core> | ||
) | ||
set_target_properties(moveit_cost_functions PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}") | ||
target_link_libraries(moveit_cost_functions | ||
moveit_planning_interface | ||
moveit_planning_scene | ||
moveit_robot_state | ||
) | ||
|
||
install(DIRECTORY include/ DESTINATION include/moveit_core) | ||
|
||
|
||
#if(BUILD_TESTING) | ||
# TODO(sjahr): Add tests | ||
#endif() |
55 changes: 55 additions & 0 deletions
55
moveit_core/cost_functions/include/moveit/cost_functions/cost_functions.hpp
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,55 @@ | ||
/********************************************************************* | ||
* 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. | ||
*********************************************************************/ | ||
|
||
/* Author: Sebastian Jahr | ||
Desc: Cost functions for MoveIt */ | ||
|
||
#pragma once | ||
|
||
#include <moveit/planning_interface/planning_interface.h> | ||
#include <moveit/planning_interface/planning_request.h> | ||
#include <moveit/planning_scene/planning_scene.h> | ||
|
||
namespace moveit | ||
{ | ||
namespace cost_functions | ||
{ | ||
[[nodiscard]] ::planning_interface::StateCostFn | ||
getClearanceCostFn(moveit::core::RobotState& robot_state, const std::string& group_name, | ||
const planning_scene::PlanningSceneConstPtr& planning_scene); | ||
|
||
[[nodiscard]] ::planning_interface::StateCostFn | ||
getWeightedCostFnSum(std::vector<std::pair<double, ::planning_interface::StateCostFn>> weight_cost_vector); | ||
} // namespace cost_functions | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/********************************************************************* | ||
* 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. | ||
*********************************************************************/ | ||
|
||
/* Author: Sebastian Jahr */ | ||
|
||
#include <moveit/cost_functions/cost_functions.hpp> | ||
|
||
namespace moveit | ||
{ | ||
namespace cost_functions | ||
{ | ||
[[nodiscard]] ::planning_interface::StateCostFn | ||
getClearanceCostFn(moveit::core::RobotState& robot_state, const std::string& group_name, | ||
const planning_scene::PlanningSceneConstPtr& planning_scene) | ||
{ | ||
// Create cost function | ||
return [robot_state, group_name, planning_scene](const Eigen::VectorXd& state_vector) mutable { | ||
robot_state.setJointGroupActivePositions(group_name, state_vector); | ||
auto const shortest_distance_to_collision = planning_scene->distanceToCollisionUnpadded(robot_state); | ||
|
||
// Return cost based on shortest_distance if the robot is not in contact or penetrated a collision object | ||
if (shortest_distance_to_collision > 0.0) | ||
{ | ||
// The closer the collision object the higher the cost | ||
return 1.0 / shortest_distance_to_collision; | ||
} | ||
return std::numeric_limits<double>::infinity(); // Return a max cost cost by default | ||
}; | ||
} | ||
|
||
/* | ||
[[nodiscard]] ::planning_interface::StateCostFn | ||
getWeightedCostFnSum(std::vector<std::pair<double, ::planning_interface::StateCostFn>> weight_cost_vector) | ||
{ | ||
return [weight_cost_vector](const moveit::core::RobotState& robot_state, | ||
const planning_interface::MotionPlanRequest& request, | ||
const planning_scene::PlanningSceneConstPtr& planning_scene) { | ||
auto weighted_sum = 0.0; | ||
for (const auto& weight_cost_pair : weight_cost_vector) | ||
{ | ||
weighted_sum += weight_cost_pair.first * weight_cost_pair.second(robot_state, request, planning_scene); | ||
} | ||
return weighted_sum; | ||
}; | ||
}*/ | ||
|
||
} // namespace cost_functions | ||
} // 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/********************************************************************* | ||
* 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. | ||
*********************************************************************/ | ||
|
||
/* Author: Sebastian Jahr */ | ||
|
||
#include <moveit/planning_interface/planning_request.h> | ||
|
||
namespace planning_interface | ||
{ | ||
MotionPlanRequest::MotionPlanRequest(moveit_msgs::msg::MotionPlanRequest request_msg, | ||
planning_interface::StateCostFn state_cost_function) | ||
: moveit_msgs::msg::MotionPlanRequest(request_msg), state_cost_function{ state_cost_function } | ||
{ | ||
} | ||
|
||
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest::toMessage() const | ||
{ | ||
moveit_msgs::msg::MotionPlanRequest request_msg; | ||
request_msg.workspace_parameters = workspace_parameters; | ||
request_msg.start_state = start_state; | ||
request_msg.goal_constraints = goal_constraints; | ||
request_msg.path_constraints = path_constraints; | ||
request_msg.trajectory_constraints = trajectory_constraints; | ||
request_msg.reference_trajectories = reference_trajectories; | ||
request_msg.pipeline_id = pipeline_id; | ||
request_msg.planner_id = planner_id; | ||
request_msg.group_name = group_name; | ||
request_msg.num_planning_attempts = num_planning_attempts; | ||
request_msg.allowed_planning_time = allowed_planning_time; | ||
request_msg.max_velocity_scaling_factor = max_velocity_scaling_factor; | ||
request_msg.max_acceleration_scaling_factor = max_acceleration_scaling_factor; | ||
request_msg.cartesian_speed_end_effector_link = cartesian_speed_end_effector_link; | ||
request_msg.max_cartesian_speed = max_cartesian_speed; | ||
return request_msg; | ||
} | ||
} // namespace planning_interface |
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
93 changes: 93 additions & 0 deletions
93
...ompl/ompl_interface/include/moveit/ompl_interface/detail/planning_interface_objective.hpp
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,93 @@ | ||
/********************************************************************* | ||
* 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. | ||
*********************************************************************/ | ||
|
||
/* Author: Sebastian Jahr | ||
Description: TODO | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <moveit/cost_functions/cost_functions.hpp> | ||
#include <moveit/planning_scene/planning_scene.h> | ||
#include <ompl/base/OptimizationObjective.h> | ||
|
||
namespace ompl_interface | ||
{ | ||
/** \brief Flexible objective that can be configured using the MoveIt planning interface cost API. */ | ||
class PlanningInterfaceObjective : public ompl::base::OptimizationObjective | ||
{ | ||
public: | ||
PlanningInterfaceObjective(const ompl::base::SpaceInformationPtr& si, | ||
const planning_interface::StateCostFn& state_cost_function); | ||
|
||
/** \brief Returns for a state calculated with the state_cost_function */ | ||
ompl::base::Cost stateCost(const ompl::base::State* state) const override; | ||
|
||
/** \brief Adapted from ompl::base::StateCostIntegralObjective: Compute the cost of a path segment from \e state_1 to | ||
\e state_2 (including endpoints) \param state_1 start state of the motion to be evaluated \param state_2 final | ||
state of the motion to be evaluated \param cost the cost of the motion segment | ||
By default, this function computes | ||
\f{eqnarray*}{ | ||
\mbox{cost} &=& \frac{cost(s_1) + cost(s_2)}{2}\vert s_1 - s_2 \vert | ||
\f} | ||
*/ | ||
ompl::base::Cost motionCost(const ompl::base::State* state_1, const ompl::base::State* state_2) const override; | ||
|
||
/** \brief Adapted from ompl::base::StateCostIntegralObjective: Estimate the cost of a path segment from \e state_1 to | ||
\e state_2 (including endpoints). \param state_1 start state of the motion to be evaluated \param state_2 final | ||
state of the motion to be evaluated \param cost the cost of the motion segment | ||
This function computes | ||
\f{eqnarray*}{ | ||
\mbox{cost} &=& \frac{cost(s_1) + cost(s_2)}{2}\vert s_1 - s_2 \vert | ||
\f} | ||
regardless of whether enableMotionCostInterpolation was specified as true in | ||
constructing this object. | ||
*/ | ||
ompl::base::Cost motionCostBestEstimate(const ompl::base::State* state_1, const ompl::base::State* state_2) const; | ||
|
||
protected: | ||
const planning_interface::StateCostFn state_cost_function_; | ||
|
||
/** \brief Adapted from ompl::base::StateCostIntegralObjective: Helper method which uses the trapezoidal rule | ||
to approximate the integral of the cost between two | ||
states of distance \e dist and costs \e c1 and \e | ||
c2 */ | ||
ompl::base::Cost trapezoid(ompl::base::Cost cost_1, ompl::base::Cost cost_2, double distance) const | ||
{ | ||
return ompl::base::Cost(0.5 * distance * (cost_1.value() + cost_2.value())); | ||
} | ||
}; | ||
} // namespace ompl_interface |
Oops, something went wrong.