Wave swings back to back, gentler joint acceleration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+33
-12
@@ -28,7 +28,9 @@ LIMITS = [360, 125, 130, 360, 120, 360] # deg, ± factory range per
|
||||
LIMIT_MARGIN = 5.0 # deg kept away from every limit
|
||||
JOINT_SPEED = {"slow": 10.0, "normal": 25.0, "route": 40.0} # deg/s; route: empty-hand pose-graph moves (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 # straight moves: accel = speed x this (per s)
|
||||
JOINT_ACCEL_FACTOR = 1.5 # joint moves: accel = speed x this (per s); estimate: x 3
|
||||
# stopped at each pose with a jolt that shook the robot
|
||||
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
|
||||
@@ -107,9 +109,19 @@ def _ready():
|
||||
raise MotionError("a Cobo π program is running")
|
||||
|
||||
|
||||
def _wait(arrived, limit_s):
|
||||
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."""
|
||||
limit is generous; a move that stops short is caught by STILL_S instead. `queued`: several moves were sent at
|
||||
once, so arrived also needs the controller's queue empty (the swings pass their last pose before the end)."""
|
||||
t0 = last_move = last_seen = time.time()
|
||||
last = None
|
||||
while time.time() - t0 < limit_s:
|
||||
@@ -128,7 +140,7 @@ def _wait(arrived, limit_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:
|
||||
@@ -157,10 +169,12 @@ def move_joints(target, speed="slow", wait=True):
|
||||
return move_path([(target, speed)], wait)
|
||||
|
||||
|
||||
def move_path(moves, wait=True):
|
||||
def move_path(moves, wait=True, queued=False):
|
||||
"""Joint moves [(joints, speed)], all checked before the first is sent, then one at a time: each waits until the
|
||||
arm is there (inpos, every joint within AT_JOINT_DEG) and stands SETTLE_S before the next is sent. stop() ends
|
||||
it between moves too. Returns the joints reached (wait=False: the last move is not waited for, its target)."""
|
||||
arm is there (inpos, every joint within AT_JOINT_DEG) and stands SETTLE_S before the next is sent. `queued`: all
|
||||
sent at once instead, the controller runs them back to back (docs/04 §10; the wave's swings) and only the end is
|
||||
waited for. stop() ends it at any point. Returns the joints reached (wait=False: the last move is not waited for,
|
||||
its target)."""
|
||||
for t, _ in moves:
|
||||
check(t)
|
||||
_ready()
|
||||
@@ -173,21 +187,28 @@ def move_path(moves, wait=True):
|
||||
seq.append((t, speed, max(abs(a - b) for a, b in zip(t, prev))))
|
||||
prev = t
|
||||
_stopped.clear()
|
||||
d = None
|
||||
d, limit = None, 0.0
|
||||
for k, (t, speed, deg) in enumerate(seq):
|
||||
if k and _stopped.wait(SETTLE_S):
|
||||
if k and not queued and _stopped.wait(SETTLE_S):
|
||||
raise MotionError("stopped")
|
||||
deg_s = JOINT_SPEED[speed]
|
||||
r = arm.cmd("joint_move", relFlag=0, jointPosition=list(t), speed=deg_s, accel=deg_s * ACCEL_FACTOR)
|
||||
r = arm.cmd("joint_move", relFlag=0, jointPosition=list(t), speed=deg_s, accel=deg_s * JOINT_ACCEL_FACTOR)
|
||||
if _stopped.is_set(): # STOP pressed while sending: stop again, after this move
|
||||
stop()
|
||||
raise MotionError("stopped")
|
||||
if r.get("errorCode") != "0":
|
||||
if queued and k:
|
||||
stop() # the moves already queued must not run on alone
|
||||
raise MotionError(f"joint_move refused: {r.get('errorMsg') or r}")
|
||||
if not wait and k == len(seq) - 1:
|
||||
last = k == len(seq) - 1
|
||||
limit += max(3 * deg / deg_s, deg / SLOW_DEG_S)
|
||||
if queued and not last:
|
||||
continue
|
||||
if not wait and last:
|
||||
return list(t)
|
||||
d = _wait(lambda d, t=t: max(abs(a - b) for a, b in zip(d["joint_actual_position"], t)) < AT_JOINT_DEG,
|
||||
max(3 * deg / deg_s, deg / SLOW_DEG_S) + EXTRA_S)
|
||||
limit + EXTRA_S, queued=queued and len(seq) > 1)
|
||||
limit = 0.0
|
||||
return d["joint_actual_position"]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user