Dashboard (web/hand_web.py) - Record/replay panel driving g1_record_replay.py as a pty child: take library (replay/download/duplicate/rename/delete/upload/delete-all), pause & resume, and in-take key buttons that grey out in the --fingers modes the recorder ignores (measured: in touch mode the keys change nothing at all). - /api/restart is container-aware: it kills inspire_g1 and lets the supervisor relaunch it. It used to run manage.sh, which started a SECOND inspire_g1 beside the supervised one - two writers on one RS-485 bus - and never returned. - Shape/combo libraries take a .bak on every write, with an undo button. Both files are rewritten in full, so deleting the last entry was unrecoverable. recorder/ - The recorder lives in this project now: one source of truth for the CLI and the dashboard, with pause/resume added to replay. - record.sh picks a runtime by itself (a python with the SDK, the vendored SDK, or the inspire-hand container). bundle.sh packs a ~340KB portable kit. tools/ - preflight.sh: read-only readiness report for a new robot (hardware, docker, build prerequisites, per-robot settings) ending in an install-path verdict. - fetch_deps.sh: stage build dependencies, verifying the libs are aarch64. - export_ui.py: regenerate an embedding app's vendored copy of the UI. docker/ - build_image.sh resolves its dependencies from several layouts: deps/ inside the project, /usr/local, a source install prefix, or a ROS2 colcon workspace (where the idl headers live when /usr/local has none). - web/ is copied in the last layer, so dashboard edits skip the C++ rebuild. - restart=always, and start.sh always builds so an edit cannot silently run a stale image. deps/unitree_sdk2 is vendored so a robot that has never seen the SDK can build. Docs: README quickstart + embedding notes, SETUP_G1 corrected (that udev rule stopped creating /dev/inspire_* symlinks a while ago), ROBOT_README describing a live install.
75 lines
2.8 KiB
Python
Executable File
75 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Regenerate a vendored copy of the dashboard UI for an app that embeds it.
|
|
|
|
Sanad's "Hands" tab serves a CODE COPY of this dashboard's HTML with every /api/
|
|
call rewritten to /api/hands/, and proxies those calls back to :8088. A hand copy
|
|
goes stale the moment hand_web.py changes — a button appears here and not there,
|
|
and nobody notices until it is needed. This regenerates that copy from the real
|
|
source, so re-vendoring is one command instead of an extraction by hand.
|
|
|
|
# write Sanad's copy (run after any dashboard change, then redeploy Sanad)
|
|
python3 tools/export_ui.py --prefix hands \
|
|
--out ~/Sanad_Package_5/Sanad/dashboard/static/hands.html
|
|
|
|
# check an existing copy is current, without writing (exit 1 if stale)
|
|
python3 tools/export_ui.py --prefix hands --check <path>
|
|
|
|
The HTML is taken from hand_web.py itself rather than re-parsed from a file, so
|
|
what gets vendored is exactly what the server serves.
|
|
"""
|
|
import argparse
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(HERE, "..", "web"))
|
|
|
|
|
|
def build(prefix):
|
|
import hand_web # noqa: E402 (path set above)
|
|
html = hand_web.HTML
|
|
if not prefix:
|
|
return html
|
|
# Only rewrite the API root. Absolute URLs that merely contain "api" (there are
|
|
# none today, but a future /api/... inside a string literal would be caught by
|
|
# the same rule) go through unchanged unless they start a request path.
|
|
out, n = re.subn(r"(?<![\w/])/api/", "/api/%s/" % prefix.strip("/"), html)
|
|
if not n:
|
|
sys.exit("no /api/ references found — has the dashboard HTML moved?")
|
|
return out
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser(description="Export the dashboard UI for embedding")
|
|
ap.add_argument("--prefix", default="hands",
|
|
help="proxy prefix the host app serves (default: hands -> /api/hands/)")
|
|
ap.add_argument("--out", help="write here (default: stdout)")
|
|
ap.add_argument("--check", metavar="PATH",
|
|
help="compare against PATH and exit 1 if it is stale")
|
|
a = ap.parse_args()
|
|
html = build(a.prefix)
|
|
|
|
if a.check:
|
|
try:
|
|
cur = open(a.check, encoding="utf-8").read()
|
|
except OSError as e:
|
|
sys.exit("cannot read %s: %s" % (a.check, e))
|
|
if cur == html:
|
|
print("up to date: %s" % a.check)
|
|
return
|
|
print("STALE: %s (%d bytes) differs from the current dashboard (%d bytes)"
|
|
% (a.check, len(cur), len(html)))
|
|
sys.exit(1)
|
|
|
|
if a.out:
|
|
with open(a.out, "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
print("wrote %s (%d bytes, prefix /api/%s/)" % (a.out, len(html), a.prefix))
|
|
else:
|
|
sys.stdout.write(html)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|