Sheep training flock of 10

This commit is contained in:
Johnny Fernandes
2026-04-23 19:22:39 +01:00
parent fdac0ae0b0
commit 81dc2aca01
3 changed files with 113 additions and 61 deletions
+9
View File
@@ -204,6 +204,15 @@ while robot.step(timestep) != -1:
fx += math.cos(wander_angle) * 0.5
fy += math.sin(wander_angle) * 0.5
# Hard-stop clamp: within 0.5 m of a wall, zero any force component that
# would push further into it. Prevents the flee force from pinning a sheep
# against the boundary when the dog approaches from outside.
HS = 0.5
if x < X_MIN + HS and fx < 0: fx = 0.0
if x > X_MAX - HS and fx > 0: fx = 0.0
if y < Y_MIN + HS and fy < 0: fy = 0.0
if y > Y_MAX - HS and fy > 0: fy = 0.0
heading = math.atan2(fy, fx)
mag = math.hypot(fx, fy)
speed = max(WANDER_SPEED, min(FLEE_SPEED, mag * 3.0))