-
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 cartesian_speed_end_effector_link -> cartesian_speed_limited_link Make clang-tidy happy Add getMinJointDisplacementCostFn
- Loading branch information
Showing
26 changed files
with
317 additions
and
27 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() |
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
/********************************************************************* | ||
* 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 | ||
getMinJointDisplacementCostFn(moveit::core::RobotState& robot_state, const std::string& group_name, | ||
const planning_scene::PlanningSceneConstPtr& planning_scene); | ||
|
||
[[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,91 @@ | ||
/********************************************************************* | ||
* 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->distanceToCollision(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 | ||
getMinJointDisplacementCostFn(moveit::core::RobotState& robot_state, const std::string& group_name, | ||
const planning_scene::PlanningSceneConstPtr& planning_scene) | ||
{ | ||
return [robot_state, group_name, planning_scene](const Eigen::VectorXd& state_vector) mutable { | ||
robot_state.setJointGroupActivePositions(group_name, state_vector); | ||
auto const current_state = planning_scene->getCurrentState(); | ||
|
||
return current_state.distance(robot_state); | ||
}; | ||
} | ||
|
||
/* | ||
[[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{ std::move(request_msg) }, state_cost_function{ std::move(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_limited_link = cartesian_speed_limited_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
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
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
Oops, something went wrong.