diff --git a/assistant/lumi.py b/assistant/lumi.py index e5228a7..eee9e24 100644 --- a/assistant/lumi.py +++ b/assistant/lumi.py @@ -427,6 +427,11 @@ PROMPT = {"en": "How can I help you?", "ko": "무엇을 도와드릴까요?"} WELCOME_BACK = {"en": "Welcome back! How can I help you?", "ko": "다시 오셨네요, 무엇을 도와드릴까요?"} WAVE_CHECK_S = 0.4 # s between two looks for a raised hand (pose net, ~20 ms); two looks in a row WAVE_MATCH_DEG = 15.0 # deg; a raised hand belongs to the tracked person within this angle +GAZE_MATCH_DEG = 15.0 # deg; the person this near where the head looks is the one Lumi looks at (estimate) +RAISE_HAND_S = 6.0 # s a "raise your hand" waits for the one who gave the order +RAISE_HAND_SAY = ("Who asked? Please raise your hand.", "누가 말씀하셨어요? 손을 들어 주세요.") +WHO_ASKED_SAY = ("Sorry, I couldn't tell who asked. Please come in front of me.", + "누가 말씀하셨는지 모르겠어요. 제 앞으로 와 주세요.") IN_VIEW_S = 0.5 # s; a track seen this recently is someone else in view (not the one coming back) PATH_HALF_WIDTH = 0.4 # m to each side of the robot's centre line; on patrol only people in this # corridor are greeted (not people sitting at desks beside the aisle) @@ -718,6 +723,11 @@ class Vision(threading.Thread): with self.lock: return track in self.tracks + def anyone(self): + """Is anybody tracked now, at any distance?""" + with self.lock: + return bool(self.tracks) + def only_seen(self): """The one person tracked, at any distance (4.7 m away, "do you see me?" yes, "come here" said "I can't see you", 2026-10-28), else None.""" @@ -2179,8 +2189,9 @@ class Lumi: pass track = None if self.vision: - track = self.current if self.current and self.vision.visible(self.current) else \ - self.vision.near_angle(self.voice_angle) if self.voice_trusted else self.vision.only_seen() + track = self.speaker_track() # who asked: the voice, the talk, the look, a raised hand + if track is None and self.vision.anyone(): # several seen, nobody raised a hand: raised_hand said so + return None if track is not None and track.distance > REACH_COME_M: # far: go to them first, never reach from afar if not self.modes.drive: self.fetch_say(*COME_CLOSER_SAY) @@ -3281,6 +3292,50 @@ class Lumi: self.answer(command) return True + def speaker_track(self): + """Who gave the order ("come here", "give me your hand", "follow me"), in this order, never a guess: + 1) this turn's voice direction when sure (find_caller: the person there, else it turns there and looks); + 2) the person talked with, still tracked (at any distance); 3) the person the head looks at (GAZE_MATCH_DEG: + "look at me" left it on them); 4) the one person tracked; 5) else the one who raises a hand when asked + (raised_hand). A voice direction that is not sure is never used: it was off by up to 90 deg (2026-10-28). + None when nobody can be told.""" + if not self.vision: + return None + if self.voice_trusted: + t = self.find_caller(self.voice_angle, True) + if t is not None: + return t + if self.current is not None and self.vision.visible(self.current): + return self.current + t = self.vision.near_angle(HEAD_SIGN * self.det_yaw(), GAZE_MATCH_DEG) + if t is not None: + log(f" speaker: person #{t.id}, the one I look at") + return t + return self.vision.only_seen() or self.raised_hand() + + def raised_hand(self): + """Several people in view and nothing tells who spoke: they are asked to raise a hand; the tracked person whose + hand is up in two looks is taken. None (said) when nobody does in RAISE_HAND_S; None at once when nobody is + tracked (the caller says it can't see them).""" + if not self.vision.anyone(): + return None + self.fetch_say(*RAISE_HAND_SAY) + from vision import scene + ups, end = {}, time.time() + RAISE_HAND_S + while time.time() < end: + frames = safe(scene.snapshot, (self.vision.camera,), default=[]) or [] + for w in safe(hands_up, frames, default=[]) or []: + t = self.vision.near_angle(w, WAVE_MATCH_DEG) + if t is not None: + ups[t.id] = ups.get(t.id, 0) + 1 + if ups[t.id] >= 2: + log(f" speaker: person #{t.id}, hand raised at {t.angle:+.0f} deg, {t.distance:.2f} m") + return t + time.sleep(WAVE_CHECK_S) + log(" speaker: nobody raised a hand") + self.fetch_say(*WHO_ASKED_SAY) + return None + def find_caller(self, robot_angle, trusted): """The visible person who called (voice direction + camera). If the voice comes from outside what the camera can see (the head camera also by turning the head), turn the base toward it first, then look for @@ -3347,10 +3402,10 @@ class Lumi: mouth.say("Sorry, driving is switched off.") return if track is None or not self.vision or not self.vision.visible(track): - track = self.find_caller(self.voice_angle, self.voice_trusted) # look where the voice came from - if track is None and self.vision: # the voice unsure: the one person in view, also far - track = self.vision.only_seen() + track = self.speaker_track() # who said it: the voice, the talk, the look, a raised hand if track is None: + if self.vision and self.vision.anyone(): # several seen, nobody raised a hand: raised_hand said so + return mouth.say("I can't see you. Could you wave or step in front of me?" if self.lang == "en" else "보이지 않아요. 손을 흔들거나 제 앞으로 와 주시겠어요?") return @@ -3470,9 +3525,9 @@ class Lumi: if self.skill_busy(): self.fetch_say("Sorry, I'm on a task right now.", "죄송해요, 지금 다른 일을 하고 있어요.") return - track = self.current if self.current is not None and self.vision and self.vision.present(self.current) else None - if track is None and self.vision: - track = self.find_caller(self.voice_angle, self.voice_trusted) + track = self.speaker_track() # who asked: the voice, the talk, the look, a raised hand + if track is None and self.vision and self.vision.anyone(): # nobody raised a hand: raised_hand said so + return if track is None: mouth.say("I can't see you. Could you step in front of me?" if en else "보이지 않아요. 제 앞으로 와 주시겠어요?") self.keep_listening() @@ -3549,6 +3604,8 @@ class Lumi: if self.current and not self.vision.present(self.current): gone = self.current # often the same person under a new track id (#5 -> #7 at again = None if following else self.vision.near_angle(gone.angle, FOCUS_REFIND_DEG) # 19:24, 2026-10-27) + if again is gone or again is not None and again.distance > STAY_MAX: # the same track, only far: gone + again = None # (else "seen again as" itself, ~33000 times a s, 2026-10-28) if again is not None: log(f"person #{gone.id} seen again as #{again.id} at {again.angle:+.0f} deg") again.greeted, self.current = True, again diff --git a/tests/test_focus.py b/tests/test_focus.py index 7ceabf2..2f25995 100644 --- a/tests/test_focus.py +++ b/tests/test_focus.py @@ -42,6 +42,9 @@ class Vision: visible = present + def anyone(self): + return bool(self.tracks) + def only_seen(self): return self.tracks[0] if len(self.tracks) == 1 else None @@ -196,4 +199,28 @@ L.turn_head = lambda yaw=None, pitch=None, force=False: heads.append((round(yaw) L.find_caller(50.0, True) lumi.time.sleep = real_sleep assert heads == [(S * 50, True), (S * 38, True)], heads +# ---- who gave the order (speaker_track): never the wrong one of several people ---- +owner, other = Track(20, 60.0, 4.0), Track(21, 0.0, 2.0) +L = fresh(owner, other) # the owner far behind the head's turn, someone else near ahead: +L._yaw = S * 60.0 # the head looks at the owner ("look at me" left it there) +L.voice_trusted = False +assert L.speaker_track() is owner and not said +L = fresh(owner, other) +L.voice_trusted, L.voice_angle = True, 2.0 # a sure voice wins over the look +assert L.speaker_track() is other +L = fresh(owner, other) # the voice unsure, the head between them, nobody talked with: +L.voice_trusted, L.voice_angle, L._yaw = False, 5.0, S * 30.0 # asked to raise a hand, the one who does is taken +up.append(60.0) +assert L.speaker_track() is owner and said == [lumi.RAISE_HAND_SAY[0]], said +up.clear() +L = fresh(owner, other) # nobody raises a hand: nobody is taken, it says so +L.voice_trusted, L._yaw, real_raise, lumi.RAISE_HAND_S = False, S * 30.0, lumi.RAISE_HAND_S, 0.3 +assert L.speaker_track() is None and said == [lumi.RAISE_HAND_SAY[0], lumi.WHO_ASKED_SAY[0]], said +goals = [] # ... and "come here" then drives nowhere, no "can't see you" +lumi.agv.go_point = lambda *a: goals.append(a) or (True, "") +L = fresh(owner, other) +L.voice_trusted, L._yaw = False, S * 30.0 +L.come_to(None) +assert not goals and said == [lumi.RAISE_HAND_SAY[0], lumi.WHO_ASKED_SAY[0]], said +lumi.RAISE_HAND_S, lumi.agv.go_point = real_raise, (lambda *a: (True, "")) print("focus ok") diff --git a/tests/test_follow.py b/tests/test_follow.py index d8077f6..670e78d 100644 --- a/tests/test_follow.py +++ b/tests/test_follow.py @@ -182,6 +182,7 @@ print("too close: stands still") # every stop word ends it at once (lumi.follow_stop, as answer() calls it); then "follow me" starts again L = lumi.Lumi.__new__(lumi.Lumi) +L._yaw, L._yaw_time = 0.0, float("inf") # the head at the front (det_yaw reads no body) stops = [] L.stop_all = lambda: stops.append(1) STOP = ["stop", "Stop!", "enough", "that's enough", "wait", "wait, Lumi", "stay here", "you can stop", "hold on", @@ -664,8 +665,10 @@ L.current, started[:] = None, [] L.follow_me() assert not started and "can't see you" in spoken[-1] L.find_caller = lambda angle, trusted: track # where the voice came from +L.voice_trusted = True # (only a sure direction counts) L.follow_me() assert started and L.current is track +L.voice_trusted = False started.clear() L.modes.drive = False L.follow_me() @@ -675,6 +678,7 @@ L.follow_me() assert not started and "on a task" in spoken[-1] L.skill_busy, real_ready = (lambda: False), follow.ready follow.ready = lambda: fetch.ARM_UNSEEN # checked before "Okay" +L.voice_trusted = True # the person found by the voice L.follow_me() assert not started and spoken[-1] == fetch.ARM_UNSEEN[0] and not any("follow you" in x for x in spoken[-1:]) follow.ready = real_ready diff --git a/tests/test_switches.py b/tests/test_switches.py index 7d24b2d..630a219 100644 --- a/tests/test_switches.py +++ b/tests/test_switches.py @@ -27,6 +27,7 @@ arm_state = {"power": 1, "enable": 1} lumi.arm.cmd = lambda name, **a: dict(arm_state) if name == "get_robot_state" else forbid() L = lumi.Lumi.__new__(lumi.Lumi) +L._yaw, L._yaw_time = 0.0, float("inf") # the head at the front (det_yaw reads no body) L.lang, L.markers, L.current, L.patrol, L.vision, L.voice_angle = "en", M, None, None, None, 0.0 L.turn_head = lambda *a, **k: moved.append("head") L.brain = types.SimpleNamespace(history=[]) diff --git a/tests/test_wake.py b/tests/test_wake.py index 284778a..feeb939 100644 --- a/tests/test_wake.py +++ b/tests/test_wake.py @@ -231,6 +231,16 @@ L.mic = Mic(U("루미야, 뭐 보여?")) L.step() assert ("answer", "뭐 보여") in done, done +# the person talked with, still tracked but past STAY_MAX (come here took a far one): gone, never "seen again" as +# itself (that looped ~33000 times a s, the assistant went deaf, 2026-10-28 18:06) +L = fresh(a := Track(10, 186.0, 4.7)) +a.greeted, L.current = True, a +L.vision.present = lambda t: t in L.vision.tracks and t.distance <= lumi.STAY_MAX +L.vision.nearest_greeted = lambda: None +lumi.ears.listen = lambda **k: (None, None) +L.step() +assert L.current is None, L.current + L = fresh() # a talk started by voice ends the same way L.voice_until = time.time() - 1 L.brain.history = [("hi", "hello")]