Portable Python env + 360° LiDAR ablation flag
Two small features.
(1) Portable interpreter
* `tools/setup_env.sh` exports HERDING_PYTHON (default points to the
project's conda env; override in your shell to retarget).
* Both `controllers/*/runtime.ini` files now use Webots' env-var
expansion: `COMMAND = $(HERDING_PYTHON)` so the Webots-launched
controllers pick up the same interpreter as the bash scripts.
* `tools/run_webots.sh`, `tools/webots_sweep{,_gt}.sh` and
`tools/calibrate_mecanum.sh` all source `setup_env.sh` at the top
instead of hard-coding `/home/jalf/miniconda3/envs/tir/bin`.
The hard-coded conda path is now exactly one line in `setup_env.sh`'s
fallback default — a single place to edit on a new machine, or
override-once via `export HERDING_PYTHON=...`.
(2) 360° LiDAR FOV ablation
* New `LIDAR_WEBOTS_360` preset matches the existing
`protos/ShepherdDog360.proto` (360 rays / 2π FOV / 15 m range).
* `tools/run_webots.sh` reads `HERDING_LIDAR=140|360` and swaps the
diff-drive proto accordingly (mecanum keeps 140° — the
ShepherdDogMecanum proto has its own LiDAR section). The variant
is written into `herding_runtime.cfg` so the controller can read
it even when Webots strips env vars.
* `controllers/shepherd_dog/shepherd_dog.py` picks the matching
`lidar_cfg` (`HERDING_WEBOTS.lidar` for 140°, `LIDAR_WEBOTS_360`
otherwise) and feeds it to `detections_from_scan` so the
perception pipeline interprets ray angles + max range correctly.
Smoke test: `HERDING_LIDAR=360 tools/run_webots.sh 5 strombom
differential field` launches with `ShepherdDog360.proto`, the
controller logs the new mode/drive/world line, and the dog is
penning sheep through 360° perception (4/5 at step 19200 before I
killed the test). No retraining required because the gym already
trains under `LIDAR_FULL` (360° preset).
126 pytest cases still pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+30
-3
@@ -33,6 +33,12 @@
|
||||
# WEBOTS_EXTRA_ARGS="--stdout --stderr" WEBOTS_HEADLESS=1 tools/run_webots.sh 10 rl
|
||||
|
||||
set -e
|
||||
|
||||
# Make sure HERDING_PYTHON is resolved and on PATH so Webots inherits
|
||||
# the right interpreter (controllers/{shepherd_dog,sheep}/runtime.ini
|
||||
# both read $HERDING_PYTHON via env-var expansion).
|
||||
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/setup_env.sh"
|
||||
|
||||
N=${1:-10}
|
||||
MODE=${2:-bc}
|
||||
DRIVE=${3:-differential}
|
||||
@@ -84,12 +90,31 @@ fi
|
||||
|
||||
cp "$SRC" "$DST"
|
||||
|
||||
# Swap robot proto based on drive mode.
|
||||
# Base worlds reference ShepherdDog (diff-drive). For mecanum we swap in
|
||||
# ShepherdDogMecanum and inject mecanum contact properties.
|
||||
# LiDAR FOV variant: HERDING_LIDAR=140 (default) or 360 (ablation).
|
||||
# 360° is only supported for differential drive; the mecanum proto
|
||||
# always uses the 140° sensor matching ShepherdDog.proto.
|
||||
LIDAR_VARIANT="${HERDING_LIDAR:-140}"
|
||||
if [[ "$LIDAR_VARIANT" != "140" && "$LIDAR_VARIANT" != "360" ]]; then
|
||||
echo "HERDING_LIDAR must be 140 or 360, got '$LIDAR_VARIANT'" >&2; exit 1
|
||||
fi
|
||||
if [[ "$LIDAR_VARIANT" == "360" && "$DRIVE" == "mecanum" ]]; then
|
||||
echo "[run_webots] HERDING_LIDAR=360 not available for mecanum drive — falling back to 140." >&2
|
||||
LIDAR_VARIANT="140"
|
||||
fi
|
||||
export HERDING_LIDAR="$LIDAR_VARIANT"
|
||||
|
||||
# Swap robot proto based on drive mode + LiDAR variant.
|
||||
# Base worlds reference ShepherdDog (diff-drive 140°). For mecanum we
|
||||
# swap in ShepherdDogMecanum; for the 360° ablation we swap in
|
||||
# ShepherdDog360.
|
||||
if [[ "$DRIVE" == "mecanum" ]]; then
|
||||
sed -i 's|"../protos/ShepherdDog.proto"|"../protos/ShepherdDogMecanum.proto"|' "$DST"
|
||||
sed -i 's|^ShepherdDog {|ShepherdDogMecanum {|' "$DST"
|
||||
elif [[ "$LIDAR_VARIANT" == "360" ]]; then
|
||||
sed -i 's|"../protos/ShepherdDog.proto"|"../protos/ShepherdDog360.proto"|' "$DST"
|
||||
sed -i 's|^ShepherdDog {|ShepherdDog360 {|' "$DST"
|
||||
fi
|
||||
if [[ "$DRIVE" == "mecanum" ]]; then
|
||||
# Inject mecanum roller contact properties. The proto's rollers are
|
||||
# split into two contact materials so that we can keep the friction
|
||||
# axes oriented along each roller's free-spin direction — but with
|
||||
@@ -152,6 +177,7 @@ HERDING_MODE=$MODE
|
||||
HERDING_POLICY_DIR=$RESOLVED_POLICY_DIR
|
||||
HERDING_DRIVE=$DRIVE
|
||||
HERDING_WORLD=$WORLD
|
||||
HERDING_LIDAR=$LIDAR_VARIANT
|
||||
HERDING_USE_GT=${HERDING_USE_GT:-0}
|
||||
EOF
|
||||
|
||||
@@ -159,6 +185,7 @@ export HERDING_MODE="$MODE"
|
||||
export HERDING_POLICY_DIR="$RESOLVED_POLICY_DIR"
|
||||
export HERDING_DRIVE="$DRIVE"
|
||||
export HERDING_WORLD="$WORLD"
|
||||
export HERDING_LIDAR="$LIDAR_VARIANT"
|
||||
|
||||
# The controller writes this sentinel when all GT sheep are penned. We
|
||||
# poll for it and kill Webots so the run finishes cleanly instead of
|
||||
|
||||
Reference in New Issue
Block a user