RobotBridge. A bridge
implements three synchronous hooks and declares a contract; the base class serves the robot wire, the control
channel, the slots and the lockstep barrier.
A bridge
This bridge is a gripper that tracks its commanded(x, y) exactly. It succeeds once x >= 0.5 with the
gripper closed. Save it as sim.py:
sim.py
The bridge slices each slot’s row out of
data before sending it, so a client sees per-env arrays: an
[H, W, 3] frame and an [A] state.
Grading
sim.result() calls the bridge’s result(), on the sim thread so grading never races a step. The default
reads three attributes your hooks update:
result() for richer grading; every key you return reaches the template. A vectorized bridge with
per-slot scores overrides result_slots() instead, returning one dict per slot. By default it repeats
result() for every slot.
hold_action() is the row a non-acting slot plays at the barrier: zeros, as wide as the action feature.
Override it when zero is not a safe action for your robot.
Running it
A bridge reaches a HUD environment through aRobotEndpoint, which the environment’s hooks start and stop.
There are three ways to build one.
Spawned from the class
Pass the class (or an instance) and the endpoint runspython -m rua.sim.bridge sim.py:PointArm as a
child process, which it owns and terminates on stop().
env.py
__init__, the endpoint reads
the attribute of the same name (or with a leading underscore). Callables are skipped, and a value that isn’t
JSON-serializable raises TypeError. contract, metadata and num_envs set on the instance after
construction travel too.
Spawned from a command
RobotEndpoint.spawn(cmd) runs any command that serves a bridge and prints its control port as a
HUD_SIM_PORT=<port> line on stdout. Everything else the child prints passes through.
Remote
RobotEndpoint.remote(host, port) attaches to a sim process something else runs, such as a GPU machine, and
leaves it running on stop(). Run the sim there with python -m rua.sim.bridge sim.py:PointArm, or
call PointArm().serve(host=..., port=...) yourself.
The sim thread
serve() blocks: it runs the wire and control channel on a background thread while the calling thread
becomes the sim thread. Every hook (reset, step, get_observation, result) runs there, in order, so a
simulator that must own the main thread works. While serving, a hook must be synchronous; an async def hook
raises TypeError. If Omniverse Kit is loaded, the sim thread also pumps its app update between hooks.
Episodes and the barrier
The base class runs the slot protocol for you:- The first claim when every slot is free calls your
resetonce for the whole batch. - Each tick,
stepruns once every live, claimed slot has sent an action. - A slot whose
terminatedis true, or that hit itsmax_ticks, drops out of the barrier; its peers keep stepping. - A slot silent for
step_timeoutseconds (30 by default, a class attribute) is told it timed out, closed, and dropped. - If
steporget_observationraises, every connected slot receives the traceback and is closed.
Serving extra capabilities
Overridecapabilities(name) to publish more than the robot wire, for example a tool server the sim process
runs. The endpoint publishes everything it returns:
metadata is a dict sent as the first frame on every robot connection, for clients that want it.