Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/env python
# Copyright 2026 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
"""Remote teleop against the REAL arm — one command. Built on top of the LOCAL real teleop.
Composes three child processes:
1. python -m tomctl.real --port <serial> --id <id> --remote-port P (LOCAL real teleop + UDP receiver)
2. python -m tomctl.livekit.bridge --room R --arms ... --remote-port P (the queue — one arm at a time)
3. python -m tomctl.livekit.cameras --room R ... (REAL cameras — wrist/top/side)
The camera publisher is **best-effort**: if it fails or a camera is unplugged it is logged and (1)+(2)
keep running, so cameras NEVER block remote control. A control child (teleop or bridge) exiting tears
the whole thing down. Operators drive from armcade `tools/livekit_viewer.html`. Ctrl-C stops all.
python -m tomctl.remote_real --id tom_follower_01 --room tom-cams # from robot/ (port from calibration)
Note: 2-arm REAL remote needs the teleop host to drive two robots (follow-up); today this wires arm1.
"""
from __future__ import annotations
import argparse
import signal
import subprocess
import sys
import time
from pathlib import Path
HERE = Path(__file__).resolve().parent
ROBOT_ROOT = HERE.parent # robot/ — the sys.path root for `python -m tomctl.<x>` + `import lerobot`
PY = sys.executable
def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("--port", default=None, help="Follower serial port override (e.g. /dev/ttyACM0). Default: the 'port' stored in the arm's ik_calibration_<id>.json.")
p.add_argument("--id", required=True, help="Robot id (calibration/config), e.g. tom_follower_01")
p.add_argument("--room", default="tom-cams", help="LiveKit room (operator + cameras + bridge share it)")
p.add_argument("--url", default="ws://localhost:7880", help="LiveKit server ws URL")
p.add_argument("--arms", nargs="+", default=["arm1"], metavar="ARM", help="Arm ids (real host wires arm1 today)")
p.add_argument("--remote-port", type=int, default=9090, help="Loopback UDP port: bridge -> teleop receiver")
p.add_argument("--max-session-s", type=float, default=None, help="Max seconds per session (default: unlimited)")
p.add_argument("--idle-timeout-s", type=float, default=30.0, help="Release a session after this idle (0 disables)")
p.add_argument("--operator", action="append", metavar="IDENTITY", help="Optional operator allow-list (repeatable)")
p.add_argument("--no-cameras", action="store_true", help="Don't launch the real camera publisher.")
p.add_argument("--cameras", nargs="+", default=None, help="Subset of cameras to publish (default: all available).")
p.add_argument("teleop_extra", nargs=argparse.REMAINDER,
help="Extra args after `--` are forwarded to `python -m tomctl.real`.")
return p.parse_args()
def main() -> None:
args = parse_args()
procs: list[tuple[str, subprocess.Popen, bool]] = [] # (name, proc, critical)
def launch(name: str, cmd: list[str], critical: bool) -> None:
print(f"[remote-real] start {name}{'' if critical else ' (best-effort)'}: {' '.join(cmd)}", flush=True)
try:
procs.append((name, subprocess.Popen(cmd, cwd=ROBOT_ROOT), critical))
except Exception as exc: # noqa: BLE001
if critical:
raise
print(f"[remote-real] {name} failed to start (optional): {exc}", flush=True)
extra = [a for a in args.teleop_extra if a != "--"]
# The single real teleop reports liveness AS the first configured arm; the bridge listens on its
# default --status-port (loopback), so arm health flows back and the web UI can show ARMS_OFFLINE.
# Serial port comes from the arm's calibration unless --port overrides (see tomctl.real).
teleop_cmd = [PY, "-m", "tomctl.real", "--id", args.id, "--remote-port", str(args.remote_port),
"--arm-id", args.arms[0]]
if args.port: # else tomctl.real resolves the port from the arm's calibration
teleop_cmd += ["--port", args.port]
launch("teleop", [*teleop_cmd, *extra], critical=True)
bridge_cmd = [PY, "-m", "tomctl.livekit.bridge", "--url", args.url, "--room", args.room,
"--arms", *args.arms, "--remote-port", str(args.remote_port),
"--idle-timeout-s", str(args.idle_timeout_s)]
if args.max_session_s is not None:
bridge_cmd += ["--max-session-s", str(args.max_session_s)]
for op in args.operator or []:
bridge_cmd += ["--operator", op]
launch("bridge", bridge_cmd, critical=True)
if not args.no_cameras:
cam_cmd = [PY, "-m", "tomctl.livekit.cameras", "--url", args.url, "--room", args.room]
if args.cameras:
cam_cmd += ["--cameras", *args.cameras]
launch("cameras", cam_cmd, critical=False)
print(f"""
==================== REMOTE REAL is up ====================
Operator drives via : armcade tools/livekit_viewer.html (url {args.url})
Mint an operator token : python -m tomctl.livekit.tokens --role operator \\
--identity <player-id> --room {args.room} --url {args.url}
Cameras are best-effort — remote control is unaffected if a camera is missing or the publisher dies.
Ctrl-C to stop everything.
==========================================================
""", flush=True)
stop = {"now": False}
signal.signal(signal.SIGINT, lambda *_: stop.update(now=True))
signal.signal(signal.SIGTERM, lambda *_: stop.update(now=True))
try:
while not stop["now"]:
for name, p, critical in procs:
if p.poll() is not None:
if critical:
print(f"[remote-real] critical child {name} exited (code {p.returncode}); shutting down", flush=True)
stop["now"] = True
# non-critical (cameras) exiting is logged once; control keeps running
time.sleep(0.3)
finally:
for name, p, _c in reversed(procs):
if p.poll() is None:
p.terminate()
for _name, p, _c in reversed(procs):
try:
p.wait(timeout=5)
except subprocess.TimeoutExpired:
p.kill()
print("[remote-real] stopped.", flush=True)
if __name__ == "__main__":
main()
05241c15dThis file is pinned to the selected release. Download the original to open it in your design tool.