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

parser_urdf: add //frame for reduced links/joints #1148

Merged
merged 4 commits into from
Sep 29, 2022

Conversation

scpeters
Copy link
Member

@scpeters scpeters commented Sep 16, 2022

🎉 New feature

Retain frame information from URDF fixed joints that are not preserved, related to #1110

Summary

Currently the location of some links and joints is lost when fixed joints are reduced and links lumped together. For example, the first snippet below is a URDF with two links outlined in red and a fixed joint outlined in blue. The child link has a visual outlined in green. The second snippet shows what results when converting to SDFormat, with the fixed joint and child link removed, and the visual moved to the parent link.

fixed_joint_simple_urdf

fixed_joint_simple_sdf

This process of "fixed joint reduction" reduces the complexity of a simulation, particularly for solvers using maximal coordinates, but it does lose some frame information. This pull request adds //model/frame tags with the same name and pose of the reduced links and joints. For example, the following would be added for the examples shown above.

    <frame name='fixed_joint' attached_to='base'>
      <pose>0 0 0 0 0 0</pose>
    </frame>
    <frame name='child_link' attached_to='fixed_joint'>
      <pose>0 0 0 0 0 0</pose>
    </frame>

Test it

Compile and run INTEGRATION_urdf_gazebo_extensions

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@scpeters scpeters requested a review from azeey as a code owner September 16, 2022 16:29
@codecov
Copy link

codecov bot commented Sep 16, 2022

Codecov Report

Merging #1148 (2e9f08e) into sdf9 (b7f0cba) will increase coverage by 0.11%.
The diff coverage is 91.30%.

@@            Coverage Diff             @@
##             sdf9    #1148      +/-   ##
==========================================
+ Coverage   87.82%   87.94%   +0.11%     
==========================================
  Files          64       64              
  Lines       10095    10118      +23     
==========================================
+ Hits         8866     8898      +32     
+ Misses       1229     1220       -9     
Impacted Files Coverage Δ
src/parser_urdf.cc 85.15% <91.30%> (+0.79%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Base automatically changed from scpeters/fix_urdf_gz_ext_test to sdf9 September 21, 2022 21:21
Currently the location of some links and joints is lost
when fixed joints are reduced and links lumped together.
This adds //model/frame tags with the same name and
pose of the reduced links and joints.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters scpeters force-pushed the scpeters/urdf_fixed_joint_frames_9 branch from 7760525 to 8b3c2ad Compare September 21, 2022 22:32
@scpeters
Copy link
Member Author

this is ready for review now that #1126 has been merged

Copy link
Contributor

@adityapande-1995 adityapande-1995 left a comment

Choose a reason for hiding this comment

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

Looks good to me !

ASSERT_NE(nullptr, link);
auto massMatrix = link->Inertial().MassMatrix();
EXPECT_DOUBLE_EQ(2.0, massMatrix.Mass());
EXPECT_EQ(2.0 * ignition::math::Matrix3d::Identity, massMatrix.Moi());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit : Can this be changed to gz namespace ? I guess not, since this is targeting an older sdf branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

it would be possible, but we would also have to bump the minimum required version of ignition-math6 to 6.13.0. These changes are already being handled in #1118, and it's slightly simpler for VIPER if we can merge this PR without the gz:: namespaces, so I'd prefer to defer that change for now

@scpeters scpeters added 🏰 citadel Ignition Citadel Gazebo 1️1️ Dependency of Gazebo classic version 11 labels Sep 28, 2022
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Just a few minor comments. Otherwise, this is a nice feature and LGTM!

Comment on lines 443 to 451
// Ensure model extension vector is allocated
if (g_extensions.find("") == g_extensions.end())
{
std::vector<SDFExtensionPtr> ge;
g_extensions.insert(std::make_pair("", ge));
}

// Add //frame tags to model extension vector
g_extensions.at("").push_back(sdfExt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: This would do the same thing, I believe.

Suggested change
// Ensure model extension vector is allocated
if (g_extensions.find("") == g_extensions.end())
{
std::vector<SDFExtensionPtr> ge;
g_extensions.insert(std::make_pair("", ge));
}
// Add //frame tags to model extension vector
g_extensions.at("").push_back(sdfExt);
g_extensions[""].push_back(sdfExt);

Copy link
Member Author

Choose a reason for hiding this comment

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

good call: simplified in 2e9f08e

auto stringToExtension = [&sdfExt](const std::string &_frame)
{
TiXmlDocument xmlNewDoc;
xmlNewDoc.Parse(_frame.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible for this to fail? i.e, do we need to check if xmlNewDoc.FirstChildElement() is nullptr?

Copy link
Member Author

@scpeters scpeters Sep 28, 2022

Choose a reason for hiding this comment

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

there's lots of places where we aren't doing proper error checking, but I've added some for this new code in 2e9f08e


sdf::ElementPtr model = robot->Root()->GetElement("model");
auto modelDom = root.ModelByIndex(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add an assertion on modelDom.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 2e9f08e

</joint>
<link name="rotary_link">
<inertial>
<mass value="12"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment that this <inertial> is set with the expected value of the <inerital> of base and intermediate_link combined?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some clarifying comments about the model in 2e9f08e, including what you have suggested here

EXPECT_EQ(1u, model->LinkCount());
EXPECT_TRUE(model->LinkNameExists("base"));

// Expect MassMatrix3 values to match for links
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove?

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 2e9f08e

* Check for tinyxml2 parsing errors
* Simplify map logic
* Add comments to example URDF
* Assert point is valid in test
* Remove outdated comment

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters scpeters merged commit 26569a5 into sdf9 Sep 29, 2022
@scpeters scpeters deleted the scpeters/urdf_fixed_joint_frames_9 branch September 29, 2022 01:56
scpeters added a commit that referenced this pull request Sep 30, 2022
Follow-up for #1148 with a cleaner implementation for
the sdf13 branch that constructs sdf::Frame objects
and serializes them to a string rather than using
a stringstream to construct XML.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel Gazebo 1️1️ Dependency of Gazebo classic version 11
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants