MuJoCo (Multi-Joint dynamics with Contact) is a physics-based simulation engine with graphics and animation for the C target. This repo defines a base reactor and some example derived reactors. The MuJoCoBase reactor provides a single simulator with graphical animation. The derived reactors customize this base class for particular MuJoCo model files. The MuJoCo menagerie is included as a submodule, so be sure to update submodules:
git submodule update --init --recursive
- Install GLFW, a graphics library used by MuJoCo
apt install libglfw3-dev- Download a prebuilt version of Mujoco v3.2.6 and install it to
/opt/mujoco. The following works for x86, for aarch64, change the download path accordingly (https://github.com/google-deepmind/mujoco/releases/tag/3.2.6)
wget https://github.com/google-deepmind/mujoco/releases/download/3.2.6/mujoco-3.2.6-linux-x86_64.tar.gz
tar xvf mujoco-*
sudo mv mujoco-3.2.6 /opt/mujocoAlternatively, Mujoco can be built from source as explained under the section for MacOS below.
- Install GLFW, a graphics library used by MuJoCo
brew install glfw- Build Mujoco v3.2.6 from source and install to
/opt/mujoco
git clone https://github.com/google-deepmind/mujoco.git -b 3.2.6
cd mujoco
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/mujoco
cmake --build .
sudo cmake --install .It has also been reported that you can instead install the MuJoCo.app bundle, though we have not tested that.
If mujoco is installed to a different location the mujoco.cmake must be updated accordingly.
Install the Lingo package manager, if you haven't already.
In your project, create Lingo.toml file with contents like the following:
[package]
name = "<your package name>"
version = "<your version number>"
[[app]]
name = "<AppName>"
main = "src/<AppName>.lf"
target = "C"
platform = "Native"
[app.properties]
[dependencies]
mujoco-c = {version=">=0.1", git="https://github.com/lf-lang/mujoco-c.git", branch="main"}
In your Lingua Franca application, instantiate one of the library reactors. For example, for the
Frank Emika Panda robot, your .lf file should include:
import MuJoCoPanda from <mujoco-c/MuJoCoPanda.lf>
main reactor {
panda = new MuJoCoPanda()
...
}
Then compile and run your app:
lingo build
build/bin/<AppName>
- MuJoCoBase: Base class providing navigation of the view and methods to update the scene and advance the simulator. This is not meant to be directly instantiated.
- MuJoCoAdvance extends MuJoCoBase: Base class providing an
advanceinput to advance the simulation to the logical time and update the scene. This refers to the hello basic demo model, which has a box and a floor. - MuJoCoAuto extends MuJoCoBase: Base class that automatically advances the simulation and outputs a tick for each step. This separates the updating of the scene, which is driven by a periodic timer. This refers to the hello basic demo model, which has a box and a floor.
- MuJoCoCar extends MuJoCoAdvance: Simulator for the car basic demo model, providing a two-wheel vehicle and keyboard controlled driving. This version actively controls the simulator advance.
- MuJoCoCarAuto extends MuJoCoAuto: Simulator for the car basic demo model, providing a two-wheel vehicle and keyboard controlled driving. This version lets the simulator advance automatically.
- MuJoCoInvertedPendulum.lf extends MuJoCoAuto: Simple inverted pendulum model.
- MuJoCoPanda.lf extends MuJoCoAuto: Simulator for a Franka Emika Panda robot.
Build the demos using lfc or make:
- Basic: Rectangular object that falls to the floor.
- Car: Simple drivable car.
- CarAuto: Simple drivable car.
- InvertedPendulum: Inverted pendulum demo.
- Panda: Franka Emika Panda robot doing gyrations.