Skip to content

Commit 307c510

Browse files
author
Peter Vaiko
committed
fix: fine tuning
#786
1 parent becb603 commit 307c510

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

scripts/Course.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ function Course:isLastWaypointIx(ix)
648648
return #self.waypoints == ix
649649
end
650650

651+
function Course:endsInReverse()
652+
return self:isReverseAt(self:getNumberOfWaypoints())
653+
end
654+
651655
function Course:print()
652656
for i = 1, #self.waypoints do
653657
local p = self.waypoints[i]

scripts/ai/turns/TurnContext.lua

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,19 +367,6 @@ function TurnContext:createCorner(vehicle, r)
367367
vehicle:getCpSettings().toolOffsetX:getValue())
368368
end
369369

370-
--- Course to reverse before starting a turn to make sure the turn is completely on the field
371-
--- @param vehicle table
372-
--- @param reverseDistance number distance to reverse in meters
373-
function TurnContext:createReverseWaypointsBeforeStartingTurn(vehicle, reverseDistance)
374-
local reverserNode = AIUtil.getReverserNode(vehicle)
375-
local _, _, dStart = localToLocal(reverserNode or vehicle:getAIDirectionNode(), self.workEndNode, 0, 0, 0)
376-
local waypoints = {}
377-
for d = dStart, dStart - reverseDistance - 1, -1 do
378-
local x, y, z = localToWorld(self.workEndNode, 0, 0, d)
379-
table.insert(waypoints, {x = x, y = y, z = z, rev = true})
380-
end
381-
return waypoints
382-
end
383370

384371
--- Course to end a pathfinder turn, a straight line from where pathfinder ended, into to next row,
385372
--- making sure it is long enough so the vehicle reaches the point to lower the implements on this course

scripts/ai/turns/TurnManeuver.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,16 +559,22 @@ ReedsSheppHeadlandTurnManeuver = CpObject(TurnManeuver)
559559
--- just after the cutter finished the corner, that is, the harvester should drive forward in the original direction
560560
--- until there is no fruit left. It'll then do a quick 90 degree 3 point turn to align with the new direction.
561561
function ReedsSheppHeadlandTurnManeuver:init(vehicle, turnContext, vehicleDirectionNode, turningRadius)
562+
self.vehicle = vehicle
562563
local solver = ReedsSheppSolver()
563564
-- use lateWorkStartNode since we covered the corner in the inbound direction already
564565
local path = PathfinderUtil.findAnalyticPath(solver, vehicleDirectionNode, 0, 0,
565566
turnContext.lateWorkStartNode, 0, -turnContext.backMarkerDistance, turningRadius)
566567
self.course = Course.createFromAnalyticPath(vehicle, path, true)
567-
self.course:adjustForReversing(2)
568-
-- add a little straight section to the end so we have a little buffer and don't end the turn right at
569-
-- the work start
570-
self.course:extend((self:getReversingOffset(vehicle, vehicleDirectionNode) or 4) + 1)
571-
TurnManeuver.setLowerImplements(self.course, 5, true)
568+
self.course:adjustForTowedImplements(2)
569+
if self.course:endsInReverse() then
570+
-- add a little straight section to the end so we have a little buffer and don't end the turn right at
571+
-- the work start
572+
local reversingOffset = (self:getReversingOffset(vehicle, vehicleDirectionNode) or 4)
573+
self:debug('Extending course by %.1f m', reversingOffset)
574+
self.course:extend( reversingOffset + 2, -turnContext.turnEndWp.dx, -turnContext.turnEndWp.dz)
575+
end
576+
local endingTurnLength = turnContext:appendEndingTurnCourse(self.course, 0)
577+
TurnManeuver.setLowerImplements(self.course, endingTurnLength, true)
572578
end
573579

574580
---@class TurnEndingManeuver : TurnManeuver

0 commit comments

Comments
 (0)