Improve attention, voice direction, reach, pick and follow from live feedback
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+58
-20
@@ -450,7 +450,7 @@ def _line_holding(name):
|
||||
if _at_pose(name):
|
||||
return
|
||||
try:
|
||||
names = arm_route.hops(skills._joints(), name, leaf=True)
|
||||
names = arm_route.hops(skills._joints(), name, leaf=True, holding=True)
|
||||
except arm_route.RouteError as e:
|
||||
raise FetchError(*e.args) from e
|
||||
lines, start = [], None
|
||||
@@ -696,15 +696,19 @@ def _sweep_blocked(deg, what):
|
||||
return False
|
||||
|
||||
|
||||
def _waist_to(rel):
|
||||
def _waist_to(rel, in_place=False, look=None):
|
||||
"""Turn the waist to `rel` deg from the front (the waist of measure-axis), lift and head stay; the arm keeps its
|
||||
pose; `rel` is cut to the body's limit. False when the arm's sweep is not clear (_sweep_blocked)."""
|
||||
pose; `rel` is cut to the body's limit. False when the arm's sweep is not clear (_sweep_blocked), or with Patrol
|
||||
off (stay_put) unless `in_place` (reach: turning to the person in front of Lumi, the base stays). `look`: the
|
||||
waist-frame angle (deg, + left, as before the turn) the head keeps facing: it sits on the waist, so its yaw goes to
|
||||
look minus the turn (cut to head.YAW_LIMIT) in the same body move. Without it the head keeps its yaw and turns
|
||||
with the waist."""
|
||||
waist = head.status()[1]
|
||||
lo, hi = head.AXIS_LIMITS[1]
|
||||
d = max(lo, min(hi, waist - _waist_turn() + rel)) - waist
|
||||
if abs(d) < 1.0:
|
||||
return True
|
||||
if stay_put:
|
||||
if stay_put and not in_place:
|
||||
log("not turning my waist: Patrol is off")
|
||||
return False
|
||||
_go_on()
|
||||
@@ -712,6 +716,9 @@ def _waist_to(rel):
|
||||
if _sweep_blocked(d, "turning my waist"):
|
||||
return False
|
||||
lift, waist = head.status()[:2]
|
||||
if look is not None:
|
||||
yaw = max(-head.YAW_LIMIT, min(head.YAW_LIMIT, look - d))
|
||||
log(f"head yaw {yaw:+.0f} deg with the waist: still on {look:+.0f} deg")
|
||||
log(f"waist {waist:.0f} -> {waist + d:.0f} deg")
|
||||
_body_move([lift, waist + d, yaw, pitch], vel=WAIST_VEL, acc=20, timeout=60)
|
||||
skills.moved()
|
||||
@@ -1067,8 +1074,9 @@ def waist_for(obj):
|
||||
def _waist_reach(task, obj, say):
|
||||
"""(obj, waypoints, joints above) of a pick after a waist turn, for an object the arm doesn't reach from here: the
|
||||
first turn of waist_for whose pick, planned where the object will be (turned), passes; the waist turns (its sweep
|
||||
checked), the camera looks again and the pick is planned from what it sees. None when no turn reaches it or the
|
||||
object is not seen again where it should be (then the base moves)."""
|
||||
checked), the camera looks again and the pick is planned from what it sees. The waist turns in place, also with
|
||||
Patrol off (the base stays). None when no turn reaches it or the object is not seen again where it should be (then
|
||||
the base moves)."""
|
||||
for deg in waist_for(obj):
|
||||
try:
|
||||
if not _reachable(turned(obj, deg)):
|
||||
@@ -1077,7 +1085,7 @@ def _waist_reach(task, obj, say):
|
||||
return None
|
||||
_step("turning my waist to reach it", say)
|
||||
_pose(_look())
|
||||
if not _waist_to(_waist_turn() + deg):
|
||||
if not _waist_to(_waist_turn() + deg, in_place=True):
|
||||
return None
|
||||
want = turned(obj, deg)
|
||||
hits = [o for o in skills.look() if _is_task(o, task) and o["seen"] >= skills.MIN_SEEN
|
||||
@@ -1528,23 +1536,26 @@ def _reach_at(obj, g):
|
||||
return True # the width decides up close
|
||||
|
||||
|
||||
def _reach(task, obj, say):
|
||||
def _reach(task, obj, say, voice=False):
|
||||
"""Step 5: (obj, waypoints, joints above) of a pick that passes IK. A cup past COMFORT_R_MM (the arm almost
|
||||
straight knocks it over) is not taken from here while the base can bring it in; out of reach: the waist, then a
|
||||
base move (_approach to pick_goal, every move measured, a way that did nothing not tried again). After every
|
||||
attempt to move, also one that failed half way, the cup is looked at again where it is kept (_see_again): a plan
|
||||
never uses a position from before a move. Up to APPROACH_TRIES times (never on the charger). A cup the base can't
|
||||
bring nearer is taken from where it stands (any grasp turn as the last resort); else ask the person, saying why."""
|
||||
bring nearer is taken from where it stands (any grasp turn as the last resort); else ask the person, saying why.
|
||||
`voice` (the voice pick, pick_here): never a grasp turn past skills.TRUSTED_YAW_DEG (+15 deg missed 2 of 2 live),
|
||||
and with Patrol off no base move is tried: the waist only, then the person is asked."""
|
||||
yaw, tried, why = arm_yaw(), set(), None # grasp turns past skills.TRUSTED_YAW_DEG only when the base can't help
|
||||
_width_far["moves"] = 0
|
||||
for i in range(APPROACH_TRIES + 1):
|
||||
can_move = yaw is not None and i < APPROACH_TRIES and not _charging() and "stuck" not in tried
|
||||
can_move = yaw is not None and i < APPROACH_TRIES and not (voice and stay_put) and not _charging() and \
|
||||
"stuck" not in tried
|
||||
edge = can_move and not stay_put and "edge" not in tried and at_edge(obj)
|
||||
if edge:
|
||||
log(f"the {task['object']} at ({obj['x']:.0f}, {obj['y']:.0f}) is at the edge of my reach: closer first")
|
||||
else:
|
||||
try:
|
||||
plan = _reachable(obj) or ((not can_move or "edge" in tried) and _reachable(obj, None))
|
||||
plan = _reachable(obj) or ((not can_move or "edge" in tried) and not voice and _reachable(obj, None))
|
||||
except skills.SkillError: # too big / small: another one of them here may do
|
||||
other = _other_here(task, obj) if i == 0 else None
|
||||
if other:
|
||||
@@ -1567,7 +1578,7 @@ def _reach(task, obj, say):
|
||||
if edge:
|
||||
tried.add("edge")
|
||||
continue
|
||||
plan = _reachable(obj, None)
|
||||
plan = not voice and _reachable(obj, None)
|
||||
if plan:
|
||||
return (obj, *plan)
|
||||
raise
|
||||
@@ -1601,7 +1612,7 @@ def _reach(task, obj, say):
|
||||
why = blocked
|
||||
break
|
||||
if why:
|
||||
plan = _reachable(obj, None) # the base can't do better: any grasp turn (P2: the last resort)
|
||||
plan = not voice and _reachable(obj, None) # the base can't do better: any grasp turn (P2: the last resort)
|
||||
if plan:
|
||||
return (obj, *plan)
|
||||
log(f"asking for help: {why}")
|
||||
@@ -1611,7 +1622,7 @@ def _reach(task, obj, say):
|
||||
("I can't reach it, please move it closer to me.", "손이 닿지 않아요. 저에게 조금 더 가까이 놓아 주세요.")))
|
||||
deadline = time.time() + ASK_WAIT_S
|
||||
while time.time() < deadline:
|
||||
if _stop.wait(ASK_EVERY_S):
|
||||
if _stop.wait(ASK_EVERY_S) or skills._cancel.is_set():
|
||||
raise Stopped()
|
||||
try:
|
||||
obj = _find(task)
|
||||
@@ -2320,7 +2331,7 @@ def _new_run():
|
||||
_clear()
|
||||
|
||||
|
||||
def _launch(fn, *a):
|
||||
def _launch(fn, *a, ahead=True):
|
||||
global _thread
|
||||
from tasks import follow # imported here: follow imports this module
|
||||
if follow.running(): # its joy_control commands would fight this task's (2026-10-23:
|
||||
@@ -2330,7 +2341,7 @@ def _launch(fn, *a):
|
||||
|
||||
def run():
|
||||
fn(*a)
|
||||
if not _stop.is_set(): # done or failed: the head looks ahead again (not after a STOP)
|
||||
if ahead and not _stop.is_set(): # done or failed: the head looks ahead again (not after a STOP)
|
||||
try:
|
||||
head_ahead()
|
||||
except Exception as e:
|
||||
@@ -2398,6 +2409,25 @@ def held_by_skill(what):
|
||||
_set(holding=True, held_object=skills._held["what"], status="holding", step="holding")
|
||||
|
||||
|
||||
def pick_here(name, colour=None, say=None):
|
||||
"""The voice pick ("take the cup", assistant/lumi.py's skill thread): the `name` (`colour`) seen from where Lumi
|
||||
stands is reached as a fetch reaches it, with trusted grasp turns only (_reach voice=True: from here, else the
|
||||
waist in place, else with Patrol on the base, else the person is asked) and picked; it ends held just above the
|
||||
table. Returns the object."""
|
||||
task = {"object": name, "colour": colour}
|
||||
_clear()
|
||||
try:
|
||||
obj = _find(task)
|
||||
log(f"found {obj['colour']} {obj['name']} at ({obj['x']:.0f}, {obj['y']:.0f}) top {obj['top_mm']:.0f} "
|
||||
f"width {obj['width_mm']:.0f}")
|
||||
obj, waypoints, ja = _reach(task, obj, say, voice=True)
|
||||
_step("picking")
|
||||
skills._guarded(skills._do_pick, obj, waypoints, ja)
|
||||
finally:
|
||||
_set(step="")
|
||||
return obj
|
||||
|
||||
|
||||
def _hold_again():
|
||||
"""The hand holds something the state does not: it is the thing forgotten last (_forget_held), its name and what
|
||||
put down needs. Live 2026-10-26 18:53:00 one hand read said empty with the cup in it; after that every reply said
|
||||
@@ -2909,8 +2939,9 @@ def _person_point():
|
||||
|
||||
def reach(angle=0.0, say=None):
|
||||
"""Hold the hand out to the person ("reach out to me", "손 내밀어"): first, when `angle` (deg, + left, waist
|
||||
frame: the person tracker's) is not 0, the waist turns to face them (_waist_to: Patrol only, its arm sweep
|
||||
checked; past the waist's limits they are asked to stand in front), then the arm along the pose graph to give
|
||||
frame: the person tracker's) is not 0, the waist turns to face them (_waist_to, also with Patrol off: the base
|
||||
stays; its arm sweep checked; past the waist's limits they are asked to stand in front; the waist stays turned
|
||||
after; the head turns with it onto them and stays on them, also after), then the arm along the pose graph to give
|
||||
(arm_route, every move checked), then at most RECEIVE_REACH_MM straight towards their hand or body
|
||||
(_person_point, _reach_to_hand). The arm stays out; "fold" brings it back to look."""
|
||||
if "give" not in motion.poses():
|
||||
@@ -2926,7 +2957,8 @@ def reach(angle=0.0, say=None):
|
||||
try:
|
||||
if angle: # the waist, not the base: the person stays where they are
|
||||
lo, hi = head.AXIS_LIMITS[1]
|
||||
if not lo <= head.status()[1] + angle <= hi or not _waist_to(angle + _waist_turn()):
|
||||
if not lo <= head.status()[1] + angle <= hi or \
|
||||
not _waist_to(angle + _waist_turn(), in_place=True, look=angle):
|
||||
raise FetchError(*TURN_TO_PERSON)
|
||||
_pose("give")
|
||||
_reach_to_hand(*_person_point())
|
||||
@@ -2934,7 +2966,7 @@ def reach(angle=0.0, say=None):
|
||||
log("reached out")
|
||||
except Exception as e:
|
||||
_fail(e, say)
|
||||
_launch(run)
|
||||
_launch(run, ahead=False) # the head stays on the person, not ahead
|
||||
|
||||
|
||||
def _arm(pose):
|
||||
@@ -3023,6 +3055,12 @@ def stop():
|
||||
if _state["status"] in ("running", "holding", "waiting"):
|
||||
_set(status="stopped")
|
||||
log("stopped")
|
||||
elif (_thread is None or not _thread.is_alive()) and state().get("status") in ("running", "waiting"):
|
||||
d = state() # a run of a process that is gone (restarted mid-task): the file says running
|
||||
d.update(status="stopped", log=d.get("log", []) + [time.strftime("%H:%M:%S") + " stopped"])
|
||||
tmp = STATE_FILE.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(d))
|
||||
os.replace(tmp, STATE_FILE)
|
||||
|
||||
|
||||
def end(timeout=5.0):
|
||||
|
||||
+126
-40
@@ -6,11 +6,13 @@ put on the map (base pose + distance, angle) with a smoothed walking velocity, s
|
||||
toward where the person is now, not where they were seen (no stop-and-go when frames are missed). A sighting far from
|
||||
that place is someone else (a passer-by who took the track over); a lost track is swapped for a fresh one near that
|
||||
place whose clothes are not clearly different (re-lock). The head turns toward the person in its own thread (only
|
||||
this task moves the body meanwhile: head.owners), the base turns after it, so they stay in view when they walk to the
|
||||
side or behind. The base is driven with joy_control every TICK_S (one command lasts 0.5 s: a stuck loop stops the base
|
||||
by itself), the arm in look and the waist at the front as for every fetch drive. Every command is checked first: where
|
||||
the base and the arm would be BRAKE_S later must be clear (lidar + map, agv.clearance); when not, the base stands, and
|
||||
after BLOCKED_END_S it gives up.
|
||||
this task moves the body meanwhile: head.owners) and the waist with it, all at once: the head straight on them (up to
|
||||
+-180 on the waist), the waist a short way toward them in the same move, the base turning toward them at the same time;
|
||||
as the base comes round the waist and the head unwind (waist_for). Nothing waits for another. Following starts with the
|
||||
waist where it is (turned toward the person after "look behind"). The base is driven with joy_control every TICK_S (one
|
||||
command lasts 0.5 s: a stuck loop stops the base by itself), the arm in look; forward only with the person near ahead
|
||||
and the waist near the front. Every command is checked first: where the base and the arm would be BRAKE_S later must be clear
|
||||
(lidar + map, agv.clearance); when not, the base stands, and after BLOCKED_END_S it gives up.
|
||||
|
||||
stop() from any thread: the event is set and the base is sent 0 at once
|
||||
"""
|
||||
@@ -57,7 +59,20 @@ BASE_CLEAR_M = fetch.BASE_HALF_M + fetch.CLEAR_M # m; base centre kept this fa
|
||||
TICK_S = 0.1 # s between commands, steady (joy_control wants > 2 Hz; a tick takes ~10-30 ms)
|
||||
LOG_S = 1.0 # s between "follow: v ... " lines (what the next live run is read from)
|
||||
JOIN_S = 2.0 # s a new "follow me" waits for the old loop to end
|
||||
HEAD_YAW_MAX = 180.0 # deg; the head turns toward the person up to this far (+ left; body API range, head.AXIS_LIMITS)
|
||||
BEHIND_DEG = 180.0 # deg; the person's angle from the base is kept within +-this (right behind: one side)
|
||||
HEAD_REL_MAX = 30.0 # deg; a person this near the base heading is looked at with the head alone; further, the
|
||||
# waist turns toward them for the rest (the head is never held back by it)
|
||||
WAIST_FOLLOW_MAX = 90.0 # deg from the front; the waist turns toward the person at most this far, the base turns
|
||||
# for the rest (fetch.WAIST_SCAN_MAX 120 is the search's; less here, estimate)
|
||||
WAIST_STEP_DEG = 8.0 # deg; one body move turns the waist at most this far, so every move is short (~0.4 s) and
|
||||
# the head's next correction is not held back; the waist keeps on in the next move
|
||||
WAIST_FOLLOW_VEL = 50 # speed ratio % of a move that turns the waist (the head in it too). The waist's deg/s at
|
||||
# this ratio is not measured; estimate ~40 deg/s as the head's (audio/sing.py), about the
|
||||
# base's own TURN_MAX_RS turn that sweeps the arm the same way. Lower it if the arm swings
|
||||
# too hard (fetch.WAIST_VEL 20 is the search's long turns)
|
||||
WAIST_DRIVE_DEG = 15.0 # deg; the base drives forward only with the waist this near the front: navigation does not
|
||||
# know the arm, blocked() checks it turned (estimate)
|
||||
WAIST_RETRY_S = 1.0 # s; a waist turn found blocked is not tried again for this long (each try probes the map)
|
||||
HEAD_PITCH = 10.0 # deg; head pitch while following, a little up toward a standing person (as "look at me")
|
||||
HEAD_STEP_DEG = 3.0 # deg; a new head move only when the target is this far from where the head was sent
|
||||
HEAD_LEAD_S = 0.3 # s; the head is sent where the person will be this much later (a moveto takes time)
|
||||
@@ -181,16 +196,14 @@ def ready():
|
||||
|
||||
|
||||
def prepare():
|
||||
"""Arm to look, waist to the front (as before every fetch drive). The head stays where it is: it is on the person
|
||||
already (the track is seen), and ahead they may be out of view (lost at once, 2026-10-21). Returns the arm's points (m, base
|
||||
frame) that stick out past the base, [] when the arm's place on the base is not measured. FetchError when it
|
||||
must not drive."""
|
||||
"""Arm to look. The waist and the head stay where they are: they are on the person already (the track is seen),
|
||||
and ahead they may be out of view (lost at once). Returns the arm's points (m, base frame) that stick out past the
|
||||
base, [] when the arm's place on the base is not measured. FetchError when it must not drive."""
|
||||
why = ready()
|
||||
if why:
|
||||
raise fetch.FetchError(*why)
|
||||
fetch._stop.clear() # a stop said earlier must not end this one
|
||||
fetch._drive_pose()
|
||||
fetch._waist_front()
|
||||
if fetch.arm_yaw() is None:
|
||||
fetch.log("follow: the arm's place on the base is not measured: only the base is checked")
|
||||
return []
|
||||
@@ -203,6 +216,12 @@ def _to_map(pose, d, a):
|
||||
return np.array([x + d * math.cos(th + math.radians(a)), y + d * math.sin(th + math.radians(a))])
|
||||
|
||||
|
||||
def _seen_from(pose, turned):
|
||||
"""The base pose turned by the waist's turn (deg): sightings are waist-frame angles (lumi.Vision), _to_map them
|
||||
from this."""
|
||||
return pose[0], pose[1], pose[2] + math.radians(turned)
|
||||
|
||||
|
||||
def _rel(pose, p):
|
||||
"""(distance m, angle deg + left) of the map point p from the base at pose."""
|
||||
x, y, th = pose
|
||||
@@ -256,19 +275,54 @@ def _pick(see, got, people, person, pose, sig, now):
|
||||
return best[1:]
|
||||
|
||||
|
||||
def _head_follow(target, done, lift, waist, stats):
|
||||
"""Turn the head to target[0] (yaw, pitch) whenever it is HEAD_STEP_DEG from where it was sent last. One moveto
|
||||
at a time, from this thread only: overlapping calls hang the body API. The drive loop never waits for it."""
|
||||
sent = None
|
||||
def waist_for(b):
|
||||
"""Waist turn (deg from the front, + left) for a person b deg from the base heading: what is past HEAD_REL_MAX,
|
||||
up to WAIST_FOLLOW_MAX. 0 when they are near ahead, so it unwinds as the base turns to them."""
|
||||
return max(-WAIST_FOLLOW_MAX, min(WAIST_FOLLOW_MAX, math.copysign(max(0.0, abs(b) - HEAD_REL_MAX), b)))
|
||||
|
||||
|
||||
def _head_follow(target, done, lift, front, w, waist_free, stats):
|
||||
"""Turn the head, and the waist with it, to the person at target[0] (deg from the base heading, pitch). Every move
|
||||
sends the head straight to them (up to +-BEHIND_DEG on the waist, never held back) and the waist at most
|
||||
WAIST_STEP_DEG toward waist_for() in the same move, so the waist keeps turning move after move while the base turns
|
||||
and the head stays on the person all along. Every waist step is checked along the arm's sweep (fetch.turn_hits);
|
||||
blocked, or waist_free False (arm not in look, its place not measured): the waist stays and the head alone turns.
|
||||
`front`: the waist's reading at the front, `w`: its turn from there now. One moveto at a time, from this thread
|
||||
only: overlapping calls hang the body API. The drive loop never waits for it."""
|
||||
sent, retry = None, 0.0 # (head yaw, pitch) sent last
|
||||
while not done.is_set():
|
||||
t = target[0]
|
||||
if t is None or sent is not None and max(abs(t[0] - sent[0]), abs(t[1] - sent[1])) < HEAD_STEP_DEG:
|
||||
if t is None:
|
||||
done.wait(TICK_S / 2)
|
||||
continue
|
||||
b, pitch = t
|
||||
want = waist_for(b) - w if waist_free and time.time() >= retry else 0.0
|
||||
step = max(-WAIST_STEP_DEG, min(WAIST_STEP_DEG, want))
|
||||
if abs(step) < HEAD_STEP_DEG and (waist_for(b) != 0.0 or abs(step) < 0.5):
|
||||
step = 0.0 # small steps only for the last bit to the front
|
||||
yaw = max(-BEHIND_DEG, min(BEHIND_DEG, b - w - step))
|
||||
off = float("inf") if sent is None else max(abs(yaw - sent[0]), abs(pitch - sent[1]))
|
||||
if step == 0.0 and off < HEAD_STEP_DEG:
|
||||
done.wait(TICK_S / 2)
|
||||
continue
|
||||
if step:
|
||||
try:
|
||||
hit = fetch.turn_hits(step)
|
||||
except (ConnectionError, OSError, ValueError, KeyError) as e: # not checked: not turned
|
||||
fetch.log(f"follow: the waist's sweep can't be checked: {e!r}")
|
||||
hit = ()
|
||||
if hit is not None:
|
||||
if hit:
|
||||
fetch.log(f"follow: waist stays at {w:+.0f} deg, turning {step:+.0f} my arm would hit something "
|
||||
f"at ({hit[0]:.2f}, {hit[1]:.2f}); the head turns alone")
|
||||
retry = time.time() + WAIST_RETRY_S
|
||||
continue # at once again: the head alone
|
||||
vel = min(HEAD_VEL, WAIST_FOLLOW_VEL) if step else HEAD_VEL
|
||||
try:
|
||||
t0 = time.time()
|
||||
head.moveto([lift, waist, *t], vel=HEAD_VEL, acc=HEAD_VEL, timeout=HEAD_TIMEOUT_S)
|
||||
sent, stats["head"], stats["head_ms"] = t, t[0], round(1000 * (time.time() - t0))
|
||||
head.moveto([lift, front + w + step, yaw, pitch], vel=vel, acc=vel, timeout=HEAD_TIMEOUT_S)
|
||||
w += step
|
||||
sent, stats["head"], stats["head_ms"] = (yaw, pitch), yaw, round(1000 * (time.time() - t0))
|
||||
except (ConnectionError, OSError, ValueError, KeyError) as e:
|
||||
fetch.log(f"follow: head error {e!r}")
|
||||
done.wait(1.0)
|
||||
@@ -279,16 +333,35 @@ def _run(see, say, people):
|
||||
v = w = 0.0
|
||||
done, target, stats = threading.Event(), [None], {"head": None, "head_ms": None}
|
||||
head.owners = (threading.current_thread(),)
|
||||
person, head_thread = Person(), None
|
||||
person, head_thread, front = Person(), None, None
|
||||
try:
|
||||
got = see() # where they are now: prepare() may turn the waist
|
||||
got = see() # where they are now (waist-frame angle)
|
||||
sig = got[3] if got else None
|
||||
if _fresh(got):
|
||||
person.seen(_to_map(agv.pose(), *got[:2]), time.time() - got[2])
|
||||
person.seen(_to_map(_seen_from(agv.pose(), fetch._waist_turn()), *got[:2]), time.time() - got[2])
|
||||
arm_pts = prepare()
|
||||
lift, waist = head.status()[:2]
|
||||
head_thread = threading.Thread(target=_head_follow, args=(target, done, lift, waist, stats), daemon=True,
|
||||
name="follow head")
|
||||
lift, waist, yaw = head.status()[:3]
|
||||
turned = fetch._waist_turn()
|
||||
front, gaze = waist - turned, turned + yaw # the waist's reading at the front; where the head looks
|
||||
waist_free = bool(arm_pts) # its sweep can be checked ...
|
||||
if waist_free:
|
||||
try:
|
||||
waist_free = fetch._at_pose(fetch._look()) # ... and the arm is folded in look
|
||||
except Exception as e:
|
||||
waist_free = False
|
||||
fetch.log(f"follow: the arm's pose can't be read: {e!r}")
|
||||
if not waist_free:
|
||||
fetch.log("follow: my arm is not in look: the waist stays, the head turns alone")
|
||||
if not waist_free and abs(turned) >= WAIST_DRIVE_DEG: # it would never drive: the waist to the front, the
|
||||
look = got[1] if _fresh(got) else None # head kept on them (fetch._waist_to checks the sweep)
|
||||
if not fetch._waist_to(0.0, in_place=True, look=look):
|
||||
raise fetch.FetchError("My arm can't turn back to the front: something is in its way.",
|
||||
"팔을 앞으로 돌릴 수 없어요. 뭔가 막고 있어요.")
|
||||
lift, waist, yaw = head.status()[:3]
|
||||
turned = waist - front
|
||||
gaze = turned + yaw
|
||||
head_thread = threading.Thread(target=_head_follow, args=(target, done, lift, front, turned, waist_free, stats),
|
||||
daemon=True, name="follow head")
|
||||
head.owners += (head_thread,)
|
||||
head_thread.start()
|
||||
start_t = next_t = time.time() # lost counts from here: prepare() takes a few seconds
|
||||
@@ -296,8 +369,13 @@ def _run(see, say, people):
|
||||
while not _stop.is_set():
|
||||
now = time.time()
|
||||
pose = agv.pose()
|
||||
try:
|
||||
turned = head.status()[1] - front
|
||||
except (ConnectionError, OSError, KeyError):
|
||||
pass # the last reading: the body API may be busy
|
||||
seen_from = _seen_from(pose, turned)
|
||||
mine, was = see(), see
|
||||
see, got = _pick(see, mine, people, person, pose, sig, now)
|
||||
see, got = _pick(see, mine, people, person, seen_from, sig, now)
|
||||
if see is not was:
|
||||
fetch.log(f"follow: re-locked onto the person at {got[0]:.2f} m {got[1]:+.0f} deg")
|
||||
elif got is None and _fresh(mine) and now - odd_t > LOG_S:
|
||||
@@ -305,9 +383,9 @@ def _run(see, say, people):
|
||||
fetch.log(f"follow: a sighting at {mine[0]:.2f} m {mine[1]:+.0f} deg is not them (someone else)")
|
||||
if _fresh(got):
|
||||
_followed[0] = (got[1], now - got[2])
|
||||
p = _to_map(pose, *got[:2])
|
||||
p = _to_map(seen_from, *got[:2])
|
||||
person.seen(p, now - got[2])
|
||||
near = [float(np.linalg.norm(_to_map(pose, *o[1:3]) - p)) for o in people() if _fresh(o[1:])] \
|
||||
near = [float(np.linalg.norm(_to_map(seen_from, *o[1:3]) - p)) for o in people() if _fresh(o[1:])] \
|
||||
if people else [0.0]
|
||||
if got[3] is not None and all(e > JUMP_M or e < 0.05 for e in near): # alone (or themselves):
|
||||
sig = reid.blend(sig, got[3]) # these clothes are theirs
|
||||
@@ -318,19 +396,20 @@ def _run(see, say, people):
|
||||
if person.p is None: # not seen yet (only before the first sighting)
|
||||
cmd, d, a, walk = (0.0, 0.0), 0.0, 0.0, 0.0
|
||||
else:
|
||||
# angles taken on from the head's last target, not -180..180: right behind, +179 and -179 are
|
||||
# the same place, the head must not swing round and the base not turn the other way
|
||||
ref = target[0][0] if target[0] else 0.0
|
||||
# angles from the base heading, taken on from the last target, not -180..180: right behind, +179
|
||||
# and -179 are the same place, the head and waist must not swing round, the base not turn the other way
|
||||
ref = target[0][0] if target[0] else gaze
|
||||
d, a = _rel(pose, person.at(now))
|
||||
a = ref + (a - ref + 180.0) % 360.0 - 180.0
|
||||
yaw = _rel(pose, person.at(now + HEAD_LEAD_S))[1]
|
||||
yaw = ref + (yaw - ref + 180.0) % 360.0 - 180.0
|
||||
target[0] = (max(-HEAD_YAW_MAX, min(HEAD_YAW_MAX, yaw)), HEAD_PITCH)
|
||||
target[0] = (max(-BEHIND_DEG, min(BEHIND_DEG, yaw)), HEAD_PITCH)
|
||||
walk = float(person.vel @ np.array([math.cos(pose[2]), math.sin(pose[2])]))
|
||||
cmd = speeds(d, a, v, w, walk, go=now - person.t <= COAST_S, dt=TICK_S)
|
||||
go = now - person.t <= COAST_S and abs(turned) < WAIST_DRIVE_DEG # forward with the waist ahead
|
||||
cmd = speeds(d, a, v, w, walk, go=go, dt=TICK_S)
|
||||
spot = cmd[0] == 0.0 and cmd[1] != 0.0 # a turn on the spot (the person aside or behind)
|
||||
if spot and not turning:
|
||||
hit = fetch.turn_hits(a) # the arm's whole sweep toward them
|
||||
hit = fetch.turn_hits(a - turned) # the arm's whole sweep toward them (it is turned already)
|
||||
if hit is not None:
|
||||
fetch.log(f"follow: turning {a:+.0f} deg my arm would hit something at "
|
||||
f"({hit[0]:.2f}, {hit[1]:.2f})")
|
||||
@@ -339,7 +418,8 @@ def _run(see, say, people):
|
||||
return
|
||||
turning = spot
|
||||
# stopped by something: on again only when the speed it was stopped at is clear (no creeping up to it)
|
||||
why = cmd != (0.0, 0.0) and blocked(max(cmd[0], hold_v) if cmd[0] else 0.0, cmd[1], arm_pts, pose)
|
||||
pts = [fetch._rot(turned) @ p for p in arm_pts] # the arm turned with the waist
|
||||
why = cmd != (0.0, 0.0) and blocked(max(cmd[0], hold_v) if cmd[0] else 0.0, cmd[1], pts, pose)
|
||||
if why:
|
||||
if blocked_t is None:
|
||||
fetch.log(f"follow: standing, {why}")
|
||||
@@ -358,7 +438,7 @@ def _run(see, say, people):
|
||||
driven = math.hypot(pose[0] - log_pose[0], pose[1] - log_pose[1]) / max(now - log_t, 1e-3)
|
||||
log_t, log_pose = now, pose
|
||||
fetch.log(f"follow: v {v:.2f} w {w:+.2f} driven {driven:.2f} m/s | person {d:.2f} m {a:+.0f} deg, seen "
|
||||
f"{now - (person.t or now):.2f} s ago, walking {walk:+.2f} m/s | head "
|
||||
f"{now - (person.t or now):.2f} s ago, walking {walk:+.2f} m/s | waist {turned:+.0f} head "
|
||||
f"{stats['head'] or 0:+.0f} deg ({stats['head_ms']} ms) | tick {1000 * (time.time() - now):.0f} ms")
|
||||
next_t = max(next_t + TICK_S, time.time()) # a steady rate; a slow tick is not caught up
|
||||
_stop.wait(next_t - time.time())
|
||||
@@ -382,11 +462,17 @@ def _run(see, say, people):
|
||||
_joy(0.0, 0.0)
|
||||
except (ConnectionError, OSError):
|
||||
pass # one command lasts 0.5 s: the base stops anyway
|
||||
if head_thread is not None: # the head back to rest (ahead, looking down) once its own
|
||||
head_thread.join(HEAD_TIMEOUT_S) # move has ended: overlapping movetos hang the body API
|
||||
try:
|
||||
head.moveto([*head.status()[:2], 0.0, head.HEAD_REST_PITCH], vel=HEAD_VEL, acc=HEAD_VEL,
|
||||
timeout=HEAD_TIMEOUT_S)
|
||||
if head_thread is not None: # the head back to rest (ahead, looking down), the waist to
|
||||
head_thread.join(HEAD_TIMEOUT_S) # the front, once its own move has ended: overlapping movetos
|
||||
try: # hang the body API
|
||||
lift, waist = head.status()[:2]
|
||||
back = front - waist
|
||||
if abs(back) >= 1.0 and fetch.turn_hits(back) is not None:
|
||||
fetch.log(f"follow: the waist stays at {-back:+.0f} deg: my arm would hit something going back")
|
||||
back = 0.0
|
||||
vel = fetch.WAIST_VEL if abs(back) >= 1.0 else HEAD_VEL
|
||||
head.moveto([lift, waist + back, 0.0, head.HEAD_REST_PITCH], vel=vel, acc=vel,
|
||||
timeout=60 if abs(back) >= 1.0 else HEAD_TIMEOUT_S)
|
||||
except (ConnectionError, OSError, ValueError, KeyError) as e:
|
||||
fetch.log(f"follow: head error {e!r}")
|
||||
head.owners = ()
|
||||
|
||||
Reference in New Issue
Block a user