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

[systems] LuenbergerObserver and KalmanFilter use shared_ptr #22351

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Dec 26, 2024

Towards #5842 and #21968. We must stop passing unique_ptr as an argument from Python down to C++... passing unique_ptr in an argument of a call from Python into C++ is made possible by Drake-specific hacks to pybind11, and we need to get rid of the hacks.


This change is Reviewable

@jwnimmer-tri jwnimmer-tri added priority: low release notes: feature This pull request contains a new feature labels Dec 26, 2024
@jwnimmer-tri
Copy link
Collaborator Author

+@RussTedrake for feature review please, if you have availability. If not that's fine and I'll find a different reviewer after the new year.

Copy link
Contributor

@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.

:lgtm:

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: needs at least two assigned reviewers


systems/estimators/luenberger_observer.cc line 87 at r1 (raw file):

    : LuenbergerObserver(std::shared_ptr<const System<T>>(
                             /* managed object = */ std::shared_ptr<void>{},
                             /* stored pointer = */ &observed_system),

btw -- TIL. Nice. That certainly simplifies things! We have a lot of places where we have parallel owned vs referenced workflows.

Copy link
Contributor

@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.

Q: How is it that the tests which pass a unique_ptr to the constructor still pass? Which codepath are they taking?

Reviewable status: needs at least two assigned reviewers

@RussTedrake
Copy link
Contributor

(and should we include a test which explicitly calls the shared_ptr versions?)

The LuenbergerObserver and KalmanFilter now take the observed system
as a shared_ptr-to-const, not unique_ptr-to-mutable. The functions
don't need to mutate anything and don't need exclusive ownership, and
passing by unique_ptr causes trouble in our pydrake bindings.

Overload SteadyStateKalmanFilter to accept the context by-const-ref
instead of the unnecessary by-mutable-unique_ptr.
Copy link
Collaborator Author

@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.

Q: How is it that the tests which pass a unique_ptr to the constructor still pass? Which codepath are they taking?

The shared-ptr class has a conversion constructor that accepts a unique_ptr. See overload (13) at https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr.

(and should we include a test which explicitly calls the shared_ptr versions?)

I ported the tests to shared_ptr and added coverage for the new const-context overload for the kalman filter.

Reviewable status: needs at least two assigned reviewers

Copy link
Contributor

@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.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: needs at least two assigned reviewers

@jwnimmer-tri
Copy link
Collaborator Author

+@SeanCurtis-TRI for platform review per schedule, please.

Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-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 5 of 5 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees SeanCurtis-TRI(platform),RussTedrake(platform)

@SeanCurtis-TRI SeanCurtis-TRI merged commit 63bdcb7 into RobotLocomotion:master Jan 2, 2025
10 checks passed
@jwnimmer-tri jwnimmer-tri deleted the kalman-shared branch January 2, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low release notes: feature This pull request contains a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants