LiveViewClient
class LiveViewClientImportable as dream.LiveViewClient.
Shows one robot on the platform’s Live View page: its cameras, status and arms, and the buttons viewers press.
The key resolves as DreamClient’s does: the argument, else your credentials. Where the platform is comes from your credentials and cannot be changed from code. The constructor checks the encoder by opening one; nothing is dialed until the first stream(), and close(), or leaving the with block, ends the link. Callbacks run on the client’s thread, so keep them short; a callback that has seconds of work (moving arms) returns it as an awaitable, which the client waits for before it answers the page.
The client runs on a thread of its own, which reads your newest stream() _POLL_HZ times a second and does all of the work from there, so it never runs on, or waits for, your control loop. A camera is encoded only while a viewer watches it, and faces are blurred on the robot before any frame leaves it, unless face_blur=False. Live View shows the robot; recording a run is the dream client’s job, done from DreamClient.set_observation().
Given the loop’s DreamClient, the client also reports the model’s round trips while the robot is running, as the station does: the page waits for the first one before it shows the run as answered (“Dream-1 is getting ready” until then), and draws its latency from them.
See also: EventChange, stream(), register_callback()
A context manager: use it in a with block. Entering: Returns the client; leaving the block calls close(). Leaving: Calls close().
Constructor
Section titled “Constructor”LiveViewClient( robot_id: str, *, api_key: str | None = None, dream_client: Any = None, face_blur: bool = True, model_fixed: bool = True, cameras: Sequence[str] | None = None, )
Resolves the key and the link and opens one encoder to prove it can; nothing runs until the first stream().
Parameters
robot_id(str): The robot as the platform knows it,rbt_and 16 hex digits: therobot_idunderlive:in the station file (~/.dreamlabs/station.yaml) that the setup wizard’s Save writes when it registers the robot. The Live View page lists robots by name, never by id.api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ (DREAM_API_KEY) when None.dream_client(Any, defaultNone, keyword-only): The loop’sdream.DreamClient, whoselast_timingstream() reads to report each new round trip to the page, whosecheckpointthe page shows as the model and whosesession_idnames the run. Without it the page never sees an answer and shows the run as getting ready. A loop that opens a new DreamClient (one per run, as the station does) sets thedream_clientattribute to it.face_blur(bool, defaultTrue, keyword-only): Blur every face in every encoded frame before it leaves the robot, with a detector per camera (shared.faceblur), and say so to the platform. On by default; off sends the frames as captured.model_fixed(bool, defaultTrue, keyword-only): True (the default) when your code chooses the model: the page shows the one you run and offers no model or action choice. False lets a viewer pick them: a Start then carries the checkpoint and the action space, which get_model() returns, and your loop runs them.cameras(Sequence[str] | None, defaultNone, keyword-only): The cameras a viewer may watch, in this order, each named as it is in your observation’s keys (video.<name>) and shown under that name, not renamed; stream() may then carry any of them, a camera with no frame yet left out, and a frame of another name is not shown. None: the cameras of the first stream(), the model’s roles renamed as the page names them (overheadistop).
Raises
DreamConfigError: No key is set anywhere,robot_idis empty, the platform ishttp://on a host other than this one (the key would cross the network in the clear), PyAV, OpenCV or websockets is not installed, the encoder does not open in this PyAV build,face_bluris on and the face detector is not installed, orcamerasnames a camera twice, an empty name orpose.
LiveViewClient.register_callback
Section titled “LiveViewClient.register_callback”LiveViewClient.register_callback( callback_func: Callable[[EventChange], object], *, home: bool = False, reset: bool = False, prompt: bool = False, ) -> None
Adds a callback for Start, Stop and a new task from the page, and for the presses it opts in to.
The callback runs on the client’s thread with the EventChange. It may return nothing (the page hears the press applied), the robot’s state after it ("running"), a mapping with state and, when the press failed, error (its message), or an awaitable (or a concurrent.futures.Future, such as asyncio.run_coroutine_threadsafe() returns) that resolves to one of those. The client waits for an awaitable up to the page’s deadline (10 s), then answers the page: an exception, or an error, is a failure with its message; past the deadline the page hears timeout. A Start, a Stop, a Home or a Reset is never cancelled halfway, deadline or not: the work goes on and the next status says where it ended. Only a new task’s awaitable is cancelled at the deadline.
Parameters
callback_func(Callable[[EventChange], object]): Called withEventChange.starton Start,EventChange.endon Stop, and on a new taskEventChange.promptwithprompt=True, elseEventChange.end. Keep it short: record the event for your loop to act on, as the example on the Live View page does, or return the work as an awaitable.home(bool, defaultFalse, keyword-only): Also call it withEventChange.homewhen a viewer presses Home. While no callback takes Home, the page hears “not supported”.reset(bool, defaultFalse, keyword-only): Also call it withEventChange.resetwhen a viewer presses Reset arms; the same holds.prompt(bool, defaultFalse, keyword-only): Call it withEventChange.prompt, rather thanEventChange.end, when a viewer sends a task.
LiveViewClient.get_prompt
Section titled “LiveViewClient.get_prompt”LiveViewClient.get_prompt() -> str | None
The task a viewer last sent from the page; after a Start without one, the prompt you last streamed.
Returns
str | None: The task’s text, or None until a viewer sends one.
LiveViewClient.get_model
Section titled “LiveViewClient.get_model”LiveViewClient.get_model() -> tuple[str | None, str | None]
The model a viewer chose with the last Start, for a client built with model_fixed=False.
Returns
tuple[str | None, str | None]: (checkpoint, action_space): the checkpoint slug and "eef" or "joint", each None when the Start named none (keep the one you run); (None, None) before the first Start and with model_fixed=True.
LiveViewClient.get_steps
Section titled “LiveViewClient.get_steps”LiveViewClient.get_steps() -> int | None
How many steps the last Start asked for, which the page offers while your status carries steps.
Returns
int | None: The step count, at least 1, or None when the Start named none (keep your count).
LiveViewClient.stats
Section titled “LiveViewClient.stats”LiveViewClient.stats() -> dict[str, Any]
The client’s own counters, for your loop’s logs or status page; safe from any thread.
Returns
dict[str, Any]: linked, node (the live node holding the link), viewers (None: the link carries camera subscriptions, not viewer counts), streams (the watched cameras), pose (whether a viewer holds the arms’ stream), dropped_frames per camera, reconnects, errors (encoder faults and closes with a code), yields (times the tick guard paused the video) and live_paused.
LiveViewClient.stream
Section titled “LiveViewClient.stream”LiveViewClient.stream( obs: Mapping[str, Any], status: str, *, arms: Mapping[str, Any] | None = None, error: str | tuple[str, str | None] | None = None, prompt: str | None = None, run: int | None = None, model: tuple[str | None, str | None] | None = None, steps: int | None = None, ) -> None
Hands the client the newest observation and the robot’s status; returns at once.
Call it whenever you have something new, from any thread and at any rate: the client reads the newest call on its own thread _POLL_HZ times a second, so your loop’s pace never reaches the video. The first call opens the link; without cameras in the constructor it also names the cameras, and every later call carries the same ones (with cameras, a camera with no frame yet may be left out). A frame is encoded once: hand the client a new array or JPEG for each new camera frame, and the same one again while the camera has delivered nothing new. Every keyword is optional; each one the page shows is shown only once you pass it.
Parameters
obs(Mapping[str, Any]): The observation, DreamClient.set_observation()’s frames and state in one mapping: eachvideo.<role>(orimage_window.<role>) key holds one frame and is a camera on the page:overheadthe main picture (top),wrist_landwrist_rthe side panels (left,right), any other role under its own name. A frame is a base64 JPEG, or an RGBuint8array[height, width, 3](the client keeps a reference, so hand it a new array per frame and the same one while it has not changed). Every other key is ignored here.status(str): What the page shows as the robot’s state:idle,running,error, or any short word. Reportrunningfrom a viewer’s Start until the episode ends: the page shows the task and its Stop button only while the robot isrunning, and offers Start only while it isidleorerror.arms(Mapping[str, Any] | None, defaultNone, keyword-only): Each arm’s joints as they are now, by name ({"left": (q, gripper), "right": (q, gripper)}):qthe joint angles in radians,gripperthe opening from 0 closed to 1 open, or None for an arm that cannot be read. The page draws the robot from them while a viewer looks (theposestream, sent only when the first call carriesarms), and shows an arm whose value is None as not answering.error(str | tuple[str, str | None] | None, defaultNone, keyword-only): Why the arms are not moving, for the page’s banner: a message, or(message, code)with a short code for it (pool_warming,ArmError); None while nothing is wrong.prompt(str | None, defaultNone, keyword-only): The task your robot runs or will run, when your code sets it: the status shows it rather than the one a viewer last sent, and a Start without a task runs it (get_prompt() then returns it).run(int | None, defaultNone, keyword-only): Your run number, which the status carries; the client counts runs itself, one per stretch ofrunning, when left out.model(tuple[str | None, str | None] | None, defaultNone, keyword-only):(checkpoint, action_space)your loop runs, which the page shows (action_space"eef"or"joint", or None); thedream_client’s checkpoint when left out.steps(int | None, defaultNone, keyword-only): How many steps your next run takes, 0 for no limit; the page then offers a step count, which a Start carries (get_steps()).
Raises
DreamObservationError:obsis not a mapping, a frame is neither a base64 JPEG nor an RGB array, withoutcameras,obscarries no frame or not the cameras of the first call;statusis empty; or a keyword is not of the shape above.
LiveViewClient.close
Section titled “LiveViewClient.close”LiveViewClient.close() -> None
Ends the link, releases the encoders and joins the client’s thread; idempotent.