Follow: head tracks round to ±180 and the base turns after it; speed matches the walk; dashboard errors only in the bell

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 15:45:27 +09:00
co-authored by Claude Opus 5.5
parent e7a264012a
commit c4d9b07558
3 changed files with 63 additions and 17 deletions
+6 -16
View File
@@ -147,8 +147,6 @@ input[type=color]{width:30px;height:28px;border:1px solid var(--line);border-rad
.mapitem span{flex:1} .mapitem span{flex:1}
.log{background:#04060a;border:1px solid var(--line);border-radius:9px;padding:9px 11px;height:calc(100vh - 430px);min-height:220px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:#b7c3d0;white-space:pre-wrap} .log{background:#04060a;border:1px solid var(--line);border-radius:9px;padding:9px 11px;height:calc(100vh - 430px);min-height:220px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:#b7c3d0;white-space:pre-wrap}
.note{font-size:12px;color:var(--muted);margin-top:6px} .note{font-size:12px;color:var(--muted);margin-top:6px}
#toast{position:fixed;left:50%;transform:translateX(-50%);bottom:16px;z-index:60;max-width:min(460px,calc(100vw - 32px));background:var(--panel2);border:1px solid var(--line);border-left:4px solid var(--bad);border-radius:10px;padding:9px 14px;box-shadow:0 8px 24px rgba(0,0,0,.45);display:none}
#toast.on{display:block;animation:in .2s}
@keyframes in{from{transform:translateY(8px);opacity:0}} @keyframes in{from{transform:translateY(8px);opacity:0}}
/* command dialog */ /* command dialog */
.modal{position:fixed;inset:0;z-index:45;background:rgba(0,0,0,.55);display:none;place-items:center;padding:16px} .modal{position:fixed;inset:0;z-index:45;background:rgba(0,0,0,.55);display:none;place-items:center;padding:16px}
@@ -350,20 +348,12 @@ input[type=color]{width:30px;height:28px;border:1px solid var(--line);border-rad
</div> </div>
</div> </div>
</div> </div>
<div id="toast"></div>
<script> <script>
const $ = id => document.getElementById(id); const $ = id => document.getElementById(id);
let status = null, mapInfo = null; let status = null, mapInfo = null;
const MAP_POLL_MS = 20000; // the marker list is read again this often const MAP_POLL_MS = 20000; // the marker list is read again this often
const TOAST_MS = 4000; // an error stays on screen this long
let toastTimer = 0;
function toast(msg) { // errors and refusals only; a new one replaces the old
note(msg);
const t = $("toast"); t.textContent = msg; t.classList.add("on");
clearTimeout(toastTimer); toastTimer = setTimeout(() => t.classList.remove("on"), TOAST_MS);
}
async function api(path, body) { async function api(path, body) {
const r = await fetch(path, {method: body === undefined ? "GET" : "POST", headers: {"Content-Type": "application/json"}, const r = await fetch(path, {method: body === undefined ? "GET" : "POST", headers: {"Content-Type": "application/json"},
body: body === undefined ? undefined : JSON.stringify(body)}); body: body === undefined ? undefined : JSON.stringify(body)});
@@ -373,7 +363,7 @@ async function api(path, body) {
} }
async function act(btn, fn) { async function act(btn, fn) {
const old = btn && btn.innerHTML; if (btn) { btn.disabled = true; btn.textContent = "…"; } const old = btn && btn.innerHTML; if (btn) { btn.disabled = true; btn.textContent = "…"; }
try { return await fn(); } catch (e) { toast(e.message); } try { return await fn(); } catch (e) { note(e.message); }
finally { if (btn) { btn.disabled = false; btn.innerHTML = old; } refreshStatus(); } finally { if (btn) { btn.disabled = false; btn.innerHTML = old; } refreshStatus(); }
} }
const fmt = (v, d = 0) => v === undefined || v === null ? "–" : (+v).toFixed(d); const fmt = (v, d = 0) => v === undefined || v === null ? "–" : (+v).toFixed(d);
@@ -518,8 +508,8 @@ function holdStart(btn) {
holdStop(true); holdStop(true);
const axis = btn.dataset.axis, dir = +btn.dataset.dir; const axis = btn.dataset.axis, dir = +btn.dataset.dir;
btn.classList.add("on"); btn.classList.add("on");
const send = () => api("/jog", {axis, direction: dir, speed: speedOf(axis)}).then(r => { if (r.error) toast(r.error); }) const send = () => api("/jog", {axis, direction: dir, speed: speedOf(axis)}).then(r => { if (r.error) note(r.error); })
.catch(e => { toast(e.message); holdStop(); }); .catch(e => { note(e.message); holdStop(); });
send(); holding = {btn, timer: setInterval(send, 150)}; send(); holding = {btn, timer: setInterval(send, 150)};
} }
function holdStop(silent) { function holdStop(silent) {
@@ -735,7 +725,7 @@ const destDD = Dropdown($("destDD"), "Choose one or more places…");
function selectDest(name) { destDD.set(name); } function selectDest(name) { destDD.set(name); }
$("goBtn").onclick = e => { $("goBtn").onclick = e => {
const stops = destDD.values, name = n => n === "home" ? "the dock" : n; const stops = destDD.values, name = n => n === "home" ? "the dock" : n;
if (!stops.length) return toast("Choose a place first"); if (!stops.length) return note("Choose a place first");
if (stops.length === 1) return act(e.target, () => api("/agv/go", {marker: stops[0]})); if (stops.length === 1) return act(e.target, () => api("/agv/go", {marker: stops[0]}));
act(e.target, () => api("/agv/route", {markers: stops, pause: +$("pause").value || 0})); act(e.target, () => api("/agv/route", {markers: stops, pause: +$("pause").value || 0}));
}; };
@@ -764,7 +754,7 @@ $("askBtn").onclick = async e => {
$("askText").onkeydown = e => { if (e.key === "Enter") $("askBtn").click(); }; $("askText").onkeydown = e => { if (e.key === "Enter") $("askBtn").click(); };
api("/volume").then(v => { $("vol").value = v.percent; $("volV").textContent = v.percent + " %"; }); api("/volume").then(v => { $("vol").value = v.percent; $("volV").textContent = v.percent + " %"; });
$("vol").oninput = e => $("volV").textContent = e.target.value + " %"; $("vol").oninput = e => $("volV").textContent = e.target.value + " %";
$("vol").onchange = e => api("/volume", {percent: +e.target.value}).catch(x => toast(x.message)); $("vol").onchange = e => api("/volume", {percent: +e.target.value}).catch(x => note(x.message));
/* assistant modes: greeter (standing) and patrol (driving) */ /* assistant modes: greeter (standing) and patrol (driving) */
let modes = {}; let modes = {};
function paintModes(m) { function paintModes(m) {
@@ -778,7 +768,7 @@ function paintModes(m) {
async function setModes(part, el) { async function setModes(part, el) {
if (el) el.classList.add("busy"); if (el) el.classList.add("busy");
try { paintModes(await api("/assistant/modes", part)); } try { paintModes(await api("/assistant/modes", part)); }
catch (e) { toast(e.message); } catch (e) { note(e.message); }
finally { if (el) el.classList.remove("busy"); } finally { if (el) el.classList.remove("busy"); }
} }
document.querySelectorAll(".mode").forEach(el => el.onclick = () => { document.querySelectorAll(".mode").forEach(el => el.onclick = () => {
+6 -1
View File
@@ -53,7 +53,7 @@ BASE_CLEAR_M = fetch.BASE_HALF_M + fetch.CLEAR_M # m; base centre kept this fa
TICK_S = 0.1 # s between commands, steady (joy_control wants > 2 Hz; a tick takes ~10-30 ms) TICK_S = 0.1 # s between commands, steady (joy_control wants > 2 Hz; a tick takes ~10-30 ms)
LOG_S = 1.0 # s between "follow: v ... " lines (what the next live run is read from) LOG_S = 1.0 # s between "follow: v ... " lines (what the next live run is read from)
JOIN_S = 2.0 # s a new "follow me" waits for the old loop to end JOIN_S = 2.0 # s a new "follow me" waits for the old loop to end
HEAD_YAW_MAX = 120.0 # deg; the head turns toward the person up to this far (+ left; body API allows 180) HEAD_YAW_MAX = 180.0 # deg; the head turns toward the person up to this far (+ left; body API range, head.AXIS_LIMITS)
HEAD_PITCH = 10.0 # deg; head pitch while following, a little up toward a standing person (as "look at me") HEAD_PITCH = 10.0 # deg; head pitch while following, a little up toward a standing person (as "look at me")
HEAD_STEP_DEG = 3.0 # deg; a new head move only when the target is this far from where the head was sent HEAD_STEP_DEG = 3.0 # deg; a new head move only when the target is this far from where the head was sent
HEAD_LEAD_S = 0.3 # s; the head is sent where the person will be this much later (a moveto takes time) HEAD_LEAD_S = 0.3 # s; the head is sent where the person will be this much later (a moveto takes time)
@@ -292,8 +292,13 @@ def _run(see, say, people):
if person.p is None: # not seen yet (only before the first sighting) if person.p is None: # not seen yet (only before the first sighting)
cmd, d, a, walk = (0.0, 0.0), 0.0, 0.0, 0.0 cmd, d, a, walk = (0.0, 0.0), 0.0, 0.0, 0.0
else: else:
# angles taken on from the head's last target, not -180..180: right behind, +179 and -179 are
# the same place, the head must not swing round and the base not turn the other way
ref = target[0][0] if target[0] else 0.0
d, a = _rel(pose, person.at(now)) d, a = _rel(pose, person.at(now))
a = ref + (a - ref + 180.0) % 360.0 - 180.0
yaw = _rel(pose, person.at(now + HEAD_LEAD_S))[1] yaw = _rel(pose, person.at(now + HEAD_LEAD_S))[1]
yaw = ref + (yaw - ref + 180.0) % 360.0 - 180.0
target[0] = (max(-HEAD_YAW_MAX, min(HEAD_YAW_MAX, yaw)), HEAD_PITCH) target[0] = (max(-HEAD_YAW_MAX, min(HEAD_YAW_MAX, yaw)), HEAD_PITCH)
walk = float(person.vel @ np.array([math.cos(pose[2]), math.sin(pose[2])])) walk = float(person.vel @ np.array([math.cos(pose[2]), math.sin(pose[2])]))
cmd = speeds(d, a, v, w, walk, go=now - person.t <= COAST_S, dt=TICK_S) cmd = speeds(d, a, v, w, walk, go=now - person.t <= COAST_S, dt=TICK_S)
+51
View File
@@ -460,6 +460,57 @@ assert follow._pick(gone, None, lambda: cand, p, (0.0, 0.0, 0.0), list(blue), ti
assert follow._pick(gone, None, lambda: cand, p, (0.0, 0.0, 0.0), None, time.time())[1] is not None assert follow._pick(gone, None, lambda: cand, p, (0.0, 0.0, 0.0), None, time.time())[1] is not None
print("re-lock by clothes: ok") print("re-lock by clothes: ok")
# walks slowly (0.2 m/s): the base goes as slowly, ~1 m behind, no stop-and-go
said.clear()
w = World(person=(1.5, 0.0), walk=(0.2, 0.0), walk_s=10.0)
follow.start(w.see, say)
time.sleep(8.0)
assert follow.running() and not said, said
follow.stop()
assert wait_end(0.5)
vs, jump = steady(w.cmds, 4.0, 7.8)
assert 0.12 < min(vs) and max(vs) < 0.3 and jump <= step, (min(vs), max(vs), jump)
assert abs(w.dist[-1] - follow.FOLLOW_GAP_M) < 0.25, w.dist[-1]
print(f"slow walk: {min(vs):.2f}-{max(vs):.2f} m/s, gap {w.dist[-1]:.2f} m")
# walks past the robot's side to behind it (1.2 m/s, 1.0 m to the left), head camera only: the head stays on them
# past 90 deg, the base turns on the spot toward them (sweep checked) and follows again; never "lost"
said.clear()
body.moves.clear()
turn_max, follow.TURN_MAX_RS = follow.TURN_MAX_RS, 0.25 # a base slower than the head
w = World(path=lambda t: (2.0 - 1.4 * min(t, 3.0), 1.0), fov=True)
follow.start(w.see, say)
time.sleep(14.0)
follow.TURN_MAX_RS = turn_max
assert follow.running() and not said, said
follow.stop()
assert wait_end(0.5)
yaws = [m[4] for m in body.moves if m[1] == "follow head"]
assert max(yaws) > 90.0 and all(abs(y) <= 180.0 for y in yaws), yaws # past the side
assert all(abs(b - a) < 90.0 for a, b in zip(yaws, yaws[1:])), yaws # never swung round
assert math.degrees(w.th) > 120.0 and w.dist[-1] < follow.FOLLOW_GAP_M + 0.4, (math.degrees(w.th), w.dist[-1])
print(f"past the side to behind: head up to {max(yaws):.0f} deg, base turned {math.degrees(w.th):.0f} deg, "
f"gap {w.dist[-1]:.2f} m")
# right behind: the angle flips between +179 and -179; the head and the base keep one side
said.clear()
body.moves.clear()
flip = [0]
def behind():
flip[0] += 1
return 2.0, 179.0 if flip[0] % 2 else -179.0, 0.0, None
follow.start(behind, say)
time.sleep(0.6)
follow.stop()
assert wait_end(0.5)
yaws = [m[4] for m in body.moves if m[1] == "follow head"]
assert yaws and all(y > 0 for y in yaws[1:]), yaws
print("right behind: one side")
# lumi: act("stop") ends following; follow_me locks onto the person talking, refuses when it must # lumi: act("stop") ends following; follow_me locks onto the person talking, refuses when it must
lumi.agv.cancel = lumi.skills.cancel = lumi.arm.stop = lambda: None lumi.agv.cancel = lumi.skills.cancel = lumi.arm.stop = lambda: None
w = World(person=(3.0, 0.0)) w = World(person=(3.0, 0.0))