Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7423 from Courseplay/SugarCaneTrailerToolPositions
Browse files Browse the repository at this point in the history
Added diff working tool positions and trigger fixes
  • Loading branch information
schwiti6190 authored Aug 11, 2021
2 parents 468d8cc + 8f4db83 commit fa9b5e0
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 239 deletions.
32 changes: 21 additions & 11 deletions AIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ function AIDriver:init(vehicle)
self.settings:validateCurrentValues()
end
self:setHudContent()
---@type TriggerHandler
self.triggerHandler = TriggerHandler(self,self.vehicle,self:getSiloSelectedFillTypeSetting())
self.triggerHandler:enableFuelLoading()
---@type TriggerSensor
self.triggerSensor = TriggerSensor(self,self.vehicle)
end

---This function is called once on the first update tick,
Expand Down Expand Up @@ -438,13 +441,13 @@ function AIDriver:update(dt)
self:resetSpeed()
self:updateLoadingText()
self.triggerHandler:onUpdate(dt)
self.triggerSensor:onUpdate(dt)
self:shouldDriverBeReleased()

self:updateDistanceMovedSinceStart(dt)
self:updateDistanceMovedSinceStart()
end

---Update moved distance since start.
function AIDriver:updateDistanceMovedSinceStart(dt)
function AIDriver:updateDistanceMovedSinceStart()
self.movedDistance = self.movedDistance + self.vehicle.lastMovedDistance
end

Expand Down Expand Up @@ -512,14 +515,9 @@ function AIDriver:driveCourse(dt)
if not self:hasTipTrigger() then
self:setSpeed(self:getRecordedSpeed())
end

local isInTrigger, isAugerWagonTrigger = self.triggerHandler:isInTrigger()
-- if self:getIsInFilltrigger() or self:hasTipTrigger() then-- or isInTrigger then
if isInTrigger then

if self.triggerHandler:isInTrigger() or self.triggerSensor:isNearTriggers() then
self:setSpeed(self.vehicle.cp.speeds.approach)
if isAugerWagonTrigger then
self:setSpeed(self.APPROACH_AUGER_TRIGGER_SPEED)
end
end

self:slowDownForWaitPoints()
Expand Down Expand Up @@ -1368,6 +1366,12 @@ function AIDriver:searchForTipTriggers()
end
end

function AIDriver:searchForLoadingFillingTriggers()
if self.ppc:getCurrentWaypointIx() > 2 and not self.ppc:reachedLastWaypoint() and not self.ppc:isReversing() then
self.triggerSensor:raycastLoadingFillingTriggers()
end
end

function AIDriver:onUnLoadCourse(allowedToDrive, dt)
-- Unloading
local takeOverSteering = false
Expand Down Expand Up @@ -2303,5 +2307,11 @@ function AIDriver:isWorkingToolPositionReached(dt,positionIx)
end

function AIDriver:getWorkingToolPositionsSetting()
--- override
if self:hasSugarCaneTrailerToolPositions() then
return self.settings.sugarCaneTrailerToolPositions
end
end

function AIDriver:hasSugarCaneTrailerToolPositions()
return self.settings.sugarCaneTrailerToolPositions:getHasSugarCaneTrailer()
end
50 changes: 49 additions & 1 deletion AIDriverUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,52 @@ function AIDriverUtil.getMixerWagonFillLevelForFillTypes(object,fillType)
end
end
end
end
end

--- Is a sugarcane trailer attached ?
---@param vehicle table
function AIDriverUtil.hasSugarCaneTrailer(vehicle)
if vehicle.spec_shovel and vehicle.spec_trailer then
return true
end
for _, implement in pairs(AIDriverUtil.getAllAttachedImplements(vehicle)) do
local object = implement.object
if object.spec_shovel and object.spec_trailer then
return true
end
end
end

--- Are there any trailer under the pipe ?
---@param pipe table
---@param shouldTrailerBeStandingStill boolean
function AIDriverUtil.isTrailerUnderPipe(pipe,shouldTrailerBeStandingStill)
if not pipe then return end
for trailer, value in pairs(pipe.objectsInTriggers) do
if value > 0 then
if shouldTrailerBeStandingStill then
local rootVehicle = trailer:getRootVehicle()
if rootVehicle then
if AIDriverUtil.isStopped(rootVehicle) then
return true
else
return false
end
end
end
return true
end
end
return false
end

---Gets the total length of the vehicle and all it's implements.
function AIDriverUtil.getVehicleAndImplementsTotalLength(vehicle)
local totalLength = vehicle.sizeLength
for _, implement in pairs(AIDriverUtil.getAllAttachedImplements(vehicle)) do
if implement.object ~= nil then
totalLength = totalLength + implement.object.sizeLength
end
end
return totalLength
end
23 changes: 19 additions & 4 deletions CombineAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ function CombineAIDriver:init(vehicle)
self.unloadAIDriverToRendezvous = CpTemporaryObject()
end

function CombineAIDriver:postInit()
---Refresh the Hud content here,as otherwise the moveable pipe is not
---detected the first time after loading a savegame.
self:setHudContent()
UnloadableFieldworkAIDriver.postInit(self)
end

function CombineAIDriver:setUpPipe()
if self.vehicle.spec_pipe then
self.pipe = self.vehicle.spec_pipe
Expand Down Expand Up @@ -212,7 +219,7 @@ end

function CombineAIDriver:drive(dt)
-- handle the pipe in any state
self:handlePipe()
self:handlePipe(dt)
-- the rest is the same as the parent class
UnloadableFieldworkAIDriver.drive(self, dt)
end
Expand Down Expand Up @@ -1085,20 +1092,23 @@ function CombineAIDriver:isChopper()
return self.combine:getFillUnitCapacity(self.combine.fillUnitIndex) > 10000000
end

function CombineAIDriver:handlePipe()
function CombineAIDriver:handlePipe(dt)
if self.pipe then
if self:isChopper() then
self:handleChopperPipe()
else
self:handleCombinePipe()
self:handleCombinePipe(dt)
end
end
end

function CombineAIDriver:handleCombinePipe()
function CombineAIDriver:handleCombinePipe(dt)

if self:isFillableTrailerUnderPipe() or self:isAutoDriveWaitingForPipe() or (self:isWaitingForUnload() and self.vehicle.cp.settings.pipeAlwaysUnfold:is(true)) then
self:openPipe()
if self.pipe and self.pipe.currentState == AIDriverUtil.PIPE_STATE_OPEN then
self:isWorkingToolPositionReached(dt,1)
end
else
--wait until the objects under the pipe are gone
if self.pipe.numObjectsInTriggers <=0 then
Expand Down Expand Up @@ -1765,3 +1775,8 @@ function CombineAIDriver:isProximitySlowDownEnabled(vehicle)
return true
end
end

function CombineAIDriver:getWorkingToolPositionsSetting()
local setting = self.settings.pipeToolPositions
return setting:getHasMoveablePipe() and setting:hasValidToolPositions() and setting
end
40 changes: 31 additions & 9 deletions FieldSupplyAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ function FieldSupplyAIDriver:init(vehicle)
self.supplyState = self.states.ON_REFILL_COURSE
self.mode=courseplay.MODE_FIELD_SUPPLY
self.debugChannel = courseplay.DBG_MODE_8
self:setHudContent()
end

function FieldSupplyAIDriver:postInit()
---Refresh the Hud content here,as otherwise the moveable pipe is not
---detected the first time after loading a savegame.
self:setHudContent()
FillableFieldworkAIDriver.postInit(self)
end

function FieldSupplyAIDriver:setHudContent()
self:findPipe()
AIDriver.setHudContent(self)
courseplay.hud:setFieldSupplyAIDriverContent(self.vehicle)
end
--this one is should be better derived!!
function FieldSupplyAIDriver:start(startingPoint)
self.refillState = self.states.REFILL_DONE
self.supplyState = self.states.ON_REFILL_COURSE
AIDriver.start(self,startingPoint)
self.state = self.states.ON_UNLOAD_OR_REFILL_COURSE
self:findPipe() --for Augerwagons
end

function FieldSupplyAIDriver:stop(msgReference)
Expand Down Expand Up @@ -84,9 +91,18 @@ function FieldSupplyAIDriver:drive(dt)
elseif self.supplyState == self.states.WAITING_FOR_GETTING_UNLOADED then
self:holdWithFuelSave()
self:updateInfoText()
if self.pipe then
self.pipe:setPipeState(AIDriverUtil.PIPE_STATE_OPEN)
if self.objectWithPipe then
self.triggerHandler:enableFillTypeUnloadingAugerWagon()
---TODO: Currently it's not possible to open the pipe after the mode 4 driver arrives,
--- as there is not trigger to detect it, while the pipe is closed.

-- if AIDriverUtil.isTrailerUnderPipe(self.pipe,true) then
--- Open the pipe if there is a trailer under the pipe and standing still.
self.objectWithPipe:setPipeState(AIDriverUtil.PIPE_STATE_OPEN)
self:isWorkingToolPositionReached(dt,1)
-- else
-- self.objectWithPipe:setPipeState(AIDriverUtil.PIPE_STATE_CLOSED)
-- end
else
self.triggerHandler:enableFillTypeUnloading()
end
Expand Down Expand Up @@ -130,7 +146,7 @@ function FieldSupplyAIDriver:isFillLevelToContinueReached()
return
end
--pipe still opening wait!
if self.pipe and not self.pipe:getIsPipeStateChangeAllowed(AIDriverUtil.PIPE_STATE_CLOSED) then
if self.objectWithPipe and not self.objectWithPipe:getIsPipeStateChangeAllowed(AIDriverUtil.PIPE_STATE_CLOSED) then
return
end
local fillLevelInfo = {}
Expand All @@ -154,15 +170,16 @@ function FieldSupplyAIDriver:needsFillTypeLoading()
end

function FieldSupplyAIDriver:findPipe()
local implementWithPipe = AIDriverUtil.getImplementWithSpecialization(self.vehicle, Pipe)
local implementWithPipe = AIDriverUtil.getImplementWithSpecialization(self.vehicle, Pipe) or self.vehicle.spec_pipe and self.vehicle
if implementWithPipe then
self.pipe = implementWithPipe
self.objectWithPipe = implementWithPipe
self.pipe = implementWithPipe.spec_pipe
end
end

function FieldSupplyAIDriver:closePipeIfNeeded(isInWaitPointRange)
if self.pipe and not self.isInWaitPointRange then
self.pipe:setPipeState(AIDriverUtil.PIPE_STATE_CLOSED)
if self.objectWithPipe and not self.isInWaitPointRange then
self.objectWithPipe:setPipeState(AIDriverUtil.PIPE_STATE_CLOSED)
end
end

Expand All @@ -172,4 +189,9 @@ end

function FieldSupplyAIDriver:getCanShowDriveOnButton()
return AIDriver.getCanShowDriveOnButton(self) or self.refillState == self.states.WAITING_FOR_GETTING_UNLOADED
end

function FieldSupplyAIDriver:getWorkingToolPositionsSetting()
local setting = self.settings.pipeToolPositions
return setting:getHasMoveablePipe() and setting:hasValidToolPositions() and setting
end
2 changes: 2 additions & 0 deletions FillableFieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function FillableFieldworkAIDriver:driveUnloadOrRefill()
else
self:clearInfoText('NO_SELECTED_FILLTYPE')
end

local isNearWaitPoint, waitPointIx = self.course:hasWaitPointWithinDistance(self.ppc:getRelevantWaypointIx(), 25)
--this one is used to disable loading at the unloading stations,
--might be better to disable the triggerID for loading
Expand All @@ -91,6 +92,7 @@ function FillableFieldworkAIDriver:driveUnloadOrRefill()
-- just drive normally
self:setSpeed(self:getRecordedSpeed())
self:closePipeIfNeeded(isNearWaitPoint)
self:searchForLoadingFillingTriggers()
end
end

Expand Down
2 changes: 1 addition & 1 deletion GrainTransportAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function GrainTransportAIDriver:drive(dt)

local allowedToDrive = true
if self:getSiloSelectedFillTypeSetting():isEmpty() then
courseplay:setInfoText(self.vehicle, "COURSEPLAY_MANUAL_LOADING")
--checking FillLevels, while loading at StartPoint
if self.readyToLoadManualAtStart then
courseplay:setInfoText(self.vehicle, "COURSEPLAY_MANUAL_LOADING")
self:setInfoText('REACHED_OVERLOADING_POINT')
self:checkFillUnits()
if self.nextClosestExactFillRootNode then
Expand Down
30 changes: 5 additions & 25 deletions OverloaderAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ function OverloaderAIDriver:findPipeAndTrailer()
if implementWithPipe then
self.pipe = implementWithPipe.spec_pipe
self.objectWithPipe = implementWithPipe
self.moveablePipe = implementWithPipe.spec_cylindered
self:debug('Overloader found its pipe')
if self.moveablePipe then
self:debug('Overloader found moveable pipe')
end
else
self:debug('Overloader has no implement with pipe')
end
Expand All @@ -66,7 +62,7 @@ end
function OverloaderAIDriver:setHudContent()
CombineUnloadAIDriver.setHudContent(self)
self:findPipeAndTrailer()
courseplay.hud:setOverloaderAIDriverContent(self.vehicle,self.moveablePipe)
courseplay.hud:setOverloaderAIDriverContent(self.vehicle)
end

function OverloaderAIDriver:start(startingPoint)
Expand All @@ -79,23 +75,7 @@ function OverloaderAIDriver:start(startingPoint)
end

function OverloaderAIDriver:isTrailerUnderPipe(shouldTrailerBeStandingStill)
if not self.pipe then return end
for trailer, value in pairs(self.pipe.objectsInTriggers) do
if value > 0 then
if shouldTrailerBeStandingStill then
local rootVehicle = trailer:getRootVehicle()
if rootVehicle then
if rootVehicle:getLastSpeed(true) <1 then
return true
else
return false
end
end
end
return true
end
end
return false
return AIDriverUtil.isTrailerUnderPipe(self.pipe,shouldTrailerBeStandingStill)
end

function OverloaderAIDriver:driveUnloadCourse(dt)
Expand Down Expand Up @@ -135,10 +115,10 @@ function OverloaderAIDriver:driveUnloadCourse(dt)
AIDriver.drive(self, dt)
end

--if we have augerPipeToolPositions, then wait until we have set them
--if we have pipeToolPositions, then wait until we have set them
function OverloaderAIDriver:getWorkingToolPositionsSetting()
local setting = self.vehicle.cp.settings.augerPipeToolPositions
return self.moveablePipe and setting:hasValidToolPositions() and self.vehicle.cp.settings.augerPipeToolPositions
local setting = self.settings.pipeToolPositions
return setting:getHasMoveablePipe() and setting:hasValidToolPositions() and setting
end

function OverloaderAIDriver:isProximitySwerveEnabled(vehicle)
Expand Down
Loading

0 comments on commit fa9b5e0

Please sign in to comment.