MuJoCo Simulation

Run a MuSHR simulation with the MuJoCo physics engine.

Beginner Tutorial | Expected duration is 30 minutes

By: Caelen Wang



This tutorial will introduce you to the MuSHR MuJoCo simulation. MuJoCo is a physics engine that provides accurate simulations for real-world interactions. By the end of the tutorial, you would be able to run a basic MuSHR simulation in the MuJoCo environment.


  • The full MuSHR stack from the Quickstart tutorial

  • ROS, follow the Intro to ROS tutorial for a refresher

  • A licensed copy of MuJoCo. Place the extracted folder mujoco200_linux along with the license mjkey.txt in the directory ~/.mujoco/

  • Cmake miminum version 3.13.2


Clone the MuSHR MuJoCo repository into your catkin workspace:

# Go to your catkin workspace
$ cd ~/catkin_ws/src
# Clone the MuSHR MuJoCo repository
$ git clone

Note that in CMakeLists.txt, you can specify the MuJoCo directory with the MUJOCO_LOCATION environment variable. The default path is ~/.mujoco/. Optionally, if you want to use OpenGL for enhanced graphics, set the USE_GL environment variable to 1, which is the default value. To compile with GL install GLFW:

$ sudo apt-get install libglfw3-dev

Compile your workspace:

$ cd .. && catkin_make

Running the Simulator

To demonstrate the MuSHR MuJoCo environment, we will run a simple simulation of a car and a block that can be pushed. Each simulation requires a ROS launch file, a MuJoCo model XML file, and a configuration YAML file with the same name. Take a look at launch/block.launch, models/block.xml, and config/block.yaml.

In the launch file, we can use a specific map file. The environment variable should match the name of the three files mentioned above:

<arg name="map_server" default="1"/>
<arg name="map_file" default="$(find mushr_mujoco_ros)/maps/empty.yaml" />
<arg name="environment" default="block" />

The node parameters specify the MuJoCo key, XML file, and YAML file paths, as well as visualization. The default paths follow that in the previous step:

<node pkg="mushr_mujoco_ros" name="mushr_mujoco_ros" type="mushr_mujoco_ros_node" output="screen">
    <param name="mj_key" value="~/.mujoco/mjkey.txt" />
    <param name="model_file_path" value="$(find mushr_mujoco_ros)/models/$(arg environment).xml" />
    <param name="config_file_path" value="$(find mushr_mujoco_ros)/config/$(arg environment).yaml" />
    <param name="viz" value="true" />

The model XML file contains MuJoCo constants that define the bodies and actuator parameters for the simulate car. To add a car to the simulation, use an “include” tag with the path from the models directory:

<include file="cars/pusher_car/buddy.xml"/>

The configuration YAML file is a list of bodies and cars whose position will be published to different topics. The MuSHR vehicles are listed under “cars” while other objects are listed under “bodies”. In this simulation, the car buddy receives the control, pose, and initpose messages on the controls, pose, and initialpose ROS topics:

- name: buddy
  control_topic : control
  pose_topic: pose
  initpose_topic: initialpose

With a grasp of the basic structure, we can start the simulation:

$ roslaunch mushr_mujoco_ros block.launch

To control the car with WASD keyboard input, open another terminal. Enter the line below, replacing the name of the car as needed:

$ rosrun topic_tools relay /mux/ackermann_cmd_mux/input/teleop /mushr_mujoco_ros/buddy/control

Experimenting with MuJoCo

Try to drive the car around and push the block. You might notice that it’s somewhat difficult to push the block with precision. Let’s change the MuJoCo model parameters to facilitate our task. Open models/block.xml and find the body tag that describes the block. Double the mass to “2.4”, and increase the size to “0.1 0.1 0.1”, which should provide a larger block to push. Increase the friction on the block by setting friction to be “0.8 0.05 0.001”. The 3 values control tangential, torsional, and rolling friction, respectively. Feel free to mess around with the values for a desired result.

<body pos="1.000000 0.000000 0.049" name="block" euler="0 0 0.000000">
  <joint type="free"/>
  <geom type="box" mass="2.4" contype="1" friction="0.8 0.05 0.001" 
  conaffinity="1" size="0.1 0.1 0.1" rgba="0.247 0.772 0.760 1"/>

After changing model parameters, remember to recompile the workspace with catkin_make for the changes to take effect. Have fun with MuJoCo! To autonomously drive figure-8s in MuJoCo, checkout the MuJoCo Figure 8 tutorial.


If you plan to use any part of the the MuSHR platform (including tutorials, codebase, or hardware instructions) for a project or paper, please cite MuSHR: A Low-Cost, Open-Source Robotic Racecar for Education and Research.

 title={{MuSHR}: A Low-Cost, Open-Source Robotic Racecar for Education and Research},
 author={Srinivasa, Siddhartha S. and Lancaster, Patrick and Michalove, Johan and Schmittle, Matt and Summers, Colin and Rockett, Matthew and Smith, Joshua R. and Chouhury, Sanjiban and Mavrogiannis, Christoforos and Sadeghi, Fereshteh},