Fix arm going to rest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 16:33:18 +09:00
co-authored by Claude Opus 5.5
parent 603a7710c5
commit 2e171381ea
3 changed files with 59 additions and 13 deletions
+9 -6
View File
@@ -284,12 +284,15 @@ def waist_home_rest(why):
if arm_route.where() in arm_route.WAVE_POSES:
wave_greet._quiet(10.0) # the hand up already: the waist turns with it up, its swings
# ended first
else: # on the charger the hand rests up in wave_start, with or
if not (fetch._at_pose(arm_route.HOME) or fetch._at_pose(arm_route.rest_pose())): # without
log(f" arm and waist stay ({why}): my arm is out") # Welcome
return False # (owner,
arm_route.move(arm_route.plan(wave_mod.START), HOME_ARM_SPEED) # 2026-11-16)
log(f" arm up to {wave_mod.START} at home ({why})")
else: # on the charger the hand rests up in wave_start, only with
if not (fetch._at_pose(arm_route.HOME) or fetch._at_pose(arm_route.rest_pose())): # Wave on; Wave
log(f" arm and waist stay ({why}): my arm is out") # off: the arm
return False # stays (owner,
if wave_greet._on and wave_greet._on(): # 2026-11-19)
arm_route.move(arm_route.plan(wave_mod.START), HOME_ARM_SPEED)
log(f" arm up to {wave_mod.START} at home ({why})")
else:
log(f" arm stays ({why}): Wave is off")
if fetch._waist_to(HOME_WAIST_DEG, in_place=True):
log(f" waist to its rest at home, {HOME_WAIST_DEG:+.0f} deg ({why})")
return True
+48 -5
View File
@@ -53,6 +53,10 @@ WAIST_FOLLOW_DEG = 20.0 # deg the waving person may move off the waist's fr
FOLLOW_EVERY_S = 3.0 # ... at most this often (between swings)
WAIST_PARTS = (1.0, 0.75, 0.5, 0.25) # a blocked waist turn is tried again this much of the way (beside a wall)
HEAD_MIN_DEG = 8.0 # deg the person may move off the head's direction before the head follows
HOME_CHECK_S = 1.0 # s between two looks at an arm left away from wave_start with Wave on
RETURN_AFTER_S = 15.0 # s the arm stands still (no jog, no pose) before it goes back to wave_start
RETRY_HOME_S = 60.0 # s before a refused way back is tried again
STILL_DEG = 0.5 # deg; any joint moving more than this between two looks is not standing still
DOWN_SPEED = "normal" # motion.JOINT_SPEED of the way down (owner: 2x the first "slow")
SWING_SPEED = "swing" # motion.JOINT_SPEED of the swings, 60 deg/s at 4x the usual acceleration (owner: faster;
# wave.SWING_SPEED of an asked wave is "quick")
@@ -643,7 +647,7 @@ def _rest_waist():
_busy.clear()
def _down(waist=None, arm_to=None, speed=None):
def _down(waist=None, arm_to=None, speed=None, lower=True):
"""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."""
@@ -655,10 +659,11 @@ def _down(waist=None, arm_to=None, speed=None):
fetch._stop.clear()
_st["waist_out"] = not fetch._waist_to(_rest() if waist is None else waist, in_place=True)
at = arm_route.where()
if at in arm_route.WAVE_POSES:
lowered = lower and at in arm_route.WAVE_POSES
if lowered:
arm_route.move(arm_route.plan(arm_to or _rest_arm()), speed or DOWN_SPEED)
_turn_head(0.0, head.HEAD_REST_PITCH)
log("arm down" if at in arm_route.WAVE_POSES or at in (_rest_arm(), arm_to) else f"arm left where it is ({at or 'between poses'})")
log("arm down" if lowered or (lower and at in (_rest_arm(), arm_to)) else f"arm left where it is ({at or 'between poses'})")
finally:
_busy.clear()
@@ -666,7 +671,7 @@ def _down(waist=None, arm_to=None, speed=None):
_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, "idle_at": 0.0, "held": False, "held_at": 0.0, "owed": 0, "people_wave": 0.0, "any_wave": 0.0,
"raise_at": 0.0} # held: the hand kept up on the charger
"raise_at": 0.0, "home_at": 0.0, "home_j": None, "home_still": 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
@@ -675,7 +680,7 @@ def step(now):
st = _st
if not _on():
if st["up"]:
_down()
_down(lower=False) # owner 2026-11-19: switched off (or an API restart), the arm stays where it is
st["up"] = st["held"] = False
return
if now - st["free_at"] > FREE_EVERY_S:
@@ -684,6 +689,9 @@ def step(now):
st["up"] = st["held"] = False
_busy.clear()
return
if not st["up"] and now - st["home_at"] >= HOME_CHECK_S:
st["home_at"] = now
_back_to_start(now)
w = _waver()
new = bool(w) and now - st["last_wave"] > NEW_WAVE_S
if new:
@@ -744,6 +752,41 @@ def step(now):
st["held"], st["idle_at"], st["held_at"] = True, now - IDLE_WAVE_EVERY_S, 0.0 # swings due at once
def _back_to_start(now):
"""Wave on, the robot free, the hand not up: an empty arm left anywhere else (after a task, a pose, a jog) goes
back up to wave.START once it has stood still RETURN_AFTER_S, along the checked pose graph (owner, 2026-11-19:
with Wave on the arm waits in wave_start; never at rest unless asked)."""
from tasks import fetch
try: # a read that fails only puts the next look off, never the greeting
if fetch.state().get("holding") or fetch._busy():
return
j = motion.joints()
except Exception:
return
if not any(j): # a switched-off arm reads all 0
return
last = _st["home_j"]
if last is None or max(abs(a - b) for a, b in zip(j, last)) > STILL_DEG:
_st["home_j"], _st["home_still"] = j, now
return
if now - _st["home_still"] < RETURN_AFTER_S:
return
if arm_route.where(j) in (wave.START, wave.SWING):
_st.update(up=True, held=True, held_at=now)
return
log(f"Wave on: the arm back to {wave.START}")
_busy.set()
try:
arm_route.goto(wave.START, speed=DOWN_SPEED)
_st.update(up=True, held=True, held_at=now)
except Exception as e:
log(f"arm not back to {wave.START}: {e.args[0] if e.args else e!r}")
_st["home_still"] = now + RETRY_HOME_S - RETURN_AFTER_S # tried again after RETRY_HOME_S, not every check
finally:
_busy.clear()
_st["home_j"] = None
def _stopped(e):
"""A stop or a failure of the arm: switched off, it never goes on by itself."""
log(f"stopped ({e!r}) - switched off")
+2 -2
View File
@@ -168,11 +168,11 @@ waver["w"] = W(5.0)
run(200.0, 200.0)
assert done == ["up route"] + ["swing"] * g.GREET_SWINGS, done # the head looks there already (within HEAD_MIN_DEG)
# the switch is turned off with the hand up: down at once
# the switch is turned off with the hand up: the waist and head to rest, the arm stays where it is (owner, 2026-11-19)
switch["on"] = False
done.clear()
run(200.5, 200.5)
assert done[:2] == ["waist +0 look None", "down normal"], done
assert done[:2] == ["waist +0 look None", "head +0 rest"] and not any(d.startswith("down") for d in done), done
# the arm stops (STOP, a person too close) during a swing: switched off, nothing moves after it
fresh()