Skip to content

Utils API¤

このページでは、Robopyのユーティリティ機能に関連するAPIを説明します。

実験ハンドラー¤

RakudaExpHandler¤

RakudaExpHandler ¤

RakudaExpHandler(rakuda_config: RakudaConfig, metadata_config: MetaDataConfig, fps: int = 10)

Bases: ExpHandler

This class handles the experimental interface for the Rakuda robot.

Sensors: 1x Realsense, 2x Digit,

Example:

from robopy.utils.exp_interface import RakudaExpHandler
handler = RakudaExpHandler(
    leader_port="/dev/ttyUSB0",
    follower_port="/dev/ttyUSB1",
    left_digit_serial="D20542",
    right_digit_serial="D20537",
    fps=20,
)
handler.record_save(max_frames=150, save_path="test_01", if_async=True)

init initialize Rakuda experimental handler

PARAMETER DESCRIPTION
leader_port

leader serial port

TYPE: str

follower_port

follower serial port

TYPE: str

left_digit_serial

left digit serial number

TYPE: str

right_digit_serial

right digit serial number

TYPE: str

fps

The frequency to capture obs. Defaults to 10

TYPE: int DEFAULT: 10

RAISES DESCRIPTION
ValueError

fps must be between 1 and 20

RuntimeError

failed to connect to Rakuda robot

METHOD DESCRIPTION
record_save

record and save data from Rakuda robot

record_save ¤

record_save(max_frames: int, save_path: str, if_async: bool = True, save_gif: bool = True, warmup_time: int = 5) -> None

record and save data from Rakuda robot

PARAMETER DESCRIPTION
max_frames

maximum number of frames to record

TYPE: int

save_path

path to save the recorded data:

TYPE: str

if_async

If use parallel. Defaults to True.

TYPE: bool DEFAULT: True

save_gif

if save gif. Defaults to True.

TYPE: bool DEFAULT: True

warmup_time

warm up time before recording. Defaults to 5.

TYPE: int DEFAULT: 5

RAISES DESCRIPTION
RuntimeError

failed to record from Rakuda robot

RuntimeError

failed to save data

データ処理¤

H5Handler¤

H5Handler ¤

Handler for saving and loading data using HDF5 format with h5py.

METHOD DESCRIPTION
get_info

Get information about HDF5 file structure.

load_hierarchical

Load hierarchical data structure from HDF5 file.

get_info staticmethod ¤

get_info(file_path: str) -> Dict[str, Any]

Get information about HDF5 file structure.

PARAMETER DESCRIPTION
file_path

Path to the HDF5 file.

TYPE: str

RETURNS DESCRIPTION
Dict[str, Any]

Dict[str, Any]: Information about file structure and sizes.

load_hierarchical staticmethod ¤

load_hierarchical(file_path: str) -> Dict[str, Any]

Load hierarchical data structure from HDF5 file.

PARAMETER DESCRIPTION
file_path

Path to the HDF5 file.

TYPE: str

RETURNS DESCRIPTION
Dict[str, Any]

Dict[str, Any]: Hierarchical dictionary containing loaded data.

Example

data = H5Handler.load_hierarchical('output.h5') camera_data = data['camera']['main'] # Access nested data

BlocsHandler¤

BLOSCHandler ¤

BLOSCHandler()
METHOD DESCRIPTION
load

Load data dictionary from a Blosc2 file.

save

Save data dictionary to a Blosc2 file.

load staticmethod ¤

load(path: str) -> NDArray

Load data dictionary from a Blosc2 file.

save staticmethod ¤

save(data: NDArray, path: str) -> None

Save data dictionary to a Blosc2 file.

ユーティリティ関数¤

find_usb_port¤

find_usb_port ¤

FUNCTION DESCRIPTION
find_available_ports

Find available USB ports on the system.

find_available_ports ¤

find_available_ports() -> list[str]

Find available USB ports on the system.

RETURNS DESCRIPTION
list[str]

list[str]: A list of available USB port names.

使用例¤

実験データの記録と保存¤

from robopy.config import RakudaConfig, RakudaSensorParams, TactileParams
from robopy.utils.exp_interface import RakudaExpHandler

# 設定
config = RakudaConfig(
    leader_port="/dev/ttyUSB0",
    follower_port="/dev/ttyUSB1",
    sensors=RakudaSensorParams(
        tactile=[
            TactileParams(serial_num="D20542", name="left"),
            TactileParams(serial_num="D20537", name="right"),
        ],
    ),
)

# ハンドラー作成
handler = RakudaExpHandler(
    rakuda_config=config,
    fps=20
)

# データ記録と保存
handler.record_save(
    max_frames=1000,
    save_path="experiment_001",
    if_async=True
)

H5ファイルの読み込みと保存¤

from robopy.utils import H5Handler

# H5ファイルの情報取得
file_info = H5Handler.get_info("path/to/data.h5")

# 階層的データの読み込み
hierarchical_data = H5Handler.load_hierarchical("path/to/data.h5")

# データの保存
import h5py
with h5py.File("output.h5", "w") as f:
    f.create_dataset("array_data", data=your_data)