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:
+36
-15
@@ -26,9 +26,10 @@ POSES_FILE = ROOT / "data" / "arm_poses.json"
|
||||
TUCK = [179.3, -88.6, -13.9, -15.8, -14.5, -121.3] # deg, arm folded beside the column (fits doorways)
|
||||
LIMITS = [360, 125, 130, 360, 120, 360] # deg, ± factory range per joint (docs/01_HARDWARE.md)
|
||||
LIMIT_MARGIN = 5.0 # deg kept away from every limit
|
||||
JOINT_SPEED = {"slow": 10.0, "normal": 25.0} # deg/s
|
||||
JOINT_SPEED = {"slow": 10.0, "normal": 25.0, "route": 40.0} # deg/s; route: empty-hand pose-graph moves (estimate)
|
||||
JOINT_ACCEL = {"slow": 30.0, "normal": 75.0, "route": 200.0} # deg/s2 (vendor: keep under 720); route: estimate
|
||||
LINEAR_SPEED = {"slow": 20.0, "normal": 50.0} # mm/s
|
||||
ACCEL_FACTOR = 3.0 # accel = speed x this (per s)
|
||||
ACCEL_FACTOR = 3.0 # linear moves: accel = speed x this (per s)
|
||||
MAX_FLIP = 90.0 # deg; an IK answer turning J1 / J4 / J6 more than this is refused
|
||||
MAX_TRAVEL = 200.0 # deg; a joint move turning any joint further is refused
|
||||
FULL_TURN = (0, 3, 5) # J1, J4, J6: ±360 joints; a target and target ± 360 are the same pose
|
||||
@@ -150,23 +151,43 @@ def nearest(target, start):
|
||||
|
||||
def move_joints(target, speed="slow", wait=True):
|
||||
"""Joint move to absolute angles (deg). Returns the joints reached (or the target if wait=False)."""
|
||||
check(target)
|
||||
return move_path([(target, speed, 0.0)], wait)
|
||||
|
||||
|
||||
def move_path(moves, wait=True):
|
||||
"""Joint moves [(joints, speed, tol)] sent one after another without waiting between them: the controller queues
|
||||
them and starts each when the one before ends (docs/04 §10). `tol` is the controller's transition radius into the
|
||||
next move (it blends through that via-point instead of stopping); the last move always ends exactly. All moves
|
||||
are checked before the first is sent. Waits for the last one; stop() ends the queue. Returns the joints reached
|
||||
(or the last target if wait=False)."""
|
||||
for t, _, _ in moves:
|
||||
check(t)
|
||||
_ready()
|
||||
deg_s = JOINT_SPEED[speed]
|
||||
start = joints()
|
||||
target = nearest(target, start)
|
||||
for i, (a, b) in enumerate(zip(target, start)):
|
||||
if abs(a - b) > MAX_TRAVEL:
|
||||
raise MotionError(f"J{i + 1} would turn {a - b:+.0f} deg - refused")
|
||||
travel = max(abs(a - b) for a, b in zip(target, start))
|
||||
prev, planned, seq = joints(), 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]
|
||||
seq.append((t, speed, tol))
|
||||
prev = t
|
||||
_stopped.clear()
|
||||
r = arm.cmd("joint_move", relFlag=0, jointPosition=list(target), speed=deg_s, accel=deg_s * ACCEL_FACTOR)
|
||||
if r.get("errorCode") != "0":
|
||||
raise MotionError(f"joint_move refused: {r.get('errorMsg') or r}")
|
||||
for k, (t, speed, tol) in enumerate(seq):
|
||||
extra = {"tol": tol} if tol > 0 and k < len(seq) - 1 else {} # no tol key at all on an exact move
|
||||
r = arm.cmd("joint_move", relFlag=0, jointPosition=list(t), speed=JOINT_SPEED[speed],
|
||||
accel=JOINT_ACCEL[speed], **extra)
|
||||
if _stopped.is_set(): # STOP pressed while sending: stop again, after this move is queued
|
||||
stop()
|
||||
raise MotionError("stopped")
|
||||
if r.get("errorCode") != "0":
|
||||
if k:
|
||||
stop() # the moves already queued must not run on alone
|
||||
raise MotionError(f"joint_move refused: {r.get('errorMsg') or r}")
|
||||
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,
|
||||
travel / deg_s)
|
||||
d = _wait(lambda d: max(abs(a - b) for a, b in zip(d["joint_actual_position"], target)) < AT_JOINT_DEG, planned)
|
||||
return d["joint_actual_position"]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user