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:
2026-10-27 20:22:32 +09:00
co-authored by Claude Opus 5.5
parent 2e8dc226ff
commit e3fa2d95b3
92 changed files with 2183 additions and 307 deletions
+81 -23
View File
@@ -1,12 +1,16 @@
"""The arm moves between named poses only along a graph of taught poses, every joint move checked before anything
moves.
"""The arm moves between named poses only by joint moves between taught poses, every joint move checked before
anything moves.
give - carry - look - wave_out - wave_start - wave
give - carry - look - wave_out - wave_start - wave (EDGES: the moves run live first)
|
ready
`look` is where every arm action starts (picks and puts go out from it and come back to it, skills.py). From any
pose of the graph the arm goes to another along the graph, one joint move per edge. An arm at no pose (after free
`look` is where every arm action starts (picks and puts go out from it and come back to it, skills.py). With an empty
hand the arm goes from pose to pose by the route of least joint travel (each move its largest joint turn plus
STOP_DEG for the stop), any two poses one joint move apart when that move passes the checks below (all but NO_EDGES;
on equal travel the EDGES first): from wave_start straight to give, from give straight to look. With something in
the hand only the EDGES (fetch runs them as straight lines, the cup upright) and never a wave pose (WAVE_POSES). An
arm at no pose (after free
drive, after a stop half way) joins the graph by one checked joint move to a pose of it, the nearest first; when no
such move passes, first straight up by UP_MM (a joint move to the IK pose above, checked the same way), then the
join. Joins further than JOIN_DEG run at HOLD_SPEED. Only when nothing passes, nothing moves and Lumi asks for the
@@ -28,6 +32,7 @@ Cobo π programs start only from `look` (start_program); hand_shaking.jks never
python manipulation/arm_route.py goto <pose> # go there along the route (SPEED; the owner at the STOP)
"""
import collections
import heapq
import sys
import time
@@ -39,7 +44,12 @@ from vision import calib, head_cam
HOME = "look" # every arm action starts here
EDGES = (("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
("wave_start", "wave"), ("look", "ready")) # the only joint moves between named poses (both ways)
("wave_start", "wave"), ("look", "ready")) # the moves with something in the hand (both ways)
NO_EDGES = {frozenset(("look", "wave_start"))} # never one joint move: passes 267 mm from the head (the wave
# goes up and down through wave_out, 309 mm)
WAVE_POSES = ("wave_out", "wave_start", "wave") # never with something in the hand (the cup would tip)
STOP_DEG = 10.0 # deg of joint travel one more stop on a route costs (SETTLE_S, slowing down and
# starting again; an estimate, it only weighs routes against each other)
SPEED = "route" # motion.JOINT_SPEED of the moves along the graph, empty hand
HOLD_SPEED = "slow" # ... with something in the hand
AT_POSE_DEG = 3.0 # deg; the arm is at a pose when every joint is this close (where, programs)
@@ -84,10 +94,10 @@ def _deg(now, pose):
return max(abs(a - b) for a, b in zip(motion.nearest(pose, now), now))
def graph():
"""{pose: joints} of the graph's taught poses."""
def graph(holding=False):
"""{pose: joints} of the graph's taught poses (`holding`: without WAVE_POSES)."""
p = motion.poses()
return {n: p[n] for e in EDGES for n in e if n in p}
return {n: p[n] for e in EDGES for n in e if n in p and not (holding and n in WAVE_POSES)}
def where(now=None):
@@ -117,10 +127,64 @@ def _path(a, b, nodes):
return None
def hops(now, target, leaf=False):
def _cheapest(a, b, nodes, ok):
"""Poses a .. b of least joint travel, one joint move between any two of `nodes` but NO_EDGES and the moves
refused in `ok` ({frozenset pair: passed}); on equal travel fewer moves off EDGES. None when there is none."""
listed = {frozenset(e) for e in EDGES}
todo, done = [((0.0, 0), [a])], set()
while todo:
cost, path = heapq.heappop(todo)
n = path[-1]
if n == b:
return path
if n in done:
continue
done.add(n)
for m in nodes:
e = frozenset((n, m))
if m not in done and e not in NO_EDGES and ok.get(e) is not False:
heapq.heappush(todo, ((cost[0] + _deg(nodes[n], nodes[m]) + STOP_DEG, cost[1] + (e not in listed)),
path + [m]))
return None
def route(a, b, nodes, holding=False):
"""Poses a .. b. Holding: the fewest EDGES. Empty hand: _cheapest, each of its moves checked (check_moves) before
it is taken, a refused one left out and the next cheapest tried. RouteError when there is no way: why the last
move was refused, else NOT_TAUGHT."""
if holding:
path = _path(a, b, nodes)
if path is None:
log(f"arm route: no way from {a} to {b} among {', '.join(nodes)}")
raise RouteError(*NOT_TAUGHT)
return path
ok, why = {}, NOT_TAUGHT
while True:
path = _cheapest(a, b, nodes, ok)
if path is None:
log(f"arm route: no checked way from {a} to {b}")
raise RouteError(*why)
for x, y in zip(path, path[1:]):
e = frozenset((x, y))
if e not in ok:
try:
check_moves(nodes[x], [nodes[y]])
ok[e] = True
except RouteError as err:
if err.args == UNSURE:
raise
ok[e], why = False, err.args
break
else:
return path
def hops(now, target, leaf=False, holding=False):
"""The poses the arm goes through from the joints `now` to `target`, in order (not the one it is at). `leaf`: the
arm is out on the task's own checked way from look (above a table): when it is at no pose, straight to target."""
nodes = graph()
if holding and target in WAVE_POSES:
raise RouteError(*SPILL)
nodes = graph(holding)
if target not in nodes:
log(f"arm route: {target} is not taught (robot/motion.py teach {target})")
raise RouteError(*NOT_TAUGHT)
@@ -135,10 +199,7 @@ def hops(now, target, leaf=False):
log(f"arm route: arm at {_r(now)}, {d[start]:.0f} deg from {start}, the nearest pose (joins within "
f"{JOIN_DEG:.0f})")
raise RouteError(*UNKNOWN)
path = _path(start, target, nodes)
if path is None:
log(f"arm route: no way from {start} to {target} among {', '.join(nodes)}")
raise RouteError(*NOT_TAUGHT)
path = route(start, target, nodes, holding)
return path if d[start] > EXACT_DEG else path[1:]
@@ -248,20 +309,17 @@ def join(now, target, holding=False):
"""[(pose, joints)] of a checked way from an arm at no pose of the graph to `target`: one joint move to a graph
pose (the nearest first), then along the graph; else first straight up by UP_MM. RouteError(UNKNOWN) when no way
passes the checks; nothing moved."""
nodes, p = graph(), motion.poses()
nodes = graph(holding)
if target not in nodes:
raise RouteError(*NOT_TAUGHT)
raise RouteError(*(SPILL if holding and target in WAVE_POSES else NOT_TAUGHT))
order = sorted(nodes, key=lambda n: (_deg(now, nodes[n]), n != HOME))
for mm in (None, *UP_MM):
first = [] if mm is None else [("up", _up(now, mm))]
if first and first[0][1] is None:
continue
for n in order:
names = _path(n, target, nodes)
if names is None:
continue
way = first + [(x, p[x]) for x in names]
for n in order: # the nearest pose first, then the way on from it
try:
way = first + [(x, nodes[x]) for x in route(n, target, nodes, holding)]
return list(zip([x for x, _ in way], check_moves(now, [j for _, j in way], holding)))
except RouteError as e:
if e.args == UNSURE:
@@ -274,7 +332,7 @@ def plan(target, holding=False, leaf=False, now=None):
"""[(pose, joints)] of the checked way from here to `target` ([] when it is there). RouteError to refuse."""
now = skills._joints() if now is None else now
try:
names = hops(now, target, leaf)
names = hops(now, target, leaf, holding)
except RouteError as e:
if e.args != UNKNOWN:
raise
+11 -9
View File
@@ -150,10 +150,11 @@ IK_SEEDS = ("ready", "look", "carry", "give") # taught poses whose arm configu
# seed, so one seed alone misses cups another configuration reaches
WRIST_MIN_DEG = 10.0 # deg; |J5| at least this at above, grasp and lift (estimate: the
# proven picks had J5 +20; near 0 J4 / J6 swing round)
TRUSTED_YAW_DEG = 15.0 # deg; grasp turns up to this picked live (-10, -15: 3 of 3); -30 and
# -45 missed 4 of 4 (2026-10-26, a finger end on the rim). The taught
# grasp point's horizontal error turns with the grasp:
# a waist turn or a base move comes before a larger turn
TRUSTED_YAW_DEG = 15.0 # deg; grasp turns from -this to 0 picked live (-10, -15: 3 of 3); -30
# and -45 missed 4 of 4 (2026-10-26, a finger end on the rim); +15
# missed 2 of 2 (2026-10-27, a finger on the cup, DI_1 set; never hover-
# checked). The taught grasp point's horizontal error turns with the
# grasp: a waist turn or a base move comes before another turn
COMFORT_R_MM = 710.0 # mm, cup's horizontal distance from the arm base origin: picks proven
# up to here (furthest live success (-68, 703)); further, the base moves
# in first when it can (tasks/fetch.py). Estimate until measured live
@@ -760,7 +761,8 @@ def checked(waypoints, start_joints):
def pick_options(obj, start, max_yaw=None):
"""(waypoints, joints above) of every grasp turn (GRASP_YAWS; within `max_yaw` deg when given) and wrist solution
"""(waypoints, joints above) of every grasp turn (GRASP_YAWS; from -`max_yaw` to 0 deg when given: the turns picked
live, TRUSTED_YAW_DEG) and wrist solution
reachable from `start`: a joint move down to above that stays above it, then straight down and up; the controller
confirms each one given. Every pick that worked live had J5 > 0: those come first. Objects of the wrong width
raise."""
@@ -768,7 +770,7 @@ def pick_options(obj, start, max_yaw=None):
tried = []
for wrist, seeds in ((1, IK_SEEDS[:1]), (1, IK_SEEDS[1:]), (-1, IK_SEEDS[:1]), (-1, IK_SEEDS[1:])):
for yaw in GRASP_YAWS: # the proven wrist (J5 > 0) and `ready` configuration first
if max_yaw is not None and abs(yaw) > max_yaw:
if max_yaw is not None and not -max_yaw <= yaw <= 0:
continue
waypoints = plan_pick(obj, yaw)
for ja in above_joints(waypoints[0][1], start, seeds):
@@ -884,7 +886,7 @@ def carry_by_joints(plan):
def reachable_pick(obj, start=None, accept=lambda waypoints, ja: True, max_yaw=None):
"""(waypoints, joints above) of the first pick option from `start` (home), grasp turned at most `max_yaw` deg
"""(waypoints, joints above) of the first pick option from `start` (home), grasp turned -`max_yaw`..0 deg
(e.g. TRUSTED_YAW_DEG; None: any), that `accept` also takes, else None."""
for waypoints, ja in pick_options(obj, home_joints() if start is None else start, max_yaw):
if accept(waypoints, ja):
@@ -893,7 +895,7 @@ def reachable_pick(obj, start=None, accept=lambda waypoints, ja: True, max_yaw=N
log(f"grasp {how}, turned {yaw:+d} deg, wrist J5 {ja[4]:+.0f}" if yaw else
f"grasp {how}, wrist J5 {ja[4]:+.0f}")
return waypoints, ja
log(f"plan refused: no grasp turn{'' if max_yaw is None else f' within {max_yaw:.0f} deg'} reaches "
log(f"plan refused: no grasp turn{'' if max_yaw is None else f' from -{max_yaw:.0f} to 0 deg'} reaches "
f"({obj['x']:.0f}, {obj['y']:.0f})")
return None
@@ -1014,7 +1016,7 @@ def pick(name="cup", colour=None):
obj = find(name, colour)
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}")
plan = reachable_pick(obj)
plan = reachable_pick(obj, max_yaw=TRUSTED_YAW_DEG) # no base here to bring it round (fetch can)
if plan is None:
raise SkillError("I can't reach it safely.")
_guarded(_do_pick, obj, *plan)