sim2bot.Robot.camera¶
camera(camera_id: str, fps: Optional[int] = None, width: Optional[int] = None, height: Optional[int] = None, quality: Optional[float] = None, codec: Any = None) -> CameraStream
¶
Subscribe to a global scene camera and return a latest-frame stream.
Parameters:
-
camera_id(str) –Required ID returned by
cameras, such asmodel:0,custom:<id>, orsensor:<id>. -
fps(Optional[int], default:None) –Requested frame rate from 1 to 30.
Noneinherits GUI/default stream settings. -
width(Optional[int], default:None) –Requested width in pixels; currently clamped to 16–1920.
-
height(Optional[int], default:None) –Requested height in pixels; currently clamped to 16–1080.
-
quality(Optional[float], default:None) –JPEG quality from 0.1 to 1.0. Ignored for raw frames.
-
codec(Any, default:None) –"jpeg"for compact frames or"raw"for uncompressed RGBA. H.264 is reserved for later.
Returns:
-
CameraStream–A
CameraStream. Close it or use a -
CameraStream–context manager to stop the subscription.
Raises:
-
RuntimeError–If the control client is not connected.
-
TimeoutError–If the video WebSocket cannot connect before its timeout.
-
ConnectionClosed–If either WebSocket closes during subscription.
-
OSError–If the video or control endpoint cannot be opened or written.
Notes
Cameras are global scene resources and do not take robot=. One
overhead feed can observe several independently addressed robots.
Unspecified stream options inherit the camera's GUI configuration.
Examples:
Read one world-mounted camera frame::
overhead = next(
item for item in sim.cameras()
if item["mount"]["kind"] == "world"
)
with sim.camera(overhead["id"], fps=24, width=640, height=480) as stream:
frame = stream.read(timeout=2.0)
Source code in sim2bot/client.py
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | |
Practical examples¶
Examples use objects discovered from the current scene rather than hard-coded robot metadata.
Read one JPEG frame
Use raw frames on localhost
Stream an overhead view while moving two arms
Guidance¶
Usage tip
Use JPEG for bandwidth efficiency and raw RGBA for the lowest localhost encode/decode latency.
Common error
Camera IDs are global; camera() intentionally has no robot= argument.