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:
+1
-1
@@ -238,7 +238,7 @@ input[type=color]{width:30px;height:28px;border:1px solid var(--line);border-rad
|
|||||||
|
|
||||||
<div class="card box">
|
<div class="card box">
|
||||||
<h3>Arm pose</h3>
|
<h3>Arm pose</h3>
|
||||||
<div class="row"><select id="poseSel" class="grow"></select><select id="poseSpeed"><option value="slow">Slow</option><option value="normal">Normal</option></select>
|
<div class="row"><select id="poseSel" class="grow"></select><select id="poseSpeed"><option value="slow">Slow</option><option value="normal">Normal</option><option value="route">Fast</option></select>
|
||||||
<button class="btn primary" id="poseGo">Move ➜</button></div>
|
<button class="btn primary" id="poseGo">Move ➜</button></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -763,7 +763,7 @@ def arm_tuck():
|
|||||||
|
|
||||||
class PoseBody(BaseModel):
|
class PoseBody(BaseModel):
|
||||||
name: str = Field(examples=["look"], description="a pose of the pose graph (manipulation/arm_route.py)")
|
name: str = Field(examples=["look"], description="a pose of the pose graph (manipulation/arm_route.py)")
|
||||||
speed: str = Field(arm_route.SPEED, description="slow / normal")
|
speed: str = Field(arm_route.SPEED, description="slow / normal / route (empty hand; holding: always slow)")
|
||||||
|
|
||||||
|
|
||||||
class LineBody(BaseModel):
|
class LineBody(BaseModel):
|
||||||
|
|||||||
+3
-2
@@ -1529,8 +1529,9 @@ class Lumi:
|
|||||||
return st is not None
|
return st is not None
|
||||||
try:
|
try:
|
||||||
if target == "fold":
|
if target == "fold":
|
||||||
seq = arm_route.plan("tuck", holding=self.fetch_status() == "holding")
|
holding = self.fetch_status() == "holding"
|
||||||
threading.Thread(target=safe, args=(arm_route.move, seq), daemon=True).start()
|
seq = arm_route.plan("tuck", holding=holding)
|
||||||
|
threading.Thread(target=safe, args=(arm_route.move, seq, None, holding), daemon=True).start()
|
||||||
else:
|
else:
|
||||||
arm_route.start_program(ARM_REACH_PROGRAM)
|
arm_route.start_program(ARM_REACH_PROGRAM)
|
||||||
return True
|
return True
|
||||||
|
|||||||
+4
-4
@@ -49,10 +49,10 @@
|
|||||||
],
|
],
|
||||||
"wave": [
|
"wave": [
|
||||||
-178.86,
|
-178.86,
|
||||||
-77.27,
|
-77.26,
|
||||||
-2.52,
|
-17.24,
|
||||||
-175.06,
|
-175.06,
|
||||||
59.89,
|
38.37,
|
||||||
-219.73
|
-219.7
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+41
-11
@@ -16,6 +16,11 @@ motion.MAX_TRAVEL, the gripper (flange -> grasp point -> finger tips) at least H
|
|||||||
centre (vision/head_cam.py), never more than skills.PATH_SAG_MM below both ends, and with something in the hand the
|
centre (vision/head_cam.py), never more than skills.PATH_SAG_MM below both ends, and with something in the hand the
|
||||||
cup's lean at most skills.MAX_TILT_DEG. Refusals are RouteError with the reason in English and Korean.
|
cup's lean at most skills.MAX_TILT_DEG. Refusals are RouteError with the reason in English and Korean.
|
||||||
|
|
||||||
|
With an empty hand the moves of a route are sent together (motion.move_path) and the arm blends through the via-points
|
||||||
|
(TOL); it stops only at the end. The blend cuts each corner inside the halves of its two moves next to the via-point,
|
||||||
|
so that cut (half of the one move to half of the next) is checked like a move too. Holding something, the arm goes one
|
||||||
|
move at a time at HOLD_SPEED.
|
||||||
|
|
||||||
Cobo π programs start only from `look` (start_program); hand_shaking.jks never (it hit the head, 2026-10-21).
|
Cobo π programs start only from `look` (start_program); hand_shaking.jks never (it hit the head, 2026-10-21).
|
||||||
|
|
||||||
python manipulation/arm_route.py check [pose] # the route from here to pose (default look), checked; moves nothing
|
python manipulation/arm_route.py check [pose] # the route from here to pose (default look), checked; moves nothing
|
||||||
@@ -23,6 +28,7 @@ Cobo π programs start only from `look` (start_program); hand_shaking.jks never
|
|||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@@ -33,7 +39,10 @@ from vision import calib, head_cam
|
|||||||
HOME = "look" # every arm action starts here
|
HOME = "look" # every arm action starts here
|
||||||
EDGES = (("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
|
EDGES = (("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
|
||||||
("wave_start", "wave"), ("look", "ready"), ("look", "tuck")) # the only joint moves between named poses (both ways)
|
("wave_start", "wave"), ("look", "ready"), ("look", "tuck")) # the only joint moves between named poses (both ways)
|
||||||
SPEED = "slow" # motion.JOINT_SPEED of every move along the graph
|
SPEED = "route" # motion.JOINT_SPEED of the moves along the graph, empty hand
|
||||||
|
HOLD_SPEED = "slow" # ... with something in the hand (one move at a time, each to a full stop)
|
||||||
|
TOL = 10.0 # the controller's transition radius at each via-point, empty hand (joint_move
|
||||||
|
# `tol`; the vendor gives no unit for joint moves). Estimate; 0 stops at each one
|
||||||
AT_POSE_DEG = 3.0 # deg; the arm is at a pose when every joint is this close (where, programs)
|
AT_POSE_DEG = 3.0 # deg; the arm is at a pose when every joint is this close (where, programs)
|
||||||
EXACT_DEG = 1.0 # deg; further than this from the nearest pose a route first goes to it
|
EXACT_DEG = 1.0 # deg; further than this from the nearest pose a route first goes to it
|
||||||
JOIN_DEG = 20.0 # deg; an arm at no pose joins the graph only this close to one (every joint)
|
JOIN_DEG = 20.0 # deg; an arm at no pose joins the graph only this close to one (every joint)
|
||||||
@@ -175,9 +184,10 @@ def move_problem(j0, j1, centre, holding=False):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def check_moves(now, targets, holding=False):
|
def check_moves(now, targets, holding=False, blend=False):
|
||||||
"""Joint targets of the moves now -> targets[0] -> ..., as move_joints will turn them (J1 / J4 / J6 nearest),
|
"""Joint targets of the moves now -> targets[0] -> ..., as move_joints will turn them (J1 / J4 / J6 nearest),
|
||||||
each checked. RouteError when one must not run."""
|
each checked; `blend`: also the corner cut at each via-point (half way along the move before to half way along the
|
||||||
|
move after). RouteError when one must not run."""
|
||||||
centre = head_cam.head_centre()
|
centre = head_cam.head_centre()
|
||||||
if centre is None:
|
if centre is None:
|
||||||
log("arm route: the head's place is not measured (vision/head_cam.py fit)")
|
log("arm route: the head's place is not measured (vision/head_cam.py fit)")
|
||||||
@@ -201,6 +211,12 @@ def check_moves(now, targets, holding=False):
|
|||||||
raise RouteError(*done[key][0])
|
raise RouteError(*done[key][0])
|
||||||
seq.append(t)
|
seq.append(t)
|
||||||
prev = t
|
prev = t
|
||||||
|
for a, v, b in zip([list(now)] + seq, seq, seq[1:]) if blend else ():
|
||||||
|
a, v, b = np.array(a, float), np.array(v, float), np.array(b, float)
|
||||||
|
problem = move_problem((a + v) / 2, (v + b) / 2, centre, holding)
|
||||||
|
if problem:
|
||||||
|
log(f"arm route: the corner at {_r(v)} refused: {problem[1]}")
|
||||||
|
raise RouteError(*problem[0])
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
|
|
||||||
@@ -209,22 +225,36 @@ def plan(target, holding=False, leaf=False, now=None):
|
|||||||
now = skills._joints() if now is None else now
|
now = skills._joints() if now is None else now
|
||||||
names = hops(now, target, leaf)
|
names = hops(now, target, leaf)
|
||||||
p = motion.poses()
|
p = motion.poses()
|
||||||
return list(zip(names, check_moves(now, [p[n] for n in names], holding)))
|
return list(zip(names, check_moves(now, [p[n] for n in names], holding, blend=not holding)))
|
||||||
|
|
||||||
|
|
||||||
def move(seq, speed=SPEED):
|
def moves(joints, speed=SPEED):
|
||||||
"""Run a plan() along its poses. motion.MotionError when stopped or failed on the way (the arm stays there)."""
|
"""motion.move_path moves of an empty-hand route through `joints`: blended at every via-point."""
|
||||||
for name, _ in seq:
|
return [(j, speed, TOL) for j in joints]
|
||||||
log(f"arm to {name}")
|
|
||||||
motion.go(name, speed)
|
|
||||||
|
|
||||||
|
|
||||||
def goto(target, holding=False, leaf=False, speed=SPEED):
|
def move(seq, speed=None, holding=False):
|
||||||
|
"""Run a plan() (made with the same `holding`) along its poses. motion.MotionError when stopped or failed on the
|
||||||
|
way (the arm stays there)."""
|
||||||
|
if not seq:
|
||||||
|
return
|
||||||
|
t0 = time.time()
|
||||||
|
if holding:
|
||||||
|
for name, _ in seq:
|
||||||
|
log(f"arm to {name}")
|
||||||
|
motion.go(name, HOLD_SPEED)
|
||||||
|
else:
|
||||||
|
log(f"arm to {' -> '.join(n for n, _ in seq)}")
|
||||||
|
motion.move_path(moves([j for _, j in seq], speed or SPEED))
|
||||||
|
log(f"arm at {seq[-1][0]} after {time.time() - t0:.1f} s")
|
||||||
|
|
||||||
|
|
||||||
|
def goto(target, holding=False, leaf=False, speed=None):
|
||||||
"""Plan, check and go to pose `target` along the graph. Returns the poses passed."""
|
"""Plan, check and go to pose `target` along the graph. Returns the poses passed."""
|
||||||
seq = plan(target, holding, leaf)
|
seq = plan(target, holding, leaf)
|
||||||
if seq:
|
if seq:
|
||||||
log(f"arm route to {target}: {' -> '.join(n for n, _ in seq)}, checked")
|
log(f"arm route to {target}: {' -> '.join(n for n, _ in seq)}, checked")
|
||||||
move(seq, speed)
|
move(seq, speed, holding)
|
||||||
return [n for n, _ in seq]
|
return [n for n, _ in seq]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"""Wave the hand when someone asked for it. A greeting never moves the arm.
|
"""Wave the hand when someone asked for it. A greeting never moves the arm.
|
||||||
|
|
||||||
The arm goes up along the pose graph (manipulation/arm_route.py: from `look` to `wave_out`, the hand away from the
|
The arm goes up along the pose graph (manipulation/arm_route.py: from `look` to `wave_out`, the hand away from the
|
||||||
head, then `wave_start`, the hand above the head), swings between the taught poses `wave_start` and `wave` (J5 +21.7
|
head, then `wave_start`, the hand above the head), swings between the taught poses `wave_start` and `wave` (J3 −14.7°
|
||||||
deg) SWINGS times and STAYS at `wave_start`: the next arm task takes it back down the same way (wave_start -> wave_out
|
deg) SWINGS times and STAYS at `wave_start`: the next arm task takes it back down the same way (wave_start -> wave_out
|
||||||
-> look). Before anything moves, every joint move is checked (arm_route.check_moves: limits, travel, the gripper clear
|
-> look). All moves are sent at once (motion.move_path): no pause between them, blended through wave_out. Before anything moves, every joint move is checked (arm_route.check_moves: limits, travel, the gripper clear
|
||||||
of the head, no dip). Refused, with the reason in English and Korean: the arm off or busy, the base driving, a task
|
of the head, no dip). Refused, with the reason in English and Korean: the arm off or busy, the base driving, a task
|
||||||
running, something in the hand, the arm at no known pose (after free drive), a pose not taught, a move too near the
|
running, something in the hand, the arm at no known pose (after free drive), a pose not taught, a move too near the
|
||||||
head.
|
head.
|
||||||
@@ -19,8 +19,8 @@ from manipulation import arm_route, skills
|
|||||||
from robot import agv, arm, gripper, motion
|
from robot import agv, arm, gripper, motion
|
||||||
|
|
||||||
START = "wave_start" # hand above the head; the wave starts and ends here
|
START = "wave_start" # hand above the head; the wave starts and ends here
|
||||||
SWING = "wave" # START with J5 +21.7 deg (taught 2026-10-21)
|
SWING = "wave" # START with J3 −14.7°)
|
||||||
SWINGS = 3 # times START -> SWING -> START
|
SWINGS = 2 # times START -> SWING -> START
|
||||||
SWING_SPEED = "slow" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED
|
SWING_SPEED = "slow" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED
|
||||||
|
|
||||||
# Why Lumi does not wave, (English, Korean)
|
# Why Lumi does not wave, (English, Korean)
|
||||||
@@ -95,8 +95,10 @@ def wave(on_start=None):
|
|||||||
if on_start:
|
if on_start:
|
||||||
on_start()
|
on_start()
|
||||||
up = len(seq) - 2 * SWINGS # the moves before are the way up along the graph
|
up = len(seq) - 2 * SWINGS # the moves before are the way up along the graph
|
||||||
for k, t in enumerate(seq):
|
way = arm_route.moves(seq[:up]) # blended through wave_out (checked by arm_route.plan) ...
|
||||||
motion.move_joints(t, arm_route.SPEED if k < up else SWING_SPEED)
|
if way:
|
||||||
|
way[-1] = (way[-1][0], way[-1][1], 0.0) # ... to a full stop at START, where the swings start
|
||||||
|
motion.move_path(way + [(t, SWING_SPEED, 0.0) for t in seq[up:]]) # all queued: no pause between moves
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+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)
|
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)
|
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
|
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
|
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_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
|
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
|
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):
|
def move_joints(target, speed="slow", wait=True):
|
||||||
"""Joint move to absolute angles (deg). Returns the joints reached (or the target if wait=False)."""
|
"""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()
|
_ready()
|
||||||
deg_s = JOINT_SPEED[speed]
|
prev, planned, seq = joints(), 0.0, []
|
||||||
start = joints()
|
for t, speed, tol in moves:
|
||||||
target = nearest(target, start)
|
t = nearest(t, prev)
|
||||||
for i, (a, b) in enumerate(zip(target, start)):
|
for i, (a, b) in enumerate(zip(t, prev)):
|
||||||
if abs(a - b) > MAX_TRAVEL:
|
if abs(a - b) > MAX_TRAVEL:
|
||||||
raise MotionError(f"J{i + 1} would turn {a - b:+.0f} deg - refused")
|
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))
|
planned += max(abs(a - b) for a, b in zip(t, prev)) / JOINT_SPEED[speed]
|
||||||
|
seq.append((t, speed, tol))
|
||||||
|
prev = t
|
||||||
_stopped.clear()
|
_stopped.clear()
|
||||||
r = arm.cmd("joint_move", relFlag=0, jointPosition=list(target), speed=deg_s, accel=deg_s * ACCEL_FACTOR)
|
for k, (t, speed, tol) in enumerate(seq):
|
||||||
if r.get("errorCode") != "0":
|
extra = {"tol": tol} if tol > 0 and k < len(seq) - 1 else {} # no tol key at all on an exact move
|
||||||
raise MotionError(f"joint_move refused: {r.get('errorMsg') or r}")
|
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:
|
if not wait:
|
||||||
return list(target)
|
return list(target)
|
||||||
d = _wait(lambda d: max(abs(a - b) for a, b in zip(d["joint_actual_position"], target)) < AT_JOINT_DEG,
|
d = _wait(lambda d: max(abs(a - b) for a, b in zip(d["joint_actual_position"], target)) < AT_JOINT_DEG, planned)
|
||||||
travel / deg_s)
|
|
||||||
return d["joint_actual_position"]
|
return d["joint_actual_position"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -328,7 +328,7 @@ def _at_pose(name):
|
|||||||
|
|
||||||
|
|
||||||
def _pose(name, holding=False, leaf=False):
|
def _pose(name, holding=False, leaf=False):
|
||||||
"""Joint moves to pose `name` along the pose graph (manipulation/arm_route.py, slow), all checked before the first
|
"""Joint moves to pose `name` along the pose graph (manipulation/arm_route.py), all checked before the first
|
||||||
one starts. `leaf`: the arm is on this task's own way out from look (arm_route.hops). Nothing when it is there."""
|
one starts. `leaf`: the arm is on this task's own way out from look (arm_route.hops). Nothing when it is there."""
|
||||||
_go_on()
|
_go_on()
|
||||||
if _at_pose(name):
|
if _at_pose(name):
|
||||||
@@ -338,9 +338,7 @@ def _pose(name, holding=False, leaf=False):
|
|||||||
except arm_route.RouteError as e:
|
except arm_route.RouteError as e:
|
||||||
raise FetchError(*e.args) from e
|
raise FetchError(*e.args) from e
|
||||||
log(f"arm to {name}: {' -> '.join(n for n, _ in seq)}")
|
log(f"arm to {name}: {' -> '.join(n for n, _ in seq)}")
|
||||||
for n, _ in seq:
|
arm_route.move(seq, holding=holding)
|
||||||
_go_on()
|
|
||||||
motion.go(n, arm_route.SPEED)
|
|
||||||
_go_on()
|
_go_on()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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")
|
refused(arm_route.NOT_TAUGHT, arm_route.goto, "nowhere")
|
||||||
POSES["wave_start"] = [0.0, -20, 20, 0, 0, 0]
|
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 ----------
|
# ---------- Cobo π programs only from look; hand_shaking never ----------
|
||||||
fake = use(POSES["carry"])
|
fake = use(POSES["carry"])
|
||||||
refused(arm_route.NOT_AT_LOOK, arm_route.start_program, "arm_reach.jks")
|
refused(arm_route.NOT_AT_LOOK, arm_route.start_program, "arm_reach.jks")
|
||||||
|
|||||||
+7
-3
@@ -138,6 +138,8 @@ fetch.AXIS_SPEED, fetch.COAST_S = 100.0, 0.0
|
|||||||
arm = {"j": [5.0] * 6} # the fake arm's joints: away from every pose
|
arm = {"j": [5.0] * 6} # the fake arm's joints: away from every pose
|
||||||
fetch.motion.go = lambda name, *a, **k: (calls.append(("pose", name)), arm.update(j=list(fetch.motion.poses()[name])))
|
fetch.motion.go = lambda name, *a, **k: (calls.append(("pose", name)), arm.update(j=list(fetch.motion.poses()[name])))
|
||||||
fetch.motion.stop = lambda: calls.append(("arm stop",))
|
fetch.motion.stop = lambda: calls.append(("arm stop",))
|
||||||
|
real_move = fetch.arm_route.move
|
||||||
|
fetch.arm_route.move = lambda seq, *a, **k: [fetch.motion.go(n) for n, _ in seq] # by name (poses share joints here)
|
||||||
fetch.motion.poses = lambda: {"tuck": [0] * 6, "ready": [0] * 6, "carry": [3] * 6, "look": [0] * 6}
|
fetch.motion.poses = lambda: {"tuck": [0] * 6, "ready": [0] * 6, "carry": [3] * 6, "look": [0] * 6}
|
||||||
fetch.motion.tcp = lambda: [0.0] * 3 + tilt["rpy"] # the flange as the fake kine_forward says
|
fetch.motion.tcp = lambda: [0.0] * 3 + tilt["rpy"] # the flange as the fake kine_forward says
|
||||||
skills._joints = lambda: arm["j"]
|
skills._joints = lambda: arm["j"]
|
||||||
@@ -233,16 +235,18 @@ except fetch.FetchError:
|
|||||||
st = run(fetch.place)
|
st = run(fetch.place)
|
||||||
assert st["status"] == "done" and not st["holding"] and ("place",) in calls and poses()[-1] == "look", (st, calls)
|
assert st["status"] == "done" and not st["holding"] and ("place",) in calls and poses()[-1] == "look", (st, calls)
|
||||||
|
|
||||||
# ---------- arm speed: every move along the pose graph at arm_route.SPEED, empty hand or holding ----------
|
# ---------- arm speed along the pose graph: arm_route.SPEED with an empty hand, HOLD_SPEED holding ----------
|
||||||
speeds = []
|
speeds = []
|
||||||
real_go = fetch.motion.go
|
real_go = fetch.motion.go
|
||||||
fetch.motion.go = lambda name, speed="slow", *a, **k: (speeds.append((name, speed)), calls.append(("pose", name)))
|
fetch.motion.go = lambda name, speed="slow", *a, **k: (speeds.append((name, speed)), calls.append(("pose", name)))
|
||||||
|
fetch.arm_route.move, fake_move = real_move, fetch.arm_route.move
|
||||||
|
fetch.motion.move_path = lambda moves, *a, **k: speeds.extend(("carry", s) for _, s, _ in moves)
|
||||||
arm.update(j=[0.5] * 6)
|
arm.update(j=[0.5] * 6)
|
||||||
fetch._pose("carry")
|
fetch._pose("carry")
|
||||||
tilt["rpy"] = up_rpy
|
tilt["rpy"] = up_rpy
|
||||||
fetch._pose("carry", holding=True)
|
fetch._pose("carry", holding=True)
|
||||||
assert speeds == [("carry", fetch.arm_route.SPEED)] * 2 and fetch.arm_route.SPEED == "slow", speeds
|
assert speeds == [("carry", "route"), ("carry", "slow")], speeds
|
||||||
fetch.motion.go = real_go
|
fetch.motion.go, fetch.arm_route.move = real_go, fake_move
|
||||||
|
|
||||||
# ---------- a drive that turns on the spot without getting anywhere is cancelled ----------
|
# ---------- a drive that turns on the spot without getting anywhere is cancelled ----------
|
||||||
reset()
|
reset()
|
||||||
|
|||||||
+11
-5
@@ -68,25 +68,31 @@ def refused(reason):
|
|||||||
raise AssertionError(f"waved, expected {reason}")
|
raise AssertionError(f"waved, expected {reason}")
|
||||||
|
|
||||||
|
|
||||||
# ---------- from look: up through wave_out, 3 swings, the arm stays at wave_start; every move clear of the head ------
|
# ---------- from look: up through wave_out, 2 swings, the arm stays at wave_start; every move clear of the head ------
|
||||||
a = use(FakeArm(LOOK))
|
a = use(FakeArm(LOOK))
|
||||||
started = []
|
started = []
|
||||||
wave.wave(on_start=lambda: started.append(len(a.sent)))
|
wave.wave(on_start=lambda: started.append(len(a.sent)))
|
||||||
assert started == [0] # said before the first move
|
assert started == [0] # said before the first move
|
||||||
top, swing = POSES["wave_start"], POSES["wave"]
|
top, swing = POSES["wave_start"], POSES["wave"]
|
||||||
assert wave.SWINGS == 3
|
assert wave.SWINGS == 2
|
||||||
assert a.sent == [POSES["wave_out"], top] + [swing, top] * 3, a.sent
|
assert a.sent == [POSES["wave_out"], top] + [swing, top] * wave.SWINGS, a.sent
|
||||||
for j0, j1 in zip([LOOK] + a.sent, a.sent):
|
for j0, j1 in zip([LOOK] + a.sent, a.sent):
|
||||||
assert arm_route.profile(j0, j1, HEAD)[0] >= arm_route.HEAD_CLEAR_MM, (j0, j1)
|
assert arm_route.profile(j0, j1, HEAD)[0] >= arm_route.HEAD_CLEAR_MM, (j0, j1)
|
||||||
assert arm_route.profile(LOOK, top, HEAD)[0] < arm_route.HEAD_CLEAR_MM # straight up from look would pass the head
|
assert arm_route.profile(LOOK, top, HEAD)[0] < arm_route.HEAD_CLEAR_MM # straight up from look would pass the head
|
||||||
assert {"look", "wave_start"} not in [set(e) for e in arm_route.EDGES] # so there is no such edge
|
assert {"look", "wave_start"} not in [set(e) for e in arm_route.EDGES] # so there is no such edge
|
||||||
a.sent.clear()
|
a.sent.clear()
|
||||||
wave.wave() # asked again while up: only the swings
|
wave.wave() # asked again while up: only the swings
|
||||||
assert a.sent == [swing, top] * 3, a.sent
|
assert a.sent == [swing, top] * wave.SWINGS, a.sent
|
||||||
a.sent.clear()
|
a.sent.clear()
|
||||||
a.j = list(swing) # stopped at wave: back to wave_start, then swings
|
a.j = list(swing) # stopped at wave: back to wave_start, then swings
|
||||||
wave.wave()
|
wave.wave()
|
||||||
assert a.sent == [top] + [swing, top] * 3, a.sent
|
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
|
||||||
|
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
|
||||||
|
arm.cmd = a
|
||||||
a.j = list(top)
|
a.j = list(top)
|
||||||
a.sent.clear()
|
a.sent.clear()
|
||||||
assert arm_route.goto("look") == ["wave_out", "look"] # the way down
|
assert arm_route.goto("look") == ["wave_out", "look"] # the way down
|
||||||
|
|||||||
Reference in New Issue
Block a user