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

Use //link/inertial/density for auto-inertials #1335

Merged
merged 14 commits into from
Feb 2, 2024

Conversation

scpeters
Copy link
Member

@scpeters scpeters commented Oct 8, 2023

🎉 New feature

Closes #1329. cc @jasmeet0915

Summary

This adds support for specifying density and auto_inertia_params in the //link/inertial/density and //link/inertial/auto_inertia_params elements respectively, which will apply to all collisions within a link. The following APIs are added:

  • static double Collision::DensityDefault(): accessor for default density value
  • overload of Collision::CalculateInertial with a std::optional<double> input to represent the value from //link/inertial/density if it has been set and an sdf::ElementPtr to the <auto_inertia_params> element or nullptr if it has not been set
  • double Link::Density() const
  • void Link::SetDensity(double)
  • sdf::ElementPtr AutoInertiaParams() const
  • void SetAutoInertiaParams(const sdf::ElementPtr)

The density precedence for Collisions is now:

  1. Density explicitly set in //collision/density or by Collision::SetDensity.
  2. Density explicitly set in //link/inertial/density or by Link::SetDensity.
  3. Default density in Collision::DensityDefault().

The following table summarizes this behavior:

Density to use Collision density set Collision density not set
Link density set Collision density Link density
Link density not set Collision density Default density

The precedence rules for AutoInertiaParams match the rules for density.

Test it

A test has has been added in UNIT_Link_TEST with the 4 combinations of link / collision density being set or not from the table above. Also the test/sdf/inertial_stats_auto.sdf file, which is tested with gz sdf --inertial-stats in UNIT_gz_TEST, is modified so that a //collision/density value is converted to //link/inertial/density, and the test still passes.

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.

The density precedence for Collisions is now:
1. Density explicitly set in //collision/density
   or by Collision::SetDensity.
2. Density explicitly set in //link/inertial/density
   or by Link::SetDensity.
3. Default density in Collision::DensityDefault().

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c3960a5) 92.40% compared to head (5bd4dc2) 92.42%.
Report is 6 commits behind head on sdf14.

Additional details and impacted files
@@            Coverage Diff             @@
##            sdf14    #1335      +/-   ##
==========================================
+ Coverage   92.40%   92.42%   +0.01%     
==========================================
  Files         134      134              
  Lines       17674    17707      +33     
==========================================
+ Hits        16332    16365      +33     
  Misses       1342     1342              

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

@azeey
Copy link
Collaborator

azeey commented Oct 27, 2023

Per #1330 (comment), and #1330 (comment) could we pass along the //link/inertial/auto_inertia_params in the new member function and avoid needing yet another overload?

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Pass //link/inertial/auto_inertia_params ElementPtr to
Collision::CalculateInertial and use it if the
Collision does not have auto_inertia_params of its own.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

Per #1330 (comment), and #1330 (comment) could we pass along the //link/inertial/auto_inertia_params in the new member function and avoid needing yet another overload?

good call, thanks for the reminder

I've started work in scpeters/inertial_density...scpeters/inertial_density_auto_params, but I didn't write the test yet, since I think it will need a mock Geometry class in order to confirm which ElementPtr is passed to CalculateInertial.

@azeey
Copy link
Collaborator

azeey commented Nov 30, 2023

Per #1330 (comment), and #1330 (comment) could we pass along the //link/inertial/auto_inertia_params in the new member function and avoid needing yet another overload?

good call, thanks for the reminder

I've started work in scpeters/inertial_density...scpeters/inertial_density_auto_params, but I didn't write the test yet, since I think it will need a mock Geometry class in order to confirm which ElementPtr is passed to CalculateInertial.

Instead of a mock Geometry class, would it be easier to provide a mesh inertia calculator callback in the test that will receive the autoInertiaParams and check to see if it's the one from the link? i.e,

this->dataPtr->mesh->CalculateInertial(_errors, _density,
will eventually call the callback provided by the test with the autoInertiaParams passed to Geometry.

The FilePath refers to the SDFormat file that the
Mesh object was parsed from, not the Mesh file itself,
so remove the unrelated warning.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

Instead of a mock Geometry class, would it be easier to provide a mesh inertia calculator callback in the test that will receive the autoInertiaParams and check to see if it's the one from the link? i.e,

this->dataPtr->mesh->CalculateInertial(_errors, _density,

will eventually call the callback provided by the test with the autoInertiaParams passed to Geometry.

I adapted the lambda callback from Geometry_TEST.cc for an auto_inertia_params test in 4eae4b8 and merged in the other changes from that branch

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

I fixed a compiler warning and coverage; CI is happy now

src/Collision.cc Show resolved Hide resolved
src/Collision.cc Show resolved Hide resolved
src/Link_TEST.cc Outdated Show resolved Hide resolved
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
A density element was written unconditionally,
even if it was not originally set by the user.
This checks the optional density value before setting
via ToElement().

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters scpeters merged commit f360776 into sdf14 Feb 2, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Use //link/inertial/density element in parser
2 participants