2026-10-21 16:54:22 +09:00
|
|
|
|
"""Wave the hand when someone asked for it. A greeting never moves the arm.
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
2026-10-21 17:34:00 +09:00
|
|
|
|
The arm goes up along the pose graph (manipulation/arm_route.py: from `look` to `wave_out`, the hand away from the
|
2026-10-21 18:10:25 +09:00
|
|
|
|
head, then `wave_start`, the hand above the head), swings between the taught poses `wave_start` and `wave` (J3 −14.7°)
|
|
|
|
|
|
SWINGS times and STAYS at `wave_start`: the next arm task takes it back down the same way (wave_start -> wave_out
|
|
|
|
|
|
-> look). The way up goes like arm_route.goto, then the swings; each move to a stop (motion.move_path). Before
|
2026-10-21 17:58:58 +09:00
|
|
|
|
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
|
2026-10-21 17:34:00 +09:00
|
|
|
|
running, something in the hand, the arm at no known pose (after free drive), a pose not taught, a move too near the
|
|
|
|
|
|
head.
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
|
|
|
|
|
python manipulation/wave.py check # plan and check from where the arm is now; moves nothing
|
|
|
|
|
|
python manipulation/wave.py run # wave (slow; the owner at the STOP)
|
|
|
|
|
|
|
2026-10-21 17:34:00 +09:00
|
|
|
|
Teach the poses first, arm moved by hand in Cobo π: python robot/motion.py teach wave_out / wave_start / wave
|
2026-10-21 15:19:07 +09:00
|
|
|
|
"""
|
|
|
|
|
|
import sys
|
2026-10-21 17:58:58 +09:00
|
|
|
|
import time
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
2026-10-21 16:54:22 +09:00
|
|
|
|
from manipulation import arm_route, skills
|
2026-10-21 15:19:07 +09:00
|
|
|
|
from robot import agv, arm, gripper, motion
|
|
|
|
|
|
|
2026-10-21 17:34:00 +09:00
|
|
|
|
START = "wave_start" # hand above the head; the wave starts and ends here
|
2026-10-21 17:58:58 +09:00
|
|
|
|
SWING = "wave" # START with J3 −14.7°
|
2026-10-21 17:48:11 +09:00
|
|
|
|
SWINGS = 2 # times START -> SWING -> START
|
2026-10-21 17:58:58 +09:00
|
|
|
|
SWING_SPEED = "normal" # motion.JOINT_SPEED of the swings; the way up is arm_route.move (as goto)
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
|
|
|
|
|
# Why Lumi does not wave, (English, Korean)
|
2026-10-21 16:26:55 +09:00
|
|
|
|
OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.")
|
2026-10-21 15:19:07 +09:00
|
|
|
|
BUSY = ("I'm busy with my arm right now.", "지금 팔로 하는 일이 있어요.")
|
|
|
|
|
|
DRIVING = ("I can't wave while I'm moving.", "움직이는 동안에는 손을 흔들 수 없어요.")
|
|
|
|
|
|
HOLDING = ("I'm holding something, so I won't wave.", "손에 물건을 들고 있어서 손을 흔들지 않을게요.")
|
2026-10-21 16:54:22 +09:00
|
|
|
|
UNKNOWN_POSE = arm_route.UNKNOWN
|
2026-10-21 15:19:07 +09:00
|
|
|
|
NOT_TAUGHT = ("I haven't learned how to wave safely yet.", "아직 안전하게 손 흔드는 법을 배우지 못했어요.")
|
|
|
|
|
|
NEAR_HEAD = ("Waving would bring my hand too close to my head, so I won't.",
|
|
|
|
|
|
"손이 머리에 너무 가까워져서 손을 흔들지 않을게요.")
|
|
|
|
|
|
UNSURE = ("I can't check my arm right now, so I won't wave.", "지금 팔 상태를 확인할 수 없어서 손을 흔들지 않을게요.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WaveError(RuntimeError):
|
|
|
|
|
|
"""args: (English, Korean) reason."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log(*a):
|
|
|
|
|
|
print(*a, flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _holding():
|
|
|
|
|
|
"""Is something in the hand? The fetch rule (fetch._in_hand): the task state first, then the torso camera, the
|
|
|
|
|
|
gripper's AI_1 when the camera can't tell. Only reads: fetch's own functions write its state file."""
|
|
|
|
|
|
from tasks import fetch
|
|
|
|
|
|
st = fetch.state()
|
|
|
|
|
|
if st.get("holding") or st.get("held_object"):
|
|
|
|
|
|
return True
|
|
|
|
|
|
try:
|
|
|
|
|
|
seen = skills.hand_sees()
|
|
|
|
|
|
except (skills.SkillError, ConnectionError, OSError, KeyError):
|
|
|
|
|
|
seen = "unknown"
|
|
|
|
|
|
return seen == "object" if seen != "unknown" else bool(gripper.state()["holding"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plan():
|
2026-10-21 17:58:58 +09:00
|
|
|
|
"""(the way up: arm_route.plan to START, the swings' joint targets) from here, each move checked. Raises
|
|
|
|
|
|
WaveError to refuse."""
|
2026-10-21 15:19:07 +09:00
|
|
|
|
from tasks import fetch
|
|
|
|
|
|
st = arm.cmd("get_robot_state")
|
|
|
|
|
|
if not (st.get("power") and st.get("enable")):
|
|
|
|
|
|
raise WaveError(*OFF)
|
|
|
|
|
|
if arm.program_state() != "idle" or fetch.state().get("status") in ("running", "waiting"):
|
|
|
|
|
|
raise WaveError(*BUSY)
|
|
|
|
|
|
if (agv.status() or {}).get("move_status") == "running":
|
|
|
|
|
|
raise WaveError(*DRIVING)
|
|
|
|
|
|
if _holding():
|
|
|
|
|
|
raise WaveError(*HOLDING)
|
2026-10-21 16:54:22 +09:00
|
|
|
|
now = motion.joints()
|
|
|
|
|
|
try:
|
2026-10-21 17:34:00 +09:00
|
|
|
|
route = arm_route.plan(START, now=now) # up along the graph ([] when it is there already)
|
|
|
|
|
|
p = motion.poses()
|
|
|
|
|
|
if SWING not in p:
|
|
|
|
|
|
raise arm_route.RouteError(*arm_route.NOT_TAUGHT)
|
2026-10-21 17:58:58 +09:00
|
|
|
|
swings = arm_route.check_moves(route[-1][1] if route else now, [p[SWING], p[START]] * SWINGS)
|
2026-10-21 16:54:22 +09:00
|
|
|
|
except arm_route.RouteError as e:
|
|
|
|
|
|
raise WaveError(*{arm_route.UNKNOWN: UNKNOWN_POSE, arm_route.NOT_TAUGHT: NOT_TAUGHT,
|
|
|
|
|
|
arm_route.BLOCKED: NOT_TAUGHT, arm_route.NEAR_HEAD: NEAR_HEAD}.get(e.args, UNSURE)) from e
|
2026-10-21 17:58:58 +09:00
|
|
|
|
return route, swings
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wave(on_start=None):
|
2026-10-21 17:34:00 +09:00
|
|
|
|
"""Plan, check and wave; the arm stays at START. `on_start()` is called once the plan is checked.
|
2026-10-21 15:19:07 +09:00
|
|
|
|
Raises WaveError (refused) or motion.MotionError (stopped / failed while moving: the arm stays where it stopped)."""
|
|
|
|
|
|
try:
|
2026-10-21 17:58:58 +09:00
|
|
|
|
route, swings = plan()
|
2026-10-21 15:19:07 +09:00
|
|
|
|
except (motion.MotionError, skills.SkillError, ConnectionError, OSError, KeyError, ValueError) as e:
|
|
|
|
|
|
log(f"wave refused: {e}")
|
|
|
|
|
|
raise WaveError(*UNSURE) from e
|
2026-10-21 17:58:58 +09:00
|
|
|
|
log(f"wave: {len(route) + len(swings)} joint moves, checked")
|
2026-10-21 15:19:07 +09:00
|
|
|
|
if on_start:
|
|
|
|
|
|
on_start()
|
2026-10-21 18:10:25 +09:00
|
|
|
|
arm_route.move(route) # up exactly as arm_route.goto
|
|
|
|
|
|
if route and motion._stopped.wait(motion.SETTLE_S): # stand at START first, as between any two moves
|
|
|
|
|
|
raise motion.MotionError("stopped")
|
2026-10-21 17:58:58 +09:00
|
|
|
|
t0 = time.time()
|
2026-10-21 18:10:25 +09:00
|
|
|
|
motion.move_path([(t, SWING_SPEED) for t in swings])
|
2026-10-21 17:58:58 +09:00
|
|
|
|
log(f"wave: {SWINGS} swings after {time.time() - t0:.1f} s")
|
2026-10-21 15:19:07 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
what = sys.argv[1] if len(sys.argv) > 1 else "check"
|
|
|
|
|
|
try:
|
|
|
|
|
|
if what == "check":
|
2026-10-21 17:58:58 +09:00
|
|
|
|
route, swings = plan()
|
|
|
|
|
|
print([n for n, _ in route], [[round(v, 1) for v in t] for t in swings])
|
2026-10-21 15:19:07 +09:00
|
|
|
|
elif what == "run":
|
|
|
|
|
|
wave()
|
|
|
|
|
|
print("done")
|
|
|
|
|
|
else:
|
|
|
|
|
|
sys.exit(__doc__)
|
|
|
|
|
|
except WaveError as e:
|
|
|
|
|
|
sys.exit(f"refused: {e.args[0]}")
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
|
print(motion.stop())
|