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

[dartsim] Add empty nested model construction and nested model entity management #228

Merged
merged 18 commits into from
Mar 23, 2021

Conversation

azeey
Copy link
Contributor

@azeey azeey commented Mar 17, 2021

🎉 New feature

Summary

This adds two new features:

  1. ConstructEmptyNestedModelFeature, which allows users to create a nested model without having to use ConstructSdfNestedModel
  2. GetNestedModelFromModel, which allow retrieving a nested model from it's parent Model entity.

Requires:

Test it

Run tests

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • 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

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
We do this by keeping track of links separately from DART so that APIs
such as `Model::GetLink()` and `Link::GetIndex` are not affected by
BodyNode's moving from one skeleton to another when a joint is created
between different (nested) models.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey azeey requested a review from mxgrey as a code owner March 17, 2021 11:24
@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Mar 17, 2021
@chapulina chapulina added DART DART engine enhancement New feature or request beta Targeting beta release of upcoming collection labels Mar 17, 2021
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
…ties

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@adlarkin adlarkin self-requested a review March 22, 2021 17:18
Copy link
Contributor

@adlarkin adlarkin left a comment

Choose a reason for hiding this comment

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

Looks pretty good! I have a few comments, and also asked a few questions to help me get a better grasp of ign-physics (I'm still trying to familiarize myself with the repository).

include/ignition/physics/ConstructEmpty.hh Show resolved Hide resolved
include/ignition/physics/ConstructEmpty.hh Outdated Show resolved Hide resolved
include/ignition/physics/GetEntities.hh Outdated Show resolved Hide resolved
@@ -213,6 +213,56 @@ namespace ignition
};
};

/////////////////////////////////////////////////
/// \brief This feature retrieves the nested model pointer from the parent
/// model by specifying the model index and model index/name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// model by specifying the model index and model index/name.
/// model by specifying the parent model index and nested model index/name.

I found it a little confusing to read "model index" twice - should one be referring to the parent model, and the other to the nested model?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably supposed to say

/// \brief This feature retrieves the nested model pointer from the parent
/// model by specifying the index or name of the nested model.

From the user's point of view, the parent model does not need to be specified, so I would recommend not mentioning that in the public API documentation, as it may be misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to say "...name or index of the nested model". b836a0a

dartsim/src/Base.hh Show resolved Hide resolved
dartsim/src/EntityManagementFeatures.cc Outdated Show resolved Hide resolved
Comment on lines 433 to 435
return this->AddModel( // NOLINT
{model, _sdfModel.Name(), modelFrame, _sdfModel.CanonicalLinkName()},
_parentID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return this->AddModel( // NOLINT
{model, _sdfModel.Name(), modelFrame, _sdfModel.CanonicalLinkName()},
_parentID);
return this->AddModel( // NOLINT
{model, _sdfModel.Name(), modelFrame, _sdfModel.CanonicalLinkName()},
_parentID, worldID);

I believe the world ID parameter is missing here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not that worldID is missing, but rather _parentID should be replaced with worldID.

Copy link
Contributor

Choose a reason for hiding this comment

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

After looking at the code further, it does appear to be correct, although I would urge some caution because the type of entity that _parentID refers to is conditional. It may refer to a world or a model depending on whether the model that's being constructed is nested. This may be a strong recipe for some maintenance confusion and a future bug creeping in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is _parentID and worldID are the same if the model is not nested. But I agree it is confusing. I changed it to worldID in 212c941.

This may be a strong recipe for some maintenance confusion and a future bug creeping in.

I agree. FWIW, this was done to avoid code duplication between ConstructSdfModel and ConstructSdfNestedModel where unlike ConstructEmptyNestedModel, ConstructSdfNestedModel is a feature that can construct a model and it's nested models from sdf::Model. i.e, ConstructSdfNestedModel is the same as ConstructSdfModel but can also handle nested models if they exist in the input sdf::Model.

dartsim/src/EntityManagement_TEST.cc Outdated Show resolved Hide resolved
dartsim/src/EntityManagement_TEST.cc Show resolved Hide resolved
/// Index of the model within this model.
/// \return A model reference. If _index is GetModelCount() or higher,
/// this will be a nullptr.
public: ModelPtrType GetModel(std::size_t _index);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest making this function more explicit by calling it GetNestedModel. Same for the overloads of GetModel below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in d137bba. Also made the same change to ConstructEmptyNestedModel.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey
Copy link
Contributor Author

azeey commented Mar 23, 2021

I believe I have addressed all the feedback. Please take a look.

@azeey azeey merged commit 246909b into gazebosim:main Mar 23, 2021
@azeey azeey deleted the dartsim_nested_entities branch March 23, 2021 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection DART DART engine 🏢 edifice Ignition Edifice enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants