Queued arm moves wait while the arm moves; wave rise at route speed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Self-check of the pose graph (manipulation/arm_route.py) with a fake arm and toy kinematics (no robot):
|
||||
python tests/test_arm_route.py"""
|
||||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
@@ -41,6 +42,8 @@ class FakeArm:
|
||||
return {"cartPosition": [30 * j[0], 30 * j[1], 30 * j[2]] + list(skills.GRASP_RPY), "errorCode": "0"}
|
||||
if name == "get_data":
|
||||
return {"joint_actual_position": list(self.j), "inpos": True}
|
||||
if name == "get_motion_state":
|
||||
return {"queue": 0, "active_queue": 0, "errorCode": "0"}
|
||||
if name == "joint_move":
|
||||
self.sent.append(list(a["jointPosition"]))
|
||||
self.j = list(a["jointPosition"])
|
||||
@@ -159,6 +162,8 @@ class QueueArm(FakeArm):
|
||||
if name == "stop_program":
|
||||
self.queue.clear()
|
||||
return {"errorCode": "0"}
|
||||
if name == "get_motion_state":
|
||||
return {"queue": len(self.queue), "active_queue": len(self.queue), "errorCode": "0"}
|
||||
return super().__call__(name, **a)
|
||||
|
||||
def moves(self):
|
||||
@@ -197,6 +202,49 @@ try:
|
||||
except motion.MotionError as e:
|
||||
assert str(e) == "stopped" and fake.queue == [] and fake.j == POSES["look"], (e, fake.j)
|
||||
|
||||
# a route through its last pose before the end (a wave): the wait ends only with the queue empty, at the end
|
||||
a_, b_ = POSES["wave_start"], POSES["wave"]
|
||||
fake = arm.cmd = QueueArm(a_)
|
||||
motion.move_path([(b_, "slow", 0.0), (a_, "slow", 0.0), (b_, "slow", 0.0), (a_, "slow", 0.0)])
|
||||
assert fake.queue == [] and fake.j == a_ and order(fake).count("get_data") >= 4, order(fake)
|
||||
|
||||
|
||||
class SlowArm(QueueArm):
|
||||
"""Runs the queued moves at `deg_s` (wall clock), far below the speed asked; `stall_at`: stops there for good."""
|
||||
|
||||
def __init__(self, joints, deg_s, stall_at=None):
|
||||
super().__init__(joints)
|
||||
self.deg_s, self.stall_at, self.t = deg_s, stall_at, None
|
||||
|
||||
def __call__(self, name, **a):
|
||||
if name == "get_data":
|
||||
now = time.time()
|
||||
step, self.t = self.deg_s * (now - (self.t or now)), now
|
||||
if self.queue and (self.stall_at is None or max(abs(x - y) for x, y in zip(self.j, self.stall_at)) > 1e-6):
|
||||
t = self.queue[0]
|
||||
d = np.clip(np.array(t) - self.j, -step, step)
|
||||
self.j = [float(v) for v in np.array(self.j) + d]
|
||||
if self.stall_at is not None and max(abs(x - y) for x, y in zip(self.j, self.stall_at)) < step:
|
||||
self.j = list(self.stall_at)
|
||||
if np.allclose(self.j, t):
|
||||
self.queue.pop(0)
|
||||
return {"joint_actual_position": list(self.j), "inpos": not self.queue}
|
||||
return super().__call__(name, **a)
|
||||
|
||||
|
||||
extra, still = motion.EXTRA_S, motion.STILL_S
|
||||
motion.EXTRA_S, motion.STILL_S = 0.0, 0.5
|
||||
fake = arm.cmd = SlowArm(POSES["look"], deg_s=8.0) # 40 deg asked at 40 deg/s: planned 1 s, takes 5 s
|
||||
motion.move_path(arm_route.moves([POSES["wave_out"], POSES["wave_start"]]))
|
||||
assert fake.j == POSES["wave_start"] and fake.queue == [], fake.j
|
||||
fake = arm.cmd = SlowArm(POSES["look"], deg_s=8.0, stall_at=[0.0, -20, 5, 0, 0, 0]) # stuck on the way: stopped
|
||||
try:
|
||||
motion.move_path(arm_route.moves([POSES["wave_out"], POSES["wave_start"]]))
|
||||
raise AssertionError("waited on a stalled arm")
|
||||
except motion.MotionError as e:
|
||||
assert "stopped before" in str(e) and fake.queue == [] and fake.log[-1][0] == "stop_program", (e, fake.log[-1])
|
||||
motion.EXTRA_S, motion.STILL_S = extra, still
|
||||
|
||||
# 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
|
||||
|
||||
+9
-3
@@ -47,6 +47,8 @@ class FakeArm:
|
||||
return {"cartPosition": [10 * j[0], 10 * j[1], 10 * j[2], 0.0, 0.0, 0.0], "errorCode": "0"}
|
||||
if name == "get_data":
|
||||
return {"joint_actual_position": list(self.j), "inpos": True}
|
||||
if name == "get_motion_state":
|
||||
return {"queue": 0, "active_queue": 0, "errorCode": "0"}
|
||||
if name == "joint_move":
|
||||
self.sent.append(list(a["jointPosition"]))
|
||||
self.j = list(a["jointPosition"])
|
||||
@@ -87,11 +89,15 @@ a.sent.clear()
|
||||
a.j = list(swing) # stopped at wave: back to wave_start, then swings
|
||||
wave.wave()
|
||||
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
|
||||
names = [] # the way up as arm_route.goto sends it, then the
|
||||
arm.cmd = lambda name, **k: (names.append((name, k.get("speed"), k.get("tol"))), a(name, **k))[1] # swings, each queued
|
||||
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
|
||||
sent = [(n, v, t) for n, v, t in names if n in ("joint_move", "get_data")]
|
||||
route, swing_s = motion.JOINT_SPEED[arm_route.SPEED], motion.JOINT_SPEED[wave.SWING_SPEED]
|
||||
assert sent[:3] == [("joint_move", route, arm_route.TOL), ("joint_move", route, None), ("get_data", None, None)], sent
|
||||
assert sent[3:4 + 2 * wave.SWINGS] == [("joint_move", swing_s, None)] * 2 * wave.SWINGS + [("get_data", None, None)], sent
|
||||
assert wave.SWING_SPEED == "normal"
|
||||
arm.cmd = a
|
||||
a.j = list(top)
|
||||
a.sent.clear()
|
||||
|
||||
Reference in New Issue
Block a user