Skip to content

Commit

Permalink
Make accessible with moveit_cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sjahr committed May 15, 2023
1 parent f84c1d1 commit a1fd037
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions moveit_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ install(
moveit_collision_detection_fcl
moveit_collision_distance_field
moveit_constraint_samplers
moveit_cost_functions
moveit_distance_field
moveit_dynamics_solver
moveit_exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace moveit
{
namespace cost_functions
{
[[nodiscard]] planning_interface::StateCostFn getClearanceCostFn();
[[nodiscard]] ::planning_interface::StateCostFn getClearanceCostFn();

[[nodiscard]] planning_interface::StateCostFn
getWeightedCostFnSum(std::vector<std::pair<double, planning_interface::StateCostFn>> weight_cost_vector);
[[nodiscard]] ::planning_interface::StateCostFn
getWeightedCostFnSum(std::vector<std::pair<double, ::planning_interface::StateCostFn>> weight_cost_vector);
} // namespace cost_functions
} // namespace moveit
6 changes: 3 additions & 3 deletions moveit_core/cost_functions/src/cost_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace moveit
{
namespace cost_functions
{
[[nodiscard]] planning_interface::StateCostFn getClearanceCostFn()
[[nodiscard]] ::planning_interface::StateCostFn getClearanceCostFn()
{
// Create cost function
return [](const moveit::core::RobotState& robot_state, const planning_interface::MotionPlanRequest& request,
Expand All @@ -57,8 +57,8 @@ namespace cost_functions
};
}

[[nodiscard]] planning_interface::StateCostFn
getWeightedCostFnSum(std::vector<std::pair<double, planning_interface::StateCostFn>> weight_cost_vector)
[[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,11 @@ void ompl_interface::ModelBasedPlanningContext::useConfig(const planning_scene::

if (state_cost_function_ != nullptr)
{
RCLCPP_WARN(LOGGER, "%s: Use user defined optimization function!",
name_.c_str());
objective = std::make_shared<ompl_interface::PlanningInterfaceObjective>(ompl_simple_setup_->getSpaceInformation(),
planning_scene, req, state_cost_function_);
ompl_simple_setup_->setOptimizationObjective(objective);
}

// Don't clear planner data if multi-query planning is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <geometry_msgs/msg/pose_stamped.hpp>
#include <moveit/moveit_cpp/moveit_cpp.h>
#include <moveit/planning_interface/planning_interface.h>
#include <moveit/planning_interface/planning_response.h>
#include <moveit/planning_pipeline_interfaces/planning_pipeline_interfaces.hpp>
#include <moveit/planning_pipeline_interfaces/solution_selection_functions.hpp>
Expand Down Expand Up @@ -189,6 +190,13 @@ class PlanningComponent
/** \brief Set the trajectory constraints generated from a moveit msg Constraints */
bool setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints& trajectory_constraints);

/** \brief Set planning cost function */
bool setStateCostFunction(const planning_interface::StateCostFn& state_cost_function)
{
state_cost_function_ = state_cost_function;
return true;
};

/** \brief Run a plan from start or current state to fulfill the last goal constraints provided by setGoal() using
* default parameters. */
planning_interface::MotionPlanResponse plan();
Expand Down Expand Up @@ -230,6 +238,7 @@ class PlanningComponent
const std::string group_name_;
// The robot_model_ member variable of MoveItCpp class will manually free the joint_model_group_ resources
const moveit::core::JointModelGroup* joint_model_group_;
planning_interface::StateCostFn state_cost_function_;

// Planning
// The start state used in the planning motion request
Expand Down
4 changes: 2 additions & 2 deletions moveit_ros/planning/moveit_cpp/src/planning_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ planning_interface::MotionPlanResponse PlanningComponent::plan(const PlanRequest
planning_scene->setCurrentState(request.start_state);

// Run planning attempt
return moveit::planning_pipeline_interfaces::planWithSinglePipeline(request, planning_scene,
moveit_cpp_->getPlanningPipelines());
return moveit::planning_pipeline_interfaces::planWithSinglePipeline(
request, planning_scene, moveit_cpp_->getPlanningPipelines(), state_cost_function_);
}

planning_interface::MotionPlanResponse PlanningComponent::plan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <moveit/planning_pipeline_interfaces/plan_responses_container.hpp>
#include <moveit/planning_interface/planning_response.h>
#include <moveit/planning_interface/planning_request.h>
#include <moveit/planning_interface/planning_interface.h>
#include <moveit/planning_pipeline/planning_pipeline.h>
#include <moveit/planning_scene/planning_scene.h>

Expand Down Expand Up @@ -73,7 +74,8 @@ typedef std::function<::planning_interface::MotionPlanResponse(
::planning_interface::MotionPlanResponse planWithSinglePipeline(
const ::planning_interface::MotionPlanRequest& motion_plan_request,
const ::planning_scene::PlanningSceneConstPtr& planning_scene,
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>& planning_pipelines);
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>& planning_pipelines,
const ::planning_interface::StateCostFn& state_cost_function = ::planning_interface::StateCostFn());

/** \brief Function to solve multiple planning problems in parallel threads with multiple planning pipelines at the same
time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.::planning_inter
::planning_interface::MotionPlanResponse
planWithSinglePipeline(const ::planning_interface::MotionPlanRequest& motion_plan_request,
const ::planning_scene::PlanningSceneConstPtr& planning_scene,
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>& planning_pipelines)
const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>& planning_pipelines,
const ::planning_interface::StateCostFn& state_cost_function)
{
::planning_interface::MotionPlanResponse motion_plan_response;
auto it = planning_pipelines.find(motion_plan_request.pipeline_id);
Expand All @@ -58,7 +59,7 @@ planWithSinglePipeline(const ::planning_interface::MotionPlanRequest& motion_pla
return motion_plan_response;
}
const planning_pipeline::PlanningPipelinePtr pipeline = it->second;
pipeline->generatePlan(planning_scene, motion_plan_request, motion_plan_response);
pipeline->generatePlan(planning_scene, motion_plan_request, motion_plan_response, state_cost_function);
return motion_plan_response;
}

Expand Down

0 comments on commit a1fd037

Please sign in to comment.