fix gamepad layout and refuse a pad whose axes disagree

An Xbox One S pad over Bluetooth numbers its controls differently from the
indices this node shipped with: the right stick is on axes 2 and 3, the
triggers on 4 and 5, and the buttons carry gaps at 2 and 5. Against the old
layout an untouched pad reported a resting trigger as full right-stick
deflection, which asked for 30 deg/s of pitch while lying on the desk, held
the lease for ever so GAMEPAD_IDLE_RELEASE_S never fired, and moved a real
arm into a controller error. X toggled freedrive and LB was the E-STOP, so
the resulting latch could not be released from the pad at all.

Layout now carries the swept indices. Each pad is also measured the first
time it is seen at rest: a stick must rest near centre and a trigger near
the bottom of its travel, and a pad that does not fit reads as absent and is
named in the log rather than driving an arm from a numbering nobody checked.
The measured rest becomes each axis's zero, so a worn stick's tilt is
subtracted rather than deadzoned away and a trigger that reads 0 until it
first moves stops reading as half pressed.

Rest is never re-measured while the pad is in use, because doing that under
a held stick would record the deflection as centre and the arm would move
when the operator let go. The probe drives from the same calibration, so
what it prints is still what the arm would get, and it shows the mismatch.

Tests name their controls through axes_for and buttons_for instead of
numbering them; the positional lists are why a wrong index passed a green
suite.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 18:06:06 -03:00
co-authored by Claude Opus 5
parent 7c1c33f5b1
commit d0f884c7e2
8 changed files with 514 additions and 84 deletions
+30 -18
View File
@@ -35,7 +35,7 @@ from dora import Node
from dora_teleop import joy, mapping
from dora_teleop.config import Config
from dora_teleop.mapping import LAYOUT
from dora_teleop.mapping import LAYOUT, axis_names
# What each velocity component is, in the order the arm takes them.
COMPONENTS = (
@@ -50,18 +50,6 @@ COMPONENTS = (
CLEAR = "\033[H\033[J"
def axis_names(layout=LAYOUT) -> dict[int, str]:
"""Name each axis index the layout uses."""
return {
layout.left_x: "left stick X",
layout.left_y: "left stick Y",
layout.left_trigger: "left trigger",
layout.right_x: "right stick X",
layout.right_y: "right stick Y",
layout.right_trigger: "right trigger",
}
def button_names(layout=LAYOUT) -> dict[int, str]:
"""Name each button index the layout uses."""
return {
@@ -89,8 +77,15 @@ def bar(value: float, width: int = 21) -> str:
return "".join(cells)
def render(sample, velocity: list[float], config: Config) -> str:
"""Build the whole display for one reading."""
def render(sample, driven, velocity: list[float], config: Config, mismatch: str | None = None) -> str:
"""Build the whole display for one reading.
``sample`` is the pad exactly as it was reported, because seeing the raw
numbers is the point of this tool. ``driven`` is the same reading after
calibration — what the node actually decides from — and ``velocity`` is what
it would send. A pad this node refuses reaches here as an absent ``driven``
and a ``mismatch`` saying why.
"""
lines = ["dora-teleop probe — Ctrl-C to stop", ""]
if not sample.present:
@@ -102,6 +97,18 @@ def render(sample, velocity: list[float], config: Config) -> str:
]
return "\n".join(lines)
if mismatch:
lines += [
" this pad does not match the layout, and the arm will not be driven from it.",
"",
f" {mismatch}",
"",
" Either something was being held when it was plugged in, or the indices",
" below are numbered differently on this pad. The axes are raw, so they",
" say which: fix `Layout` in dora_teleop/mapping.py to match them.",
"",
]
names = axis_names()
lines.append(f" axes ({len(sample.axes)} reported)")
for index, value in enumerate(sample.axes):
@@ -121,7 +128,7 @@ def render(sample, velocity: list[float], config: Config) -> str:
lines += [
"",
f" moving: {moving}",
f" asking for the arm: {'yes' if mapping.is_active(sample) else 'no'}",
f" asking for the arm: {'yes' if mapping.is_active(driven) else 'no'}",
]
return "\n".join(lines)
@@ -137,14 +144,19 @@ def main() -> None:
args = parser.parse_args()
config = Config.from_env()
calibration = joy.Calibration()
node = Node(args.name)
for event in node:
if event["type"] != "INPUT" or event["id"] != "joy":
continue
sample = joy.decode(event)
velocity = mapping.velocity(sample.axes, sample.buttons, config) if sample.present else [0.0] * 6
print(CLEAR + render(sample, velocity, config), flush=True)
# Through the same calibration the node drives from, so what this prints
# stays what the arm would get. What is displayed is still the raw
# reading: the indices are what a pad is checked against.
driven = calibration.apply(sample)
velocity = mapping.velocity(driven.axes, driven.buttons, config) if driven.present else [0.0] * 6
print(CLEAR + render(sample, driven, velocity, config, calibration.mismatch), flush=True)
if __name__ == "__main__":