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

[wpimath] Add full state support to LinearSystemId functions #6554

Merged
merged 26 commits into from
May 15, 2024

Conversation

narmstro2020
Copy link
Contributor

Addresses issue #6513

C++ version needs to be done, but I need some feedback before proceeding.

This relies on LinearSystem providing a function to trim the C and D matrices to a single row for use in the KalmanFilter, LinearQuadraticRegular, and LinearSystemLoop classes.

The trimmed version of the LinearSystem is passed into these classes.
This would add more of a implementation burden on users who wish to use this in the classes.
While what I've written works in principle, would it be better to modify the KalmanFilter, LQR, and LinearSystemLoop classes to take in the LinearSystem and extract what they need instead?

DCMotorSim, ElevatorSim, and SingleJointedArmSim have been modified to use the velocity output of the LinearSystem instead the state.

@narmstro2020 narmstro2020 requested review from a team as code owners April 28, 2024 14:17
@narmstro2020 narmstro2020 marked this pull request as draft April 28, 2024 14:17
@narmstro2020 narmstro2020 marked this pull request as ready for review April 28, 2024 15:08
Copy link
Member

@calcmogul calcmogul left a comment

Choose a reason for hiding this comment

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

While what I've written works in principle, would it be better to modify the KalmanFilter, LQR, and LinearSystemLoop classes to take in the LinearSystem and extract what they need instead?

Those classes can take any linear system, so they can't know what to slice unless the user tells them. At that point, the user might as well do the slicing via the LinearSystem method to separate concerns.

@narmstro2020
Copy link
Contributor Author

Thanks for the help @calcmogul
I'll plan on working on the C++ version tomorrow.

@narmstro2020
Copy link
Contributor Author

@calcmogul
I've started the C++ version. LinearSystemId, and all of the simulation classes have been modified accordingly.
I need some help with the C++ Slice function in LinearSystem. I started it, but wasn't sure how to extract the rows like in the Java version.

@calcmogul
Copy link
Member

calcmogul commented Apr 29, 2024

Declare the parameter pack like this: https://godbolt.org/z/aoz7YYjfo.

Use "Array of indices" from https://eigen.tuxfamily.org/dox/group__TutorialSlicingIndexing.html to slice the matrices.

If you want to sort and deduplicate the indices first, copy them into a std::array via std::array arr{outputIndices...};, then use https://en.cppreference.com/w/cpp/algorithm/ranges/sort piped into https://en.cppreference.com/w/cpp/algorithm/ranges/unique.

@narmstro2020
Copy link
Contributor Author

@calcmogul
It's a start, but I'm still having some struggles getting this to compile.

@calcmogul
Copy link
Member

I got it to compile, but the precondition checks need some work still.

@narmstro2020
Copy link
Contributor Author

@calcmogul
How so on the condition checks?

@calcmogul
Copy link
Member

calcmogul commented Apr 29, 2024

If the user adds a duplicate index, the function uses the wrong output dimension for the return type (too large). We should probably just throw an error on duplicates.

@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

Simple checks for duplication.

@narmstro2020
Copy link
Contributor Author

How is this one looking. Anything else I need to do?

@narmstro2020
Copy link
Contributor Author

Thank you. Requested changes made and committed.

narmstro2020 and others added 2 commits May 13, 2024 12:52
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

Thanks again.

@calcmogul calcmogul added the breaking Introduces a breaking change. label May 13, 2024
@PeterJohnson PeterJohnson merged commit 7fc1781 into wpilibsuite:main May 15, 2024
25 checks passed
chauser pushed a commit to chauser/allwpilib that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Introduces a breaking change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants