Sheep training flock _ improver

This commit is contained in:
Johnny Fernandes
2026-04-24 22:46:51 +01:00
parent d599181d22
commit b3251fcca3
2 changed files with 24 additions and 33 deletions
+10 -12
View File
@@ -133,18 +133,16 @@ while robot.step(timestep) != -1:
fx, fy = 0.0, 0.0
# Outside the pen: repel from the exterior of the side and back walls so
# sheep don't get pinned against them when fleeing from the dog.
# The pen entrance is open on the north (y > PEN_Y_MAX), so only push away
# from the west (x≈PEN_X_MIN), east (x≈PEN_X_MAX), and south (y≈PEN_Y_MIN) exteriors.
PEN_EXT_MARGIN = 1.2
if not penned:
if PEN_Y_MIN - PEN_EXT_MARGIN < y < PEN_Y_MAX and x < PEN_X_MIN + PEN_EXT_MARGIN:
fx -= ((PEN_X_MIN + PEN_EXT_MARGIN - x) / PEN_EXT_MARGIN) * 8.0
if PEN_Y_MIN - PEN_EXT_MARGIN < y < PEN_Y_MAX and x > PEN_X_MAX - PEN_EXT_MARGIN:
fx += ((x - (PEN_X_MAX - PEN_EXT_MARGIN)) / PEN_EXT_MARGIN) * 8.0
if y < PEN_Y_MIN + PEN_EXT_MARGIN and PEN_X_MIN < x < PEN_X_MAX:
fy += ((PEN_Y_MIN + PEN_EXT_MARGIN - y) / PEN_EXT_MARGIN) * 8.0
# Repel unpenned sheep from the exterior of the pen's side walls so they
# don't get pinned by flee forces. Only fires when strictly outside the pen
# (x < PEN_X_MIN or x > PEN_X_MAX) at pen height (y in pen y-range).
# Entrance is open on the north (y > PEN_Y_MAX) — no force there.
PEN_EXT_MARGIN = 0.8
if not penned and PEN_Y_MIN < y < PEN_Y_MAX:
if PEN_X_MIN - PEN_EXT_MARGIN < x < PEN_X_MIN:
fx -= ((x - (PEN_X_MIN - PEN_EXT_MARGIN)) / PEN_EXT_MARGIN) * 6.0
if PEN_X_MAX < x < PEN_X_MAX + PEN_EXT_MARGIN:
fx += ((PEN_X_MAX + PEN_EXT_MARGIN - x) / PEN_EXT_MARGIN) * 6.0
if penned:
# Inside pen: wander freely, strong boundary forces prevent exit,