Skip to content

Commit

Permalink
Merge pull request #1297 from Courseplay/vine-turn
Browse files Browse the repository at this point in the history
Vine turn
  • Loading branch information
Tensuko committed Mar 27, 2022
2 parents d9fe31c + 3dcb46c commit f88162f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
18 changes: 16 additions & 2 deletions scripts/ai/AIDriveStrategyVineFieldWorkCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function AIDriveStrategyVineFieldWorkCourse.new(customMt)
customMt = AIDriveStrategyVineFieldWorkCourse_mt
end
local self = AIDriveStrategyFieldWorkCourse.new(customMt)

return self
end

Expand All @@ -47,4 +46,19 @@ end

function AIDriveStrategyVineFieldWorkCourse:getImplementLowerEarly()
return true
end
end

function AIDriveStrategyVineFieldWorkCourse:startTurn(ix)

local _, frontMarkerDistance = AIUtil.getFirstAttachedImplement(self.vehicle)
local _, backMarkerDistance = AIUtil.getLastAttachedImplement(self.vehicle)

self:debug('Starting a turn at waypoint %d, front marker %.1f, back marker %.1f', ix, frontMarkerDistance, backMarkerDistance)
self.ppc:setShortLookaheadDistance()


self.turnContext = TurnContext(self.course, ix, ix + 1, self.turnNodes, self:getWorkWidth(),
frontMarkerDistance, -backMarkerDistance, 0, 0)
self.aiTurn = VineTurn(self.vehicle, self, self.ppc, self.turnContext, self.course, self.workWidth)
self.state = self.states.TURNING
end
18 changes: 17 additions & 1 deletion scripts/ai/turns/AITurn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -980,4 +980,20 @@ end

function StartRowOnly:updateTurnProgress()
-- do nothing since this isn't really a turn
end
end

--- A turn for working between vine rows.
---@class VineTurn : CourseTurn
VineTurn = CpObject(CourseTurn)
function VineTurn:init(vehicle, driveStrategy, ppc, turnContext, fieldWorkCourse, workWidth)
CourseTurn.init(self, vehicle, driveStrategy, ppc, turnContext, fieldWorkCourse, workWidth, 'VineTurn')
end

function VineTurn:startTurn()
local turnManeuver = VineTurnManeuver(self.vehicle, self.turnContext, self.vehicle:getAIDirectionNode(),
self.turningRadius, self.workWidth)
self.turnCourse = turnManeuver:getCourse()
self.ppc:setCourse(self.turnCourse)
self.ppc:initialize(1)
self.state = self.states.TURNING
end
24 changes: 24 additions & 0 deletions scripts/ai/turns/TurnManeuver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,28 @@ function AlignmentCourse:init(vehicle, vehicleDirectionNode, turningRadius, cour
end
self:debug('Alignment course with %d waypoints created.', #alignmentWaypoints)
self.course = Course.createFromAnalyticPath(self.vehicle, alignmentWaypoints, true)
end

---@class VineTurnManeuver : TurnManeuver
VineTurnManeuver = CpObject(TurnManeuver)
function VineTurnManeuver:init(vehicle, turnContext, vehicleDirectionNode, turningRadius, workWidth)
TurnManeuver.init(self, vehicle, turnContext, vehicleDirectionNode, turningRadius, workWidth, 0)

self:debug('Start generating')

local turnEndNode, startOffset, goalOffset = self.turnContext:getTurnEndNodeAndOffsets(0)
local _, _, dz = turnContext:getLocalPositionOfTurnEnd(vehicle:getAIDirectionNode())
if dz > 0 then
startOffset = startOffset + dz
else
goalOffset = goalOffset + dz
end
self:debug('r=%.1f, w=%.1f, dz=%.1f, startOffset=%.1f, goalOffset=%.1f',
turningRadius, workWidth, dz, startOffset, goalOffset)
local path = PathfinderUtil.findAnalyticPath(PathfinderUtil.dubinsSolver,
-- always move the goal a bit backwards to let the vehicle align
vehicleDirectionNode, startOffset, turnEndNode, 0, goalOffset - turnContext.frontMarkerDistance, self.turningRadius)
self.course = Course.createFromAnalyticPath(self.vehicle, path, true)
local endingTurnLength = self.turnContext:appendEndingTurnCourse(self.course, 0, false)
TurnManeuver.setLowerImplements(self.course, endingTurnLength, true)
end
1 change: 1 addition & 0 deletions scripts/reloadAI.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ type ai\AIDriveStrategyFieldWorkCourse.lua >> %outfile%
type ai\AIDriveStrategyCombineCourse.lua >> %outfile%
type ai\AIDriveStrategyPlowCourse.lua >> %outfile%
type ai\AIDriveStrategyDriveToFieldWorkStart.lua >> %outfile%
type ai\AIDriveStrategyVineFieldWorkCourse.lua >> %outfile%
echo ]]^> >> %outfile%
echo ^</code^> >> %outfile%

0 comments on commit f88162f

Please sign in to comment.