Skip to content

Commit

Permalink
fix: find closest bale logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pvaiko committed Mar 15, 2024
1 parent 8d7de9b commit fd841e2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/ai/AIDriveStrategyFindBales.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function AIDriveStrategyFindBales:findClosestBale(bales, baleToIgnore)
local closestBale, minDistance, ix = nil, math.huge, 1
local invalidBales = 0
for i, bale in ipairs(bales) do
if bale:isStillValid() and bale ~= baleToIgnore then
if bale:isStillValid() then
local _, _, _, d = bale:getPositionInfoFromNode(self.vehicle:getAIDirectionNode())
self:debug('%d. bale (%d, %s) in %.1f m', i, bale:getId(), bale:getBaleObject(), d)
if d < self.turningRadius * 4 then
Expand All @@ -251,9 +251,13 @@ function AIDriveStrategyFindBales:findClosestBale(bales, baleToIgnore)
self:debug(' Dubins length is %.1f m', d)
end
if d < minDistance then
closestBale = bale
minDistance = d
ix = i
if bale ~= baleToIgnore then
closestBale = bale
minDistance = d
ix = i
else
self:debug(' IGNORED')
end
end
else
--- When a bale gets wrapped it changes its identity and the node becomes invalid. This can happen
Expand Down

0 comments on commit fd841e2

Please sign in to comment.