Carry held things in look and come to the speaker before handing over

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 20:18:32 +09:00
co-authored by Claude Opus 5.5
parent f66e954d60
commit 7a668153ee
7 changed files with 305 additions and 33 deletions
+13 -1
View File
@@ -248,6 +248,15 @@ def fetch_head_ahead():
fetch.head_ahead() # drives look ahead, wherever the head was turned fetch.head_ahead() # drives look ahead, wherever the head was turned
def held_to_look():
"""Something held goes to look before the base drives (fetch.drive_ready); 409 when it can't (no drive)."""
from tasks import fetch
try:
fetch.drive_ready()
except Exception as e:
raise HTTPException(409, f"the arm is not ready to drive: {e}")
@app.post("/agv/go", tags=["base"], summary="Drive to a marker (returns at once; watch /status move_status)") @app.post("/agv/go", tags=["base"], summary="Drive to a marker (returns at once; watch /status move_status)")
def go(body: GoBody): def go(body: GoBody):
_route.stop() _route.stop()
@@ -257,6 +266,7 @@ def go(body: GoBody):
if assistant_pids(): if assistant_pids():
send_to_assistant("go", marker=body.marker) send_to_assistant("go", marker=body.marker)
return {"ok": True, "marker": body.marker, "by": "assistant"} return {"ok": True, "marker": body.marker, "by": "assistant"}
held_to_look()
part(fetch_head_ahead) part(fetch_head_ahead)
ok, msg = agv.go(body.marker) ok, msg = agv.go(body.marker)
if not ok: if not ok:
@@ -322,6 +332,7 @@ def go_route(body: RouteBody):
if assistant_pids(): if assistant_pids():
send_to_assistant("route", markers=body.markers, pause=body.pause) send_to_assistant("route", markers=body.markers, pause=body.pause)
return {"ok": True, "route": body.markers, "by": "assistant"} return {"ok": True, "route": body.markers, "by": "assistant"}
held_to_look()
_route.start(body.markers, body.pause) _route.start(body.markers, body.pause)
return {"ok": True, "route": body.markers, "by": "api"} return {"ok": True, "route": body.markers, "by": "api"}
@@ -714,6 +725,7 @@ def go_point(body: PointBody):
if assistant_pids(): if assistant_pids():
send_to_assistant("go_point", point=[body.x, body.y, body.theta]) send_to_assistant("go_point", point=[body.x, body.y, body.theta])
return {"ok": True, "by": "assistant"} return {"ok": True, "by": "assistant"}
held_to_look()
part(fetch_head_ahead) part(fetch_head_ahead)
ok, msg = agv.go_point(body.x, body.y, body.theta) ok, msg = agv.go_point(body.x, body.y, body.theta)
if not ok: if not ok:
@@ -1039,7 +1051,7 @@ def _said(kind, words, what):
if kind == "talk": if kind == "talk":
return f"answer \u201c{words}\u201d" return f"answer \u201c{words}\u201d"
a, t = what a, t = what
return {"look": f"look {t}", "lift": f"lift {t}", "wave": "wave", "come": "come to me", "come_back": "go back", return {"look": f"look {t}", "lift": f"lift {t}", "wave": "wave", "come": "come to me and give it to you" if t == "give" else "come to me", "come_back": "go back",
"follow": "follow me", "go_to": f"go to {brain.place_said(t)}", "arm": f"arm {t}", "follow": "follow me", "go_to": f"go to {brain.place_said(t)}", "arm": f"arm {t}",
"quiet": "be quiet", "waist": f"turn my waist {t}"}.get(a, f"{a} {t}".strip()) "quiet": "be quiet", "waist": f"turn my waist {t}"}.get(a, f"{a} {t}".strip())
+76 -23
View File
@@ -173,8 +173,8 @@ FIX_SAY = (("Okay.", "네."), # a command
("Sorry, which one did you mean? Please say it again.", "죄송해요, 어느 쪽 말씀이세요? 다시 한 번 말씀해 주세요.")) ("Sorry, which one did you mean? Please say it again.", "죄송해요, 어느 쪽 말씀이세요? 다시 한 번 말씀해 주세요."))
BASE_OFF_SAY = ("I can't drive or turn my waist right now. Switch on Patrol for that.", # Greeter only: a base / BASE_OFF_SAY = ("I can't drive or turn my waist right now. Switch on Patrol for that.", # Greeter only: a base /
"지금은 이동하거나 허리를 돌릴 수 없어요. 패트롤을 켜 주세요.") # waist motion asked for "지금은 이동하거나 허리를 돌릴 수 없어요. 패트롤을 켜 주세요.") # waist motion asked for
WAIST_BACK_SAY = ("I can't turn back to the front right now, so I won't drive.", # a drive with the waist turned WAIST_BACK_SAY = ("I can't get my arm and waist ready to drive right now, so I won't drive.", # waist_home: the waist
"지금은 앞으로 돌아설 수 없어서 이동하지 않을게요.") # and it can't come back (waist_home) "지금은 팔과 허리를 이동 자세로 할 수 없어서 이동하지 않을게요.") # can't come back or a held cup to look
ARM_OFF_SAY = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.") # an arm action with the arm switched off ARM_OFF_SAY = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.") # an arm action with the arm switched off
ARM_TASKS = {"pick", "put", "move_object", "fetch", "give", "place", "receive", "wave"} # + arm reach / fold ARM_TASKS = {"pick", "put", "move_object", "fetch", "give", "place", "receive", "wave"} # + arm reach / fold
@@ -207,12 +207,15 @@ def waist_home(why, fold=False):
"""The waist back to the front: at a conversation's end, before every drive or base turn, when someone else takes """The waist back to the front: at a conversation's end, before every drive or base turn, when someone else takes
over the talk. In place (the base stays), so with Greeter only too; fetch._waist_to checks the arm's sweep and the over the talk. In place (the base stays), so with Greeter only too; fetch._waist_to checks the arm's sweep and the
limits. Not while a task runs (it turns the waist itself) or the arm is out of look (a hand held out): logged, the limits. Not while a task runs (it turns the waist itself) or the arm is out of look (a hand held out): logged, the
waist stays, unless `fold` (an order to drive or turn): an empty arm goes back to look along the checked pose waist stays, unless `fold` (an order to drive or turn): something held goes to look first wherever the waist is
graph first (an arm left half way by a failed reach refused every drive after it, 2026-10-28). True when the (fetch.drive_ready: straight checked lines, holding speed); an empty arm goes back to look along the checked pose
waist is at the front.""" graph when the waist must turn (an arm left half way by a failed reach refused every drive after it). True when
the waist is at the front (and a held thing in look)."""
from tasks import fetch from tasks import fetch
with _waist_lock: with _waist_lock:
try: try:
if fold and fetch.state().get("holding"):
fetch.drive_ready() # a drive with the cup held out in carry / give: never
if abs(fetch._waist_turn()) < 1.0: if abs(fetch._waist_turn()) < 1.0:
return True return True
if fetch.state().get("status") == "running": if fetch.state().get("status") == "running":
@@ -1395,10 +1398,13 @@ class Lumi:
def fetch_finish(self, how, on=None, voice=True): def fetch_finish(self, how, on=None, voice=True):
"""Give / place what the hand holds; a refusal ("I haven't learned how to hand things over yet") is spoken. """Give / place what the hand holds; a refusal ("I haven't learned how to hand things over yet") is spoken.
`voice`: asked by voice (else from the dashboard).""" `voice`: asked by voice (else from the dashboard): a hand-over goes to the person who asked, driven to first when
far (near_speaker)."""
from tasks import fetch from tasks import fetch
if voice and self.arm_off(): if voice and self.arm_off():
return return
if voice and how == "give" and not self.near_speaker("give")[0]: # to whoever asked, come to them first
return
self.stay() self.stay()
try: try:
if how == "give": if how == "give":
@@ -2208,20 +2214,9 @@ class Lumi:
return None return None
with _waist_lock: # a waist coming back to the front (face) ends first with _waist_lock: # a waist coming back to the front (face) ends first
pass pass
track = None ok, track = self.near_speaker("reach")
if self.vision: if not ok:
track = self.speaker_track() # who asked: the voice, the talk, the look, a raised hand return None
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.patrol: # Greeter only: the base stays
self.fetch_say(*COME_CLOSER_SAY)
return None
log(f" reach: person #{track.id} {track.distance:.2f} m away: coming closer first")
self.come_to(track)
if not self.vision.present(track) or track.distance > REACH_COME_M:
self.fetch_say(*COME_CLOSER_SAY)
return None
angle = track.angle if track else None # only to someone seen: a "sure" voice was 166 deg angle = track.angle if track else None # only to someone seen: a "sure" voice was 166 deg
# off with the person in front (2026-10-28 19:13) # off with the person in front (2026-10-28 19:13)
hand = safe(fetch.give_bearing, default=0.0) or 0.0 hand = safe(fetch.give_bearing, default=0.0) or 0.0
@@ -2243,6 +2238,28 @@ class Lumi:
self.reached_at = time.time() self.reached_at = time.time()
return True return True
def near_speaker(self, why):
"""Before the hand goes out to the person who asked (a reach, a hand-over): who it is (speaker_track) and, further
than REACH_COME_M, the base comes to them first (come_to, as "come here"): never held out from afar. (True,
track) to go on (track None: nobody seen, the hand goes out in front); (False, None) when not (said)."""
if not self.vision:
return True, None
track = self.speaker_track() # who asked: the voice, the talk, the look, a raised hand
if track is None: # several seen, nobody raised a hand: raised_hand said so
return not self.vision.anyone(), None
if track.distance <= REACH_COME_M:
return True, track
if not self.modes.patrol: # Greeter only: the base stays
self.fetch_say(*COME_CLOSER_SAY)
return False, None
log(f" {why}: person #{track.id} {track.distance:.2f} m away: coming closer first")
if self.come_to(track) is False: # stopped on the way
return False, None
if not self.vision.present(track) or track.distance > REACH_COME_M:
self.fetch_say(*COME_CLOSER_SAY)
return False, None
return True, track
def reach_done(self, text=None): def reach_done(self, text=None):
"""The hand is held out (reach_out) and the reach has ended: "thanks" / "okay" / "고마워" / "됐어" (`text`) or """The hand is held out (reach_out) and the reach has ended: "thanks" / "okay" / "고마워" / "됐어" (`text`) or
REACH_HOLD_S without one folds the arm back to look. True when it folded.""" REACH_HOLD_S without one folds the arm back to look. True when it folded."""
@@ -2951,6 +2968,9 @@ class Lumi:
if action == "come_back": if action == "come_back":
self.come_back(speak=True) self.come_back(speak=True)
return True return True
if action == "come" and target == "give":
self.come_and_give(text)
return True
if action == "come": if action == "come":
self.come_to(self.current, say=True) # drives first, says "I'm coming" as it starts self.come_to(self.current, say=True) # drives first, says "I'm coming" as it starts
return True return True
@@ -3420,7 +3440,8 @@ class Lumi:
# ---------- come here ---------- # ---------- come here ----------
def come_to(self, track, say=False): def come_to(self, track, say=False):
"""Drive to the person (a visible track) and stop about COME_STOP in front of them. `say`: "I'm coming" """Drive to the person (a visible track) and stop about COME_STOP in front of them. `say`: "I'm coming"
once the base has the goal, spoken while it drives (the motion never waits for the words).""" once the base has the goal, spoken while it drives (the motion never waits for the words). False when a stop
word ended it on the way."""
if track is None or not self.vision or not self.vision.visible(track): if track is None or not self.vision or not self.vision.visible(track):
track = self.speaker_track() # who said it: the voice, the talk, the look, a raised hand track = self.speaker_track() # who said it: the voice, the talk, the look, a raised hand
if track is None: if track is None:
@@ -3467,7 +3488,7 @@ class Lumi:
break break
if self.stop_heard(): # the main loop waits here: listen for "stop" too if self.stop_heard(): # the main loop waits here: listen for "stop" too
self.stop_all() self.stop_all()
return return False
if self.vision.present(track): if self.vision.present(track):
if track.distance <= COME_STOP: if track.distance <= COME_STOP:
log(f" person #{track.id} is {track.distance:.2f} m away - stop") log(f" person #{track.id} is {track.distance:.2f} m away - stop")
@@ -3483,6 +3504,19 @@ class Lumi:
self.turn_head(HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, track.angle)), force=True) self.turn_head(HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, track.angle)), force=True)
self.last_activity = time.time() self.last_activity = time.time()
def come_and_give(self, text):
""""Come here and give me (it / the cup)", "이리 와서 줘" (route: come_give): a hand-over held out from afar is
taken back (end_run), Lumi comes to the speaker (come_to; the held thing goes to look first, waist_home), then
hands it over (fetch_finish). Nothing held: it comes and says the hand is empty."""
self.end_run(text)
if self.come_to(self.current, say=True) is False: # stopped on the way
return
if self.held_now():
self.fetch_finish("give")
else:
mouth.say(EMPTY_HAND_SAY[self.lang])
self.keep_listening()
def pointed_drive(self, text): def pointed_drive(self, text):
""""Go there" / "저기로 가" / "come to where I'm pointing" with a pointing arm: drive to the floor spot pointed """"Go there" / "저기로 가" / "come to where I'm pointing" with a pointing arm: drive to the floor spot pointed
at (vision/pointing.py). True when handled. "here" / "여기" without a pointing arm is left to come-here (False); at (vision/pointing.py). True when handled. "here" / "여기" without a pointing arm is left to come-here (False);
@@ -3909,7 +3943,7 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
by)); "end" (a goodbye); "sing"; "quick" (brain.intent's rule, one of QUICK_RULES, or the example bank's by)); "end" (a goodbye); "sing"; "quick" (brain.intent's rule, one of QUICK_RULES, or the example bank's
reading: assistant/intent_bank.py); (None, None): the LLM reads reading: assistant/intent_bank.py); (None, None): the LLM reads
it. seen: seeing.answer or a stand-in; chain_ok: False on a mission or while a chain runs.""" it. seen: seeing.answer or a stand-in; chain_ok: False on a mission or while a chain runs."""
from assistant import chain, intent_bank from assistant import chain, intent_bank, steps
text = MYEOT_SLIP.sub("몇", text or "") # whisper's 멸 for 몇: "멸 센티까지 잡아?" asks, orders nothing text = MYEOT_SLIP.sub("몇", text or "") # whisper's 멸 for 몇: "멸 센티까지 잡아?" asks, orders nothing
text = re.sub(r"(?<=[가-힣])(?=[a-zA-Z]{2})", " ", text) # "원래 자리에put back": the English word apart text = re.sub(r"(?<=[가-힣])(?=[a-zA-Z]{2})", " ", text) # "원래 자리에put back": the English word apart
text = re.sub(r"\bcome on back\b", "come back", text, flags=re.I) # not 1 m back text = re.sub(r"\bcome on back\b", "come back", text, flags=re.I) # not 1 m back
@@ -3933,6 +3967,12 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
how = stuck and detour.read(text, markers, stuck["goal"]) # only a direct order (detour.read), else the LLM how = stuck and detour.read(text, markers, stuck["goal"]) # only a direct order (detour.read), else the LLM
if how: if how:
return "detour", how return "detour", how
give = not hold and come_give(text, markers) # "come here and give me", "이리 와서 줘": come, then hand it over
if give:
named = chain_ok and not (holding() if callable(holding) else holding) and steps.read(give, markers, llm=False)
if named and named[0] and not named[1] and named[0][0]["do"] == "pick": # empty, "와서 컵 줘": pick, give
return "chain", [("quick", "come here", ("come", "")), ("steps", give, named[0])]
return "quick", ("come", "give")
plan = chain_ok and not brain_mod.not_an_order(text, asked=False) and brain_mod.direct_order(text) and \ plan = chain_ok and not brain_mod.not_an_order(text, asked=False) and brain_mod.direct_order(text) and \
chain.plan(text, markers, NOT_A_STEP) # not "when the show starts, go to the stage", "Jake, wave" chain.plan(text, markers, NOT_A_STEP) # not "when the show starts, go to the stage", "Jake, wave"
picks = [i for i, (k, _, w) in enumerate(plan or []) if k == "steps" and any(st.get("do") == "pick" for st in w) or picks = [i for i, (k, _, w) in enumerate(plan or []) if k == "steps" and any(st.get("do") == "pick" for st in w) or
@@ -4001,6 +4041,19 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
return None, None return None, None
COME_GIVE = re.compile(r"^(?:(?:let'?s|please|can you|could you|would you|will you|now|okay|ok)[\s,]+)*(?:come|get)"
r"(?:\s+(?:over\s+)?(?:here|to me|closer|this way|over))?(?:\s+please)?\s*(?:,|\.|and then|and|then)\s*"
r"(?P<rest>.+)$|^(?:(?:이리|여기|이쪽|이쪽으로|여기로|나한테|저한테|내 ?앞으로|제 ?앞으로)\s*)?와서\s*(?P<ko>.+)$", re.I)
def come_give(text, markers):
""""Come here and give me (it / the cup)", "이리 와서 (컵) 줘": the give part when the rest is a hand-over to the
speaker (brain.hand_request), else None (route: come to them, then hand it over)."""
m = COME_GIVE.match(WAKE.sub(" ", text or "").strip(" ,.!?"))
rest = m and (m.group("rest") or m.group("ko")).strip(" ,.!?")
return rest if rest and brain_mod.hand_request(rest, True, None, markers) == ("give", None) else None
def arm_quick(rule, holding): def arm_quick(rule, holding):
"""A rule's reading as route's ("quick", rule); an open hand while holding is refused (the thing would fall).""" """A rule's reading as route's ("quick", rule); an open hand while holding is refused (the thing would fall)."""
if tuple(rule[:2]) == ("arm", "open") and (holding() if callable(holding) else holding): if tuple(rule[:2]) == ("arm", "open") and (holding() if callable(holding) else holding):
+1 -1
View File
@@ -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.093, -0.113], "arm_xy_measured": "2026-10-27 13:07", "arm_xy_samples": [[0.111, -0.086], [0.093, -0.095], [0.187, -0.113], [0.117, -0.129], [0.066, -0.109], [0.041, -0.114], [0.051, -0.127]]} {"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.09, -0.111], "arm_xy_measured": "2026-10-29 19:38", "arm_xy_samples": [[0.111, -0.086], [0.093, -0.095], [0.187, -0.113], [0.117, -0.129], [0.066, -0.109], [0.041, -0.114], [0.051, -0.127], [0.087, -0.078]]}
+17 -5
View File
@@ -403,6 +403,19 @@ def _drive_pose(holding=False):
log("the arm is switched off: it stays where it is for the drive") log("the arm is switched off: it stays where it is for the drive")
def drive_ready():
"""Before a drive or base turn started outside the task runner (a trip, come here, a base turn to a voice, the
dashboard's go): something held goes to look first, the straight checked lines at holding speed (_drive_pose); a
drive with the hand out in carry or give stalls and swings the cup past people. An empty arm is the caller's
(lumi.waist_home). Not while a task runs (it moves the arm itself): FetchError then, and when the arm can't go."""
if not state().get("holding"):
return
if _busy():
raise FetchError("I'm busy with another task.", "지금 다른 일을 하고 있어요.")
_stop.clear() # an old stop must not end this one; a new one does
_drive_pose(True)
def _pose(name, holding=False, leaf=False): def _pose(name, holding=False, leaf=False):
"""Joint moves to pose `name` along the pose graph (manipulation/arm_route.py), all checked before the first """Joint moves to pose `name` along the pose graph (manipulation/arm_route.py), all checked before the first
one starts. `leaf`: the arm is on this task's own way out from look (arm_route.hops). Nothing when it is there.""" one starts. `leaf`: the arm is on this task's own way out from look (arm_route.hops). Nothing when it is there."""
@@ -756,16 +769,15 @@ def _waist_front():
def _turn(deg, holding=False, why="to look further"): def _turn(deg, holding=False, why="to look further"):
"""Turn the base on the spot by `deg` (+ = left), arm in look (holding: it is there already), the lift where it """Turn the base on the spot by `deg` (+ = left), arm in look (holding: the straight lines, _drive_pose), the lift
is. False when it must not: Patrol off (stay_put), charging, or the arm would hit something on the way (turn_hits).""" where it is. False when it must not: Patrol off (stay_put), charging, or the arm would hit something on the way (turn_hits)."""
if stay_put: if stay_put:
log("not turning: Patrol is off") log("not turning: Patrol is off")
return False return False
if _charging(): if _charging():
log("on the charger: I don't turn") log("on the charger: I don't turn")
return False return False
if not holding: _drive_pose(holding) # holding: in look already after a pick, not after a give / carry
_drive_pose()
_waist_front() _waist_front()
if _sweep_blocked(deg, "turning"): if _sweep_blocked(deg, "turning"):
return False return False
@@ -2541,7 +2553,7 @@ def _finish(fn, say, end=None):
if not _state["holding"]: if not _state["holding"]:
_hold_again() # the state was lost; give still works, place needs skills._held _hold_again() # the state was lost; give still works, place needs skills._held
_new_run() _new_run()
_set(status="running") _set(status="running", task=None) # no mission's steps left over: a hand-over is no mission (mission_talk)
def run(): def run():
try: try:
+1 -1
View File
@@ -208,7 +208,7 @@ def prepare():
if why: if why:
raise fetch.FetchError(*why) raise fetch.FetchError(*why)
fetch._stop.clear() # a stop said earlier must not end this one fetch._stop.clear() # a stop said earlier must not end this one
fetch._drive_pose() fetch._drive_pose(bool(fetch.state().get("holding"))) # a held cup: straight lines at holding speed
if fetch.arm_yaw() is None: if fetch.arm_yaw() is None:
fetch.log("follow: the arm's place on the base is not measured: only the base is checked") fetch.log("follow: the arm's place on the base is not measured: only the base is checked")
return [] return []
+163
View File
@@ -0,0 +1,163 @@
"""Come here and hand it over, the live test of 2026-10-29 19:41 replayed with fakes. "Give me a cup" with the cup in the
hand went out to a person 2 m away; "Give me here. Let's come here" was then ignored as "not to me" (the hand-over
still carried the steps of the mission before it, "move back 1 m"), and "come here" drove with the cup held out in
give. Now: the hand-over goes to the person who asked and comes to them first when they are further than
REACH_COME_M; "come here and give me" / "이리 와서 줘" comes, then hands over (empty: comes, says the hand is empty);
every drive and base turn with something held brings it to look first (fetch.drive_ready, _turn, follow). No robot.
.venv/bin/python tests/test_come_give.py
"""
import tempfile
import types
from pathlib import Path
import no_robot # noqa: F401 any connection to the robot fails the test
from assistant import brain, lumi
from tasks import fetch, follow
M = ["home", "p1", "p3", "p9"]
events, said = [], []
lumi.log = fetch.log = lambda *a: None
lumi.mouth = types.SimpleNamespace(say=lambda text, **k: said.append(text))
# ---------- the words: come, then the hand-over (EN + KO), with and without something in the hand ----------
COME_GIVE = ["come here and give me", "Come here and give it to me.", "Lumi, come here and give me", "come and give it to me",
"Let's come here and give me.", "come over here and hand it to me", "come closer, give it to me",
"come here and give me that", "이리 와서 줘", "루미야 이리 와서 줘", "여기 와서 주세요", "나한테 와서 그거 줘",
"와서 줘", "이리 와서 건네 줘"]
NAMED = ["come here and give me the cup", "Come here and give me the cup.", "와서 컵 줘", "이리 와서 컵 줘",
"come to me and give me a red cup"]
NOT = {"come here": ("quick", ("come", "")), "이리 와": ("quick", ("come", "")),
"come here and wave": "chain", "이리 와서 손 흔들어": "chain", "come here and give me your hand": "chain",
"don't come here and give it to me": (None, None)}
bad = []
for held in (True, False):
for t in COME_GIVE + NAMED:
got = lumi.route(t, M, brain.Brain(), holding=held)
if held or t in COME_GIVE:
ok = got == ("quick", ("come", "give"))
else: # nothing held, a thing named: come, then the pick-and-give
ok = got[0] == "chain" and got[1][0][2] == ("come", "") and got[1][1][0] == "steps" and \
[s["do"] for s in got[1][1][2]] == ["pick", "give"]
if not ok:
bad.append((held, t, got))
for t, want in NOT.items():
got = lumi.route(t, M, brain.Brain(), holding=held)
if (got[0] if isinstance(want, str) else got) != want:
bad.append((held, t, got))
assert not bad, bad
# ---------- Lumi with fakes: the person, the base, the hand ----------
lumi.arm.cmd = lambda name, **a: {"power": 1, "enable": 1} # the arm is on (arm_off)
real_give = fetch.give
fetch.give = lambda say=None: events.append("give")
L = lumi.Lumi.__new__(lumi.Lumi)
L.lang, L.markers, L.current, L.patrol, L.voice_trusted = "en", M, None, None, False
L.brain = brain.Brain()
L.modes = types.SimpleNamespace(greeter=True, patrol=True)
L.keep_listening = lambda: None
L.mission_running = lambda: False
L.skill_busy = lambda: False
L.fetch_status = lambda: "holding"
person = types.SimpleNamespace(id=5, angle=7.0, distance=1.97) # where the live give went out from
L.vision = types.SimpleNamespace(present=lambda t: True, anyone=lambda: True)
L.speaker_track = lambda: person
come = {"to": 1.1, "result": None}
def come_to(track, say=False):
events.append("come")
(track or person).distance = come["to"] # None: come_to finds the speaker itself
return come["result"]
L.come_to = come_to
L.end_run = lambda text: events.append("end run")
hand = {"held": True}
L.held_now = lambda: hand["held"]
# the hand-over by voice goes to the person who asked: far -> comes to them first, near -> at once
for text in ["Give me a cup.", "give it to me", "hand it over", "컵 줘", "이리 줘", "나한테 주세요"]:
for dist, patrol, want, words in ((1.97, True, ["come", "give"], []), (1.2, True, ["give"], []),
(3.0, False, [], [lumi.COME_CLOSER_SAY[0]])):
person.distance, L.modes.patrol = dist, patrol
events.clear(), said.clear()
assert L.hand_command(text) and events == want and said == words, (text, dist, patrol, events, said)
L.modes.patrol = True
person.distance, come["to"] = 2.5, 2.4 # it came, but they are still too far (stepped back)
events.clear(), said.clear()
L.fetch_finish("give")
assert events == ["come"] and said == [lumi.COME_CLOSER_SAY[0]], (events, said)
person.distance, come["to"], come["result"] = 2.5, 1.1, False # "stop" on the way: no hand-over after it
events.clear(), said.clear()
L.fetch_finish("give")
assert events == ["come"] and not said, (events, said)
come["result"] = None
person.distance = 3.0 # the dashboard's give: in front, as it was
events.clear()
L.fetch_finish("give", voice=False)
assert events == ["give"]
L.speaker_track = lambda: None # several seen, nobody raised a hand (raised_hand said so)
events.clear()
L.fetch_finish("give")
assert events == []
L.speaker_track = lambda: person
# "give me your hand" with the cup in the hand: the same hand-over, so the same come first
person.distance = 2.2
events.clear()
real_check, fetch.check_hand = fetch.check_hand, lambda: True
assert lumi.Lumi.arm_pose(L, "reach") is None and events == ["come", "give"], events
fetch.check_hand = real_check
# "come here and give me": the hand held out ends, comes, hands over; nothing held: comes, says the hand is empty
for text in COME_GIVE:
for held, want, words in ((True, ["end run", "come", "give"], []),
(False, ["end run", "come"], [lumi.EMPTY_HAND_SAY["en"]])):
hand["held"], person.distance, come["result"] = held, 2.0, None
events.clear(), said.clear()
assert L.quick_command(text, ("come", "give")), text
assert events == want and said == words, (text, held, events, said)
hand["held"], come["result"] = True, False # stopped on the way: nothing after it
events.clear(), said.clear()
L.quick_command("come here and give me", ("come", "give"))
assert events == ["end run", "come"] and not said, events
L.modes.patrol = False # Greeter only: no come, said why
said.clear(), events.clear()
assert L.quick_command("이리 와서 줘", ("come", "give")) and not events and said == [lumi.BASE_OFF_SAY[0]], said
L.modes.patrol = True
fetch.give = real_give
# ---------- a hand-over is no mission: the steps of the mission before it are not carried along ----------
fetch.STATE_FILE = Path(tempfile.mkdtemp()) / "lumi_task.json"
fetch._set(status="holding", holding=True, task={"steps": [{"do": "move", "dir": "back", "m": 1.0}], "sender": None})
fetch._in_hand = lambda: True
fetch.motion.poses = lambda: {"give": [0] * 6, "look": [0] * 6}
fetch._lift_to = lambda mm: None
fetch.head_ahead = lambda: None
fetch._give = lambda say: events.append("held out") or "kept"
real_mission = lumi.Lumi.mission_running
fetch.give()
fetch._thread.join(2)
assert fetch.state()["task"] is None and not real_mission(L)
fetch._set(status="running") # while it is held out: still no mission (mission_talk)
assert not real_mission(L)
fetch._set(status="holding")
# ---------- every drive and turn with something held: to look first ----------
moves = []
real_pose = fetch._drive_pose
fetch._drive_pose = lambda holding=False: moves.append(holding)
fetch.stay_put = False
fetch._charging = lambda: False
fetch._waist_front = lambda: None
fetch._sweep_blocked = lambda *a, **k: True # stops _turn after the arm (no base move in a test)
assert fetch._turn(90.0, holding=True) is False and moves == [True] # a mission's turn after a give / carry
moves.clear()
real_ready = follow.ready
follow.ready = lambda: None
fetch.arm_yaw = lambda: None
assert follow.prepare() == [] and moves == [True] # follow me with the cup: the held lines, holding speed
follow.ready, fetch._drive_pose = real_ready, real_pose
print(f"come give ok ({len(COME_GIVE) + len(NAMED)} wordings x held / empty, far give comes first, come and give, "
"no stale mission, held drives to look)")
+34 -2
View File
@@ -122,8 +122,40 @@ lumi.arm_route.move = lambda seq, speed=None, holding=False: route.append(seq[-1
fetch.state = lambda: {"status": "failed", "holding": False} fetch.state = lambda: {"status": "failed", "holding": False}
assert not lumi.waist_home("the conversation is over") and not route and waist["turn"] == 26.0 assert not lumi.waist_home("the conversation is over") and not route and waist["turn"] == 26.0
assert lumi.waist_home("coming to a person", fold=True) and route == ["look"] and waist["turn"] == 0.0 assert lumi.waist_home("coming to a person", fold=True) and route == ["look"] and waist["turn"] == 0.0
# something in the hand (live 2026-10-29: "come here" drove with the cup held out in give): to look first along the
# straight held lines (fetch.drive_ready), also with the waist at the front; a conversation's end moves nothing
route.clear(), waist.update(turn=26.0) route.clear(), waist.update(turn=26.0)
fetch.state = lambda: {"status": "failed", "holding": True} # something in the hand: never moved for a drive fetch.state = lambda: {"status": "stopped", "holding": True}
assert not lumi.waist_home("coming to a person", fold=True) and not route real_ready = fetch.drive_ready
fetch.drive_ready = lambda: route.append("held look")
assert not lumi.waist_home("the conversation is over") and not route
assert lumi.waist_home("coming to a person", fold=True) and route == ["held look"] and waist["turn"] == 0.0
route.clear()
assert lumi.waist_home("driving", fold=True) and route == ["held look"] # the waist at the front already
fetch.drive_ready = lambda: (_ for _ in ()).throw(fetch.FetchError("I can't move my arm there safely."))
route.clear(), waist.update(turn=26.0)
assert not lumi.waist_home("coming to a person", fold=True) and not route and waist["turn"] == 26.0 # no drive
fetch.drive_ready = real_ready
(fetch._waist_turn, fetch.state, fetch._at_pose, fetch._waist_to, lumi.arm_route.plan, lumi.arm_route.move) = real (fetch._waist_turn, fetch.state, fetch._at_pose, fetch._waist_to, lumi.arm_route.plan, lumi.arm_route.move) = real
# fetch.drive_ready itself: nothing held -> no arm move; held -> the held lines to look (_drive_pose(True)); a task
# running -> refused (it moves the arm itself)
real = (fetch.state, fetch._drive_pose, fetch._busy)
moves = []
fetch._drive_pose = lambda holding=False: moves.append(holding)
fetch._busy = lambda: False
fetch.state = lambda: {"status": "done", "holding": False}
fetch.drive_ready()
assert moves == []
fetch.state = lambda: {"status": "stopped", "holding": True}
fetch._stop.set() # an old stop (the hand-over ended) does not end it
fetch.drive_ready()
assert moves == [True] and not fetch._stop.is_set()
fetch._busy = lambda: True
try:
fetch.drive_ready()
raise AssertionError("drove the arm while a task runs")
except fetch.FetchError:
pass
(fetch.state, fetch._drive_pose, fetch._busy) = real
print(f"reach live ok ({len(REACH) + len(NOT_REACH)} wordings, stop during a hung body move, held state, auto fold)") print(f"reach live ok ({len(REACH) + len(NOT_REACH)} wordings, stop during a hung body move, held state, auto fold)")