Sim Module
Sim module for managing MuJoCo simulations.
This module provides a Simulation class to handle MuJoCo simulations, including loading models, running simulations, capturing data, and rendering frames.
- class mujoco_toolbox.sim.Simulation(*args: Any, **kwargs: Any)[source]
Bases:
object
Simulation class for managing MuJoCo simulations.
- body_data(body_name: str, data_name: str | None = None) dict[str, ndarray] | ndarray [source]
Get the data for a specific body in the simulation.
- Parameters:
body_name (str) – The name of the body to retrieve data for.
data_name (str) – The name of the data to retrieve.
- Returns:
The data for the specified body.
- Return type:
dict[str, np.ndarray] | np.ndarray
- id2name(id: int) str [source]
Get the name of a body given its ID.
- Parameters:
id (int) – The ID of the body.
- Returns:
The name of the body.
- Return type:
str
- name2id(name: str) int [source]
Get the name of a body given its index.
- Parameters:
name (str) – The name of the body.
- Returns:
The index of the body.
- Return type:
int
- reload() Simulation [source]
Reload the model and data objects.
- Returns:
Self for method chaining.
- Return type:
- run(*, render: bool = False, camera: str | None = None, interactive: bool = False, show_menu: bool = True, multi_thread: bool = False) Simulation [source]
Run the simulation with optional rendering.
- Parameters:
render (bool) – If True, renders the simulation.
camera (str) – The camera view to render from, defaults to None.
data_rate (int) – How often to capture data, expressed as frames
second. (per)
interactive (bool) – If True, opens an interactive viewer window.
show_menu (bool) – Shows the menu in the interactive viewer.
True. (Interactive must be)
multi_thread (bool) – If True, runs the simulation in multi-threaded
mode.
- Returns:
The current Simulation object for method chaining.
- Return type:
self
- save(title: str = 'output.gif', *, frame_idx: int | tuple[int, int] | None = None, time_idx: float | tuple[float, float] | None = None) str [source]
Save specific frame(s) as a video or GIF to a file.
- Parameters:
title (str, optional) – Filename for the saved media. Filename should end with the desired codec extension (e.g., .mp4, .gif)
frame_idx (int or tuple, optional) – Single frame index or (start, stop) frame indices.
time_idx (float or tuple, optional) – Single time or (start, end) times in seconds.
- Returns:
Absolute path to the saved file.
- Return type:
str
- Raises:
ValueError – If no frames are captured or invalid input parameters.
- show(title: str | None = None, *, frame_idx: int | tuple[int, int] | None = None, time_idx: float | tuple[float, float] | None = None) None [source]
Render specific frame(s) as a video or GIF in a window.
- Parameters:
title (str, optional) – Title for the rendered media.
frame_idx (int or tuple, optional) – Single frame index or (start, stop) frame indices.
time_idx (float or tuple, optional) – Single time or (start, end) times in seconds.
- Raises:
ValueError – If no frames are captured or invalid input parameters.
- class mujoco_toolbox.sim.Wrapper(*args: Any, **kwargs: Any)[source]
Bases:
Simulation