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:
2026-10-21 17:58:58 +09:00
co-authored by Claude Opus 5.5
parent 217eb93d81
commit a5ae852097
4 changed files with 102 additions and 30 deletions
+27 -11
View File
@@ -36,7 +36,9 @@ FULL_TURN = (0, 3, 5) # J1, J4, J6: ±360 joints;
AT_JOINT_DEG = 0.3 # arrived when every joint is this close ...
AT_TCP_MM = 1.0 # ... or the TCP this close (linear moves)
POLL_S = 0.1
EXTRA_S = 10.0 # s allowed on top of 3x the planned move time
EXTRA_S = 10.0 # s allowed on top of the longest a move may take
SLOW_DEG_S = 5.0 # deg/s; long joint moves ran this slow whatever the speed asked
# (measured: 157 deg of J6 in 37 s, 60 deg of J1 in 8.5 s)
STILL_S = 2.0 # s without joint motion (and not there) -> the move ended short
STILL_DEG = 0.05 # joint change that counts as motion
BLIND_S = 1.0 # s without a valid state reply while moving -> stop the arm
@@ -104,13 +106,22 @@ def _ready():
raise MotionError("a Cobo π program is running")
def _wait(arrived, planned_s):
"""Wait while the arm moves. Big joint moves run slower than speed / travel suggests (measured: 157 deg
of J6 at 10 deg/s took well over 21 s), so the limit is generous; a move that stops short is caught by
STILL_S instead."""
def _queue_empty():
"""The controller has no motion command left to run (get_motion_state; an odd reply counts as not empty)."""
try:
r = arm.cmd("get_motion_state")
except (ConnectionError, OSError):
return False
return r.get("queue") == 0 and r.get("active_queue", 0) == 0
def _wait(arrived, limit_s, queued=False):
"""Wait while the arm moves, at most limit_s. Big moves run far slower than the speed asked (SLOW_DEG_S), so the
limit is generous; a move that stops short is caught by STILL_S instead. `queued`: several moves were sent, so
arrived also needs the controller's queue empty (a route can pass its last pose before, a wave does)."""
t0 = last_move = last_seen = time.time()
last = None
while time.time() - t0 < 3 * planned_s + EXTRA_S:
while time.time() - t0 < limit_s:
if _stopped.is_set():
raise MotionError("stopped")
try:
@@ -126,12 +137,14 @@ def _wait(arrived, planned_s):
last_seen = time.time()
if d.get("protective_stop") or d.get("emergency_stop"):
raise MotionError("the controller stopped the arm (protective / emergency stop)")
if d.get("inpos") and arrived(d):
if d.get("inpos") and arrived(d) and (not queued or _queue_empty()):
return d
j = d["joint_actual_position"]
if last is None or max(abs(a - b) for a, b in zip(j, last)) > STILL_DEG:
last, last_move = j, time.time()
elif time.time() - last_move > STILL_S and time.time() - t0 > STILL_S + 1:
if queued:
stop() # the moves still queued must not run on later
raise MotionError("the arm stopped before the target")
time.sleep(POLL_S)
stop()
@@ -163,13 +176,15 @@ def move_path(moves, wait=True):
for t, _, _ in moves:
check(t)
_ready()
prev, planned, seq = joints(), 0.0, []
prev, planned, travel, seq = joints(), 0.0, 0.0, []
for t, speed, tol in moves:
t = nearest(t, prev)
for i, (a, b) in enumerate(zip(t, prev)):
if abs(a - b) > MAX_TRAVEL:
raise MotionError(f"J{i + 1} would turn {a - b:+.0f} deg - refused")
planned += max(abs(a - b) for a, b in zip(t, prev)) / JOINT_SPEED[speed]
deg = max(abs(a - b) for a, b in zip(t, prev))
planned += deg / JOINT_SPEED[speed]
travel += deg
seq.append((t, speed, tol))
prev = t
_stopped.clear()
@@ -187,7 +202,8 @@ def move_path(moves, wait=True):
target = seq[-1][0]
if not wait:
return list(target)
d = _wait(lambda d: max(abs(a - b) for a, b in zip(d["joint_actual_position"], target)) < AT_JOINT_DEG, planned)
d = _wait(lambda d: max(abs(a - b) for a, b in zip(d["joint_actual_position"], target)) < AT_JOINT_DEG,
max(3 * planned, travel / SLOW_DEG_S) + EXTRA_S, queued=len(seq) > 1)
return d["joint_actual_position"]
@@ -227,7 +243,7 @@ def move_linear(target=None, delta=None, speed="slow", wait=True, path_checked=F
if not wait:
return list(target)
d = _wait(lambda d: sum((a - b) ** 2 for a, b in zip(d["actual_position"][:3], target[:3])) ** 0.5 < AT_TCP_MM,
dist / mm_s)
3 * dist / mm_s + EXTRA_S)
return d["actual_position"]