Skip to content

Commit

Permalink
tweak unloader combine harvester
Browse files Browse the repository at this point in the history
getPipeRoot calculate the root component based on discharge node
calculate getPipeSide based on getPipeRoot to prevent wrong side detection if harvester is stopped in a turn position
calculate getPipeLength based on getPipeRoot to ensure correct distance and position if harvester is stopped in a turn position
disabled angleToSideChaseSide to angleToRearChaseSide comparison in getPipeChasePosition - should fix #391
  • Loading branch information
Axel32019 committed May 25, 2022
1 parent 564ecce commit 27827e2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
5 changes: 2 additions & 3 deletions scripts/Modes/CombineUnloaderMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ function CombineUnloaderMode:getSideChaseOffsetX()
local headerExtra = math.max((AutoDrive.getFrontToolWidth(self.combine) - self.combine.size.width) / 2, 0)

local sideChaseTermPipeIn = self.combine.size.width / 2 + unloaderWidest / 2 + headerExtra
local sideChaseTermPipeOut = self.combine.size.width / 2 + (AutoDrive.getPipeLength(self.combine))
local sideChaseTermPipeOut = AutoDrive.getPipeLength(self.combine)
-- Some combines fold up their pipe so tight that targeting it could cause a collision.
-- So, choose the max between the two to avoid a collison
local sideChaseTermX = math.max(sideChaseTermPipeIn, sideChaseTermPipeOut)
Expand Down Expand Up @@ -520,7 +520,6 @@ function CombineUnloaderMode:getSideChaseOffsetX_new()
local headerExtra = math.max((AutoDrive.getFrontToolWidth(self.combine) - self.combine.size.width) / 2, 0)

local sideChaseTermPipeIn = self.combine.size.width / 2 + unloaderWidest / 2 + headerExtra
local sideChaseTermPipeOut = self.combine.size.width / 2 + (AutoDrive.getPipeLength(self.combine))
-- Some combines fold up their pipe so tight that targeting it could cause a collision.
-- So, choose the max between the two to avoid a collison
local sideChaseTermX = 0
Expand Down Expand Up @@ -737,7 +736,7 @@ function CombineUnloaderMode:getPipeChasePosition(planningPhase)
(
(
self:isUnloaderOnCorrectSide(self.pipeSide)
and math.abs(angleToSideChaseSide) < math.abs(angleToRearChaseSide)
-- and math.abs(angleToSideChaseSide) < math.abs(angleToRearChaseSide)
)
or (planningPhase == true)
)
Expand Down
52 changes: 48 additions & 4 deletions scripts/Utils/CombineUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function AutoDrive.getDischargeNode(combine)
end
end

function AutoDrive.getPipeRoot(combine)
function AutoDrive.getPipeRoot_old(combine)
if combine.ad ~= nil and combine.ad.pipeRoot ~= nil then
return combine.ad.pipeRoot
end
Expand Down Expand Up @@ -68,11 +68,55 @@ function AutoDrive.getPipeRoot(combine)
return pipeRoot
end


function AutoDrive.getPipeRoot(combine)
if combine.ad ~= nil and combine.ad.pipeRoot ~= nil then
return combine.ad.pipeRoot
end
local dischargeNode = AutoDrive.getDischargeNode(combine)
local pipeRoot = nil

if dischargeNode then
for _, component in ipairs(combine.components) do

local node = dischargeNode
local count = 0
repeat
node = getParent(node)
count = count + 1
until ((node == component.node) or (node == 0) or (node == nil) or count >= 100)

if node and node ~= 0 then
-- found
pipeRoot = node
break
end
end
end
if pipeRoot == nil or pipeRoot == 0 then
-- fallback
pipeRoot = combine.components[1].node
end

if combine.ad ~= nil then
combine.ad.pipeRoot = pipeRoot
end
return pipeRoot
end

-- ret: -1 right, 1 left, 0 behind
-- not for sugarcane harvesters, choppers!!!
function AutoDrive.getPipeSide(combine)
local combineNode = combine.components[1].node
if combine.ad ~= nil and combine.ad.storedPipeSide ~= nil then
return combine.ad.storedPipeSide
end
local combineNode = AutoDrive.getPipeRoot(combine)
local dischargeNode = AutoDrive.getDischargeNode(combine)
local dischargeX, dichargeY, dischargeZ = getWorldTranslation(dischargeNode)
local diffX, _, _ = worldToLocal(combineNode, dischargeX, dichargeY, dischargeZ)
if combine.ad ~= nil then
combine.ad.storedPipeSide = AutoDrive.sign(diffX)
end
return AutoDrive.sign(diffX)
end

Expand All @@ -88,10 +132,10 @@ function AutoDrive.getPipeLength(combine)
pipeRootZ - dischargeZ)
--AutoDrive.debugPrint(combine, AutoDrive.DC_COMBINEINFO, "AutoDrive.getPipeLength - " .. length)
if AutoDrive.isPipeOut(combine) and not AutoDrive.getIsBufferCombine(combine) then
local combineNode = combine.components[1].node
local combineNode = AutoDrive.getPipeRoot(combine)
local dischargeX, dichargeY, dischargeZ = getWorldTranslation(AutoDrive.getDischargeNode(combine))
diffX, _, _ = worldToLocal(combineNode, dischargeX, dichargeY, dischargeZ)
length = math.abs(diffX) - combine.size.width /2
length = math.abs(diffX)

-- Store pipe length for 'normal' harvesters
if combine.ad ~= nil then
Expand Down

0 comments on commit 27827e2

Please sign in to comment.