opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
758 stars 307 forks source link

Adding `SynergyController` #3796

Closed nickbianco closed 1 week ago

nickbianco commented 1 month ago

Fixes issue #3677

Brief summary of changes

Adds SynergyController, a controller that computes controls for a model based on a linear combination of a set of Input control signals and a set of synergy vectors. These changes also include a new utility function for performing basic non-negative matrix factorization, and a sub-example in exampleMocoInverse demostrating how to use SynergyController with Moco.

Other changes include:

Testing I've completed

testMocoControllers.cpp was refactored to use SynergyController.cpp in favor of the custom TriplePendulumController class. Added unit tests specific SynergyController.

Looking for feedback on...

CHANGELOG.md (choose one)

[perf-win]

Performance analysis

Platform: Windows, self-hosted runner

Test Name lhs [secs] stderr [secs] rhs [secs] stderr [secs] Speedup
Arm26 0.37 0.00 0.36 0.00 1.03
ellipsoid_wrap 4.36 0.01 4.34 0.00 1.00
ellipsoid_wrap_function_based_paths 3.61 0.01 3.63 0.01 0.99
Gait2354 0.44 0.00 0.43 0.00 1.02
MocoSlidingMass 1.60 0.01 1.63 0.02 0.98
MocoSquatToStand 14.94 0.04 14.94 0.07 1.00
passive_dynamic 5.88 0.01 5.85 0.02 1.00
passive_dynamic_noanalysis 3.63 0.06 3.54 0.02 1.03
RajagopalModel 9.53 0.10 9.70 0.13 0.98
ToyDropLanding 14.53 0.14 14.52 0.06 1.00
ToyDropLanding_fbp_stepwisereg 13.03 0.06 12.93 0.06 1.01
ToyDropLanding_function_based_paths 13.28 0.04 13.42 0.09 0.99
ToyDropLanding_nomuscles 0.60 0.00 0.63 0.00 0.95

This change is Reviewable

nickbianco commented 4 weeks ago

@aymanhab or @carmichaelong, do either of you have bandwidth for a review?

@AlbertoCasasOrtiz, if you're interested in learning more about opensim-core, tagging along as a second reviewer here would be a good place to start!

nickbianco commented 3 weeks ago

I've made a few updates: added Python and Matlab versions of the new example, and changes to the bindings to support these examples (and InputController-derived types in Moco in general).

nickbianco commented 2 weeks ago

@carmichaelong @AlbertoCasasOrtiz I made a few small changes, but this is now ready for review.

nickbianco commented 2 weeks ago

Thanks @carmichaelong!

nickbianco commented 1 week ago

The failing tests on the Windows2022 are unrelated, so I'm merging.

Thanks @carmichaelong and @AlbertoCasasOrtiz!