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")
|
||||
|
||||
Reference in New Issue
Block a user