diff --git a/data/fetch_calib.json b/data/fetch_calib.json index 4bf0497..b06ad49 100644 --- a/data/fetch_calib.json +++ b/data/fetch_calib.json @@ -1 +1 @@ -{"arm_yaw_in_base_deg": -95.5, "objects": ["cup", "cup"], "waist_deg": -20.31, "measured": "2026-10-19 15:55 (median of -96.4, -94.9, -95.5; one run that paired both cups with one was left out)", "arm_xy_in_base_m": [0.074, -0.085], "arm_xy_measured": "2026-10-30 20:49", "arm_xy_samples": [[0.041, -0.114], [0.051, -0.127], [0.087, -0.078], [0.074, -0.085], [0.069, -0.085], [0.049, -0.08], [0.095, -0.104], [0.08, -0.079], [0.075, -0.092]]} \ No newline at end of file +{"arm_yaw_in_base_deg": -95.5, "objects": ["cup", "cup"], "waist_deg": 0.09, "measured": "2026-10-19 15:55 (median of -96.4, -94.9, -95.5; one run that paired both cups with one was left out)", "arm_xy_in_base_m": [0.074, -0.085], "arm_xy_measured": "2026-10-30 20:49", "arm_xy_samples": [[0.041, -0.114], [0.051, -0.127], [0.087, -0.078], [0.074, -0.085], [0.069, -0.085], [0.049, -0.08], [0.095, -0.104], [0.08, -0.079], [0.075, -0.092]], "waist_note": "from the front since 2026-11-13 (was -20.31 on the controller's own scale, WAIST_FRONT_DEG -20.4)"} \ No newline at end of file diff --git a/data/hover_readings.json b/data/hover_readings.json new file mode 100644 index 0000000..cd36974 --- /dev/null +++ b/data/hover_readings.json @@ -0,0 +1,101 @@ +{ + "note": "skills.py hover readings: ring centre minus rim centre (dx + = Lumi's right, dy + = away), arm frame, mm. Input to skills.py offset.", + "cup": [ + -126, + 619 + ], + "top_mm": -188, + "readings": [ + { + "turn_deg": 0, + "dx": 2, + "dy": 4, + "how": "moved the hovering hand -2 / -4 until the ring was centred, 15 mm over the rim" + } + ], + "spots": [ + { + "cup": [ + -70, + 591 + ], + "top_mm": -188, + "readings": [ + { + "turn_deg": 0, + "dx": 2, + "dy": 1 + }, + { + "turn_deg": -15, + "dx": -5, + "dy": -1 + }, + { + "turn_deg": -30, + "dx": -6, + "dy": -3 + } + ] + }, + { + "cup": [ + 36, + 559 + ], + "top_mm": -191, + "readings": [ + { + "turn_deg": -15, + "dx": -5, + "dy": -7 + }, + { + "turn_deg": -45, + "dx": -8, + "dy": -12 + } + ] + } + ], + "checks_after_fix": [ + { + "cup": [ + -1, + 594 + ], + "turn_deg": -45, + "dx": -4, + "dy": 0 + }, + { + "cup": [ + -2, + 590 + ], + "turn_deg": -30, + "dx": -8, + "dy": 0 + }, + { + "cup": [ + -2, + 592 + ], + "turn_deg": -30, + "dx": -4, + "dy": 0, + "calib": "ROUND_FIX (13.9, -3.1)" + }, + { + "cup": [ + 10, + 540 + ], + "turn_deg": 0, + "dx": 0, + "dy": 0, + "calib": "ROUND_FIX (13.9, -3.1)" + } + ] +} \ No newline at end of file diff --git a/robot/head.py b/robot/head.py index 367734c..527b09f 100644 --- a/robot/head.py +++ b/robot/head.py @@ -21,13 +21,19 @@ HEAD_REST_PITCH = PITCH_RANGE[0] # deg; the head's rest: its lowest, looking do # and near things are in view. Every "head back / ahead" uses it; yaw rests at 0 VEL = 40 # speed ratio %, 1-100 (was 15: too slow to follow a visitor) ACC = 40 # acceleration ratio %, 1-100 +ENABLE_TIMEOUT_S = 10.0 # s for reset / enable: the controller answers enable after more than 2 s (2026-11-13: + # the app's BODY enable failed twice with a 2 s timeout right after a power cycle) # Temporary: the head camera's cable is too short, any lift above the bottom pulls it out, so the lift stays at 0 and # Lumi searches by driving and turning. Back to 250 mm (the body API allows 300) when the longer cable is in. LIFT_MAX_MM = 0.0 -# [lift mm, waist, head yaw, head pitch] limits of the body API (docs/03), the lift held to LIFT_MAX_MM. The controller -# drops a whole moveto when any value is outside, and its own encoders read a little past the ends (pitch -5.003 at -# the bottom stop). -AXIS_LIMITS = ((0.0, LIFT_MAX_MM), (-140.0, 140.0), (-180.0, 180.0), (-5.0, 35.0)) +# The controller's waist reading when the torso faces the base's front (the torso camera and the logo over the base's +# middle): owner by eye 2026-11-13; at the controller's 0 the torso stood about 20 deg to the left. Every waist angle +# outside this file is from the front (+ left), so 0 is the front everywhere; only _call's raw values are not. +WAIST_FRONT_DEG = -20.4 +# [lift mm, waist, head yaw, head pitch] limits of the body API (docs/03: waist -140..140 on the controller), the lift +# held to LIFT_MAX_MM, the waist from the front. The controller drops a whole moveto when any value is outside, and its +# own encoders read a little past the ends (pitch -5.003 at the bottom stop). +AXIS_LIMITS = ((0.0, LIFT_MAX_MM), (-140.0 - WAIST_FRONT_DEG, 140.0 - WAIST_FRONT_DEG), (-180.0, 180.0), (-5.0, 35.0)) _one = threading.Lock() # one moveto at a time: overlapping calls hang the body API owners = () # threads that own the body now (tasks/follow.py); empty: anyone may move it @@ -41,8 +47,9 @@ def _call(path, body=None, timeout=2): def moveto(pos, vel=VEL, acc=ACC, timeout=30): - """Move all four body joints; every value is clamped into AXIS_LIMITS. Blocks until the motion ends (and while - another thread's moveto runs). None, nothing sent, when other threads own the body (`owners`).""" + """Move all four body joints (the waist from the front); every value is clamped into AXIS_LIMITS. Blocks until the + motion ends (and while another thread's moveto runs). None, nothing sent, when other threads own the body + (`owners`).""" if owners and threading.current_thread() not in owners: return None # ponytail: skipped silently, the owner turns it back pos = [max(lo, min(hi, float(p))) for p, (lo, hi) in zip(pos, AXIS_LIMITS)] @@ -55,13 +62,42 @@ def moveto(pos, vel=VEL, acc=ACC, timeout=30): if all(abs(a["pos"] - b["pos"]) < 0.05 for a, b in zip(before, joints)): # the positions tell break if not all(j["enable"] for j in joints): # off after a controller power cycle; moveto needs them on - _call("enable", {"enable": 1}) - return _call("moveto", {"pos": pos, "vel": vel, "acc": acc}, timeout=max(1.0, end - time.time())) + _call("enable", {"enable": 1}, timeout=ENABLE_TIMEOUT_S) + raw = [pos[0], pos[1] + WAIST_FRONT_DEG, pos[2], pos[3]] # the controller counts the waist from its own 0 + return _call("moveto", {"pos": raw, "vel": vel, "acc": acc}, timeout=max(1.0, end - time.time())) + + +def joints(): + """The controller's status, one dict per joint (id, pos, vel, toq, enable, error, ecode), the waist's pos from the + front (WAIST_FRONT_DEG).""" + j = _call("status") + j[1] = {**j[1], "pos": j[1]["pos"] - WAIST_FRONT_DEG} + return j def status(): """[lift mm, waist deg, head yaw deg, head pitch deg]""" - return [j["pos"] for j in _call("status")] + return [j["pos"] for j in joints()] + + +def enabled(): + """True when all four body joints are enabled.""" + return all(j["enable"] for j in joints()) + + +def set_enabled(on, retries=5): + """Enable (vendor pattern: reset, enable, check, repeat) or disable all four body joints. Returns enabled().""" + with _one: # never in the middle of a moveto + if not on: + _call("enable", {"enable": 0}, timeout=ENABLE_TIMEOUT_S) + return enabled() + for _ in range(retries): + _call("reset", {}, timeout=ENABLE_TIMEOUT_S) + _call("enable", {"enable": 1}, timeout=ENABLE_TIMEOUT_S) + if enabled(): + return True + time.sleep(0.3) + return enabled() def turn(yaw, pitch=None, vel=VEL, acc=ACC, limit=YAW_LIMIT):