Skip to content

MapQDDotToAcceleration() and MapAccelerationToQDDot() for simple mobilizers #22698

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

Merged
merged 5 commits into from
Mar 7, 2025

Conversation

mitiguy
Copy link
Contributor

@mitiguy mitiguy commented Mar 4, 2025

This is the first PR of several to help address issue #22630. It creates MapQDDotToAcceleration() and MapAccelerationToQDDot() for simple mobilizers.

Subsequent PRs will create helper methods for more complex mobilizers (e.g., rpy_ball_mobilizer, curvilinear_mobilizer, quaternion_floating_mobilizer, etc.) to consolidate creation of the N(q) and N⁺(q) matrices that is shared between MapQDotToVelocity() and MapQDDotToAcceleration() as well as MapVelocityToQDDot() and MapAccelerationToQDDot().

In conjunction with each of the subsequent PRs, each more complex mobilizer will implement its functions MapQDDotToAcceleration() and MapAccelerationToQDDot().

FYI: Since mobilizers are Drake internal classes, after the internal mobilizer work is complete, there will be PRs (code and testing) for the public API in MultibodyPlant to address issue #22630.


This change is Reviewable

@mitiguy mitiguy force-pushed the MapQDDotToVDotMobilizers branch from eec887b to f300ad0 Compare March 4, 2025 22:25
@mitiguy mitiguy changed the title [WIP] Mobilizer functionality for MapQddotToVdot and vice-versa. MapQDDotToAcceleration() and MapAccelerationToQDDot() for simple mobilizers Mar 4, 2025
Copy link
Contributor Author

@mitiguy mitiguy 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: 2 unresolved discussions, LGTM missing from assignee sherm1(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


a discussion (no related file):
Feature review +@sherm1


multibody/tree/mobilizer.h line 618 at r1 (raw file):

                                 EigenPtr<VectorX<T>> v) const = 0;

  // Uses the kinematic mapping `q̈ = N(q)⋅v̇` to calculate q̈ from v̇.

Self-blocking. Remove tic-marks around q̈ = N(q)⋅v̇ here and below.

Copy link
Member

@sherm1 sherm1 left a comment

Choose a reason for hiding this comment

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

PR description should explain what's here and what's not (with what's planned to follow) and give some rationale.

Feature :lgtm: pending some comment cleanups

Reviewed 16 of 16 files at r1, all commit messages.
Reviewable status: 8 unresolved discussions, needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


multibody/tree/mobilizer.h line 618 at r1 (raw file):

                                 EigenPtr<VectorX<T>> v) const = 0;

  // Uses the kinematic mapping `q̈ = N(q)⋅v̇` to calculate q̈ from v̇.

missing term in comment

Suggestion:

q̈=N(q)⋅v̇ + Ṅ(q,v)⋅v to calculate q̈ from v and v̇

multibody/tree/mobilizer.h line 621 at r1 (raw file):

  // @param[in] vdot 1ˢᵗ time derivatives of generalized velocities (v̇).
  // @param[out] qddot 2ⁿᵈ time derivatives of the generalized positions (q̈).
  // Note: Generalized positions and velocities are stored in `context`.

BTW consider naming the variables to match the equations

Suggestion:

positions q and velocities v

multibody/tree/mobilizer.h line 628 at r1 (raw file):

                                      EigenPtr<VectorX<T>> qddot) const;

  // Uses the kinematic mapping `v̇ = N(q)⋅q̈` to calculate v̇ from q̈.

Missing term and wrong matrix!

Per f2f we should write the equations in terms of what the user is supplying in the arguments to these routines: q,v from the context, qddot or vdot as a separate argument. (They never supply qdot)

Suggestion:

v̇ = N⁺(q)⋅q̈ + Ṅ⁺(q,v)⋅q̇ where q̇ = N(q)v

multibody/tree/mobilizer.h line 629 at r1 (raw file):

  // Uses the kinematic mapping `v̇ = N(q)⋅q̈` to calculate v̇ from q̈.
  // @param[in] qddot 2ⁿᵈ time derivatives of the generalized positions (q̈).

BTW consider disambiguating (I thought at first the symbol was supposed to be generalized positions since that's what it was next to)
(same elsewhere)

Suggestion:

qddot 2ⁿᵈ time derivatives q̈ of the generalized positions q.

multibody/tree/mobilizer.h line 636 at r1 (raw file):

  virtual void MapQDDotToAcceleration(const systems::Context<T>& context,
                                      const Eigen::Ref<const VectorX<T>>& qddot,
                                      EigenPtr<VectorX<T>> v) const;

nit: v -> vdot


multibody/tree/prismatic_mobilizer.h line 184 at r1 (raw file):

  // Computes the kinematic mapping from generalized velocities v to time
  // derivatives of the generalized positions `q̇`. For this mobilizer `q̇ = v`.

BTW you didn't clean up the old comments here to match the new ones as you did for planar & screw


multibody/tree/revolute_mobilizer.h line 187 at r1 (raw file):

  bool is_velocity_equal_to_qdot() const override { return true; }

  void MapVelocityToQDot(const systems::Context<T>& context,

BTW you didn't add old comments here to match the new ones like in planar & screw

Copy link
Member

@sherm1 sherm1 left a comment

Choose a reason for hiding this comment

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

Should be release notes: none since this is all internal. It's not a real feature until users can get to it through the public API (Joint).

Reviewable status: 8 unresolved discussions, needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)

@sherm1 sherm1 added release notes: none This pull request should not be mentioned in the release notes and removed release notes: feature This pull request contains a new feature labels Mar 5, 2025
Copy link
Contributor Author

@mitiguy mitiguy left a comment

Choose a reason for hiding this comment

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

@sherm1 Thanks for the review. PTAL after it (hopefully) passes CI.

Reviewable status: 2 unresolved discussions, needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


multibody/tree/mobilizer.h line 618 at r1 (raw file):

Previously, mitiguy (Mitiguy) wrote…

Self-blocking. Remove tic-marks around q̈ = N(q)⋅v̇ here and below.

Done.


multibody/tree/mobilizer.h line 618 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

missing term in comment

Done with slightly different wording.


multibody/tree/mobilizer.h line 621 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW consider naming the variables to match the equations

Done with slightly different wording.


multibody/tree/mobilizer.h line 628 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

Missing term and wrong matrix!

Per f2f we should write the equations in terms of what the user is supplying in the arguments to these routines: q,v from the context, qddot or vdot as a separate argument. (They never supply qdot)

Done with slightly different wording.


multibody/tree/mobilizer.h line 629 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW consider disambiguating (I thought at first the symbol was supposed to be generalized positions since that's what it was next to)
(same elsewhere)

Done with slightly different wording.


multibody/tree/mobilizer.h line 636 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

nit: v -> vdot

Done.


multibody/tree/prismatic_mobilizer.h line 184 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW you didn't clean up the old comments here to match the new ones as you did for planar & screw

Done.


multibody/tree/revolute_mobilizer.h line 187 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW you didn't add old comments here to match the new ones like in planar & screw

Done.

Copy link
Member

@sherm1 sherm1 left a comment

Choose a reason for hiding this comment

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

The PR description only talks about mobilizers, which are internal. The original issue #22630 needs a public API in MultibodyPlant. These first PRs are just internal, but there should be some mention of the end game.

Feature :lgtm:

+@xuchenhan-tri for platform review per rotation, please

Reviewed 3 of 3 files at r2, all commit messages.
Reviewable status: 4 unresolved discussions, LGTM missing from assignee xuchenhan-tri(platform), commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


multibody/tree/mobilizer.h line 618 at r2 (raw file):

                                 EigenPtr<VectorX<T>> v) const = 0;

  // Calculates q̈ from v̇ and v using q̈ = N(q)⋅v̇ + Ṅ(q,v)⋅v.

BTW should list q as well (below also)

Suggestion:

Calculates q̈ from v̇, v, and q

multibody/tree/revolute_mobilizer.h line 187 at r2 (raw file):

  bool is_velocity_equal_to_qdot() const override { return true; }

  // Maps v to qdot, which for this mobilizer is q̇ = v̇.

minor: should be v rather than vdot


multibody/tree/prismatic_mobilizer.h line 183 at r2 (raw file):

  bool is_velocity_equal_to_qdot() const override { return true; }

  // Maps v to qdot, which for this mobilizer is q̇ = v̇.

minor: should be v rather than vdot

Suggestion:

q̇ = v

Copy link
Contributor

@xuchenhan-tri xuchenhan-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: platform

Reviewed 13 of 16 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: 5 unresolved discussions, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


multibody/tree/planar_mobilizer.cc line 192 at r2 (raw file):

    const systems::Context<T>&, const Eigen::Ref<const VectorX<T>>& vdot,
    EigenPtr<VectorX<T>> qddot) const {
  DRAKE_ASSERT(vdot.size() == kNv);

BTW, it looks like these validity checks are spread across all derived classes. Is it possible to do this in MobilizerImpl?

@mitiguy mitiguy force-pushed the MapQDDotToVDotMobilizers branch from 50431cd to 11b4449 Compare March 7, 2025 00:52
Copy link
Member

@sherm1 sherm1 left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r3, all commit messages.
Reviewable status: 1 unresolved discussion, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)

Copy link
Contributor Author

@mitiguy mitiguy 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, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)


multibody/tree/mobilizer.h line 618 at r2 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW should list q as well (below also)

Done.


multibody/tree/planar_mobilizer.cc line 192 at r2 (raw file):

Previously, xuchenhan-tri wrote…

BTW, it looks like these validity checks are spread across all derived classes. Is it possible to do this in MobilizerImpl?

Sounds reasonable. I'll check with you and Sherm before the next PR. These validity checks will be repeated for the more complicated mobilizers. For this PR, I think it is OK to merge as-is as it mimics the current code for MapVelocityToQDot() and MapQDotToVelocity(). If we make the change, I want to change all 4 functions simultaneously in a super-simple PR.


multibody/tree/prismatic_mobilizer.h line 183 at r2 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

minor: should be v rather than vdot

Done here and three other places.


multibody/tree/revolute_mobilizer.h line 187 at r2 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

minor: should be v rather than vdot

Done here and 3 other places.

Copy link
Contributor

@xuchenhan-tri xuchenhan-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 6 of 6 files at r3, all commit messages.
Reviewable status: commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)

Copy link
Contributor

@xuchenhan-tri xuchenhan-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: commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @mitiguy)


multibody/tree/prismatic_mobilizer.h line 183 at r2 (raw file):

Previously, mitiguy (Mitiguy) wrote…

Done here and three other places.

The reviewable coloring is failing so miserably here :(

@mitiguy mitiguy added status: squashing now https://drake.mit.edu/reviewable.html#curated-commits and removed status: squashing now https://drake.mit.edu/reviewable.html#curated-commits labels Mar 7, 2025
Copy link
Contributor Author

@mitiguy mitiguy left a comment

Choose a reason for hiding this comment

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

+label squashing now

Reviewable status: commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)

Copy link
Contributor Author

@mitiguy mitiguy left a comment

Choose a reason for hiding this comment

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

+label status: squashing now

Reviewable status: commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)

@mitiguy mitiguy added the status: squashing now https://drake.mit.edu/reviewable.html#curated-commits label Mar 7, 2025
@mitiguy mitiguy merged commit a513002 into RobotLocomotion:master Mar 7, 2025
10 checks passed
@mitiguy mitiguy deleted the MapQDDotToVDotMobilizers branch March 7, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium release notes: none This pull request should not be mentioned in the release notes status: squashing now https://drake.mit.edu/reviewable.html#curated-commits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants