Skip to content

Commit

Permalink
Some more adjustements for loading inside of a bunker silo
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Oct 17, 2023
1 parent e78f1a3 commit 425d780
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 8 additions & 4 deletions scripts/ai/AIDriveStrategyShovelSiloLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function AIDriveStrategyShovelSiloLoader:setAllStaticParameters()
Markers.setMarkerNodes(self.vehicle)
self.frontMarkerNode, self.backMarkerNode, self.frontMarkerDistance, self.backMarkerDistance =
Markers.getMarkerNodes(self.vehicle)
self.siloEndProximitySensor = SingleForwardLookingProximitySensorPack(self.vehicle, self.shovelController:getShovelNode(), 5, 1)
self.siloEndProximitySensor = SingleForwardLookingProximitySensorPack(self.vehicle, self.shovelController:getShovelNode(), 1, 1)
self.heapNode = CpUtil.createNode("heapNode", 0, 0, 0, nil)
self.lastTrailerSearch = 0
self.isStuckTimer = Timer.new(self.isStuckMs)
Expand Down Expand Up @@ -275,9 +275,13 @@ function AIDriveStrategyShovelSiloLoader:getDriveData(dt, vX, vY, vZ)
self.isStuckTimer:startIfNotRunning()
end
local _, _, closestObject = self.siloEndProximitySensor:getClosestObjectDistanceAndRootVehicle()
local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 0)
if self.silo:isTheSameSilo(closestObject) or isEndReached then
self:debug("End wall detected or bunker silo end is reached.")
local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
self:setMaxSpeed(maxSpeed)
if isEndReached then
self:debug("End of the silo or heap was detected.")
self:startDrivingOutOfSilo()
elseif self.silo:isTheSameSilo(closestObject) and self.silo:isNodeInSilo(self.shovelController:getShovelNode()) then
self:debug("End wall of the silo was detected.")
self:startDrivingOutOfSilo()
end
if self.shovelController:isFull() then
Expand Down
15 changes: 15 additions & 0 deletions scripts/silo/BunkerSiloVehicleController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,21 @@ function CpBunkerSiloLoaderController:getNextLine(numLines, width)
return self:getLineWithTheMostFillLevel(width)
end


--- Is the end of the silo reached.
---@param node number
---@param margin number
---@return boolean end reached?
---@return number distance to the end
function CpBunkerSiloLoaderController:isEndReached(node, margin)
if self.drivingTarget then
local dx, dz = unpack(self.drivingTarget[2])
local _, _, z = worldToLocal(node, dx, 0, dz)
return z < margin, MathUtil.clamp(z * 2, 5, math.huge)
end
return false, math.huge
end

function CpBunkerSiloLoaderController:draw()
if self:isDebugEnabled() then
if self.bestLoadTarget then
Expand Down
4 changes: 3 additions & 1 deletion scripts/silo/BunkerSiloWrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ function CpSilo:getTotalFillLevel()
return 0
end

function CpSilo:isTheSameSilo()
function CpSilo:isTheSameSilo(object)
--- override
return false
end

--- Heap Bunker Silo
Expand Down Expand Up @@ -339,6 +340,7 @@ function CpBunkerSilo:isTheSameSilo(object)
end
end
end
return false
end

function CpBunkerSilo:getFrontArea(length, sideOffset)
Expand Down

0 comments on commit 425d780

Please sign in to comment.