Arm switched off: clear message, drives / turns / follow work without an enabled arm; no goodbye into an empty room; "look behind" stays 60 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 18:42:29 +09:00
co-authored by Claude Opus 5.5
parent 48724cac15
commit 50bee0b0c3
6 changed files with 85 additions and 36 deletions
+29 -11
View File
@@ -185,7 +185,7 @@ DONE_TALK = re.compile(r"\b(bye+|goodbye|see you|never ?mind|nothing|that'?s (al
TALK_RECENT_S = 20.0 # s; someone spoke with Lumi this recently: what they say next is to Lumi too TALK_RECENT_S = 20.0 # s; someone spoke with Lumi this recently: what they say next is to Lumi too
ENOUGH = re.compile(r"\b(enough|no more)\b|그만해|됐어 ?그만", re.I) # with stop_order: ends a mission at once ENOUGH = re.compile(r"\b(enough|no more)\b|그만해|됐어 ?그만", re.I) # with stop_order: ends a mission at once
ASK_NOT_ORDER = re.compile(r"\b(can|could|would|will) you\b|\bplease\b|줄래|줄 ?수|해 ?줘|주세요|(?<!뭐 )줘", re.I) # a request ASK_NOT_ORDER = re.compile(r"\b(can|could|would|will) you\b|\bplease\b|줄래|줄 ?수|해 ?줘|주세요|(?<!뭐 )줘", re.I) # a request
LOOK_KEEP_S = 60.0 # s after a "look left" the head is not turned back ahead when the person leaves the view LOOK_KEEP_S = 60.0 # s after a "look left" (and after the last word or command since) the head stays there
COMPANY_Q = re.compile(r"\b(cutshion|barista robot|drawing robot|your (maker|makers|company|ceo|price)|(this|the|that|what|which) company|" COMPANY_Q = re.compile(r"\b(cutshion|barista robot|drawing robot|your (maker|makers|company|ceo|price)|(this|the|that|what|which) company|"
r"ceo of (it|this|the company)|founder of (it|this)|mega ?coffee|" r"ceo of (it|this|the company)|founder of (it|this)|mega ?coffee|"
r"sonovictus|omron|borgwarner|bogate|cnt tech|seed round|target market|business model|(your|cutshion'?s?) awards?|how much (do|does) (you|it|this|lumi) cost)\b|" r"sonovictus|omron|borgwarner|bogate|cnt tech|seed round|target market|business model|(your|cutshion'?s?) awards?|how much (do|does) (you|it|this|lumi) cost)\b|"
@@ -544,6 +544,10 @@ class Vision(threading.Thread):
near = [t for t in self.tracks if t.distance <= 3.0] near = [t for t in self.tracks if t.distance <= 3.0]
return near[0] if len(near) == 1 else None return near[0] if len(near) == 1 else None
def anyone_near(self):
with self.lock:
return any(t.distance <= STAY_MAX for t in self.tracks)
def nearest_greeted(self): def nearest_greeted(self):
with self.lock: with self.lock:
here = [t for t in self.tracks if t.greeted and t.distance <= STAY_MAX] here = [t for t in self.tracks if t.greeted and t.distance <= STAY_MAX]
@@ -738,6 +742,11 @@ class Lumi:
self._markers = names self._markers = names
# ---------- actions ---------- # ---------- actions ----------
def look_held(self):
"""After a "look left / behind" the head stays there until LOOK_KEEP_S pass with nothing said or asked."""
return time.time() - max(getattr(self, "looked_at", 0.0), getattr(self, "last_activity", 0.0)) < LOOK_KEEP_S \
if getattr(self, "looked_at", 0.0) else False
def turn_head(self, yaw=None, pitch=None): def turn_head(self, yaw=None, pitch=None):
def run(): def run():
try: try:
@@ -2155,16 +2164,20 @@ class Lumi:
self.voice_until = time.time() + VOICE_SESSION_S self.voice_until = time.time() + VOICE_SESSION_S
self.last_activity = time.time() self.last_activity = time.time()
def end_conversation(self, text=None): def end_conversation(self, text=None, quiet=False):
"""Say a goodbye that fits the conversation, forget it, and drive on if Lumi was on the way.""" """Say a goodbye that fits the conversation (none when `quiet`: nobody to say it to), forget it, and drive on if
bye = self.brain.farewell(text, self.lang) Lumi was on the way."""
log(f" goodbye: {bye}") bye = "" if quiet else self.brain.farewell(text, self.lang)
if text and BYE_WAVE.search(text) and self.current is not None and self.vision and self.vision.present(self.current): if bye:
log(f" goodbye: {bye}")
if bye and text and BYE_WAVE.search(text) and self.current is not None and self.vision and self.vision.present(self.current):
threading.Thread(target=self.wave, kwargs={"quiet": True}, daemon=True).start() # only if safe: else no arm threading.Thread(target=self.wave, kwargs={"quiet": True}, daemon=True).start() # only if safe: else no arm
mouth.say(bye, abort=self.speak_abort) if bye:
mouth.say(bye, abort=self.speak_abort)
self.current, self.voice_until, self.closing_pending = None, 0.0, None self.current, self.voice_until, self.closing_pending = None, 0.0, None
self.brain.reset() self.brain.reset()
self.turn_head(0, 0) if not self.look_held(): # "look behind": the head stays there a while (LOOK_KEEP_S)
self.turn_head(0, 0)
if self.traveling(): if self.traveling():
log(" conversation over - driving on") log(" conversation over - driving on")
self.patrol.wait_until = time.time() + 0.5 self.patrol.wait_until = time.time() + 0.5
@@ -2728,7 +2741,7 @@ class Lumi:
else: else:
# often still there, out of the frame (beside the arm): keep listening without the wake word # often still there, out of the frame (beside the arm): keep listening without the wake word
# for a while, like a conversation started by voice. After "look left" the head stays there # for a while, like a conversation started by voice. After "look left" the head stays there
if time.time() - getattr(self, "looked_at", 0.0) > LOOK_KEEP_S: if not self.look_held():
self.turn_head(0, 0) self.turn_head(0, 0)
self.voice_until = time.time() + VOICE_SESSION_S self.voice_until = time.time() + VOICE_SESSION_S
self.last_activity, self.prompts = time.time(), 0 self.last_activity, self.prompts = time.time(), 0
@@ -2747,9 +2760,14 @@ class Lumi:
if self.talk_turn(): if self.talk_turn():
self.voice_until = max(self.voice_until, time.time() + VOICE_SESSION_S) self.voice_until = max(self.voice_until, time.time() + VOICE_SESSION_S)
return return
if getattr(self, "looked_at", 0.0) and not self.look_held():
log(f" nothing said for {LOOK_KEEP_S:.0f} s after a look: head ahead")
self.looked_at = 0.0
self.turn_head(0, 0)
if self.voice_until: if self.voice_until:
log("voice conversation over (silence)") talked = bool(self.brain.history) and self.vision is not None and self.vision.anyone_near()
self.end_conversation(None) log(f"voice conversation over (silence){'' if talked else ', nobody here or nothing said: no goodbye'}")
self.end_conversation(None, quiet=not talked)
if self.check_wake(): # "Hi Lumi" works in every mode if self.check_wake(): # "Hi Lumi" works in every mode
return return
if self.patrol: if self.patrol:
+4
View File
@@ -57,6 +57,7 @@ NEAR_HEAD = ("That would bring my hand too close to my head, so I won't move my
SPILL = ("I can't move my arm there without spilling it.", "쏟지 않고는 팔을 거기로 움직일 수 없어요.") SPILL = ("I can't move my arm there without spilling it.", "쏟지 않고는 팔을 거기로 움직일 수 없어요.")
UNSURE = ("I can't check my arm right now, so I won't move it.", "지금 팔 상태를 확인할 수 없어서 움직이지 않을게요.") UNSURE = ("I can't check my arm right now, so I won't move it.", "지금 팔 상태를 확인할 수 없어서 움직이지 않을게요.")
NOT_AT_LOOK = ("My arm has to be in its look pose first.", "먼저 팔이 기본 자세에 있어야 해요.") NOT_AT_LOOK = ("My arm has to be in its look pose first.", "먼저 팔이 기본 자세에 있어야 해요.")
OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.") # not powered / enabled in Cobo π (joints read 0)
RETIRED = ("I don't use that arm program any more.", "그 팔 프로그램은 이제 쓰지 않아요.") RETIRED = ("I don't use that arm program any more.", "그 팔 프로그램은 이제 쓰지 않아요.")
@@ -122,6 +123,9 @@ def hops(now, target, leaf=False):
if d[start] > JOIN_DEG: if d[start] > JOIN_DEG:
if leaf: if leaf:
return [target] return [target]
if not any(now): # a switched-off arm reads all joints 0
log("arm route: the arm reads all 0: switched off")
raise RouteError(*OFF)
log(f"arm route: arm at {_r(now)}, {d[start]:.0f} deg from {start}, the nearest pose (joins within " log(f"arm route: arm at {_r(now)}, {d[start]:.0f} deg from {start}, the nearest pose (joins within "
f"{JOIN_DEG:.0f})") f"{JOIN_DEG:.0f})")
raise RouteError(*UNKNOWN) raise RouteError(*UNKNOWN)
+23 -10
View File
@@ -175,6 +175,8 @@ stay_put = False # set by assistant/lumi.py for a ta
# head and lift only, no base move, no waist turn (NEED_PATROL) # head and lift only, no base move, no waist turn (NEED_PATROL)
NEED_PATROL = ("For that I'd have to drive or turn. Switch on Patrol, please.", NEED_PATROL = ("For that I'd have to drive or turn. Switch on Patrol, please.",
"그러려면 이동하거나 돌아야 해요. 패트롤을 켜 주세요.") "그러려면 이동하거나 돌아야 해요. 패트롤을 켜 주세요.")
ARM_UNSEEN = ("My arm's power is off, so I can't tell where it is. Please switch it on.", # drives check the
"팔 전원이 꺼져 있어서 팔 위치를 알 수 없어요. 팔 전원을 켜 주세요.") # arm's way
_task = {"start_pose": None, # map pose (x, y, theta) where the current task was given _task = {"start_pose": None, # map pose (x, y, theta) where the current task was given
"trip_from": None} # where Lumi stood before its last trip, task or mission: "come back" "trip_from": None} # where Lumi stood before its last trip, task or mission: "come back"
# returns there (lumi.come_back); short moves and turns don't set it # returns there (lumi.come_back); short moves and turns don't set it
@@ -329,6 +331,20 @@ def _at_pose(name):
return max(abs(a - b) for a, b in zip(j, motion.nearest(motion.poses()[name], j))) <= 1.0 return max(abs(a - b) for a, b in zip(j, motion.nearest(motion.poses()[name], j))) <= 1.0
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
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())
except (FetchError, motion.MotionError) as e:
if tuple(e.args[:1]) != arm_route.OFF[:1] and "not powered" not in str(e):
raise
if not any(skills._joints()):
raise FetchError(*ARM_UNSEEN) from e
log("the arm is switched off: it stays where it is for the drive")
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."""
@@ -653,7 +669,7 @@ def _turn(deg, holding=False, why="to look further"):
log("on the charger: I don't turn") log("on the charger: I don't turn")
return False return False
if not holding: if not holding:
_pose(_look()) _drive_pose()
_waist_front() _waist_front()
if _sweep_blocked(deg, "turning"): if _sweep_blocked(deg, "turning"):
return False return False
@@ -1732,7 +1748,10 @@ def _fail(e, say):
return return
en = e.args[0] if e.args else str(e) en = e.args[0] if e.args else str(e)
ko = e.args[1] if isinstance(e, (FetchError, skills.SkillError)) and len(e.args) > 1 else "문제가 생겨서 멈췄어요." ko = e.args[1] if isinstance(e, (FetchError, skills.SkillError)) and len(e.args) > 1 else "문제가 생겨서 멈췄어요."
if not isinstance(e, (FetchError, skills.SkillError)): if isinstance(e, motion.MotionError) and "not powered" in str(e):
log(f"error: {e}")
en, ko = arm_route.OFF
elif not isinstance(e, (FetchError, skills.SkillError)):
log(f"error: {type(e).__name__}: {e}") log(f"error: {type(e).__name__}: {e}")
en = "Something went wrong, I stopped." en = "Something went wrong, I stopped."
try: try:
@@ -1976,10 +1995,7 @@ def _run_steps(steps, say):
def _do_step(s, say): def _do_step(s, say):
d, holding = s["do"], _state["holding"] d, holding = s["do"], _state["holding"]
if d == "go": if d == "go":
if holding: _drive_pose(holding)
_line_holding(LOOK_POSE)
else:
_pose(_look())
_step(f"driving to {s['to']}") _step(f"driving to {s['to']}")
_drive_to("here" if s["to"] == "here" else {"marker": s["to"]}, say, watch_holding=holding) _drive_to("here" if s["to"] == "here" else {"marker": s["to"]}, say, watch_holding=holding)
_say(say, "I'm here.", "도착했어요.") _say(say, "I'm here.", "도착했어요.")
@@ -2108,10 +2124,7 @@ def _move(direction, m, holding):
"""Drive `m` metres forward / back, or turn 90 deg left / right (arm sweep checked) and drive forward. Straight """Drive `m` metres forward / back, or turn 90 deg left / right (arm sweep checked) and drive forward. Straight
with joy_control in MOVE_SEGMENT_M pieces; before each the base's way (_straight_clear) and the arm's (line_hits) with joy_control in MOVE_SEGMENT_M pieces; before each the base's way (_straight_clear) and the arm's (line_hits)
are checked again with the live lidar, and a held object is checked after it. Stopped short -> FetchError.""" are checked again with the live lidar, and a held object is checked after it. Stopped short -> FetchError."""
if holding: _drive_pose(holding)
_line_holding(LOOK_POSE)
else:
_pose(_look())
if direction in ("left", "right"): if direction in ("left", "right"):
_step(f"turning {direction}") _step(f"turning {direction}")
if not _turn(90.0 if direction == "left" else -90.0, holding, why=f"to drive {direction}"): if not _turn(90.0 if direction == "left" else -90.0, holding, why=f"to drive {direction}"):
+11 -6
View File
@@ -61,7 +61,6 @@ HEAD_VEL = 50 # speed ratio %; the head is at its full speed from
HEAD_TIMEOUT_S = 5 # s; one head move (90 deg at ~40 deg/s takes ~2.5 s) HEAD_TIMEOUT_S = 5 # s; one head move (90 deg at ~40 deg/s takes ~2.5 s)
CHARGER = ("I'm on the charger, I can't follow you from here.", "충전 중이라 따라갈 수 없어요.") CHARGER = ("I'm on the charger, I can't follow you from here.", "충전 중이라 따라갈 수 없어요.")
ARM_OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.") # only when the arm must go to look
ARM_BUSY = ("A program is running on my arm, so I can't follow you.", "팔에서 프로그램이 실행 중이라 따라갈 수 없어요.") ARM_BUSY = ("A program is running on my arm, so I can't follow you.", "팔에서 프로그램이 실행 중이라 따라갈 수 없어요.")
LOST = ("I lost you, so I stopped. Stand in front of me and say follow me again.", LOST = ("I lost you, so I stopped. Stand in front of me and say follow me again.",
"놓쳐서 멈췄어요. 제 앞에 서서 다시 따라오라고 말해 주세요.") "놓쳐서 멈췄어요. 제 앞에 서서 다시 따라오라고 말해 주세요.")
@@ -147,8 +146,9 @@ def blocked(v, w, arm_pts, pose=None):
def ready(): def ready():
"""Why following can't start now as (en, ko), None when it can. The arm must be able to go to look, or be there """Why following can't start now as (en, ko), None when it can. The arm goes to look; switched off (not powered /
already: then it may stay switched off (it does not move while following).""" enabled) it stays where it is (it does not move while following, its points are checked), unless it reads all
joints 0 (powered off: where it is is not known)."""
if fetch._charging(): if fetch._charging():
return CHARGER return CHARGER
try: try:
@@ -156,8 +156,13 @@ def ready():
return None return None
motion._ready() motion._ready()
except motion.MotionError as e: except motion.MotionError as e:
fetch.log(f"follow: the arm can't go to look: {e}") if "program" in str(e):
return ARM_BUSY if "program" in str(e) else ARM_OFF fetch.log(f"follow: the arm can't go to look: {e}")
return ARM_BUSY
if not any(fetch.skills._joints()):
fetch.log("follow: the arm is powered off, where it is is not known")
return fetch.ARM_UNSEEN
fetch.log("follow: the arm is switched off: it stays where it is")
except Exception as e: # the controller does not answer except Exception as e: # the controller does not answer
fetch.log(f"follow: the arm does not answer: {e!r}") fetch.log(f"follow: the arm does not answer: {e!r}")
return NO_ARM return NO_ARM
@@ -173,7 +178,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._pose(fetch._look()) fetch._drive_pose()
fetch._waist_front() fetch._waist_front()
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")
+11 -6
View File
@@ -247,7 +247,7 @@ assert wait_end(1.0) and said and "charger" in said[0] and all(c[1:] == (0.0, 0.
fetch._charging = lambda: False fetch._charging = lambda: False
print("charger: refused") print("charger: refused")
# the arm switched off but in look: follows with the arm still; not in look: refused with the reason, never driven # the arm switched off: follows with the arm still, in look or not; powered off (joints 0): refused, never driven
def arm_off(): def arm_off():
raise motion.MotionError("arm is not powered / enabled") raise motion.MotionError("arm is not powered / enabled")
@@ -262,16 +262,21 @@ assert follow.running() and any(c[1] > 0 for c in w.cmds)
follow.stop() follow.stop()
assert wait_end(0.5) assert wait_end(0.5)
fetch._at_pose = lambda name: False fetch._at_pose = lambda name: False
assert follow.ready() == follow.ARM_OFF real_joints, fetch.skills._joints = fetch.skills._joints, lambda: [5.0] * 6
assert follow.ready() is None
fetch.skills._joints = lambda: [0.0] * 6
assert follow.ready() == fetch.ARM_UNSEEN
said.clear()
w = World() w = World()
follow.start(w.see, say) follow.start(w.see, say)
assert wait_end(1.0) and said == [follow.ARM_OFF[0]] and all(c[1:] == (0.0, 0.0) for c in w.cmds), said assert wait_end(1.0) and said == [fetch.ARM_UNSEEN[0]] and all(c[1:] == (0.0, 0.0) for c in w.cmds), said
fetch.skills._joints = real_joints
motion._ready = lambda: (_ for _ in ()).throw(motion.MotionError("a Cobo π program is running")) motion._ready = lambda: (_ for _ in ()).throw(motion.MotionError("a Cobo π program is running"))
assert follow.ready() == follow.ARM_BUSY assert follow.ready() == follow.ARM_BUSY
fetch._at_pose = lambda name: (_ for _ in ()).throw(ConnectionError("no answer")) fetch._at_pose = lambda name: (_ for _ in ()).throw(ConnectionError("no answer"))
assert follow.ready() == follow.NO_ARM assert follow.ready() == follow.NO_ARM
fetch._at_pose, motion._ready = (lambda name: True), forbid fetch._at_pose, motion._ready = (lambda name: True), forbid
print("arm off: follows in look, refuses otherwise") print("arm off: follows, powered off refuses")
# any other failure in prepare: said, the base at 0, the head free again, the thread ends # any other failure in prepare: said, the base at 0, the head free again, the thread ends
said.clear() said.clear()
@@ -554,9 +559,9 @@ L.modes.drive, L.skill_busy = True, lambda: True
L.follow_me() L.follow_me()
assert not started and "on a task" in spoken[-1] assert not started and "on a task" in spoken[-1]
L.skill_busy, real_ready = (lambda: False), follow.ready L.skill_busy, real_ready = (lambda: False), follow.ready
follow.ready = lambda: follow.ARM_OFF # checked before "Okay" follow.ready = lambda: fetch.ARM_UNSEEN # checked before "Okay"
L.follow_me() L.follow_me()
assert not started and spoken[-1] == follow.ARM_OFF[0] and not any("follow you" in x for x in spoken[-1:]) assert not started and spoken[-1] == fetch.ARM_UNSEEN[0] and not any("follow you" in x for x in spoken[-1:])
follow.ready = real_ready follow.ready = real_ready
follow.start = real_start follow.start = real_start
print("lumi hooks: ok") print("lumi hooks: ok")
+7 -3
View File
@@ -127,9 +127,9 @@ L.lang = "ko"
lumi.Lumi.receive_from_hand(L, "cup") lumi.Lumi.receive_from_hand(L, "cup")
assert said == [lumi.ARM_OFF_SAY[1]] assert said == [lumi.ARM_OFF_SAY[1]]
L.lang = "en" L.lang = "en"
assert lumi.wave_mod.OFF == follow.ARM_OFF == lumi.ARM_OFF_SAY assert lumi.wave_mod.OFF == fetch.arm_route.OFF == lumi.ARM_OFF_SAY
# follow: an enabled arm never refuses; a disabled one only when it must move to look # follow: an enabled arm never refuses; a disabled one follows where it is; powered off (joints 0) asks
follow.fetch._charging = lambda: False follow.fetch._charging = lambda: False
at_look = [True] at_look = [True]
follow.fetch._at_pose = lambda name: at_look[0] follow.fetch._at_pose = lambda name: at_look[0]
@@ -140,7 +140,11 @@ assert follow.ready() is None
at_look[0] = False at_look[0] = False
assert follow.ready() is None # enabled: it may go to look assert follow.ready() is None # enabled: it may go to look
arm_state.update(enable=0) arm_state.update(enable=0)
assert follow.ready() == follow.ARM_OFF # off and not at look: ask real_joints, follow.fetch.skills._joints = follow.fetch.skills._joints, lambda: [5.0] * 6
assert follow.ready() is None # off and not at look: follows, the arm stays
follow.fetch.skills._joints = lambda: [0.0] * 6
assert follow.ready() == follow.fetch.ARM_UNSEEN # powered off: where the arm is is not known
follow.fetch.skills._joints = real_joints
at_look[0] = True at_look[0] = True
assert follow.ready() is None # off but already at look: follows assert follow.ready() is None # off but already at look: follows