RecorderManager#

RecorderManager 协调多个 recorders,管理它们的生命周期和数据分发。

概述#

RecorderManager:

  • 管理 recorders 集合

  • 将数据分派到适当的 recorders

  • 处理录制会话的启动/停止

  • 协调构建和清理阶段

用法#

RecorderManager 通常通过 Scene 访问:

import genesis as gs

gs.init()
scene = gs.Scene()
robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf"))
scene.build()

# Add multiple recorders
scene.add_recorder(
    gs.recorders.NPZFileWriter(filepath="data.npz"),
    data_func=lambda: robot.get_qpos(),
)

scene.add_recorder(
    gs.recorders.MPLLinePlotter(title="Positions"),
    data_func=lambda: robot.get_qpos(),
)

# Start all recorders
scene.start_recording()

for i in range(1000):
    scene.step()

# Stop all recorders
scene.stop_recording()

录制控制#

# Start recording all registered recorders
scene.start_recording()

# Check recording status
if scene.is_recording:
    print("Currently recording")

# Stop recording and trigger cleanup
scene.stop_recording()

# Stop recording and save video (if viewer is active)
scene.stop_recording(save_to="output.mp4")

API 参考#

class genesis.recorders.recorder_manager.RecorderManager(step_dt: float)[source]#

Bases: object

Manage the creation, processing, and cleanup of all data recorders.

Parameters:

step_dt (float) – The simulation time step.

RECORDER_TYPES_MAP = {<class 'genesis.options.recorders.PyQtLinePlot'>: <class 'genesis.recorders.plotters.PyQtLinePlotter'>, <class 'genesis.options.recorders.MPLLinePlot'>: <class 'genesis.recorders.plotters.MPLLinePlotter'>, <class 'genesis.options.recorders.MPLImagePlot'>: <class 'genesis.recorders.plotters.MPLImagePlotter'>, <class 'genesis.options.recorders.VideoFile'>: <class 'genesis.recorders.file_writers.VideoFileWriter'>, <class 'genesis.options.recorders.CSVFile'>: <class 'genesis.recorders.file_writers.CSVFileWriter'>, <class 'genesis.options.recorders.NPZFile'>: <class 'genesis.recorders.file_writers.NPZFileWriter'>}#
add_recorder(data_func: Callable[[], Any], rec_options: RecorderOptions) Recorder[source]#

Automatically read and process data. See RecorderOptions for more details.

Parameters:
  • data_func (Callable[[], Any]) – A function with no arguments that returns the data to be recorded.

  • rec_options (RecorderOptions) – The options for the recorder which determines how the data is recorded and processed.

Returns:

recorder – The created recorder object.

Return type:

Recorder

build()[source]#

Start data recording.

stop()[source]#

Stop and complete data recording.

reset(envs_idx=None)[source]#
step(global_step: int)[source]#

Increment the step count and process data from each recording configuration.

In threaded mode, data is put in queues. In non-threaded mode, data is processed synchronously.

property is_recording: bool#
property is_built: bool#

另请参阅#