Turn the waist with the arm on a hand-over, recover stopped picks and improve follow tracking
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,4 +60,27 @@ try:
|
||||
raise AssertionError("went to a wave pose holding")
|
||||
except arm_route.RouteError as e:
|
||||
assert e.args == arm_route.SPILL, e.args
|
||||
|
||||
# ---------- give_pre taught: an empty-hand way to give always ends give_pre -> give, the last move slow ----------
|
||||
POSES["give_pre"] = moved(POSES["give"], 4, 20) # give with J5 20 deg further (a stand-in)
|
||||
for start in ("look", "wave_start", "wave", "carry", "ready", "wave_out", "give_pre"):
|
||||
route = names("give", POSES[start])
|
||||
assert route[-2:] == ["give_pre", "give"] or start == "give_pre" and route == ["give"], (start, route)
|
||||
assert route.count("give") == 1, (start, route) # never through give on the way to give_pre
|
||||
assert names("give", POSES["give"]) == [] # there already: nothing moves
|
||||
assert names("give", moved(POSES["give"], 4, 2)) == ["give"] # at give within AT_POSE_DEG: as before
|
||||
assert names("give", moved(POSES["carry"], 0, -30))[-2:] == ["give_pre", "give"] # a join from far too
|
||||
assert names("give", POSES["look"], holding=True) == ["carry", "give"] # holding: give_pre not used
|
||||
assert "give_pre" not in arm_route.graph(holding=True)
|
||||
assert names("look", POSES["give"]) == ["look"] # other targets as before
|
||||
sent = []
|
||||
real_path, motion.move_path = motion.move_path, lambda moves, **k: sent.extend(moves)
|
||||
arm_route.move(arm_route.plan("give", now=list(POSES["wave_start"])))
|
||||
assert [s for _, s in sent][-1] == arm_route.GIVE_SPEED and \
|
||||
all(s == arm_route.SPEED for _, s in sent[:-1]), sent # the last move, give_pre -> give, slow
|
||||
del POSES["give_pre"] # not taught: the route and speed as before
|
||||
sent.clear()
|
||||
arm_route.move(arm_route.plan("give", now=list(POSES["wave_start"])))
|
||||
assert [s for _, s in sent] == [arm_route.SPEED], sent
|
||||
motion.move_path = real_path
|
||||
print("arm give route ok")
|
||||
|
||||
@@ -171,7 +171,7 @@ class Patrol:
|
||||
|
||||
|
||||
class Modes:
|
||||
patrol, drive = True, True
|
||||
patrol = True
|
||||
|
||||
|
||||
L = lumi.Lumi.__new__(lumi.Lumi)
|
||||
|
||||
+8
-6
@@ -979,8 +979,9 @@ ahead = lambda mm, side=0.0: [g0[0] + mm, g0[1] + side, g0[2]]
|
||||
scene["person_in_front"] = {"position_mm": ahead(900.0), "hands": {"left": {"position_mm": ahead(600.0, 100.0),
|
||||
"distance_m": 1.1}, "right": {"position_mm": ahead(400.0), "distance_m": 0.9}}}
|
||||
turns = []
|
||||
real_waist_to = fetch._waist_to
|
||||
fetch._waist_to = lambda deg, in_place=False, look=None: turns.append(deg) or in_place and deg < 90 # in place
|
||||
real_blocked, real_route_points = fetch._sweep_blocked, fetch._route_points
|
||||
fetch._sweep_blocked = lambda deg, what, pts=None: turns.append(deg) or deg >= 90 # the waist turn with the arm
|
||||
fetch._route_points = lambda seq: []
|
||||
|
||||
|
||||
def reached(angle=0.0):
|
||||
@@ -1005,8 +1006,8 @@ scene["person_in_front"] = None
|
||||
st, moves = reached()
|
||||
assert st["status"] == "done" and poses()[-1] == "give" and not moves, (st, moves)
|
||||
fetch.stay_put = True # Greeter only: the waist still turns (the base stays)
|
||||
st, moves = reached(40.0) # to the side: the waist turns first, by the
|
||||
assert turns == [40.0 + fetch._waist_turn()] and poses()[-1] == "give", (turns, poses()) # waist's offset too
|
||||
st, moves = reached(40.0) # to the side: the waist turns with the arm
|
||||
assert turns == [40.0] and poses()[-1] == "give", (turns, poses())
|
||||
fetch.stay_put = False
|
||||
turns.clear()
|
||||
said.clear()
|
||||
@@ -1015,7 +1016,7 @@ assert st["status"] == "failed" and not poses() and said[-1] == fetch.TURN_TO_PE
|
||||
turns.clear()
|
||||
st, moves = reached(160.0) # past the waist's limit (-15 + 160 > 140): stand in front
|
||||
assert st["status"] == "failed" and not turns and not poses() and said[-1] == fetch.TURN_TO_PERSON[0], (st, turns)
|
||||
fetch._waist_to = real_waist_to
|
||||
fetch._sweep_blocked = real_blocked
|
||||
# the head on the person through the whole reach (live: the waist turned with the head kept at +46 on it, so the
|
||||
# head looked 90 deg left, away, until head_ahead at the end): Greeter only, person at -40 deg (waist frame), the
|
||||
# head on them; the sweep check turns the head to that side (head_hits); every head command looks their way, the
|
||||
@@ -1028,7 +1029,7 @@ def head_cmd(pos, **kw):
|
||||
hp.update(waist=pos[1], yaw=pos[2], pitch=pos[3])
|
||||
gaze.append(pos[1] + 15.0 + pos[2])
|
||||
fetch.head.moveto = head_cmd
|
||||
fetch._sweep_blocked = lambda deg, what: head_cmd([75.0, hp["waist"], math.copysign(fetch.HEAD_SIDE_DEG, deg),
|
||||
fetch._sweep_blocked = lambda deg, what, pts=None: head_cmd([75.0, hp["waist"], math.copysign(fetch.HEAD_SIDE_DEG, deg),
|
||||
fetch.HEAD_LOW_PITCH]) and False
|
||||
fetch.stay_put = True
|
||||
st, moves = reached(-40.0)
|
||||
@@ -1040,6 +1041,7 @@ st, moves = reached(0.0) # in front: no wai
|
||||
assert st["status"] == "done" and not gaze and hp["yaw"] == 0.0, gaze
|
||||
fetch.stay_put = False
|
||||
fetch.head.status, fetch.head.moveto, fetch._sweep_blocked = real_status, real_move, real_blocked
|
||||
fetch._route_points = real_route_points
|
||||
fetch._line_rows, fetch._scene = real_line_rows, real_scene
|
||||
hand["front"] = False
|
||||
# the cup is in the hand but nobody says okay: the hand never closes (their fingers may be in it)
|
||||
|
||||
@@ -232,12 +232,12 @@ placed = {"at": None}
|
||||
real_place_at = fetch._place_at
|
||||
|
||||
|
||||
def place_at(tries, top):
|
||||
def place_at(tries, top, **kw):
|
||||
for p in tries:
|
||||
if col(*p) <= REACH_MM:
|
||||
placed["at"] = p
|
||||
break
|
||||
return real_place_at(tries, top)
|
||||
return real_place_at(tries, top, **kw)
|
||||
|
||||
|
||||
skills.reachable_pick = reachable
|
||||
@@ -405,4 +405,65 @@ room["cups"].append({"id": 1, "map": np.array([0.15, 0.85])})
|
||||
st = run(fetch.start, TASK)
|
||||
fetch._look_around = real_around
|
||||
assert st["status"] == "holding" and any("near me at +90 deg" in l for l in st["log"]), st["log"]
|
||||
# ---------- 2026-10-29 13:50: "take the cup" (voice pick) held it just above the table, "stop", then "put the cup on
|
||||
# the table": straight back down where it was picked, never to look first ----------
|
||||
setup(None, table=(0.355, 1.6, -1.0, 1.0))
|
||||
room["holding"] = {"id": 9, "map": None}
|
||||
fetch._set(holding=True, status="holding", held_object={"object": "cup", "colour": "white"})
|
||||
skills._held.update(top_mm=-186.0, x=108.0, y=603.0, yaw=-15.0, table=-330.0, what={"object": "cup"})
|
||||
fetch._note_stand() # as pick_here leaves it
|
||||
lifted = skills.up(skills.plan_place(108.0, 603.0, -186.0, yaw=-15.0)[1][1], skills.LIFT_MM - skills.PLACE_EXTRA_MM)
|
||||
real_tcp, real_holding, real_place = fetch.motion.tcp, fetch._line_holding, skills._do_place
|
||||
fetch.motion.tcp = lambda: list(lifted)
|
||||
arm["j"] = [5.0] * 6 # over the table, not at look
|
||||
fetch._line_holding = lambda name: (log.append(("line", name)), real_holding(name))[1]
|
||||
skills._do_place = lambda wp: (do_place(wp), arm.update(j=[0.0] * 6))[0] # the real one ends at look
|
||||
st = run(fetch.place, None, {"name": "dining table", "colour": None})
|
||||
done = [l for l in log if l[0] == "place"]
|
||||
assert st["status"] == "done" and done == [("place", 108, 603)], (st["log"], log)
|
||||
assert ("line", "look") not in log and not any("arm to look" in l for l in st["log"]), (st["log"], log)
|
||||
# ... the base moved since the pick: the usual search from look
|
||||
setup(None, table=(0.355, 1.6, -1.0, 1.0))
|
||||
room["holding"] = {"id": 9, "map": None}
|
||||
fetch._set(holding=True, status="holding", held_object={"object": "cup", "colour": "white"})
|
||||
skills._held.update(top_mm=-186.0, x=108.0, y=603.0, yaw=-15.0, table=-330.0, what={"object": "cup"})
|
||||
fetch._note_stand()
|
||||
base["pose"] = (0.1, 0.0, 0.0)
|
||||
arm["j"] = [5.0] * 6
|
||||
fetch._line_holding = lambda name: (log.append(("line", name)), arm.update(j=[0.0] * 6))
|
||||
run(fetch.place)
|
||||
assert log and log[0] == ("line", "look"), log
|
||||
fetch.motion.tcp, fetch._line_holding, skills._do_place = real_tcp, real_holding, real_place
|
||||
arm["j"] = [0.0] * 6
|
||||
print("held over the pick spot after a stop: put straight back down at", done[0][1:])
|
||||
# ... the STOP came in the 30 mm lift of the voice pick itself (pick_here), the fingers already holding it: the same
|
||||
setup((108.0, 603.0), table=(0.355, 1.6, -1.0, 1.0))
|
||||
def stopped_in_lift(obj, wp, ja): # _do_pick holds it (skills._held) from the close on
|
||||
do_pick(obj, wp, ja)
|
||||
raise skills.SkillError("Stopped.")
|
||||
real_back_out, skills._do_pick = skills.back_out, stopped_in_lift
|
||||
skills.back_out = lambda: log.append(("back out",))
|
||||
fetch.stay_put = True
|
||||
try:
|
||||
fetch.pick_here("cup", None)
|
||||
raise AssertionError("not stopped")
|
||||
except skills.SkillError:
|
||||
pass
|
||||
fetch.stay_put = False
|
||||
skills._do_pick, skills.back_out = do_pick, real_back_out
|
||||
assert log[0] == ("back out",) and skills._held.get("base") is not None, (log, skills._held) # out first; stand noted
|
||||
fetch._set(holding=True, status="holding", held_object={"object": "cup", "colour": None})
|
||||
h = skills._held
|
||||
lifted = skills.up(skills.plan_place(h["x"], h["y"], h["top_mm"])[1][1], skills.LIFT_MM / 2 - skills.PLACE_EXTRA_MM)
|
||||
fetch.motion.tcp = lambda: list(lifted)
|
||||
arm["j"] = [5.0] * 6
|
||||
log.clear()
|
||||
fetch._line_holding = lambda name: (log.append(("line", name)), real_holding(name))[1]
|
||||
skills._do_place = lambda wp: (do_place(wp), arm.update(j=[0.0] * 6))[0]
|
||||
st = run(fetch.place, None, {"name": "dining table", "colour": None})
|
||||
assert st["status"] == "done" and [l for l in log if l[0] == "place"] == [("place", 108, 603)], (st["log"], log)
|
||||
assert ("line", "look") not in log, log
|
||||
fetch.motion.tcp, fetch._line_holding, skills._do_place = real_tcp, real_holding, real_place
|
||||
arm["j"] = [0.0] * 6
|
||||
print("stopped in the lift of a voice pick: put straight back down")
|
||||
print("fetch ways ok")
|
||||
|
||||
+53
-13
@@ -507,10 +507,12 @@ assert math.degrees(w.th) > 120.0 and w.dist[-1] < follow.FOLLOW_GAP_M + 0.4, (m
|
||||
print(f"past the side to behind: waist + head up to {max(gaze):.0f} deg, base turned {math.degrees(w.th):.0f} deg, "
|
||||
f"gap {w.dist[-1]:.2f} m")
|
||||
|
||||
# owner, live: the head waited for a slow stepwise waist and lost the person. Now head, waist and base all at once:
|
||||
# the person right behind (170 deg) -> the first move puts head + waist on them (the head not held to HEAD_REL_MAX),
|
||||
# the waist keeps turning move after move while the base turns, the base forward only once they are ahead
|
||||
# owner, live: the head waited for a slow stepwise waist and lost the person. Now the head and the base at once: the
|
||||
# person right behind (170 deg) -> the first move puts the head on them (never held to HEAD_REL_MAX), the waist stays
|
||||
# (it only ever unwinds), the base turns at once, forward only once they are ahead
|
||||
assert follow.waist_for(10.0) == 0.0 and follow.waist_for(-70.0) == -40.0 and follow.waist_for(170.0) == 90.0
|
||||
assert follow.unwind(0.0, 170.0) == 0.0 and follow.unwind(-55.0, -169.0) == -55.0 # never further out
|
||||
assert follow.unwind(60.0, 70.0) == 40.0 and follow.unwind(60.0, 10.0) == 0.0 and follow.unwind(30.0, -90.0) == 0.0
|
||||
|
||||
|
||||
def at(deg, r=2.0):
|
||||
@@ -552,17 +554,16 @@ follow.stop()
|
||||
assert wait_end(0.5)
|
||||
moves = [m for m in body.moves if m[1] == "follow head"]
|
||||
first = moves[0]
|
||||
assert 0.0 < first[3] <= follow.WAIST_STEP_DEG and first[4] > 90.0 and abs(first[3] + first[4] - 170.0) < 10.0, first
|
||||
assert first[3] == 0.0 and first[4] > 90.0 and abs(first[4] - 170.0) < 10.0, first # the head alone on them
|
||||
assert max(abs(s[4]) for s in samples[5:]) < 15.0, max(abs(s[4]) for s in samples[5:]) # gaze on them
|
||||
turning = [s for s in samples if 10.0 < s[3] < 90.0] # the base turning ...
|
||||
assert turning and max(s[1] for s in turning) >= 3 * follow.WAIST_STEP_DEG, turning[:3] # ... the waist too
|
||||
assert all(m[3] == 0.0 for m in moves), moves # the waist stays
|
||||
assert w.cmds[0][2] > 0.0 and w.cmds[0][0] - w.t0 < 0.5, w.cmds[:2] # turning at once
|
||||
assert max(b[0] - a[0] for a, b in zip(w.cmds, w.cmds[1:])) < 0.2 # no tick waits
|
||||
assert ahead and max(abs(a) for a in ahead) <= follow.TURN_ONLY_DEG + 5.0, max(abs(a) for a in ahead)
|
||||
assert abs(body.pos[1]) < 1e-6 and abs(body.pos[2]) <= follow.TURN_DEAD_DEG + follow.HEAD_STEP_DEG, body.pos
|
||||
assert abs(math.degrees(w.th) - 170.0) < 10.0 and w.dist[-1] < follow.FOLLOW_GAP_M + 0.3, (math.degrees(w.th), w.dist[-1])
|
||||
print(f"behind 170 deg: first move waist {first[3]:+.0f} head {first[4]:+.0f}, waist up to "
|
||||
f"{max(s[1] for s in samples):.0f} deg while the base turned, forward only within {max(map(abs, ahead)):.0f} deg")
|
||||
print(f"behind 170 deg: first move head {first[4]:+.0f}, the waist stays, forward only within "
|
||||
f"{max(map(abs, ahead)):.0f} deg")
|
||||
|
||||
# "look behind" turned the waist and the head to the owner, then "follow me": nothing turns away from them
|
||||
said.clear()
|
||||
@@ -579,6 +580,7 @@ print(f"start turned to the owner: gaze off at most {max(abs(s[4]) for s in samp
|
||||
|
||||
# stopped with the waist turned: it comes back to the front (sweep checked), the head to rest
|
||||
body.moves.clear()
|
||||
body.pos = [50.0, 60.0, 10.0, follow.HEAD_PITCH] # on them at 70 deg
|
||||
w = at(70.0)
|
||||
follow.TURN_MAX_RS, turn_max = 0.05, follow.TURN_MAX_RS # a slow base
|
||||
follow.start(w.see, say)
|
||||
@@ -590,6 +592,47 @@ follow.TURN_MAX_RS = turn_max
|
||||
assert body.moves[-1][3:] == (0.0, 0.0, head.HEAD_REST_PITCH), body.moves[-1]
|
||||
print("stopped turned: waist back to the front")
|
||||
|
||||
# live 2026-10-29 14:18: the person walked round the right side to behind at ~0.75 m (no base turn that near), then
|
||||
# stepped out and the base turned 0.6 rad/s. Every move also turned the waist further out (a slow ~1 s move), the
|
||||
# head lagged 30-40 deg, then the base and the waist both turned the same way: off them, lost. With a body as slow as
|
||||
# the real one the head alone must stay on them: the gaze within 25 deg (the camera sees +-47), the waist never out.
|
||||
|
||||
|
||||
def real_body(path, b=None, timeout=2):
|
||||
"""The body API as slow as live: ~0.45 s a move + the travel (head ~70, waist ~15 deg/s), moving all along."""
|
||||
if path != "moveto":
|
||||
return body.call(path, b, timeout)
|
||||
start, goal, t0 = list(body.pos), list(b["pos"]), time.time()
|
||||
dur = 0.45 + max(abs(goal[2] - start[2]) / 70.0, abs(goal[1] - start[1]) / 15.0)
|
||||
while time.time() - t0 < dur:
|
||||
body.pos = [a + (g - a) * (time.time() - t0) / dur for a, g in zip(start, goal)]
|
||||
time.sleep(0.02)
|
||||
body.pos = goal
|
||||
body.moves.append((time.time(), threading.current_thread().name, *goal))
|
||||
return {"code": 0}
|
||||
|
||||
|
||||
def round_right(t):
|
||||
a = math.radians(-20.0 - 25.0 * min(t, 6.0))
|
||||
r = 0.75 + 0.3 * min(max(t - 6.0, 0.0), 2.0)
|
||||
return r * math.cos(a), r * math.sin(a)
|
||||
|
||||
|
||||
said.clear()
|
||||
body.moves.clear()
|
||||
body.pos = [50.0, 0.0, -20.0, follow.HEAD_PITCH]
|
||||
head._call = real_body
|
||||
w = World(path=round_right, fov=True)
|
||||
samples, _ = watch(w, 12.0)
|
||||
follow.stop()
|
||||
assert wait_end(3.0) and not said, said
|
||||
head._call = body.call
|
||||
off = max(abs(s[4]) for s in samples)
|
||||
assert off < 25.0, max(samples, key=lambda s: abs(s[4]))
|
||||
assert all(abs(s[1]) < 1e-6 for s in samples), max(samples, key=lambda s: abs(s[1])) # the waist never out
|
||||
assert math.degrees(w.th) < -120.0, math.degrees(w.th) # the base came round
|
||||
print(f"round the side to behind, slow body: gaze off at most {off:.0f} deg, base turned {math.degrees(w.th):.0f} deg")
|
||||
|
||||
# the arm's sweep blocked for the waist, or the arm not in look: the waist stays, the head alone goes on them
|
||||
turn_hits = fetch.turn_hits
|
||||
for why in ("sweep", "not look"):
|
||||
@@ -647,7 +690,7 @@ follow.start = lambda see, say=None, people=None: started.append(see)
|
||||
track = types.SimpleNamespace(id=7, distance=1.8, angle=10.0, greeted=False, history=[1.7], last_seen=time.time(),
|
||||
look=None)
|
||||
L.lang, L.voice_angle, L.voice_trusted = "en", 0.0, False
|
||||
L.modes = types.SimpleNamespace(drive=True, patrol=True)
|
||||
L.modes = types.SimpleNamespace(patrol=True)
|
||||
L.skill_busy = lambda: False
|
||||
L.keep_listening = lambda: None
|
||||
L.fetch_say = lambda en, ko: spoken.append(en)
|
||||
@@ -670,10 +713,7 @@ L.follow_me()
|
||||
assert started and L.current is track
|
||||
L.voice_trusted = False
|
||||
started.clear()
|
||||
L.modes.drive = False
|
||||
L.follow_me()
|
||||
assert not started and "switched off" in spoken[-1]
|
||||
L.modes.drive, L.skill_busy = True, lambda: True
|
||||
L.skill_busy = lambda: True
|
||||
L.follow_me()
|
||||
assert not started and "on a task" in spoken[-1]
|
||||
L.skill_busy, real_ready = (lambda: False), follow.ready
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
"""Self-check of "give me your hand" with a waist turn (tasks/fetch.py reach, _give_turning): the waist and the arm
|
||||
move together (the waist command goes out before the arm route ends, the arm starts before the waist is there), the
|
||||
sweep is checked with the hand at every pose of the route over the whole turn (refused when only the route's pose
|
||||
would hit something), and STOP ends both. Fake body, arm and map, no robot: python tests/test_give_together.py"""
|
||||
import json
|
||||
import math
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import no_robot # noqa: F401 any connection to the robot fails the test
|
||||
from robot import motion
|
||||
from tasks import fetch
|
||||
|
||||
tmp = Path(tempfile.mkdtemp())
|
||||
fetch.STATE_FILE = tmp / "lumi_task.json"
|
||||
fetch.CALIB_FILE = tmp / "base_axis.json"
|
||||
fetch.CALIB_FILE.write_text(json.dumps({"arm_yaw_in_base_deg": 0.0, "arm_xy_in_base_m": [0.0, 0.0], "waist_deg": 0.0}))
|
||||
fetch.log = lambda *a: None
|
||||
|
||||
body = {"pos": [0.0, 0.0, 0.0, 0.0]} # lift, waist, head yaw, head pitch
|
||||
events = [] # (time, what)
|
||||
CHUNK_S = 0.15 # s one fake waist move takes
|
||||
|
||||
|
||||
def moveto(pos, **kw):
|
||||
events.append((time.time(), "waist start", pos[1]))
|
||||
time.sleep(CHUNK_S)
|
||||
body["pos"] = list(pos)
|
||||
events.append((time.time(), "waist end", pos[1]))
|
||||
return {"status": 0}
|
||||
|
||||
|
||||
fetch.head.moveto = moveto
|
||||
fetch.head.status = lambda: list(body["pos"])
|
||||
fetch.skills.moved = lambda *a, **k: None
|
||||
fetch.skills.objects.base_from_camera = lambda: None # no depth: the lidar / map check decides
|
||||
fetch.head_cam.base_from_head = lambda yaw, pitch: None
|
||||
fetch.agv.pose = lambda: (0.0, 0.0, 0.0)
|
||||
fetch.motion.poses = lambda: {"give": [2.0] * 6, "give_pre": [1.0] * 6, "look": [0.0] * 6}
|
||||
fetch._person_point = lambda: ((0.0, 600.0, 0.0), 100.0)
|
||||
fetch._reach_to_hand = lambda *a: events.append((time.time(), "hand"))
|
||||
joints = {"now": [0.0] * 6}
|
||||
fetch.skills._joints = lambda: list(joints["now"])
|
||||
fetch.arm_points_3d = lambda j=None: [(500.0 * math.cos(math.radians(45.0 * (joints["now"] if j is None else j)[0])),
|
||||
500.0 * math.sin(math.radians(45.0 * (joints["now"] if j is None else j)[0])),
|
||||
0.0)] * 3 # j0 0 / 1 / 2 (look, give_pre, give): the hand at 0 / 45 / 90 deg
|
||||
SEQ = [("give_pre", [1.0] * 6), ("give", [2.0] * 6)]
|
||||
fetch.arm_route.plan = lambda target, holding=False, leaf=False, now=None: list(SEQ)
|
||||
arm_stop = threading.Event()
|
||||
|
||||
|
||||
def arm_move(seq, speed=None, holding=False):
|
||||
events.append((time.time(), "arm start"))
|
||||
for _, j in seq:
|
||||
if arm_stop.wait(0.2):
|
||||
raise motion.MotionError("stopped")
|
||||
joints["now"] = list(j)
|
||||
events.append((time.time(), "arm end"))
|
||||
|
||||
|
||||
fetch.arm_route.move = arm_move
|
||||
fetch.skills.cancel = lambda: arm_stop.set()
|
||||
fetch.agv.cancel = lambda: None
|
||||
obstacle = {"at": None}
|
||||
fetch.agv.clearance = lambda x, y: 0.0 if obstacle["at"] and math.dist((x, y), obstacle["at"]) < 0.05 else 1.0
|
||||
|
||||
|
||||
def when(what):
|
||||
return [e[0] for e in events if e[1] == what]
|
||||
|
||||
|
||||
def reset():
|
||||
events.clear()
|
||||
body["pos"] = [0.0, 0.0, 0.0, 0.0]
|
||||
joints["now"] = [0.0] * 6
|
||||
arm_stop.clear()
|
||||
|
||||
|
||||
# ---------- clear: waist and arm together, the head stays on the person ----------
|
||||
reset()
|
||||
fetch.reach(30.0, look=30.0)
|
||||
fetch._thread.join(10)
|
||||
st = fetch.state()
|
||||
assert st["status"] == "done", st
|
||||
w0, arm0, arm1, w1 = when("waist start")[0], when("arm start")[0], when("arm end")[0], when("waist end")[-1]
|
||||
assert w0 <= arm0 < arm1, events # the waist command went out first, before the arm route ended
|
||||
assert arm0 < w1, events # the arm started before the waist got there
|
||||
assert len(when("waist start")) == math.ceil(30.0 / fetch.WAIST_STEP_DEG), events
|
||||
assert abs(body["pos"][1] - 30.0) < 1e-6 and abs(body["pos"][2]) < 1e-6, body # waist 30, head yaw 30 - 30 = 0
|
||||
assert events[-1][1] == "hand" and joints["now"] == [2.0] * 6
|
||||
|
||||
# ---------- only the give pose, turned, meets something: refused, nothing moves ----------
|
||||
reset()
|
||||
obstacle["at"] = (500.0 * math.cos(math.radians(120.0)) / 1000.0, 500.0 * math.sin(math.radians(120.0)) / 1000.0)
|
||||
assert fetch.turn_hits(30.0) is None # the old check (the hand where it is now) sees nothing
|
||||
fetch.reach(30.0, look=30.0)
|
||||
fetch._thread.join(10)
|
||||
st = fetch.state()
|
||||
assert st["status"] == "failed" and not events and joints["now"] == [0.0] * 6, (st, events)
|
||||
obstacle["at"] = None
|
||||
|
||||
# ---------- STOP while both move: the arm stops now, the waist after the move it is in ----------
|
||||
reset()
|
||||
fetch.reach(40.0, look=40.0)
|
||||
time.sleep(0.1)
|
||||
assert when("arm start") and when("waist start"), events
|
||||
t = time.time()
|
||||
fetch.end()
|
||||
assert time.time() - t < 1.0 and not fetch._busy()
|
||||
time.sleep(3 * CHUNK_S) # nothing more is sent after the move in progress
|
||||
assert arm_stop.is_set() and not when("arm end"), events
|
||||
assert len(when("waist start")) <= 2 and all(s < t + 0.05 for s in when("waist start")), events
|
||||
assert fetch.state()["status"] == "stopped" and body["pos"][1] < 40.0
|
||||
|
||||
# ---------- no turn: only the arm (the plain route) ----------
|
||||
reset()
|
||||
posed = []
|
||||
real_pose, fetch._pose = fetch._pose, lambda name, **k: posed.append(name)
|
||||
fetch.reach(0.0)
|
||||
fetch._thread.join(5)
|
||||
assert posed == ["give"] and not when("waist start") and fetch.state()["status"] == "done"
|
||||
fetch._pose = real_pose
|
||||
print("give together ok (ordering, route sweep refusal, stop ends both, no turn)")
|
||||
@@ -2,9 +2,9 @@
|
||||
import no_robot # noqa: F401 any connection to the robot fails the test
|
||||
from robot import gripper as g
|
||||
|
||||
assert g.gap_mm(g.AI_OPEN) == 94.0 and g.gap_mm(g.AI_SHUT) == 68.0 # belly, open / closed (tape)
|
||||
assert g.gap_mm(50) == 94.0 and g.gap_mm(5000) == 68.0 # readings past the ends are clamped
|
||||
assert abs(g.gap_mm((g.AI_OPEN + g.AI_SHUT) / 2) - 81.0) < 0.01 # linear between
|
||||
assert g.gap_mm(g.AI_SHUT, "tips") == 63.0 and g.gap_mm(g.AI_OPEN, "shank") == 66.0
|
||||
assert g.gap_mm(g.AI_OPEN) == 102.0 and g.gap_mm(g.AI_SHUT) == 77.0 # belly, open / closed (owner)
|
||||
assert g.gap_mm(50) == 102.0 and g.gap_mm(5000) == 77.0 # readings past the ends are clamped
|
||||
assert abs(g.gap_mm((g.AI_OPEN + g.AI_SHUT) / 2) - 89.5) < 0.01 # linear between
|
||||
assert g.gap_mm(g.AI_SHUT, "tips") == 73.0 and g.gap_mm(g.AI_OPEN, "shank") == 66.0
|
||||
assert all(hasattr(g, n) for n in ("MOVE_S", "SENSOR_DI", "READ_TRIES", "READ_GAP_S", "CLOSED_AI", "EMPTY_AI"))
|
||||
print("gripper ok")
|
||||
|
||||
@@ -125,7 +125,7 @@ fetch._waist_to = fake_waist_to
|
||||
L = lumi.Lumi.__new__(lumi.Lumi)
|
||||
L.vision, L.current = Vision([]), None
|
||||
L.voice_angle, L.voice_trusted = 170.0, True
|
||||
L.modes = type("M", (), {"drive": True, "patrol": False})()
|
||||
L.modes = type("M", (), {"patrol": False})()
|
||||
turns.clear()
|
||||
L.look_at_speaker()
|
||||
assert waist["calls"] == [(120, True, 170.0)], waist
|
||||
|
||||
@@ -11,6 +11,7 @@ import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import no_robot # noqa: F401 any connection to the robot fails the test
|
||||
from assistant import brain
|
||||
from tasks import fetch
|
||||
|
||||
@@ -45,6 +46,10 @@ fetch._pose = lambda name: moved.append(name)
|
||||
fetch._person_point = lambda: ((0.0, 600.0, 0.0), 100.0)
|
||||
fetch._reach_to_hand = lambda *a: moved.append("hand")
|
||||
fetch._sweep_blocked = lambda *a, **k: False # never the real base's pose and map (it failed at the charger)
|
||||
fetch._route_points = lambda seq: []
|
||||
real_route = (fetch.arm_route.plan, fetch.arm_route.move)
|
||||
fetch.arm_route.plan = lambda target, holding=False, leaf=False, now=None: [(target, [0] * 6)]
|
||||
fetch.arm_route.move = lambda seq, speed=None, holding=False: moved.append("route " + seq[-1][0])
|
||||
|
||||
fetch.reach(-22.7)
|
||||
time.sleep(0.3)
|
||||
@@ -57,12 +62,14 @@ except fetch.FetchError as e:
|
||||
t = time.time()
|
||||
fetch.end() # "stop" / a new command
|
||||
assert time.time() - t < 1.0 and not fetch._busy(), "stop waited for the hung body call"
|
||||
assert fetch.state()["status"] == "stopped" and moved == []
|
||||
assert fetch.state()["status"] == "stopped" and moved == ["route give"] # the arm went with the hung waist turn
|
||||
moved.clear()
|
||||
|
||||
hung.set() # the body answers again
|
||||
fetch.reach(0.0) # the next "give me your hand": starts, not "busy"
|
||||
fetch._thread.join(2)
|
||||
assert moved == ["give", "hand"] and fetch.state()["status"] == "done", (moved, fetch.state()["status"])
|
||||
fetch.arm_route.plan, fetch.arm_route.move = real_route
|
||||
# ---------- closed on nothing is empty, whatever the camera sees ----------
|
||||
grip = {"ai": [4153.0, 489.0], "holding": False} # the live close of 17:40:39
|
||||
fetch.gripper.state = lambda: dict(grip)
|
||||
|
||||
@@ -39,6 +39,10 @@ def refused(fn, *a):
|
||||
JOG = server.JogBody(axis="head_yaw", direction=1)
|
||||
manual = (lambda: server.jog(JOG), server.gripper_open, server.gripper_close)
|
||||
|
||||
# a modes file from before "Come when called" was dropped still loads, without the old key
|
||||
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": False, "wave": True, "drive": False}))
|
||||
assert server.read_modes() == {"greeter": True, "patrol": False, "wave": True}, server.read_modes()
|
||||
|
||||
# idle, Patrol on: allowed
|
||||
server.MODES_FILE.write_text(json.dumps({"greeter": True, "patrol": True}))
|
||||
task("idle")
|
||||
|
||||
+79
-8
@@ -31,7 +31,7 @@ for yaw in (-30, 45): # a t
|
||||
p = dict(skills.plan_place(-200, 600, cup["top_mm"], yaw=yaw))["place"]
|
||||
assert np.allclose(np.array(p[:3]) + calib.rpy_matrix(*p[3:]) @ skills.GRASP_OFFSET, [-200, 600, g[2] + 3])
|
||||
|
||||
for bad in (88, 30, 50): # seen widths: +SEEN_UNDER_MM over 92, under 61
|
||||
for bad in (95, 30, 50): # seen widths: +SEEN_UNDER_MM over 97, under 61
|
||||
try:
|
||||
skills.plan_pick({**cup, "width_mm": bad})
|
||||
raise AssertionError(f"width {bad} accepted")
|
||||
@@ -221,7 +221,7 @@ skills.flat_points = real_flat
|
||||
print("skills fresh / flat ok")
|
||||
|
||||
# ---------- a pick stores what put down needs: the table under the object, also when its bottom was not in view ------
|
||||
skills._prepare = lambda: None
|
||||
real_prepare, skills._prepare = skills._prepare, lambda: None
|
||||
skills._cancel.clear() # cancel() above
|
||||
skills.motion.move_joints = lambda j, speed=None: None
|
||||
skills.gripper.close = lambda: {"ai": [3500.0], "holding": True, "object_in_front": False}
|
||||
@@ -365,29 +365,29 @@ print("skills on_table ok")
|
||||
|
||||
# ---------- side grasp: a cup too wide at the top for the hooks to come down over it, narrower lower down ----------
|
||||
top = cup["top_mm"]
|
||||
wide = {**cup, "width_mm": 90.0, "height_mm": 120.0, # 98 the fingers would meet: over MAX_WIDTH
|
||||
"profile": [(top - 10.0 * i, 88.0 if i < 4 else 72.0) for i in range(12)]} # 96 at the rim, 80 from 40 mm down
|
||||
wide = {**cup, "width_mm": 92.0, "height_mm": 120.0, # 100 the fingers would meet: over MAX_WIDTH
|
||||
"profile": [(top - 10.0 * i, 100.0 if i < 4 else 72.0) for i in range(12)]} # 100 at the rim, 72 from 40 mm down
|
||||
assert skills.side(wide) and not skills.side(cup)
|
||||
d = skills.tips_dir()
|
||||
assert np.isclose(np.linalg.norm(d), 1.0) and d[1] > 0.5 # the tips point away from the robot
|
||||
z = skills.side_height(wide)
|
||||
assert z == top - 65.0, z # nearest SIDE_AT of its 120 mm (50 mm up, top - 70) where the band is all 72
|
||||
short = {**wide, "top_mm": top - 50.0, "height_mm": 70.0, # a 70 mm cup on the same table
|
||||
"profile": [(top - 50.0 - 10.0 * i, 88.0 if i < 2 else 74.0) for i in range(7)]}
|
||||
"profile": [(top - 50.0 - 10.0 * i, 100.0 if i < 2 else 74.0) for i in range(7)]}
|
||||
assert skills.side_height(short) == top - 50.0 - 45.0 # 25 mm up: the hooks' bottom 17 over it
|
||||
way = skills.plan_pick(wide)
|
||||
assert [n for n, _ in way] == ["above", "side", "grasp", "lift"], way
|
||||
p = dict(way)
|
||||
assert np.isclose(p["side"][2], p["grasp"][2]) and p["side"][3:] == p["grasp"][3:] # in level at the grasp height
|
||||
back = skills.side_back(wide)
|
||||
assert np.isclose(back, 98.0 / 2 + np.linalg.norm(skills.TIPS_OFFSET) + skills.SIDE_CLEAR_MM)
|
||||
assert np.isclose(back, 100.0 / 2 + np.linalg.norm(skills.TIPS_OFFSET) + skills.SIDE_CLEAR_MM)
|
||||
assert np.allclose(np.subtract(p["grasp"][:2], p["side"][:2]), d * back) # it goes in along the tips' direction
|
||||
assert np.allclose(np.subtract(p["above"][:3], p["side"][:3]), [0, 0, skills.clear_above(top - z)])
|
||||
g = np.array(p["grasp"][:3]) + calib.rpy_matrix(*p["grasp"][3:]) @ skills.GRASP_OFFSET
|
||||
assert np.allclose(g, [wide["x"], wide["y"], z]) # the hooks' point on the cup axis
|
||||
assert [n for n, _ in skills.plan_pick(cup)] == ["above", "grasp", "lift"] # a cup whose top fits: from above, as before
|
||||
for bad in ([(top - 10.0 * i, 88.0) for i in range(12)], # wide all the way down
|
||||
[(top - 10.0 * i, 88.0 if i < 10 else 72.0) for i in range(12)], # narrow only where the hooks hit the table
|
||||
for bad in ([(top - 10.0 * i, 100.0) for i in range(12)], # wide all the way down
|
||||
[(top - 10.0 * i, 100.0 if i < 10 else 72.0) for i in range(12)], # narrow only where the hooks hit the table
|
||||
None): # its widths down its height not measured
|
||||
try:
|
||||
skills.plan_pick({**wide, "profile": bad})
|
||||
@@ -428,3 +428,74 @@ assert [n for n, _ in lines_] == ["side", "grasp", "out sideways", "up"], lines_
|
||||
assert np.allclose(np.subtract(p["grasp"][:2], lines_[2][1][:2]), d * back)
|
||||
skills._held.clear()
|
||||
print("skills side grasp ok")
|
||||
|
||||
# ---------- a pick stopped on its way in (the open hand beside / around the cup): the next pick backs out the way it
|
||||
# came first, never a diagonal move from there; a stop once the fingers hold it leaves it ready to put down ----------
|
||||
def stop_at(where, at): # STOP while moving to waypoint `where`: the hand ends at `at`
|
||||
def line(name, pose):
|
||||
lines_.append((name, pose))
|
||||
if name == where:
|
||||
skills.motion.tcp = lambda: list(at)
|
||||
raise skills.SkillError("Stopped.")
|
||||
skills.motion.tcp = lambda: list(pose)
|
||||
return line
|
||||
skills.gripper.close = lambda: {"ai": [3500.0], "holding": True, "object_in_front": False}
|
||||
skills.gripper.state = lambda: {"ai": [150.0], "holding": False} # open: the stop came before the close
|
||||
skills._joints = skills.home_joints = lambda: [0.0] * 6 # back at home after backing out: no route
|
||||
mid = list(np.add(p["side"], p["grasp"]) / 2) # half way in, beside the cup
|
||||
for way_, where, at, want in ((way, "grasp", mid, ["out sideways", "up"]), # side grasp, half way in
|
||||
(way, "grasp", p["grasp"], ["out sideways", "up"]), # ... around it
|
||||
(way, "side", p["side"], ["up"]), # ... still coming down
|
||||
(skills.plan_pick(cup), "grasp", grasp, ["up"])): # down around it from above
|
||||
w = dict(way_)
|
||||
skills._held.update(top_mm=-1.0, x=0.0, y=0.0) # from an earlier pick
|
||||
lines_.clear()
|
||||
skills._line = stop_at(where, at)
|
||||
try:
|
||||
skills._do_pick(wide if "side" in w else cup, way_, READY)
|
||||
raise AssertionError("not stopped")
|
||||
except skills.SkillError:
|
||||
pass
|
||||
try: # "put it down": nothing is held, nothing moves
|
||||
skills.put_down()
|
||||
raise AssertionError("put down with an open hand")
|
||||
except skills.SkillError as e:
|
||||
assert e.args[0] == "I'm not holding anything I picked.", e.args
|
||||
lines_.clear()
|
||||
real_prepare() # "take the cup" again
|
||||
assert [n for n, _ in lines_] == want, (where, lines_)
|
||||
out, top_ = lines_[-2][1] if len(lines_) > 1 else at, lines_[-1][1]
|
||||
start_ = w.get("side", w["grasp"])
|
||||
assert np.allclose(out[:3], [start_[0], start_[1], at[2]], atol=1e-6), (out, start_) # out along the way in
|
||||
assert np.allclose(top_[:3], [start_[0], start_[1], w["above"][2]], atol=1e-6) # then straight up to above
|
||||
lines_.clear()
|
||||
real_prepare() # backed out once: nothing more
|
||||
assert not lines_, lines_
|
||||
skills.motion.tcp = lambda: [0.0, 300.0, 0.0] + list(skills.GRASP_RPY) # moved away since (another task): no lines
|
||||
skills._line = stop_at("grasp", grasp)
|
||||
try:
|
||||
skills._do_pick(cup, skills.plan_pick(cup), READY)
|
||||
except skills.SkillError:
|
||||
pass
|
||||
skills.motion.tcp = lambda: [0.0, 300.0, 0.0] + list(skills.GRASP_RPY)
|
||||
lines_.clear()
|
||||
real_prepare()
|
||||
assert not lines_ and not skills._pick_way, lines_
|
||||
# STOP in the lift, the fingers holding it: put down knows it (as at the end of a pick), the next pick backs out nothing
|
||||
for way_, obj_ in ((way, wide), (skills.plan_pick(cup), cup)):
|
||||
skills._held.clear()
|
||||
skills._line = stop_at("lift", dict(way_)["grasp"])
|
||||
try:
|
||||
skills._do_pick(obj_, way_, READY)
|
||||
raise AssertionError("not stopped")
|
||||
except skills.SkillError:
|
||||
pass
|
||||
assert skills._held["top_mm"] == obj_["top_mm"] and np.isclose(skills._held["back"], back if obj_ is wide else 0.0)
|
||||
assert np.isclose(skills._held["below"], obj_["top_mm"] - skills.grasp_height(obj_)) and not skills._pick_way
|
||||
placed = []
|
||||
real_place_first, skills._place_first = skills._place_first, lambda tries, refusal: placed.append(tries[0])
|
||||
skills.put_down(back=True)
|
||||
skills._place_first = real_place_first
|
||||
assert placed == [(obj_["x"], obj_["y"])], placed
|
||||
skills._held.clear()
|
||||
print("skills stopped pick ok")
|
||||
|
||||
@@ -127,13 +127,13 @@ lumi.head.status = lambda: [0, 0, 0, 0]
|
||||
lumi.nav.person_on_map = lambda *a: (3.0, 0.0)
|
||||
lumi.nav.approach = lambda *a: (2.0, 0.0, 0.0)
|
||||
L = fresh(U("Stop!"), trip=False)
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {"drive": True})(), lambda *a, **k: None
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {})(), lambda *a, **k: None
|
||||
base["move_status"] = "running"
|
||||
t = time.time()
|
||||
L.come_to(Track())
|
||||
assert stopped(L) and time.time() - t < 3, done
|
||||
L = fresh(U("What is your name?"), trip=False)
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {"drive": True})(), lambda *a, **k: None
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {})(), lambda *a, **k: None
|
||||
base["move_status"] = "running"
|
||||
threading.Timer(1.0, lambda: base.update(move_status="succeeded")).start()
|
||||
L.come_to(Track())
|
||||
@@ -142,7 +142,7 @@ assert "agv cancel" not in done and L.pending_text == "What is your name?", done
|
||||
# right after Lumi said "Okay, I stopped.", "Stop." is no echo of it (own_echo counts "stop" in "stopped")
|
||||
lumi.mouth.recent_speech = lambda s: "Okay, I stopped. Let's go to p5."
|
||||
L = fresh(U("Stop."), trip=False)
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {"drive": True})(), lambda *a, **k: None
|
||||
L.vision, L.modes, L.turn_head = Vision(), type("Modes", (), {})(), lambda *a, **k: None
|
||||
base["move_status"] = "running"
|
||||
L.come_to(Track())
|
||||
assert stopped(L), done
|
||||
|
||||
+12
-4
@@ -55,7 +55,7 @@ DOES = {"go_to": "start_trip", "follow": "follow_me", "come": "come_to", "move":
|
||||
"look": "look", "lift": "lift"}
|
||||
|
||||
# ---------- Greeter only: the base refused aloud (no "Okay" first), everything in place done ----------
|
||||
L.modes = types.SimpleNamespace(greeter=True, patrol=False, drive=True, wave=True)
|
||||
L.modes = types.SimpleNamespace(greeter=True, patrol=False, wave=True)
|
||||
for text in BASE:
|
||||
moved.clear()
|
||||
said.clear()
|
||||
@@ -211,10 +211,10 @@ L.vision.present = lambda t: True
|
||||
L.come_to = lambda t: came.append(t.id) or setattr(t, "distance", 1.1)
|
||||
reached.clear(), said.clear()
|
||||
assert L.reach_out(False) and came == [8] and reached == [21.0], (came, reached)
|
||||
person.distance, L.modes.drive = 3.0, False # far and driving switched off: asked to come, no reach
|
||||
person.distance, L.modes.patrol = 3.0, False # far, Greeter only (the base stays): asked to come, no reach
|
||||
reached.clear(), said.clear(), came.clear()
|
||||
assert L.reach_out(False) is None and not reached and not came and said == [lumi.COME_CLOSER_SAY[0]], (said, reached)
|
||||
L.modes.drive, person.distance = True, 1.0
|
||||
L.modes.patrol, person.distance = True, 1.0
|
||||
fetch.give_bearing = lambda: 0.0
|
||||
L.turn_head = lambda *a, **k: moved.append("head")
|
||||
seen_vision, L.vision = L.vision, None # nobody seen, the voice's direction not trusted: ask
|
||||
@@ -278,7 +278,7 @@ P = lumi.Patrol(["p3"])
|
||||
P.tick(force=True)
|
||||
assert order == ["waist", ("go", "home")] and P.mode == "going_home", order
|
||||
lumi.agv.status = lambda: {"move_status": "idle", "power_percent": 90}
|
||||
L.modes.patrol, L.modes.drive = True, True
|
||||
L.modes.patrol = True
|
||||
real_turned, lumi.waist_turned = lumi.waist_turned, lambda: 30.0 # turned 30 left for someone
|
||||
order.clear()
|
||||
L.look_toward(150.0) # a voice behind: the base turns to it from the base's front
|
||||
@@ -294,5 +294,13 @@ assert order == ["waist"], order
|
||||
lumi.waist_home, lumi.waist_turned = real_home, real_turned
|
||||
for name in ("status", "go", "go_point", "turn_by"):
|
||||
setattr(lumi.agv, name, forbid)
|
||||
# a modes file from before "Come when called" was dropped still loads; its "drive" key is ignored
|
||||
import json, tempfile, os
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
lumi.MODES_FILE = os.path.join(tmp, "lumi_modes.json")
|
||||
json.dump({"greeter": True, "patrol": True, "wave": False, "drive": False}, open(lumi.MODES_FILE, "w"))
|
||||
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)
|
||||
|
||||
print(f"switches ok: {len(BASE)} base phrases refused with Greeter only, {len(IN_PLACE)} in place done; "
|
||||
"arm off asks; Patrol allows all; stop always")
|
||||
|
||||
@@ -196,6 +196,39 @@ assert L.wave() is True and said == [] and not fetch.state()["holding"], said
|
||||
wave.wave = real_wave
|
||||
fetch.STATE_FILE.unlink()
|
||||
|
||||
# ---------- the arm moves while the words are said, never after them (wave, open / close) ----------
|
||||
gate, order = threading.Event(), []
|
||||
|
||||
|
||||
def slow_say(text, **k): # speech that ends only when the test says so
|
||||
order.append(("say", text))
|
||||
gate.wait(30)
|
||||
|
||||
|
||||
lumi.mouth = types.SimpleNamespace(say=slow_say)
|
||||
L.lang = "en"
|
||||
wave.wave = lambda on_start=None: (on_start(), order.append("move"))
|
||||
done = []
|
||||
th = threading.Thread(target=lambda: done.append(L.wave(("Okay!", "네!"))))
|
||||
th.start()
|
||||
th.join(10)
|
||||
assert done == [True] and "move" in order, (done, order) # waved with the words still being said
|
||||
gate.set()
|
||||
wave.wave = real_wave
|
||||
gate.clear(), order.clear()
|
||||
L.arm_pose = lambda target: order.append("gripper") or True
|
||||
L.base_off = lambda *a, **k: False
|
||||
L.arm_off = lambda: False
|
||||
L.brain = types.SimpleNamespace(history=[])
|
||||
th = threading.Thread(target=L.quick_command, args=("open your hand", ("arm", "open")))
|
||||
th.start()
|
||||
th.join(1)
|
||||
assert "gripper" in order and th.is_alive(), order # the gripper started while the words go on
|
||||
gate.set()
|
||||
th.join(5)
|
||||
del L.arm_pose, L.base_off, L.arm_off
|
||||
lumi.mouth = types.SimpleNamespace(say=lambda text, **k: said.append(text))
|
||||
|
||||
# ---------- "bye bye" to the person in view: a (quiet) wave beside the goodbye; else only the goodbye ----------
|
||||
waves = []
|
||||
L.wave = lambda **k: waves.append(k)
|
||||
|
||||
Reference in New Issue
Block a user