Keep the hand raised on the charger with steady greeting waves
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Self-check of the wave greeting (tasks/wave_greet.py) with a fake arm, head, waist and speech, no robot, and of the
|
||||
waving detector (vision/waving.py) on the recordings of vision/wave_record.py when they are here (tests/data/waves,
|
||||
local only: people in the pictures): python tests/test_wave_greet.py"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
@@ -87,11 +88,11 @@ def fresh():
|
||||
plan_error["e"] = None
|
||||
|
||||
|
||||
# someone waves 30 deg on the left at 2 m: head to them, a greeting, arm up at the route speed, one swing, waist to them
|
||||
# someone waves 30 deg on the left at 2 m: head to them, a greeting, arm up at the route speed, GREET_SWINGS swings, waist to them
|
||||
fresh()
|
||||
waver["w"] = W(30.0)
|
||||
run(100.0, 100.0)
|
||||
assert done == ["head +30", "up route", "swing", "waist +30 look 30.0"], done
|
||||
assert done == ["head +30", "up route"] + ["swing"] * g.GREET_SWINGS + ["waist +30 look 30.0"], done
|
||||
assert len(said) == 1 and said[0] in sum(g.wave_lines.INTRO, ()), said # someone new: Lumi introduces itself
|
||||
assert g.busy()
|
||||
|
||||
@@ -132,16 +133,16 @@ said.clear()
|
||||
run(115.5, 116.0)
|
||||
assert done.count("swing") == 1 and said == [], (done, said)
|
||||
|
||||
# nobody waves for HOLD_S: arm down slowly, waist to the front, head to rest; not before
|
||||
# nobody waves for HOLD_S: the waist to the front, the hand stays up (held); not before
|
||||
waver["w"] = None
|
||||
done.clear()
|
||||
run(116.5, 116.0 + g.HOLD_S - 1)
|
||||
assert done == [], done
|
||||
run(116.0 + g.HOLD_S + 0.5, 116.0 + g.HOLD_S + 0.5)
|
||||
assert done == ["waist +0 look None", "down normal", "head +0 rest"], done
|
||||
assert not g.busy() and arm["at"] == "look"
|
||||
assert done == ["waist +0 look None"], done
|
||||
assert not g.busy() and arm["at"] == "wave_start" and g._st["up"] and g._st["held"]
|
||||
|
||||
# the waist's way back is blocked: the arm still goes down; the waist is tried again every REFUSED_S while nobody waves
|
||||
# the waist's way back is blocked: the hand stays up there, held
|
||||
fresh()
|
||||
waver["w"] = W(30.0)
|
||||
run(150.0, 150.0)
|
||||
@@ -151,7 +152,7 @@ fetch._waist_to = lambda rel, in_place=False, look=None: done.append(f"waist {re
|
||||
blocked.update(n=blocked["n"] - 1) or False if blocked["n"] > 0 else True)
|
||||
done.clear()
|
||||
run(150.5 + g.HOLD_S, 150.5 + g.HOLD_S + g.REFUSED_S * 2.5)
|
||||
assert done[:3] == ["waist +0", "down normal", "head +0 rest"] and done[3:] == ["waist +0"], done
|
||||
assert done == ["waist +0"] and g._st["held"] and g._st["waist_out"], done
|
||||
fetch._waist_to = lambda rel, in_place=False, look=None: done.append(f"waist {rel:+.0f} look {look}") or True
|
||||
|
||||
# beside a wall the full waist turn is blocked: it turns as far as its sweep is clear, the head on the person
|
||||
@@ -166,7 +167,7 @@ fetch._waist_to = lambda rel, in_place=False, look=None: done.append(f"waist {re
|
||||
fresh()
|
||||
waver["w"] = W(5.0)
|
||||
run(200.0, 200.0)
|
||||
assert done == ["up route", "swing"], done # the head looks there already (within HEAD_MIN_DEG)
|
||||
assert done == ["up route"] + ["swing"] * g.GREET_SWINGS, done # the head looks there already (within HEAD_MIN_DEG)
|
||||
|
||||
# the switch is turned off with the hand up: down at once
|
||||
switch["on"] = False
|
||||
@@ -310,7 +311,7 @@ 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 GREET_M, nobody by the arm
|
||||
# a loop patrol's wave for people passing: only with the hand up, someone within PASSER_M, nobody by the arm
|
||||
near = {"m": None}
|
||||
waver["w"] = None
|
||||
g._someone_within = lambda m: near["m"] is not None and near["m"] < m
|
||||
@@ -329,8 +330,21 @@ assert not g.passer_wave() # the hand is not up
|
||||
arm["at"] = saved
|
||||
done.clear()
|
||||
|
||||
# the hand held up, someone waves for a moment and stops: GREET_SWINGS swings all the same, then no more
|
||||
fresh()
|
||||
arm["at"] = "wave_start"
|
||||
g._st.update(up=True, held=True, idle_at=1e9)
|
||||
waver["w"] = W(10.0)
|
||||
run(400.0, 400.0)
|
||||
waver["w"] = None
|
||||
run(400.5, 420.0)
|
||||
assert done.count("swing") == g.GREET_SWINGS and g._st["owed"] == 0, done
|
||||
arm["at"] = "look"
|
||||
done.clear()
|
||||
|
||||
# a hand at the head (scratching, a phone at the ear) is not a raised hand; the same hand held out to the side is
|
||||
import numpy as np # noqa: E402
|
||||
import cv2 # noqa: E402
|
||||
kp = np.zeros((17, 3))
|
||||
for name, xy in (("nose", (640, 200)), ("left_eye", (650, 190)), ("right_eye", (630, 190)), ("left_shoulder", (700, 320)),
|
||||
("right_shoulder", (580, 320)), ("right_elbow", (560, 260)), ("right_wrist", (600, 210))):
|
||||
@@ -353,6 +367,18 @@ if DATA.exists():
|
||||
assert first < 2.0, (f.name, first) # found within 2 s
|
||||
if f.name != "pause_2m": # (it stops waving half way)
|
||||
assert sum(seen) > 0.75 * len(seen), (f.name, sum(seen), len(seen))
|
||||
for name in ("right_3m", "left_3m"): # the same waves shrunk to 10 m: still found
|
||||
w, n, hit, k = waving.Watcher(), 0, 0, 3 / 10
|
||||
for line in open(DATA / f"{name}.jsonl"):
|
||||
d = json.loads(line)
|
||||
g = cv2.imread(str(DATA / name / f"{d['n']:04d}.jpg"), cv2.IMREAD_GRAYSCALE)
|
||||
far = np.full_like(g, 128)
|
||||
small = cv2.resize(g, None, fx=k, fy=k, interpolation=cv2.INTER_AREA)
|
||||
far[:small.shape[0], :small.shape[1]] = small
|
||||
n += 1
|
||||
hit += any(v for _, v in w.update(d["t"], far, [{**p, "kp": np.array(p["kp"]) * [k, k, 1]}
|
||||
for p in d["people"]]))
|
||||
assert hit > 0.75 * n, (name, hit, n)
|
||||
r = waving.run_recording(DATA / "pause_2m") # stopped at ~6 s: no longer waving 2.5 s later
|
||||
assert not any(any(w) for t, w in r if t - r[0][0] > 8.5)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user