Skip to content

Feature/625 mujoco-based dynamics#908

Merged
juan-g-bonilla merged 24 commits into
developfrom
feature/625-mujoco
Apr 14, 2025
Merged

Feature/625 mujoco-based dynamics#908
juan-g-bonilla merged 24 commits into
developfrom
feature/625-mujoco

Conversation

@juan-g-bonilla
Copy link
Copy Markdown
Contributor

Description

This PR adds a new paradigm for dynamics simulation. It makes use of the MuJoCo library for multi-body dynamics. A new DynamicObject is added, MJScene, whose purpose is to expose an interface that can interoperate with the rest of the Basilisk framework, while internally using MuJoCo to solve the complicated dynamics of a multi-body system. Scenarios have been added that showcase the current capabilities.

This feature should be considered in "alpha". Any and all code is subject to considerable refactors in the near future. Validation efforts are not complete; do not use this feature to produce results that you actually care about.

Verification

Tests have been added in src/simulation/dynamics/mujoco/_UnitTest and scenarios in examples/mujoco (src/tests/test_scenarioMujoco.py checks that these scenarios run).

Documentation

The scenarios documentation page has been updated to include a new section Multi-Body Dynamics Simulations with MuJoCo.

Future work

Things still to figure out (non-exhaustive):

  • Stateful SysModel (for models that define states with derivatives to be integrated by MJScene.
  • Possibly rework how the inertial properties (mass, etc.) are updated.
  • Allow prescribing joints and mass.
  • Add torque to the gravity model NBodyGravity.
  • Add hooks for vizard.
  • Add more tests to compare results and performance of spacecraft and MJScene

@juan-g-bonilla juan-g-bonilla added enhancement New feature or request dont merge Waiting on other changes before merging labels Jan 21, 2025
@juan-g-bonilla juan-g-bonilla self-assigned this Jan 21, 2025
@juan-g-bonilla juan-g-bonilla requested a review from a team as a code owner January 21, 2025 09:00
@juan-g-bonilla juan-g-bonilla force-pushed the feature/625-mujoco branch 3 times, most recently from 8004d67 to d5f4f22 Compare January 23, 2025 04:31
@juan-g-bonilla juan-g-bonilla force-pushed the feature/625-mujoco branch 8 times, most recently from 68fa6f1 to 6a4a2fa Compare February 23, 2025 20:47
@juan-g-bonilla juan-g-bonilla added documentation Improvements or additions to documentation build Build system or compilation enhancement and removed dont merge Waiting on other changes before merging labels Feb 23, 2025
Copy link
Copy Markdown
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

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

I think I'll do this in stages and leave feedback as I find it. Was able to compile BSK without --mujoco flag just fine. All tests passed or mujoco tests were skipped as expected. Nice work.

I next compiled BSK with `--mujocoflag set to true. mujoco`` version 3.2.6 was installed without issues. Compiling finished with no issues.

To do:

  • need to update docs/source/Install/installBuild.rst table to discuss the --mujoco build option. I'd add it under the opNav description.

Comment thread src/simulation/dynamics/gravityEffector/gravityEffector.i
Comment thread docs/source/Support/bskReleaseNotes.rst Outdated
@juan-g-bonilla juan-g-bonilla changed the title Feature/625 mujoco [draft] Feature/625 mujoco-based dynamics Feb 27, 2025
Copy link
Copy Markdown
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

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

Great work overall. I found some small things to address, typos, questions on msg variable naming and frames, etc.

Comment thread src/simulation/dynamics/_GeneralModuleFiles/interpolator.h
Comment thread libs/mujoco/conanfile.py Outdated
Comment thread libs/mujoco/conanfile.py Outdated
Comment thread src/architecture/msgPayloadDefC/ForceMsgPayload.h Outdated
Comment thread src/architecture/msgPayloadDefC/ForceMsgPayload.h Outdated
Comment thread examples/mujoco/scenarioSimpleDocking.py
Comment thread examples/mujoco/scenarioUnbalancedThrusters.py
Comment thread examples/mujoco/scenarioUnbalancedThrusters.py Outdated
Comment thread examples/mujoco/scenarioUnbalancedThrusters.py Outdated
Comment thread examples/mujoco/scenarioSimpleDocking.py Outdated
@juan-g-bonilla
Copy link
Copy Markdown
Contributor Author

@schaubh Thanks for the feedback and the commits to solve some of the issues. I think my latest push addresses your comments.

@schaubh
Copy link
Copy Markdown
Contributor

schaubh commented Mar 27, 2025

If the replay install fails, then the whole configuration process should fail. Provide info on how to custom download and build gflw. We used

conan download glfw/3.4@ -r=conancenter
conan install . --build=missing

Copy link
Copy Markdown
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

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

next round of suggestions

Comment thread src/architecture/msgPayloadDefC/ForceAtSiteMsgPayload.h Outdated
Comment thread src/architecture/msgPayloadDefC/TorqueAtSiteMsgPayload.h Outdated
Comment thread src/simulation/dynamics/mujoco/pythonUtils.py
@juan-g-bonilla
Copy link
Copy Markdown
Contributor Author

juan-g-bonilla commented Mar 27, 2025

Build page for MuJoCo: MacOS has an error for glfw3, how to fix that by manually building. Found a better fix

@juan-g-bonilla juan-g-bonilla force-pushed the feature/625-mujoco branch 2 times, most recently from 243ea57 to 4c3adcb Compare March 30, 2025 08:18
@juan-g-bonilla
Copy link
Copy Markdown
Contributor Author

@schaubh just appended commits to move the mujoco files to mujocoDynamics.

@juan-g-bonilla juan-g-bonilla force-pushed the feature/625-mujoco branch 2 times, most recently from bed2a59 to 3b6db28 Compare April 12, 2025 07:50
Note the special behavior: mujocoDynamics gets to
see the _GeneralModuleFiles of dynamics

Link dynamicsLib for mujocoDynamicsLib
Copy link
Copy Markdown
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

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

Nice work here. I did a clean build on my system with and without the --mujoco build flag and everything worked as expected. This is an exciting beta feature to add to BSK.

@juan-g-bonilla juan-g-bonilla merged commit 43d3df0 into develop Apr 14, 2025
21 of 22 checks passed
@juan-g-bonilla juan-g-bonilla deleted the feature/625-mujoco branch April 14, 2025 04:44
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Basilisk Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build system or compilation enhancement documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

MuJoCo as simulation module

2 participants