Skip to content

Commit becb603

Browse files
author
Peter Vaiko
committed
fix: callstack
#786
1 parent 98c630a commit becb603

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

scripts/ai/turns/TurnManeuver.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ end
247247
--- Get the distance between the direction node of the vehicle and the reverser node (if there is one). This
248248
--- is to make sure that when the course changes to reverse and there is a reverse node, the first reverse
249249
--- waypoint is behind the reverser node. Otherwise we'll just keep backing up until the emergency brake is triggered.
250-
function TurnManeuver:getReversingOffset()
251-
local reverserNode, debugText = AIUtil.getReverserNode(self.vehicle)
250+
---@return number|nil distance in meters to the reverser node, or nil if there is no reverser node
251+
function TurnManeuver:getReversingOffset(vehicle, vehicleDirectionNode)
252+
local reverserNode, debugText = AIUtil.getReverserNode(vehicle)
252253
if reverserNode then
253-
local _, _, dz = localToLocal(reverserNode, self.vehicleDirectionNode, 0, 0, 0)
254+
local _, _, dz = localToLocal(reverserNode, vehicleDirectionNode, 0, 0, 0)
254255
self:debug('Using reverser node (%s) distance %.1f', debugText, dz)
255256
return math.abs(dz)
256257
end
257-
return self.steeringLength
258258
end
259259

260260
--- Set implement lowering control for the end of the turn
@@ -274,7 +274,7 @@ end
274274
function TurnManeuver:adjustCourseToFitField(course, dBack, ixBeforeEndingTurnSection)
275275
self:debug('moving course back: d=%.1f', dBack)
276276
local endingTurnLength
277-
local reversingOffset = self:getReversingOffset()
277+
local reversingOffset = self:getReversingOffset(self.vehicle, self.vehicleDirectionNode) or self.steeringLength
278278
-- generate a straight reverse section first (less than 1 m step should make sure we always end up with
279279
-- at least two waypoints
280280
local courseWithReversing = Course.createFromNode(self.vehicle, self.vehicle:getAIDirectionNode(),
@@ -567,7 +567,7 @@ function ReedsSheppHeadlandTurnManeuver:init(vehicle, turnContext, vehicleDirect
567567
self.course:adjustForReversing(2)
568568
-- add a little straight section to the end so we have a little buffer and don't end the turn right at
569569
-- the work start
570-
self.course:extend(self:getReversingOffset() + 1)
570+
self.course:extend((self:getReversingOffset(vehicle, vehicleDirectionNode) or 4) + 1)
571571
TurnManeuver.setLowerImplements(self.course, 5, true)
572572
end
573573

0 commit comments

Comments
 (0)