Fix bugs found in review, with tests and docs for the four modes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:47:15 +09:00
co-authored by Claude Opus 5.5
parent a6094568d0
commit ed2c6bdafd
10 changed files with 592 additions and 69 deletions
+68
View File
@@ -0,0 +1,68 @@
"""Self-check of the four switches (owner, 2026-11-16): Greeter, Patrol, Wave (wave_greet) and Welcome each work on
their own, so lumi.py runs while any of them is on and stops when all four are off; the assistant reads all four.
Fake state, no robot: python tests/test_four_modes.py"""
import json
import tempfile
import types
from pathlib import Path
import no_robot # noqa: F401 any connection to the robot fails the test
from api import server
from assistant import lumi
tmp = Path(tempfile.mkdtemp())
server.MODES_FILE = tmp / "lumi_modes.json" # never the real /dev/shm file
lumi.MODES_FILE = str(server.MODES_FILE)
# the file keeps all four; an old file without welcome reads it as off
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": True}))
assert server.read_modes() == {"greeter": False, "patrol": False, "wave_greet": True, "welcome": False}, server.read_modes()
# who starts and stops lumi.py
running, calls = [], []
server.assistant_pids = lambda: list(running)
server.start_assistant = lambda *a, **k: (calls.append("start"), running.append(1))
server.assistant_stop = lambda *a, **k: (calls.append("stop"), running.clear())
server._calib_active = lambda: False
server.agv.status = lambda: {"charge_state": True, "move_status": "idle"} # on the charger (Welcome)
server._bg = lambda fn: fn() # the stop after the hand is down runs at once here
server.arm_route.where = lambda: "look" # the hand is down
server.MODES_FILE.write_text(json.dumps({}))
def switch(**kw):
return server.modes_set(server.ModesBody(**kw))
for only in ("greeter", "patrol", "wave_greet", "welcome"):
calls.clear()
r = switch(**{only: True})
assert calls == ["start"] and r["running"] and r[only], (only, calls, r)
calls.clear()
r = switch(**{only: False})
assert calls == ["stop"] and not r["running"], (only, calls, r)
# Welcome on, then Wave on and Welcome off: lumi.py keeps running
switch(welcome=True)
calls.clear()
switch(wave_greet=True)
switch(welcome=False)
assert calls == [] and running, calls
switch(wave_greet=False)
assert calls == ["stop"], calls
assert server.any_on({"greeter": False, "patrol": False, "wave_greet": False, "welcome": True})
assert not server.any_on(dict(server.DEFAULT_MODES))
# the assistant reads the four switches live
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": True, "welcome": True}))
m = lumi.Modes(types.SimpleNamespace(patrol=False, no_arm=False))
assert (m.greeter, m.patrol, m.wave_greet, m.welcome) == (False, False, True, True), vars(m)
assert lumi.waving_on() and lumi.wave_greet_on()
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": False, "wave_greet": False, "welcome": True}))
assert lumi.waving_on() and not lumi.wave_greet_on() and lumi.welcome_on()
server.MODES_FILE.write_text(json.dumps({"greeter": True}))
assert not lumi.waving_on() and not lumi.welcome_on()
print("ok: four switches")
+155
View File
@@ -0,0 +1,155 @@
"""Self-check of the owner's mode rules of 2026-11-16 (second round): the hand is up whenever Wave alone is on and always
on the charger; with Greeter or Patrol a drive goes in look, lowered slowly; with Greeter / Patrol and Wave together Lumi
only answers people who wave (stops, raises the hand, waves, lowers it, drives on), no waves at everyone, no keep alive;
a blocked drive is said aloud and the same place is tried again; Welcome only on the charger. Fake state, no robot:
python tests/test_mode_rules.py"""
import json
import tempfile
import time
import types
from pathlib import Path
import no_robot # noqa: F401 any connection to the robot fails the test
from fastapi import HTTPException
from api import server
from assistant import lumi
from manipulation import arm_route, wave
from tasks import fetch, wave_greet as g
tmp = Path(tempfile.mkdtemp())
server.MODES_FILE = tmp / "lumi_modes.json"
lumi.MODES_FILE = str(server.MODES_FILE)
def modes(**kw):
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": False, "welcome": False, **kw}))
# Wave alone, or Wave with Greeter / Patrol
modes(wave_greet=True)
assert lumi.wave_only()
modes(wave_greet=True, greeter=True)
assert not lumi.wave_only()
modes(patrol=True)
assert not lumi.wave_only()
# drives: Wave alone stops for people passing and keep alive; with Patrol too only for someone waving, whose wave is
# answered with the hand raised and lowered again
order, real = [], (g.passer_due, g._waver, g.keep_alive_due)
lumi.agv.status = lambda: {"move_status": "running", "power_percent": 90}
lumi.agv.dock_marker = lambda: "home"
g.passer_due, g.keep_alive_due = (lambda: True), (lambda now=None: True)
def drive(hand_up, waving):
g._waver = lambda: (10.0, 2.0, None, None) if waving else None
P = lumi.Patrol(["p1", "p2"])
P.moving, P.hand_up = True, hand_up
P.pause = lambda: order.append("pause")
P.passer_wave = lambda: order.append("passer")
P.keep_alive = lambda: order.append("keep")
P.answer_waver = lambda: order.append("answer")
order.clear()
P.tick(force=True)
if P.waving:
P.waving.join(1.0)
return list(order)
modes(wave_greet=True)
assert drive(True, False) == ["pause", "passer"], order
modes(wave_greet=True, patrol=True)
assert drive(False, False) == [], order # nobody waving: drives on, no waves at people, no keep alive
assert drive(False, True) == ["pause", "answer"], order
modes(patrol=True)
assert drive(False, True) == [], order # Wave off: no waving at all
g.passer_due, g._waver, g.keep_alive_due = real
# the hand for a drive: up only with Wave alone
g._on = lambda: True
modes(wave_greet=True, greeter=True)
assert not lumi.wave_only()
g._drive_on = lumi.wave_only
g.arm_route.where = lambda now=None: "look"
assert g.raise_for_drive() is False
g._drive_on = None
# answering someone who waves on a drive: up, swings while they wave (at least GREET_SWINGS), down slowly to look
done = []
g._waver = lambda: (15.0, 2.0, None, None) if len([d for d in done if d == "swing"]) < 4 else None
g._someone_within = lambda m: False
pose = {"at": "look"}
g.arm_route.where = lambda now=None: pose["at"]
wave.plan = lambda: ([("wave_start", None)], [])
g._up = lambda route: done.append("up") or pose.update(at="wave_start")
g._swing = lambda: done.append("swing")
g._head_to = lambda b: done.append(f"head {b:+.0f}")
g._turn_head = lambda yaw, pitch=None: done.append(f"head {yaw:+.0f}")
g._down = lambda waist=None, arm_to=None, speed=None: done.append(f"down {arm_to} {speed}")
fetch.drive_arm = lambda: "look"
assert g.answer_waver(speed="slow")
assert done[:2] == ["up", "head +15"] and done.count("swing") == 4 and done[-1] == "down look slow", done
done.clear()
g._waver = lambda: None
assert not g.answer_waver(speed="slow") and done == [] # nobody waving any more: nothing
# a hand up comes down slowly before a drive with Greeter / Patrol (lower passes the speed on)
done.clear()
g._quiet = lambda wait_s: None
pose["at"] = "wave_start"
g.lower(speed="slow")
assert done == ["down look slow"], done
# on the charger the arm rests in wave_start (with or without Welcome), slowly, from look or its rest
moved = []
lumi.on_charger = lambda: True
fetch.state = lambda: {"status": "idle"}
fetch._stop.clear = lambda: None
pose["at"] = "look"
lumi.arm_route.where = lambda now=None: pose["at"]
fetch._at_pose = lambda name: name == pose["at"]
lumi.arm_route.plan = lambda target, holding=False, leaf=False, now=None: [target]
lumi.arm_route.move = lambda seq, speed=None, holding=False: moved.append((seq[-1], speed)) or pose.update(at=seq[-1])
fetch._waist_to = lambda rel, in_place=False, look=None: True
assert lumi.waist_home_rest("test")
assert moved == [(wave.START, lumi.HOME_ARM_SPEED)], moved
moved.clear()
assert lumi.waist_home_rest("again") and moved == [], moved # already up: stays
# a blocked drive: said aloud (also with only Wave on) and the same place tried again
lumi.agv.status = lambda: {"move_status": "running", "power_percent": 90, "current_pose": {"x": 1.0, "y": 1.0, "theta": 0.0}}
for route, once, wave_on, done_after in ((["p1", "p2"], False, False, False), (["p3"], True, True, False),
(["p3"], True, False, True)):
modes(wave_greet=wave_on, patrol=not wave_on)
P = lumi.Patrol(route, once=once)
P.moving, P.i = True, 0
P.progress = ((1.0, 1.0, 0.0), time.time() - lumi.STUCK_DRIVE_S - 1)
lumi.agv.cancel = lambda: None
P.tick(force=True)
assert P.stuck == route[0] and P.i == 0 and (P.mode == "done") == done_after, (route, P.mode, P.i)
said = []
real_say, lumi.mouth.say = lumi.mouth.say, (lambda text, **k: said.append(text))
modes(wave_greet=True)
me = types.SimpleNamespace(modes=types.SimpleNamespace(greeter=False, patrol=False, wave_greet=True, welcome=False),
lang="en", patrol=types.SimpleNamespace(stuck="p3", stuck_why=None, once=False))
lumi.Lumi.say_stuck(me)
assert said and "blocking" in said[0], said
lumi.mouth.say = real_say
# Welcome only on the charger
server.assistant_pids = lambda: [1]
server.start_assistant = lambda *a, **k: None
server._calib_active = lambda: False
modes()
server.agv.status = lambda: {"charge_state": False, "move_status": "idle"}
try:
server.modes_set(server.ModesBody(welcome=True))
raise AssertionError("Welcome switched on off the charger")
except HTTPException as e:
assert e.status_code == 409 and e.detail == server.WELCOME_OFF_CHARGER, e.detail
server.agv.status = lambda: {"charge_state": True, "move_status": "idle"}
assert server.modes_set(server.ModesBody(welcome=True))["welcome"]
assert server.modes_set(server.ModesBody(welcome=False))["welcome"] is False # off is always allowed
print("ok: mode rules")
+162
View File
@@ -0,0 +1,162 @@
"""Self-check of the safety fixes for the four modes (review of 2026-11-16): a stop switches Wave and Welcome off, so
nothing raises the arm by itself again; the swings of a drive wait for the base to stand; a new drive waits for them;
keep alive does not stop the base again and again; held swings end when someone comes close; the last switch off
lowers the hand before lumi.py stops. Fake state, no robot: python tests/test_modes_safety.py"""
import json
import tempfile
import threading
import time
from pathlib import Path
import no_robot # noqa: F401 any connection to the robot fails the test
from api import server
from assistant import lumi
from tasks import wave_greet as g
tmp = Path(tempfile.mkdtemp())
server.MODES_FILE = tmp / "lumi_modes.json"
lumi.MODES_FILE = str(server.MODES_FILE)
# C1: an arm stop switches both Wave and Welcome off (through the API, as the dashboard does)
sent = []
real_open = lumi.urllib.request.urlopen
lumi.urllib.request.urlopen = lambda req, timeout=5: sent.append(json.loads(req.data)) or type("R", (), {"close": lambda s: None})()
lumi.wave_greet_off()
assert sent == [{"wave_greet": False, "welcome": False}], sent
lumi.urllib.request.urlopen = real_open
# C2: STOP switches Wave and Welcome off (the supervisor must not bring lumi.py back to raise the arm); Greeter and
# Patrol keep their switches as before
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": False, "wave_greet": True, "welcome": True}))
server.jogger.stop = server._route.stop = lambda: None
server.part = lambda fn, *a, **k: None
server.assistant_stop = lambda: {"stopped": []}
server.stop_all()
assert server.read_modes() == {"greeter": True, "patrol": False, "wave_greet": False, "welcome": False}, server.read_modes()
assert not server.any_on({**server.read_modes(), "greeter": False})
# I1: a drive's swings wait for the base to stand; a base that does not stop: no swings
states = iter(["running", "running", "idle"])
lumi.agv.status = lambda: {"move_status": next(states, "idle")}
assert lumi.base_stopped(timeout=2.0, every=0.01)
lumi.agv.status = lambda: {"move_status": "running"}
assert not lumi.base_stopped(timeout=0.1, every=0.01)
swung = []
real_keep, real_passer = g.keep_alive_wave, g.passer_wave
g.keep_alive_wave = lambda: swung.append("keep") or True
g.passer_wave = lambda: swung.append("passer") or True
lumi.BASE_STOP_WAIT_S = 0.1
P = lumi.Patrol(["p1", "p2"])
P.keep_alive()
P.passer_wave()
assert swung == [], swung # the base never stopped
lumi.agv.status = lambda: {"move_status": "idle"}
P.keep_alive()
P.passer_wave()
assert swung == ["keep", "passer"], swung
# I3: keep alive that could not swing starts the quiet count again (no stop every 2 s); keep alive waits wave_after
g.keep_alive_wave = lambda: False
g._st["any_wave"] = 0.0
P.keep_alive()
assert time.time() - g._st["any_wave"] < 5, g._st["any_wave"]
g.keep_alive_wave, g.passer_wave = real_keep, real_passer
order = []
lumi.agv.status = lambda: {"move_status": "running", "power_percent": 90}
real_on, real_due, real_waver, real_kad = lumi.wave_greet_on, g.passer_due, g._waver, g.keep_alive_due
real_only, lumi.wave_only = lumi.wave_only, (lambda: True) # Wave alone (keep alive only then)
lumi.wave_greet_on, g.passer_due, g._waver, g.keep_alive_due = (lambda: True), (lambda: False), (lambda: False), \
(lambda now=None: True)
P = lumi.Patrol(["p1", "p2"])
P.moving, P.hand_up, P.wave_after = True, True, time.time() + 60
P.pause = lambda: order.append("pause")
P.tick(force=True)
assert order == [], order # keep alive due, but a stop was just made: not yet
P.wave_after = 0.0
P.keep_alive = lambda: None
P.tick(force=True)
assert order == ["pause"], order
lumi.wave_greet_on, g.passer_due, g._waver, g.keep_alive_due = real_on, real_due, real_waver, real_kad
lumi.wave_only = real_only
# I2: a new drive waits while a drive's swings still run (the arm must be still when the base moves)
went = []
lumi.arm_route.where = lambda now=None: "look" # never the real arm controller or base
lumi.agv.dock_marker = lambda: "home"
lumi.agv.status = lambda: {"move_status": "idle", "power_percent": 90}
lumi.agv.go = lambda m: went.append(m) or (True, "OK")
real_home, lumi.waist_home = lumi.waist_home, (lambda why, fold=False: True)
with g._drive_wave:
assert g.drive_wave_busy()
P = lumi.Patrol(["p3"], once=True)
P.tick(force=True)
assert went == [] and not P.moving, went
assert not g.drive_wave_busy()
P.tick(force=True)
assert went == ["p3"], went
lumi.waist_home = real_home
# I4: held swings (Welcome at home, keep alive) end as soon as someone is within IDLE_CLEAR_M, or the switch is off
n = []
real_swing, g._swing = g._swing, (lambda: n.append(1))
g._waver, g._free, g._on = (lambda: None), (lambda: True), (lambda: True)
near = {"n": 0}
g._someone_within = lambda m: len(n) >= 1 # someone walks up after the first swing
g._idle_swings(lambda: True)
assert len(n) == 1, n
n.clear()
g._someone_within = lambda m: False
g._on = lambda: False
g._idle_swings(lambda: True)
assert n == [], n
g._swing = real_swing
# I5: the last switch off with the hand up: lumi.py stops only once the hand is down (or after a wait)
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": False, "welcome": False}))
poses, stopped = iter(["wave_start", "wave_start", "look"]), []
server.arm_route.where = lambda: next(poses, "look")
server.assistant_stop = lambda: stopped.append(time.time()) or {"stopped": []}
server.stop_when_lowered(wait_s=2.0, every=0.01)
assert len(stopped) == 1, stopped
server.arm_route.where = lambda: "wave_start" # never comes down: stopped all the same after the wait
t0 = time.time()
server.stop_when_lowered(wait_s=0.2, every=0.01)
assert len(stopped) == 2 and time.time() - t0 >= 0.2, stopped
# Welcome alone drives with the hand down: only Wave raises it for a drive (owner, 2026-11-16)
import types # noqa: E402
g.arm_route.where = lambda now=None: "look"
g._on, g._drive_on = (lambda: True), (lambda: False) # Welcome on, Wave off
assert g.raise_for_drive() is False
g.arm_route.where = lambda now=None: "wave_start"
g._drive_on = lambda: True # Wave on: the hand up (already there)
assert g.raise_for_drive() is True
g._drive_on = None
# a blocked trip is said aloud, also with only Wave on (owner, 2026-11-16, second round)
said = []
real_say, lumi.mouth.say = lumi.mouth.say, (lambda text, **k: said.append(text))
Mo = lambda **kw: types.SimpleNamespace(**{"greeter": False, "patrol": False, "wave_greet": False, "welcome": False, **kw})
me = types.SimpleNamespace(modes=Mo(wave_greet=True), lang="en",
patrol=types.SimpleNamespace(stuck="p3", stuck_why=("Blocked.", "막혔어요."), once=True))
lumi.Lumi.say_stuck(me)
assert said == ["Blocked."] and me.patrol.stuck is None, said
me.modes, me.patrol.stuck, me.patrol.stuck_why = Mo(patrol=True), "p3", ("Blocked.", "막혔어요.")
lumi.Lumi.say_stuck(me)
assert said == ["Blocked.", "Blocked."], said
lumi.mouth.say = real_say
# the last switch off, then a switch on again while the hand comes down: lumi.py is not stopped after all (it was,
# and the supervisor started it again and again, 2026-11-16 16:31)
stopped.clear()
server.arm_route.where = lambda: "wave_start"
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": True, "welcome": False}))
server.stop_when_lowered(wait_s=0.2, every=0.01)
assert stopped == [], stopped
server.MODES_FILE.write_text(json.dumps({"greeter": False, "patrol": False, "wave_greet": False, "welcome": False}))
server.stop_when_lowered(wait_s=0.2, every=0.01)
assert len(stopped) == 1, stopped
print("ok: no stop after a switch on again")
print("ok: modes safety")
+30
View File
@@ -0,0 +1,30 @@
"""Self-check: with only Wave and/or Welcome on, Lumi only waves (owner, 2026-11-16): no talk, no wake word, the wave
greeting says nothing; with Greeter or Patrol on it talks as before. Fake state, no robot:
python tests/test_quiet_modes.py"""
import sys
import types
import no_robot # noqa: F401 any connection to the robot fails the test
from assistant import lumi
from tasks import wave_greet
M = lambda **kw: types.SimpleNamespace(**{"greeter": False, "patrol": False, "wave_greet": False, "welcome": False, **kw})
assert not lumi.talk_allowed(M(wave_greet=True, welcome=True))
assert lumi.talk_allowed(M(greeter=True, wave_greet=True))
assert lumi.talk_allowed(M(patrol=True))
assert not lumi.talk_allowed(M())
# the wave greeting's lines: silent while talk is not allowed
said = []
from audio import mouth # noqa: E402
mouth.say = lambda text: said.append(text) # never the real speaker
wave_greet._bg = lambda fn, *a: fn(*a) # run in this thread
wave_greet._talk = lambda: False
wave_greet._say([("hello", "안녕")], 0)
assert said == [], said
wave_greet._talk = lambda: True
wave_greet._say([("hello", "안녕")], 0)
assert said == ["hello"], said
print("ok: quiet modes")
+1 -1
View File
@@ -41,7 +41,7 @@ manual = (lambda: server.jog(JOG), server.gripper_open, server.gripper_close)
# a modes file with keys no longer used ("drive", "wave" when asked) still loads, without them
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": False, "wave": True, "drive": False}))
assert server.read_modes() == {"greeter": True, "patrol": False, "wave_greet": False}, server.read_modes()
assert server.read_modes() == {"greeter": True, "patrol": False, "wave_greet": False, "welcome": False}, server.read_modes()
# idle, Patrol on: allowed
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": True}))
+16 -8
View File
@@ -239,7 +239,7 @@ assert lumi.waist_home("test") is False
# 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.plan, lumi.wave_greet.lower = (lambda target, holding=False: [target]), (lambda **k: 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 == "rest"), (lambda: {"status": "idle"})
assert lumi.waist_home("drive", fold=True) and went == ["look"], went
@@ -269,19 +269,23 @@ order.clear()
P = lumi.Patrol(["p3"])
P.tick(force=True)
assert order == ["waist", ("go", "home")] and P.mode == "going_home", order
# a there-and-back loop (p1, p2) stops for anyone passing, a plain trip to p3 only for someone waving
# with Wave on every drive (a loop or a plain trip) stops for someone new passing (owner, 2026-11-16); a dock leg not
lumi.agv.status = lambda: {"move_status": "running", "power_percent": 90}
real_on, real_due, real_waver = lumi.wave_greet_on, lumi.wave_greet.passer_due, lumi.wave_greet._waver
real_only, lumi.wave_only = lumi.wave_only, (lambda: True) # Wave alone: stops for people passing
lumi.wave_greet_on, lumi.wave_greet.passer_due, lumi.wave_greet._waver = (lambda: True), (lambda: True), \
(lambda: False)
for passers, stops in ((True, True), (False, False)):
P = lumi.Patrol(["p1", "p2"], passers=passers)
for route, passers, stops in ((["p1", "p2"], True, True), (["p3"], False, True), ([(1.0, 2.0, 0.0)], False, True),
(["home"], False, False)):
P = lumi.Patrol(route, passers=passers)
P.dock_leg = route == ["home"]
P.moving, P.hand_up, P.passer_wave = True, True, (lambda: None)
P.pause = lambda: order.append("pause")
order.clear()
P.tick(force=True)
assert (order == ["pause"]) == stops, (passers, order)
assert (order == ["pause"]) == stops, (route, order)
lumi.wave_greet_on, lumi.wave_greet.passer_due, lumi.wave_greet._waver = real_on, real_due, real_waver
lumi.wave_only = real_only
lumi.agv.status = lambda: {"move_status": "idle", "power_percent": 90}
L.modes.patrol = True
real_turned, lumi.waist_turned = lumi.waist_turned, lambda: 30.0 # turned 30 left for someone
@@ -307,11 +311,13 @@ 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
# ---------- on the charger with nothing to do: the arm slowly from rest or look up to wave_start (owner, 2026-11-16:
# at home the hand rests up, with or without Welcome), 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
real_where, lumi.arm_route.where = lumi.arm_route.where, (lambda now=None: arm_at["now"])
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"
@@ -319,8 +325,9 @@ 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)]),
[("arm", "wave_start", lumi.HOME_ARM_SPEED), ("waist", lumi.HOME_WAIST_DEG)]),
({"charge_state": True, "move_status": "idle"}, "look",
[("arm", "wave_start", lumi.HOME_ARM_SPEED), ("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
@@ -332,6 +339,7 @@ for task in ({"status": "running"}, {"status": "idle", "holding": True}): # a
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
lumi.arm_route.where = real_where
# ---------- on the charger the body stays turned to its rest: someone speaking or calling turns the head only ------
moves = []
+108 -53
View File
@@ -227,65 +227,83 @@ 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
# Welcome (owner, 2026-11-16): switched on, the hand goes up to wave_start at once and stays, no swings yet, no words;
# someone right by the arm: later. At home (_home) a new person 0.8..6 m: the head to them and IDLE_SWINGS swings, each
# person once. Keep alive (_idle: Welcome, on the charger, nobody talked for KEEP_QUIET_S): KEEP_QUIET_S after the last
# wave at people, IDLE_SWINGS swings every IDLE_WAVE_EVERY_S toward the nearest person at any distance, else the front.
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
g._welcome, g._home, g._idle, g._rest_arm = (lambda: True), (lambda: False), (lambda: False), (lambda: "look")
g._someone_within = lambda m: True
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"] * g.IDLE_SWINGS and said == [] and g._st["up"] and g._st["held"], (done, said)
assert done == ["up route"] and g._st["up"] and g._st["held"] and said == [], (done, said)
run(691.5, 700.0)
assert done == ["up route"], done # held up, still: nobody new, keep alive not allowed
g._home = lambda: True
person, marked = {"p": (25.0, 3.0, None, None)}, []
real_new, real_mark = g._new_passer, g._mark_passed
g._new_passer = lambda now=None: person["p"]
g._mark_passed = lambda now=None: marked.append(1) or person.update(p=None)
done.clear()
run(701.0, 702.0)
assert done[0] == "head +25" and done.count("swing") == g.IDLE_SWINGS and marked == [1] and said == [], done
done.clear()
run(702.5, 710.0)
assert "swing" not in done, done # the same person: not again
g._idle = lambda: True
nearest = {"b": None}
real_any, g._nearest_any = g._nearest_any, (lambda now=None: nearest["b"])
run(710.5, 701.0 + g.KEEP_QUIET_S - 1)
assert "swing" not in done, done # not before KEEP_QUIET_S after the last wave at people
run(701.0 + g.KEEP_QUIET_S + 0.5, 701.0 + g.KEEP_QUIET_S + 1.5)
assert done.count("swing") == g.IDLE_SWINGS, done # nobody seen: to the front
done.clear()
t = 701.0 + g.KEEP_QUIET_S + 2
nearest["b"] = -40.0 # someone far away on the right
run(t, t + g.IDLE_WAVE_EVERY_S - 3)
assert done == [], done # not before IDLE_WAVE_EVERY_S
run(t + g.IDLE_WAVE_EVERY_S, t + g.IDLE_WAVE_EVERY_S + 1)
assert done[0] == "head -40" and done.count("swing") == g.IDLE_SWINGS, done
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()
g._home = lambda: not talk["on"]
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"] * g.IDLE_SWINGS, 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
done.clear() # the hand left up (its way down did not run): swings from there
arm["at"], g._st["idle_at"] = "wave_start", 0.0
run(1200.0, 1200.0)
assert done == ["swing"] * g.IDLE_SWINGS and g._st["held"], done
g.lower()
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)
g._welcome = lambda: False # Welcome off: nothing goes up by itself on the charger
g._idle = g._home = lambda: True
run(1200.0, 1300.0)
assert done == [], done
g._idle, g._rest_arm = (lambda: False), g.arm_route.rest_pose
g._welcome, g._home, g._idle, g._rest_arm = (lambda: False), (lambda: False), (lambda: False), g.arm_route.rest_pose
g._new_passer, g._mark_passed, g._nearest_any = real_new, real_mark, real_any
# keep alive on the way (Wave on, lumi.Patrol): due KEEP_QUIET_S after the last swing of any kind, not with someone by
# the arm; IDLE_SWINGS swings toward the nearest person at any distance, else the front, only with the hand up
g._st["any_wave"] = 2000.0
assert not g.keep_alive_due(2000.0 + g.KEEP_QUIET_S - 1)
assert g.keep_alive_due(2000.0 + g.KEEP_QUIET_S)
g._someone_within = lambda m: True
assert not g.keep_alive_due(2000.0 + g.KEEP_QUIET_S)
g._someone_within = lambda m: False
g.note_quiet_start(3000.0)
assert not g.keep_alive_due(3000.0 + 1) and g.keep_alive_due(3000.0 + g.KEEP_QUIET_S)
real_any, g._nearest_any = g._nearest_any, (lambda now=None: 15.0)
arm["at"] = "look"
done.clear()
assert not g.keep_alive_wave() and done == [] # the hand is not up
arm["at"] = "wave_start"
assert g.keep_alive_wave() and done.count("swing") == g.IDLE_SWINGS, done
time.sleep(0.2)
assert "head +15" in done and done[-1] == "head +0" and g._st["any_wave"] > 3000.0, done
g._nearest_any = real_any
arm["at"] = "look"
done.clear()
# 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
@@ -310,29 +328,62 @@ waver["w"] = W(0.0)
run(621.0, 621.0)
assert said[-1] in sum(g.wave_lines.INTRO, ()), said
# a loop patrol's wave for people passing: only with the hand up, someone within PASSER_M, nobody by the arm
# a drive's wave for people passing (Wave on): only with the hand up, a new person PASSER_MIN_M..PASSER_M away,
# nobody by the arm; each person once (_mark_passed after the swings, owner 2026-11-16)
near = {"m": None}
marked = []
waver["w"] = None
g._someone_within = lambda m: near["m"] is not None and near["m"] < m
g._nearest = lambda m: 20.0 if near["m"] is not None and near["m"] < m else None
real_new, g._new_passer = g._new_passer, lambda now=None: (20.0, near["m"], None, None) \
if near["m"] is not None and g.PASSER_MIN_M <= near["m"] <= g.PASSER_M else None
real_mark, g._mark_passed = g._mark_passed, lambda now=None: marked.append(1)
assert (g.PASSER_MIN_M, g.PASSER_M, g.IDLE_CLEAR_M) == (0.8, 6.0, 0.8)
saved, arm["at"] = arm["at"], "wave_start"
done.clear()
assert not g.passer_wave() and not done # nobody there
assert not g.passer_due()
near["m"] = 0.5
assert not g.passer_wave() and not done and not g.passer_due() # someone right by the arm: no stop, no wave
near["m"] = 1.2
assert g.passer_due() # just over 1 m: a stop and a wave
near["m"] = 0.75
assert not g.passer_due() # within IDLE_CLEAR_M 0.8: no stop
near["m"] = 0.9
assert g.passer_due() # just over 0.8 m: a stop and a wave
near["m"] = g.PASSER_M + 0.5
assert not g.passer_due() # too far
near["m"] = 2.0
assert g.passer_wave() and done.count("swing") == g.IDLE_SWINGS
assert g.passer_wave() and done.count("swing") == g.IDLE_SWINGS and marked == [1] # remembered as waved at
time.sleep(0.2) # the head turns in the background
assert "head +20" in done and done[-1] == "head +0" # to them, then ahead again for the drive
arm["at"], near["m"] = "look", 2.0
assert not g.passer_wave() # the hand is not up
arm["at"] = saved
done.clear()
g._mark_passed = real_mark
g._new_passer = real_new # the module's own again
# each person once: someone waved at is not new again while in view, and new again after GONE_S out of view
import numpy as np # noqa: E402
from vision import reid # noqa: E402
img = np.zeros((200, 200, 3), np.uint8)
img[:, :100] = (200, 30, 30)
img[:, 100:] = (30, 200, 30)
red, green = reid.look(img, (0, 0, 100, 200)), reid.look(img, (100, 0, 200, 200))
g._passed.known = []
now = 1000.0
g._seen["head"].update(t=now, people=[(10.0, 2.0, red, None), (-30.0, 7.5, green, None)])
g._seen["torso"].update(t=0.0, people=[])
p = g._new_passer(now)
assert p is not None and p[1] == 2.0, p # the one at 7.5 m is too far
g._mark_passed(now)
assert g._new_passer(now + 0.1) is None # waved at: not new again
g._seen["head"].update(t=now + 3, people=[(5.0, 3.0, red, None), (0.0, 4.0, green, None)])
p = g._new_passer(now + 3)
assert p is not None and p[1] == 4.0, p # the other one came near: new
g._mark_passed(now + 3)
g._seen["head"].update(t=now + 3 + g.GONE_S + 1, people=[(5.0, 3.0, red, None)])
assert g._new_passer(now + 3 + g.GONE_S + 1) is not None # gone longer than GONE_S: waved at again
g._seen["head"].update(t=0.0, people=[])
g._passed.known = []
# the hand held up, someone waves for a moment and stops: GREET_SWINGS swings all the same, then no more
fresh()
@@ -346,14 +397,18 @@ assert done.count("swing") == g.GREET_SWINGS and g._st["owed"] == 0, done
arm["at"] = "look"
done.clear()
# on the charger, the waving over: after HOLD_S the waist back to the front and IDLE_SWINGS swings at once
# on the charger with Welcome, the waving over: after HOLD_S the waist back to the front, the hand held; keep alive
# swings once KEEP_QUIET_S passed since that wave
fresh()
arm["at"] = "wave_start"
g._st.update(up=True, held=False, last_wave=600.0)
g._st.update(up=True, held=False, last_wave=600.0, people_wave=0.0, idle_at=0.0)
real_idle, g._idle = g._idle, (lambda: True)
real_any, g._nearest_any = g._nearest_any, (lambda now=None: None) # never the live camera files
run(600.0 + g.HOLD_S + 0.5, 600.0 + g.HOLD_S + 2.0)
assert done[0] == "waist +0 look None" and done[1:] == ["swing"] * g.IDLE_SWINGS and g._st["held"], done
g._idle = real_idle
assert done == ["waist +0 look None"] and g._st["held"], done
run(600.0 + g.KEEP_QUIET_S + 0.5, 600.0 + g.KEEP_QUIET_S + 2.0)
assert done[1:] == ["swing"] * g.IDLE_SWINGS, done
g._idle, g._nearest_any = real_idle, real_any
arm["at"] = "look"
done.clear()