Skip to content
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

Update "Store OMPL Planning Data" PR #2364

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions moveit_planners/ompl/ompl_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set_target_properties(moveit_ompl_interface
PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}")

find_package(OpenMP REQUIRED)
find_package(std_srvs)

# Used to link in ODE, an OMPL dependency, on macOS
if(APPLE)
Expand All @@ -36,6 +37,7 @@ ament_target_dependencies(
moveit_ros_planning
rclcpp
pluginlib
std_srvs
tf2_eigen
tf2_ros
OMPL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
#include <moveit/planning_interface/planning_interface.h>
#include <moveit_msgs/msg/motion_plan_request.hpp>
#include <moveit_msgs/msg/motion_plan_response.hpp>
#include <rclcpp/node.hpp>
#include <string>
#include <map>
#include <rclcpp/rclcpp.hpp>
#include <std_srvs/srv/trigger.hpp>

/** \brief The MoveIt interface to OMPL */
namespace ompl_interface
Expand All @@ -69,6 +70,13 @@ class OMPLInterface

virtual ~OMPLInterface();

/** @brief Store the OMPL planner data in a file.
* @param request the service request
* @param response the service response
*/
void storePlannerData(const std::shared_ptr<std_srvs::srv::Trigger::Request>& request,
const std::shared_ptr<std_srvs::srv::Trigger::Response>& response);

/** @brief Specify configurations for the planners.
@param pconfig Configurations for the different planners */
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap& pconfig);
Expand Down Expand Up @@ -151,5 +159,7 @@ class OMPLInterface

private:
constraint_sampler_manager_loader::ConstraintSamplerManagerLoaderPtr constraint_sampler_manager_loader_;

rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr store_planner_data_service_;
};
} // namespace ompl_interface
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class MultiQueryPlannerAllocator
{
public:
MultiQueryPlannerAllocator() = default;
~MultiQueryPlannerAllocator();

/** @brief Store the OMPL planner data in a file.
*/
bool storePlannerData();

template <typename T>
ob::PlannerPtr allocatePlanner(const ob::SpaceInformationPtr& si, const std::string& new_name,
Expand Down Expand Up @@ -83,6 +86,10 @@ class PlanningContextManager
constraint_samplers::ConstraintSamplerManagerPtr csm);
~PlanningContextManager();

/** @brief Store the OMPL planner data in a file.
*/
bool storePlannerData();

/** @brief Specify configurations for the planners.
@param pconfig Configurations for the different planners */
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap& pconfig);
Expand Down
24 changes: 24 additions & 0 deletions moveit_planners/ompl/ompl_interface/src/ompl_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ OMPLInterface::OMPLInterface(const moveit::core::RobotModelConstPtr& robot_model
RCLCPP_DEBUG(getLogger(), "Initializing OMPL interface using ROS parameters");
loadPlannerConfigurations();
loadConstraintSamplers();

store_planner_data_service_ = node_->create_service<std_srvs::srv::Trigger>(
"store_planner_data",
[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>& request,
const std::shared_ptr<std_srvs::srv::Trigger::Response>& response) -> void {
storePlannerData(request, response);
});
}

OMPLInterface::OMPLInterface(const moveit::core::RobotModelConstPtr& robot_model,
Expand All @@ -78,10 +85,27 @@ OMPLInterface::OMPLInterface(const moveit::core::RobotModelConstPtr& robot_model
RCLCPP_DEBUG(getLogger(), "Initializing OMPL interface using specified configuration");
setPlannerConfigurations(pconfig);
loadConstraintSamplers();

store_planner_data_service_ = node_->create_service<std_srvs::srv::Trigger>(
"store_planner_data",
[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>& request,
const std::shared_ptr<std_srvs::srv::Trigger::Response>& response) -> void {
storePlannerData(request, response);
});
}

OMPLInterface::~OMPLInterface() = default;

void OMPLInterface::storePlannerData(const std::shared_ptr<std_srvs::srv::Trigger::Request>& /* unused */,
const std::shared_ptr<std_srvs::srv::Trigger::Response>& response)
{
response->success = context_manager_.storePlannerData();
if (!response->success)
{
RCLCPP_ERROR(getLogger(), "Motion planning graph is empty");
}
}

void OMPLInterface::setPlannerConfigurations(const planning_interface::PlannerConfigurationMap& pconfig)
{
planning_interface::PlannerConfigurationMap pconfig2 = pconfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,24 @@ struct PlanningContextManager::CachedContexts
std::mutex lock_;
};

MultiQueryPlannerAllocator::~MultiQueryPlannerAllocator()
bool MultiQueryPlannerAllocator::storePlannerData()
{
// Store all planner data
for (const auto& entry : planner_data_storage_paths_)
{
ob::PlannerData data(planners_[entry.first]->getSpaceInformation());
planners_[entry.first]->getPlannerData(data);
if (data.numVertices() == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an debug info for this here. The error in OMPLInterface::storePlannerData() shouldn't make assumptions about the reason for failures in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added debug info, please check if this is what you meant.

{
RCLCPP_ERROR_STREAM(getLogger(), "Could not fetch space information or space information is empty.");
return false;
}
RCLCPP_INFO_STREAM(getLogger(), "Storing planner data. NumEdges: " << data.numEdges()
<< ", NumVertices: " << data.numVertices());
storage_.store(data, entry.second.c_str());
}

return true;
}

template <typename T>
Expand Down Expand Up @@ -269,6 +276,11 @@ PlanningContextManager::PlanningContextManager(moveit::core::RobotModelConstPtr

PlanningContextManager::~PlanningContextManager() = default;

bool PlanningContextManager::storePlannerData()
{
return planner_allocator_.storePlannerData();
}

ConfiguredPlannerAllocator PlanningContextManager::plannerSelector(const std::string& planner) const
{
auto it = known_planners_.find(planner);
Expand Down
Loading