Skip to content

[multibody] Throw if CalcSpatialInertia frame is not in the plant - #24934

Open
castor639 wants to merge 2 commits into
RobotLocomotion:masterfrom
castor639:calc-spatial-inertia-frame-check
Open

[multibody] Throw if CalcSpatialInertia frame is not in the plant#24934
castor639 wants to merge 2 commits into
RobotLocomotion:masterfrom
castor639:calc-spatial-inertia-frame-check

Conversation

@castor639

@castor639 castor639 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Validate that frame_F belongs to this MultibodyTree before computing spatial inertia, so an unowned FixedOffsetFrame throws instead of segfaulting.

Fixes #22636.


This change is Reviewable

Validate that frame_F belongs to this MultibodyTree before computing
spatial inertia, so an unowned FixedOffsetFrame throws instead of
segfaulting.

Fixes RobotLocomotion#22636.
@SeanCurtis-TRI SeanCurtis-TRI added the release notes: fix This pull request contains fixes (no new features) label Sep 1, 2026
@SeanCurtis-TRI SeanCurtis-TRI self-assigned this Sep 1, 2026
@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

+(release notes: fix) +a:@SeanCurtis-TRI

@SeanCurtis-TRI SeanCurtis-TRI added the status: single reviewer ok https://drake.mit.edu/reviewable.html label Sep 1, 2026

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+(status: single reviewer ok)

:LGTM:

@SeanCurtis-TRI reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignee SeanCurtis-TRI(platform) (waiting on castor639).

@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

@drake-jenkins-bot test this please

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@SeanCurtis-TRI made 1 comment.
Reviewable status: 1 unresolved discussion (waiting on castor639).


multibody/plant/multibody_plant.h line 4165 at r1 (raw file):

  /// @param[in] context Contains the configuration of the set S of bodies.
  /// @param[in] frame_F specifies the about-point Fo (frame_F's origin) and
  ///  the expressed-in frame for the returned spatial inertia.

nit: CI is failling because this change to the header requires a rebuild of drake docs:

bazel run //bindings/generated_docstrings:regenerate

Then include the changed file in this commit.

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@SeanCurtis-TRI reviewed 1 file and all commit messages.
Reviewable status: 1 unresolved discussion, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on castor639).

@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

@drake-jenkins-bot retest this please

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI Failure in //multibody/plant:fused_welds_test. That body was not expecting the newly introduced throw. The FusedTest.CompositeSpatialInertia test needs to be updated.

@SeanCurtis-TRI made 2 comments.
Reviewable status: 2 unresolved discussions, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on castor639).


multibody/plant/test/multibody_plant_momentum_energy_test.cc line 340 at r2 (raw file):

      "CalcSpatialInertia\\(\\): contains a repeated BodyIndex.*");

  // Verify an exception is thrown if frame_F was never added to the plant

nit: Failure based on introduction of lint on this file. FIx via:

bazel-bin/tools/lint/clang-format -style=file -i multibody/plant/test/multibody\_plant\_momentum\_energy\_test.cc

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) status: single reviewer ok https://drake.mit.edu/reviewable.html

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CalcSpatialInertia segfaults if passed a frame that isn't part of the plant

2 participants