Skip to content

Commit f2a0844

Browse files
henningkaysermergify[bot]
authored andcommitted
Handle unsupported position constraints in OMPL (#2417)
* Handle unsupported position constraints in OMPL OMPL constrained planning assumes that all position constraints have three dimensions, meaning that they are represented by a BOX bounding volume. If another shape is used (like a SPHERE from moveit_core/kinematic_constraints/utils.hpp), the constraint adapter implementation will produce a segfault because of the lack of dimensions. This fix prevents this by checking for the required BOX type. * Add warning if more than one position primitive is used --------- Co-authored-by: Sebastian Jahr <[email protected]> (cherry picked from commit b0401e9) # Conflicts: # moveit_planners/ompl/ompl_interface/src/detail/ompl_constraints.cpp
1 parent d1e097a commit f2a0844

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

moveit_planners/ompl/ompl_interface/src/detail/ompl_constraints.cpp

+47-13
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,15 @@ ompl::base::ConstraintPtr createOMPLConstraints(const moveit::core::RobotModelCo
364364
const std::string& group,
365365
const moveit_msgs::msg::Constraints& constraints)
366366
{
367-
// TODO(bostoncleek): does this reach the end w/o a return ?
368-
369-
const std::size_t num_dofs = robot_model->getJointModelGroup(group)->getVariableCount();
370-
const std::size_t num_pos_con = constraints.position_constraints.size();
371-
const std::size_t num_ori_con = constraints.orientation_constraints.size();
372-
373367
// This factory method contains template code to support position and/or orientation constraints.
374368
// If the specified constraints are invalid, a nullptr is returned.
375369
std::vector<ompl::base::ConstraintPtr> ompl_constraints;
376-
if (num_pos_con > 1)
370+
const std::size_t num_dofs = robot_model->getJointModelGroup(group)->getVariableCount();
371+
372+
// Parse Position Constraints
373+
if (!constraints.position_constraints.empty())
377374
{
375+
<<<<<<< HEAD
378376
RCLCPP_WARN(LOGGER, "Only a single position constraint is supported. Using the first one.");
379377
}
380378
if (num_ori_con > 1)
@@ -385,27 +383,63 @@ ompl::base::ConstraintPtr createOMPLConstraints(const moveit::core::RobotModelCo
385383
{
386384
BaseConstraintPtr pos_con;
387385
if (constraints.name == "use_equality_constraints")
386+
=======
387+
if (constraints.position_constraints.size() > 1)
388+
>>>>>>> b0401e91a (Handle unsupported position constraints in OMPL (#2417))
389+
{
390+
RCLCPP_WARN(getLogger(), "Only a single position constraint is supported. Using the first one.");
391+
}
392+
393+
const auto& primitives = constraints.position_constraints.at(0).constraint_region.primitives;
394+
if (primitives.size() > 1)
395+
{
396+
RCLCPP_WARN(getLogger(), "Only a single position primitive is supported. Using the first one.");
397+
}
398+
if (primitives.empty() || primitives.at(0).type != shape_msgs::msg::SolidPrimitive::BOX)
388399
{
389-
pos_con = std::make_shared<EqualityPositionConstraint>(robot_model, group, num_dofs);
400+
RCLCPP_ERROR(getLogger(), "Unable to plan with the requested position constraint. "
401+
"Only BOX primitive shapes are supported as constraint region.");
390402
}
391403
else
392404
{
393-
pos_con = std::make_shared<BoxConstraint>(robot_model, group, num_dofs);
405+
BaseConstraintPtr pos_con;
406+
if (constraints.name == "use_equality_constraints")
407+
{
408+
pos_con = std::make_shared<EqualityPositionConstraint>(robot_model, group, num_dofs);
409+
}
410+
else
411+
{
412+
pos_con = std::make_shared<BoxConstraint>(robot_model, group, num_dofs);
413+
}
414+
pos_con->init(constraints);
415+
ompl_constraints.emplace_back(pos_con);
394416
}
395-
pos_con->init(constraints);
396-
ompl_constraints.emplace_back(pos_con);
397417
}
398-
if (num_ori_con > 0)
418+
419+
// Parse Orientation Constraints
420+
if (!constraints.orientation_constraints.empty())
399421
{
422+
if (constraints.orientation_constraints.size() > 1)
423+
{
424+
RCLCPP_WARN(getLogger(), "Only a single orientation constraint is supported. Using the first one.");
425+
}
426+
400427
auto ori_con = std::make_shared<OrientationConstraint>(robot_model, group, num_dofs);
401428
ori_con->init(constraints);
402429
ompl_constraints.emplace_back(ori_con);
403430
}
404-
if (num_pos_con < 1 && num_ori_con < 1)
431+
432+
// Check if we have any constraints to plan with
433+
if (ompl_constraints.empty())
405434
{
435+
<<<<<<< HEAD
406436
RCLCPP_ERROR(LOGGER, "No path constraints found in planning request.");
437+
=======
438+
RCLCPP_ERROR(getLogger(), "Failed to parse any supported path constraints from planning request.");
439+
>>>>>>> b0401e91a (Handle unsupported position constraints in OMPL (#2417))
407440
return nullptr;
408441
}
442+
409443
return std::make_shared<ompl::base::ConstraintIntersection>(num_dofs, ompl_constraints);
410444
}
411445
} // namespace ompl_interface

moveit_planners/ompl/ompl_interface/src/planning_context_manager.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ PlanningContextManager::getPlanningContext(const planning_interface::PlannerConf
372372
ompl::base::ConstraintPtr ompl_constraint =
373373
createOMPLConstraints(robot_model_, config.group, req.path_constraints);
374374

375+
// Fail if ompl constraints could not be parsed successfully
376+
if (!ompl_constraint)
377+
{
378+
return ModelBasedPlanningContextPtr();
379+
}
380+
375381
// Create a constrained state space of type "projected state space".
376382
// Other types are available, so we probably should add another setting to ompl_planning.yaml
377383
// to choose between them.

0 commit comments

Comments
 (0)