Per-sheep pen-time metrics, seed support, make webots → menu

* `controllers/shepherd_dog/shepherd_dog.py`
  - Tracks the first step at which each sheep crosses the gate; on
    auto-finish (all sheep penned) prints a `[results]` summary
    block: mode/drive/world/lidar/dogs/seed line, total simulated
    time, per-sheep penning order with absolute step + seconds since
    sim start, and the gate spread between the first and last
    penning.
  - Reads `HERDING_SEED` (env / runtime cfg) and seeds the
    controller's RNG when set. Empty = time-based default = old
    non-deterministic behaviour.
* `controllers/sheep/sheep.py` reads `HERDING_SEED` the same way
  (loading `herding_runtime.cfg` itself so it works even when
  Webots strips env vars) and seeds Python's RNG XOR'd with the
  sheep's name hash, so a fixed seed gives a reproducible flock
  trajectory without all sheep starting from identical wander state.
* `tools/run_webots.sh` writes `HERDING_SEED` into the runtime cfg
  (empty when unset so existing scripts keep their stochastic
  behaviour).
* `tools/webots_menu.sh` gains a Seed prompt (random / fixed
  integer); the launch summary box shows the choice next to the
  perception row.
* `Makefile`
  - `make webots`  now fires the interactive picker (replacing the
    old positional invocation).
  - `make webots_quick MODE=… DRIVE=… WORLD=… N=…` is the old
    positional path, kept for batch / scripted use.

Smoke-tested: menu renders Mode → Drive → World → LiDAR → Dogs
→ Sheep → Perception → Seed → Headless prompts and shows the
selected Seed value in the launch summary. 126 pytest cases still
pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Johnny Fernandes
2026-05-17 10:33:34 +00:00
parent bdaff6a3e1
commit e86fee5ae8
5 changed files with 106 additions and 6 deletions
+1
View File
@@ -232,6 +232,7 @@ HERDING_LIDAR=$LIDAR_VARIANT
HERDING_NDOGS=$NDOGS
HERDING_AXIS_LEAK=${HERDING_AXIS_LEAK:-0.3}
HERDING_USE_GT=${HERDING_USE_GT:-0}
HERDING_SEED=${HERDING_SEED:-}
EOF
export HERDING_MODE="$MODE"
+13
View File
@@ -142,6 +142,17 @@ ask_choice "Perception" "lidar" \
if [[ "$CHOICE" == "gt" ]]; then USE_GT=1; else USE_GT=0; fi
echo
ask_choice "Seed" "random" \
"Random (different sheep wander each run):random" \
"Fixed seed (reproducible run — pick an integer):fixed"
if [[ "$CHOICE" == "fixed" ]]; then
ask_int " → Seed value" 0 0 1000000
SEED="$CHOICE"
else
SEED=""
fi
echo
ask_choice "Headless?" "no" \
"No — show the Webots window:no" \
"Yes — headless, fast simulation (xvfb-run):yes"
@@ -158,6 +169,7 @@ ${B}${C}── Launch configuration ──────────────
Dogs : ${B}$NDOGS${R}$( [[ "$NDOGS" == "2" ]] && echo " (axis_leak=${B}$AXIS_LEAK${R})" )
Sheep : ${B}$N_SHEEP${R}
Perception : ${B}$( [[ "$USE_GT" == "1" ]] && echo "GT bypass" || echo "LiDAR" )${R}
Seed : ${B}$( [[ -n "$SEED" ]] && echo "$SEED" || echo "random" )${R}
Headless : ${B}$HEADLESS${R}
${C}──────────────────────────────────────────────────────────────────${R}
@@ -173,6 +185,7 @@ export HERDING_LIDAR="$LIDAR"
export HERDING_NDOGS="$NDOGS"
export HERDING_USE_GT="$USE_GT"
[[ -n "${AXIS_LEAK:-}" ]] && export HERDING_AXIS_LEAK="$AXIS_LEAK"
[[ -n "$SEED" ]] && export HERDING_SEED="$SEED"
if [[ "$HEADLESS" == "yes" ]]; then
export WEBOTS_HEADLESS=1
export WEBOTS_EXTRA_ARGS="--stdout --stderr"