MuJoCo Plugin¶
Overview¶
About MuJoCo¶
MuJoCo (Multi-Joint dynamics with Contact) is a physics engine widely used in the field of robotics research. It was originally developed by Emo Todorov and his colleagues at the University of Washington, and after being acquired by Google DeepMind in 2021, it has been released as open-source software under the Apache 2.0 license. It has become one of the standard simulation platforms especially in robot learning research, including reinforcement learning.
MuJoCo is designed to handle the equations of motion of multibody systems based on generalized coordinates (joint coordinates), and can handle articulated robots stably. As for contacts, it is characterized by its soft contact model formulated as convex optimization, which allows simulations involving contacts to be processed stably and quickly.
About the MuJoCo Plugin¶
The MuJoCo plugin of Choreonoid is a plugin for using MuJoCo as a physics engine of Choreonoid. It provides the “MuJoCoSimulator” as a simulator item, which can be used in the same way as the simulator items of the other physics engines. The standard body models handled by Choreonoid can be used as they are, and position control, velocity control, and torque control are all supported.
MuJoCo, along with PhysX, is positioned as a semi-standard physics engine of Choreonoid, and an official prebuilt library (version 3.9.0) is bundled with the Choreonoid repository. This means that you do not need to install MuJoCo separately; it becomes automatically available just by building Choreonoid.
Setup¶
The MuJoCo library required by the MuJoCo plugin is bundled with Choreonoid and is enabled by default. Therefore, just by following the normal build procedure of Choreonoid, the MuJoCo plugin is also built and becomes ready to use. What is bundled is the prebuilt dynamic library and the header files of the official MuJoCo release, and the supported platforms are Linux (x86_64) and Windows (x86_64).
The following two CMake options are provided, but you usually do not need to change them.
ENABLE_MUJOCO: Enables the bundled MuJoCo library. The default isON.BUILD_MUJOCO_PLUGIN: Builds the MuJoCo plugin itself. The default is the value ofENABLE_MUJOCO(that is, usuallyON).
If you do not want to use MuJoCo, turn both ENABLE_MUJOCO and BUILD_MUJOCO_PLUGIN OFF in the CMake configuration.
Using the MuJoCo Simulator¶
When the MuJoCo plugin is loaded, the “MuJoCoSimulator” becomes available as a simulator item. Create it from the main menu with “File” - “New” - “MuJoCoSimulator”, and place it as a child item of the world item following the procedure explained in Creating a Simulation Project. The basic usage is common to the other simulator items.
Supported Features¶
The MuJoCo simulator supports the following features:
Actuation modes: torque command (JointEffort), velocity command (JointVelocity), and position command (JointDisplacement)
Simulation of force sensors, acceleration sensors, and angular velocity sensors (rate gyros)
State output of link velocities, accelerations, and drive efforts (enabled with the corresponding properties)
Setting friction and restitution coefficients with Contact Materials
Extra joints ( Setting Extra Joints )
Consideration of the equivalent rotor inertia (armature) ( Setting the Rotor Inertia )
Simulation of pseudo continuous tracks and conveyors based on surface velocity
Properties¶
In addition to Properties Common to Simulator Items, the following properties are available in the MuJoCo simulator item.
Property |
Default value |
Meaning |
|---|---|---|
Gravity |
0 0 -9.80665 |
The gravitational acceleration vector [m/s^2]. |
Integrator |
ImplicitFast |
Selects the numerical integration method from “Euler”, “Implicit”, and “ImplicitFast”. The default ImplicitFast is usually sufficient. |
Solver |
Newton |
Selects the solver for computing contact and constraint forces from “PGS”, “CG”, and “Newton”. |
Solver iterations |
100 |
The maximum number of iterations of the solver. |
Number of threads |
1 |
The number of threads used for the MuJoCo computation. |
Position gain |
10000.0 |
The gain of the actuators used for driving joints with position commands. |
Velocity gain |
100.0 |
The gain of the actuators used for driving joints with velocity commands. |
Min friction |
0.001 |
The lower bound of the friction coefficients used in the contact computation. |
Max friction |
1.0 |
The upper bound of the friction coefficients used in the contact computation. |
Friction impedance ratio |
1.0 |
Corresponds to the impratio parameter of MuJoCo. It is the ratio of the impedance in the friction directions to that in the normal direction of contacts, and larger values suppress slipping. |
Self collision |
false |
Enables self collisions within body models by default. |
Velocity output |
false |
Outputs the link velocities as simulation results. |
Acceleration output |
false |
Outputs the link accelerations as simulation results. |
Drive effort output |
false |
Writes back the torque (or force for a prismatic joint) actually used for driving each joint as the joint effort value. |
Samples¶
No samples dedicated to the MuJoCo plugin are provided, but for many of the general simulation samples bundled with Choreonoid ( sample/SimpleController/ etc.), you can simulate them with MuJoCo by replacing the simulator item in the project with the MuJoCo simulator.