Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/ai/SelfUnloadHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ SelfUnloadHelper.maxDistanceFromField = 20
---@return table|nil best fill node of trailer
---@return number|nil distance of trailer from myVehicle
function SelfUnloadHelper:findBestTrailer(fieldPolygon, myVehicle, implementWithPipe, pipeOffsetX)
if fieldPolygon == nil or #fieldPolygon == 0 then
CpUtil.errorVehicle(myVehicle, 'Field polygon is nil or empty, can\'t find a trailer to unload to')
return nil
end
local bestTrailer, bestFillUnitIndex, bestFillType
local minDistance = math.huge
for _, otherVehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
Expand Down Expand Up @@ -125,7 +129,6 @@ end
---@param fillRootNode number|nil optional fill node for the trailer, must not be nil if bestTrailer is not nil
function SelfUnloadHelper:getTargetParameters(fieldPolygon, myVehicle, implementWithPipe, objectWithPipeAttributes,
bestTrailer, fillRootNode)

if not bestTrailer then
-- no trailer passed in, let's find one
bestTrailer, fillRootNode = SelfUnloadHelper:findBestTrailer(fieldPolygon,
Expand Down
19 changes: 9 additions & 10 deletions scripts/ai/strategies/AIDriveStrategyCombineCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ AIDriveStrategyCombineCourse.isAAIDriveStrategyCombineCourse = true
function AIDriveStrategyCombineCourse:init(task, job)
AIDriveStrategyFieldWorkCourse.init(self, task, job)
AIDriveStrategyCourse.initStates(self, AIDriveStrategyCombineCourse.myStates)
--- Combine needs a field polygon for the self-unload to work. Although it is a user setting, but it can be
--- changed during the work, so we always require the field polygon, regardless of the setting, as it is checked
--- only after starting the CP driver.
self.state = self.states.WAITING_FOR_FIELD_BOUNDARY_DETECTION
self.fruitLeft, self.fruitRight = 0, 0
self.litersPerMeter = 0
self.litersPerSecond = 0
Expand Down Expand Up @@ -243,17 +239,20 @@ function AIDriveStrategyCombineCourse:getDriveData(dt, vX, vY, vZ)
self:setMaxSpeed(0)
end

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

if self.state == self.states.WAITING_FOR_FIELD_BOUNDARY_DETECTION then
self:setMaxSpeed(0)
if self.vehicle:cpIsFieldBoundaryDetectionRunning() then
if self.settings.selfUnload:getValue() then
-- don't have the field boundary yet, and self unload is selected, don't move
self:setMaxSpeed(0)
end
if self:waitForFieldBoundary() then
self:debug('Have field boundary now.')
self.state = self.states.INITIAL
end
elseif self.state == self.states.WORKING then
-- Harvesting
Expand Down
Loading