Skip to content

sim2bot.CameraStream.read

read(timeout: float = 5.0) -> Optional[CameraFrame]

Wait for a frame newer than the previous read.

Parameters:

  • timeout (float, default: 5.0 ) –

    Maximum blocking time in seconds.

Returns:

Notes

read() returns the next fresh slot value even if it is older than max_age. Iterator mode performs the age filter automatically.

Source code in sim2bot/client.py
def read(self, timeout: float = 5.0) -> Optional[CameraFrame]:
    """Wait for a frame newer than the previous read.

    Args:
        timeout: Maximum blocking time in seconds.

    Returns:
        The next [`CameraFrame`][sim2bot.client.CameraFrame], or ``None`` when
        the timeout expires.

    Notes:
        ``read()`` returns the next fresh slot value even if it is older than
        ``max_age``. Iterator mode performs the age filter automatically.
    """
    frame, self._last_seq = self._slot.get(self._last_seq, timeout)
    return frame

Practical examples

Examples use objects discovered from the current scene rather than hard-coded robot metadata.

Handle a timeout

frame = feed.read(timeout=2.0)
if frame is None:
    print("No new frame")

Discard old frames explicitly

frame = feed.read(timeout=1.0)
if frame is not None and frame.age < 0.25:
    process(frame)

Guidance

Common error

A None result means the read timed out; it does not automatically close the subscription.


See also