You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to understand a bit how MuJoCo works, so I implemented an extremly hackish "proof of concept" of ignition-physics/MuJoCo integration. While first attempt is a big hack and may be problematic to continue on, it may be useful to other people trying to do this in a more proper way.
With extremly hackish I mean that the following features are not supported:
Floating Base models
Tree models
Collisions
Joint limits
Joint friction
Adding bodies/joint/models
Set control joint force
Getting the joint state
And probably many more feature I am not thinking about.
Furthermore, attributes were added without proper getters/setters. However, with this I was able to get some basic fixed base chain to simulate some basic passive dynamics.
Additional context
A video of the MVP simulating a fixed base double pendulum with Gazebo (if you look in the video, you can see also the MJCF file automatically generated from ignition-physics calls):
ignition_gazebo_mujoco_mvp.mp4
The code shown in the video is part of the mujoco branch in three ignition libraries:
(you can omit --render-engine ogre if ogre2 works fine for you).
To explain how I did proceed, I did the following:
I copied the tpe engine in a mujoco to have the necessary boilerplate to start working
I added to the mujocolib library (obtained after renaming the tpeliblibrary) the features that were not in tpe that I was interested in, such as inertial parameters for links and joints
I added in the mujoco-plugin library the features I was interested in (for example, Joint features)
As MuJoCo do not have support for building the model while the simulation is ongoing, I added in mujocolib::World the World::RegeneratedMuJoCoDataStructures, that will re-generated a MuJoCo's MJCF file whenever it was detected that the structure encoded in the mujocolib::World instance and in its child elements was changed (ideally, for the elements that were there before the state should be carried over, but this is not implemented in this MVP). Most of the MuJoCo-specific code (including the on-the fly generation of MJCF files) is here.
I modified mujocolib::World::Step to actually step the MuJoCo simulation, and copy the link state back in the mujocolib::World instance, from where then the ign-physics APIs access it. Some MuJoCo-specific code is also here).
Alternatives considered
Something that I noticed is that most of the logic related to handling entities is probably something that could be reused for many more physics engines that like MuJoCo have the following properties:
Do not have an API to add bodies/models on the fly, so whenever a new link/joint/model is added or removed, need to re-generate their simulation from scratch (if I am not wrong, this is kind of similar to the problem that were encounter in Integrate Bullet #44).
Do not have a shared ptr for each entity.
Something that could make sense could be to have some simpler interface for these kind of physics engines.
Initial prototye is in #811. The plan is to clean that up and get it to a mergable state without introducing any new features. Following that, we can divide up the implementation of various features. Here's the tentive plan:
Priority
Task / Feature
Key gz-physics Feature(s)
Notes
Assignee
1
Implement Runtime Pose Setting
SetFreeGroupWorldPose
Critical for GUI interaction and runtime pose updates.
Desired behavior
MuJoCo, a physics engine that is quite used in the Reinforcement Learning community is now free to use will be open sourced soon, see https://deepmind.com/blog/announcements/mujoco and https://community.gazebosim.org/t/deep-mind-bought-mujoco-and-is-open-sourcing-it . It would be cool to have a ignition-physics plugin for it, even because one standard reply in review of any paper sent to RL conferences is "Did you compared/tested it with MuJoCo?".
Implementation suggestion
I wanted to understand a bit how MuJoCo works, so I implemented an extremly hackish "proof of concept" of ignition-physics/MuJoCo integration. While first attempt is a big hack and may be problematic to continue on, it may be useful to other people trying to do this in a more proper way.
With extremly hackish I mean that the following features are not supported:
And probably many more feature I am not thinking about.
Furthermore, attributes were added without proper getters/setters. However, with this I was able to get some basic fixed base chain to simulate some basic passive dynamics.
Additional context
A video of the MVP simulating a fixed base double pendulum with Gazebo (if you look in the video, you can see also the MJCF file automatically generated from ignition-physics calls):
ignition_gazebo_mujoco_mvp.mp4
The code shown in the video is part of the
mujocobranch in three ignition libraries:To run it, just install mujoco with the following instructions:
After that, add the following code in your
setup.shor.bashrc:(this will ensure that mujoco is correctly found by the
FindIgnMuJoCo.cmakescript added in ign-cmake).Then follow the instructions in https://ignitionrobotics.org/docs/fortress/install_ubuntu_src, but use the file https://raw.githubusercontent.com/traversaro/gazebodistro/mujoco/collection-fortress.yaml in vcs instead of the official one. Then after completing the installation, you can run the example world with the command:
(you can omit
--render-engine ogreifogre2works fine for you).To explain how I did proceed, I did the following:
tpeengine in amujocoto have the necessary boilerplate to start workingmujocoliblibrary (obtained after renaming thetpeliblibrary) the features that were not intpethat I was interested in, such as inertial parameters for links and jointsmujoco-pluginlibrary the features I was interested in (for example, Joint features)mujocolib::Worldthe World::RegeneratedMuJoCoDataStructures, that will re-generated a MuJoCo's MJCF file whenever it was detected that the structure encoded in themujocolib::Worldinstance and in its child elements was changed (ideally, for the elements that were there before the state should be carried over, but this is not implemented in this MVP). Most of the MuJoCo-specific code (including the on-the fly generation of MJCF files) is here.mujocolib::World::Stepto actually step the MuJoCo simulation, and copy the link state back in themujocolib::Worldinstance, from where then the ign-physics APIs access it. Some MuJoCo-specific code is also here).Alternatives considered
Something that I noticed is that most of the logic related to handling entities is probably something that could be reused for many more physics engines that like MuJoCo have the following properties:
Something that could make sense could be to have some simpler interface for these kind of physics engines.
Initial prototye is in #811. The plan is to clean that up and get it to a mergable state without introducing any new features. Following that, we can divide up the implementation of various features. Here's the tentive plan: