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

Fix getLinkModelNamesWithCollisionGeometry to include the base link #2660

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

MarqRazz
Copy link
Contributor

@MarqRazz MarqRazz commented Jan 24, 2024

Description

I was working on an MTC task a while ago where I was manually modifying the planning scene. In my program I was calling getLinkModelNamesWithCollisionGeometry() on the JointModelGroup to get the links of the manipulator that had collision geometry and noticed that the base link of the group is never included. This caused planning problems like this while I was debugging...
collision_issue

To test this change out I modified the moveit2_tutorial Robot Model and Robot State where I asked it to print the results of getLinkModelNamesWithCollisionGeometry and with this new change it now includes panda_link0 🥇

RCLCPP_INFO(LOGGER, "Joint model group `panda_arm` collision links:");
std::vector<std::string> collision_link_model_names = joint_model_group->getLinkModelNamesWithCollisionGeometry();
for (const auto& name : collision_link_model_names)
{
    RCLCPP_INFO(LOGGER, "Link with collision: %s", name.c_str());
}

Output:
Joint model group `panda_arm` collision links:
  Link with collision: panda_link0
  Link with collision: panda_link1
  Link with collision: panda_link2
  Link with collision: panda_link3
  Link with collision: panda_link4
  Link with collision: panda_link5
  Link with collision: panda_link6
  Link with collision: panda_link7

Very small nitpick but I have also noticed that in Rviz the base link is not highlighted for the goal pose which shows that it is not include in the group when using the motion planning widget.
image

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@MarqRazz MarqRazz requested a review from tylerjw January 24, 2024 20:11
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4c024bc) 51.15% compared to head (bb6b86f) 51.15%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2660      +/-   ##
==========================================
+ Coverage   51.15%   51.15%   +0.01%     
==========================================
  Files         393      393              
  Lines       32749    32753       +4     
==========================================
+ Hits        16750    16753       +3     
- Misses      15999    16000       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MarqRazz
Copy link
Contributor Author

Closes #2325

Copy link
Contributor

@sjahr sjahr left a comment

Choose a reason for hiding this comment

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

Makes sense to me, thanks for fixing it!

@MarqRazz MarqRazz merged commit 4e58ff1 into moveit:main Jan 25, 2024
12 checks passed
@MarqRazz MarqRazz deleted the pr-fix_model_with_collision branch January 25, 2024 17:03
@@ -229,6 +229,14 @@ JointModelGroup::JointModelGroup(const std::string& group_name, const srdf::Mode
{
link_model_map_[link_model->getName()] = link_model;
link_model_name_vector_.push_back(link_model->getName());
// if this is the first link of the group with a valid parent and includes geometry (for example `base_link`) it should included
if (link_model_with_geometry_vector_.empty() && link_model->getParentLinkModel() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is the correct approach. There can be more than one discrete subtree in a group, this would only consider the first one.

We discussed a similar issue I observed in moveit/moveit#3570

I think the previous version of the code is correct for is_chain_ == false (a list of <link> or <joint> tags in SRDF) but not for the case of <chain> where the root link is included but not parent joint.

Copy link
Contributor

@sjahr sjahr Mar 25, 2024

Choose a reason for hiding this comment

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

Oh you're right, thanks for pointing that out! Do you think we should revert this change for now or just add a check for is_chain_?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this is getting surprisingly complicated ... is_chain_ is not passed to the constructor but guessed about near the end of the constructor. They might be different things altogether?

According to the code in RobotModel a chain as specified in SRDF could also go from finger_1_tip to finger_2_tip with the root being somewhere in the middle (eg the wrist).

Maybe a list of links should also get passed in to the constructor.

I'm also not yet sure how this relates to collision checking and what the problem actually was.

@simonschmeisser
Copy link
Contributor

Could you please add your SRDF?

@sjahr
Copy link
Contributor

sjahr commented Mar 25, 2024

Could you please add your SRDF?

Unfortunately, I don't have access to it

@MarqRazz
Copy link
Contributor Author

MarqRazz commented Mar 27, 2024

Here is the SRDF for the Panda arm.

Prior to this PR if you were to request the link models with collision geometry
std::vector<std::string> collision_link_model_names = joint_model_group->getLinkModelNamesWithCollisionGeometry();
it would not include the base frame panda_link0 which you can see is part of the panda_arm joint model group. I was only trying to fix this function call to return a valid list. In my original use case with the robot on a rail (which was also build with <chain>) I was manually enabling and disabling collisions given the result from getLinkModelNamesWithCollisionGeometry which is why I noticed the issue.

@simonschmeisser
Copy link
Contributor

Good to know that the collision checking failure was caused by workarounds. I tested a bit with a similar setup today (MoveIt1) but couldn't notice anything broken.

I think this fix adds regressions if:

  • group is specified via , then the parent should obviously be excluded
  • group is specified via , then the convention as documented is to include only the child links
  • group is chain but ^ shaped, then some link will be duplicated in the list

And does not fix

  • more than one "vertical" chain is specified, then only one will be corrected

Most likely the list of links should be passed into the constructor and the special casing for be done in RobotModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getLinkModelNamesWithCollisionGeometry() does not include base_link of robot
3 participants