Files
dora-teleop/tests/test_console.py
cristhian da1b079b7b
validate / validate (pull_request) Successful in 58m41s
validate / test (pull_request) Successful in 58m44s
validate / markdownlint (pull_request) Successful in 58m40s
serve the web console from the node and drop the websocket bridge
The browser reached this node through `dora-websocket-transceiver`: a second
node, a second port, and a round trip through the dataflow for every button
press, to carry a UI only this node can interpret. The node now serves the
page and holds the browsers' sockets itself on one port, so the console is
one URL and a consumer wires nothing for it.

`dora_teleop/server.py` runs aiohttp on a thread of its own and meets the
control loop at two non-blocking points: a bounded queue the tick drains, and
a snapshot handed back. Both queues are bounded deliberately — a flood is
dropped rather than grown, and a slow browser loses stale snapshots rather
than the newest — because nothing a browser does may stall the thread that
stops the arm. A port already in use stops the node rather than leaving it
announcing a console nobody can open.

The web deadman moved but did not change: it was a `clients` message from the
bridge and is now the open-socket count read each tick. One hop fewer, same
meaning.

Contract, so 0.2.0 -> 0.3.0: `ui_command` and `clients` are gone. `ui_state`
stays published for `dora topic echo` and the bench, with no browser reading
it. New WEB_HOST and WEB_PORT (7000; 0 opens no port).

The console itself is laid out like the arm's own pendant — two rings
quartered into arc sectors you hold, each with its out-of-plane axis as pills
above. Directions and signs match xArm Studio on the controller, `Y+` on the
left included: two consoles driving one arm that disagree about which way is
+Y is a trap, not a preference.

Also sends a velocity only when it changes, repeating an unchanged one on
JOG_KEEPALIVE_S (0.2 s) purely to beat the consumer's own expiry. Repeating
every tick made `dora-ulite6` re-plan the same motion twenty times a second.
That turned out not to be the whole cause of the stepping an operator felt —
the rest was fixed in dora-ulite6 v0.3.1, pinned here — but sending 18
messages where 83 went before is worth keeping on its own.

`dora-joy` moves to v0.1.1: v0.1 is an annotated tag, and dora 1.0.1 records
the tag object's id as the commit hash and then rejects its own checkout for
sitting on the peeled commit. Neither dataflow could be built before this.
2026-09-16 14:50:21 -03:00

90 lines
3.2 KiB
Python

"""The page and the node are one contract, checked here rather than by eye.
`ui.py` translates for a console it cannot import, and the page reads telemetry
by key. Nothing in either language catches a rename, so a typo would surface as
a dead button on a machine that can move — which is the wrong place to find it.
"""
import json
import re
from pathlib import Path
from dora_teleop import ui
PAGE = Path(__file__).resolve().parent.parent / "dora_teleop" / "web" / "index.html"
def page():
return PAGE.read_text()
def sent_types():
"""Return every message type the page can send."""
return set(re.findall(r'type:\s*"([a-z_]+)"', page()))
def read_keys():
"""Return the telemetry keys the page renders by name."""
listed = re.search(r"const KEYS = \[(.*?)\]", page(), re.DOTALL).group(1)
return set(re.findall(r'"([a-z_]+)"', listed))
def snapshot_keys():
view = ui.ArmView()
view.pose = [1.0] * 6
return set(ui.snapshot(view, "web", False, 0.0))
def test_every_message_the_page_sends_is_one_the_node_serves():
# `data` is the bridge's own envelope, not a console command.
for kind in sent_types() - {"data"}:
assert ui.command_of({"type": kind}) is not None or kind == "jog", kind
def test_every_telemetry_key_the_page_reads_is_one_the_node_sends():
missing = read_keys() - snapshot_keys()
assert not missing, f"the page reads keys the node does not send: {sorted(missing)}"
def test_the_page_reads_the_pose_units_from_the_node():
# Rather than assuming mm, which is only true of one robot.
assert "units.position" in page().replace("telemetry.units && telemetry.units.position", "units.position")
assert "units" in snapshot_keys()
def test_the_jog_the_page_sends_is_normalised_and_accepted():
# Six axes, each a fraction of full deflection. If the page ever sent a
# velocity instead, it would have to know the robot's units.
command = ui.command_of(json.loads('{"type": "jog", "axes": [0, -0.6, 0, 0, 0, 0]}'))
assert command is not None
assert command.axes == [0.0, -0.6, 0.0, 0.0, 0.0, 0.0]
def test_the_page_can_ask_for_everything_the_node_serves():
# `move` is the one command with no button: it is a pose in the robot's own
# units, which is exactly what this page is built not to know.
served = {"jog", "jog_stop", "estop", "reset", "home", "control", "gripper", "freedrive"}
assert served <= sent_types()
def test_the_page_gates_its_jog_pad_on_holding_the_lease():
# The node refuses a jog from a non-owner and answers with a toast; a pad
# that looks live but is refused teaches an operator to distrust the screen.
assert 'owner === "web"' in page()
def test_the_published_schemas_do_not_depend_on_the_value_sent():
# pyarrow reads a null `value` as its own type, so an inferred schema would
# change the type of the `command` port between one verb and the next.
from dora_teleop import message
assert message.pack_command("stop", None).type == message.COMMAND
assert message.pack_command("freedrive", 1.0).type == message.COMMAND
assert (
message.pack_twist({"linear": [0.0] * 3, "angular": [0.0] * 3, "frame": "base"}).type == message.TWIST
)
assert message.pack_jog([0.0] * 6).type == message.JOG