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:
@@ -146,10 +146,15 @@ Credentials are kept by the project owner.
|
|||||||
|
|
||||||
## Operating modes
|
## Operating modes
|
||||||
|
|
||||||
Set from the dashboard; both are off after every restart.
|
Set from the dashboard or the Lumi app; all are off after every restart. Each works on its own, in any mix
|
||||||
|
(details: [docs/18_MODES.md](docs/18_MODES.md)).
|
||||||
|
|
||||||
- **Greeter:** Lumi stays in place and converses.
|
- **Greeter:** Lumi stays in place and does everything but drive: converses, sings, gestures.
|
||||||
- **Patrol:** all capabilities, including navigation and manipulation.
|
- **Patrol:** all capabilities, including navigation and manipulation.
|
||||||
|
- **Wave:** drives with its hand raised and stops to wave at each person on the way once, waves back at people who
|
||||||
|
wave; alone it only waves, it does not talk.
|
||||||
|
- **Welcome:** on the charger the hand stays raised; it waves at people who come into view and at people who wave.
|
||||||
|
- Wave and Welcome keep Lumi visibly alive: after 30 s without a wave it waves (at home every 15 s).
|
||||||
- **STOP:** halts the base, arm, body and assistant immediately.
|
- **STOP:** halts the base, arm, body and assistant immediately.
|
||||||
|
|
||||||
## Safety
|
## Safety
|
||||||
@@ -331,10 +336,15 @@ docs/, tools/ 문서와 운영 도구
|
|||||||
|
|
||||||
## 동작 모드
|
## 동작 모드
|
||||||
|
|
||||||
대시보드에서 설정하며, 재시작 후에는 모두 꺼진 상태입니다.
|
대시보드나 Lumi 앱에서 설정하며, 재시작 후에는 모두 꺼진 상태입니다. 각 모드는 단독으로도, 함께도 동작합니다
|
||||||
|
(자세한 내용: [docs/18_MODES.md](docs/18_MODES.md)).
|
||||||
|
|
||||||
- **그리터:** 제자리에서 대화합니다.
|
- **그리터:** 제자리에서 주행 외의 모든 일을 합니다: 대화, 노래, 동작.
|
||||||
- **순찰:** 주행과 조작을 포함한 모든 기능을 사용합니다.
|
- **순찰:** 주행과 조작을 포함한 모든 기능을 사용합니다.
|
||||||
|
- **손 인사(Wave):** 손을 든 채 주행하며 길에서 만난 사람마다 한 번씩 멈춰 손을 흔들고, 손을 흔드는 사람에게 답합니다.
|
||||||
|
이것만 켜져 있으면 말하지 않고 손만 흔듭니다.
|
||||||
|
- **환영(Welcome):** 충전기 위에서 손을 든 채 기다리며, 보이는 사람과 손을 흔드는 사람에게 손을 흔듭니다.
|
||||||
|
- 손 인사와 환영 모드에서는 30초 동안 손을 흔들지 않으면 스스로 흔듭니다(충전기에서는 15초마다).
|
||||||
- **정지(STOP):** 베이스, 팔, 바디, 어시스턴트를 즉시 멈춥니다.
|
- **정지(STOP):** 베이스, 팔, 바디, 어시스턴트를 즉시 멈춥니다.
|
||||||
|
|
||||||
## 안전
|
## 안전
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Lumi's four modes
|
||||||
|
|
||||||
|
Four switches (dashboard, the Lumi app, `POST /assistant/modes`): **Greeter**, **Patrol**, **Wave** (`wave_greet`),
|
||||||
|
**Welcome** (`welcome`). Each works on its own, any mix may be on; `lumi.py` runs while any of them is on and stops
|
||||||
|
when all four are off (the hand comes down first). Owner's rules of 2026-11-16.
|
||||||
|
|
||||||
|
| Mode | What Lumi does |
|
||||||
|
|---|---|
|
||||||
|
| **Greeter** | Stays where it is and does everything except going somewhere: greets people who come close, talks, answers, sings, arm moves, "look at me". An order to go somewhere is refused ("switch on Patrol"). |
|
||||||
|
| **Patrol** | Everything Greeter does, plus drives and whole tasks (go to a point, routes and loops, fetch, missions). |
|
||||||
|
| **Wave** | Alone: the hand is always up in `wave_start` (also on drives, e.g. a dashboard loop of markers); a new person 0.8 to 6 m on the way: stop, 3 waves, drive on (each person once, until they leave the cameras' view); someone waving 1 to 5 m: turn to them and wave back while they wave; keep alive. Near home on the way to the charger it ignores people. With Greeter or Patrol on too: it only answers people who wave (on a drive it stops, raises the hand, waves, lowers it slowly to look, drives on); no waves at everyone, no keep alive. |
|
||||||
|
| **Welcome** | Only on the charger (it can't be switched on elsewhere): waves at each new person 0.8 to 6 m, waves back at people who wave 1 to 5 m, keep alive. |
|
||||||
|
|
||||||
|
**The hand:** on the charger it rests up in `wave_start`, with or without Welcome, and the next moves start from
|
||||||
|
there. Wave alone: always up. Greeter or Patrol on (also with Wave): a drive starts by lowering it slowly to `look`,
|
||||||
|
and the drive and its orders go on from `look`.
|
||||||
|
|
||||||
|
**Talk:** with only Wave and/or Welcome on, Lumi does not talk, take wake words or orders; it only waves. With Greeter
|
||||||
|
or Patrol on too, it greets, talks and does orders; a conversation comes first and the waving waits. Called while
|
||||||
|
driving (Greeter or Patrol), it stops, talks, and drives on to the same place after the conversation.
|
||||||
|
|
||||||
|
**Blocked way:** Lumi says so aloud (also with only Wave on) and tries the same place again until the way is free (a
|
||||||
|
loop, or a Wave trip; a single trip by voice waits for "try again" / "go around it").
|
||||||
|
|
||||||
|
**Keep alive** (part of Wave alone and Welcome, no switch): any wave starts a 30 s count. 30 s without a wave: on the
|
||||||
|
way, Lumi stops, turns toward the nearest person it sees at any distance (else straight ahead), waves 3 times and
|
||||||
|
drives on; at home it does that every 15 s until someone comes into range or waves.
|
||||||
|
|
||||||
|
**Safety:** the arm waves only with the base stopped (it waits for the base to stand), with nobody within 0.8 m
|
||||||
|
(`IDLE_CLEAR_M`), not while holding something, not in a conversation or task; a new drive waits for the swings to end.
|
||||||
|
STOP stops everything and switches Wave and Welcome off. Collision limits in Cobo π are still the defaults: test with
|
||||||
|
someone at STOP.
|
||||||
|
|
||||||
|
Values: `tasks/wave_greet.py` and `assistant/lumi.py`, listed in [TUNING.md](TUNING.md). The same text is in the Lumi
|
||||||
|
app repository, `docs/LUMI_MODES.md`.
|
||||||
+3
-3
@@ -199,7 +199,7 @@ Every value here is a constant at the top of its file, with a comment on what it
|
|||||||
| File | Name | Default | What it does |
|
| File | Name | Default | What it does |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `tasks/wave_greet.py` | `GREET_MIN_M`, `GREET_M` | 1.0 m, 5.0 m | People waving nearer or further away are not answered (camera depth; without depth there, the shoulder width with `SHOULDER_M` 0.36 m) |
|
| `tasks/wave_greet.py` | `GREET_MIN_M`, `GREET_M` | 1.0 m, 5.0 m | People waving nearer or further away are not answered (camera depth; without depth there, the shoulder width with `SHOULDER_M` 0.36 m) |
|
||||||
| `tasks/wave_greet.py` | `PASSER_M` | 5.0 m (`GREET_M`) | A drive's stop and wave for people passing: someone this near and nobody within `IDLE_CLEAR_M` (1 m) |
|
| `tasks/wave_greet.py` | `PASSER_MIN_M`, `PASSER_M`, `IDLE_CLEAR_M` | 0.8 m, 6.0 m, 0.8 m | Wave: a drive's stop and wave for someone new passing this near (each person once, `_passed`, forgotten `GONE_S` after they leave the view); Welcome: the same range at home; nobody within `IDLE_CLEAR_M` when a wave starts (owner, 2026-11-16; was 1 m) |
|
||||||
| `vision/waving.py` | `FLOW_PX`, `FLOW_SHOULDER_PX` | 1.0 px, 80 px | Hand flow per frame that counts as a swing, for a person this wide at the shoulders; smaller (further) people need proportionally less |
|
| `vision/waving.py` | `FLOW_PX`, `FLOW_SHOULDER_PX` | 1.0 px, 80 px | Hand flow per frame that counts as a swing, for a person this wide at the shoulders; smaller (further) people need proportionally less |
|
||||||
| `tasks/wave_greet.py` | `GONE_S` | 10 s | A greeted person out of both cameras' view this long is forgotten: their next wave gets an introduction again |
|
| `tasks/wave_greet.py` | `GONE_S` | 10 s | A greeted person out of both cameras' view this long is forgotten: their next wave gets an introduction again |
|
||||||
| `tasks/wave_greet.py` | `HOLD_S` | 15 s | The waist stays on the last person who waved this long, then turns back to its rest; the hand stays up and the idle swings start at once |
|
| `tasks/wave_greet.py` | `HOLD_S` | 15 s | The waist stays on the last person who waved this long, then turns back to its rest; the hand stays up and the idle swings start at once |
|
||||||
@@ -210,8 +210,8 @@ Every value here is a constant at the top of its file, with a comment on what it
|
|||||||
| `robot/gripper.py` | `FITTED` | False | The gripper is on the flange; while it is off AI_1 floats and is never read as closed or holding. True when it is back on |
|
| `robot/gripper.py` | `FITTED` | False | The gripper is on the flange; while it is off AI_1 floats and is never read as closed or holding. True when it is back on |
|
||||||
| `tasks/wave_greet.py` | `NEW_WAVE_S` | 5 s | No waving this long: the next wave gets a new greeting line |
|
| `tasks/wave_greet.py` | `NEW_WAVE_S` | 5 s | No waving this long: the next wave gets a new greeting line |
|
||||||
| `tasks/wave_greet.py` | `JOKE_AFTER_S`, `JOKE_EVERY_S` | 10 s, 12 s | Waving on and on: the first joke after this long, then one every this long |
|
| `tasks/wave_greet.py` | `JOKE_AFTER_S`, `JOKE_EVERY_S` | 10 s, 12 s | Waving on and on: the first joke after this long, then one every this long |
|
||||||
| `tasks/wave_greet.py`, `assistant/lumi.py` | `IDLE_WAVE_EVERY_S`, `IDLE_SWINGS`, `IDLE_AFTER_S` | 15 s, 3, 15 s | On the charger with the wave greeting on and nothing said to Lumi for `IDLE_AFTER_S`: the hand goes up and stays up, this many swings every `IDLE_WAVE_EVERY_S`; a call stops the swings (the hand stays up), a drive or an arm order takes it down. Estimates |
|
| `tasks/wave_greet.py` | `KEEP_QUIET_S`, `IDLE_WAVE_EVERY_S`, `IDLE_SWINGS` | 30 s, 15 s, 3 | Keep alive (owner, 2026-11-16): Wave on the way, `KEEP_QUIET_S` without a swing: the base stops, this many swings toward the nearest person at any distance (else ahead), drives on. Welcome on the charger: the hand up at once and held; `KEEP_QUIET_S` after the last wave at people (and nothing said to Lumi), these swings every `IDLE_WAVE_EVERY_S` |
|
||||||
| `assistant/lumi.py` | `PASSER_WAVE_EVERY_S`, `PASSER_MARKERS`, `DOCK_QUIET_M` | 15 s, "line", 2 m | With the wave greeting on, the empty arm drives with the hand up (`wave_start`). On the way to markers whose names start with `PASSER_MARKERS`, and on every leg of a there-and-back route loop, the base stops for anyone 1–5 m away and waves (`PASSER_M`); to other markers only for someone waving; at most every `PASSER_WAVE_EVERY_S`; never nearer than `DOCK_QUIET_M` to the dock (a stop there undoes the docking). Estimates |
|
| `assistant/lumi.py` | `PASSER_WAVE_EVERY_S`, `DOCK_QUIET_M` | 5 s, 2 m | With Wave on, the empty arm drives with the hand up (`wave_start`); every drive (a point, a route, a loop) stops for someone new passing (`PASSER_M`) and for keep alive; at most every `PASSER_WAVE_EVERY_S` (a stop that could not wave does not repeat at once); never on the dock leg or nearer than `DOCK_QUIET_M` to the dock (a stop there undoes the docking). `PASSER_MARKERS` is no longer used |
|
||||||
| `assistant/lumi.py` | `PASSER_MAX_M`, `PASSER_EVERY_S`, `PASSER_DEG` | 4 m, 2 s, 10° | On the charger with nobody talking to Lumi: the head turns to the nearest person this near, at most this often, when they are this far off where it looks (the body stays). Estimates |
|
| `assistant/lumi.py` | `PASSER_MAX_M`, `PASSER_EVERY_S`, `PASSER_DEG` | 4 m, 2 s, 10° | On the charger with nobody talking to Lumi: the head turns to the nearest person this near, at most this often, when they are this far off where it looks (the body stays). Estimates |
|
||||||
| `tasks/wave_greet.py` | `WAIST_MAX_DEG` | 30° | The waist turns toward a waving person this far from the front at most; the head covers the rest. Estimate |
|
| `tasks/wave_greet.py` | `WAIST_MAX_DEG` | 30° | The waist turns toward a waving person this far from the front at most; the head covers the rest. Estimate |
|
||||||
| `tasks/wave_greet.py` | `WAIST_MIN_DEG` | 10° | A person nearer the front than this: only the head turns, not the waist |
|
| `tasks/wave_greet.py` | `WAIST_MIN_DEG` | 10° | A person nearer the front than this: only the head turns, not the waist |
|
||||||
|
|||||||
@@ -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")
|
||||||
@@ -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")
|
||||||
@@ -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")
|
||||||
@@ -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")
|
||||||
@@ -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
|
# 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}))
|
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
|
# idle, Patrol on: allowed
|
||||||
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": True}))
|
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": True}))
|
||||||
|
|||||||
+16
-8
@@ -239,7 +239,7 @@ assert lumi.waist_home("test") is False
|
|||||||
# also with the waist at the front already
|
# also with the waist at the front already
|
||||||
went = []
|
went = []
|
||||||
real_plan, real_move, real_lower = lumi.arm_route.plan, lumi.arm_route.move, lumi.wave_greet.lower
|
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])
|
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"})
|
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
|
assert lumi.waist_home("drive", fold=True) and went == ["look"], went
|
||||||
@@ -269,19 +269,23 @@ order.clear()
|
|||||||
P = lumi.Patrol(["p3"])
|
P = lumi.Patrol(["p3"])
|
||||||
P.tick(force=True)
|
P.tick(force=True)
|
||||||
assert order == ["waist", ("go", "home")] and P.mode == "going_home", order
|
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}
|
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_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), \
|
lumi.wave_greet_on, lumi.wave_greet.passer_due, lumi.wave_greet._waver = (lambda: True), (lambda: True), \
|
||||||
(lambda: False)
|
(lambda: False)
|
||||||
for passers, stops in ((True, True), (False, False)):
|
for route, passers, stops in ((["p1", "p2"], True, True), (["p3"], False, True), ([(1.0, 2.0, 0.0)], False, True),
|
||||||
P = lumi.Patrol(["p1", "p2"], passers=passers)
|
(["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.moving, P.hand_up, P.passer_wave = True, True, (lambda: None)
|
||||||
P.pause = lambda: order.append("pause")
|
P.pause = lambda: order.append("pause")
|
||||||
order.clear()
|
order.clear()
|
||||||
P.tick(force=True)
|
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_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}
|
lumi.agv.status = lambda: {"move_status": "idle", "power_percent": 90}
|
||||||
L.modes.patrol = True
|
L.modes.patrol = True
|
||||||
real_turned, lumi.waist_turned = lumi.waist_turned, lambda: 30.0 # turned 30 left for someone
|
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))
|
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)
|
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 ----------
|
# it, with a drive running, a task, a cup or the hand out: nothing moves ----------
|
||||||
turned, arm_at = [], {"now": "rest"}
|
turned, arm_at = [], {"now": "rest"}
|
||||||
real_waist_to, real_at_pose, real_state = fetch._waist_to, fetch._at_pose, fetch.state
|
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_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._waist_to = lambda rel, in_place=False, look=None: turned.append(("waist", rel)) or True
|
||||||
fetch._at_pose = lambda name: name == arm_at["now"]
|
fetch._at_pose = lambda name: name == arm_at["now"]
|
||||||
lumi.arm_route.rest_pose = lambda holding=False: "rest"
|
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])
|
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"}
|
fetch.state = lambda: {"status": "idle"}
|
||||||
for st, at, want in (({"charge_state": True, "move_status": "succeeded"}, "rest",
|
for st, at, want in (({"charge_state": True, "move_status": "succeeded"}, "rest",
|
||||||
[("arm", "look", lumi.HOME_ARM_SPEED), ("waist", lumi.HOME_WAIST_DEG)]),
|
[("arm", "wave_start", 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": "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": True, "move_status": "running"}, "rest", []), # leaving the charger
|
||||||
({"charge_state": False, "move_status": "idle"}, "rest", []), # not at home
|
({"charge_state": False, "move_status": "idle"}, "rest", []), # not at home
|
||||||
({"charge_state": True, "move_status": "idle"}, "give", [])): # the hand held out
|
({"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
|
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
|
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.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 ------
|
# ---------- on the charger the body stays turned to its rest: someone speaking or calling turns the head only ------
|
||||||
moves = []
|
moves = []
|
||||||
|
|||||||
+108
-53
@@ -227,65 +227,83 @@ done.clear()
|
|||||||
g.lower() # the hand is down: nothing moves
|
g.lower() # the hand is down: nothing moves
|
||||||
assert done == [], done
|
assert done == [], done
|
||||||
|
|
||||||
# nothing asked for a while on the charger (_idle): the hand goes up and stays up, no words; 2 swings every
|
# Welcome (owner, 2026-11-16): switched on, the hand goes up to wave_start at once and stays, no swings yet, no words;
|
||||||
# IDLE_WAVE_EVERY_S while nobody talks; a call stops them (the hand still up); a drive brings it down (lower); someone
|
# 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
|
||||||
# waving is greeted as always
|
# 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()
|
fresh()
|
||||||
waver["w"] = None
|
waver["w"] = None
|
||||||
g._idle, g._rest_arm = (lambda: True), (lambda: "look")
|
g._welcome, g._home, g._idle, g._rest_arm = (lambda: True), (lambda: False), (lambda: False), (lambda: "look")
|
||||||
g._someone_within = lambda m: True # someone right by the arm: no idle wave, tried again later
|
g._someone_within = lambda m: True
|
||||||
g._st["idle_at"] = 0.0
|
|
||||||
run(690.0, 690.0)
|
run(690.0, 690.0)
|
||||||
assert done == [], done
|
assert done == [], done
|
||||||
g._someone_within = lambda m: False
|
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)
|
run(691.0, 691.0)
|
||||||
assert done == [], done
|
assert done == ["up route"] and g._st["up"] and g._st["held"] and said == [], (done, said)
|
||||||
arm["at"] = "look"
|
run(691.5, 700.0)
|
||||||
g._st["idle_at"] = 700.0 # the last idle wave
|
assert done == ["up route"], done # held up, still: nobody new, keep alive not allowed
|
||||||
run(700.0, 700.0 + g.IDLE_WAVE_EVERY_S - 1)
|
g._home = lambda: True
|
||||||
assert done == [] and said == [], done # not before IDLE_WAVE_EVERY_S
|
person, marked = {"p": (25.0, 3.0, None, None)}, []
|
||||||
run(700.0 + g.IDLE_WAVE_EVERY_S + 0.5, 700.0 + g.IDLE_WAVE_EVERY_S + 0.5)
|
real_new, real_mark = g._new_passer, g._mark_passed
|
||||||
assert done == ["up route"] + ["swing"] * g.IDLE_SWINGS and said == [] and g._st["up"] and g._st["held"], (done, said)
|
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()
|
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
|
talk = {"on": True} # someone talks to Lumi: no swings, the hand stays up, still
|
||||||
g._idle = lambda: not talk["on"]
|
g._idle = lambda: not talk["on"]
|
||||||
done.clear()
|
g._home = lambda: not talk["on"]
|
||||||
run(1000.0, 1100.0)
|
run(1000.0, 1100.0)
|
||||||
assert done == [] and g._st["up"], done
|
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
|
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
|
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()
|
done.clear()
|
||||||
said.clear() # someone waves back during an idle wave: greeted as always,
|
g._welcome = lambda: False # Welcome off: nothing goes up by itself on the charger
|
||||||
real_waver, g._waver = g._waver, (lambda: W(20.0)) # the hand stays up and swings on
|
g._idle = g._home = lambda: True
|
||||||
arm["at"], g._st["idle_at"], g._st["up"] = "look", 0.0, False
|
run(1200.0, 1300.0)
|
||||||
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
|
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
|
# 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
|
# 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)
|
run(621.0, 621.0)
|
||||||
assert said[-1] in sum(g.wave_lines.INTRO, ()), said
|
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}
|
near = {"m": None}
|
||||||
|
marked = []
|
||||||
waver["w"] = None
|
waver["w"] = None
|
||||||
g._someone_within = lambda m: near["m"] is not None and near["m"] < m
|
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"
|
saved, arm["at"] = arm["at"], "wave_start"
|
||||||
done.clear()
|
done.clear()
|
||||||
assert not g.passer_wave() and not done # nobody there
|
assert not g.passer_wave() and not done # nobody there
|
||||||
assert not g.passer_due()
|
assert not g.passer_due()
|
||||||
near["m"] = 0.5
|
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
|
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
|
near["m"] = 0.75
|
||||||
assert g.passer_due() # just over 1 m: a stop and a wave
|
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
|
near["m"] = g.PASSER_M + 0.5
|
||||||
assert not g.passer_due() # too far
|
assert not g.passer_due() # too far
|
||||||
near["m"] = 2.0
|
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
|
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
|
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
|
arm["at"], near["m"] = "look", 2.0
|
||||||
assert not g.passer_wave() # the hand is not up
|
assert not g.passer_wave() # the hand is not up
|
||||||
arm["at"] = saved
|
arm["at"] = saved
|
||||||
done.clear()
|
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
|
# the hand held up, someone waves for a moment and stops: GREET_SWINGS swings all the same, then no more
|
||||||
fresh()
|
fresh()
|
||||||
@@ -346,14 +397,18 @@ assert done.count("swing") == g.GREET_SWINGS and g._st["owed"] == 0, done
|
|||||||
arm["at"] = "look"
|
arm["at"] = "look"
|
||||||
done.clear()
|
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()
|
fresh()
|
||||||
arm["at"] = "wave_start"
|
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_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)
|
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
|
assert done == ["waist +0 look None"] and g._st["held"], done
|
||||||
g._idle = real_idle
|
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"
|
arm["at"] = "look"
|
||||||
done.clear()
|
done.clear()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user