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

Mujoco parser: improve error message for "size from mesh" #22389

Merged

Conversation

RussTedrake
Copy link
Contributor

@RussTedrake RussTedrake commented Jan 3, 2025

Towards #20444. Related to #22372.

+@rpoyner-tri for feature review, please.


This change is Reviewable

@RussTedrake RussTedrake added the release notes: fix This pull request contains fixes (no new features) label Jan 3, 2025
Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 unresolved discussion, needs at least two assigned reviewers


a discussion (no related file):
nit: consider adding (a) test case(s) to detail_mujoco_parser_test to to exercise the new error.

Copy link
Contributor Author

@RussTedrake RussTedrake left a comment

Choose a reason for hiding this comment

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

Reviewable status: LGTM missing from assignee jwnimmer-tri(platform)


a discussion (no related file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

nit: consider adding (a) test case(s) to detail_mujoco_parser_test to to exercise the new error.

Done.

+@jwnimmer-tri for platform review, please (per rotation)

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform)


multibody/parsing/detail_mujoco_parser.cc line 688 at r2 (raw file):
The listing of types here seems extraordinarily brittle, and I'm not even sure the logic is correct. The spec says that:

[mesh] can also be specified if the geom type corresponds to a geometric primitive, namely one of “sphere”, “capsule”, “cylinder”, “ellipsoid”, “box”.

The hard-coded list of types in the if-test here seems to be all of the known types from our if-else chain over the next 120 lines, excepting the types the spec calls out in the quote. That means if we add more (non-primitive) types to the if-else chain below, we would also need to remember to fix this spot, but that's not very likely to be noticed.

Wouldn't it be a much more robust phrasing go like this?

If has_mesh_attribute is True, then:

(1) if type is "mesh" then proceed without remark; else

(2) if type is “sphere”, “capsule”, “cylinder”, “ellipsoid”, or “box” then report Error() with message citing 22372; else

(3) report Error() that "mesh" is not allowed on this $type (e.g., a plane).

Phrasing the code an an allow-list that matches the spec exactly seems a lot better long-term.

If you agree with behavior (3) then we'll also need a (small) unit test case for trying to specify the mesh for a plane and/or hfield.

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform)


multibody/parsing/detail_mujoco_parser.cc line 688 at r2 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

The listing of types here seems extraordinarily brittle, and I'm not even sure the logic is correct. The spec says that:

[mesh] can also be specified if the geom type corresponds to a geometric primitive, namely one of “sphere”, “capsule”, “cylinder”, “ellipsoid”, “box”.

The hard-coded list of types in the if-test here seems to be all of the known types from our if-else chain over the next 120 lines, excepting the types the spec calls out in the quote. That means if we add more (non-primitive) types to the if-else chain below, we would also need to remember to fix this spot, but that's not very likely to be noticed.

Wouldn't it be a much more robust phrasing go like this?

If has_mesh_attribute is True, then:

(1) if type is "mesh" then proceed without remark; else

(2) if type is “sphere”, “capsule”, “cylinder”, “ellipsoid”, or “box” then report Error() with message citing 22372; else

(3) report Error() that "mesh" is not allowed on this $type (e.g., a plane).

Phrasing the code an an allow-list that matches the spec exactly seems a lot better long-term.

If you agree with behavior (3) then we'll also need a (small) unit test case for trying to specify the mesh for a plane and/or hfield.

Or maybe (3) is a warning, not an error? I don't know the nominal MuJoCo parser policy when we encounter elements not specified in the schema.

Copy link
Contributor Author

@RussTedrake RussTedrake left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignee jwnimmer-tri(platform)


multibody/parsing/detail_mujoco_parser.cc line 688 at r2 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Or maybe (3) is a warning, not an error? I don't know the nominal MuJoCo parser policy when we encounter elements not specified in the schema.

Done. (the mujoco parser throws an error, so i have, too)
https://github.com/google-deepmind/mujoco/blob/69c9ac074a7f54c7f9b7619b8bcc3d0eb69bfbcd/src/user/user_mesh.cc#L744

Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),jwnimmer-tri(platform)

@RussTedrake RussTedrake merged commit 21da721 into RobotLocomotion:master Jan 5, 2025
10 checks passed
@RussTedrake RussTedrake deleted the mujoco_capsule_size branch January 5, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: fix This pull request contains fixes (no new features)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants