Arm routes queued without stops at via-points; wave with two swings
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -131,6 +131,83 @@ refused(arm_route.NOT_TAUGHT, arm_route.goto, "wave") # no way to
|
||||
refused(arm_route.NOT_TAUGHT, arm_route.goto, "nowhere")
|
||||
POSES["wave_start"] = [0.0, -20, 20, 0, 0, 0]
|
||||
|
||||
# ---------- empty hand: all moves sent at once, blended at via-points, the wait only for the end; holding: one by one --
|
||||
|
||||
|
||||
class QueueArm(FakeArm):
|
||||
"""Queues joint moves like the controller: each get_data shows the next one done (and inpos, as a stop at a
|
||||
via-point could); stop_program empties the queue. `on_move(k)` / `on_poll()` run before the k-th move / a poll."""
|
||||
|
||||
def __init__(self, joints, on_move=None, on_poll=None):
|
||||
super().__init__(joints)
|
||||
self.queue, self.log, self.on_move, self.on_poll = [], [], on_move, on_poll
|
||||
|
||||
def __call__(self, name, **a):
|
||||
self.log.append((name, a.get("speed"), a.get("tol")))
|
||||
if name == "joint_move":
|
||||
if self.on_move:
|
||||
self.on_move(len(self.sent))
|
||||
self.sent.append(list(a["jointPosition"]))
|
||||
self.queue.append(list(a["jointPosition"]))
|
||||
return {"errorCode": "0"}
|
||||
if name == "get_data":
|
||||
if self.on_poll:
|
||||
self.on_poll()
|
||||
if self.queue:
|
||||
self.j = self.queue.pop(0)
|
||||
return {"joint_actual_position": list(self.j), "inpos": True}
|
||||
if name == "stop_program":
|
||||
self.queue.clear()
|
||||
return {"errorCode": "0"}
|
||||
return super().__call__(name, **a)
|
||||
|
||||
def moves(self):
|
||||
return [(s, t) for n, s, t in self.log if n == "joint_move"]
|
||||
|
||||
|
||||
def order(fake):
|
||||
return [n for n, _, _ in fake.log if n in ("joint_move", "get_data")]
|
||||
|
||||
|
||||
fake = arm.cmd = QueueArm(POSES["look"])
|
||||
assert arm_route.goto("wave_start") == ["wave_out", "wave_start"] and fake.j == POSES["wave_start"]
|
||||
route = motion.JOINT_SPEED[arm_route.SPEED]
|
||||
assert fake.moves() == [(route, arm_route.TOL), (route, None)], fake.moves() # blended at wave_out, exact at the end
|
||||
assert order(fake)[:2] == ["joint_move"] * 2 and order(fake).count("get_data") >= 2, order(fake) # inpos at wave_out
|
||||
fake = arm.cmd = QueueArm(POSES["look"]) # did not end the wait
|
||||
arm_route.goto("wave_start", holding=True)
|
||||
assert order(fake) == ["joint_move", "get_data", "joint_move", "get_data"], order(fake)
|
||||
assert fake.moves() == [(motion.JOINT_SPEED[arm_route.HOLD_SPEED], None)] * 2, fake.moves()
|
||||
assert motion.JOINT_SPEED[arm_route.HOLD_SPEED] < route
|
||||
|
||||
# STOP while the moves are sent, or while the arm runs them: stopped, the queue emptied after the last move sent
|
||||
fake = arm.cmd = QueueArm(POSES["look"], on_move=lambda k: k == 1 and motion.stop())
|
||||
try:
|
||||
arm_route.goto("wave_start")
|
||||
raise AssertionError("went on after STOP")
|
||||
except motion.MotionError as e:
|
||||
assert str(e) == "stopped"
|
||||
names = [n for n, _, _ in fake.log]
|
||||
assert names[-1] == "stop_program" and names.count("joint_move") == 2, names
|
||||
assert fake.queue == [] and "get_data" not in names, names
|
||||
fake = arm.cmd = QueueArm(POSES["look"], on_poll=motion.stop)
|
||||
try:
|
||||
arm_route.goto("wave_start")
|
||||
raise AssertionError("went on after STOP")
|
||||
except motion.MotionError as e:
|
||||
assert str(e) == "stopped" and fake.queue == [] and fake.j == POSES["look"], (e, fake.j)
|
||||
|
||||
# the blend's corner cut is checked: a head inside the corner at wave_out refuses the blended route, not the one by one
|
||||
f, g, tip, _ = arm_route._gripper([0.0, 0.0, 0.0] + list(skills.GRASP_RPY))
|
||||
head["centre"] = np.array([0.0, -330.0, 330.0]) + g # 270+ mm from both moves, 212 from the cut
|
||||
for j0, j1 in ((POSES["look"], POSES["wave_out"]), (POSES["wave_out"], POSES["wave_start"])):
|
||||
assert arm_route.profile(j0, j1, head["centre"])[0] >= arm_route.HEAD_CLEAR_MM
|
||||
fake = use(POSES["look"])
|
||||
refused(arm_route.NEAR_HEAD, arm_route.goto, "wave_start")
|
||||
assert fake.sent == []
|
||||
assert arm_route.goto("wave_start", holding=True) == ["wave_out", "wave_start"]
|
||||
head["centre"] = FAR
|
||||
|
||||
# ---------- Cobo π programs only from look; hand_shaking never ----------
|
||||
fake = use(POSES["carry"])
|
||||
refused(arm_route.NOT_AT_LOOK, arm_route.start_program, "arm_reach.jks")
|
||||
|
||||
+7
-3
@@ -138,6 +138,8 @@ fetch.AXIS_SPEED, fetch.COAST_S = 100.0, 0.0
|
||||
arm = {"j": [5.0] * 6} # the fake arm's joints: away from every pose
|
||||
fetch.motion.go = lambda name, *a, **k: (calls.append(("pose", name)), arm.update(j=list(fetch.motion.poses()[name])))
|
||||
fetch.motion.stop = lambda: calls.append(("arm stop",))
|
||||
real_move = fetch.arm_route.move
|
||||
fetch.arm_route.move = lambda seq, *a, **k: [fetch.motion.go(n) for n, _ in seq] # by name (poses share joints here)
|
||||
fetch.motion.poses = lambda: {"tuck": [0] * 6, "ready": [0] * 6, "carry": [3] * 6, "look": [0] * 6}
|
||||
fetch.motion.tcp = lambda: [0.0] * 3 + tilt["rpy"] # the flange as the fake kine_forward says
|
||||
skills._joints = lambda: arm["j"]
|
||||
@@ -233,16 +235,18 @@ except fetch.FetchError:
|
||||
st = run(fetch.place)
|
||||
assert st["status"] == "done" and not st["holding"] and ("place",) in calls and poses()[-1] == "look", (st, calls)
|
||||
|
||||
# ---------- arm speed: every move along the pose graph at arm_route.SPEED, empty hand or holding ----------
|
||||
# ---------- arm speed along the pose graph: arm_route.SPEED with an empty hand, HOLD_SPEED holding ----------
|
||||
speeds = []
|
||||
real_go = fetch.motion.go
|
||||
fetch.motion.go = lambda name, speed="slow", *a, **k: (speeds.append((name, speed)), calls.append(("pose", name)))
|
||||
fetch.arm_route.move, fake_move = real_move, fetch.arm_route.move
|
||||
fetch.motion.move_path = lambda moves, *a, **k: speeds.extend(("carry", s) for _, s, _ in moves)
|
||||
arm.update(j=[0.5] * 6)
|
||||
fetch._pose("carry")
|
||||
tilt["rpy"] = up_rpy
|
||||
fetch._pose("carry", holding=True)
|
||||
assert speeds == [("carry", fetch.arm_route.SPEED)] * 2 and fetch.arm_route.SPEED == "slow", speeds
|
||||
fetch.motion.go = real_go
|
||||
assert speeds == [("carry", "route"), ("carry", "slow")], speeds
|
||||
fetch.motion.go, fetch.arm_route.move = real_go, fake_move
|
||||
|
||||
# ---------- a drive that turns on the spot without getting anywhere is cancelled ----------
|
||||
reset()
|
||||
|
||||
+11
-5
@@ -68,25 +68,31 @@ def refused(reason):
|
||||
raise AssertionError(f"waved, expected {reason}")
|
||||
|
||||
|
||||
# ---------- from look: up through wave_out, 3 swings, the arm stays at wave_start; every move clear of the head ------
|
||||
# ---------- from look: up through wave_out, 2 swings, the arm stays at wave_start; every move clear of the head ------
|
||||
a = use(FakeArm(LOOK))
|
||||
started = []
|
||||
wave.wave(on_start=lambda: started.append(len(a.sent)))
|
||||
assert started == [0] # said before the first move
|
||||
top, swing = POSES["wave_start"], POSES["wave"]
|
||||
assert wave.SWINGS == 3
|
||||
assert a.sent == [POSES["wave_out"], top] + [swing, top] * 3, a.sent
|
||||
assert wave.SWINGS == 2
|
||||
assert a.sent == [POSES["wave_out"], top] + [swing, top] * wave.SWINGS, a.sent
|
||||
for j0, j1 in zip([LOOK] + a.sent, a.sent):
|
||||
assert arm_route.profile(j0, j1, HEAD)[0] >= arm_route.HEAD_CLEAR_MM, (j0, j1)
|
||||
assert arm_route.profile(LOOK, top, HEAD)[0] < arm_route.HEAD_CLEAR_MM # straight up from look would pass the head
|
||||
assert {"look", "wave_start"} not in [set(e) for e in arm_route.EDGES] # so there is no such edge
|
||||
a.sent.clear()
|
||||
wave.wave() # asked again while up: only the swings
|
||||
assert a.sent == [swing, top] * 3, a.sent
|
||||
assert a.sent == [swing, top] * wave.SWINGS, a.sent
|
||||
a.sent.clear()
|
||||
a.j = list(swing) # stopped at wave: back to wave_start, then swings
|
||||
wave.wave()
|
||||
assert a.sent == [top] + [swing, top] * 3, a.sent
|
||||
assert a.sent == [top] + [swing, top] * wave.SWINGS, a.sent
|
||||
names = [] # all moves sent one after another, no poll
|
||||
arm.cmd = lambda name, **k: (names.append(name), a(name, **k))[1] # between them
|
||||
a.j = list(LOOK)
|
||||
wave.wave()
|
||||
assert [n for n in names if n in ("joint_move", "get_data")][:3 + 2 * wave.SWINGS] == ["joint_move"] * (2 + 2 * wave.SWINGS) + ["get_data"], names
|
||||
arm.cmd = a
|
||||
a.j = list(top)
|
||||
a.sent.clear()
|
||||
assert arm_route.goto("look") == ["wave_out", "look"] # the way down
|
||||
|
||||
Reference in New Issue
Block a user