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:
+36
-16
@@ -1,9 +1,9 @@
|
||||
"""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 (EDGES: the moves run live first)
|
||||
|
|
||||
ready
|
||||
give_pre - 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). 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
|
||||
@@ -26,10 +26,16 @@ cup's lean at most skills.MAX_TILT_DEG. Refusals are RouteError with the reason
|
||||
A route runs one move at a time (motion.move_path): each to a full stop and SETTLE_S standing, then the next; SPEED
|
||||
with an empty hand, HOLD_SPEED with something in it.
|
||||
|
||||
With an empty hand and `give_pre` taught, every way to `give` ends give_pre -> give: the route goes to `give_pre`
|
||||
(never through `give`), stands there, and the last move into `give` runs at GIVE_SPEED. Without `give_pre` the route
|
||||
to `give` is the plain cheapest one. With something in the hand `give_pre` is not used (fetch's straight moves).
|
||||
|
||||
Cobo π programs start only from `look` (start_program); hand_shaking.jks never (it hit the head, 2026-10-21).
|
||||
|
||||
python manipulation/arm_route.py check [pose] # the route from here to pose (default look), checked; moves nothing
|
||||
python manipulation/arm_route.py goto <pose> # go there along the route (SPEED; the owner at the STOP)
|
||||
|
||||
Teach a pose (arm moved by hand in Cobo π first): python robot/motion.py teach give_pre (then teach give)
|
||||
"""
|
||||
import collections
|
||||
import heapq
|
||||
@@ -43,7 +49,10 @@ from robot import arm, gripper, kinematics, motion
|
||||
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"),
|
||||
GIVE = "give" # the hand held out to a person
|
||||
GIVE_PRE = "give_pre" # one step before GIVE: an empty-hand way to GIVE always ends GIVE_PRE -> GIVE
|
||||
GIVE_SPEED = "slow" # motion.JOINT_SPEED of the last move, GIVE_PRE -> GIVE (first live runs: slow)
|
||||
EDGES = (("give_pre", "give"), ("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
|
||||
("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)
|
||||
@@ -94,10 +103,11 @@ def _deg(now, pose):
|
||||
return max(abs(a - b) for a, b in zip(motion.nearest(pose, now), now))
|
||||
|
||||
|
||||
def graph(holding=False):
|
||||
"""{pose: joints} of the graph's taught poses (`holding`: without WAVE_POSES)."""
|
||||
def graph(holding=False, skip=()):
|
||||
"""{pose: joints} of the graph's taught poses but `skip` (`holding`: without WAVE_POSES and GIVE_PRE)."""
|
||||
p = motion.poses()
|
||||
return {n: p[n] for e in EDGES for n in e if n in p and not (holding and n in WAVE_POSES)}
|
||||
return {n: p[n] for e in EDGES for n in e
|
||||
if n in p and n not in skip and not (holding and n in WAVE_POSES + (GIVE_PRE,))}
|
||||
|
||||
|
||||
def where(now=None):
|
||||
@@ -179,12 +189,13 @@ def route(a, b, nodes, holding=False):
|
||||
return path
|
||||
|
||||
|
||||
def hops(now, target, leaf=False, holding=False):
|
||||
def hops(now, target, leaf=False, holding=False, skip=()):
|
||||
"""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."""
|
||||
arm is out on the task's own checked way from look (above a table): when it is at no pose, straight to target.
|
||||
`skip`: poses the way must not pass."""
|
||||
if holding and target in WAVE_POSES:
|
||||
raise RouteError(*SPILL)
|
||||
nodes = graph(holding)
|
||||
nodes = graph(holding, skip)
|
||||
if target not in nodes:
|
||||
log(f"arm route: {target} is not taught (robot/motion.py teach {target})")
|
||||
raise RouteError(*NOT_TAUGHT)
|
||||
@@ -305,11 +316,11 @@ def _up(now, mm):
|
||||
return r.get("jointPosition")
|
||||
|
||||
|
||||
def join(now, target, holding=False):
|
||||
def join(now, target, holding=False, skip=()):
|
||||
"""[(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 = graph(holding)
|
||||
nodes = graph(holding, skip)
|
||||
if target not in nodes:
|
||||
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))
|
||||
@@ -329,14 +340,22 @@ def join(now, target, holding=False):
|
||||
|
||||
|
||||
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."""
|
||||
"""[(pose, joints)] of the checked way from here to `target` ([] when it is there). RouteError to refuse.
|
||||
Empty hand to GIVE with GIVE_PRE taught: the way to GIVE_PRE (not through GIVE), then GIVE."""
|
||||
now = skills._joints() if now is None else now
|
||||
if target == GIVE and not holding and GIVE_PRE in graph() and where(now) != GIVE:
|
||||
seq = _plan(GIVE_PRE, False, leaf, now, skip=(GIVE,))
|
||||
return seq + [(GIVE, check_moves(seq[-1][1] if seq else now, [motion.poses()[GIVE]])[0])]
|
||||
return _plan(target, holding, leaf, now)
|
||||
|
||||
|
||||
def _plan(target, holding, leaf, now, skip=()):
|
||||
try:
|
||||
names = hops(now, target, leaf, holding)
|
||||
names = hops(now, target, leaf, holding, skip)
|
||||
except RouteError as e:
|
||||
if e.args != UNKNOWN:
|
||||
raise
|
||||
seq = join(now, target, holding)
|
||||
seq = join(now, target, holding, skip)
|
||||
log(f"arm route: joining from {_r(now)} by {' -> '.join(n for n, _ in seq)}, checked")
|
||||
return seq
|
||||
p = motion.poses()
|
||||
@@ -351,7 +370,8 @@ def move(seq, speed=None, holding=False):
|
||||
t0 = time.time()
|
||||
log(f"arm to {' -> '.join(n for n, _ in seq)}")
|
||||
s = HOLD_SPEED if holding else speed or SPEED
|
||||
motion.move_path([(j, s) for _, j in seq])
|
||||
last = GIVE_SPEED if not holding and GIVE_PRE in graph() else s # GIVE_PRE -> GIVE (plan)
|
||||
motion.move_path([(j, last if n == GIVE else s) for n, j in seq])
|
||||
log(f"arm at {seq[-1][0]} after {time.time() - t0:.1f} s")
|
||||
|
||||
|
||||
|
||||
+44
-8
@@ -65,10 +65,10 @@ LIFT_MM = 30.0 # first lift after closing, the
|
||||
MAX_TILT_DEG = 15.0 # deg; a held cup's axis may lean this far from vertical on a joint
|
||||
# move with it (place_options; tasks/fetch.py uses the same)
|
||||
PLACE_EXTRA_MM = 3.0 # put down this much higher than it was picked (same table)
|
||||
MIN_WIDTH, MAX_WIDTH = 70.0, 81.0 # mm: the cup's top goes through the open hooks' ring (87 by tape) and
|
||||
# the belly closes round it (closed 68). MAX_WIDTH: the owner's margin
|
||||
# 6 for the camera (an 84 mm rim read 83-85); wider tops are taken from
|
||||
# the side (side()). The tips grasp (61-72) missed twice live on a
|
||||
MIN_WIDTH, MAX_WIDTH = 70.0, 97.0 # mm: the cup's top goes through the open hooks' ring (tips 100 open,
|
||||
# owner's measure) and the belly closes round it. MAX_WIDTH: the
|
||||
# owner's margin 3; wider tops are taken from the side (side()). The
|
||||
# tips grasp (61-72) missed twice live on a
|
||||
# 66 mm can (2026-10-22): off by the owner until it is checked; 61
|
||||
# brings it back
|
||||
SEEN_UNDER_MM = 8.0 # the camera's width is this much under the width the fingers meet
|
||||
@@ -119,9 +119,9 @@ BELOW_SHOULDER_MM = 80.0 # bottles: grasp this far below
|
||||
# the owner's taught tips grasp of a spray can, at its middle (2026-10-22,
|
||||
# grasp_tips_teach.json); the hand's lowest part (TIP_MM below) must
|
||||
# stay TIP_CLEAR_MM above the table (else its lowest point seen)
|
||||
SIDE_MAX_WIDTH = 84.0 # mm; side grasp (a cup whose top is wider than MAX_WIDTH): the width the
|
||||
SIDE_MAX_WIDTH = 97.0 # mm; side grasp (a cup whose top is wider than MAX_WIDTH): the width the
|
||||
# fingers meet (seen + SIDE_SEEN_MM) where the hooks go in from the
|
||||
# side, under the open tips' 87 mm (owner's tape) with a margin 3
|
||||
# side, under the open tips' 100 mm (owner's measure) with a margin 3
|
||||
SIDE_SEEN_MM = 0.0 # ... the camera's width of a cup's lower part is not under like its rim:
|
||||
# an 84 mm rim cup read 73-77 where the tape gave 71 (45 mm up) and
|
||||
# AI_1 74 (60 mm up, 2026-10-29)
|
||||
@@ -195,8 +195,11 @@ CONFIRM_DEG = 2.0 # deg; its inverse kinematics w
|
||||
RETRIES = 4 # the controller now and then answers with nothing: ask again,
|
||||
RETRY_S = 0.2 # waiting this long, twice as long each time (it drops connections)
|
||||
OPEN_AI = gripper.CLOSED_AI # AI_1 below this after opening = released
|
||||
BACK_OUT_NEAR_MM = 30.0 # back_out: the hand this near the stopped pick's way in is still in it
|
||||
|
||||
_held = {} # what pick() holds: {"top_mm", "x", "y"} for place() / put_down()
|
||||
_pick_way = {} # the pick's waypoints {name: pose} from the move to above until the
|
||||
# hand holds or has backed out (back_out after a stop)
|
||||
_cancel = threading.Event() # set by cancel(): the running skill makes no further move
|
||||
LOG = collections.deque(maxlen=40) # last log lines, shown by the API
|
||||
moved_at = {} # camera -> time its last move (lift, waist, base, head) ended:
|
||||
@@ -1015,6 +1018,7 @@ def _prepare():
|
||||
if gripper.state()["ai"][0] > OPEN_AI:
|
||||
log("opening the gripper")
|
||||
gripper.open_()
|
||||
back_out()
|
||||
if max(abs(a - b) for a, b in zip(_joints(), home_joints())) > 1.0:
|
||||
from manipulation import arm_route
|
||||
arm_route.goto(home())
|
||||
@@ -1038,14 +1042,40 @@ def _give_up(reason, back=0.0):
|
||||
"""Open, back up 100 mm (from a side grasp first `back` mm out sideways: the rim is wider than the hooks), home,
|
||||
raise. Only used while the object is at (or just above) the table."""
|
||||
log(f"{reason}: opening, backing up")
|
||||
_held.clear()
|
||||
gripper.open_()
|
||||
if back:
|
||||
_line("out sideways", back_off(motion.tcp(), back))
|
||||
motion.move_linear(delta=[0, 0, ABOVE_MM], speed=HOLDING_SPEED)
|
||||
_back_home()
|
||||
_pick_way.clear()
|
||||
raise SkillError(reason)
|
||||
|
||||
|
||||
def back_out():
|
||||
"""A pick stopped on its way in (_pick_way: the open hand beside the object or down around it): out the way it
|
||||
came before anything else moves, a side grasp straight out against the tips' direction to its "side" point, then
|
||||
straight up to its "above" height. Nothing when no pick was stopped there or the hand is no longer near its way."""
|
||||
if not _pick_way:
|
||||
return
|
||||
now, way = motion.tcp(), _pick_way
|
||||
above, grasp = way["above"], way["grasp"]
|
||||
start = way.get("side", grasp)
|
||||
near = np.hypot(start[0] - grasp[0], start[1] - grasp[1]) + BACK_OUT_NEAR_MM
|
||||
if now[2] >= above[2] - 1.0 or now[2] < grasp[2] - BACK_OUT_NEAR_MM or \
|
||||
np.hypot(now[0] - grasp[0], now[1] - grasp[1]) > near:
|
||||
_pick_way.clear() # already up there, or moved away since: nothing to back out of
|
||||
return
|
||||
log("a pick was stopped here: backing out the way it came in")
|
||||
if "side" in way:
|
||||
d = float(np.dot(np.subtract(now[:2], start[:2]), tips_dir(yaw_of(now))))
|
||||
if d > 1.0:
|
||||
now = back_off(now, d)
|
||||
_line("out sideways", now)
|
||||
_line("up", [now[0], now[1], above[2]] + list(now[3:]))
|
||||
_pick_way.clear()
|
||||
|
||||
|
||||
def _do_pick(obj, waypoints, ja):
|
||||
"""Pick with the planned joints `ja` above the object (pick_options); a side grasp goes down beside it first."""
|
||||
way = dict(waypoints)
|
||||
@@ -1055,8 +1085,11 @@ def _do_pick(obj, waypoints, ja):
|
||||
if table is None:
|
||||
table = table_z(obj) if table_z(obj) is not None else table_near(obj) # what put down needs: the object's height
|
||||
log(f"it stands on a table at {table:.0f} mm" if table is not None else "the table under it is not in view")
|
||||
_held.clear() # nothing held until the fingers close on it
|
||||
_prepare()
|
||||
_go_on()
|
||||
_pick_way.clear()
|
||||
_pick_way.update(way)
|
||||
log(f"above: joint move to ({above[0]:.0f}, {above[1]:.0f}, {above[2]:.0f})")
|
||||
motion.move_joints(ja, EMPTY_SPEED)
|
||||
if back:
|
||||
@@ -1068,14 +1101,17 @@ def _do_pick(obj, waypoints, ja):
|
||||
log(f"AI_1 {s['ai'][0]:.0f} holding {s['holding']} finger sensor {s['object_in_front']}")
|
||||
if not s["holding"]:
|
||||
_give_up("I missed it.", back)
|
||||
# held from here on: a stop in the lift leaves it ready to put down
|
||||
_held.update(top_mm=obj["top_mm"], x=obj["x"], y=obj["y"], yaw=yaw_of(grasp), table=table,
|
||||
tips=grip_width(obj) < BELLY_MIN_MM, below=obj["top_mm"] - grasp_height(obj), back=back)
|
||||
_pick_way.clear()
|
||||
_line("lift", lift)
|
||||
s = gripper.state()
|
||||
log(f"AI_1 {s['ai'][0]:.0f} holding {s['holding']}")
|
||||
if not s["holding"]:
|
||||
_held.clear()
|
||||
_line("slipped, back down", grasp)
|
||||
_give_up("It slipped out of my hand.", back)
|
||||
_held.update(top_mm=obj["top_mm"], x=obj["x"], y=obj["y"], yaw=yaw_of(grasp), table=table,
|
||||
tips=grip_width(obj) < BELLY_MIN_MM, below=obj["top_mm"] - grasp_height(obj), back=back)
|
||||
|
||||
|
||||
def _do_place(waypoints):
|
||||
|
||||
Reference in New Issue
Block a user