Follow: Lumi listens only to the followed person (voice direction vs their angle); others get one polite line, the head stays; a stop from anyone stops
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+49
-2
@@ -291,6 +291,9 @@ ANSWER_ECHO_S = 10.0 # s of Lumi's speech a dialog answer is check
|
|||||||
VOICE_SESSION_S = 15.0 # s a conversation started by voice (nobody in view) waits for the next words
|
VOICE_SESSION_S = 15.0 # s a conversation started by voice (nobody in view) waits for the next words
|
||||||
SPEAKER_MATCH_DEG = 25.0 # a voice direction belongs to the visible person within this angle
|
SPEAKER_MATCH_DEG = 25.0 # a voice direction belongs to the visible person within this angle
|
||||||
DOA_MIN_CONF = 0.12 # below this the sound direction is not trusted
|
DOA_MIN_CONF = 0.12 # below this the sound direction is not trusted
|
||||||
|
FOLLOW_VOICE_DEG = 35.0 # while following, a voice this near the followed person's angle is theirs (estimate:
|
||||||
|
# the sound direction's median error was 22-31 deg on 2026-10-22)
|
||||||
|
FOLLOW_SORRY_S = 20.0 # s; "Sorry, I'm following someone" at most this often
|
||||||
COME_STOP = 1.1 # m; driving to a person stops when the camera sees them this close
|
COME_STOP = 1.1 # m; driving to a person stops when the camera sees them this close
|
||||||
COME_TIMEOUT = 60.0 # s
|
COME_TIMEOUT = 60.0 # s
|
||||||
MAX_MOVE_M = 3.0 # m; "move forward N metres" is limited to this
|
MAX_MOVE_M = 3.0 # m; "move forward N metres" is limited to this
|
||||||
@@ -1888,9 +1891,12 @@ class Lumi:
|
|||||||
return False
|
return False
|
||||||
from tasks import follow
|
from tasks import follow
|
||||||
if follow.running() and follow.stop_word(text): # following: the base stops now, "stop" is answered next
|
if follow.running() and follow.stop_word(text): # following: the base stops now, "stop" is answered next
|
||||||
follow.stop()
|
follow.stop() # (anyone's: safety)
|
||||||
self.pending_text = "stop"
|
self.pending_text = "stop"
|
||||||
return True
|
return True
|
||||||
|
if follow.running() and not self.followed_speaks(u):
|
||||||
|
log(f" following: not the person I follow, ignored: {text!r}")
|
||||||
|
return False
|
||||||
if not ears.understood(BARGE_IN_LOGPROB): # unclear while Lumi talks = mostly Lumi's own voice
|
if not ears.understood(BARGE_IN_LOGPROB): # unclear while Lumi talks = mostly Lumi's own voice
|
||||||
log(f" ignored while talking (unclear): {text!r}")
|
log(f" ignored while talking (unclear): {text!r}")
|
||||||
return False
|
return False
|
||||||
@@ -1978,7 +1984,11 @@ class Lumi:
|
|||||||
log(f" heard nothing (mic noise {ears.last.get('noise')}, threshold {ears.last.get('threshold')}, "
|
log(f" heard nothing (mic noise {ears.last.get('noise')}, threshold {ears.last.get('threshold')}, "
|
||||||
f"loudest {ears.last.get('peak')}{', ' + ears.last_stt['dropped'] if ears.last_stt.get('dropped') else ''})")
|
f"loudest {ears.last.get('peak')}{', ' + ears.last_stt['dropped'] if ears.last_stt.get('dropped') else ''})")
|
||||||
return False
|
return False
|
||||||
self.who_spoke(u)
|
from tasks import follow
|
||||||
|
if self.follow_filter(text, u): # following: only the followed person is listened to
|
||||||
|
return True
|
||||||
|
if not follow.running(): # following: the head stays on the followed person
|
||||||
|
self.who_spoke(u)
|
||||||
self.answer(text)
|
self.answer(text)
|
||||||
if self.mission_hold == "talk" and not self.asked_go_on and self.mission_running():
|
if self.mission_hold == "talk" and not self.asked_go_on and self.mission_running():
|
||||||
self.asked_go_on = True # answered while halted for them: may I go on?
|
self.asked_go_on = True # answered while halted for them: may I go on?
|
||||||
@@ -2003,6 +2013,40 @@ class Lumi:
|
|||||||
name = "my charging dock" if target == "home" else target
|
name = "my charging dock" if target == "home" else target
|
||||||
mouth.say(f"Sorry, I can't find a way to {name}. Something may be blocking the path.")
|
mouth.say(f"Sorry, I can't find a way to {name}. Something may be blocking the path.")
|
||||||
|
|
||||||
|
def followed_speaks(self, u):
|
||||||
|
"""While following: does the voice come from the person followed (the sound direction against their angle
|
||||||
|
now, within FOLLOW_VOICE_DEG)? False when it can't tell (not calibrated, unsure, not seen)."""
|
||||||
|
from tasks import follow
|
||||||
|
want = follow.followed_angle()
|
||||||
|
if want is None or u is None or getattr(u, "mics", None) is None:
|
||||||
|
return False
|
||||||
|
cal = doa.load_calib()
|
||||||
|
if not cal["fitted"]:
|
||||||
|
return False
|
||||||
|
ang, conf, _ = doa.estimate(u.mics, cal)
|
||||||
|
if conf < DOA_MIN_CONF:
|
||||||
|
return False
|
||||||
|
heard = HEAD_SIGN * self.det_yaw() + ang
|
||||||
|
return abs((heard - want + 180.0) % 360.0 - 180.0) <= FOLLOW_VOICE_DEG
|
||||||
|
|
||||||
|
def follow_filter(self, text, u):
|
||||||
|
"""While following, words not from the followed person: a stop word still stops the base (safety); anything
|
||||||
|
else is not acted on, at most one short line every FOLLOW_SORRY_S, the head not turned. True if dropped here."""
|
||||||
|
from tasks import follow
|
||||||
|
if not follow.running() or self.followed_speaks(u):
|
||||||
|
return False
|
||||||
|
if follow.stop_word(text) or stop_order(text, self.markers):
|
||||||
|
log(f" follow: stop word from someone else {text!r} - stopped")
|
||||||
|
follow.stop()
|
||||||
|
self.stop_all()
|
||||||
|
return True
|
||||||
|
log(f" follow: not the person I follow, not acted on: {text!r}")
|
||||||
|
if time.time() - getattr(self, "sorry_at", 0.0) > FOLLOW_SORRY_S:
|
||||||
|
self.sorry_at = time.time()
|
||||||
|
mouth.say("Sorry, I'm following someone right now." if mouth.lang_of(text) == "en"
|
||||||
|
else "지금은 다른 분을 따라가는 중이에요.")
|
||||||
|
return True
|
||||||
|
|
||||||
def who_spoke(self, u):
|
def who_spoke(self, u):
|
||||||
"""Use the sound direction: pick the visible person who spoke; meanwhile collect calibration samples."""
|
"""Use the sound direction: pick the visible person who spoke; meanwhile collect calibration samples."""
|
||||||
if not self.vision or u is None:
|
if not self.vision or u is None:
|
||||||
@@ -2440,6 +2484,9 @@ class Lumi:
|
|||||||
# ---------- wake word ----------
|
# ---------- wake word ----------
|
||||||
def check_wake(self):
|
def check_wake(self):
|
||||||
"""Idle or driving: is someone calling "Lumi" / "Hi Lumi" / "Hey Lumi" (or just "Hi" / "Hey")? Handles it."""
|
"""Idle or driving: is someone calling "Lumi" / "Hi Lumi" / "Hey Lumi" (or just "Hi" / "Hey")? Handles it."""
|
||||||
|
from tasks import follow
|
||||||
|
if follow.running(): # following: talk_turn listens to the followed person only
|
||||||
|
return False
|
||||||
u = self.mic.next(0.0)
|
u = self.mic.next(0.0)
|
||||||
if u is None or not (0.3 <= u.seconds <= WAKE_MAX_S) or getattr(u, "during_speech", False):
|
if u is None or not (0.3 <= u.seconds <= WAKE_MAX_S) or getattr(u, "during_speech", False):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ NO_ARM = ("My arm is not answering, so I can't drive safely.", "팔이 응답하
|
|||||||
_stop = threading.Event()
|
_stop = threading.Event()
|
||||||
_send = threading.Lock() # a command and the stop never cross: after stop() no drive command goes out
|
_send = threading.Lock() # a command and the stop never cross: after stop() no drive command goes out
|
||||||
_thread = None
|
_thread = None
|
||||||
|
_followed = [None] # (waist-frame angle deg, time) of the last sighting of the person followed now
|
||||||
|
SEEN_MAX_S = 1.5 # s; an older sighting does not tell where they are (lumi decides who speaks from it)
|
||||||
|
|
||||||
|
|
||||||
STOP_WORDS = re.compile(r"\b(stop|halt|freeze|enough|wait|hold on|stay(?! with)|don'?t (move|follow)|no more|"
|
STOP_WORDS = re.compile(r"\b(stop|halt|freeze|enough|wait|hold on|stay(?! with)|don'?t (move|follow)|no more|"
|
||||||
@@ -86,6 +88,13 @@ def running():
|
|||||||
return _thread is not None and _thread.is_alive()
|
return _thread is not None and _thread.is_alive()
|
||||||
|
|
||||||
|
|
||||||
|
def followed_angle():
|
||||||
|
"""Waist-frame angle (deg, + left) of the person being followed, seen within SEEN_MAX_S; None if not following
|
||||||
|
or not seen."""
|
||||||
|
got = _followed[0]
|
||||||
|
return got[0] if running() and got and time.time() - got[1] <= SEEN_MAX_S else None
|
||||||
|
|
||||||
|
|
||||||
def _joy(v, w):
|
def _joy(v, w):
|
||||||
agv.request(f"/api/joy_control?linear_velocity={v:.3f}&angular_velocity={w:.3f}")
|
agv.request(f"/api/joy_control?linear_velocity={v:.3f}&angular_velocity={w:.3f}")
|
||||||
|
|
||||||
@@ -279,6 +288,7 @@ def _run(see, say, people):
|
|||||||
odd_t = now
|
odd_t = now
|
||||||
fetch.log(f"follow: a sighting at {mine[0]:.2f} m {mine[1]:+.0f} deg is not them (someone else)")
|
fetch.log(f"follow: a sighting at {mine[0]:.2f} m {mine[1]:+.0f} deg is not them (someone else)")
|
||||||
if _fresh(got):
|
if _fresh(got):
|
||||||
|
_followed[0] = (got[1], now - got[2])
|
||||||
p = _to_map(pose, *got[:2])
|
p = _to_map(pose, *got[:2])
|
||||||
person.seen(p, now - got[2])
|
person.seen(p, now - got[2])
|
||||||
near = [float(np.linalg.norm(_to_map(pose, *o[1:3]) - p)) for o in people() if _fresh(o[1:])] \
|
near = [float(np.linalg.norm(_to_map(pose, *o[1:3]) - p)) for o in people() if _fresh(o[1:])] \
|
||||||
@@ -368,6 +378,7 @@ def start(see, say=None, people=None):
|
|||||||
stop()
|
stop()
|
||||||
_thread.join(JOIN_S)
|
_thread.join(JOIN_S)
|
||||||
_stop.clear()
|
_stop.clear()
|
||||||
|
_followed[0] = None
|
||||||
fetch.log("follow: start")
|
fetch.log("follow: start")
|
||||||
_thread = threading.Thread(target=_run, args=(see, say, people), daemon=True, name="follow")
|
_thread = threading.Thread(target=_run, args=(see, say, people), daemon=True, name="follow")
|
||||||
_thread.start()
|
_thread.start()
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
"""Self-check of who Lumi listens to while following (only the followed person; anyone's stop word stops the base),
|
||||||
|
no robot, no audio: python tests/test_follow_listen.py"""
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
from assistant import lumi
|
||||||
|
from tasks import follow
|
||||||
|
|
||||||
|
done, heard = [], []
|
||||||
|
follow.running = lambda: run["on"]
|
||||||
|
follow.followed_angle = lambda: run["angle"]
|
||||||
|
follow.stop = lambda: done.append("follow stop")
|
||||||
|
lumi.doa.load_calib = lambda: {"fitted": True}
|
||||||
|
lumi.doa.estimate = lambda mics, cal: (mics, 0.5, None) # the fake mics carry the voice angle (head frame)
|
||||||
|
lumi.mouth.say = lambda text, **k: done.append(("say", text))
|
||||||
|
lumi.mouth.recent_speech = lambda s=30.0: ""
|
||||||
|
lumi.ears.understood = lambda *a: True
|
||||||
|
run = {"on": True, "angle": 20.0}
|
||||||
|
|
||||||
|
|
||||||
|
class U: # one utterance from the head array
|
||||||
|
def __init__(self, deg):
|
||||||
|
self.mics, self.seconds, self.source, self.during_speech = deg, 1.2, "array", False
|
||||||
|
|
||||||
|
|
||||||
|
class Track:
|
||||||
|
def __init__(self, tid, angle):
|
||||||
|
self.id, self.angle, self.person, self.greeted = tid, angle, None, False
|
||||||
|
|
||||||
|
|
||||||
|
class Vision: # someone at -60 deg besides the followed person
|
||||||
|
def __init__(self):
|
||||||
|
self.stranger = Track(31, -60.0)
|
||||||
|
|
||||||
|
def only_person(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def near_angle(self, a, max_diff=25.0):
|
||||||
|
return self.stranger if abs(a + 60.0) <= max_diff else None
|
||||||
|
|
||||||
|
def present(self, t):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def to_greet(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def fresh(said, deg, yaw=10.0):
|
||||||
|
L = lumi.Lumi.__new__(lumi.Lumi)
|
||||||
|
L.markers, L.lang, L.current, L.mission_hold, L.asked_go_on = ["home"], "en", None, None, False
|
||||||
|
L.pending_text, L.closing_pending, L.voice_until, L.vision = None, None, time.time() + 15, Vision()
|
||||||
|
L.patrol, L.chain_stop, L.sorry_at = None, threading.Event(), 0.0
|
||||||
|
L.warm_llm = lambda: None
|
||||||
|
L.det_yaw = lambda: yaw
|
||||||
|
L.turn_head = lambda *a: done.append(("head", a))
|
||||||
|
L.answer = lambda text: heard.append(text)
|
||||||
|
L.fetch_say = lambda en, ko: done.append(("say", en))
|
||||||
|
L.keep_listening = lambda: None
|
||||||
|
L.act = lambda action, target: done.append(("act", action))
|
||||||
|
lumi.ears.listen = lambda **k: (said, U(deg))
|
||||||
|
done.clear()
|
||||||
|
heard.clear()
|
||||||
|
return L
|
||||||
|
|
||||||
|
|
||||||
|
# the followed person (at +20 deg, head yaw +10, voice +10 in the head frame) asks while walking: answered, following on
|
||||||
|
for q in ("What's the weather like today?", "How far am I from you?", "Can you see me?", "오늘 날씨 어때?"):
|
||||||
|
L = fresh(q, 10.0)
|
||||||
|
assert L.talk_turn() and heard == [q] and "follow stop" not in done, (q, heard, done)
|
||||||
|
assert not any(d[0] == "head" for d in done if isinstance(d, tuple)), done
|
||||||
|
# a little off (the sound direction is not exact) is still them; far off is not
|
||||||
|
L = fresh("How far am I from you?", 35.0) # 25 deg off
|
||||||
|
assert L.talk_turn() and heard, heard
|
||||||
|
# a stranger at -60 deg asks / commands: not acted on, one short line, the head not turned, no new current
|
||||||
|
for i, q in enumerate(("What time is it?", "Lumi, come to me", "Follow me", "Hi Lumi")):
|
||||||
|
L = fresh(q, -70.0)
|
||||||
|
L.sorry_at = 0.0 if i == 0 else time.time()
|
||||||
|
assert L.talk_turn() and heard == [] and "follow stop" not in done, (q, heard, done)
|
||||||
|
assert L.current is None and not any(d[0] == "head" for d in done if isinstance(d, tuple)), done
|
||||||
|
says = [d for d in done if isinstance(d, tuple) and d[0] == "say"]
|
||||||
|
assert says == ([("say", "Sorry, I'm following someone right now.")] if i == 0 else []), (q, says)
|
||||||
|
L = fresh("지금 몇 시야?", -70.0)
|
||||||
|
assert L.talk_turn() and done == [("say", "지금은 다른 분을 따라가는 중이에요.")], done
|
||||||
|
# unsure (not calibrated, or the followed person not seen): only the followed person's words count, so dropped
|
||||||
|
lumi.doa.load_calib = lambda: {"fitted": False}
|
||||||
|
L = fresh("How far am I from you?", 10.0)
|
||||||
|
assert L.talk_turn() and heard == [], heard
|
||||||
|
lumi.doa.load_calib = lambda: {"fitted": True}
|
||||||
|
run["angle"] = None
|
||||||
|
L = fresh("How far am I from you?", 10.0)
|
||||||
|
assert L.talk_turn() and heard == [], heard
|
||||||
|
run["angle"] = 20.0
|
||||||
|
# the followed person says stop: it goes to answer(), whose follow_stop ends following
|
||||||
|
L = fresh("stop", 10.0)
|
||||||
|
assert L.talk_turn() and heard == ["stop"], heard
|
||||||
|
assert L.follow_stop("stop") and "follow stop" in done, done
|
||||||
|
# a stranger says stop: the base stops (safety), following ends
|
||||||
|
for word in ("stop", "Stop it!", "멈춰", "wait"):
|
||||||
|
L = fresh(word, -70.0)
|
||||||
|
assert L.talk_turn() and "follow stop" in done and ("act", "stop") in done and heard == [], (word, done)
|
||||||
|
# not following: today's rule, anyone is heard and looked at
|
||||||
|
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)
|
||||||
|
print("follow listen ok")
|
||||||
Reference in New Issue
Block a user