Open traversaro opened 2 years ago
Well done @traversaro! Very impressive work, look forward to trying it out.
Well done @traversaro! Very impressive work, look forward to trying it out.
Do not expect too much from it! I do not think it works for anything except for the fixed_dbl_pendulum.sdf
(that I had to add ad-hoc to Ignition Gazebo). 😄
Incredible, I was just thinking about this earlier today. Very exciting to see other are interested and prototyping it.
this is awesome!
Much desired. Thank you for putting in the work and sharing it!! So many possibilities.
Awesome! Was about to ask whether there are any plans of integrating MuJoCo. Having it as a physics engine in Gazebo would be great :thumbsup:
Awesome! Was about to ask whether there are any plans of integrating MuJoCo. Having it as a physics engine in Gazebo would be great 👍
Just to clarify, this is just a proof of concept that I do not plan to (at the moment) to develop further, so at the moment I do not know if there are any plans to integrate MuJoCo in Ignition Gazebo. However if someone is willing to invest the time to develop a MuJoCo plugin, I would be happy to provide guidance/explain more in depth the proof of concept.
Yeah, I didn't expect this to be a kickoff for the integration. Actually it was supposed to be a question: Are there any plans to officially support MuJoCo as a physics engine in ignition-physics?
I think this functionality would be quite useful for this: https://github.com/gazebosim/gz-sim/pull/1560 , as mujoco does not easily provide a way to incrementally build a model (see https://github.com/gazebosim/gz-physics/pull/298#issuecomment-1171056948 for a longer discussion).
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):
https://user-images.githubusercontent.com/1857049/138121453-a804e232-53f7-44ee-b4d1-dd4959d60ec0.mp4
The code shown in the video is part of the
mujoco
branch in three ignition libraries:To run it, just install mujoco with the following instructions:
After that, add the following code in your
setup.sh
or.bashrc
:(this will ensure that mujoco is correctly found by the
FindIgnMuJoCo.cmake
script 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 ogre
ifogre2
works fine for you).To explain how I did proceed, I did the following:
tpe
engine in amujoco
to have the necessary boilerplate to start workingmujocolib
library (obtained after renaming thetpelib
library) the features that were not intpe
that I was interested in, such as inertial parameters for links and jointsmujoco-plugin
library the features I was interested in (for example, Joint features)mujocolib::World
the World::RegeneratedMuJoCoDataStructures, that will re-generated a MuJoCo's MJCF file whenever it was detected that the structure encoded in themujocolib::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.mujocolib::World::Step
to actually step the MuJoCo simulation, and copy the link state back in themujocolib::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: