scene_pymujoco_sim

Scene utilities for synchronous Python MuJoCo simulations.

This module provides the mujoco_scene helper used by RobotBlockSet synchronous MuJoCo backends to load models, manage the viewer, render auxiliary camera windows, and control simulation stepping and resets.

class robotblockset.mujoco.scene_pymujoco_sim.mujoco_scene(model_xml_file: str | None = None, model: mujoco.MjModel | None = None, show_viewer: bool = True, show_camera: List[str | int] | None = None, verbose: int = 0)[source]

Bases: rbs_object

MuJoCo scene manager with viewer support for synchronous backends.

Attributes:
  • spec (Optional[mujoco.MjSpec]) – MuJoCo specification object when the scene was loaded from XML.

  • model (mujoco.MjModel) – Compiled MuJoCo model used by the scene.

  • data (mujoco.MjData) – Runtime MuJoCo data associated with model.

  • pause (bool) – Flag indicating whether simulation stepping is paused.

  • viewer (Optional[mujoco.viewer.Handle]) – Passive MuJoCo viewer used for the main scene window.

  • show_camera (list[Union[str, int]]) – Camera names or IDs rendered in additional windows.

  • cam_windows (list[dict[str, object]]) – Metadata for additional GLFW camera windows.

Create a synchronous MuJoCo scene manager.

Parameters:
  • model_xml_file (str, optional) – Path to the MuJoCo XML model file to load.

  • model (mujoco.MjModel, optional) – Existing MuJoCo model to use instead of loading from XML.

  • show_viewer (bool, optional) – If True, open the main passive MuJoCo viewer.

  • show_camera (Optional[List[Union[str, int]]], optional) – Camera names or IDs to render in auxiliary windows.

  • verbose (int, optional) – Verbosity level used for status messages.

Returns:

This constructor initializes the synchronous MuJoCo scene object in place.

Return type:

None

__init__(model_xml_file: str | None = None, model: mujoco.MjModel | None = None, show_viewer: bool = True, show_camera: List[str | int] | None = None, verbose: int = 0) None[source]

Create a synchronous MuJoCo scene manager.

Parameters:
  • model_xml_file (str, optional) – Path to the MuJoCo XML model file to load.

  • model (mujoco.MjModel, optional) – Existing MuJoCo model to use instead of loading from XML.

  • show_viewer (bool, optional) – If True, open the main passive MuJoCo viewer.

  • show_camera (Optional[List[Union[str, int]]], optional) – Camera names or IDs to render in auxiliary windows.

  • verbose (int, optional) – Verbosity level used for status messages.

Returns:

This constructor initializes the synchronous MuJoCo scene object in place.

Return type:

None

start_simulation() None[source]

Start the viewer and auxiliary camera windows.

Returns:

This method creates the passive viewer and any requested camera windows.

Return type:

None

stop_simulation() None[source]

Stop rendering by closing the passive viewer.

Returns:

This method closes the main viewer window.

Return type:

None

restart_simulation() None[source]

Restart rendering and recompile the model when possible.

Returns:

This method refreshes the scene after stopping the viewer.

Return type:

None

update_cam_windows() None[source]

Render all active auxiliary camera windows.

Returns:

This method updates and prunes additional GLFW camera windows.

Return type:

None

mj_step() None[source]

Advances the simulation by one time step.

Returns:

This method steps the MuJoCo simulation and refreshes viewers.

Return type:

None

mj_forward() None[source]

Advances the simulation by using forward dynamics.

Returns:

This method recomputes forward dynamics and refreshes viewers.

Return type:

None

mj_pause() None[source]

Pause simulation stepping.

Returns:

This method sets the internal pause flag.

Return type:

None

mj_run() None[source]

Resume simulation stepping.

Returns:

This method clears the internal pause flag.

Return type:

None

mj_wait(wait: float = 0) None[source]

Advance the MuJoCo simulation for a specified duration.

This method performs repeated simulation steps until the internal simulation time (self.data.time) has advanced by the given amount. Unlike a passive delay (e.g., time.sleep), this function actively progresses the MuJoCo physics simulation.

Parameters:

wait (float, optional) – Amount of simulated time (in seconds) to advance. A value of 0 (default) performs no additional steps.

Notes

  • Simulation progresses by repeatedly calling self.mj_step.

  • The function returns only after the MuJoCo model time exceeds the initial time plus wait.

  • This does not block real time; the speed of advancement depends on computation speed and simulation complexity.

Returns:

This method blocks until the requested amount of simulated time has elapsed.

Return type:

None

mj_reset(keyframe: int | None = None) None[source]

Resets the simulation state to its initial state, or to a specified keyframe.

Parameters:

keyframe (int, optional) – The index of the keyframe to reset to. If None, the simulation is reset to the initial state.

Return type:

None

mj_capture_camera(camera: int | str = -1, scene_option: mujoco.MjvOption | None = None, **kwargs: object) ndarray[source]

Captures an image from a specified camera in the simulation.

Parameters:
  • camera (Union[int, str], optional) – The ID or name of the camera to capture. Default is -1, which captures the default camera.

  • scene_option (mujoco.MjvOption, optional) – Rendering options to customize the scene appearance. Default is None.

  • **kwargs (object) – Additional keyword arguments passed to mujoco.Renderer.

Returns:

The rendered image as a NumPy array (RGB format).

Return type:

np.ndarray

Classes

mujoco_scene([model_xml_file, model, ...])

MuJoCo scene manager with viewer support for synchronous backends.