diff --git a/assistant/lumi.py b/assistant/lumi.py index c928b6d..729b131 100644 --- a/assistant/lumi.py +++ b/assistant/lumi.py @@ -1130,11 +1130,14 @@ class Lumi: self.fetch_finish(action) def look_at_speaker(self): - """"Look at me": the person seen nearest the voice (both cameras). Nobody seen there: the head turns to the - voice first, then to whoever the head camera finds there; nobody there either (the voice direction can be - off): the person talked to, else the nearest person seen. Nobody seen and no voice: the head stays. Then the - head tilts until the head camera sees the person from their head down (look_me_pitch). That person becomes - the one talked with, and while the look is held the head follows them (look_me, keep_focus).""" + """"Look at me": the cameras first, the voice direction only to choose. Someone seen (both cameras): the one + near the voice, else the person talked with, else the one nearest where the head looks; the body never turns + then (a sure voice read 90 deg off in the median and put a person in front behind, 2026-10-28/29, so a repeat + "look at me" flipped the base from side to side). Nobody seen: the head sweeps the voice's side, then the + other side; nobody there either and a sure voice past the head's reach: the body turns to it (turn_body_to) + and the head looks there. Then the head tilts until the head camera sees the person from their head down + (look_me_pitch). That person becomes the one talked with, and while the look is held the head follows them + (look_me, keep_focus).""" if not self.vision: return self.head_busy = True # keep_focus waits: the head is turned here @@ -1153,28 +1156,38 @@ class Lumi: recent = time.time() - getattr(self, "voice_at", 0.0) <= VOICE_KEEP_S # this turn's sound too weak: the voice = self.voice_angle if self.voice_trusted or recent else None # caller's last sure direction + gaze = HEAD_SIGN * self.det_yaw() seen = self.vision.seen() - found = near(seen, voice) if voice is not None else None - if found is None and voice is not None and abs(voice) > head.YAW_LIMIT: - voice = self.turn_body_to(voice) # behind or far aside: the head alone can't get there - if found is None and voice is not None: - log(f" look me: nobody seen at the voice ({voice:+.0f} deg), turning there first") - face(voice) - time.sleep(LOOK_ME_SETTLE_S) # new head camera frames from there - seen = self.vision.seen() - found = near(seen, voice) - why = "nearest the voice" - if found is None: + found, why = (near(seen, voice), "nearest the voice") if voice is not None else (None, "") + if found is None and seen: cur = self.current if self.current and self.vision.present(self.current) else None if cur: found, why = (cur.angle, cur.distance), f"the person talked with (#{cur.id})" - elif voice is not None: # the voice off: the person nearest its direction, not - found = min(seen, key=lambda s: abs(s[0] - voice), default=None) # the nearest one far off it - why = f"nearest the voice's side ({voice:+.0f} deg)" - else: - found, why = min(seen, key=lambda s: s[1], default=None), "the nearest seen, no voice direction" + else: # stays on whoever the head is on: never the other side + found = min(seen, key=lambda s: abs(s[0] - gaze)) + why = "nearest where the head looks" + ("" if voice is None else f", none at the voice {voice:+.0f} deg") + if found is None: # nobody in view: the head camera looks around first + first = gaze if voice is None else max(-head.YAW_LIMIT, min(head.YAW_LIMIT, voice)) + side = 1.0 if first >= 0 else -1.0 + for a in (side * head.YAW_LIMIT, -side * head.YAW_LIMIT): + log(f" look me: nobody seen, looking at {a:+.0f} deg") + face(a) + time.sleep(LOOK_ME_SETTLE_S) # new head camera frames from there + seen = self.vision.seen() + if seen: + found, why = min(seen, key=lambda s: abs(s[0] - a)), "found looking around" + break + if found is None and voice is not None and abs(voice) > head.YAW_LIMIT: + voice = self.turn_body_to(voice) # behind: the head alone can't get there + self.voice_angle, self.voice_trusted, self.voice_at = voice, False, 0.0 # measured before the turn: + log(f" look me: turned toward the voice, looking at {voice:+.0f} deg") # never used again + face(voice) + time.sleep(LOOK_ME_SETTLE_S) + seen = self.vision.seen() + found, why = min(seen, key=lambda s: abs(s[0] - voice), default=None), "after turning to the voice" if found is None: - log(f" look me: nobody seen{'' if voice is None else ' at the voice either'}, the head stays") + log(" look me: nobody seen, the head goes back") + face(gaze) return log(f" look me: person at {found[0]:+.0f} deg, {found[1]:.2f} m ({why})") face(found[0]) @@ -3356,7 +3369,9 @@ class Lumi: if t is not None: return t view = CAMERA_HALF_FOV + (head.YAW_LIMIT if self.vision.camera == "head" else 0.0) - w = waist_turned() if abs(robot_angle) > view and self.modes.patrol else None + w = waist_turned() if abs(robot_angle) > view and self.modes.patrol and not self.vision.seen() else None + # someone in view: no base turn on the voice alone (it read a person in front as behind), the head path + # below falls back to the person seen nearest the voice's side if w is not None and waist_home("turning to a caller", fold=True): log(f" caller outside the camera ({robot_angle:+.0f} deg): turning toward the voice") self.turn_head(0, force=True) # a call or an order: also over a held look diff --git a/tests/test_follow_listen.py b/tests/test_follow_listen.py index 92a4f3b..973c3a7 100644 --- a/tests/test_follow_listen.py +++ b/tests/test_follow_listen.py @@ -118,7 +118,7 @@ for by_clip in (True, False): run["on"] = False L = fresh("What time is it?", -70.0) assert L.talk_turn() and heard == ["What time is it?"] and L.current is L.vision.stranger, (heard, L.current) -# "look at me" / "이쪽 봐": the head turns to this turn's voice first; nobody there: to the person seen (-60) +# "look at me" / "이쪽 봐": the cameras first: the person seen (-60), whatever the voice says lumi.head.turn = lambda yaw, pitch=None: done.append(("head turn", round(yaw))) lumi.LOOK_ME_SETTLE_S = 0.0 @@ -130,7 +130,7 @@ def looked(L, want): return [d for d in done if d[0] == "head turn"] == want -for deg, want in ((40.0, [50, -60]), (-70.0, [-60])): +for deg, want in ((40.0, [-60]), (-70.0, [-60])): L = fresh("이쪽 봐 줘", deg) L.answer = lambda text: lumi.Lumi.act(L, "look", "me") L.base_off, L.mission_running = (lambda *a, **k: False), (lambda: False) diff --git a/tests/test_look_me.py b/tests/test_look_me.py index b1a9915..e86b324 100644 --- a/tests/test_look_me.py +++ b/tests/test_look_me.py @@ -1,5 +1,5 @@ -"""Self-check of "look at me": the person seen nearest the voice (head or torso camera), the voice first when nobody -is seen there, nobody seen -> the head stays. No robot: python tests/test_look_me.py""" +"""Self-check of "look at me": the cameras first (head or torso camera), the voice only chooses among the people seen; +nobody seen -> the head looks around, then a sure voice from behind turns the body. No robot: python tests/test_look_me.py""" import math import no_robot # noqa: F401 any connection to the robot fails the test @@ -27,10 +27,11 @@ class Vision: return None -def look(seen, voice=None, after=None): +def look(seen, voice=None, after=None, gaze=0.0): L = lumi.Lumi.__new__(lumi.Lumi) L.vision, L.current = Vision(seen, after), None L.voice_angle, L.voice_trusted = (voice or 0.0), voice is not None + L.det_yaw = lambda: gaze turns.clear() L.look_at_speaker() return list(turns) @@ -40,12 +41,21 @@ def look(seen, voice=None, after=None): assert look([(-33.0, 0.78)]) == [-33], turns # the voice agrees with a person seen: that person, not the nearer one elsewhere assert look([(-33.0, 1.2), (40.0, 0.6)], voice=-20.0) == [-33], turns -# the voice comes from out of view: the head turns there, then to the person its camera finds -assert look([(40.0, 0.6)], voice=-55.0, after=[(-50.0, 0.9), (40.0, 0.6)]) == [-55, -50], turns -# the voice direction is wrong (left), the only person is on the right: voice first, then the person seen -assert look([(-33.0, 0.78)], voice=50.0) == [50, -33], turns -# nobody seen, no voice: the head does not move (it used to tilt up) -assert look([]) == [], turns +# someone in view, the voice elsewhere: the person seen (the voice read people in front as behind, 2026-10-29) +assert look([(40.0, 0.6)], voice=-55.0) == [40], turns +assert look([(-33.0, 0.78)], voice=50.0) == [-33], turns +# the owner's report: person in front at -22, repeat "look at me" with the voice read at +128 / -122 / +120 behind: +# the head stays on them every time, the base never turns +for v in (128.0, -122.0, 120.0, -120.0): + assert look([(-22.0, 1.3)], voice=v) == [-22], (v, turns) +# several seen, none at the voice: the one nearest where the head looks, not one on the voice's side +assert look([(-30.0, 1.0), (35.0, 1.0)], voice=150.0, gaze=-25.0) == [-30], turns +# nobody seen: the head looks to the voice's side first, finds the person there +assert look([], voice=-55.0, after=[(-50.0, 0.9)]) == [-60, -50], turns +# nobody seen on that side either: the other side, then back where it looked when nobody is anywhere +assert look([], voice=-55.0) == [-60, 60, 0], turns +# nobody seen, no voice: looks around and back +assert look([], gaze=10.0) == [60, -60, 10], turns # "Lumi" with the voice read on the left, nobody there: the head turns there, then to the person seen, else back heads = [] @@ -67,6 +77,19 @@ for seen, want in (([(-33.0, 0.8)], [50, -33]), ([], [50, 5])): heads.clear() assert L.find_caller(50.0, True) is None and heads == want, heads +# a call with the voice read behind (+150) while someone stands in view at -22: no base turn, the head finds them +base = [] +lumi.agv.turn_by = lambda rad: base.append(rad) +lumi.waist_turned = lambda: 0.0 +L = lumi.Lumi.__new__(lumi.Lumi) +L.vision, L.current = Head([(-22.0, 1.3)]), None +L.modes = type("M", (), {"patrol": True})() +L.det_yaw = lambda: 0.0 +L.turn_head = lambda yaw=None, pitch=None, force=False: heads.append(round(yaw)) +heads.clear() +L.find_caller(150.0, True) +assert base == [] and heads == [60, -22], (base, heads) + # the pitch follows the person in the head camera (torso camera intrinsics, near the head camera's) FY, CY, H = 608.4, 363.2, 720 far = lumi.look_me_pitch @@ -96,6 +119,7 @@ class Camera(Vision): def look_pitch(cam): L = lumi.Lumi.__new__(lumi.Lumi) L.vision, L.current, L.voice_angle, L.voice_trusted = cam, None, 0.0, False + L.det_yaw = lambda: 0.0 turns.clear(), pitches.clear() L.look_at_speaker() return [round(p) for p in pitches] @@ -125,9 +149,11 @@ fetch._waist_to = fake_waist_to L = lumi.Lumi.__new__(lumi.Lumi) L.vision, L.current = Vision([]), None L.voice_angle, L.voice_trusted = 170.0, True +L.det_yaw = lambda: 0.0 L.modes = type("M", (), {"patrol": False})() turns.clear() L.look_at_speaker() assert waist["calls"] == [(120, True, 170.0)], waist -assert turns == [50], turns # 170 - 120 left for the head +assert turns == [60, -60, 50, 0], turns # looked around first; 170 - 120 left for the head; nobody: back +assert not L.voice_trusted and L.voice_at == 0.0 # a direction measured before the turn is never used again print("look me behind: ok")