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:
2026-10-29 15:55:03 +09:00
co-authored by Claude Opus 5.5
parent 390ec9db99
commit e8d651da49
24 changed files with 728 additions and 200 deletions
+153 -37
View File
@@ -102,6 +102,8 @@ SEARCH_BASE_DEG = (180.0, 90.0) # then the base turns towards that side, th
LIFT_TRIES = LIFT_RANGE # mm; nothing found: all of it again at the other end of these
SAME_BASE_M = 0.02 # m / rad; the base is still where it picked: the pick spot is still table
SAME_BASE_RAD = 0.035
BACK_DOWN_MM = 60.0 # mm; held with the flange this near (sideways) over the pick spot, base, waist and
# lift as they picked: a put down goes straight down there, no look first
WAIST_REACH_STEPS = (0.0, 15.0, -15.0, 30.0, -30.0) # deg; a pick out of reach: waist turns tried around the one
# that brings the object to PICK_ZONE_CENTRE's bearing about the column (the waist carries
# the arm round the column: what it reaches beside it, it reaches ahead), before a base move
@@ -149,6 +151,8 @@ HEAD_LOW_PITCH = -5.0 # head pitch for those checks and the search: its l
HEAD_READS = 4 # head camera frames read per view (10 a second) ...
HEAD_SAME_MM = 120.0 # ... an object counts when seen at least twice within this distance
WAIST_VEL = 20 # % of the waist's speed: the arm sweeps sideways
WAIST_STEP_DEG = 10.0 # deg; a waist turn made together with an arm move goes in moves this long: the body API
# cannot stop a moveto, so a STOP ends the turn after the move it is in (_give_turning)
HEAD_AHEAD = (0.0, head.HEAD_REST_PITCH) # head (yaw, pitch) deg before a drive to a place and after every task: ahead, at rest
# (search turns and short moves keep the head where the search turned it)
OFFSET_TURN_DEG = 15.0 # a move that turned the base at least this much tells where the arm base is (arm_offset)
@@ -570,9 +574,11 @@ def _charging():
return True # unknown: better not drive off
def arm_points_3d():
"""(x, y, z) mm in the arm base frame of the flange, the grasp point and the finger tips, from the joints now."""
c = skills._ask("kine_forward", jointPosition=[float(v) for v in skills._joints()])["cartPosition"]
def arm_points_3d(joints=None):
"""(x, y, z) mm in the arm base frame of the flange, the grasp point and the finger tips, at `joints` (default:
the joints now)."""
joints = skills._joints() if joints is None else joints
c = skills._ask("kine_forward", jointPosition=[float(v) for v in joints])["cartPosition"]
R, f = calib.rpy_matrix(*c[3:]), np.array(c[:3])
g = f + R @ skills.GRASP_OFFSET
return [f, g, g + R @ (skills.TIP_MM * skills.FINGER_DIR)]
@@ -595,26 +601,28 @@ def _near_hand(p, pts):
return best
def depth_hits(deg, camera="torso", T=None):
def depth_hits(deg, camera="torso", T=None, pts=None):
"""Like turn_hits, with the torso depth camera: the arm's points along the turn at their real height (a table top's
edge, a shelf: the lidar at the base's height does not see them), (x, y, z) mm in the arm frame now of the first
one the camera sees something at or in front of; None when clear. Points out of its view are left to the lidar;
depth on the arm's own parts (in view, within SELF_MM of them) does not count. Another camera: its name and its
camera -> arm base transform T."""
camera -> arm base transform T. `pts`: the arm-frame points (mm) of every pose the arm passes while it turns
(_route_points), checked from the start of the turn on; default the hand now, from the first step."""
yaw = arm_yaw()
T = skills.objects.base_from_camera() if T is None else T
if yaw is None or T is None:
return None
pts, t, cam = arm_points_3d(), arm_xy(), T[:3, 3]
hand, t, cam = arm_points_3d(), arm_xy(), T[:3, 3]
k0, pts = (1, hand) if pts is None else (0, pts)
n = max(1, math.ceil(abs(deg) / SWEEP_STEP_DEG))
cand = []
for k in range(1, n + 1):
for k in range(k0, n + 1):
R = _rot(deg * k / n)
for p in pts:
xy = _rot(-yaw) @ (R @ to_base(p[:2], yaw, t) - t) * 1000.0
cand.append(np.array([xy[0], xy[1], p[2]]))
for c, h in zip(cand, skills.surface_points([tuple(c) for c in cand], camera=camera, T=T)):
if h is None or _near_hand(h, pts) < SELF_MM:
if h is None or _near_hand(h, hand) < SELF_MM:
continue
if np.linalg.norm(np.subtract(h, cam)) <= np.linalg.norm(c - cam) + ARM_CLEAR_M * 1000.0:
return c
@@ -653,7 +661,7 @@ def _head_to(yaw, pitch):
skills.moved("head")
def head_hits(deg):
def head_hits(deg, pts=None):
"""depth_hits with the head camera turned towards the side of the turn: the torso camera sees only ahead, the arm
sweeps to the side. None when clear, or when the head camera is not calibrated (then the other checks decide).
The head stays there: the next look or drive turns it where it needs it."""
@@ -662,18 +670,19 @@ def head_hits(deg):
if T is None:
return None
_head_to(side, HEAD_LOW_PITCH)
return depth_hits(deg, "head", T)
return depth_hits(deg, "head", T, pts)
def turn_hits(deg):
def turn_hits(deg, pts=None):
"""The map point (x, y) where the arm would come closer than ARM_CLEAR_M to something the lidar or the map shows
while the base turns by `deg`, checked every SWEEP_STEP_DEG along the way; None when the way is clear. The base
itself turns in its own footprint; navigation does not know about the arm sticking out."""
itself turns in its own footprint; navigation does not know about the arm sticking out. `pts`: as depth_hits."""
if arm_yaw() is None:
return None
pts, (x, y, th) = arm_points(), agv.pose()
k0, pts = (1, arm_points()) if pts is None else (0, [to_base(p[:2], arm_yaw(), arm_xy()) for p in pts])
x, y, th = agv.pose()
n = max(1, math.ceil(abs(deg) / SWEEP_STEP_DEG))
for k in range(1, n + 1):
for k in range(k0, n + 1):
R = _rot(math.degrees(th) + deg * k / n)
for p in pts:
w = np.array([x, y]) + R @ p
@@ -682,15 +691,16 @@ def turn_hits(deg):
return None
def _sweep_blocked(deg, what):
def _sweep_blocked(deg, what, pts=None):
"""True (and logged) when the arm would hit something while it swings by `deg` about the base centre: a base turn
on the spot and a waist turn sweep the same circles (turn_hits, depth_hits, head_hits)."""
hit = turn_hits(deg)
on the spot and a waist turn sweep the same circles (turn_hits, depth_hits, head_hits). `pts`: as depth_hits."""
kw = {} if pts is None else {"pts": pts}
hit = turn_hits(deg, **kw)
if hit is not None:
log(f"not {what} {deg:+.0f} deg: my arm would hit something at ({hit[0]:.2f}, {hit[1]:.2f})")
return True
for cam, check in (("camera", depth_hits), ("head camera", head_hits)):
seen = check(deg)
seen = check(deg, **kw)
if seen is not None:
log(f"not {what} {deg:+.0f} deg: the {cam} sees something in my arm's way at ({seen[0]:.0f}, "
f"{seen[1]:.0f}, {seen[2]:.0f}) mm")
@@ -1656,10 +1666,7 @@ def place_spots(held, base_now, seen, table=None):
"""Where the held object may go: the pick spot when the base has not moved since the pick, then free grid spots
the depth camera sees as table at `table` mm (default: the pick table's height), nearest the pick zone centre
first. Free: FREE_MM from everything seen standing on the table."""
b0 = held.get("base")
same = b0 is not None and math.hypot(base_now[0] - b0[0], base_now[1] - b0[1]) < SAME_BASE_M \
and abs((base_now[2] - b0[2] + math.pi) % (2 * math.pi) - math.pi) < SAME_BASE_RAD \
and abs(held.get("waist", 0.0) - _waist_turn()) < 1.0
same = _same_stand(held, base_now)
tries = [(held["x"], held["y"])] if same else []
others = [o for o in seen if not (same and math.hypot(o["x"] - held["x"], o["y"] - held["y"]) < skills.CLUSTER_MM)]
table = held.get("table") if table is None else table
@@ -1675,6 +1682,31 @@ def place_spots(held, base_now, seen, table=None):
return tries + skills.on_table(grid, table)
def _same_stand(held, base_now):
"""The base and the waist are still where `held` was picked: the pick spot is where it was in the arm frame."""
b0 = held.get("base")
return b0 is not None and math.hypot(base_now[0] - b0[0], base_now[1] - b0[1]) < SAME_BASE_M \
and abs((base_now[2] - b0[2] + math.pi) % (2 * math.pi) - math.pi) < SAME_BASE_RAD \
and abs(held.get("waist", 0.0) - _waist_turn()) < 1.0
def _put_back_here(top0):
"""Held over the spot it was picked from (a voice pick ends just above it, a stop after the grasp leaves it there)
with the base, the waist and the lift as they picked: straight down there, checked like any place (_place_at),
no look first. Live 2026-10-29: "put it on the table" took the cup to look and back to the same table. None when
it is held elsewhere or the way down is refused (then the search from look)."""
h = skills._held
lift0 = h.get("lift")
if not _same_stand(h, agv.pose()) or lift0 is None or abs(lift0 - head.status()[0]) >= LIFT_TOL_MM:
return None
above = skills.plan_place(h["x"], h["y"], top0, yaw=h.get("yaw", 0.0))[0][1]
now = motion.tcp()
if math.hypot(now[0] - above[0], now[1] - above[1]) > BACK_DOWN_MM:
return None
log("held over the spot it was picked from: putting it back down there")
return _place_at([(h["x"], h["y"])], top0, turned=False)
def _place_here(top0, kept=None):
"""One look for a place from where the arm is (look, the held object out of the view): measure the table (the
kept one's height only, _kept_band), fit the lift, try the spots. True when the object was put down, else None."""
@@ -1792,9 +1824,9 @@ def _place_far(top0, far):
return _place_at(spots, _top_on(top0, far["table"]))
def _place_at(tries, top):
def _place_at(tries, top, turned=True):
"""Put the held object down at the first of `tries` (x, y) whose way down passes IK: straight from here with the
held grasp turn, else any grasp turn and wrist (skills.place_options). True when it is down."""
held grasp turn, else (`turned`) any grasp turn and wrist (skills.place_options). True when it is down."""
log(f"place spots: {', '.join(f'({x:.0f}, {y:.0f})' for x, y in tries[:6])}")
for n, (x, y) in enumerate(tries):
if n >= PLACE_REFUSALS: # the rest are further / lower: each refused spot costs ~1 s of
@@ -1818,6 +1850,8 @@ def _place_at(tries, top):
return True
if rows:
log(f"spot ({x:.0f}, {y:.0f}) refused at {rows[-1][0]}: {rows[-1][3]}")
if not turned:
continue
opt = next(skills.place_options(x, y, top, skills._joints()), None) # another grasp turn or wrist (the
if opt: # cup's own turn does not matter)
log(f"putting it down at ({x:.0f}, {y:.0f})")
@@ -2131,6 +2165,10 @@ def _put_down(say=None, on=None):
if top is None:
raise FetchError("I'm not holding anything I picked.")
_step("placing")
if not on or not on.get("pointed") and on.get("name") == "dining table" and not on.get("colour") and \
on.get("prefer") in (None, "near"):
if _put_back_here(top): # held just above the table it came from
return
_line_holding(LOOK_POSE)
if on and on.get("pointed"): # "put it here / there" with a pointing hand
return _put_pointed(top, say)
@@ -2220,6 +2258,7 @@ def _pick_here(task, say):
no = skills.refusal(task["object"])
if no:
raise FetchError(*no)
skills._guarded(skills.back_out) # a pick stopped beside / around it: out the way it came
for attempt in range(PICK_TRIES):
_step("looking")
obj = _see(task, say)
@@ -2227,15 +2266,12 @@ def _pick_here(task, say):
obj, waypoints, ja = _reach(task, obj, say)
_step("picking")
try:
skills._guarded(skills._do_pick, obj, waypoints, ja) # ends 3 cm above the table, holding
_pick(obj, waypoints, ja) # ends 3 cm above the table, holding
break
except skills.SkillError as e:
if e.args[0] not in MISSES or attempt == PICK_TRIES - 1:
raise
_say(say, "I missed it. Let me try again.", "놓쳤어요. 다시 해 볼게요.")
skills._held["base"] = agv.pose() # place_spots: put back here if the base stays ...
skills._held["waist"] = _waist_turn() # ... and the waist too
skills._held["lift"] = head.status()[0] # _top_on when its table was not measured
skills._held["what"] = {"object": task["object"], "colour": task.get("colour")} # held_name() when the state lost it
_set(holding=True, held_object=skills._held["what"])
_say(say, "I've got it.", "잡았어요.")
@@ -2244,6 +2280,23 @@ def _pick_here(task, say):
_carry_from(waypoints[0][1], ja)
def _pick(obj, waypoints, ja):
"""skills._do_pick; whenever it leaves the object held, also after a stop in the lift, the stand is noted with it
(a put down goes straight back down from here: _put_back_here)."""
try:
skills._guarded(skills._do_pick, obj, waypoints, ja)
finally:
if "top_mm" in skills._held:
_note_stand()
def _note_stand():
"""Where the body stood at the pick, kept with the held object."""
skills._held["base"] = agv.pose() # place_spots, _put_back_here: put back here if the base
skills._held["waist"] = _waist_turn() # stays ... and the waist too
skills._held["lift"] = head.status()[0] # _top_on when its table was not measured
def _carry_from(above, ja):
"""Holding, the arm at `above` (flange pose over the pick spot, joints `ja` there): to look the way a pick ends."""
try:
@@ -2421,12 +2474,13 @@ def pick_here(name, colour=None, say=None):
task = {"object": name, "colour": colour}
_clear()
try:
skills._guarded(skills.back_out) # a pick stopped beside / around it: out the way it came
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)
_pick(obj, waypoints, ja)
finally:
_set(step="")
return obj
@@ -2961,11 +3015,11 @@ def give_bearing():
def reach(angle=0.0, say=None, look=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, 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
"""Hold the hand out to the person ("reach out to me", "손 내밀어"): when `angle` (deg, + left, waist frame: the
person tracker's) is not 0, the waist turns to face them while the arm goes along the pose graph to give, both at
once (_give_turning, also with Patrol off: the base stays; the arm's sweep over the turn checked first; past the
waist's limits they are asked to stand in front; the waist stays turned after; the head stays on them, also
after); else only the arm 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. `look`: the person's angle the
head stays on when the waist turns by another `angle` (to bring the hand, not the waist's front, onto them)."""
if "give" not in motion.poses():
@@ -2981,10 +3035,11 @@ def reach(angle=0.0, say=None, look=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(), in_place=True, look=angle if look is None else look):
if not lo <= head.status()[1] + angle <= hi:
raise FetchError(*TURN_TO_PERSON)
_pose("give")
_give_turning(angle + _waist_turn(), angle if look is None else look)
else:
_pose("give")
_reach_to_hand(*_person_point())
_set(status="done", step="")
log("reached out")
@@ -2993,6 +3048,67 @@ def reach(angle=0.0, say=None, look=None):
_launch(run, ahead=False) # the head stays on the person, not ahead
def _route_points(seq):
"""Arm-frame points (mm; flange, grasp point, finger tips) of the arm now, halfway along each joint move of the
arm_route plan `seq` and at its end: where the hand can be while it goes along it."""
js, prev = [skills._joints()], skills._joints()
for _, j in seq:
js += [[(a + b) / 2 for a, b in zip(prev, j)], j]
prev = j
return [p for j in js for p in arm_points_3d(j)]
def _give_turning(rel, look):
"""The waist turns to `rel` (as _waist_to, in place) while the arm goes along the pose graph to give, both at once:
the hand comes out toward the person while Lumi turns to them; the head stays on `look` (waist-frame deg, as
before the turn). Checked before anything moves: the arm route (arm_route: joints, the head; the arm and the head
both sit on the waist, so those checks hold at any waist angle) and the sweep of the hand at every pose it passes
(_route_points) over the whole turn, from its start (_sweep_blocked). FetchError(TURN_TO_PERSON) when the sweep is
not clear. The waist command goes out first, in its own thread in WAIST_STEP_DEG moves; then the arm route; then
both are waited for. A STOP or a failed arm move ends the waist turn after the move it is in."""
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 _pose("give")
_go_on()
pitch = head.status()[3] # head_hits turns the head to the side: it comes back with the waist
try:
seq = arm_route.plan("give")
except arm_route.RouteError as e:
raise FetchError(*e.args) from e
if _sweep_blocked(d, "turning my waist with my arm", pts=_route_points(seq)):
raise FetchError(*TURN_TO_PERSON)
_go_on()
lift = head.status()[0]
n, halt, out = max(1, math.ceil(abs(d) / WAIST_STEP_DEG)), threading.Event(), {}
log(f"waist {waist:.0f} -> {waist + d:.0f} deg with the arm to give: {' -> '.join(x for x, _ in seq) or 'there'}")
def turn():
try:
for k in range(1, n + 1):
if halt.is_set():
return
dk = d * k / n
y = max(-head.YAW_LIMIT, min(head.YAW_LIMIT, look - dk))
_body_move([lift, waist + dk, y, pitch], vel=WAIST_VEL, acc=20, timeout=60)
except Exception as e:
out["error"] = e
t = threading.Thread(target=turn, name="waist", daemon=True)
t.start()
try:
arm_route.move(seq)
while t.is_alive():
if _stop.wait(0.1):
raise Stopped()
finally:
halt.set()
if "error" in out:
raise out["error"]
skills.moved()
_go_on()
def _arm(pose):
if pose in ("open", "close"):
st = gripper.open_() if pose == "open" else gripper.close()
+30 -16
View File
@@ -6,10 +6,10 @@ 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) 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
this task moves the body meanwhile: head.owners), straight on them (up to +-180 on the waist), sent where they will be
seen from where the base will be when the move ends; the base turns toward them at the same time. The waist never
turns further out: following starts with it where it is (turned toward the person after "look behind") and it unwinds
as the base comes round (unwind). Nothing waits for another. 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.
@@ -60,10 +60,9 @@ TICK_S = 0.1 # s between commands, steady (joy_control wants > 2
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
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)
HEAD_REL_MAX = 30.0 # deg; a turned waist unwinds until the person is this far from the base heading, the
# head looks for the rest (it never turns further out while following, unwind())
WAIST_FOLLOW_MAX = 90.0 # deg from the front; a waist turned further unwinds to this first (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
@@ -75,8 +74,11 @@ WAIST_DRIVE_DEG = 15.0 # deg; the base drives forward only with the waist t
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)
HEAD_VEL = 50 # speed ratio %; the head is at its full speed from 50 (audio/sing.py, measured)
HEAD_LEAD_S = 0.3 # s; the head is sent where the person will be, seen from where the base will be, this
HEAD_LEAD_MAX_S = 1.5 # much later at least, or as long as the last head move took (live 0.5-1.3 s), at most this:
# the base turning 0.6 rad/s goes 35-45 deg round in one move, which left the head off them
HEAD_VEL = 100 # speed and acceleration ratio %, the body API's maximum: the head's speed tops out from 50
# (~40 deg/s, audio/sing.py, measured at 100 / 100); the waist's moves keep WAIST_FOLLOW_VEL
HEAD_TIMEOUT_S = 5 # s; one head move (90 deg at ~40 deg/s takes ~2.5 s)
CHARGER = ("I'm on the charger, I can't follow you from here.", "충전 중이라 따라갈 수 없어요.")
@@ -284,11 +286,20 @@ def waist_for(b):
return max(-WAIST_FOLLOW_MAX, min(WAIST_FOLLOW_MAX, math.copysign(max(0.0, abs(b) - HEAD_REL_MAX), b)))
def unwind(w, b):
"""Where the waist, turned w deg, goes for a person b deg from the base heading: toward waist_for(b), but only
back toward the front, never further out. Turning out made every move a slow waist move and, with the base turning
the same way, left the head 40-70 deg off the person (live 2026-10-29, lost): the head alone follows them, the
base turns, and the waist unwinds as the base comes round (the head's turn back gets smaller, not bigger)."""
goal = waist_for(b)
return 0.0 if goal * w <= 0.0 else math.copysign(min(abs(goal), abs(w)), w)
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);
"""Turn the head to the person at target[0] (deg from the base heading, pitch), the waist back toward the front
with it. 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 unwind() in the same move, so a turned waist comes back 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."""
@@ -299,7 +310,7 @@ def _head_follow(target, done, lift, front, w, waist_free, stats):
done.wait(TICK_S / 2)
continue
b, pitch = t
want = waist_for(b) - w if waist_free and time.time() >= retry else 0.0
want = unwind(w, 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
@@ -405,7 +416,10 @@ def _run(see, say, people):
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]
lead = max(HEAD_LEAD_S, min((stats["head_ms"] or 0) / 1000.0, HEAD_LEAD_MAX_S))
then = (pose[0] + v * lead * math.cos(pose[2]), pose[1] + v * lead * math.sin(pose[2]),
pose[2] + w * lead) # the base when the head gets there (v, w: this command)
yaw = _rel(then, person.at(now + lead))[1]
yaw = ref + (yaw - ref + 180.0) % 360.0 - 180.0
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])]))