Improve arm motion resilience and test isolation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
-11
@@ -203,11 +203,13 @@ def waist_turned():
|
||||
return safe(fetch._waist_turn, default=0.0) or 0.0
|
||||
|
||||
|
||||
def waist_home(why):
|
||||
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. True when the waist is at the front."""
|
||||
waist stays, unless `fold` (an order to drive or turn): an empty arm goes back to look along the checked pose
|
||||
graph first (an arm left half way by a failed reach refused every drive after it, 2026-10-28). True when the
|
||||
waist is at the front."""
|
||||
from tasks import fetch
|
||||
with _waist_lock:
|
||||
try:
|
||||
@@ -217,8 +219,11 @@ def waist_home(why):
|
||||
log(f" waist stays turned ({why}): a task runs")
|
||||
return False
|
||||
if not fetch._at_pose(fetch._look()):
|
||||
log(f" waist stays turned ({why}): my arm is not folded in look")
|
||||
return False
|
||||
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)
|
||||
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})")
|
||||
@@ -801,7 +806,7 @@ class Patrol:
|
||||
if self.mode == "patrol" and battery < LOW_BATTERY and now >= self.wait_until:
|
||||
log(f"battery {battery} % - going home to charge")
|
||||
self.pause()
|
||||
if not waist_home("going home"): # every drive starts with the waist at the front
|
||||
if not waist_home("going home", fold=True): # every drive starts with the waist at the front
|
||||
self.wait_until = now + 5
|
||||
return
|
||||
ok, msg = safe(agv.go, "home", default=(False, "error"))
|
||||
@@ -850,7 +855,7 @@ class Patrol:
|
||||
if (ms == "running" and not force) or now < self.wait_until: # something else is driving, or waiting
|
||||
return
|
||||
target = self.route[self.i]
|
||||
if not waist_home("driving"): # every drive starts with the waist at the front
|
||||
if not waist_home("driving", fold=True): # every drive starts with the waist at the front
|
||||
if self.once: # said by say_stuck
|
||||
self.stuck, self.stuck_why, self.mode = target, WAIST_BACK_SAY, "done"
|
||||
else:
|
||||
@@ -2201,7 +2206,8 @@ class Lumi:
|
||||
if not self.vision.present(track) or track.distance > REACH_COME_M:
|
||||
self.fetch_say(*COME_CLOSER_SAY)
|
||||
return None
|
||||
angle = track.angle if track else self.voice_angle if self.voice_trusted else 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, "
|
||||
@@ -3349,7 +3355,7 @@ class Lumi:
|
||||
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.drive and self.modes.patrol else None
|
||||
if w is not None and waist_home("turning to a caller"):
|
||||
if w is not None and waist_home("turning to a caller", fold=True):
|
||||
log(f" caller outside the camera ({robot_angle:+.0f} deg): turning toward the voice")
|
||||
self.turn_head(0, force=True) # a call or an order: also over a held look
|
||||
safe(agv.turn_by, math.radians(robot_angle + w)) # from the base's front: the waist is there now
|
||||
@@ -3384,7 +3390,7 @@ class Lumi:
|
||||
self.turn_head(HEAD_SIGN * robot_angle)
|
||||
elif self.modes.drive and self.modes.patrol:
|
||||
w = waist_turned()
|
||||
if not waist_home("turning to a voice"):
|
||||
if not waist_home("turning to a voice", fold=True):
|
||||
return
|
||||
log(f" voice behind ({robot_angle:+.0f} deg): turning the base")
|
||||
self.turn_head(0)
|
||||
@@ -3425,7 +3431,7 @@ class Lumi:
|
||||
if goal is None:
|
||||
mouth.say("Sorry, I can't get closer from here.")
|
||||
return
|
||||
if not waist_home("coming to a person"): # every drive starts with the waist at the front
|
||||
if not waist_home("coming to a person", fold=True): # every drive starts with the waist at the front
|
||||
mouth.say(WAIST_BACK_SAY[0 if self.lang == "en" else 1])
|
||||
return
|
||||
ok, msg = safe(agv.go_point, *goal, default=(False, "error"))
|
||||
@@ -3484,7 +3490,7 @@ class Lumi:
|
||||
self.keep_listening()
|
||||
return True
|
||||
far = spot["clamped"]
|
||||
if not waist_home("driving where pointed"): # every drive starts with the waist at the front
|
||||
if not waist_home("driving where pointed", fold=True): # every drive starts with the waist at the front
|
||||
mouth.say(WAIST_BACK_SAY[0 if en else 1])
|
||||
return True
|
||||
mouth.say((f"Going that way, {pointing.MAX_M:g} meters." if far else "Going there.") if en else
|
||||
|
||||
+6
-4
@@ -41,7 +41,9 @@ SLOW_DEG_S = 5.0 # deg/s; long joint moves r
|
||||
# (measured: 157 deg of J6 in 37 s, 60 deg of J1 in 8.5 s)
|
||||
STILL_S = 2.0 # s without joint motion (and not there) -> the move ended short
|
||||
STILL_DEG = 0.05 # joint change that counts as motion
|
||||
BLIND_S = 1.0 # s without a valid state reply while moving -> stop the arm
|
||||
BLIND_S = 3.0 # s without a valid state reply while moving -> stop the arm
|
||||
# (the controller drops its connections ~0.5 s every few s and
|
||||
# arm.cmd retries for up to ~3 s: at 1.0 a reach stopped half way)
|
||||
SETTLE_S = 0.3 # s the arm stands at a pose before the next move (estimate;
|
||||
# going straight on shook the whole robot, 2026-10-21)
|
||||
|
||||
@@ -125,12 +127,12 @@ def _wait(arrived, limit_s, queued=False):
|
||||
raise MotionError("stopped")
|
||||
try:
|
||||
d = arm.cmd("get_data")
|
||||
except (ConnectionError, OSError):
|
||||
d = {}
|
||||
except (ConnectionError, OSError) as e:
|
||||
d = {"error": repr(e)}
|
||||
if "joint_actual_position" not in d: # the controller now and then answers a poll with nothing
|
||||
if time.time() - last_seen > BLIND_S:
|
||||
stop()
|
||||
raise MotionError("lost the arm state while moving - stopped")
|
||||
raise MotionError(f"lost the arm state while moving - stopped (last reply: {str(d)[:120]})")
|
||||
time.sleep(POLL_S)
|
||||
continue
|
||||
last_seen = time.time()
|
||||
|
||||
@@ -27,6 +27,13 @@ def _guard(real):
|
||||
socket.socket.connect = _guard(socket.socket.connect)
|
||||
socket.socket.connect_ex = _guard(socket.socket.connect_ex)
|
||||
|
||||
# the running assistant's blocked-drive state (/dev/shm): a test must not read it (after a live STUCK, "look at that"
|
||||
# became "go around" and the intents test failed, 2026-10-28)
|
||||
from assistant import detour as _detour # noqa: E402
|
||||
import tempfile as _tempfile # noqa: E402
|
||||
from pathlib import Path as _Path # noqa: E402
|
||||
_detour.STATE_FILE = _Path(_tempfile.mkdtemp()) / "lumi_stuck.json"
|
||||
|
||||
|
||||
@atexit.register
|
||||
def _report():
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ lumi.doa.estimate = lambda mics, cal, ref=None: (-40.0, 0.9, 0.0)
|
||||
lumi.waist_turned = lambda: 0.0
|
||||
from tasks import fetch as _fetch # noqa: E402
|
||||
_fetch._waist_to = lambda rel, in_place=False, look=None: True # "look at me" past the head turns the waist
|
||||
lumi.waist_home = lambda why: True
|
||||
lumi.waist_home = lambda why, fold=False: True
|
||||
lumi.agv.turn_by = lambda rad: None # "look at me" past the head with Patrol turns the base
|
||||
lumi.agv.status = lambda: {"move_status": "succeeded"}
|
||||
U = types.SimpleNamespace(mics=None, seconds=1.0, source="clip")
|
||||
@@ -165,7 +165,7 @@ lumi.agv.go_point = lambda *a: (True, "")
|
||||
lumi.agv.turn_by = lambda a: (_ for _ in ()).throw(AssertionError("the base turned away from the caller"))
|
||||
lumi.nav.person_on_map = lambda *a: (3.0, 0.0)
|
||||
lumi.nav.approach = lambda *a: (2.0, 0.0, 0.0)
|
||||
lumi.waist_home = lambda why: True
|
||||
lumi.waist_home = lambda why, fold=False: True
|
||||
L = fresh(a := Track(5, -19.0, 2.5), Track(8, 30.0, 2.4))
|
||||
L.current, L.look_me, L.looked_at = a, a, time.time()
|
||||
L.voice_angle, L.voice_trusted = -107.0, True # the voice read far off (19:24:22): the focus wins
|
||||
|
||||
@@ -101,4 +101,22 @@ assert not L.reach_done("thanks") and not folds and not L.reached_at
|
||||
L.reached_at = 0.0
|
||||
status["now"] = "done"
|
||||
assert not L.reach_done("thanks") and not folds # no reach out: "thanks" moves nothing
|
||||
|
||||
# an arm left half way (a reach stopped by a lost state reply) and the waist turned: an order to drive folds the empty
|
||||
# arm along the checked route, then the waist comes to the front; a conversation's end or a held thing never folds it
|
||||
# (live 2026-10-28 19:08-19:13: every "come here" said "I can't turn back to the front")
|
||||
route, waist = [], {"turn": 26.0}
|
||||
real = (fetch._waist_turn, fetch.state, fetch._at_pose, fetch._waist_to, lumi.arm_route.plan, lumi.arm_route.move)
|
||||
fetch._waist_turn = lambda: waist["turn"]
|
||||
fetch._at_pose = lambda name: bool(route)
|
||||
fetch._waist_to = lambda deg, in_place=False, look=None: waist.update(turn=deg) or True
|
||||
lumi.arm_route.plan = lambda target, holding=False: [(target, [0] * 6)]
|
||||
lumi.arm_route.move = lambda seq, speed=None, holding=False: route.append(seq[-1][0])
|
||||
fetch.state = lambda: {"status": "failed", "holding": False}
|
||||
assert not lumi.waist_home("the conversation is over") and not route and waist["turn"] == 26.0
|
||||
assert lumi.waist_home("coming to a person", fold=True) and route == ["look"] and waist["turn"] == 0.0
|
||||
route.clear(), waist.update(turn=26.0)
|
||||
fetch.state = lambda: {"status": "failed", "holding": True} # something in the hand: never moved for a drive
|
||||
assert not lumi.waist_home("coming to a person", fold=True) and not route
|
||||
(fetch._waist_turn, fetch.state, fetch._at_pose, fetch._waist_to, lumi.arm_route.plan, lumi.arm_route.move) = real
|
||||
print(f"reach live ok ({len(REACH) + len(NOT_REACH)} wordings, stop during a hung body move, held state, auto fold)")
|
||||
|
||||
@@ -22,7 +22,7 @@ lumi.motion.stop = lambda: done.append("arm stop")
|
||||
follow.stop = lambda: done.append("follow stop")
|
||||
fetch.stop = lambda: done.append("fetch stop")
|
||||
fetch.state = lambda: {"status": "idle"}
|
||||
lumi.waist_home = lambda why: True # the waist at the front before a drive (it reads the body and arm)
|
||||
lumi.waist_home = lambda why, fold=False: True # the waist at the front before a drive (it reads the body and arm)
|
||||
lumi.waist_turned = lambda: 0.0
|
||||
lumi.mouth.say = lambda text, **k: done.append(("say", text))
|
||||
lumi.mouth.own_voice = lambda u: False
|
||||
|
||||
@@ -217,10 +217,15 @@ assert L.reach_out(False) is None and not reached and not came and said == [lumi
|
||||
L.modes.drive, person.distance = True, 1.0
|
||||
fetch.give_bearing = lambda: 0.0
|
||||
L.turn_head = lambda *a, **k: moved.append("head")
|
||||
L.vision = None # nobody seen, the voice's direction not trusted: ask
|
||||
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: turn to the voice
|
||||
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]
|
||||
moved.clear(), reached.clear(), said.clear()
|
||||
L.fetch_status = lambda: "holding"
|
||||
@@ -259,7 +264,7 @@ for n, f in real.items():
|
||||
# ---------- every drive and base turn starts with the waist at the front ----------
|
||||
order = []
|
||||
real_home = lumi.waist_home
|
||||
lumi.waist_home = lambda why: order.append("waist") or True
|
||||
lumi.waist_home = lambda why, fold=False: order.append("waist") or True
|
||||
lumi.agv.status = lambda: {"move_status": "idle", "power_percent": 90}
|
||||
lumi.agv.go = lambda m: order.append(("go", m)) or (True, "OK")
|
||||
lumi.agv.go_point = lambda x, y, th: order.append(("go", (x, y, th))) or (True, "OK")
|
||||
@@ -278,7 +283,7 @@ real_turned, lumi.waist_turned = lumi.waist_turned, lambda: 30.0 # turned 30 l
|
||||
order.clear()
|
||||
L.look_toward(150.0) # a voice behind: the base turns to it from the base's front
|
||||
assert order == ["waist", ("turn", 180)], order
|
||||
lumi.waist_home = lambda why: order.append("waist") or False # it can't come back: no drive, no turn, said why
|
||||
lumi.waist_home = lambda why, fold=False: order.append("waist") or False # it can't come back: no drive, no turn, said why
|
||||
order.clear()
|
||||
P = lumi.Patrol(["p3"], once=True)
|
||||
P.tick(force=True)
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ lumi.ears.transcribe = lambda mono: mono
|
||||
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: True
|
||||
lumi.waist_home = lambda why, fold=False: True
|
||||
M = ["home", "dock2"]
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ assert "head" in done and L.voice_until == 0.0, done # end_conversation: yaw 0
|
||||
# a held look keeps both (the waist waits like the head)
|
||||
homed, back = [], threading.Event()
|
||||
real_home, real_turned = lumi.waist_home, lumi.waist_turned
|
||||
lumi.waist_home = lambda why: homed.append(why) or back.set() or True
|
||||
lumi.waist_home = lambda why, fold=False: homed.append(why) or back.set() or True
|
||||
for patrol in (False, True):
|
||||
L = fresh(a := Track(33, 40))
|
||||
a.greeted, L.current, L.modes.patrol = True, a, patrol
|
||||
@@ -336,7 +336,7 @@ for turned, homes, want in ((30.0, True, -20.0), (30.0, False, -50.0), (0.0, Tru
|
||||
heads, back = [], threading.Event()
|
||||
L.turn_head = lambda yaw=None, *r, **k: heads.append(yaw) or back.set()
|
||||
lumi.waist_turned = lambda w=turned: w
|
||||
lumi.waist_home = lambda why, ok=homes: homed.append(why) or ok
|
||||
lumi.waist_home = lambda why, ok=homes, fold=False: homed.append(why) or ok
|
||||
homed.clear()
|
||||
lumi.Lumi.who_spoke(L, U("Lumi, stop.", seconds=1.0))
|
||||
assert back.wait(2) and L.current is b and heads == [lumi.HEAD_SIGN * want], (turned, homes, heads)
|
||||
|
||||
Reference in New Issue
Block a user