dream.live
Import it as from dream import live.
Live View for any control loop: the robot’s cameras, status and arms on the platform, and the page’s buttons.
LiveViewClient is the one class, and the one implementation of Live View: the station that dreamcli robot up runs (robots.station) is an ordinary caller of it, so everything the page shows of a station, your own loop can show too. Hand the client every observation with LiveViewClient.stream(); read the task a viewer typed with LiveViewClient.get_prompt(); and register a callback, which runs with an EventChange when a viewer presses a button.
Example
import dream def on_episode(event: dream.EventChange) -> None: print("viewer pressed", event.value) # "start", or "end" (Stop, or a new task while running) with dream.LiveViewClient("rbt_0123456789abcdef") as live: live.register_callback(on_episode) while running: live.stream(obs, "running") # obs: the frames and state you hand DreamClient.set_observation(), in one mapping task = live.get_prompt() # the task a viewer last sent, or None
The client keeps one outbound connection to the platform’s live service, so the page shows your robot like any station and nothing needs opening at your end. It opens on the first stream(), on a thread of its own, and redials after a fault with a jittered backoff; stream() never waits on the network. What it does on that thread, and how it stays off your loop:
- A camera is encoded only while a viewer watches it. Live View shows the robot; recording a run is the dream client’s job, done from DreamClient.set_observation().
- Faces are blurred on the robot, in every encoded frame, before anything leaves it (
face_blur, on by default), each camera with a detector of its own (shared.faceblur, which the library carries). - Each camera has one encoder (PyAV’s
libvpx, VP8, one thread) and one worker thread; the client’s threads run niced (_NICE), so the scheduler prefers your loop whenever both are runnable. An unwatched camera’s encoder closes_IDLE_ENCODER_Safter its last viewer leaves; an encoder that fails is reopened on the first frame after that delay. - At most one unsent frame per camera: a stalled uplink overwrites it, counts a drop and makes the next frame a keyframe; the socket holds well under a second (
_WRITE_HIGH_WATER,_NOTSENT_LOWAT,_SNDBUF_BYTES). Nothing queues on the robot. - Everything runs from the client’s own thread, which reads your newest stream()
_POLL_HZtimes a second; when and from where you call stream() changes nothing it does, so call it from your loop, a camera callback or a thread of your own, as often as you have something new. - The tick guard watches that thread, never your loop: while the robot runs and a camera is encoded, a p95 of its poll interval past
_YIELD_TICK_RATIOpoll periods for_YIELD_WINDOW_Smeans the computer has no CPU to spare for video, so it closes every encoder, reportslive_paused: "tick"and retries after_YIELD_BACKOFF_S. Your loop’s own pace (a sync hold, a slowget_action(), a camera’s jitter) never pauses the video.
The link is the platform’s robot link, ROBOT_LINK_PATH on the platform’s host, defined by shared.contracts.live in the platform repository, which this package cannot import; the names it needs are restated below as private constants, each naming the contract’s, and a test in the platform repository holds them to it.
See also: LiveViewClient, EventChange
Classes
Section titled “Classes”EventChange: What a viewer did from the Live View page; the argument of every registered callback.LiveViewClient: Shows one robot on the platform’s Live View page: its cameras, status and arms, and the buttons viewers press.