Wrapper Module
Wrapper module for managing MuJoCo simulations.
This module provides a Wrapper class to handle MuJoCo simulations, including loading models, running simulations, capturing data, and rendering frames.
- class mujoco_toolbox.wrapper.Wrapper(*args: Any, **kwargs: Any)[source]
Bases:
object
Wrapper 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
- property captured_data: dict[str, ndarray]
Read-only property to access the entire captured simulation data.
- property controller: Callable[[MjModel, MjData, Any], None] | None
Controller Function.
- property data: MjData
Read-only property to access the MjData single-step object.
Use captured_data to access the entire simulation data.
- property data_rate: int
Data rate of the simulation in frames per second.
- property duration: float
Duration of the simulation in seconds.
- property fps: float
Frames per second.
- property frames: list[ndarray]
Read-only property to access the captured frames.
- property gravity: ndarray
Gravity vector of the simulation.
- 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
- property initial_conditions: dict[str, list]
Initial conditions for the simulation.
- property keyframe: int | None
Keyframe index for the simulation.
- property model: MjModel
Read-only property to access the MjModel object.
- 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() Wrapper [source]
Reload the model and data objects.
- Returns:
Self for method chaining.
- Return type:
- property resolution: tuple[int, int]
Resolution of the simulation in pixels (w,h).
- run(*, render: bool = False, camera: str | None = None, interactive: bool = False, show_menu: bool = True, multi_thread: bool = False) Wrapper [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 Wrapper object for method chaining.
- Return type:
self
- save(title: str = 'render', codec: str = '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.
codec (str, optional) – Video codec/format. Defaults to “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.
- save_yaml(name: str = 'Model') None [source]
Save simulation data to a YAML file.
- Parameters:
name (str) – The filename for the YAML file.
- Returns:
None
- show(title: str | None = None, codec: str = 'gif', 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.
codec (str, optional) – Video codec/format. Defaults to “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.
- Raises:
ValueError – If no frames are captured or invalid input parameters.
- property ts: float
Timestep of the simulation in seconds.