Simulation guide

Introduction

MuJoCo (Multi-Joint dynamics with Contact) is a physics engine for robotic simulation. This guide covers:

  1. Downloading and installing MuJoCo

  2. Setting up Python bindings

  3. Running a basic example

Installation

Downloading MuJoCo (Linux)

  1. Visit the official site: https://mujoco.org/download

  2. Download the appropriate version for your OS (Linux)

  3. Extract to your home directory:

mkdir ~/.mujoco
tar -xvzf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco

Environment Variables

Add to your ~/.bashrc or ~/.zshrc:

export MUJOCO_PY_MUJOCO_PATH=~/.mujoco/mujoco210/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mujoco210/bin
export MUJOCO_KEY_PATH=~/.mujoco/mjkey.txt

Then reload:

source ~/.bashrc

Python Package Installation

Recommended (MuJoCo 2.3.0+):

pip install mujoco

For legacy versions:

pip install mujoco-py

Linux dependencies (Ubuntu/Debian):

sudo apt install libosmesa6-dev libgl1-mesa-glx patchelf

Testing

Create test_mujoco.py:

import mujoco
import os

# Path to the model (change it to suit your system)
model_path = os.path.expanduser('<path_to_model>')

model = mujoco.MjModel.from_xml_path(model_path)
data = mujoco.MjData(model)

for _ in range(1000):
    mujoco.mj_step(model, data)
    print(data.qpos)

Run the test:

python test_mujoco.py

Troubleshooting

  1. License errors: - Ensure mjkey.txt exists in ~/.mujoco/

  2. GLFW issues: .. code-block:: bash

    sudo apt install libglfw3 libglfw3-dev

  3. Video driver problems: - Update your OpenGL drivers

  4. Most of the problems with mujoco py lib can be soleved by suggestions from lib error

Additional Resources

MuJoCo simulation