From cf8a170297af6a5c5783b088c1cb9d8dacf1798a Mon Sep 17 00:00:00 2001 From: Cutshion Date: Wed, 4 Nov 2026 17:37:09 +0900 Subject: [PATCH] Fix hand reach, arm rest routing and response delays on the charger Co-Authored-By: Claude Opus 5.5 --- api/server.py | 2 +- assistant/brain.py | 4 +- assistant/lumi.py | 235 +++++++++++++++++++++++++++---------- assistant/steps.py | 39 ++++-- manipulation/arm_route.py | 17 ++- tasks/fetch.py | 46 +++++++- tasks/wave_greet.py | 139 +++++++++++++++++++--- tests/test_command_box.py | 20 ++++ tests/test_fetch.py | 28 +++++ tests/test_look_me.py | 1 + tests/test_mission_stop.py | 13 ++ tests/test_steps.py | 17 +++ tests/test_switches.py | 141 +++++++++++++++------- tests/test_wake.py | 4 + tests/test_wave_greet.py | 75 ++++++++++++ 15 files changed, 641 insertions(+), 140 deletions(-) diff --git a/api/server.py b/api/server.py index 5c7a848..61fe600 100644 --- a/api/server.py +++ b/api/server.py @@ -1404,7 +1404,7 @@ def task_state(): class ModesBody(BaseModel): greeter: bool | None = Field(None, description="standing: greet people who come close, talk, wake word") patrol: bool | None = Field(None, description="driving anywhere: stop for people in the way, talk, drive on") - wave_greet: bool | None = Field(None, description="wave back at people who wave, Greeter / Patrol not needed") + wave_greet: bool | None = Field(None, description="wave back at people who wave, with or without Greeter / Patrol") @app.get("/assistant/modes", tags=["assistant"], summary="Greeter / patrol / wave greeting switches") diff --git a/assistant/brain.py b/assistant/brain.py index 2240d8a..89eb3bd 100644 --- a/assistant/brain.py +++ b/assistant/brain.py @@ -782,8 +782,8 @@ INTENTS = [ # (action, pattern) checked in order on what the visitor said r"hand closed?|squeeze (your )?(hand|fingers)( shut)?)\b|^\W*grip\W*$" r"|손을? ?(?:꽉 |좀 )*(쥐|오므려|닫아)|\bclose\s*해\s*손|손가락\s*(?:을\s*)?(?:좀\s*|한번\s*|다\s*)*모아|주먹 ?(을 )?쥐|잡아(?!먹|당| ?보자| ?봐도| ?볼래)|손 ?close|(그리퍼|집게)(를|을)? ?(좀 )?(닫아|오므려)"), ("arm", r"\b(reach out(?! to (?!me\b))|stretch (out )?your (arm|hand)|put your (arm|hand) (out|forward)|hand forward|" - r"hold out your (arm|hand|gripper|claw|fingers)|extend your (arm|hand|gripper)|give me your hand|offer me your hand|" - r"give me (?:a|ur|you) hand(?!\s+(?:with|to|for|in|on|carrying|moving|lifting)\b)|" + r"hold out your (arm|hand|gripper|claw|fingers)|extend your (arm|hand|gripper)|give me your hands?|offer me your hands?|" # "give me your hands." (heard live 2026-11-04) + r"give me (?:a|ur|you) hands?(?!\s+(?:with|to|for|in|on|carrying|moving|lifting)\b)|" r"(put|hold|stick) your (arm|hand) out|put out your (arm|hand)|reach (?:your |ur |youur )?(?:arm|hand) out|reach (?:your |ur )?arm|" r"reach (out )?(to|toward|towards|for) me)\b|팔을? ?(?:앞으로 |쭉 |좀 |다시 |이쪽으로 )*(뻗|내밀)" r"|손을? ?(좀 |앞으로 |아프로 |쭉 )*(내밀|내미(?=[시세십])|뻗)(?!었)|\blet me hold your hand\b|^\W*(?:(?:루미야?|lumi|에구|아|어이|얘야|로봇아?|음|저기요?)\W*)*(?:(?:나|저)(?:한테|에게)?\s*)?(?:손|hand|핸드) ?(?:을 )?" diff --git a/assistant/lumi.py b/assistant/lumi.py index 2806846..ee071ff 100644 --- a/assistant/lumi.py +++ b/assistant/lumi.py @@ -60,6 +60,7 @@ import subprocess import sys import threading import time +import urllib.request # Started with the system python (no cv2 there)? Restart with the project's venv. ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # the project folder @@ -98,7 +99,9 @@ from assistant import fetch_dialog from assistant import seeing from assistant import memory from assistant.brain import Brain +from tasks import wave_greet +API_URL = "http://127.0.0.1:8100" # api/server.py: the wave greeting switch is turned off there after an arm stop NEAR_MIN, NEAR_MAX = 0.5, 1.2 # m, greeting zone PATROL_NEAR_MAX = 1.0 # m, on patrol: only people this close stop the robot STAY_MAX = 2.5 # m, a greeted person farther than this counts as gone @@ -188,16 +191,6 @@ def needs_arm(action, target=""): return action in ARM_TASKS or action == "arm" and target not in ("open", "close") -def reach_turn(angle, hand=0.0): - """Waist turn (deg, + left) before "reach out to me" to a person at the waist-frame `angle` (None: nobody seen or - heard) that brings the hand, held out at `hand` deg in give (fetch.give_bearing), onto them: 0 within - REACH_FRONT_DEG, else angle - hand. Greeter only turns the waist for it too: the base stays (fetch.reach).""" - if angle is None: - return None - turn = float(angle) - hand - return 0.0 if abs(turn) <= REACH_FRONT_DEG else turn - - _waist_lock = threading.Lock() # one waist return at a time (a conversation's end and the drive after it) @@ -207,30 +200,87 @@ def waist_turned(): return safe(fetch._waist_turn, default=0.0) or 0.0 +def wave_greet_on(): + """The dashboard's "Wave greeting" switch (MODES_FILE, written by api/server.py).""" + try: + with open(MODES_FILE) as f: + return bool(json.load(f).get("wave_greet")) + except (OSError, ValueError): + return False + + +def wave_greet_off(): + """Switch the wave greeting off (after a stop of the arm), through the API like the dashboard does.""" + req = urllib.request.Request(API_URL + "/assistant/modes", data=json.dumps({"wave_greet": False}).encode(), + headers={"Content-Type": "application/json"}) + try: + urllib.request.urlopen(req, timeout=5).close() + except OSError as e: + log(f"wave greeting not switched off: {e!r}") + + +def on_charger(): + """The base stands on its charger (home), no drive running (leaving it, it still charges for a moment).""" + st = safe(agv.status, default={}) or {} + return bool(st.get("charge_state")) and st.get("move_status") != "running" + + +def waist_home_rest(why): + """On the charger with nothing to do (after a drive home, at a conversation's end): the empty arm slowly from its + rest (arm_route.REST) to look and the waist to HOME_WAIST_DEG (owner, 2026-11-04); every order that moves the arm + or the base takes it to REST first again (waist_home fold). Checked like every move. Not while a task runs, with + something in the hand or the arm out (a hand held out). True when both are there.""" + from tasks import fetch + if not on_charger(): + return False + with _waist_lock: + try: + st = fetch.state() + if st.get("status") == "running" or st.get("holding"): + log(f" arm and waist stay ({why}): a task runs or something is in my hand") + return False + fetch._stop.clear() + if not fetch._at_pose(arm_route.HOME): + if not fetch._at_pose(arm_route.rest_pose()): + log(f" arm and waist stay ({why}): my arm is out") + return False + arm_route.move(arm_route.plan(arm_route.HOME), HOME_ARM_SPEED) + log(f" arm to look at home ({why})") + if fetch._waist_to(HOME_WAIST_DEG, in_place=True): + log(f" waist to its rest at home, {HOME_WAIST_DEG:+.0f} deg ({why})") + return True + except Exception as e: + log(f" arm and waist stay ({why}): {e!r}") + return False + + 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 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 - waist stays, unless `fold` (an order to drive or turn): something held goes to look first wherever the waist is - (fetch.drive_ready: straight checked lines, holding speed); an empty arm goes back to look along the checked pose - 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).""" + limits. Not while a task runs (it turns the waist itself) or the arm is out of its rest (a hand held out): logged, + the waist stays, unless `fold` (an order to drive or turn): something held goes to look first wherever the waist + is (fetch.drive_ready: straight checked lines, holding speed), an empty arm to its rest (arm_route.REST, owner + 2026-11-04) along the checked pose graph. True when the waist is at the front (and the arm at its rest).""" from tasks import fetch with _waist_lock: try: - if fold and fetch.state().get("holding"): + if fold: + wave_greet.lower() # a hand up for a wave greeting comes down before any drive + holding, running = fetch.state().get("holding"), fetch.state().get("status") == "running" + if fold and holding: fetch.drive_ready() # a drive with the cup held out in carry / give: never - if abs(fetch._waist_turn()) < 1.0: + if fold and not holding and not running and not fetch._at_pose(rest := arm_route.rest_pose()): + log(f" arm to {rest} first ({why})") # every drive and turn starts with the empty arm at rest + arm_route.move(arm_route.plan(rest, holding=False), None, False) # (a bag on the hooks too), + if abs(fetch._waist_turn()) < 1.0: # wherever the waist is return True - if fetch.state().get("status") == "running": + if running: log(f" waist stays turned ({why}): a task runs") return False - if not fetch._at_pose(fetch._look()): - if not fold or fetch.state().get("holding"): - log(f" waist stays turned ({why}): my arm is not folded in look") - return False - log(f" arm back to look first ({why})") - arm_route.move(arm_route.plan(arm_route.HOME, holding=False), None, False) + rest = arm_route.rest_pose(holding) # look with a cup; look on the charger too (waist_home_rest) + if not fetch._at_pose(rest) and not fetch._at_pose(arm_route.HOME): + log(f" waist stays turned ({why}): my arm is not at {rest}") + return False fetch._stop.clear() # no task runs: an old stop must not end this; a new one does if fetch._waist_to(0.0, in_place=True): log(f" waist to the front ({why})") @@ -373,7 +423,8 @@ HELLO_ONLY = re.compile(r"^(?=\W*\w)\s*(?:(?:hi|hey|hello|hiya|hai|hallo|helo|hi CALL_REST = re.compile(r"^(?:[\W_]|\b(?:hi|hey|hello|hiya|hai|ok|okay|there|how are you(?: doing)?(?: today)?)\b|" r"안녕(?:하세요|하십니까)?|하이|헤이|야|아)*$", re.I) # what is left of a call without the name CAMERA_HALF_FOV = 42.0 # deg; half the camera's view (+ the head's YAW_LIMIT for the head camera) -WAKE_MAX_S = 6.0 # s; longer utterances are not checked for the wake word +WAKE_MAX_S = 6.0 # s; longer utterances are not checked for the wake word (reading every 8 s cut of a + # loud hall's noise held the next words back: answers came late, 2026-11-04) BARGE_IN_LOGPROB = -0.6 # an interruption must be heard more clearly than a normal answer (-1.0) ECHO_LIKELY = 0.45 # sound match (mouth.echo) from which a barge-in is Lumi's own voice when its words ECHO_LIKELY_SHARE = 0.4 # ... share this much with what Lumi said; echoes 0.51 / 0.54, the visitor 0.14-0.32 @@ -412,13 +463,17 @@ FOLLOW_SORRY_S = 20.0 # s; "Sorry, I'm following someone" at most t COME_STOP = 1.1 # m; driving to a person stops when the camera sees them this close COME_TIMEOUT = 60.0 # s MAX_MOVE_M = 3.0 # m; "move forward N metres" is limited to this -REACH_FRONT_DEG = 10.0 # deg; "reach out to me": a person further than this from where the hand points is - # turned to first (the waist, Greeter or Patrol); the reach after give moves at most - # fetch.RECEIVE_REACH_MM sideways (estimate) REACH_COME_M = 1.5 # m; a person further than this is driven to first (come_to, COME_STOP), the hand is # never held out from afar (owner, 2026-10-28) +HOME_WAIST_DEG = 85.8 # deg (+ left) from the front the waist rests at on the charger (owner's pose, + # 2026-11-04: body waist 65.5 deg); every drive turns it back to the front first +IDLE_AFTER_S = 15.0 # s without a word to Lumi on the charger before the wave greeting waves now and then + # (tasks/wave_greet.py IDLE_WAVE_EVERY_S; estimate) +PASSER_MAX_M, PASSER_EVERY_S, PASSER_DEG = 3.0, 5.0, 20.0 # on the charger, nobody talking: the head turns to the nearest + # person this near, at most this often, when this far off its direction (estimates) +HOME_ARM_SPEED = "slow" # motion.JOINT_SPEED of the arm's way from rest to look on the charger (owner: slowly) +HOME_DOCK_WAIT_S = 3.0 # s after arriving home before the charger is asked whether it charges (estimate) COME_CLOSER_SAY = ("Please come a little closer.", "조금 더 가까이 와 주세요.") -STAND_IN_FRONT_SAY = ("Please stand in front of me.", "제 앞에 서 주세요.") HAND_LOOK_KEEP_S = 10.0 # s a look at the hand (fetch.look_at_hand) stands for: the arm goes to carry and # back once per order, not once per question about the hand REACH_HOLD_S = 30.0 # s the hand stays held out after a reach, then the arm folds back to look (estimate) @@ -854,9 +909,14 @@ class Patrol: if self.mode == "going_home": self.mode = "charging" if st.get("charge_state") else "patrol" log("docked, charging" if self.mode == "charging" else f"could not dock ({ms})") + if self.mode == "charging": + threading.Thread(target=waist_home_rest, args=("docked",), daemon=True).start() return if ms == "succeeded": log(f"patrol at {self.route[self.i]}") + if self.route[self.i] == "home": + threading.Thread(target=lambda: time.sleep(HOME_DOCK_WAIT_S) or waist_home_rest("at home"), + daemon=True).start() if self.once and self.i == len(self.route) - 1: self.mode = "done" log("route finished") @@ -1004,7 +1064,7 @@ class Lumi: """The waist back to the front too when a conversation ends (waist_home, in the background), Greeter or Patrol; it waits like the head while a look is held.""" if not self.look_held(): - threading.Thread(target=waist_home, args=(why,), daemon=True).start() + threading.Thread(target=lambda: waist_home_rest(why) or waist_home(why), daemon=True).start() def keep_focus(self): """In the background: the head stays on the person Lumi talks with (self.current) as they move, a turn when @@ -1031,8 +1091,8 @@ class Lumi: """Turn to the person who now speaks: a waist turned for someone else comes back to the front first (waist_home), then the head turns to them (their angle from where the waist was, plus the turn taken back).""" w = waist_turned() - if abs(w) < 1.0: - self.turn_head(HEAD_SIGN * track.angle) + if abs(w) < 1.0 or on_charger(): # on the charger the waist stays at its rest: the head only + self.turn_head(HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, track.angle))) return angle = track.angle @@ -1209,7 +1269,7 @@ class Lumi: voice = getattr(self, "voice_guess", None) found, why = sweep(gaze if voice is None else voice) w = waist_turned() - if found is None and abs(w) > LOOK_ME_WAIST_DEG and waist_home("looking for the caller"): + if found is None and abs(w) > LOOK_ME_WAIST_DEG and not on_charger() and waist_home("looking for the caller"): voice = None if voice is None else voice + w # the cameras turn with the waist: a caller on the gaze = 0.0 # other side of it was in no view; again from the front log(f" look me: waist from {w:+.0f} deg to the front") @@ -2228,10 +2288,12 @@ class Lumi: return st is not None if target == "reach": return self.reach_out(held) + if target == "fold" and self.bag_on(): + return self.bag_off() self.reached_at = 0.0 # folding: no auto fold after it try: holding = self.fetch_status() == "holding" - seq = arm_route.plan(arm_route.HOME if target == "fold" else target, holding=holding) # "carry", "ready" + seq = arm_route.plan(arm_route.rest_pose(holding) if target == "fold" else target, holding=holding) # "carry", "ready" threading.Thread(target=safe, args=(arm_route.move, seq, None, holding), daemon=True).start() return True except arm_route.RouteError as e: @@ -2242,12 +2304,28 @@ class Lumi: log(f" arm {target}: {e}") return False + @staticmethod + def bag_on(): + """A bag hangs on the gripper's hooks (fetch state "bag", set by "hold the bag").""" + from tasks import fetch + return bool(fetch.state().get("bag")) + + def bag_off(self): + """"Fold your arm" with a bag on the hooks (put there by a mission's bag step, "hold the bag"): the arm back to + look, drives in look again (fetch.bag_off). True when done, None when refused (said).""" + from tasks import fetch + try: + fetch.bag_off() + except (fetch.FetchError, arm_route.RouteError) as e: + log(f" bag off refused: {e.args[0]}") + self.fetch_say(e.args[0], e.args[1] if len(e.args) > 1 else "죄송해요, 지금은 할 수 없어요.") + return None + return True + def reach_out(self, held): - """"Reach out to me", "give me your hand", "손 내밀어": something in the hand = hand it over. Else toward the - person (the tracked one, else the one the voice came from, else the voice's direction): further than - REACH_COME_M the base comes to them first (come_to); the head turns to them; the hand further from them than - REACH_FRONT_DEG: the waist turns first, until the hand (not the waist's front) points at them (reach_turn, Greeter only too: the base - stays); then fetch.reach (give pose along the graph, a short checked move toward their hand). The arm folds back on the next words that + """"Reach out to me", "give me your hand", "손 내밀어": something in the hand = hand it over. Else the hand goes + out at once the way the waist faces (owner, 2026-11-04: no turn to the person, no drive): fetch.reach (give + pose along the graph, a short checked move toward a hand seen there). The arm folds back on the next words that are no arm order or after REACH_HOLD_S (reach_done). True when started, None when refused or handed over (said).""" from tasks import fetch @@ -2259,26 +2337,10 @@ class Lumi: return None with _waist_lock: # a waist coming back to the front (face) ends first pass - ok, track = self.near_speaker("reach") - if not ok: - return None - 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) - hand = safe(fetch.give_bearing, default=0.0) or 0.0 - turn = reach_turn(angle, hand) - log(f" reach: person at {'?' if angle is None else f'{angle:+.0f}'} deg, hand at {hand:+.0f} deg, " - f"waist turn {turn}") - if turn is None: - self.fetch_say(*STAND_IN_FRONT_SAY) - return None - if not turn: # a waist turn takes the head along onto them (fetch._waist_to look): no head move here, - yaw = HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, angle)) # it raced it - log(f" reach: the head on them ({yaw:+.0f} deg) while the arm goes out") - safe(fetch._aim_at, None) # an earlier task's target no longer holds the head (it looked - self.turn_head(yaw, force=True) # away until the arm was out, 2026-10-30) + log(" reach: the hand out the way the waist faces") self.stay() try: - fetch.reach(turn, say=self.fetch_say, look=angle) + fetch.reach(0.0, say=self.fetch_say) except fetch.FetchError as e: log(f" reach refused: {e}") self.fetch_say(e.args[0], e.args[1] if len(e.args) > 1 else "죄송해요, 지금은 할 수 없어요.") @@ -2287,7 +2349,7 @@ class Lumi: 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 + """Before the hand goes out to the person who asked (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: @@ -2328,7 +2390,7 @@ class Lumi: return False if status == "running": safe(fetch.stop) - log(f" reach over ({'said ' + repr(text) if text else 'timeout'}): the arm back to look") + log(f" reach over ({'said ' + repr(text) if text else 'timeout'}): the arm back to rest") return bool(self.arm_pose("fold")) def typed(self, text): @@ -2405,7 +2467,9 @@ class Lumi: except fetch.FetchError as e: log(f" fetch refused: {e}") elif cmd == "fetch_stop": - safe(fetch.stop) + from tasks import follow + safe(follow.stop) # the dashboard's stop ends following too (agv.cancel + safe(fetch.stop) # does not stop joy_control) elif cmd == "fetch_release": safe(fetch.release_now) elif cmd == "fetch_carry": @@ -2838,6 +2902,9 @@ class Lumi: held look ("look left") and a task's aim keep the head (turn_head).""" if not self.vision or u is None: return + rule = text and brain_mod.intent(text, self.markers) + if rule and rule[0] == "look" and rule[1] != "me": # "look left": the head goes there at once, not to the + return # speaker first (the body takes one move at a time) if self._who_spoke(u, text): # someone else took over: face() turned to them return t = self.current if self.current is not None and self.vision.present(self.current) else self.vision.only_person() @@ -2883,6 +2950,21 @@ class Lumi: self.face(t) return True + def watch_passers(self): + """On the charger with nobody talking to Lumi: the head turns to the nearest person within PASSER_MAX_M, at most + every PASSER_EVERY_S, when they are more than PASSER_DEG off where it looks (owner, 2026-11-04: the head + follows the people passing by, left and right). Not while the wave greeting moves or a look is held.""" + now = time.time() + if now - getattr(self, "passer_at", 0.0) < PASSER_EVERY_S or wave_greet.busy() or self.look_held(): + return + self.passer_at = now + seen = self.vision.seen(PASSER_MAX_M) + if not seen or not on_charger(): + return + want = HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, min(seen, key=lambda s: s[1])[0])) + if abs(want - self.det_yaw()) > PASSER_DEG: + self.turn_head(want) + def det_yaw(self): """Current head yaw (deg), read from the body every 0.3 s (the torso camera does not know it).""" now = time.time() @@ -3178,7 +3260,12 @@ class Lumi: return from tasks import fetch # the way it goes: route(), as the dashboard's Command box full = brain_mod.hand_request(text, True, self.brain, self.markers) # an order that needs the hand: a fully - needs = bool(full) and full[0] in ("give", "place") # shut hand is looked at first (live 2026-10-30: a cup + bag = self.bag_on() # a bag on the hooks: the gripper holds nothing, no look at it + if bag and full and full[0] == "give": # "give me the bag", "가방 줘": the hand with the bag out in + if self.reach_out(False): # give; "thanks" (reach_done) folds it to look, the bag mode ends + mouth.say("Here you go." if self.lang == "en" else "여기요.") + return + needs = bool(full) and full[0] in ("give", "place") and not bag # shut hand is looked at first (live 2026-10-30: a cup kind, data = route(text, self.markers, self.brain, lambda: self.held_now(look=needs), # put in it was "not held") seen=lambda x: seeing.answer(x, self.lang, slow_line=mouth.say), last=last, chain_ok=not part and not self.mission_running() and not self.chain_busy()) if kind == "stop": @@ -3494,7 +3581,8 @@ 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 and not self.vision.seen() else None + w = waist_turned() if abs(robot_angle) > view and self.modes.patrol and not self.vision.seen() and \ + not on_charger() else None # on the charger the body stays, the head looks # 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): @@ -3528,8 +3616,8 @@ class Lumi: def look_toward(self, robot_angle): """Turn the head toward a waist-frame angle; turn the base too if it is outside the head's range.""" - if abs(robot_angle) <= head.YAW_LIMIT: - self.turn_head(HEAD_SIGN * robot_angle) + if abs(robot_angle) <= head.YAW_LIMIT or on_charger(): # on the charger the body stays, the head only + self.turn_head(HEAD_SIGN * max(-head.YAW_LIMIT, min(head.YAW_LIMIT, robot_angle))) elif self.modes.patrol: w = waist_turned() if not waist_home("turning to a voice", fold=True): @@ -3736,7 +3824,7 @@ class Lumi: # on the way only people in the path, close by; standing: everyone in the greeting zone self.vision.near_max, self.vision.corridor = (PATROL_NEAR_MAX, PATH_HALF_WIDTH) if moving else (NEAR_MAX, None) if not self.vision.pinned: # driving: the path ahead; standing: the people - self.vision.prefer = "torso" if moving else "head" + self.vision.prefer = "torso" if moving and not self.bag_on() else "head" # a bag hangs before the torso one if time.time() < self.calib_until: self.vision.det.focus_angle = None self.calibrate_step() @@ -3748,6 +3836,8 @@ class Lumi: following = follow.running() # no greetings (the head would turn away), keep listening greet_now = self.modes.greeter and not moving and time.time() > self.quiet_until and not following \ and not self.doing() and self.current is None # never during a task or while talking with someone + if greet_now and wave_greet_on(): # a wave is answered by the wave greeting (arm and words) + greet_now = False candidate = self.waver() if greet_now else None # Lumi never speaks to someone who only stands there or focus = self.current or candidate # walks past: a wave (or the wake word) calls it self.vision.det.focus_angle = focus.angle if focus else None # drawn red in the dashboard @@ -3799,6 +3889,7 @@ class Lumi: if self.voice_until: log("voice conversation over (silence): the wake word or a wave again") self.end_conversation(None, quiet=True) # Lumi never speaks unasked: no goodbye into a silence + self.watch_passers() # on the charger: the head on people passing by if self.check_wake(): # "Hi Lumi" works in every mode return if self.patrol: @@ -3870,9 +3961,23 @@ class Lumi: memory.watch(arm_ok=lambda: not getattr(self, "busy_now", "") and self.doing() is None and self.fetch_status() != "running", look_held=self.look_held) self.warm_llm() + if self.vision and self.modes.wave: # the API's wave greeting waits while this process runs + wave_greet.start(wave_greet_on, self.wave_free, wave_greet_off, free_every=0.05, + rest=lambda: HOME_WAIST_DEG if on_charger() else 0.0, + rest_arm=lambda: arm_route.HOME if on_charger() else arm_route.rest_pose(), + idle=lambda: time.time() - getattr(self, "last_activity", time.time()) > IDLE_AFTER_S and on_charger()) log("ready") self.run_camera() if self.vision else self.run_desk() + def wave_free(self): + """The wave greeting may use the robot: no drive, task, skill, follow, calibration or asked wave runs, and + nobody is being talked to, unless the hand is already up for them (it stays up, swings, comes down).""" + from tasks import follow + if self.traveling() or self.doing() is not None or follow.running() or self.wave_lock.locked() or \ + time.time() < self.calib_until or self.fetch_status() in ("running", "waiting") or self.bag_on(): + return False + return wave_greet.up() or self.current is None and time.time() >= self.voice_until + NOT_STOP = re.compile( # a stop word that orders no stop: negated, about someone or something else, another meaning r"\b(?:don'?t|do not|never|no need to|not) (?:\w+ )?sto+p\b|\bkeep (?:going|moving|walking|driving)\b|\bcontinue\b|" diff --git a/assistant/steps.py b/assistant/steps.py index d38ca11..b897356 100644 --- a/assistant/steps.py +++ b/assistant/steps.py @@ -9,7 +9,7 @@ A step is a dict, "do" says which: {"do": "turn", "deg": + left} {"do": "pick", "object", "colour"} {"do": "receive", "object"} {"do": "say", "text"} {"do": "place", "on": None | {"name": camera class, "colour", "side": "left" | "right" | None}} - {"do": "give"} {"do": "hold"} {"do": "arm", "pose": "reach" | "fold" | "open" | "close"} + {"do": "give"} {"do": "hold"} {"do": "arm", "pose": "reach" | "fold" | "open" | "close" | "bag"} {"do": "wait", "s": seconds | None (until told to go on; at the end: stay there), "until": "instruction" (optional)} {"do": "receive", "object", "wait_s": seconds} ("wait until someone gives you the cup": the hand held out this long) Nothing is guessed: a clause the rules can't read stays unread and the whole command is asked again.""" @@ -360,6 +360,27 @@ def _hold(c): r"|wait (?:there )?holding it|들고 있어(?:요|줘)?", c) else None +_BAG_EN = r"(?:the |this |that |my |a |your |our )?(?:shopping |paper |gift )?bag" +_BAG_KO = r"(?:이 |그 |제 |내 )?(?:쇼핑백|종이 ?가방|가방)(?:을|를|은|는|이)?" + + +def _bag(c, markers): + """"take the bag to p1", "hold this bag", "here's the bag", "가방 들어", "가방 p1으로 가져가": the arm to its bag + pose (a person hangs the bag on the hooks), then the drive if a place is named.""" + m = re.fullmatch(rf"(?:take|carry|bring|hold|grab|get|keep|hang|deliver) {_BAG_EN}(?: (?:to|over to|for me to) (.+?)| (home))?" + rf"|(?:here'?s|here is|this is) {_BAG_EN}|{_BAG_EN} (?:pose|position)|" + rf"{_BAG_KO}\s*(?:(.+?)\s*(?:으로|로|에|까지)\s*)?(?:좀\s*)?" + rf"(?:들어|받아|맡아|걸어|가져가|가지고 가|갖고 가|들고 가|옮겨|배달해)\s*(?:줘|요|주세요|줄래|서|고)?" + rf"|{_BAG_KO}\s*(?:포즈|자세)(?:로|으로)?", c) + if not m: + return None + where = m.group(1) or m.group(2) or m.group(3) + if not where: + return [{"do": "arm", "pose": "bag"}] + to = _places(where, markers) + return to and [{"do": "arm", "pose": "bag"}, {"do": "go", "to": to if len(to) > 1 else to[0]}] + + def _arm(c): for pose, p in (("reach", r"(?:reach out|stretch out|stretch|extend|put out|hold out) (?:your |my )?(?:arm|hand)|" r"reach out|팔을? ?(?:뻗어|뻗고|내밀어|내밀고)(?:줘|요)?"), @@ -803,6 +824,9 @@ def _clause_steps(c, markers, after=None): s = after and after["do"] in ("pick", "receive") and _place_at(c, markers, after) if s: return s # "컵 집어서 | exit에 갖다 줘": delivered there, not only a drive + s = _bag(c, markers) + if s is not None: + return s or None for f in (_go, _move, _turn, _give, _hold, _arm): s = f(c, markers) if f is _go else f(c) if s: @@ -1125,7 +1149,7 @@ LLM_SCHEMA = {"type": "object", "required": ["steps"], "properties": {"steps": { "object": {"type": ["string", "null"]}, "colour": {"type": ["string", "null"]}, "text": {"type": "string"}, "on": {"type": ["object", "null"], "properties": {"name": {"type": "string"}, "colour": {"type": ["string", "null"]}, "side": {"type": ["string", "null"]}}}, - "pose": {"enum": ["reach", "fold", "open", "close"]}, "s": {"type": ["number", "null"]}, + "pose": {"enum": ["reach", "fold", "open", "close", "bag"]}, "s": {"type": ["number", "null"]}, "until": {"type": ["string", "null"]}}}}}} LLM_NUM_PREDICT = 700 # tokens; a 7-step answer is ~400 NEGATION = re.compile(r"\b(?:not|don'?t|do not|never|instead|except|without|no)\b|말고|대신|하지 ?마|지 ?마|빼고") @@ -1269,7 +1293,7 @@ def _checked(raw, text, markers): return None if d == "arm": pat = {"reach": r"reach|stretch|뻗|내밀", "fold": r"fold|bend|tuck|접|굽", "open": r"\bopen|펴|벌려|열", - "close": r"\bclose|쥐|오므|닫"}.get(raw.get("pose")) + "close": r"\bclose|쥐|오므|닫", "bag": r"\bbag\b|가방|쇼핑백"}.get(raw.get("pose")) return {"do": "arm", "pose": raw["pose"]} if pat and re.search(pat, t) else None return None @@ -1320,7 +1344,7 @@ def _bad_fields(s): return "a place I don't know" if d == "give" and not isinstance(s.get("person", ""), str): return "a person without a name" - if d == "arm" and s.get("pose") not in ("reach", "fold", "open", "close"): + if d == "arm" and s.get("pose") not in ("reach", "fold", "open", "close", "bag"): return "an arm movement I don't know" if d == "wait" and (not (s.get("s") is None or num(s["s"])) or s.get("until") not in (None, "instruction") or s.get("until") and s.get("s") is None): @@ -1375,7 +1399,7 @@ def check(steps, holding, markers=()): if not holding: out.append(f"Step {i}: I have nothing in my hand to {'put down' if d == 'place' else 'hand over'}.") holding = False - elif d == "arm" and s["pose"] in ("reach", "fold") and holding: + elif d == "arm" and s["pose"] in ("reach", "fold", "bag") and holding: out.append(f"Step {i}: I can't move my arm like that while holding something.") elif d == "arm" and s["pose"] == "open" and holding: out.append(f"Step {i}: I won't open my hand while holding something: it would fall. " @@ -1454,7 +1478,8 @@ def _en(s, last=False): else "give it to you" if d == "hold": return "hold it" - return {"reach": "reach out my arm", "fold": "fold my arm", "open": "open my hand", "close": "close my hand"}[s["pose"]] + return {"reach": "reach out my arm", "fold": "fold my arm", "open": "open my hand", "close": "close my hand", + "bag": "hold my hand ready for the bag"}[s["pose"]] def _ko(s, last=False): @@ -1497,7 +1522,7 @@ def _ko(s, last=False): return "거기 있는 분께 건네주고" if s.get("_away") else "건네주고" if d == "hold": return "들고 있고" - return {"reach": "팔을 뻗고", "fold": "팔을 접고", "open": "손을 펴고", "close": "손을 쥐고"}[s["pose"]] + return {"reach": "팔을 뻗고", "fold": "팔을 접고", "open": "손을 펴고", "close": "손을 쥐고", "bag": "가방 들 준비를 하고"}[s["pose"]] def _will(stem): diff --git a/manipulation/arm_route.py b/manipulation/arm_route.py index 5a89c1f..ba8cff9 100644 --- a/manipulation/arm_route.py +++ b/manipulation/arm_route.py @@ -52,15 +52,21 @@ from robot import arm, gripper, kinematics, motion from vision import calib, head_cam HOME = "look" # every arm action starts here +REST = "rest" # the empty arm rests and drives here (owner, 2026-11-04): after "thanks", "fold", + # a wave, and before every drive or turn; a held cup still drives in look GIVE = "give" # the hand held out to a person GIVE_PRE = "give_pre" # one step before GIVE: an empty-hand way to GIVE always ends GIVE_PRE -> GIVE GIVE_SPEED = "route" # motion.JOINT_SPEED of the last move, GIVE_PRE -> GIVE EDGES = (("give_pre", "give"), ("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"), - ("wave_start", "wave"), ("look", "ready")) # the moves with something in the hand (both ways) + ("wave_start", "wave"), ("look", "ready"), ("look", "bag"), ("carry", "bag"), + ("rest", "look"), ("rest", "bag"), ("rest", "give_pre")) # the moves with something in + # the hand (both ways) WAVE_POSES = ("wave_out", "wave_start", "wave") # never with something in the hand (the cup would tip) NO_EDGES = {frozenset(("look", "wave_start")), # never one joint move: passes 267 mm from the head (the wave - *(frozenset(("give", w)) for w in ("wave_out", "wave_start", "wave"))} # goes up and down through - # wave_out, 309 mm); give and the wave poses through give_pre + *(frozenset(("give", w)) for w in ("wave_out", "wave_start", "wave")), # goes up and down through + *(frozenset((p, w)) for p in ("rest", "give_pre") for w in ("wave_start", "wave"))} # wave_out, 309 mm); + # give and the wave poses through give_pre; rest and give_pre + # (110 deg moves) through wave_out too STOP_DEG = 10.0 # deg of joint travel one more stop on a route costs (SETTLE_S, slowing down and # starting again; an estimate, it only weighs routes against each other) SPEED = "route" # motion.JOINT_SPEED of the moves along the graph, empty hand @@ -118,6 +124,11 @@ def graph(holding=False, skip=()): if n in p and n not in skip and not (holding and n in WAVE_POSES + (GIVE_PRE,))} +def rest_pose(holding=False): + """REST for an empty hand when it is taught, else HOME (also with something in the hand).""" + return REST if not holding and REST in motion.poses() else HOME + + def where(now=None): """The graph pose the arm is at (every joint within AT_POSE_DEG), else None.""" now = skills._joints() if now is None else now diff --git a/tasks/fetch.py b/tasks/fetch.py index ad880f8..9577e9a 100644 --- a/tasks/fetch.py +++ b/tasks/fetch.py @@ -50,6 +50,9 @@ LOOK_POSE = "look" # drives, turns, looks and waits here, also with an # the torso view, too near for depth (ready if not taught). carry is only passed through after a # pick: in carry the hand is ~0.3 m before the base's front, where its 3D camera seems to see # it as an obstacle (every drive in carry stalled; the same drives in look went, 2026-10-16) +BAG_POSE = "bag" # the arm held out for a bag to be hung on the gripper's hooks (owner's pose); drives go + # in arm_route.REST like every empty-hand drive (in look the bag hung before the base's + # 3D camera and every drive stalled) CHECK_POSE = "carry" # a fully shut hand is looked at here (look_at_hand): the torso camera sees the place between # the fingers ~445 mm away (from the joints and the calibration; in look it is above the view, # in give a person's hand can be there). Not yet tried live: the fingers may hide it @@ -402,12 +405,31 @@ def _at_pose(name): return max(abs(a - b) for a, b in zip(j, motion.nearest(motion.poses()[name], j))) <= 1.0 +BAG_HOLDING = ("My hand is holding something, I can't take a bag now.", "손에 뭔가 들고 있어서 지금은 가방을 들 수 없어요.") +BAG_HANG_SAY = ("Please hang the bag on my hand.", "가방을 제 손에 걸어 주세요.") +BAG_HANG_S = 8.0 # s a mission waits after the arm went to BAG_POSE, for a person to hang the bag on (estimate) + + +def bag_off(): + """The bag taken off the hooks ("fold your arm", "thanks" after "give me the bag", outside a task): the arm to its + rest (arm_route.rest_pose) along the pose graph and the state's "bag" cleared. FetchError when busy or the arm + can't go.""" + _adopt() + with _lock: + if _busy(): + raise FetchError("I'm busy with another task.", "지금 다른 일을 하고 있어요.") + _stop.clear() # an old stop must not end this one; a new one does + _pose(arm_route.rest_pose()) + _set(bag=False) + log("no bag: the arm at rest") + + def _drive_pose(holding=False): - """The arm to look before the base drives or turns. A switched-off arm (Cobo π: not powered or not enabled) stays + """The arm to its rest (arm_route.rest_pose; look with something held) before the base drives or turns. A switched-off arm (Cobo π: not powered or not enabled) stays where it is: drives and talk need no arm, and the arm's points are still checked from its joints. Powered off, it reads all joints 0: where it is is not known, so no drive (ARM_UNSEEN).""" try: - _line_holding(LOOK_POSE) if holding else _pose(_look()) + _line_holding(LOOK_POSE) if holding else _pose(arm_route.rest_pose()) # a bag on the hooks too except (FetchError, motion.MotionError) as e: if tuple(e.args[:1]) != arm_route.OFF[:1] and "not powered" not in str(e): raise @@ -3066,7 +3088,7 @@ def _do_step(s, say): if _give(say) == "kept": raise FetchError("Nobody took it, I'm still holding it.", "아무도 안 받아서 계속 들고 있어요.") elif d == "arm": - _arm(s["pose"]) + _arm(s["pose"], say) elif d == "carry": _carry_held() # "hold": nothing to do, the mission ends holding @@ -3423,15 +3445,27 @@ def _give_turning(rel, look): _go_on() -def _arm(pose): +def _arm(pose, say=None): if pose in ("open", "close"): st = gripper.open_() if pose == "open" else gripper.close() if pose == "open": skills._held.clear() _set(holding=False) log(f"gripper {pose}: {st}") - elif pose == "fold": # the arm's home - _line_holding(LOOK_POSE) if _state["holding"] else _pose(LOOK_POSE) + elif pose == "fold": # the arm's rest + _line_holding(LOOK_POSE) if _state["holding"] else _pose(arm_route.rest_pose()) + _set(bag=False) + elif pose == "bag": # the hooks ready for a bag; drives keep the arm there (BAG_POSE) + if _state["holding"]: + raise FetchError(*BAG_HOLDING) + hung = _state.get("bag") + _pose(BAG_POSE) + _set(bag=True) + if not hung: # a person hangs it on now, before the next step drives + if say: + say(*BAG_HANG_SAY) + if _stop.wait(BAG_HANG_S): + raise Stopped() elif pose == "reach": # the hand held out, as for a hand-over if "give" not in motion.poses(): raise FetchError("I haven't learned how to reach out yet.") diff --git a/tasks/wave_greet.py b/tasks/wave_greet.py index 565a750..4fbc9d0 100644 --- a/tasks/wave_greet.py +++ b/tasks/wave_greet.py @@ -1,5 +1,7 @@ -"""Wave back at people who wave at Lumi: the dashboard switch "Wave greeting". Greeter / Patrol are not needed; while -either runs the assistant owns the robot and this waits. Runs in the API process (api/server.py starts it). +"""Wave back at people who wave at Lumi: the dashboard switch "Wave greeting", with or without Greeter / Patrol. It +runs in the process that owns the robot: the API's (api/server.py) while the assistant is off, the assistant's +(assistant/lumi.py) while it runs. There it waits while a drive, task, skill or conversation has the robot; a drive +or turn brings a raised hand down first (lower()). Someone waving within GREET_M of either camera (vision/waving.py; the head camera may look elsewhere): the head turns to them and the arm goes up at once (manipulation/wave.py checks and plans the way, look -> wave_out -> wave_start, at the route speed), Lumi says a @@ -51,6 +53,12 @@ REFUSED_S = 30.0 # s before trying again after the arm was refused ( # between tries to bring a blocked waist back to the front HEAD_TIMEOUT_S = 5.0 # s a head move may take; the body API now and then never answers a moveto, and the call # holds the body lock all that time (the waist turn waited 30 s behind it) +IDLE_WAVE_EVERY_S = 20.0 # s between two waves while nothing is asked of Lumi on the charger (owner: now and then for + # the passers-by; estimate), from the end of the last one (or anyone's last wave) +IDLE_SWINGS = 2 # swings of such a wave +IDLE_CLEAR_M = 1.0 # m; nobody this near in either camera when such a wave starts (one coming closer while the + # arm goes up still stops it: _too_close); estimate +IDLE_RETRY_S = 1.0 # s between two asks whether Lumi is idle (it asks the base whether it charges) CLOSE_FRESH_S = 1.5 # s a camera service detection counts for the too-close check _seen = {c: {"t": 0.0, "wavers": []} for c in CAMERAS} # wavers: [(bearing deg from the waist's front, + left; @@ -60,6 +68,9 @@ _met_lock = threading.Lock() _busy = threading.Event() # the arm is up or moving for a greeting _speaking = threading.Lock() _on = _free = _off = None # set by start() +_rest = lambda: 0.0 # waist angle (deg from the front) the waist goes back to; set by start() +_rest_arm = arm_route.rest_pose # the pose the arm goes down to; set by start() +_idle = lambda: False # nothing asked of Lumi for a while (on the charger): a wave now and then; set by start() def log(*a): @@ -168,6 +179,19 @@ def _too_close(): return False +def _someone_within(m): + """A person within `m` metres in either camera's fresh detections.""" + for cam in ("head", "torso"): + try: + d = json.loads(camview.det_path(cam).read_text()) + except (FileNotFoundError, ValueError): + continue + if time.time() - d["time"] < CLOSE_FRESH_S and \ + any(p.get("distance_m") is not None and p["distance_m"] < m for p in d["people"]): + return True + return False + + # ---------- moving and talking ---------- def _bg(fn, *args): threading.Thread(target=fn, args=args, daemon=True).start() @@ -302,18 +326,55 @@ def _greet(w, lang): return True -def _down(): - """Waist to the front first, the way it came with the hand up (in `look` the arm sticks out further and the same - turn back can be blocked), then the arm slowly down to look and the head to rest.""" +def _idle_wave(): + """Nobody asks anything (on the charger, _idle): the hand goes up and stays up (owner, 2026-11-04: "held"), the + waist where it is, no words; it swings IDLE_SWINGS times now and then (step) so passers-by see Lumi is on. A drive + or an order for the arm takes it down (lower, a task), the switch turned off too. False when the arm is refused.""" + if _someone_within(IDLE_CLEAR_M) or arm_route.where() != _rest_arm(): + return True # someone near the arm, or the arm still on its way to rest: next time + try: + route, _ = wave.plan() + except Exception as e: + log(f"no idle wave: {e.args[0] if isinstance(e, wave.WaveError) else repr(e)}") + return False + log("nothing asked for a while: the hand up for the passers-by") + _busy.set() + try: + _up(route) + _st.update(up=True, held=True, held_at=0.0) + _idle_swings() + finally: + _busy.clear() + return True + + +def _idle_swings(): + """IDLE_SWINGS swings of the held hand; someone waving back (greeted as always, step) or talking to Lumi (the hand + stays up, still) ends them.""" + for _ in range(IDLE_SWINGS): + if _waver(): + log("idle wave: someone waves back") + _st["last_wave"] = 0.0 + return + if not (_free() and _idle()): + log("idle wave: someone talks to me, the hand stays up") + return + _swing() + + +def _down(waist=None): + """Waist to its rest (`waist` deg from the front, else _rest()) first, the way it came with the hand up (in `look` + the arm sticks out further and the same turn back can be blocked), then the arm slowly down (_rest_arm) and the + head to rest.""" from tasks import fetch _busy.set() try: if _st["up"] and arm_route.where() is None: _settle() # mid-swing: the queued swings end first fetch._stop.clear() - _st["waist_out"] = not fetch._waist_to(0.0, in_place=True) + _st["waist_out"] = not fetch._waist_to(_rest() if waist is None else waist, in_place=True) if arm_route.where() in arm_route.WAVE_POSES: - arm_route.move(arm_route.plan(arm_route.HOME), DOWN_SPEED) + arm_route.move(arm_route.plan(_rest_arm()), DOWN_SPEED) _turn_head(0.0, head.HEAD_REST_PITCH) log("arm down") finally: @@ -322,7 +383,8 @@ def _down(): _st = {"up": False, "last_wave": 0.0, "lang": 0, "next_joke": 0.0, "free": False, "free_at": 0.0, "refused_until": 0.0, "waist_out": False, "follow_at": 0.0, "swing_at": 0.0, - "swing_end": 0.0} # swing_end: when the swings sent so far should be done # waist_out: the way back to the front was blocked, tried again later + "swing_end": 0.0, "idle_at": 0.0, "held": False, "held_at": 0.0} # held: the hand kept up on the charger + # (_idle_wave) # swing_end: when the swings sent so far should be done # waist_out: the way back to the front was blocked, tried again later def step(now): @@ -331,12 +393,12 @@ def step(now): if not _on(): if st["up"]: _down() - st["up"] = False + st["up"] = st["held"] = False return if now - st["free_at"] > FREE_EVERY_S: st["free"], st["free_at"] = _free(), now if not st["free"]: # the assistant or a task has the robot: it takes the arm from here - st["up"] = False + st["up"] = st["held"] = False _busy.clear() return w = _waver() @@ -350,10 +412,17 @@ def step(now): st["up"] = _greet(w, st["lang"]) if not st["up"]: st["refused_until"] = now + REFUSED_S + elif not w and now > st["refused_until"] and now - max(st["idle_at"], st["last_wave"]) > IDLE_WAVE_EVERY_S: + if not _idle(): + st["idle_at"] = now - IDLE_WAVE_EVERY_S + IDLE_RETRY_S # asked again in IDLE_RETRY_S, not every step + elif not _idle_wave(): + st["refused_until"] = now + REFUSED_S + else: + st["idle_at"] = now # its swings IDLE_WAVE_EVERY_S apart elif not w and st["waist_out"] and now > st["refused_until"]: from tasks import fetch fetch._stop.clear() - st["waist_out"] = not fetch._waist_to(0.0, in_place=True) + st["waist_out"] = not fetch._waist_to(_rest(), in_place=True) st["refused_until"] = now + REFUSED_S elif w: if new: @@ -371,6 +440,19 @@ def step(now): st["swing_at"] = now + SWING_POLL_S if not _swing_on(now): st["up"] = False # someone moved the arm: the next wave starts from where it is + elif st["held"]: # held up on the charger: swings now and then while nobody talks to Lumi + if now - st["idle_at"] > IDLE_WAVE_EVERY_S and now - st["held_at"] > IDLE_RETRY_S: + st["held_at"] = now + if _idle(): + if arm_route.where() in (wave.START, wave.SWING): + _busy.set() + try: + _idle_swings() + finally: + _busy.clear() + st["idle_at"] = now + else: # an order moved the arm meanwhile: not held any more + st["up"] = st["held"] = False elif now - st["last_wave"] > HOLD_S: _down() st["up"] = False @@ -399,10 +481,37 @@ def _run(): _stopped(e) -def start(on, free, off): - """`on()`: the switch is on; `free()`: nothing else has the robot; `off()`: turn the switch off.""" - global _on, _free, _off - _on, _free, _off = on, free, off +def up(): + """The hand is up for a greeting (or was, when someone else took the robot meanwhile).""" + return _st["up"] + + +def lower(wait_s=10.0): + """A drive or a turn takes the robot (lumi.waist_home): the way up and the queued swings end, then a hand left in + a wave pose comes down to look, the waist to the front. Never driven with the hand up. Nothing when the greeting + does not run in this process (start() not called).""" + if _on is None: + return + end = time.time() + wait_s + while _busy.is_set() and time.time() < end: + time.sleep(0.05) + if _st["swing_end"] > time.time() - SWING_S: + _settle() # swings sent without waiting may still run + _st["swing_end"] = 0.0 + _st["up"] = arm_route.where() in arm_route.WAVE_POSES + if _st["up"]: + _down(0.0) # a drive follows: the waist to the front + _st["up"] = _st["held"] = False + + +def start(on, free, off, free_every=FREE_EVERY_S, rest=None, rest_arm=None, idle=None): + """`on()`: the switch is on; `free()`: nothing else has the robot (asked every `free_every` s); `off()`: turn the + switch off; `rest()`: the waist's angle when the hand is down (the front unless given); `rest_arm()`: the arm's + pose then (arm_route.rest_pose unless given); `idle()`: nothing asked for a while, a wave every IDLE_WAVE_EVERY_S + (never unless given).""" + global _on, _free, _off, FREE_EVERY_S, _rest, _rest_arm, _idle + _on, _free, _off, FREE_EVERY_S = on, free, off, free_every + _rest, _rest_arm, _idle = rest or _rest, rest_arm or _rest_arm, idle or _idle for cam in CAMERAS: threading.Thread(target=_watch, args=(cam,), daemon=True).start() threading.Thread(target=_run, daemon=True).start() diff --git a/tests/test_command_box.py b/tests/test_command_box.py index dcc0977..3ba8007 100644 --- a/tests/test_command_box.py +++ b/tests/test_command_box.py @@ -522,3 +522,23 @@ ko = sum(1 for t, _, _ in READ if brain.HANGUL.search(t)) print(f"{len(READ) - len(bad)}/{len(READ)} read right ({ko} Korean, {len(READ) - ko} English)") assert not bad print("command box ok") + +# ---------- a bag on the hooks: "give me the bag" holds it out at once (the gripper holds nothing), a new bag order +# is still a mission ---------- +L.bag_on = lambda: True +L.reach_out = lambda held: rec("reach", held) +L.held_now = lambda look=False: look and (_ for _ in ()).throw(AssertionError("the arm moved to look at the hand")) +for text in ("give me the bag", "Lumi, give me the bag please", "hand me the bag", "give it to me", "가방 줘", "가방 주세요"): + assert voice(text) == ("reach", False), (text, got_voice) +assert voice("take the bag to p1")[0] == "steps" and got_voice[0][1][0] == {"do": "arm", "pose": "bag"}, got_voice +L.bag_on, L.held_now = (lambda: False), (lambda look=False: False) +assert voice("give me the bag") != ("reach", False) # no bag: not this way +print("bag give ok") + +# "thanks" after the bag was held out: reach_done folds (arm_pose "fold"), which with a bag on takes it off (look) +offs = [] +real_off, fetch.bag_off = fetch.bag_off, lambda: offs.append("off") +L.bag_on = lambda: True +assert lumi.Lumi.arm_pose(L, "fold") and offs == ["off"], offs +fetch.bag_off = real_off +print("bag fold ok") diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 9d26b13..b539de7 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -1381,3 +1381,31 @@ fetch.skills.cancel = fetch.agv.cancel = lambda: None fetch.stop() assert fetch.state()["status"] == "stopped" and fetch.state()["log"][-1].endswith("stopped"), fetch.state() print("stale run stopped ok") + +# ---- a bag on the hooks: drives keep the arm in the bag pose; the step waits for the bag once; fold takes it off ---- +went, said = [], [] +fetch._pose = lambda name, holding=False, leaf=False: went.append(name) +fetch._set(holding=False, bag=False) +fetch._drive_pose() +assert went == [fetch.arm_route.rest_pose()], went # the empty arm drives at rest +went.clear() +real_wait, fetch._stop = fetch._stop, threading.Event() +fetch.BAG_HANG_S = 0.01 +fetch._arm("bag", lambda en, ko: said.append(en)) +assert went == [fetch.BAG_POSE] and fetch.state()["bag"] and said == [fetch.BAG_HANG_SAY[0]], (went, said) +fetch._drive_pose() +fetch._arm("bag", lambda en, ko: said.append(en)) # hung already: no asking again +assert went == [fetch.BAG_POSE, fetch.arm_route.rest_pose(), fetch.BAG_POSE] and len(said) == 1, (went, said) # drives at + # rest with the bag too; hung already: no asking again +fetch._set(holding=True) +try: + fetch._arm("bag") + raise AssertionError("bag pose with a cup in the hand") +except fetch.FetchError: + pass +fetch._set(holding=False) +went.clear() +fetch.bag_off() +assert went == [fetch.arm_route.rest_pose()] and not fetch.state()["bag"], went +fetch._stop = real_wait +print("bag ok") diff --git a/tests/test_look_me.py b/tests/test_look_me.py index 952fcd2..593e3c5 100644 --- a/tests/test_look_me.py +++ b/tests/test_look_me.py @@ -8,6 +8,7 @@ from assistant import lumi turns, pitches = [], [] lumi.head.turn = lambda yaw, pitch=None, **k: (turns.append(round(yaw)), pitches.append(pitch)) lumi.LOOK_ME_SETTLE_S = 0.0 +lumi.on_charger = lambda: False # off the charger: the body may turn (it asks the base) lumi.waist_turned = lambda: 0.0 # the waist at the front unless a case says otherwise diff --git a/tests/test_mission_stop.py b/tests/test_mission_stop.py index 12cdf4c..a426cd4 100644 --- a/tests/test_mission_stop.py +++ b/tests/test_mission_stop.py @@ -122,6 +122,19 @@ with os.fdopen(fd, "w") as f: L.poll_commands() os.remove(lumi.CMD_FILE) assert "stop" in done and run["status"] == "stopped" and L.mission_hold is None, done +# 19:47 the dashboard's stop while following (no task runs): following ends too, not only the task +from tasks import follow +ended, real = [], (follow.stop, fetch.stop) +follow.stop, fetch.stop = (lambda: ended.append("follow")), (lambda: ended.append("task")) +L = fresh() +L.cmd_id, L.modes = 0, type("Modes", (), {"patrol": True})() +fd, lumi.CMD_FILE = tempfile.mkstemp(suffix=".json") +with os.fdopen(fd, "w") as f: + json.dump({"id": 1, "time": time.time(), "cmd": "fetch_stop"}, f) +L.poll_commands() +os.remove(lumi.CMD_FILE) +follow.stop, fetch.stop = real +assert ended == ["follow", "task"], ended # 16:56:38 "One more." right after "look left": further left; also "a bit more", "더", after a lift diff --git a/tests/test_steps.py b/tests/test_steps.py index 981cd30..c9ecdfd 100644 --- a/tests/test_steps.py +++ b/tests/test_steps.py @@ -308,6 +308,23 @@ assert llm_says("go to p2, then chill there and do whatever the visitors tell yo {"do": "wait", "s": None, "until": "instruction"}])[0] == S("go p2 | wait order") print("steps wait ok") +# ---- a bag hung on the gripper's hooks (owner, 2026-11-04): the arm to its bag pose, then the drive ---- +for text, want in (("take the bag to p1", "arm bag | go p1"), ("Lumi, take this bag to p2", "arm bag | go p2"), + ("carry my bag to p4", "arm bag | go p4"), ("take the bag home", "arm bag | go home"), + ("take the bag and go to p1", "arm bag | go p1"), ("hold the bag", "arm bag"), + ("here's the bag", "arm bag"), ("가방 들어", "arm bag"), ("가방 좀 받아 줘", "arm bag"), + ("가방 p1으로 가져가", "arm bag | go p1"), ("쇼핑백 p3까지 옮겨 줘", "arm bag | go p3"), + ("가방 홈으로 가져가 줘", "arm bag | go home"), ("take the cup to p1", "pick cup | go p1")): + got, unread = steps.rules(text, M) + assert not unread and got == [short(x) for x in want.split(" | ")], (text, got, unread) +for text in ("I have a bag", "what a nice bag", "where is my bag?", "the bag is heavy", "가방 p99로 가져가"): + got, unread = steps.rules(text, M) + assert unread or not got, (text, got) # no order, or a place not on the map: nothing runs +bag = [short("arm bag"), short("go p1")] +assert steps.check(bag, False, M) == [] and steps.check(bag, True, M) # never with a cup in the hand +assert steps.describe(bag) == "Hold my hand ready for the bag, then go to p1." and steps.is_mission(bag) +print("steps bag ok") + # ---- three or four steps in one breath on the conference map (tests/steps_cases7.py) ---- from assistant import brain from tests import steps_cases7 as c7 diff --git a/tests/test_switches.py b/tests/test_switches.py index e56049a..60e0ab9 100644 --- a/tests/test_switches.py +++ b/tests/test_switches.py @@ -177,12 +177,7 @@ L.act("go_to", "p3") assert moved == ["start_trip"] follow.stop, fetch.stop = real_follow_stop, real_fetch_stop -# ---------- "reach out to me": toward the person; the waist turns to them with Greeter only too (the base stays) ---- -assert lumi.reach_turn(None) is None and lumi.reach_turn(8.0) == 0.0 -assert lumi.reach_turn(-35.0) == -35.0 and lumi.reach_turn(35.0) == 35.0 -# the hand held out 21 deg right of the waist's front (give): the waist turns until the hand, not its front, points -# at the person (live 2026-10-28: turned straight at them, the hand went out beside them) -assert lumi.reach_turn(36.0, -21.0) == 57.0 and lumi.reach_turn(-15.0, -21.0) == 0.0 and lumi.reach_turn(0.0, -21.0) == 21.0 +# ---------- "reach out to me": at once the way the waist faces, wherever the person is (owner, 2026-11-04) ---------- reached, looked = [], [] real_reach, real_bearing = fetch.reach, fetch.give_bearing fetch.reach = lambda angle=0.0, say=None, look=None: reached.append(angle) or looked.append(look) @@ -190,43 +185,21 @@ fetch.give_bearing = lambda: 0.0 L.fetch_finish = lambda how, **k: moved.append(how) L.skill_thread, L.voice_trusted = None, False person = types.SimpleNamespace(angle=35.0, distance=1.0, id=8) -L.vision = types.SimpleNamespace(present=lambda t: False, near_angle=lambda a, d=25: None, only_person=lambda: person, - visible=lambda t: False, only_seen=lambda: person) +L.vision = types.SimpleNamespace(present=lambda t: True, near_angle=lambda a, d=25: None, only_person=lambda: person, + visible=lambda t: True, only_seen=lambda: person) L.turn_head = lambda yaw=None, pitch=None, force=False: moved.append(("head", yaw)) -for patrol, angle, want in ((False, 35.0, [35.0]), (True, 35.0, [35.0]), (False, -40.0, [-40.0]), (False, -8.0, [0.0]), - (True, -8.0, [0.0])): - L.modes.patrol, person.angle = patrol, angle - reached.clear(), said.clear(), moved.clear() - got = L.reach_out(False) - # a waist turn takes the head onto them (fetch._waist_to look); a head turn here raced it (looked away live) - head_cmds = [] if want[0] else [("head", lumi.HEAD_SIGN * angle)] - assert got and reached == want and moved == head_cmds and not said, (patrol, angle, reached, moved, said) -fetch.give_bearing = lambda: -21.0 # the hand right of the front: turned further, the head on them -person.angle = 36.0 -reached.clear(), looked.clear() -assert L.reach_out(False) and reached == [57.0] and looked == [36.0], (reached, looked) -person.angle, person.distance = 0.0, 3.0 # far away: come to them first, then reach came = [] -L.vision.present = lambda t: True -L.come_to = lambda t: came.append(t.id) or setattr(t, "distance", 1.1) -reached.clear(), said.clear() -assert L.reach_out(False) and came == [8] and reached == [21.0], (came, reached) -person.distance, L.modes.patrol = 3.0, False # far, Greeter only (the base stays): asked to come, no reach -reached.clear(), said.clear(), came.clear() -assert L.reach_out(False) is None and not reached and not came and said == [lumi.COME_CLOSER_SAY[0]], (said, reached) -L.modes.patrol, person.distance = True, 1.0 -fetch.give_bearing = lambda: 0.0 -L.turn_head = lambda *a, **k: moved.append("head") -seen_vision, L.vision = L.vision, None # nobody seen, the voice's direction not trusted: ask -reached.clear(), said.clear() -assert L.reach_out(False) is None and not reached and said == [lumi.STAND_IN_FRONT_SAY[0]] -L.voice_trusted, L.voice_angle, L.modes.patrol = True, -50.0, True # heard from the right, nobody seen there: -L.find_caller = lambda angle, trusted: None # no reach to a bare voice direction (it was -reached.clear(), said.clear() # 166 deg off, 2026-10-28) -assert L.reach_out(False) is None and not reached and said == [lumi.STAND_IN_FRONT_SAY[0]] -L.find_caller = lambda angle, trusted: person # someone seen there: to them -person.angle, L.vision = -50.0, seen_vision -assert L.reach_out(False) and reached == [-50.0] +L.come_to = lambda t: came.append(t.id) +for patrol, angle, dist in ((False, 35.0, 1.0), (True, -40.0, 1.0), (True, 0.0, 25.9), (False, 0.0, 3.0)): + L.modes.patrol, person.angle, person.distance = patrol, angle, dist # (25.9 m: a crowd, 2026-11-04) + reached.clear(), said.clear(), moved.clear(), came.clear() + assert L.reach_out(False) and reached == [0.0] and not moved and not came and not said, (patrol, angle, reached, moved, said) +L.vision = None # nobody seen at all: the same +reached.clear() +assert L.reach_out(False) and reached == [0.0] +L.modes.patrol, person.distance, person.angle = True, 1.0, 35.0 +L.vision = types.SimpleNamespace(present=lambda t: True, near_angle=lambda a, d=25: None, only_person=lambda: person, + visible=lambda t: True, only_seen=lambda: person) moved.clear(), reached.clear(), said.clear() L.fetch_status = lambda: "holding" real_check, fetch.check_hand = fetch.check_hand, lambda: True # the hand checked: something is in it @@ -242,6 +215,7 @@ fetch.reach, fetch.give_bearing = real_reach, real_bearing # ---------- the waist back to the front (waist_home): in place, Greeter only too; never with the arm out or a task ---- real = {n: getattr(fetch, n) for n in ("_waist_turn", "state", "_at_pose", "_waist_to")} +real_rest, lumi.arm_route.rest_pose = lumi.arm_route.rest_pose, lambda holding=False: "look" if holding else "rest" calls = [] fetch._waist_to = lambda rel, in_place=False: calls.append((rel, in_place)) or True fetch.state = lambda: {"status": "idle"} @@ -256,10 +230,27 @@ fetch._at_pose = lambda name: False # the hand held out (a assert lumi.waist_home("test") is False and calls == [] fetch._at_pose = lambda name: True assert lumi.waist_home("test") and calls == [(0.0, True)] # in place: also with Patrol off (stay_put) +calls.clear() +fetch._at_pose = lambda name: name == "look" # in look on the charger (not rest): it turns too +assert lumi.waist_home("test") and calls == [(0.0, True)], calls fetch._waist_to = lambda rel, in_place=False: False # the arm's sweep is not clear assert lumi.waist_home("test") is False +# a drive or turn (fold): the empty arm goes to rest first wherever it is, also with the waist at the front already +went = [] +real_plan, real_move, real_lower = lumi.arm_route.plan, lumi.arm_route.move, lumi.wave_greet.lower +lumi.arm_route.plan, lumi.wave_greet.lower = (lambda target, holding=False: [target]), (lambda: None) +lumi.arm_route.move = lambda seq, speed=None, holding=False: went.append(seq[-1]) +fetch._waist_turn, fetch._at_pose, fetch.state = (lambda: 0.4), (lambda name: name == "look"), (lambda: {"status": "idle"}) +assert lumi.waist_home("drive", fold=True) and went == ["rest"], went +went.clear() +fetch.state = lambda: {"status": "idle", "holding": True} # a cup: look (drive_ready), never rest +real_ready, fetch.drive_ready = fetch.drive_ready, lambda: went.append("drive_ready") +assert lumi.waist_home("drive", fold=True) and went == ["drive_ready"], went +fetch.drive_ready = real_ready +lumi.arm_route.plan, lumi.arm_route.move, lumi.wave_greet.lower = real_plan, real_move, real_lower for n, f in real.items(): setattr(fetch, n, f) +lumi.arm_route.rest_pose = real_rest # ---------- every drive and base turn starts with the waist at the front ---------- order = [] @@ -302,5 +293,73 @@ with tempfile.TemporaryDirectory() as tmp: m = lumi.Modes(types.SimpleNamespace(patrol=None, no_arm=False)) assert (m.greeter, m.patrol, m.wave) == (True, True, False) and not hasattr(m, "drive"), vars(m) +# ---------- on the charger with nothing to do: the arm slowly from rest to look, the waist to HOME_WAIST_DEG; off +# it, with a drive running, a task, a cup or the hand out: nothing moves ---------- +turned, arm_at = [], {"now": "rest"} +real_waist_to, real_at_pose, real_state = fetch._waist_to, fetch._at_pose, fetch.state +real_plan, real_move, real_rest = lumi.arm_route.plan, lumi.arm_route.move, lumi.arm_route.rest_pose +fetch._waist_to = lambda rel, in_place=False, look=None: turned.append(("waist", rel)) or True +fetch._at_pose = lambda name: name == arm_at["now"] +lumi.arm_route.rest_pose = lambda holding=False: "rest" +lumi.arm_route.plan = lambda target, holding=False: [target] +lumi.arm_route.move = lambda seq, speed=None, holding=False: turned.append(("arm", seq[-1], speed)) or arm_at.update(now=seq[-1]) +fetch.state = lambda: {"status": "idle"} +for st, at, want in (({"charge_state": True, "move_status": "succeeded"}, "rest", + [("arm", "look", lumi.HOME_ARM_SPEED), ("waist", lumi.HOME_WAIST_DEG)]), + ({"charge_state": True, "move_status": "idle"}, "look", [("waist", lumi.HOME_WAIST_DEG)]), + ({"charge_state": True, "move_status": "running"}, "rest", []), # leaving the charger + ({"charge_state": False, "move_status": "idle"}, "rest", []), # not at home + ({"charge_state": True, "move_status": "idle"}, "give", [])): # the hand held out + lumi.agv.status, arm_at["now"], turned[:] = (lambda st=st: st), at, [] + assert lumi.waist_home_rest("test") == bool(want) and turned == want, (st, at, turned) +lumi.agv.status = lambda: {"charge_state": True, "move_status": "idle"} +for task in ({"status": "running"}, {"status": "idle", "holding": True}): # a task, a cup in the hand + fetch.state, arm_at["now"], turned[:] = (lambda t=task: t), "rest", [] + assert not lumi.waist_home_rest("test") and turned == [], task +fetch._waist_to, fetch._at_pose, fetch.state = real_waist_to, real_at_pose, real_state +lumi.arm_route.plan, lumi.arm_route.move, lumi.arm_route.rest_pose = real_plan, real_move, real_rest + +# ---------- on the charger the body stays turned to its rest: someone speaking or calling turns the head only ------ +moves = [] +real_on, real_turned, real_home2 = lumi.on_charger, lumi.waist_turned, lumi.waist_home +lumi.on_charger, lumi.waist_turned = (lambda: True), (lambda: 86.0) +lumi.waist_home = lambda why, fold=False: moves.append(("waist", why)) or True +L.turn_head = lambda yaw=None, pitch=None, force=False: moves.append(("head", yaw)) +lumi.Lumi.face(L, types.SimpleNamespace(angle=-30.0)) +lumi.Lumi.look_toward(L, 170.0) # a voice behind: no base turn, the head as far as it goes +assert moves == [("head", lumi.HEAD_SIGN * -30.0), ("head", lumi.HEAD_SIGN * lumi.head.YAW_LIMIT)], moves +lumi.on_charger, lumi.waist_turned, lumi.waist_home = real_on, real_turned, real_home2 + +# ---------- on the charger, nobody talking: the head on the nearest passer-by, left and right, not too often ---------- +moves = [] +real_on, real_busy = lumi.on_charger, lumi.wave_greet.busy +lumi.on_charger, lumi.wave_greet.busy = (lambda: True), (lambda: False) +L.turn_head = lambda yaw=None, pitch=None, force=False: moves.append(yaw) +L.look_held, L.det_yaw = (lambda: False), (lambda: 0.0) +L.vision = types.SimpleNamespace(seen=lambda m: [(40.0, 3.5), (-25.0, 1.8)]) +L.passer_at = 0.0 +L.watch_passers() +assert moves == [lumi.HEAD_SIGN * -25.0], moves # the nearest one +L.watch_passers() +assert len(moves) == 1 # not again within PASSER_EVERY_S +L.passer_at, L.det_yaw = 0.0, (lambda: lumi.HEAD_SIGN * -25.0) +L.watch_passers() +assert len(moves) == 1 # looking at them already +L.passer_at, lumi.on_charger = 0.0, (lambda: False) +L.watch_passers() +assert len(moves) == 1 # off the charger: never +lumi.on_charger, lumi.wave_greet.busy = real_on, real_busy + +# ---------- "look left" turns the head there at once: no turn to the speaker first (one body move at a time) ---------- +moves = [] +L.vision, L.markers, L.current = types.SimpleNamespace(only_person=lambda: None, present=lambda t: False), ["p1"], None +L._who_spoke = lambda u, text: moves.append("who") +L.turn_head = lambda yaw=None, pitch=None, force=False: moves.append(yaw) +for text in ("Lumi, look at the right side.", "Look at the left side.", "왼쪽 봐", "look up"): + lumi.Lumi.who_spoke(L, object(), text) +assert moves == [], moves +lumi.Lumi.who_spoke(L, object(), "look at me") # "look at me" needs the voice: as before +assert moves == ["who"], moves + print(f"switches ok: {len(BASE)} base phrases refused with Greeter only, {len(IN_PLACE)} in place done; " "arm off asks; Patrol allows all; stop always") diff --git a/tests/test_wake.py b/tests/test_wake.py index e1b053b..9da7907 100644 --- a/tests/test_wake.py +++ b/tests/test_wake.py @@ -32,6 +32,7 @@ lumi.ears.understood = lambda lp: True lumi.time.sleep = lambda s: None lumi.waist_turned = lambda: 0.0 # the waist at the front (it reads the body) lumi.waist_home = lambda why, fold=False: True +lumi.wave_greet_on = lumi.on_charger = lambda: False # the dashboard's switch file and the base: not this test's M = ["home", "dock2"] @@ -76,6 +77,9 @@ class Vision: # people in the greeting zone def anyone_near(self): return bool(self.tracks) + def seen(self, max_m=lumi.STAY_MAX): + return [(t.angle, t.distance) for t in self.tracks if t.distance <= max_m] + def nearest_greeted(self): return next((t for t in self.tracks if t.greeted), None) diff --git a/tests/test_wave_greet.py b/tests/test_wave_greet.py index 6eb77c3..6a0a923 100644 --- a/tests/test_wave_greet.py +++ b/tests/test_wave_greet.py @@ -206,6 +206,81 @@ switch["free"] = False run(500.0, 505.0) assert done == [] and not g.busy(), done +# a drive starts (lumi.waist_home) with the hand up mid-swing: the swings end, then the arm down before the drive +fresh() +waver["w"] = W(0.0) +run(550.0, 550.0) +g._st["swing_end"] = 1e12 # a swing still queued +switch["free"] = False +run(550.5, 550.5) # the drive took the robot: the wave greeting lets go +done.clear() +g._rest = lambda: 86.0 # on the charger the waist rests turned; a drive still wants the front +g.lower() +assert done == ["settle", "waist +0 look None", "down normal", "head +0 rest"] and arm["at"] == "look", done +arm["at"] = "wave_start" # nobody waves any more on the charger: down to the waist's rest there +done.clear() +g._down() +assert done[:2] == ["waist +86 look None", "down normal"], done +g._rest = lambda: 0.0 +done.clear() +g.lower() # the hand is down: nothing moves +assert done == [], done + +# nothing asked for a while on the charger (_idle): the hand goes up and stays up, no words; 2 swings every +# IDLE_WAVE_EVERY_S while nobody talks; a call stops them (the hand still up); a drive brings it down (lower); someone +# waving is greeted as always +fresh() +waver["w"] = None +g._idle, g._rest_arm = (lambda: True), (lambda: "look") +g._someone_within = lambda m: True # someone right by the arm: no idle wave, tried again later +g._st["idle_at"] = 0.0 +run(690.0, 690.0) +assert done == [], done +g._someone_within = lambda m: False +arm["at"] = "rest" # the arm still on its way to look on the charger: not yet +g._st["idle_at"] = 0.0 +run(691.0, 691.0) +assert done == [], done +arm["at"] = "look" +g._st["idle_at"] = 700.0 # the last idle wave +run(700.0, 700.0 + g.IDLE_WAVE_EVERY_S - 1) +assert done == [] and said == [], done # not before IDLE_WAVE_EVERY_S +run(700.0 + g.IDLE_WAVE_EVERY_S + 0.5, 700.0 + g.IDLE_WAVE_EVERY_S + 0.5) +assert done == ["up route", "swing", "swing"] and said == [] and g._st["up"] and g._st["held"], (done, said) +done.clear() +t = 700.0 + g.IDLE_WAVE_EVERY_S + 1 +run(t, t + g.IDLE_WAVE_EVERY_S - 2) +assert done == [], done # up, still, until the next swings +run(t + g.IDLE_WAVE_EVERY_S, t + g.IDLE_WAVE_EVERY_S + 200) +assert done.count("swing") >= 2 * 9 and "down normal" not in done and "up route" not in done, done # never down +talk = {"on": True} # someone talks to Lumi: no swings, the hand stays up, still +g._idle = lambda: not talk["on"] +done.clear() +run(1000.0, 1100.0) +assert done == [] and g._st["up"], done +talk["on"] = False # quiet again: the swings go on +run(1101.0, 1102.0) +assert done == ["swing", "swing"], done +done.clear() +g.lower() # a drive: down to the front first +assert "down normal" in done and not g._st["up"] and not g._st["held"], done +g._idle = lambda: True +done.clear() +said.clear() # someone waves back during an idle wave: greeted as always, +real_waver, g._waver = g._waver, (lambda: W(20.0)) # the hand stays up and swings on +arm["at"], g._st["idle_at"], g._st["up"] = "look", 0.0, False +run(760.0, 760.0) +assert "up route" in done and "down normal" not in done and g._st["up"], done +run(760.5, 762.0) +assert said and said[0] in sum(g.wave_lines.INTRO + g.wave_lines.GREET, ()) and done.count("swing") >= 1, (done, said) +g._waver = real_waver +g._st["up"] = g._st["held"] = False +done.clear() +g._idle = lambda: False # someone talks to Lumi, or off the charger: no idle waves +run(800.0, 900.0) +assert done == [], done +g._idle, g._rest_arm = (lambda: False), g.arm_route.rest_pose + # Lumi introduces itself once per person: the same person waving again (after NEW_WAVE_S) gets a hello, someone # else an introduction, and the first person too once they were out of view for GONE_S fresh()