Speed up arm gestures and route the hand-over through give_pre

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 19:10:09 +09:00
co-authored by Claude Opus 5.5
parent e8d651da49
commit 799e210f4b
10 changed files with 67 additions and 32 deletions
+8 -1
View File
@@ -904,6 +904,7 @@ class Modes:
class Lumi:
chain_thread = None # several commands of one sentence done in order (chain_run)
chain_stop = threading.Event() # set by "stop" or anything new said: the rest of the chain is not done
wave_lock = threading.Lock() # held while a wave / handshake runs: a second one asked meanwhile is refused
def __init__(self, args):
self.a = args
@@ -1027,14 +1028,19 @@ class Lumi:
why = (wave_mod.HOLDING if st == "holding" and self.held_now() else # a stale "holding": checked again
wave_mod.BUSY if self.skill_busy() or self.mission_running() else
wave_mod.DRIVING if follow.running() else None)
if not self.wave_lock.acquire(blocking=False): # the same request typed / said twice: one wave
log(" wave refused: already waving")
return False
try:
if why:
raise wave_mod.WaveError(*why)
if self.vision:
self.vision.arm_watch = True
self.publish_busy("wave")
# a person near stops the arm on the way up (it sweeps out sideways), not in the swings above the head
wave_mod.wave(on_start=(lambda: threading.Thread(target=self.fetch_say, args=ok, daemon=True).start())
if ok else None)
if ok else None,
on_up=lambda: setattr(self.vision, "arm_watch", False) if self.vision else None)
return True
except wave_mod.WaveError as e:
log(f" wave refused: {e.args[0]}")
@@ -1047,6 +1053,7 @@ class Lumi:
if self.vision:
self.vision.arm_watch = False
self.publish_busy(None)
self.wave_lock.release()
return False
def base_off(self, action, target="", say=True):
+13 -5
View File
@@ -16,12 +16,12 @@
119.9
],
"give": [
-270.97,
-86.67,
-3.28,
-270.52,
-88.89,
-12.03,
-168.9,
56.87,
128.14
27.29,
-231.86
],
"look": [
-239.15,
@@ -54,5 +54,13 @@
-175.06,
38.37,
-219.7
],
"give_pre": [
-270.52,
-88.89,
-12.04,
-168.9,
65.55,
-231.86
]
}
+4 -4
View File
@@ -6,20 +6,20 @@ Every value here is a constant at the top of its file, with a comment on what it
| File | Name | Default | What it does |
|---|---|---|---|
| `robot/motion.py` | `JOINT_SPEED` | slow 10, normal 25, route 40 °/s | Joint move speeds. "normal" / "route" are the dashboard's Arm pose card "Normal" / "Fast". route: estimate |
| `robot/motion.py` | `JOINT_SPEED` | slow 10, normal 25, fast 40, quick 50, route 60 °/s | Joint move speeds. "normal" / "route" are the dashboard's Arm pose card "Normal" / "Fast"; route = the Cobo π joint speed limit (60) |
| `robot/motion.py` | `LINEAR_SPEED` | slow 20, normal 50 mm/s | Straight move speeds |
| `robot/motion.py` | `ACCEL_FACTOR` | 3.0 | Straight moves: acceleration = speed × this per second |
| `robot/motion.py` | `JOINT_ACCEL_FACTOR` | 1.5 | Joint moves: acceleration = speed × this per second (route 60 °/s², normal 37.5, slow 15). Lower = softer start and stop, longer moves. Estimate |
| `manipulation/arm_route.py` | `SPEED` | "route" | Joint moves along the pose graph (to `look`, `carry`, `give`, `ready`, `wave_out`, `wave_start`, `wave`) with an empty hand; the wave's way up |
| `manipulation/arm_route.py` | `HOLD_SPEED` | "slow" | The same with something in the hand |
| `manipulation/arm_route.py` | `GIVE_SPEED` | "slow" | The last move into `give`, from `give_pre` (only when `give_pre` is taught: every empty-hand way to `give` then ends `give_pre` → `give`) |
| `manipulation/arm_route.py` | `GIVE_SPEED` | "route" | The last move into `give`, from `give_pre` (only when `give_pre` is taught: every empty-hand way to `give` then ends `give_pre` → `give`) |
| `manipulation/skills.py` | `EMPTY_SPEED` | "normal" | Arm with nothing in the hand: the joint move from `look` to above a cup |
| `manipulation/skills.py` | `HOLDING_SPEED` | "slow" | With an object in the hand, and the last 10 cm down onto an object and up from it |
| `manipulation/skills.py` | `ABOVE_MM` | 100 mm | Height above the grasp from where the arm goes straight down (slow) |
| `manipulation/skills.py` | `MAX_TILT_DEG` | 15° | How far a held cup may lean on any move (`tasks/fetch.py` uses the same) |
| `manipulation/wave.py` | `SWINGS` | 2 | The wave: times `wave_start` → `wave` → `wave_start` (the two taught poses, J3 −2.5° ↔ −17.2°) |
| `manipulation/wave.py` | `SWING_SPEED` | "normal" | `motion.JOINT_SPEED` of the swings. The swings are queued back to back (no stop between them); the way up goes as `arm_route.goto`, with a stop at each pose |
| `manipulation/wave.py` | `ARRIVE_SPEED` | "normal" | The way up's last move, `wave_out` → `wave_start` (J1 60°); "slow" for a softer arrival |
| `manipulation/wave.py` | `SWING_SPEED` | "quick" | `motion.JOINT_SPEED` of the swings. The swings are queued back to back (no stop between them); the way up goes as `arm_route.goto`, with a stop at each pose |
| `manipulation/wave.py` | `ARRIVE_SPEED` | "route" | The way up's last move, `wave_out` → `wave_start` (J1 60°); "slow" for a softer arrival |
| `robot/motion.py` | `SLOW_DEG_S`, `EXTRA_S` | 5 °/s, 10 s | The longest a joint move may take: its largest joint travel at this slow rate (or 3× the planned time if longer), plus `EXTRA_S`; then the arm is stopped. Long moves run at 4.3–7 °/s whatever speed is asked |
| `robot/motion.py` | `STILL_S` | 2 s | An arm standing this long short of its target has stopped short: stopped, nothing more sent |
| `robot/motion.py` | `SETTLE_S` | 0.3 s | After each arrival (inpos, joints within 0.3°) the arm stands this long before the next move of a route or wave. Estimate |
+5 -4
View File
@@ -51,12 +51,13 @@ from vision import calib, head_cam
HOME = "look" # every arm action starts here
GIVE = "give" # the hand held out to a person
GIVE_PRE = "give_pre" # one step before GIVE: an empty-hand way to GIVE always ends GIVE_PRE -> GIVE
GIVE_SPEED = "slow" # motion.JOINT_SPEED of the last move, GIVE_PRE -> GIVE (first live runs: slow)
GIVE_SPEED = "route" # motion.JOINT_SPEED of the last move, GIVE_PRE -> GIVE
EDGES = (("give_pre", "give"), ("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
("wave_start", "wave"), ("look", "ready")) # the moves with something in the hand (both ways)
NO_EDGES = {frozenset(("look", "wave_start"))} # never one joint move: passes 267 mm from the head (the wave
# goes up and down through wave_out, 309 mm)
WAVE_POSES = ("wave_out", "wave_start", "wave") # never with something in the hand (the cup would tip)
NO_EDGES = {frozenset(("look", "wave_start")), # never one joint move: passes 267 mm from the head (the wave
*(frozenset(("give", w)) for w in ("wave_out", "wave_start", "wave"))} # goes up and down through
# wave_out, 309 mm); give and the wave poses through give_pre
STOP_DEG = 10.0 # deg of joint travel one more stop on a route costs (SETTLE_S, slowing down and
# starting again; an estimate, it only weighs routes against each other)
SPEED = "route" # motion.JOINT_SPEED of the moves along the graph, empty hand
@@ -193,7 +194,7 @@ def hops(now, target, leaf=False, holding=False, skip=()):
"""The poses the arm goes through from the joints `now` to `target`, in order (not the one it is at). `leaf`: the
arm is out on the task's own checked way from look (above a table): when it is at no pose, straight to target.
`skip`: poses the way must not pass."""
if holding and target in WAVE_POSES:
if holding and target in WAVE_POSES + (GIVE_PRE,): # GIVE_PRE is the empty hand's (the gripper reads holding)
raise RouteError(*SPILL)
nodes = graph(holding, skip)
if target not in nodes:
+7 -4
View File
@@ -23,8 +23,8 @@ from robot import agv, arm, gripper, motion
START = "wave_start" # hand above the head; the wave starts and ends here
SWING = "wave" # START with J3 −14.7°
SWINGS = 2 # times START -> SWING -> START
SWING_SPEED = "normal" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED ...
ARRIVE_SPEED = "normal" # ... but its last move, into START: at route speed it stopped there hard (J1 60°)
SWING_SPEED = "quick" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED ...
ARRIVE_SPEED = "route" # ... its last move, into START (J1 60°), too (owner: as fast as the way down)
# Why Lumi does not wave, (English, Korean)
OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.")
@@ -86,8 +86,9 @@ def plan():
return route, swings
def wave(on_start=None):
"""Plan, check and wave; the arm stays at START. `on_start()` is called once the plan is checked.
def wave(on_start=None, on_up=None):
"""Plan, check and wave; the arm stays at START. `on_start()` is called once the plan is checked, `on_up()` at
START before the swings (the hand above the head from there on).
Raises WaveError (refused) or motion.MotionError (stopped / failed while moving: the arm stays where it stopped)."""
try:
route, swings = plan()
@@ -104,6 +105,8 @@ def wave(on_start=None):
log(f"arm at {START} after {time.time() - t0:.1f} s")
if route and motion._stopped.wait(motion.SETTLE_S): # stand at START first, as between any two moves
raise motion.MotionError("stopped")
if on_up:
on_up()
t0 = time.time()
motion.move_path([(t, SWING_SPEED) for t in swings], queued=True) # back to back, no stop between swings
log(f"wave: {SWINGS} swings after {time.time() - t0:.1f} s")
+1 -1
View File
@@ -25,7 +25,7 @@ ROOT = Path(__file__).resolve().parents[1] # the project folder
POSES_FILE = ROOT / "data" / "arm_poses.json"
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, "route": 40.0} # deg/s; route: empty-hand pose-graph moves (estimate)
JOINT_SPEED = {"slow": 10.0, "normal": 25.0, "fast": 40.0, "quick": 50.0, "route": 60.0} # deg/s; route: empty-hand pose-graph moves (the Cobo π joint speed limit, 60)
LINEAR_SPEED = {"slow": 20.0, "normal": 50.0} # mm/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
+4 -4
View File
@@ -31,8 +31,8 @@ def moved(j, joint, deg):
# ---------- empty hand: the least joint travel, every move checked ----------
assert names("give", POSES["wave_start"]) == ["give"] # after a wave: straight down to give
assert names("give", POSES["wave"]) == ["give"]
for s in ("wave_start", "wave"): # after a wave: never in one move to give
assert names("give", POSES[s])[-1] == "give" and len(names("give", POSES[s])) > 1
assert names("give", POSES["look"]) == ["give"] # 32 deg, not look -> carry -> give (71)
assert names("look", POSES["give"]) == ["look"]
assert names("look", POSES["wave_start"]) == ["wave_out", "look"] # never look - wave_start in one move
@@ -77,10 +77,10 @@ sent = []
real_path, motion.move_path = motion.move_path, lambda moves, **k: sent.extend(moves)
arm_route.move(arm_route.plan("give", now=list(POSES["wave_start"])))
assert [s for _, s in sent][-1] == arm_route.GIVE_SPEED and \
all(s == arm_route.SPEED for _, s in sent[:-1]), sent # the last move, give_pre -> give, slow
all(s == arm_route.SPEED for _, s in sent[:-1]), sent # the last move, give_pre -> give, GIVE_SPEED
del POSES["give_pre"] # not taught: the route and speed as before
sent.clear()
arm_route.move(arm_route.plan("give", now=list(POSES["wave_start"])))
assert [s for _, s in sent] == [arm_route.SPEED], sent
assert all(s == arm_route.SPEED for _, s in sent), sent # no give_pre: every move at route speed
motion.move_path = real_path
print("arm give route ok")
+7 -1
View File
@@ -83,6 +83,11 @@ for a in POSES:
fake = use(POSES[a])
route = arm_route.goto(b)
assert fake.sent == [POSES[n] for n in route] and arm_route.where(fake.j) == b, (a, b, route)
if frozenset((a, b)) in arm_route.NO_EDGES and {a, b} != {"look", "wave_start"}: # give - wave poses:
hops = [a] + route # through give_pre /
assert route[-1] == b and not any(frozenset(h) in arm_route.NO_EDGES for h in zip(hops, hops[1:])), \
(a, b, route) # wave_out
continue
want = [] if a == b else ["wave_out", b] if {a, b} == {"look", "wave_start"} else [b]
assert route == want, (a, b, route) # look - wave_start: wave_out ties wave, EDGES first
# ... holding: along EDGES only, never a wave pose
@@ -100,7 +105,8 @@ use(POSES["give"])
assert arm_route.goto("look", holding=True) == ["carry", "look"] # after giving: give -> carry -> look
assert arm_route.goto("give", holding=True) == ["carry", "give"] # to give: look -> carry -> give
use(POSES["wave_start"])
assert arm_route.goto("give") == ["give"] # empty after a wave: straight to give
r = arm_route.goto("give") # empty after a wave: never wave pose - give
assert r[-1] == "give" and "wave_start" not in r and len(r) > 1, r # in one move (owner)
assert not any("tuck" in e for e in arm_route.EDGES)
use(POSES["look"])
assert arm_route.goto("wave_start") == ["wave_out", "wave_start"] # up: never look -> wave_start directly
+1 -1
View File
@@ -85,7 +85,7 @@ fetch._thread.join(10)
st = fetch.state()
assert st["status"] == "done", st
w0, arm0, arm1, w1 = when("waist start")[0], when("arm start")[0], when("arm end")[0], when("waist end")[-1]
assert w0 <= arm0 < arm1, events # the waist command went out first, before the arm route ended
assert abs(w0 - arm0) < 0.1 and w0 < arm1, events # both start together (threads: either first), the waist before the arm ends
assert arm0 < w1, events # the arm started before the waist got there
assert len(when("waist start")) == math.ceil(30.0 / fetch.WAIST_STEP_DEG), events
assert abs(body["pos"][1] - 30.0) < 1e-6 and abs(body["pos"][2]) < 1e-6, body # waist 30, head yaw 30 - 30 = 0
+17 -7
View File
@@ -75,9 +75,10 @@ def refused(reason):
# ---------- 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)))
started, up = [], []
wave.wave(on_start=lambda: started.append(len(a.sent)), on_up=lambda: up.append(len(a.sent)))
assert started == [0] # said before the first move
assert up == [2] # at wave_start, before the swings (person stop off)
top, swing = POSES["wave_start"], POSES["wave"]
assert wave.SWINGS == 2
assert a.sent == [POSES["wave_out"], top] + [swing, top] * wave.SWINGS, a.sent
@@ -98,12 +99,12 @@ a.j = list(LOOK)
wave.wave()
sent = [e for e in names if e[0] in ("joint_move", "get_data")]
route, swing_s = motion.JOINT_SPEED[arm_route.SPEED], motion.JOINT_SPEED[wave.SWING_SPEED]
arrive = motion.JOINT_SPEED[wave.ARRIVE_SPEED] # into wave_start softer than the route speed
assert arrive < route and wave.ARRIVE_SPEED == "normal"
arrive = motion.JOINT_SPEED[wave.ARRIVE_SPEED] # into wave_start at the route speed too
assert arrive == route and wave.ARRIVE_SPEED == "route"
assert sent == [("joint_move", route, False), ("get_data", None, False), ("joint_move", arrive, False),
("get_data", None, False)] + \
[("joint_move", swing_s, False)] * 2 * wave.SWINGS + [("get_data", None, False)], sent # swings back to back
assert wave.SWING_SPEED == "normal"
assert wave.SWING_SPEED == "quick"
arm.cmd = a
a.j = list(top)
a.sent.clear()
@@ -190,9 +191,18 @@ assert L.wave() is False and said == [wave.HOLDING[1]]
said.clear()
assert L.wave(quiet=True) is False and said == [] # a goodbye wave refused: no words about it
hand["holding"] = False # a stale "holding", the hand empty (2026-10-23
real_wave, wave.wave = wave.wave, lambda on_start=None: None # 17:43): checked again, not refused for holding
real_wave, wave.wave = wave.wave, lambda on_start=None, on_up=None: None # 17:43): checked again, not refused for holding
said.clear()
assert L.wave() is True and said == [] and not fetch.state()["holding"], said
held, go = threading.Event(), threading.Event() # the same request twice (16:21, typed): one wave
wave.wave = lambda on_start=None, on_up=None: (held.set(), go.wait(10))
first = threading.Thread(target=L.wave)
first.start()
held.wait(10)
assert L.wave() is False # asked again while it waves: refused, no second
go.set()
first.join()
assert L.wave() is True # ... and the next one after it ended runs
wave.wave = real_wave
fetch.STATE_FILE.unlink()
@@ -207,7 +217,7 @@ def slow_say(text, **k): # speech tha
lumi.mouth = types.SimpleNamespace(say=slow_say)
L.lang = "en"
wave.wave = lambda on_start=None: (on_start(), order.append("move"))
wave.wave = lambda on_start=None, on_up=None: (on_start(), order.append("move"))
done = []
th = threading.Thread(target=lambda: done.append(L.wave(("Okay!", "네!"))))
th.start()