Skip to content

Commit 4b58e6a

Browse files
committed
feat: better transition to headland at corners
#1156
1 parent 7d5ea61 commit 4b58e6a

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,19 +550,24 @@ end
550550
--- Use pathfinder to next waypoint
551551
-----------------------------------------------------------------------------------------------------------------------
552552
function AIDriveStrategyFieldWorkCourse:startPathfindingToNextWaypoint(ix)
553-
self:debug('start pathfinding to waypoint %d', ix + 1)
553+
local targetIx = ix + 1
554+
self:debug('start pathfinding to waypoint %d', targetIx)
555+
if self.fieldWorkCourse:isHeadlandTurnAtIx(targetIx + 1) then
556+
self:debug('waypoint after the next is headland turn, skip next and find path to the headland corner at waypoint %d', targetIx + 1)
557+
targetIx = targetIx + 1
558+
end
554559
local fm, bm = self:getFrontAndBackMarkers()
555-
self.turnContext = RowStartOrFinishContext(self.vehicle, self.fieldWorkCourse, ix + 1, ix + 1,
560+
self.turnContext = RowStartOrFinishContext(self.vehicle, self.fieldWorkCourse, targetIx, targetIx,
556561
self.turnNodes, self:getWorkWidth(), fm, bm, self:getTurnEndSideOffset(false), self:getTurnEndForwardOffset())
557562
local _, steeringLength = AIUtil.getSteeringParameters(self.vehicle)
558563
local targetNode, zOffset = self.turnContext:getTurnEndNodeAndOffsets(steeringLength)
559564
local context = PathfinderContext(self.vehicle)
560565
:allowReverse(self:getAllowReversePathfinding())
561566
:ignoreFruit(not self.settings.avoidFruit:getValue())
562-
self.waypointToContinueOnFailedPathfinding = ix + 1
567+
self.waypointToContinueOnFailedPathfinding = targetIx
563568
self.pathfinderController:registerListeners(self, self.onPathfindingDoneToNextWaypoint,
564569
self.onPathfindingFailedToNextWaypoint)
565-
self:debug('Start pathfinding to target waypoint %d, zOffset %.1f', ix + 1, zOffset)
570+
self:debug('Start pathfinding to target waypoint %d, zOffset %.1f', targetIx, zOffset)
566571
self.state = self.states.WAITING_FOR_PATHFINDER
567572
-- to have a course set while waiting for the pathfinder
568573
self:startCourse(self.fieldWorkCourse, self.waypointToContinueOnFailedPathfinding)

scripts/courseGenerator/WaypointAttributes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function WaypointAttributes:shouldUsePathfinderToNextWaypoint()
7272
return self.usePathfinderToNextWaypoint
7373
end
7474

75-
--- if this is true, the driver should use the pathfinder to navigate to the this waypoint from the previous.
75+
--- if this is true, the driver should use the pathfinder to navigate to this waypoint from the previous.
7676
--- One example of this is when row starts at a small island so the 180º turn must use the pathfinder to avoid the island.
7777
function WaypointAttributes:shouldUsePathfinderToThisWaypoint()
7878
return self.usePathfinderToThisWaypoint

0 commit comments

Comments
 (0)