diff --git a/api/server.py b/api/server.py
index ce81f11..c23e74c 100644
--- a/api/server.py
+++ b/api/server.py
@@ -763,7 +763,7 @@ def arm_tuck():
class PoseBody(BaseModel):
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):
diff --git a/assistant/lumi.py b/assistant/lumi.py
index d9b352a..f89de8e 100644
--- a/assistant/lumi.py
+++ b/assistant/lumi.py
@@ -1529,8 +1529,9 @@ class Lumi:
return st is not None
try:
if target == "fold":
- seq = arm_route.plan("tuck", holding=self.fetch_status() == "holding")
- threading.Thread(target=safe, args=(arm_route.move, seq), daemon=True).start()
+ holding = self.fetch_status() == "holding"
+ seq = arm_route.plan("tuck", holding=holding)
+ threading.Thread(target=safe, args=(arm_route.move, seq, None, holding), daemon=True).start()
else:
arm_route.start_program(ARM_REACH_PROGRAM)
return True
diff --git a/data/arm_poses.json b/data/arm_poses.json
index 8e13e12..a79cab7 100644
--- a/data/arm_poses.json
+++ b/data/arm_poses.json
@@ -49,10 +49,10 @@
],
"wave": [
-178.86,
- -77.27,
- -2.52,
+ -77.26,
+ -17.24,
-175.06,
- 59.89,
- -219.73
+ 38.37,
+ -219.7
]
}
\ No newline at end of file
diff --git a/manipulation/arm_route.py b/manipulation/arm_route.py
index 871cecf..33c02a1 100644
--- a/manipulation/arm_route.py
+++ b/manipulation/arm_route.py
@@ -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
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).
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 sys
+import time
import numpy as np
@@ -33,7 +39,10 @@ from vision import calib, head_cam
HOME = "look" # every arm action starts here
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)
-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)
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)
@@ -175,9 +184,10 @@ def move_problem(j0, j1, centre, holding=False):
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),
- 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()
if centre is None:
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])
seq.append(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
@@ -209,22 +225,36 @@ def plan(target, holding=False, leaf=False, now=None):
now = skills._joints() if now is None else now
names = hops(now, target, leaf)
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):
- """Run a plan() along its poses. motion.MotionError when stopped or failed on the way (the arm stays there)."""
- for name, _ in seq:
- log(f"arm to {name}")
- motion.go(name, speed)
+def moves(joints, speed=SPEED):
+ """motion.move_path moves of an empty-hand route through `joints`: blended at every via-point."""
+ return [(j, speed, TOL) for j in joints]
-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."""
seq = plan(target, holding, leaf)
if seq:
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]
diff --git a/manipulation/wave.py b/manipulation/wave.py
index 4ccbf78..d49f757 100644
--- a/manipulation/wave.py
+++ b/manipulation/wave.py
@@ -1,9 +1,9 @@
"""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
-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
--> 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
running, something in the hand, the arm at no known pose (after free drive), a pose not taught, a move too near the
head.
@@ -19,8 +19,8 @@ from manipulation import arm_route, skills
from robot import agv, arm, gripper, motion
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)
-SWINGS = 3 # times START -> SWING -> START
+SWING = "wave" # START with J3 −14.7°)
+SWINGS = 2 # times START -> SWING -> START
SWING_SPEED = "slow" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED
# Why Lumi does not wave, (English, Korean)
@@ -95,8 +95,10 @@ def wave(on_start=None):
if on_start:
on_start()
up = len(seq) - 2 * SWINGS # the moves before are the way up along the graph
- for k, t in enumerate(seq):
- motion.move_joints(t, arm_route.SPEED if k < up else SWING_SPEED)
+ way = arm_route.moves(seq[:up]) # blended through wave_out (checked by arm_route.plan) ...
+ 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__":
diff --git a/robot/motion.py b/robot/motion.py
index 9ee1dc9..9523bb7 100644
--- a/robot/motion.py
+++ b/robot/motion.py
@@ -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"]
diff --git a/tasks/fetch.py b/tasks/fetch.py
index 2cf0b3b..38ed18f 100644
--- a/tasks/fetch.py
+++ b/tasks/fetch.py
@@ -328,7 +328,7 @@ def _at_pose(name):
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."""
_go_on()
if _at_pose(name):
@@ -338,9 +338,7 @@ def _pose(name, holding=False, leaf=False):
except arm_route.RouteError as e:
raise FetchError(*e.args) from e
log(f"arm to {name}: {' -> '.join(n for n, _ in seq)}")
- for n, _ in seq:
- _go_on()
- motion.go(n, arm_route.SPEED)
+ arm_route.move(seq, holding=holding)
_go_on()
diff --git a/tests/test_arm_route.py b/tests/test_arm_route.py
index f0378e8..681bb17 100644
--- a/tests/test_arm_route.py
+++ b/tests/test_arm_route.py
@@ -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")
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 ----------
fake = use(POSES["carry"])
refused(arm_route.NOT_AT_LOOK, arm_route.start_program, "arm_reach.jks")
diff --git a/tests/test_fetch.py b/tests/test_fetch.py
index d9a221e..ba933fd 100644
--- a/tests/test_fetch.py
+++ b/tests/test_fetch.py
@@ -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
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",))
+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.tcp = lambda: [0.0] * 3 + tilt["rpy"] # the flange as the fake kine_forward says
skills._joints = lambda: arm["j"]
@@ -233,16 +235,18 @@ except fetch.FetchError:
st = run(fetch.place)
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 = []
real_go = fetch.motion.go
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)
fetch._pose("carry")
tilt["rpy"] = up_rpy
fetch._pose("carry", holding=True)
-assert speeds == [("carry", fetch.arm_route.SPEED)] * 2 and fetch.arm_route.SPEED == "slow", speeds
-fetch.motion.go = real_go
+assert speeds == [("carry", "route"), ("carry", "slow")], speeds
+fetch.motion.go, fetch.arm_route.move = real_go, fake_move
# ---------- a drive that turns on the spot without getting anywhere is cancelled ----------
reset()
diff --git a/tests/test_wave.py b/tests/test_wave.py
index 1545775..8ab195f 100644
--- a/tests/test_wave.py
+++ b/tests/test_wave.py
@@ -68,25 +68,31 @@ def refused(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))
started = []
wave.wave(on_start=lambda: started.append(len(a.sent)))
assert started == [0] # said before the first move
top, swing = POSES["wave_start"], POSES["wave"]
-assert wave.SWINGS == 3
-assert a.sent == [POSES["wave_out"], top] + [swing, top] * 3, a.sent
+assert wave.SWINGS == 2
+assert a.sent == [POSES["wave_out"], top] + [swing, top] * wave.SWINGS, 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(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
a.sent.clear()
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.j = list(swing) # stopped at wave: back to wave_start, then swings
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.sent.clear()
assert arm_route.goto("look") == ["wave_out", "look"] # the way down