Skip to content

Commit 8736119

Browse files
committed
Use lastRealisticBallPos when checking for out of field violations
This is hopefully a bit more stable against people making their hand visible at the edge of the field.
1 parent bfaf503 commit 8736119

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

autoref/rules/outoffield.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local Referee = require "base/referee"
2626
local debug = require "base/debug"
2727
local vis = require "base/vis"
2828
local World = require "base/world"
29+
local BallObserver = require "ballobserver"
2930
local Event = require "gameevents"
3031

3132
local OUT_OF_FIELD_MIN_TIME = 0.25
@@ -54,7 +55,7 @@ local function isBallInField(ballPos)
5455
end
5556

5657
function OutOfField:occuring()
57-
local ballPos = World.Ball.pos
58+
local ballPos = BallObserver.getRealisticBallPos()
5859
local previousPos = self.lastTouchPosition
5960

6061
local lastTeam = Referee.teamWhichTouchedBallLast()
@@ -78,17 +79,17 @@ function OutOfField:occuring()
7879
else
7980
self.maxHeightAfterBlueTouch = 0
8081
end
81-
elseif isBallInField() then
82+
elseif isBallInField(ballPos) then
8283
self.maxHeightAfterYellowTouch = math.max(self.maxHeightAfterYellowTouch, World.Ball.posZ)
8384
self.maxHeightAfterBlueTouch = math.max(self.maxHeightAfterBlueTouch, World.Ball.posZ)
8485
end
8586

86-
if isBallInField() then
87+
if isBallInField(ballPos) then
8788
self.wasInFieldBefore = true
8889
elseif self.wasInFieldBefore then
8990
self.outOfFieldTime = World.Time
9091
self.wasInFieldBefore = false
91-
self.outOfFieldPos = World.Ball.pos:copy()
92+
self.outOfFieldPos = ballPos:copy()
9293
self.waitingForDecision = true
9394
end
9495
end
@@ -100,7 +101,7 @@ function OutOfField:occuring()
100101
end
101102
end
102103
end
103-
if isBallInField() and not self.waitingForDecision then
104+
if isBallInField(ballPos) and not self.waitingForDecision then
104105
self.rawOutOfFieldCounter = 0
105106
end
106107

@@ -120,7 +121,7 @@ function OutOfField:occuring()
120121
return
121122
end
122123

123-
vis.addCircle("ball out of play", World.Ball.pos, 0.02, vis.colors.blue, true)
124+
vis.addCircle("ball out of play", ballPos, 0.02, vis.colors.blue, true)
124125
local event
125126
if math.abs(self.outOfFieldPos.y) > World.Geometry.FieldHeightHalf then -- out of goal line
126127
event = Event.ballLeftField(lastRobot.isYellow, lastRobot.id, self.outOfFieldPos, true)
@@ -140,7 +141,7 @@ function OutOfField:occuring()
140141
and math.abs(ballPos.y) > World.Geometry.FieldHeightHalf
141142
and math.abs(ballPos.y) <World.Geometry.FieldHeightHalf+0.2
142143

143-
local closeToGoal = World.Ball.pos:distanceToLineSegment(World.Geometry[side.."GoalLeft"], World.Geometry[side.."GoalRight"]) < CLOSE_TO_GOAL_THRESHOLD
144+
local closeToGoal = ballPos:distanceToLineSegment(World.Geometry[side.."GoalLeft"], World.Geometry[side.."GoalRight"]) < CLOSE_TO_GOAL_THRESHOLD
144145

145146
if closeToGoal or insideGoal
146147
or math.abs(ballPos.y) > World.Geometry.FieldHeightHalf+0.2 then -- math.abs(World.Ball.pos.x) < World.Geometry.GoalWidth/2

0 commit comments

Comments
 (0)