Fix hand reach, arm rest routing and response delays on the charger
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+40
-6
@@ -50,6 +50,9 @@ LOOK_POSE = "look" # drives, turns, looks and waits here, also with an
|
||||
# the torso view, too near for depth (ready if not taught). carry is only passed through after a
|
||||
# pick: in carry the hand is ~0.3 m before the base's front, where its 3D camera seems to see
|
||||
# it as an obstacle (every drive in carry stalled; the same drives in look went, 2026-10-16)
|
||||
BAG_POSE = "bag" # the arm held out for a bag to be hung on the gripper's hooks (owner's pose); drives go
|
||||
# in arm_route.REST like every empty-hand drive (in look the bag hung before the base's
|
||||
# 3D camera and every drive stalled)
|
||||
CHECK_POSE = "carry" # a fully shut hand is looked at here (look_at_hand): the torso camera sees the place between
|
||||
# the fingers ~445 mm away (from the joints and the calibration; in look it is above the view,
|
||||
# in give a person's hand can be there). Not yet tried live: the fingers may hide it
|
||||
@@ -402,12 +405,31 @@ def _at_pose(name):
|
||||
return max(abs(a - b) for a, b in zip(j, motion.nearest(motion.poses()[name], j))) <= 1.0
|
||||
|
||||
|
||||
BAG_HOLDING = ("My hand is holding something, I can't take a bag now.", "손에 뭔가 들고 있어서 지금은 가방을 들 수 없어요.")
|
||||
BAG_HANG_SAY = ("Please hang the bag on my hand.", "가방을 제 손에 걸어 주세요.")
|
||||
BAG_HANG_S = 8.0 # s a mission waits after the arm went to BAG_POSE, for a person to hang the bag on (estimate)
|
||||
|
||||
|
||||
def bag_off():
|
||||
"""The bag taken off the hooks ("fold your arm", "thanks" after "give me the bag", outside a task): the arm to its
|
||||
rest (arm_route.rest_pose) along the pose graph and the state's "bag" cleared. FetchError when busy or the arm
|
||||
can't go."""
|
||||
_adopt()
|
||||
with _lock:
|
||||
if _busy():
|
||||
raise FetchError("I'm busy with another task.", "지금 다른 일을 하고 있어요.")
|
||||
_stop.clear() # an old stop must not end this one; a new one does
|
||||
_pose(arm_route.rest_pose())
|
||||
_set(bag=False)
|
||||
log("no bag: the arm at rest")
|
||||
|
||||
|
||||
def _drive_pose(holding=False):
|
||||
"""The arm to look before the base drives or turns. A switched-off arm (Cobo π: not powered or not enabled) stays
|
||||
"""The arm to its rest (arm_route.rest_pose; look with something held) before the base drives or turns. A switched-off arm (Cobo π: not powered or not enabled) stays
|
||||
where it is: drives and talk need no arm, and the arm's points are still checked from its joints. Powered off, it
|
||||
reads all joints 0: where it is is not known, so no drive (ARM_UNSEEN)."""
|
||||
try:
|
||||
_line_holding(LOOK_POSE) if holding else _pose(_look())
|
||||
_line_holding(LOOK_POSE) if holding else _pose(arm_route.rest_pose()) # a bag on the hooks too
|
||||
except (FetchError, motion.MotionError) as e:
|
||||
if tuple(e.args[:1]) != arm_route.OFF[:1] and "not powered" not in str(e):
|
||||
raise
|
||||
@@ -3066,7 +3088,7 @@ def _do_step(s, say):
|
||||
if _give(say) == "kept":
|
||||
raise FetchError("Nobody took it, I'm still holding it.", "아무도 안 받아서 계속 들고 있어요.")
|
||||
elif d == "arm":
|
||||
_arm(s["pose"])
|
||||
_arm(s["pose"], say)
|
||||
elif d == "carry":
|
||||
_carry_held()
|
||||
# "hold": nothing to do, the mission ends holding
|
||||
@@ -3423,15 +3445,27 @@ def _give_turning(rel, look):
|
||||
_go_on()
|
||||
|
||||
|
||||
def _arm(pose):
|
||||
def _arm(pose, say=None):
|
||||
if pose in ("open", "close"):
|
||||
st = gripper.open_() if pose == "open" else gripper.close()
|
||||
if pose == "open":
|
||||
skills._held.clear()
|
||||
_set(holding=False)
|
||||
log(f"gripper {pose}: {st}")
|
||||
elif pose == "fold": # the arm's home
|
||||
_line_holding(LOOK_POSE) if _state["holding"] else _pose(LOOK_POSE)
|
||||
elif pose == "fold": # the arm's rest
|
||||
_line_holding(LOOK_POSE) if _state["holding"] else _pose(arm_route.rest_pose())
|
||||
_set(bag=False)
|
||||
elif pose == "bag": # the hooks ready for a bag; drives keep the arm there (BAG_POSE)
|
||||
if _state["holding"]:
|
||||
raise FetchError(*BAG_HOLDING)
|
||||
hung = _state.get("bag")
|
||||
_pose(BAG_POSE)
|
||||
_set(bag=True)
|
||||
if not hung: # a person hangs it on now, before the next step drives
|
||||
if say:
|
||||
say(*BAG_HANG_SAY)
|
||||
if _stop.wait(BAG_HANG_S):
|
||||
raise Stopped()
|
||||
elif pose == "reach": # the hand held out, as for a hand-over
|
||||
if "give" not in motion.poses():
|
||||
raise FetchError("I haven't learned how to reach out yet.")
|
||||
|
||||
+124
-15
@@ -1,5 +1,7 @@
|
||||
"""Wave back at people who wave at Lumi: the dashboard switch "Wave greeting". Greeter / Patrol are not needed; while
|
||||
either runs the assistant owns the robot and this waits. Runs in the API process (api/server.py starts it).
|
||||
"""Wave back at people who wave at Lumi: the dashboard switch "Wave greeting", with or without Greeter / Patrol. It
|
||||
runs in the process that owns the robot: the API's (api/server.py) while the assistant is off, the assistant's
|
||||
(assistant/lumi.py) while it runs. There it waits while a drive, task, skill or conversation has the robot; a drive
|
||||
or turn brings a raised hand down first (lower()).
|
||||
|
||||
Someone waving within GREET_M of either camera (vision/waving.py; the head camera may look elsewhere): the head turns to them and the arm goes up at
|
||||
once (manipulation/wave.py checks and plans the way, look -> wave_out -> wave_start, at the route speed), Lumi says a
|
||||
@@ -51,6 +53,12 @@ REFUSED_S = 30.0 # s before trying again after the arm was refused (
|
||||
# between tries to bring a blocked waist back to the front
|
||||
HEAD_TIMEOUT_S = 5.0 # s a head move may take; the body API now and then never answers a moveto, and the call
|
||||
# holds the body lock all that time (the waist turn waited 30 s behind it)
|
||||
IDLE_WAVE_EVERY_S = 20.0 # s between two waves while nothing is asked of Lumi on the charger (owner: now and then for
|
||||
# the passers-by; estimate), from the end of the last one (or anyone's last wave)
|
||||
IDLE_SWINGS = 2 # swings of such a wave
|
||||
IDLE_CLEAR_M = 1.0 # m; nobody this near in either camera when such a wave starts (one coming closer while the
|
||||
# arm goes up still stops it: _too_close); estimate
|
||||
IDLE_RETRY_S = 1.0 # s between two asks whether Lumi is idle (it asks the base whether it charges)
|
||||
CLOSE_FRESH_S = 1.5 # s a camera service detection counts for the too-close check
|
||||
|
||||
_seen = {c: {"t": 0.0, "wavers": []} for c in CAMERAS} # wavers: [(bearing deg from the waist's front, + left;
|
||||
@@ -60,6 +68,9 @@ _met_lock = threading.Lock()
|
||||
_busy = threading.Event() # the arm is up or moving for a greeting
|
||||
_speaking = threading.Lock()
|
||||
_on = _free = _off = None # set by start()
|
||||
_rest = lambda: 0.0 # waist angle (deg from the front) the waist goes back to; set by start()
|
||||
_rest_arm = arm_route.rest_pose # the pose the arm goes down to; set by start()
|
||||
_idle = lambda: False # nothing asked of Lumi for a while (on the charger): a wave now and then; set by start()
|
||||
|
||||
|
||||
def log(*a):
|
||||
@@ -168,6 +179,19 @@ def _too_close():
|
||||
return False
|
||||
|
||||
|
||||
def _someone_within(m):
|
||||
"""A person within `m` metres in either camera's fresh detections."""
|
||||
for cam in ("head", "torso"):
|
||||
try:
|
||||
d = json.loads(camview.det_path(cam).read_text())
|
||||
except (FileNotFoundError, ValueError):
|
||||
continue
|
||||
if time.time() - d["time"] < CLOSE_FRESH_S and \
|
||||
any(p.get("distance_m") is not None and p["distance_m"] < m for p in d["people"]):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# ---------- moving and talking ----------
|
||||
def _bg(fn, *args):
|
||||
threading.Thread(target=fn, args=args, daemon=True).start()
|
||||
@@ -302,18 +326,55 @@ def _greet(w, lang):
|
||||
return True
|
||||
|
||||
|
||||
def _down():
|
||||
"""Waist to the front first, the way it came with the hand up (in `look` the arm sticks out further and the same
|
||||
turn back can be blocked), then the arm slowly down to look and the head to rest."""
|
||||
def _idle_wave():
|
||||
"""Nobody asks anything (on the charger, _idle): the hand goes up and stays up (owner, 2026-11-04: "held"), the
|
||||
waist where it is, no words; it swings IDLE_SWINGS times now and then (step) so passers-by see Lumi is on. A drive
|
||||
or an order for the arm takes it down (lower, a task), the switch turned off too. False when the arm is refused."""
|
||||
if _someone_within(IDLE_CLEAR_M) or arm_route.where() != _rest_arm():
|
||||
return True # someone near the arm, or the arm still on its way to rest: next time
|
||||
try:
|
||||
route, _ = wave.plan()
|
||||
except Exception as e:
|
||||
log(f"no idle wave: {e.args[0] if isinstance(e, wave.WaveError) else repr(e)}")
|
||||
return False
|
||||
log("nothing asked for a while: the hand up for the passers-by")
|
||||
_busy.set()
|
||||
try:
|
||||
_up(route)
|
||||
_st.update(up=True, held=True, held_at=0.0)
|
||||
_idle_swings()
|
||||
finally:
|
||||
_busy.clear()
|
||||
return True
|
||||
|
||||
|
||||
def _idle_swings():
|
||||
"""IDLE_SWINGS swings of the held hand; someone waving back (greeted as always, step) or talking to Lumi (the hand
|
||||
stays up, still) ends them."""
|
||||
for _ in range(IDLE_SWINGS):
|
||||
if _waver():
|
||||
log("idle wave: someone waves back")
|
||||
_st["last_wave"] = 0.0
|
||||
return
|
||||
if not (_free() and _idle()):
|
||||
log("idle wave: someone talks to me, the hand stays up")
|
||||
return
|
||||
_swing()
|
||||
|
||||
|
||||
def _down(waist=None):
|
||||
"""Waist to its rest (`waist` deg from the front, else _rest()) first, the way it came with the hand up (in `look`
|
||||
the arm sticks out further and the same turn back can be blocked), then the arm slowly down (_rest_arm) and the
|
||||
head to rest."""
|
||||
from tasks import fetch
|
||||
_busy.set()
|
||||
try:
|
||||
if _st["up"] and arm_route.where() is None:
|
||||
_settle() # mid-swing: the queued swings end first
|
||||
fetch._stop.clear()
|
||||
_st["waist_out"] = not fetch._waist_to(0.0, in_place=True)
|
||||
_st["waist_out"] = not fetch._waist_to(_rest() if waist is None else waist, in_place=True)
|
||||
if arm_route.where() in arm_route.WAVE_POSES:
|
||||
arm_route.move(arm_route.plan(arm_route.HOME), DOWN_SPEED)
|
||||
arm_route.move(arm_route.plan(_rest_arm()), DOWN_SPEED)
|
||||
_turn_head(0.0, head.HEAD_REST_PITCH)
|
||||
log("arm down")
|
||||
finally:
|
||||
@@ -322,7 +383,8 @@ def _down():
|
||||
|
||||
_st = {"up": False, "last_wave": 0.0, "lang": 0, "next_joke": 0.0, "free": False, "free_at": 0.0, "refused_until": 0.0,
|
||||
"waist_out": False, "follow_at": 0.0, "swing_at": 0.0,
|
||||
"swing_end": 0.0} # swing_end: when the swings sent so far should be done # waist_out: the way back to the front was blocked, tried again later
|
||||
"swing_end": 0.0, "idle_at": 0.0, "held": False, "held_at": 0.0} # held: the hand kept up on the charger
|
||||
# (_idle_wave) # swing_end: when the swings sent so far should be done # waist_out: the way back to the front was blocked, tried again later
|
||||
|
||||
|
||||
def step(now):
|
||||
@@ -331,12 +393,12 @@ def step(now):
|
||||
if not _on():
|
||||
if st["up"]:
|
||||
_down()
|
||||
st["up"] = False
|
||||
st["up"] = st["held"] = False
|
||||
return
|
||||
if now - st["free_at"] > FREE_EVERY_S:
|
||||
st["free"], st["free_at"] = _free(), now
|
||||
if not st["free"]: # the assistant or a task has the robot: it takes the arm from here
|
||||
st["up"] = False
|
||||
st["up"] = st["held"] = False
|
||||
_busy.clear()
|
||||
return
|
||||
w = _waver()
|
||||
@@ -350,10 +412,17 @@ def step(now):
|
||||
st["up"] = _greet(w, st["lang"])
|
||||
if not st["up"]:
|
||||
st["refused_until"] = now + REFUSED_S
|
||||
elif not w and now > st["refused_until"] and now - max(st["idle_at"], st["last_wave"]) > IDLE_WAVE_EVERY_S:
|
||||
if not _idle():
|
||||
st["idle_at"] = now - IDLE_WAVE_EVERY_S + IDLE_RETRY_S # asked again in IDLE_RETRY_S, not every step
|
||||
elif not _idle_wave():
|
||||
st["refused_until"] = now + REFUSED_S
|
||||
else:
|
||||
st["idle_at"] = now # its swings IDLE_WAVE_EVERY_S apart
|
||||
elif not w and st["waist_out"] and now > st["refused_until"]:
|
||||
from tasks import fetch
|
||||
fetch._stop.clear()
|
||||
st["waist_out"] = not fetch._waist_to(0.0, in_place=True)
|
||||
st["waist_out"] = not fetch._waist_to(_rest(), in_place=True)
|
||||
st["refused_until"] = now + REFUSED_S
|
||||
elif w:
|
||||
if new:
|
||||
@@ -371,6 +440,19 @@ def step(now):
|
||||
st["swing_at"] = now + SWING_POLL_S
|
||||
if not _swing_on(now):
|
||||
st["up"] = False # someone moved the arm: the next wave starts from where it is
|
||||
elif st["held"]: # held up on the charger: swings now and then while nobody talks to Lumi
|
||||
if now - st["idle_at"] > IDLE_WAVE_EVERY_S and now - st["held_at"] > IDLE_RETRY_S:
|
||||
st["held_at"] = now
|
||||
if _idle():
|
||||
if arm_route.where() in (wave.START, wave.SWING):
|
||||
_busy.set()
|
||||
try:
|
||||
_idle_swings()
|
||||
finally:
|
||||
_busy.clear()
|
||||
st["idle_at"] = now
|
||||
else: # an order moved the arm meanwhile: not held any more
|
||||
st["up"] = st["held"] = False
|
||||
elif now - st["last_wave"] > HOLD_S:
|
||||
_down()
|
||||
st["up"] = False
|
||||
@@ -399,10 +481,37 @@ def _run():
|
||||
_stopped(e)
|
||||
|
||||
|
||||
def start(on, free, off):
|
||||
"""`on()`: the switch is on; `free()`: nothing else has the robot; `off()`: turn the switch off."""
|
||||
global _on, _free, _off
|
||||
_on, _free, _off = on, free, off
|
||||
def up():
|
||||
"""The hand is up for a greeting (or was, when someone else took the robot meanwhile)."""
|
||||
return _st["up"]
|
||||
|
||||
|
||||
def lower(wait_s=10.0):
|
||||
"""A drive or a turn takes the robot (lumi.waist_home): the way up and the queued swings end, then a hand left in
|
||||
a wave pose comes down to look, the waist to the front. Never driven with the hand up. Nothing when the greeting
|
||||
does not run in this process (start() not called)."""
|
||||
if _on is None:
|
||||
return
|
||||
end = time.time() + wait_s
|
||||
while _busy.is_set() and time.time() < end:
|
||||
time.sleep(0.05)
|
||||
if _st["swing_end"] > time.time() - SWING_S:
|
||||
_settle() # swings sent without waiting may still run
|
||||
_st["swing_end"] = 0.0
|
||||
_st["up"] = arm_route.where() in arm_route.WAVE_POSES
|
||||
if _st["up"]:
|
||||
_down(0.0) # a drive follows: the waist to the front
|
||||
_st["up"] = _st["held"] = False
|
||||
|
||||
|
||||
def start(on, free, off, free_every=FREE_EVERY_S, rest=None, rest_arm=None, idle=None):
|
||||
"""`on()`: the switch is on; `free()`: nothing else has the robot (asked every `free_every` s); `off()`: turn the
|
||||
switch off; `rest()`: the waist's angle when the hand is down (the front unless given); `rest_arm()`: the arm's
|
||||
pose then (arm_route.rest_pose unless given); `idle()`: nothing asked for a while, a wave every IDLE_WAVE_EVERY_S
|
||||
(never unless given)."""
|
||||
global _on, _free, _off, FREE_EVERY_S, _rest, _rest_arm, _idle
|
||||
_on, _free, _off, FREE_EVERY_S = on, free, off, free_every
|
||||
_rest, _rest_arm, _idle = rest or _rest, rest_arm or _rest_arm, idle or _idle
|
||||
for cam in CAMERAS:
|
||||
threading.Thread(target=_watch, args=(cam,), daemon=True).start()
|
||||
threading.Thread(target=_run, daemon=True).start()
|
||||
|
||||
Reference in New Issue
Block a user