47 static const rclcpp::Logger LOGGER = rclcpp::get_logger(
"moveit.ompl_planning.ompl_interface");
50 const std::string& parameter_namespace)
52 , parameter_namespace_(parameter_namespace)
53 , robot_model_(robot_model)
54 , constraint_sampler_manager_(std::make_shared<
constraint_samplers::ConstraintSamplerManager>())
55 , context_manager_(robot_model, constraint_sampler_manager_)
56 , use_constraints_approximations_(true)
58 RCLCPP_DEBUG(LOGGER,
"Initializing OMPL interface using ROS parameters");
65 const rclcpp::Node::SharedPtr& node,
const std::string& parameter_namespace)
67 , parameter_namespace_(parameter_namespace)
68 , robot_model_(robot_model)
69 , constraint_sampler_manager_(std::make_shared<
constraint_samplers::ConstraintSamplerManager>())
70 , context_manager_(robot_model, constraint_sampler_manager_)
71 , use_constraints_approximations_(true)
73 RCLCPP_DEBUG(LOGGER,
"Initializing OMPL interface using specified configuration");
87 if (pconfig.find(
group->getName()) == pconfig.end())
91 pconfig2[empty.
name] = empty;
98 ModelBasedPlanningContextPtr
102 moveit_msgs::msg::MoveItErrorCodes dummy;
106 ModelBasedPlanningContextPtr
109 moveit_msgs::msg::MoveItErrorCodes& error_code)
const
111 ModelBasedPlanningContextPtr ctx =
118 constraint_sampler_manager_loader_ =
119 std::make_shared<constraint_sampler_manager_loader::ConstraintSamplerManagerLoader>(
node_,
124 const std::map<std::string, std::string>& group_params,
127 rcl_interfaces::msg::ListParametersResult planner_params_result =
130 if (planner_params_result.names.empty())
132 RCLCPP_ERROR(LOGGER,
"Could not find the planner configuration '%s' on the param server", planner_id.c_str());
136 planner_config.
name = group_name +
"[" + planner_id +
"]";
137 planner_config.
group = group_name;
140 planner_config.
config = group_params;
143 for (
const auto& planner_param : planner_params_result.names)
145 const rclcpp::Parameter param =
node_->get_parameter(planner_param);
146 auto param_name = planner_param.substr(planner_param.find(planner_id) + planner_id.size() + 1);
147 planner_config.
config[param_name] = param.value_to_string();
159 for (
const std::string& group_name :
robot_model_->getJointModelGroupNames())
163 static const std::pair<std::string, rclcpp::ParameterType> KNOWN_GROUP_PARAMS[] = {
164 {
"projection_evaluator", rclcpp::ParameterType::PARAMETER_STRING },
165 {
"longest_valid_segment_fraction", rclcpp::ParameterType::PARAMETER_DOUBLE },
166 {
"enforce_joint_model_state_space", rclcpp::ParameterType::PARAMETER_BOOL },
167 {
"enforce_constrained_state_space", rclcpp::ParameterType::PARAMETER_BOOL }
173 std::map<std::string, std::string> specific_group_params;
174 for (
const auto& [
name,
type] : KNOWN_GROUP_PARAMS)
176 std::string param_name{ group_name_param };
179 if (
node_->has_parameter(param_name))
181 const rclcpp::Parameter parameter =
node_->get_parameter(param_name);
182 if (parameter.get_type() !=
type)
184 RCLCPP_ERROR_STREAM(LOGGER,
"Invalid type for parameter '" <<
name <<
"' expected ["
185 << rclcpp::to_string(
type) <<
"] got ["
186 << rclcpp::to_string(parameter.get_type()) <<
"]");
189 if (parameter.get_type() == rclcpp::ParameterType::PARAMETER_STRING)
190 specific_group_params[
name] = parameter.as_string();
191 else if (parameter.get_type() == rclcpp::ParameterType::PARAMETER_DOUBLE)
193 else if (parameter.get_type() == rclcpp::ParameterType::PARAMETER_INTEGER)
194 specific_group_params[
name] = std::to_string(parameter.as_int());
195 else if (parameter.get_type() == rclcpp::ParameterType::PARAMETER_BOOL)
196 specific_group_params[
name] = std::to_string(parameter.as_bool());
202 std::string default_planner_id;
203 if (
node_->get_parameter(group_name_param +
".default_planner_config", default_planner_id))
207 default_planner_id =
"";
211 if (default_planner_id.empty())
213 default_pc.
group = group_name;
214 default_pc.
config = specific_group_params;
215 default_pc.
config[
"type"] =
"geometric::RRTConnect";
218 default_pc.
name = group_name;
219 pconfig[default_pc.
name] = default_pc;
222 std::vector<std::string> config_names;
223 if (
node_->get_parameter(group_name_param +
".planner_configs", config_names))
225 for (
const auto& planner_id : config_names)
230 pconfig[pc.
name] = pc;
236 for (
const auto& [
name, config_settings] : pconfig)
238 RCLCPP_DEBUG(LOGGER,
"Parameters for configuration '%s'",
name.c_str());
240 for (
const auto& [param_name, param_value] : config_settings.config)
242 RCLCPP_DEBUG_STREAM(LOGGER,
" - " << param_name <<
" = " << param_value);
251 RCLCPP_INFO(LOGGER,
"OMPL ROS interface is running.");
rclcpp::Node::SharedPtr node_
bool use_constraints_approximations_
void printStatus()
Print the status of this node.
constraint_samplers::ConstraintSamplerManagerPtr constraint_sampler_manager_
void loadConstraintSamplers()
Load the additional plugins for sampling constraints.
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap &pconfig)
Specify configurations for the planners.
PlanningContextManager context_manager_
bool loadPlannerConfiguration(const std::string &group_name, const std::string &planner_id, const std::map< std::string, std::string > &group_params, planning_interface::PlannerConfigurationSettings &planner_config)
Load planner configurations for specified group into planner_config.
moveit::core::RobotModelConstPtr robot_model_
The kinematic model for which motion plans are computed.
const std::string parameter_namespace_
The ROS node.
ModelBasedPlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req) const
void loadPlannerConfigurations()
Configure the planners.
OMPLInterface(const moveit::core::RobotModelConstPtr &robot_model, const rclcpp::Node::SharedPtr &node, const std::string ¶meter_namespace)
Initialize OMPL-based planning for a particular robot model. ROS configuration is read from the speci...
ModelBasedPlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::msg::MoveItErrorCodes &error_code, const rclcpp::Node::SharedPtr &node, bool use_constraints_approximations) const
Returns a planning context to OMPLInterface, which in turn passes it to OMPLPlannerManager.
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap &pconfig)
Specify configurations for the planners.
locale-agnostic conversion functions from floating point numbers to strings
The constraint samplers namespace contains a number of methods for generating samples based on a cons...
std::string toString(double d)
Convert a double to std::string using the classic C locale.
The MoveIt interface to OMPL.
std::map< std::string, PlannerConfigurationSettings > PlannerConfigurationMap
Map from PlannerConfigurationSettings.name to PlannerConfigurationSettings.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
This namespace includes the central class for representing planning contexts.
Specify the settings for a particular planning algorithm, for a particular group. The Planner plugin ...
std::map< std::string, std::string > config
Key-value pairs of settings that get passed to the planning algorithm.
std::string group
The group (as defined in the SRDF) this configuration is meant for.