Follow keeps up at walking pace (0.5 m/s, slow near the person, faster when the gap grows); short moves end a running follow, drive without pauses and say honestly when the wheels did not move; a STOP ends a waiting body move at once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 16:02:27 +09:00
co-authored by Claude Opus 5.5
parent 5c3c6c72bf
commit 41f7bd5aca
6 changed files with 235 additions and 43 deletions
+74 -3
View File
@@ -1,6 +1,7 @@
"""Self-check of distances and speed by voice (assistant/driving.py, brain.intent's moves, fetch's straight move and
speed) with a fake base, no robot: python tests/test_driving.py"""
import tempfile
import threading
import time
from pathlib import Path
@@ -118,13 +119,33 @@ assert driving.say_speed(1, 1.2, True) == "Okay, a bit faster: 120 percent of my
assert driving.say_speed(1, fetch.SPEED_MAX, False) == "I'm already at my top speed."
# ---------- a 1 cm move is driven, and the last joy_control command lasts only the time left ----------
pose = [0.0, 0.0, 0.0]
fetch.agv.pose = lambda: tuple(pose)
# a fake base (heading 0): its x follows the joy_control speed, each command for JOY_HOLD_S; no wheels: it stays
base = {"x": 0.0, "v": 0.0, "t": time.time(), "wheels": True}
def roll():
now = time.time()
dt, base["t"] = now - base["t"], now
if base["wheels"]:
base["x"] += base["v"] * min(dt, fetch.JOY_HOLD_S)
if dt > fetch.JOY_HOLD_S:
base["v"] = 0.0
def joy_request(cmd, timeout=3.0):
if "joy_control" in cmd:
roll()
base["v"] = float(cmd.split("linear_velocity=")[1].split("&")[0])
joy.append((time.time(), cmd))
return {}
fetch.agv.pose = lambda: (roll(), (base["x"], 0.0, 0.0))[1]
fetch.agv.clearance = lambda x, y: 5.0
fetch._waist_front = lambda: None
real_moved, skills.moved = skills.moved, lambda after=0.0: None
joy = []
fetch.agv.request = lambda cmd, timeout=3.0: joy.append((time.time(), cmd)) or {}
fetch.agv.request = joy_request
for dist in (0.01, 0.03, 0.07, 0.37):
joy.clear()
t0 = time.time()
@@ -150,7 +171,57 @@ for m, v in ((0.01, "-0.050"), (0.3, "-0.120")):
vel = {c.split("linear_velocity=")[1].split("&")[0] for _, c in joy} - {"0"}
assert vel == {v}, (m, vel)
fetch.speed_factor = 1.0
# _move rolls on between its pieces (no stop-and-go), the time spent checking counted as driven: 0.8 m is 0.8 m
STOP = "linear_velocity=0&angular_velocity=0"
fetch.MOVE_SPEED = 0.5
real_line_hits = fetch.line_hits
fetch.line_hits = lambda d: time.sleep(0.15) # a slow check of the arm's way
joy.clear()
x0 = base["x"]
fetch._move("back", 0.8, holding=False)
time.sleep(fetch.JOY_HOLD_S + 0.05)
roll()
stops = [k for k, (_, c) in enumerate(joy) if c.endswith(STOP)]
assert stops == [len(joy) - 1], stops # one stop: at the end
assert abs((x0 - base["x"]) - 0.8) < 0.03, x0 - base["x"]
assert fetch._rolling["v"] == 0.0
# the base does not follow the commands (2026-10-23: a follow loop sent its own): said, stopped, never "done"
base["wheels"] = False
joy.clear()
try:
fetch._move("back", 1.0, holding=False)
raise AssertionError("a move the base did not drive ended as done")
except fetch.FetchError as e:
assert "did not move" in e.args[0] and "0.00 m of 1" in e.args[0], e.args
assert joy[-1][1].endswith(STOP) and fetch._rolling["v"] == 0.0, joy[-3:]
base["wheels"] = True
# something steps into the way after the first piece: stops at once (also while rolling), says how far it got
clear_at = {"x": base["x"] - 0.3}
fetch.agv.clearance = lambda x, y: 5.0 if x > clear_at["x"] else 0.1
joy.clear()
try:
fetch._move("back", 1.0, holding=False)
raise AssertionError("drove into an obstacle")
except fetch.FetchError as e:
assert "in my way" in e.args[0], e.args
time.sleep(fetch.JOY_HOLD_S + 0.05)
assert base["x"] > clear_at["x"] and joy[-1][1].endswith(STOP), (base, clear_at) # stopped before it
fetch.agv.clearance = lambda x, y: 5.0
fetch.line_hits = real_line_hits
fetch.agv.request, skills.moved = real_request, real_moved
# a task (a move by voice) ends a follow that runs first: two joy_control senders must never fight
from tasks import follow
follow._stop.clear()
follow._thread = threading.Thread(target=follow._stop.wait, daemon=True)
follow._thread.start()
follow._joy = lambda v, w: None
fetch._launch(lambda: None)
assert not follow.running() and follow._stop.is_set()
fetch._thread.join(1.0)
# "again" / "a bit more" right after a turn (2026-10-21)
_turn = driving.last_command([("turn left", "ACTION: turn left 90")])
assert _turn == ("turn", "left 90"), _turn
+3
View File
@@ -135,6 +135,7 @@ fetch.agv.request = lambda cmd, **kw: (calls.append(("joy", cmd.split("linear_ve
room = {"clear": lambda x, y: 1.0, "probe": lambda x, y: (float("inf"), float("inf"))}
fetch.agv.probe = lambda x, y: room["probe"](x, y)
fetch.AXIS_SPEED, fetch.COAST_S = 100.0, 0.0
fetch.MOVED_CHECK_M = float("inf") # this fake base never moves its pose (the check: test_driving.py)
arm = {"j": [5.0] * 6} # the fake arm's joints: away from every pose
fetch.motion.go = lambda name, *a, **k: (calls.append(("pose", name)), arm.update(j=list(fetch.motion.poses()[name])))
fetch.motion.stop = lambda: calls.append(("arm stop",))
@@ -1000,7 +1001,9 @@ for bad in ([P(do="give")], [P(do="place", on=None)], [P(do="go", to="p9")], [P(
assert not any(c[0] in ("go", "go_point", "joy", "pose") for c in calls), calls
# a move is driven in pieces, each checked again; back on the charger is refused
reset()
hold, fetch.JOY_HOLD_S = fetch.JOY_HOLD_S, 0.0005 # at this fake 100 m/s a real hold would roll the whole way
st = run(fetch.run_steps, [P(do="move", dir="forward", m=0.6)], say)
fetch.JOY_HOLD_S = hold
assert st["status"] == "done" and [c for c in calls if c[0] == "joy"].count(("joy", "100.000")) == 3, calls # 0.25+0.25+0.1
fetch.agv.status = lambda: {"move_status": "succeeded", "charge_state": True}
st = run(fetch.run_steps, [P(do="move", dir="back", m=0.5)], say)
+37
View File
@@ -592,4 +592,41 @@ L.follow_me = lambda: called.append(1)
L.mission_running = lambda: False
L.brain, L.markers = types.SimpleNamespace(history=[]), M
assert L.quick_command("follow me") and called
# the speed law (live 2026-10-23: capped at 0.3 m/s the base fell 4 m behind a person walking 0.6-0.75 m/s)
def settle(d, walk, v=0.0, n=60):
for _ in range(n):
v = follow.speeds(d, 0.0, v, 0.0, walk, dt=0.1)[0]
return v
assert follow.FOLLOW_MAX_MS == 0.5 # joy_control's own clamp (docs/05)
assert settle(1.8, 0.7) == follow.FOLLOW_MAX_MS # far behind a walker: full speed
assert abs(settle(1.5, 0.0) - 0.4) < 1e-6 # standing 0.5 m beyond the gap: gentle
assert settle(1.1, 0.0) < 0.1 and settle(1.0, 0.5) == 0.0 # near the gap: slow; at it: none
assert settle(1.3, -0.4, v=0.4) == 0.0 # coming back toward the base: slows
vs = [settle(1.0 + r, 0.3) for r in (0.1, 0.3, 0.6, 1.0)]
assert vs == sorted(vs) and vs[-1] == follow.FOLLOW_MAX_MS, vs # faster the further behind
v, prev = 0.0, [] # speeds up and eases back gradually
for d in [3.0] * 20 + [1.2] * 20:
prev.append(v)
v = follow.speeds(d, 0.0, v, 0.0, 0.0, dt=0.1)[0]
steps = [b - a for a, b in zip(prev, prev[1:])]
assert max(steps) <= follow.ACCEL_MS2 * 0.1 + 1e-9 and min(steps) >= -follow.DECEL_MS2 * 0.1 - 1e-9, steps
# never into the person: they walk at 0.5 m/s and stop dead; the base sees them REACT_S late (walking estimate
# filtered as Person does) and must still stand before NEAR_STOP_M
gap, v, walk, t, seen = follow.FOLLOW_GAP_M + 0.1, 0.0, 0.0, 0.0, []
for k in range(300): # 0.1 s ticks
t = k * 0.1
pw = 0.5 if t < 15.0 else 0.0
seen.append((gap, pw))
lag = seen[max(0, len(seen) - 1 - round(follow.REACT_S / 0.1))]
walk += (lag[1] - walk) * 0.1 / (follow.VEL_TAU_S + 0.1)
v = follow.speeds(lag[0], 0.0, v, 0.0, walk, dt=0.1)[0]
gap += (pw - v) * 0.1
assert gap > follow.NEAR_STOP_M, (t, gap, v)
if 10.0 < t < 15.0:
assert v > 0.45, (t, v) # keeps up with a 0.5 m/s walk
assert v == 0.0 and gap < follow.FOLLOW_GAP_M + 0.2, (v, gap)
print("all follow checks passed")