Modules

MuJoCo Loader

The MuJoCo Loader module provides utilities for loading MuJoCo models and setting up the simulation environment.

MuJoCo Model Loader and Viewer

This script provides functionality to load and visualize MuJoCo physics simulation models. It supports both active and passive viewing modes: - Active viewer: Runs independently in a separate thread - Passive viewer: Requires manual synchronization

Usage:

python -m mujoco_tools.mujoco_loader –model path/to/model.xml [–active_viewer|–passive_viewer]

param –model:

Path to the MuJoCo XML model file

param –passive_viewer:

Enable passive viewer mode

param –active_viewer:

Enable active viewer mode

Player

The Player module provides visualization capabilities for MuJoCo simulations.

class mujoco_tools.player.MujocoPlayer(model_path, mode='kinematics', input_data_freq=500, output_path=None, output_prefix=None)[source]

Bases: object

Initialize MuJoCo player with model and optional recorders

add_recorder(recorder)[source]

Add a recorder to the player

play_trajectory(data, input_data_freq)[source]

Play trajectory and notify all recorders

save_data()[source]

Save data from all recorders

Recorder

The Recorder module offers tools for recording data and videos from MuJoCo simulations.

class mujoco_tools.recorder.VideoRecorder(camera_name='lateral_camera_angle', width=1920, height=1080, fps=50, vision_flags=None, output_video_freq=50)[source]

Bases: object

Initialize video recorder with rendering settings

setup_renderer(width, height)[source]

Set up the MuJoCo renderer with given settings

initialize(output_path, output_prefix)[source]

Initialize video writer

record_frame(model, data)[source]

Record a single frame directly to video file

save(output_path, output_prefix='video')[source]

Finish recording and release video writer

class mujoco_tools.recorder.StateRecorder(model, output_format='npy', datatypes=None, output_data_freq=50)[source]

Bases: object

Initialize state recorder for positions and orientations

initialize(output_path, output_prefix)[source]

Initialize state recorder

reset()[source]

Reset recorded data

record_frame(model, data)[source]

Record position and orientation data for the current frame

tendon_waypoint(model, data)[source]

Record tendon waypoint xpos ten_wrapadr is the start address of tendon’s path ten_wrapnum is the number of wrap points in path wrap_xpos is the Cartesian 3D points in all paths :returns: list of numpy arrays, (ntendon, num_waypoints, 6) :rtype: waypoint_xpos

save(output_path, output_prefix='state')[source]

Save recorded state data

Data Processor

The Data Processor module provides utilities for processing and analyzing simulation data.

class mujoco_tools.data_processor.DataProcessor(model, data)[source]

Bases: object

process()[source]

Tools

The Tools module contains various utility functions for working with MuJoCo simulations.

mujoco_tools.tools.load_model_from_path(model_path)[source]

Load a MuJoCo model from a path and initialize its data.

Parameters:

model_path (str) – Path to the MuJoCo XML model file

Returns:

Model and data objects

Return type:

Tuple[mujoco.MjModel, mujoco.MjData]

mujoco_tools.tools.get_joint_qpos(model, data, joint_name)[source]

Get joint position(s) by joint name.

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • joint_name (str) – Name of the joint

Returns:

Joint position(s)

Return type:

np.ndarray

mujoco_tools.tools.set_joint_qpos(model, data, joint_name, value)[source]

Set joint position(s) by joint name.

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • joint_name (str) – Name of the joint

  • value (ndarray) – Position value(s) to set

mujoco_tools.tools.get_body_pose(model, data, body_name)[source]

Get body position and orientation (quaternion).

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • body_name (str) – Name of the body

Returns:

Position (xyz) and orientation (quaternion)

Return type:

Tuple[np.ndarray, np.ndarray]

mujoco_tools.tools.apply_force_to_body(model, data, body_name, force, point=None)[source]

Apply force to a body at specified point (or center of mass if not specified).

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • body_name (str) – Name of the body

  • force (ndarray) – Force vector [fx, fy, fz]

  • point (ndarray | None) – Point of application in world coordinates (optional)

mujoco_tools.tools.get_sensor_data(model, data, sensor_name)[source]

Get sensor reading by name.

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • sensor_name (str) – Name of the sensor

Returns:

Sensor reading

Return type:

np.ndarray

mujoco_tools.tools.reset_simulation(model, data)[source]

Reset simulation to initial state.

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

mujoco_tools.tools.forward_kinematics(model, data)[source]

Compute forward kinematics.

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

mujoco_tools.tools.get_jacobian(model, data, body_name)[source]

Get body Jacobian (translational and rotational).

Parameters:
  • model (MjModel) – MuJoCo model

  • data (MjData) – MuJoCo data

  • body_name (str) – Name of the body

Returns:

Translational and rotational Jacobians

Return type:

Tuple[np.ndarray, np.ndarray]

mujoco_tools.tools.launch_passive_viewer(model, data)[source]
Parameters:
  • model (MjModel) –

  • data (MjData) –

mujoco_tools.tools.launch_viewer(model, data)[source]
Parameters:
  • model (MjModel) –

  • data (MjData) –

CLI

The CLI module provides a command-line interface for using MuJoCo Tools.

Command-line interface for MuJoCo tools

mujoco_tools.cli.parse_data_arg(data_str)[source]

Parse data argument string into a dictionary Example: “qpos data/qpos.npy ctrl data/ctrl.npy” -> {“qpos”: “data/qpos.npy”, “ctrl”: “data/ctrl.npy”}

Parameters:

data_str (str) –

Return type:

Dict[str, str]

mujoco_tools.cli.parse_vision_flags(flags_str)[source]

Parse vision flags string into a dictionary Example: “mjVIS_ACTUATOR mjVIS_ACTIVATION” -> {“mjVIS_ACTUATOR”: True, “mjVIS_ACTIVATION”: True}

Parameters:

flags_str (str) –

Return type:

Dict[str, bool]

mujoco_tools.cli.main()[source]