Skip to content

Commit 2754769

Browse files
authored
Merge pull request #908 from Courseplay/861-harvester-field-boundary
fix: field boundary checks
2 parents 61a9947 + c0a0e77 commit 2754769

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

scripts/ai/SelfUnloadHelper.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ SelfUnloadHelper.maxDistanceFromField = 20
3535
---@return table|nil best fill node of trailer
3636
---@return number|nil distance of trailer from myVehicle
3737
function SelfUnloadHelper:findBestTrailer(fieldPolygon, myVehicle, implementWithPipe, pipeOffsetX)
38+
if fieldPolygon == nil or #fieldPolygon == 0 then
39+
CpUtil.errorVehicle(myVehicle, 'Field polygon is nil or empty, can\'t find a trailer to unload to')
40+
return nil
41+
end
3842
local bestTrailer, bestFillUnitIndex, bestFillType
3943
local minDistance = math.huge
4044
for _, otherVehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
@@ -125,7 +129,6 @@ end
125129
---@param fillRootNode number|nil optional fill node for the trailer, must not be nil if bestTrailer is not nil
126130
function SelfUnloadHelper:getTargetParameters(fieldPolygon, myVehicle, implementWithPipe, objectWithPipeAttributes,
127131
bestTrailer, fillRootNode)
128-
129132
if not bestTrailer then
130133
-- no trailer passed in, let's find one
131134
bestTrailer, fillRootNode = SelfUnloadHelper:findBestTrailer(fieldPolygon,

scripts/ai/strategies/AIDriveStrategyCombineCourse.lua

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ AIDriveStrategyCombineCourse.isAAIDriveStrategyCombineCourse = true
7676
function AIDriveStrategyCombineCourse:init(task, job)
7777
AIDriveStrategyFieldWorkCourse.init(self, task, job)
7878
AIDriveStrategyCourse.initStates(self, AIDriveStrategyCombineCourse.myStates)
79-
--- Combine needs a field polygon for the self-unload to work. Although it is a user setting, but it can be
80-
--- changed during the work, so we always require the field polygon, regardless of the setting, as it is checked
81-
--- only after starting the CP driver.
82-
self.state = self.states.WAITING_FOR_FIELD_BOUNDARY_DETECTION
8379
self.fruitLeft, self.fruitRight = 0, 0
8480
self.litersPerMeter = 0
8581
self.litersPerSecond = 0
@@ -243,17 +239,20 @@ function AIDriveStrategyCombineCourse:getDriveData(dt, vX, vY, vZ)
243239
self:setMaxSpeed(0)
244240
end
245241

246-
if self.state == self.states.INITIAL and self.vehicle:cpGetFieldPolygon() == nil then
247-
self:setMaxSpeed(0)
248-
self.state = self.states.WAITING_FOR_FIELD_BOUNDARY_DETECTION
242+
--- Combine may need the field polygon for the self-unload to work, so if by now we don't have one
243+
--- and the field boundary detection is not running, start it. This can happen if the combine wasn't started
244+
--- directly, such as as it was driving to the field and then switched strategy
245+
if not self.vehicle:cpIsFieldBoundaryDetectionRunning() and self.vehicle:cpGetFieldPolygon() == nil then
249246
self:startFieldBoundaryDetection()
250247
end
251248

252-
if self.state == self.states.WAITING_FOR_FIELD_BOUNDARY_DETECTION then
253-
self:setMaxSpeed(0)
249+
if self.vehicle:cpIsFieldBoundaryDetectionRunning() then
250+
if self.settings.selfUnload:getValue() then
251+
-- don't have the field boundary yet, and self unload is selected, don't move
252+
self:setMaxSpeed(0)
253+
end
254254
if self:waitForFieldBoundary() then
255255
self:debug('Have field boundary now.')
256-
self.state = self.states.INITIAL
257256
end
258257
elseif self.state == self.states.WORKING then
259258
-- Harvesting

0 commit comments

Comments
 (0)