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

Better up/down -> headland transition for #6067 #6388

Merged
merged 1 commit into from
Nov 28, 2020
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
21 changes: 21 additions & 0 deletions AITurn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,25 @@ function CombinePocketHeadlandTurn:turn(dt)
self.driver:lowerImplements()
self.implementsLowered = true
end
end

--- A turn type which isn't really a turn, we only use this to finish a row (drive straight until the implement
--- reaches the end of the row, don't drive towards the next waypoint until then)
--- This is to make sure the last row before transitioning to the headland is properly finished, otherwise
--- we'd start driving towards the next headland waypoint, turning towards it before the implement reaching the
--- end of the row and leaving unworked patches.
---@class FinishRowOnly : AITurn
FinishRowOnly = CpObject(AITurn)

function FinishRowOnly:init(vehicle, driver, turnContext)
AITurn.init(self, vehicle, driver, turnContext, 'FinishRowOnly')
end

function FinishRowOnly:finishRow()
-- keep driving straight until we need to raise our implements
if self.driver:shouldRaiseImplements(self:getRaiseImplementNode()) then
self:debug('Row finished, returning to fieldwork.')
self.driver:resumeFieldworkAfterTurn(self.turnContext.turnEndWpIx)
end
return false
end
13 changes: 12 additions & 1 deletion FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ function FieldworkAIDriver:onWaypointChange(ix)
self:debug('adding offset (%.1f front marker) to make sure we do not miss anything when the course ends', self.frontMarkerDistance)
self.aiDriverOffsetZ = -self.frontMarkerDistance
end
elseif not self.course:isOnHeadland(ix) and self.course:isOnHeadland(ix + 1) then
self:debug('last row waypoint before switching to the headland')
self:finishRow(ix)
end
if self.fieldworkState ~= self.states.TURNING and self.course:isTurnStartAtIx(ix) then
self:startTurn(ix)
Expand All @@ -698,7 +701,7 @@ function FieldworkAIDriver:onWaypointChange(ix)
end

function FieldworkAIDriver:onTowedImplementPassedWaypoint(ix)
self:debug('Implement passsed waypoint %d', ix)
self:debug('Implement passed waypoint %d', ix)
end

--- Should we return to the first point of the course after we are done?
Expand Down Expand Up @@ -1105,6 +1108,14 @@ function FieldworkAIDriver:getTurnEndForwardOffset()
return 0
end

function FieldworkAIDriver:finishRow(ix)
self:setMarkers()
self.turnContext = RowFinishingContext(self.course, ix, self.aiDriverData, self.vehicle.cp.workWidth,
self.frontMarkerDistance, self:getTurnEndSideOffset(), self:getTurnEndForwardOffset())
self.aiTurn = FinishRowOnly(self.vehicle, self, self.turnContext)
self.fieldworkState = self.states.TURNING
end

function FieldworkAIDriver:startTurn(ix)
-- set a short lookahead distance for PPC to increase accuracy, especially after switching back from
-- turn.lua. That often happens too early (when lowering the implement) when we still have a cross track error,
Expand Down
11 changes: 11 additions & 0 deletions turn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2304,5 +2304,16 @@ function TurnContext:drawDebug()
end
end

--- A special turn context for the RowFinishOnly turn (up/down -> headland transition).
---@class RowFinishingContext : TurnContext
RowFinishingContext = CpObject(TurnContext)

--- Force the 180 turn behavior so the row finishing straight course is created properly. Without this
--- it would calculate a transition to the headland as a headland turn as such transitions are always
--- less then 180 and then the row finishing course would be offset
function RowFinishingContext:isHeadlandCorner()
return false
end

-- do not delete this line
-- vim: set noexpandtab: