a584a034e9
Repo hygiene pass after a long working session.
Files removed:
* stage1_train.log — runtime training log (~125 KB), shouldn't have
been tracked.
* training/bc/demos.npz — orphan default-name demos file from before
the world+drive-suffixed naming convention took over; no script
references it.
* training/runs/bc_dagger{1,2}_differential_field/policy.zip — failed
DAgger experiment artifacts. Per `memory/dagger_results.md` the
whole DAgger experiment hit 0/5 on Webots transfer; these checkpoints
have no consumers.
Untracked-but-deleted (no git change) — also cleaned from disk:
* Root-level runtime logs (43 *.log files, all unused — gitignored now).
* training/bc/{combined,dagger}*.npz (5 huge demo blobs, 2.6 GB
reclaimed; not committed).
* training/bc/v1/ (2.6 GB backup of pre-DAgger demos; reclaimed).
* training/runs/at_20260426_*/ (orphan timestamped runs; reclaimed).
* All __pycache__/.
Dead code removed:
* `herding/control/strombom.py::compute_action_debug` — no callers
anywhere in the repo.
* `herding/control/sequential.py::compute_action_debug` — same.
* `herding/control/universal.py::compute_action_diff` — same.
.gitignore extended to cover:
* All *.log files (training/eval/webots logs are runtime artifacts).
* training/bc/*.npz (re-collectable on demand by `make bc_demos`).
* training/bc/v1/.
* .pytest_cache, *.pyc, .claude/.
README refreshed:
* Mecanum + round-world coverage in the headline.
* Quick-start updated for DRIVE/WORLD-suffixed Makefile targets,
GT-bypass example, and the mecanum-retrain caveat.
* Layout reflects the actual current tree (config.py, both protos,
both worlds, all tools).
* Results table replaced with the Webots end-to-end numbers from
the 2026-05-16 sweep (8/8 diff combos + LiDAR/GT comparison).
Verification: 126 pytest cases still pass (was 126 going in — no
test-coverage regression from the dead-code removal).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""Strömbom (2014) collect/drive heuristic for the shepherd dog.
|
|
|
|
When the flock is scattered (max radius > F_FACTOR · √n) the dog moves
|
|
to a point behind the furthest sheep and pushes it back toward the
|
|
flock CoM. Otherwise it drives, parking behind the CoM relative to
|
|
the pen target. Returns a unit-vector intent ``(vx, vy, mode)``.
|
|
|
|
Reference: Strömbom et al. 2014, "Solving the shepherding problem."
|
|
"""
|
|
|
|
import math
|
|
|
|
from herding.world.geometry import (
|
|
FIELD_ROUND_R, FIELD_SHAPE,
|
|
PEN_ENTRY, GATE_Y, in_pen,
|
|
)
|
|
|
|
F_FACTOR = 4.0 # collect/drive threshold scaled by √n
|
|
DELTA_COLLECT = 1.5 # drive-position offset behind the furthest sheep
|
|
DELTA_DRIVE = 2.0 # drive-position offset behind the flock CoM
|
|
|
|
|
|
def _unit(x, y):
|
|
d = math.hypot(x, y)
|
|
if d < 1e-6:
|
|
return 0.0, 0.0
|
|
return x / d, y / d
|
|
|
|
|
|
def _is_active(x, y) -> bool:
|
|
"""A sheep still in the field counts; one south of the gate doesn't."""
|
|
return (not in_pen(x, y)) and y > GATE_Y
|
|
|
|
|
|
def compute_action(dog_xy, sheep_positions, pen_target=PEN_ENTRY):
|
|
"""Return ``(vx, vy, mode)`` — mode in {idle, collect, drive}."""
|
|
active = [(x, y) for (x, y) in sheep_positions.values() if _is_active(x, y)]
|
|
if not active:
|
|
return 0.0, 0.0, "idle"
|
|
|
|
n = len(active)
|
|
com_x = sum(p[0] for p in active) / n
|
|
com_y = sum(p[1] for p in active) / n
|
|
dists = [math.hypot(p[0] - com_x, p[1] - com_y) for p in active]
|
|
radius = max(dists)
|
|
|
|
if radius > F_FACTOR * math.sqrt(n):
|
|
# Collect: aim behind the furthest sheep, opposite the CoM.
|
|
idx = max(range(n), key=lambda i: dists[i])
|
|
sx, sy = active[idx]
|
|
ux, uy = _unit(sx - com_x, sy - com_y)
|
|
tx, ty = sx + DELTA_COLLECT * ux, sy + DELTA_COLLECT * uy
|
|
mode = "collect"
|
|
else:
|
|
# Drive: aim behind the CoM, opposite the pen.
|
|
ux, uy = _unit(com_x - pen_target[0], com_y - pen_target[1])
|
|
tx, ty = com_x + DELTA_DRIVE * ux, com_y + DELTA_DRIVE * uy
|
|
mode = "drive"
|
|
|
|
# Round-field wall fallback: if the drive target lies outside the
|
|
# curved boundary, push the flock radially inward first so it
|
|
# leaves the wall — otherwise the dog ends up tangent to the wall
|
|
# and the flock circles indefinitely.
|
|
if FIELD_SHAPE == "field_round" and mode == "drive":
|
|
if math.hypot(tx, ty) > FIELD_ROUND_R - 1.0:
|
|
r_com = math.hypot(com_x, com_y)
|
|
if r_com > 1e-3:
|
|
ux2, uy2 = com_x / r_com, com_y / r_com
|
|
tx = com_x + DELTA_DRIVE * ux2
|
|
ty = com_y + DELTA_DRIVE * uy2
|
|
r_t = math.hypot(tx, ty)
|
|
if r_t > FIELD_ROUND_R - 1.0:
|
|
scale = (FIELD_ROUND_R - 1.0) / r_t
|
|
tx *= scale
|
|
ty *= scale
|
|
|
|
ax, ay = _unit(tx - dog_xy[0], ty - dog_xy[1])
|
|
return ax, ay, mode
|