Skip to content

Commit

Permalink
Sort constraints for reduced cardinality
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Nov 21, 2023
1 parent 6e5b963 commit 636b4d5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions nexus_motion_planner/src/motion_plan_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using warehouse_ros::MessageWithMetadata;
using warehouse_ros::Metadata;
using warehouse_ros::Query;

// Utils =======================================================================

// Append a range inclusive query with some tolerance about some center value.
void queryAppendRangeInclusiveWithTolerance(
Query& query, const std::string& name, double center, double tolerance)
Expand All @@ -38,6 +40,42 @@ void queryAppendRangeInclusiveWithTolerance(
name, center - tolerance / 2, center + tolerance / 2);
}

// Sort constraint components by joint or link name.
void sort_constraints(
std::vector<moveit_msgs::msg::JointConstraint>& joint_constraints,
std::vector<moveit_msgs::msg::PositionConstraint>& position_constraints,
std::vector<moveit_msgs::msg::OrientationConstraint>& orientation_constraints)
{
std::sort(
joint_constraints.begin(), joint_constraints.end(),
[](
const moveit_msgs::msg::JointConstraint& l,
const moveit_msgs::msg::JointConstraint& r)
{
return l.joint_name < r.joint_name;
});

std::sort(
position_constraints.begin(), position_constraints.end(),
[](
const moveit_msgs::msg::PositionConstraint& l,
const moveit_msgs::msg::PositionConstraint& r)
{
return l.link_name < r.link_name;
});

std::sort(
orientation_constraints.begin(), orientation_constraints.end(),
[](
const moveit_msgs::msg::OrientationConstraint& l,
const moveit_msgs::msg::OrientationConstraint& r)
{
return l.link_name < r.link_name;
});
}

// Motion Plan Cache ===========================================================

MotionPlanCache::MotionPlanCache(const rclcpp::Node::SharedPtr& node)
: node_(node)
{
Expand Down Expand Up @@ -417,6 +455,10 @@ MotionPlanCache::extract_and_append_plan_goal_to_query(
{
orientation_constraints.push_back(orientation_constraint);
}

// Also sort for even less cardinality.
sort_constraints(
joint_constraints, position_constraints, orientation_constraints);
}

// Joint constraints
Expand Down Expand Up @@ -742,6 +784,10 @@ MotionPlanCache::extract_and_append_plan_goal_to_metadata(
{
orientation_constraints.push_back(orientation_constraint);
}

// Also sort for even less cardinality.
sort_constraints(
joint_constraints, position_constraints, orientation_constraints);
}

// Joint constraints
Expand Down

0 comments on commit 636b4d5

Please sign in to comment.