Simulation guide
Introduction
MuJoCo (Multi-Joint dynamics with Contact) is a physics engine for robotic simulation. This guide covers:
Downloading and installing MuJoCo
Setting up Python bindings
Running a basic example
Installation
Downloading MuJoCo (Linux)
Visit the official site: https://mujoco.org/download
Download the appropriate version for your OS (Linux)
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
License errors: - Ensure mjkey.txt exists in ~/.mujoco/
GLFW issues: .. code-block:: bash
sudo apt install libglfw3 libglfw3-dev
Video driver problems: - Update your OpenGL drivers
Most of the problems with mujoco py lib can be soleved by suggestions from lib error
Additional Resources
Official docs: https://mujoco.readthedocs.io
Examples: https://github.com/deepmind/mujoco