Wave along the taught poses: look, wave_out, wave_start, three swings to wave
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,5 +30,29 @@
|
|||||||
199.97,
|
199.97,
|
||||||
81.4,
|
81.4,
|
||||||
158.35
|
158.35
|
||||||
|
],
|
||||||
|
"wave_out": [
|
||||||
|
-239.15,
|
||||||
|
-89.88,
|
||||||
|
0.5,
|
||||||
|
-160.11,
|
||||||
|
77.47,
|
||||||
|
-201.64
|
||||||
|
],
|
||||||
|
"wave_start": [
|
||||||
|
-178.86,
|
||||||
|
-77.26,
|
||||||
|
-2.49,
|
||||||
|
-175.06,
|
||||||
|
38.21,
|
||||||
|
-219.73
|
||||||
|
],
|
||||||
|
"wave": [
|
||||||
|
-178.86,
|
||||||
|
-77.27,
|
||||||
|
-2.52,
|
||||||
|
-175.06,
|
||||||
|
59.89,
|
||||||
|
-219.73
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
"""The arm moves between named poses only along a graph of taught poses, every joint move checked before anything
|
"""The arm moves between named poses only along a graph of taught poses, every joint move checked before anything
|
||||||
moves.
|
moves.
|
||||||
|
|
||||||
give - carry - look - wave_start - wave
|
give - carry - look - wave_out - wave_start - wave
|
||||||
| \\
|
| \\
|
||||||
ready tuck
|
ready tuck
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ from robot import arm, gripper, motion
|
|||||||
from vision import calib, head_cam
|
from vision import calib, head_cam
|
||||||
|
|
||||||
HOME = "look" # every arm action starts here
|
HOME = "look" # every arm action starts here
|
||||||
EDGES = (("give", "carry"), ("carry", "look"), ("look", "wave_start"), ("wave_start", "wave"),
|
EDGES = (("give", "carry"), ("carry", "look"), ("look", "wave_out"), ("wave_out", "wave_start"),
|
||||||
("look", "ready"), ("look", "tuck")) # the only joint moves between named poses (both ways)
|
("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 = "slow" # motion.JOINT_SPEED of every move along the graph
|
||||||
AT_POSE_DEG = 3.0 # deg; the arm is at a pose when every joint is this close (where, programs)
|
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
|
EXACT_DEG = 1.0 # deg; further than this from the nearest pose a route first goes to it
|
||||||
|
|||||||
+22
-21
@@ -1,27 +1,27 @@
|
|||||||
"""Wave the hand when someone asked for it. A greeting never moves the arm.
|
"""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_start`, the hand away from the
|
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`, raised), swings one wrist joint there and STAYS at `wave`: the next arm task takes it back down
|
head, then `wave_start`, the hand above the head), swings between the taught poses `wave_start` and `wave` (J5 +21.7
|
||||||
the same way (wave -> wave_start -> look). Before anything moves, every joint move is checked (arm_route.check_moves:
|
deg) SWINGS times and STAYS at `wave_start`: the next arm task takes it back down the same way (wave_start -> wave_out
|
||||||
limits, travel, the gripper clear of the head, no dip). Refused, with the reason in English and Korean: the arm off or
|
-> look). Before anything moves, every joint move is checked (arm_route.check_moves: limits, travel, the gripper clear
|
||||||
busy, the base driving, a task running, something in the hand, the arm at no known pose (after free drive), a pose not
|
of the head, no dip). Refused, with the reason in English and Korean: the arm off or busy, the base driving, a task
|
||||||
taught, a move too near the head.
|
running, something in the hand, the arm at no known pose (after free drive), a pose not taught, a move too near the
|
||||||
|
head.
|
||||||
|
|
||||||
python manipulation/wave.py check # plan and check from where the arm is now; moves nothing
|
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)
|
python manipulation/wave.py run # wave (slow; the owner at the STOP)
|
||||||
|
|
||||||
Teach the route first, arm moved by hand in Cobo π: python robot/motion.py teach wave_start / teach wave
|
Teach the poses first, arm moved by hand in Cobo π: python robot/motion.py teach wave_out / wave_start / wave
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from manipulation import arm_route, skills
|
from manipulation import arm_route, skills
|
||||||
from robot import agv, arm, gripper, motion
|
from robot import agv, arm, gripper, motion
|
||||||
|
|
||||||
TOP = "wave" # the raised pose (arm_route.EDGES: look - wave_start - wave)
|
START = "wave_start" # hand above the head; the wave starts and ends here
|
||||||
WAVE_JOINT = 4 # joint index swung at the raised pose (4 = J5); check on the first slow run
|
SWING = "wave" # START with J5 +21.7 deg (taught 2026-10-21)
|
||||||
WAVE_DEG = 15.0 # deg each way from the raised pose
|
SWINGS = 3 # times START -> SWING -> START
|
||||||
WAVE_SWINGS = 2 # times there and back
|
SWING_SPEED = "slow" # motion.JOINT_SPEED of the swings; the way up is arm_route.SPEED
|
||||||
WAVE_SPEED = arm_route.SPEED # motion.JOINT_SPEED; the route and the swings
|
|
||||||
|
|
||||||
# Why Lumi does not wave, (English, Korean)
|
# Why Lumi does not wave, (English, Korean)
|
||||||
OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.")
|
OFF = ("Please enable my arm first.", "먼저 제 팔을 켜 주세요.")
|
||||||
@@ -71,12 +71,12 @@ def plan():
|
|||||||
raise WaveError(*HOLDING)
|
raise WaveError(*HOLDING)
|
||||||
now = motion.joints()
|
now = motion.joints()
|
||||||
try:
|
try:
|
||||||
route = arm_route.plan(TOP, now=now) # up along the graph ([] when it is up already)
|
route = arm_route.plan(START, now=now) # up along the graph ([] when it is there already)
|
||||||
start = route[-1][1] if route else now
|
p = motion.poses()
|
||||||
top = motion.nearest(motion.poses()[TOP], start)
|
if SWING not in p:
|
||||||
i = WAVE_JOINT
|
raise arm_route.RouteError(*arm_route.NOT_TAUGHT)
|
||||||
swings = [top[:i] + [top[i] + s * WAVE_DEG] + top[i + 1:] for _ in range(WAVE_SWINGS) for s in (1, -1)]
|
seq = [j for _, j in route] + arm_route.check_moves(route[-1][1] if route else now,
|
||||||
seq = [j for _, j in route] + arm_route.check_moves(start, ([] if route else [top]) + swings + [top])
|
[p[SWING], p[START]] * SWINGS)
|
||||||
except arm_route.RouteError as e:
|
except arm_route.RouteError as e:
|
||||||
raise WaveError(*{arm_route.UNKNOWN: UNKNOWN_POSE, arm_route.NOT_TAUGHT: NOT_TAUGHT,
|
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
|
arm_route.BLOCKED: NOT_TAUGHT, arm_route.NEAR_HEAD: NEAR_HEAD}.get(e.args, UNSURE)) from e
|
||||||
@@ -84,7 +84,7 @@ def plan():
|
|||||||
|
|
||||||
|
|
||||||
def wave(on_start=None):
|
def wave(on_start=None):
|
||||||
"""Plan, check and wave; the arm stays at TOP. `on_start()` is called once the plan is checked.
|
"""Plan, check and wave; the arm stays at START. `on_start()` is called once the plan is checked.
|
||||||
Raises WaveError (refused) or motion.MotionError (stopped / failed while moving: the arm stays where it stopped)."""
|
Raises WaveError (refused) or motion.MotionError (stopped / failed while moving: the arm stays where it stopped)."""
|
||||||
try:
|
try:
|
||||||
seq = plan()
|
seq = plan()
|
||||||
@@ -94,8 +94,9 @@ def wave(on_start=None):
|
|||||||
log(f"wave: {len(seq)} joint moves, checked")
|
log(f"wave: {len(seq)} joint moves, checked")
|
||||||
if on_start:
|
if on_start:
|
||||||
on_start()
|
on_start()
|
||||||
for t in seq:
|
up = len(seq) - 2 * SWINGS # the moves before are the way up along the graph
|
||||||
motion.move_joints(t, WAVE_SPEED)
|
for k, t in enumerate(seq):
|
||||||
|
motion.move_joints(t, arm_route.SPEED if k < up else SWING_SPEED)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+13
-9
@@ -12,7 +12,8 @@ from vision import head_cam
|
|||||||
|
|
||||||
fetch.STATE_FILE = Path(tempfile.mkdtemp()) / "lumi_task.json" # never the real /dev/shm file
|
fetch.STATE_FILE = Path(tempfile.mkdtemp()) / "lumi_task.json" # never the real /dev/shm file
|
||||||
POSES = {"look": [0.0] * 6, "carry": [20.0, 0, 0, 0, 0, 0], "give": [40.0, 0, 0, 0, 0, 0],
|
POSES = {"look": [0.0] * 6, "carry": [20.0, 0, 0, 0, 0, 0], "give": [40.0, 0, 0, 0, 0, 0],
|
||||||
"wave_start": [0.0, -20, 0, 0, 0, 0], "wave": [0.0, -20, 20, 0, 0, 0], "ready": [0.0, 0, -20, 0, 0, 0],
|
"wave_out": [0.0, -20, 0, 0, 0, 0], "wave_start": [0.0, -20, 20, 0, 0, 0],
|
||||||
|
"wave": [0.0, -20, 20, 0, 20, 0], "ready": [0.0, 0, -20, 0, 0, 0],
|
||||||
"tuck": [-20.0, 0, 0, 0, 0, 0]}
|
"tuck": [-20.0, 0, 0, 0, 0, 0]}
|
||||||
FAR = np.array([0.0, 0.0, 5000.0]) # the head far away: nothing near it
|
FAR = np.array([0.0, 0.0, 5000.0]) # the head far away: nothing near it
|
||||||
head = {"centre": FAR}
|
head = {"centre": FAR}
|
||||||
@@ -78,15 +79,18 @@ use(POSES["give"])
|
|||||||
assert arm_route.goto("look") == ["carry", "look"] # after giving: give -> carry -> look
|
assert arm_route.goto("look") == ["carry", "look"] # after giving: give -> carry -> look
|
||||||
assert arm_route.goto("give") == ["carry", "give"] # to give: look -> carry -> give
|
assert arm_route.goto("give") == ["carry", "give"] # to give: look -> carry -> give
|
||||||
use(POSES["wave"])
|
use(POSES["wave"])
|
||||||
assert arm_route.goto("tuck") == ["wave_start", "look", "tuck"] # fold: through look
|
assert arm_route.goto("tuck") == ["wave_start", "wave_out", "look", "tuck"] # fold: through look
|
||||||
|
use(POSES["look"])
|
||||||
|
assert arm_route.goto("wave_start") == ["wave_out", "wave_start"] # up: never look -> wave_start directly
|
||||||
|
assert {"look", "wave_start"} not in [set(e) for e in arm_route.EDGES]
|
||||||
|
|
||||||
# ---------- after a wave the arm stays up; the next pick goes wave -> wave_start -> look first ----------
|
# ---------- after a wave the arm stays at wave_start; the next pick goes down through wave_out first ----------
|
||||||
fake = use(POSES["wave"])
|
fake = use(POSES["wave_start"])
|
||||||
skills._prepare()
|
skills._prepare()
|
||||||
assert fake.sent == [POSES["wave_start"], POSES["look"]], fake.sent
|
assert fake.sent == [POSES["wave_out"], POSES["look"]], fake.sent
|
||||||
fake = use(POSES["wave"])
|
fake = use(POSES["wave_start"])
|
||||||
fetch._pose("look")
|
fetch._pose("look")
|
||||||
assert fake.sent == [POSES["wave_start"], POSES["look"]], fake.sent
|
assert fake.sent == [POSES["wave_out"], POSES["look"]], fake.sent
|
||||||
|
|
||||||
# ---------- an unknown pose near a known one: a checked joint move to it, then on ----------
|
# ---------- an unknown pose near a known one: a checked joint move to it, then on ----------
|
||||||
near = [3.0, 2.0, -4.0, 5.0, 0.0, 0.0] # 5 deg from look (free drive)
|
near = [3.0, 2.0, -4.0, 5.0, 0.0, 0.0] # 5 deg from look (free drive)
|
||||||
@@ -113,7 +117,7 @@ for start in (POSES["look"], near, POSES["give"]):
|
|||||||
refused(arm_route.NEAR_HEAD, arm_route.goto, "give" if start != POSES["give"] else "look")
|
refused(arm_route.NEAR_HEAD, arm_route.goto, "give" if start != POSES["give"] else "look")
|
||||||
assert fake.sent == [], fake.sent
|
assert fake.sent == [], fake.sent
|
||||||
fake = use(POSES["look"])
|
fake = use(POSES["look"])
|
||||||
assert arm_route.goto("wave") == ["wave_start", "wave"] # another edge: clear of it
|
assert arm_route.goto("wave") == ["wave_out", "wave_start", "wave"] # other edges: clear of it
|
||||||
head["centre"] = None # the head not measured: nothing moves
|
head["centre"] = None # the head not measured: nothing moves
|
||||||
refused(arm_route.UNSURE, arm_route.goto, "look")
|
refused(arm_route.UNSURE, arm_route.goto, "look")
|
||||||
head["centre"] = FAR
|
head["centre"] = FAR
|
||||||
@@ -125,7 +129,7 @@ POSES["give"] = [40.0, 0, 0, 0, 0, 0]
|
|||||||
del POSES["wave_start"]
|
del POSES["wave_start"]
|
||||||
refused(arm_route.NOT_TAUGHT, arm_route.goto, "wave") # no way to wave without wave_start
|
refused(arm_route.NOT_TAUGHT, arm_route.goto, "wave") # no way to wave without wave_start
|
||||||
refused(arm_route.NOT_TAUGHT, arm_route.goto, "nowhere")
|
refused(arm_route.NOT_TAUGHT, arm_route.goto, "nowhere")
|
||||||
POSES["wave_start"] = [0.0, -20, 0, 0, 0, 0]
|
POSES["wave_start"] = [0.0, -20, 20, 0, 0, 0]
|
||||||
|
|
||||||
# ---------- Cobo π programs only from look; hand_shaking never ----------
|
# ---------- Cobo π programs only from look; hand_shaking never ----------
|
||||||
fake = use(POSES["carry"])
|
fake = use(POSES["carry"])
|
||||||
|
|||||||
+23
-10
@@ -16,7 +16,8 @@ from vision import head_cam
|
|||||||
fetch.STATE_FILE = Path(tempfile.mkdtemp()) / "lumi_task.json" # never the real /dev/shm file
|
fetch.STATE_FILE = Path(tempfile.mkdtemp()) / "lumi_task.json" # never the real /dev/shm file
|
||||||
lumi.BUSY_FILE = str(fetch.STATE_FILE.parent / "lumi_busy.json") # nor the real busy file
|
lumi.BUSY_FILE = str(fetch.STATE_FILE.parent / "lumi_busy.json") # nor the real busy file
|
||||||
LOOK = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
LOOK = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
||||||
POSES = {"look": LOOK, "wave_start": [-50.0, 0.0, 0.0, 0.0, 0.0, 0.0], "wave": [-50.0, 0.0, 60.0, 0.0, 30.0, 0.0]}
|
POSES = {"look": LOOK, "wave_out": [-50.0, 0.0, 0.0, 0.0, 0.0, 0.0], "wave_start": [-50.0, 0.0, 60.0, 0.0, 0.0, 0.0],
|
||||||
|
"wave": [-50.0, 0.0, 60.0, 0.0, 21.7, 0.0]}
|
||||||
HEAD = np.array([-100.0, -200.0, 700.0]) # mm, the head's turning centre in the toy arm
|
HEAD = np.array([-100.0, -200.0, 700.0]) # mm, the head's turning centre in the toy arm
|
||||||
motion.poses = lambda: dict(POSES)
|
motion.poses = lambda: dict(POSES)
|
||||||
head_cam.head_centre = lambda: HEAD
|
head_cam.head_centre = lambda: HEAD
|
||||||
@@ -67,27 +68,36 @@ def refused(reason):
|
|||||||
raise AssertionError(f"waved, expected {reason}")
|
raise AssertionError(f"waved, expected {reason}")
|
||||||
|
|
||||||
|
|
||||||
# ---------- from look: up along the graph, wave, and the arm stays up; every move clear of the head ----------
|
# ---------- from look: up through wave_out, 3 swings, the arm stays at wave_start; every move clear of the head ------
|
||||||
a = use(FakeArm(LOOK))
|
a = use(FakeArm(LOOK))
|
||||||
started = []
|
started = []
|
||||||
wave.wave(on_start=lambda: started.append(len(a.sent)))
|
wave.wave(on_start=lambda: started.append(len(a.sent)))
|
||||||
assert started == [0] # said before the first move
|
assert started == [0] # said before the first move
|
||||||
top = POSES["wave"]
|
top, swing = POSES["wave_start"], POSES["wave"]
|
||||||
up, down = top[:4] + [top[4] + wave.WAVE_DEG] + top[5:], top[:4] + [top[4] - wave.WAVE_DEG] + top[5:]
|
assert wave.SWINGS == 3
|
||||||
assert a.sent == [POSES["wave_start"], top] + [up, down] * wave.WAVE_SWINGS + [top], a.sent
|
assert a.sent == [POSES["wave_out"], top] + [swing, top] * 3, a.sent
|
||||||
for j0, j1 in zip([LOOK] + a.sent, 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(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 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()
|
a.sent.clear()
|
||||||
wave.wave() # asked again while up: only the swings
|
wave.wave() # asked again while up: only the swings
|
||||||
assert a.sent == [top] + [up, down] * wave.WAVE_SWINGS + [top], a.sent
|
assert a.sent == [swing, top] * 3, 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
|
||||||
|
a.j = list(top)
|
||||||
|
a.sent.clear()
|
||||||
|
assert arm_route.goto("look") == ["wave_out", "look"] # the way down
|
||||||
|
assert a.sent == [POSES["wave_out"], LOOK], a.sent
|
||||||
|
|
||||||
# ---------- a taught pose whose way passes the head: refused before anything moves ----------
|
# ---------- a taught pose whose way passes the head: refused before anything moves ----------
|
||||||
POSES["wave_start"] = [-15.0, 0.0, 40.0, 0.0, 0.0, 0.0]
|
POSES["wave_out"] = [-15.0, 0.0, 40.0, 0.0, 0.0, 0.0]
|
||||||
a = use(FakeArm(LOOK))
|
a = use(FakeArm(LOOK))
|
||||||
refused(wave.NEAR_HEAD)
|
refused(wave.NEAR_HEAD)
|
||||||
assert a.sent == []
|
assert a.sent == []
|
||||||
POSES["wave_start"] = [-50.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
POSES["wave_out"] = [-50.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
||||||
|
|
||||||
# ---------- holding something: refused (task state, or AI_1 when the camera can't tell) ----------
|
# ---------- holding something: refused (task state, or AI_1 when the camera can't tell) ----------
|
||||||
a = use(FakeArm(LOOK))
|
a = use(FakeArm(LOOK))
|
||||||
@@ -106,7 +116,7 @@ assert a.sent == []
|
|||||||
POSES["carry"] = [30.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
POSES["carry"] = [30.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
||||||
a = use(FakeArm(POSES["carry"]))
|
a = use(FakeArm(POSES["carry"]))
|
||||||
wave.wave()
|
wave.wave()
|
||||||
assert a.sent[:3] == [LOOK, POSES["wave_start"], top], a.sent
|
assert a.sent[:4] == [LOOK, POSES["wave_out"], top, swing], a.sent
|
||||||
del POSES["carry"]
|
del POSES["carry"]
|
||||||
|
|
||||||
# ---------- an unknown start (after free drive: the wrist the other way round), base, power ----------
|
# ---------- an unknown start (after free drive: the wrist the other way round), base, power ----------
|
||||||
@@ -123,7 +133,10 @@ refused(wave.BUSY)
|
|||||||
fetch.STATE_FILE.unlink()
|
fetch.STATE_FILE.unlink()
|
||||||
del POSES["wave"]
|
del POSES["wave"]
|
||||||
refused(wave.NOT_TAUGHT)
|
refused(wave.NOT_TAUGHT)
|
||||||
POSES["wave"] = top
|
POSES["wave"] = swing
|
||||||
|
del POSES["wave_out"]
|
||||||
|
refused(wave.NOT_TAUGHT)
|
||||||
|
POSES["wave_out"] = [-50.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
||||||
assert a.sent == []
|
assert a.sent == []
|
||||||
|
|
||||||
# ---------- the assistant: a greeting sends no arm command; a wave asked while holding is refused aloud ----------
|
# ---------- the assistant: a greeting sends no arm command; a wave asked while holding is refused aloud ----------
|
||||||
|
|||||||
Reference in New Issue
Block a user