Skip to content

Commit bac83db

Browse files
committed
Merge remote-tracking branch 'origin/ChopperSupport' into ChopperSupport
2 parents e4ab56d + c3883b6 commit bac83db

File tree

8 files changed

+89
-44
lines changed

8 files changed

+89
-44
lines changed

config/VehicleConfigurations.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ You can define the following custom settings:
234234
/>
235235
<Vehicle name="titan18.xml"
236236
noReverse="true"
237-
turnRadius = "9"
237+
turnRadius = "7.5"
238238
implementWheelAlwaysOnGround = "true"
239239
raiseLate = "true"
240240
lowerEarly = "true"
@@ -353,7 +353,7 @@ You can define the following custom settings:
353353
<Vehicle name="pw10012.xml"
354354
noReverse = "true"
355355
implementWheelAlwaysOnGround = "true"
356-
turnRadius = "14"
356+
turnRadius = "7.5"
357357
raiseLate = "true"
358358
lowerEarly = "true"
359359
/>
@@ -403,8 +403,7 @@ You can define the following custom settings:
403403
<!--Implements-->
404404
<!--Mod: Gregoire Besson SPSL9 -->
405405
<Vehicle name="spsl9.xml"
406-
toolOffsetX = "2.1"
407-
turnRadius = "12"
406+
turnRadius = "7.5"
408407
implementWheelAlwaysOnGround = "true"
409408
workingWidth = "10.5"
410409
noReverse = "true"

scripts/ai/AIDriveStrategyCombineCourse.lua

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,15 @@ function AIDriveStrategyCombineCourse:getTurnCourse()
13081308
end
13091309

13101310
function AIDriveStrategyCombineCourse:startTurn(ix)
1311-
self:debug('Starting a combine turn.')
1311+
self:debug(' Starting a combine turn.')
13121312

13131313
self.turnContext = TurnContext(self.vehicle, self.course, ix, ix + 1, self.turnNodes, self:getWorkWidth(),
13141314
self.frontMarkerDistance, self.backMarkerDistance,
13151315
self:getTurnEndSideOffset(), self:getTurnEndForwardOffset())
13161316

13171317
-- Combines drive special headland corner maneuvers, except potato and sugar beet harvesters
13181318
if self.turnContext:isHeadlandCorner() then
1319-
if self:isPotatoOrSugarBeetHarvester() then
1319+
if self.combineController:isPotatoOrSugarBeetHarvester() then
13201320
self:debug('Headland turn but this harvester uses normal turn maneuvers.')
13211321
AIDriveStrategyCombineCourse.superClass().startTurn(self, ix)
13221322
elseif self.course:isOnConnectingTrack(ix) then
@@ -1446,16 +1446,6 @@ function AIDriveStrategyCombineCourse:isDischarging()
14461446
return self.pipeController:isDischarging()
14471447
end
14481448

1449-
function AIDriveStrategyCombineCourse:isPotatoOrSugarBeetHarvester()
1450-
for i, fillUnit in ipairs(self.vehicle:getFillUnits()) do
1451-
if self.vehicle:getFillUnitSupportsFillType(i, FillType.POTATO) or
1452-
self.vehicle:getFillUnitSupportsFillType(i, FillType.SUGARBEET) then
1453-
self:debug('This is a potato or sugar beet harvester.')
1454-
return true
1455-
end
1456-
end
1457-
return false
1458-
end
14591449

14601450
-----------------------------------------------------------------------------------------------------------------------
14611451
--- Self unload

scripts/ai/AIDriveStrategyCourse.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ AIDriveStrategyCourse.onFinishedEvent = "onFinished"
3737
AIDriveStrategyCourse.onStartEvent = "onStart"
3838
AIDriveStrategyCourse.updateEvent = "update"
3939
AIDriveStrategyCourse.deleteEvent = "delete"
40+
--- A row has just been finished, implements are being raised and about to start the actual turn
41+
AIDriveStrategyCourse.onFinishRowEvent = "onFinishRow"
42+
--- The actual turn is done, now we are starting into the row and will lower the implements when
43+
--- they reach the start of the row
44+
AIDriveStrategyCourse.onTurnEndProgressEvent = "onTurnEndProgress"
4045

4146
function AIDriveStrategyCourse.new(customMt)
4247
if customMt == nil then

scripts/ai/AIDriveStrategyPlowCourse.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,13 @@ end
168168
function AIDriveStrategyPlowCourse:updateFieldworkOffset(course)
169169
--- Ignore the tool offset setting.
170170
course:setOffset((self.aiOffsetX or 0), (self.aiOffsetZ or 0))
171+
end
172+
173+
--- When we return from a turn, the offset is reverted and should immediately set, not waiting
174+
--- for the first waypoint to pass as it is on the wrong side right after the turn
175+
function AIDriveStrategyPlowCourse:resumeFieldworkAfterTurn(ix)
176+
-- call twice to trick the smoothing and reach the desired value sooner.
177+
self:updatePlowOffset()
178+
self:updatePlowOffset()
179+
AIDriveStrategyPlowCourse.superClass().resumeFieldworkAfterTurn(self, ix)
171180
end

scripts/ai/controllers/CombineController.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,14 @@ function CombineController:isDroppingStrawSwath()
124124
return self.combineSpec.strawPSenabled
125125
end
126126

127+
function CombineController:isPotatoOrSugarBeetHarvester()
128+
for i, fillUnit in ipairs(self.implement:getFillUnits()) do
129+
if self.implement:getFillUnitSupportsFillType(i, FillType.POTATO) or
130+
self.implement:getFillUnitSupportsFillType(i, FillType.SUGARBEET) then
131+
self:debug('This is a potato or sugar beet harvester.')
132+
return true
133+
end
134+
end
135+
return false
136+
end
137+

scripts/ai/controllers/ImplementController.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ function ImplementController:onFinished()
8787
--- override
8888
end
8989

90+
function ImplementController:onFinishRow(isHeadlandTurn)
91+
end
92+
93+
function ImplementController:onTurnEndProgress(workStartNode, isLeftTurn)
94+
end
95+
9096
--- Any object this controller wants us to ignore, can register here a callback at the proximity controller
9197
function ImplementController:registerIgnoreProximityObjectCallback(proximityController)
9298

scripts/ai/controllers/PlowController.lua

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,57 @@ function PlowController:getIsPlowRotationAllowed()
6666
return self.implement:getIsPlowRotationAllowed()
6767
end
6868

69+
function PlowController:isFullyRotated()
70+
local rotationAnimationTime = self.implement:getAnimationTime(self.plowSpec.rotationPart.turnAnimation)
71+
return rotationAnimationTime < 0.001 or rotationAnimationTime > 0.999
72+
end
73+
6974
--- Rotates the plow if possible.
7075
---@param shouldBeOnTheLeft boolean|nil
7176
function PlowController:rotate(shouldBeOnTheLeft)
7277
if self:isRotatablePlow() and self:getIsPlowRotationAllowed() then
7378
self.implement:setRotationMax(shouldBeOnTheLeft)
7479
end
80+
end
81+
82+
--- We rotate plows in 180º turns to the center so we can turn on a smaller radius. This is
83+
--- triggered by the onFinishRow and onTurnEndProgress controller events emitted by all
84+
--- CourseTurn and derived turns.
85+
--- With the Giants helper, plows are rotated by the onAIFieldWorkerTurnProgress event which
86+
--- we now only use in the KTurn (only 3-point hitch mounted plows use the KTurn, so all
87+
--- plow turns are covered)
88+
89+
--- This is called once when the row is finished and the turn is just about to start.
90+
--- Rotate the plow to the center position to allow for smaller turn radius (when not rotated,
91+
--- the tractor's back wheel touching the plow won't let us turn sharp enough, and thus
92+
--- using a lot of real estate for a turn.
93+
---@param isHeadlandTurn boolean true if this is a headland turn
94+
function PlowController:onFinishRow(isHeadlandTurn)
95+
-- no need to rotate to center on headland turns
96+
if self:isRotatablePlow() and not isHeadlandTurn then
97+
self.implement:setRotationCenter()
98+
end
99+
end
100+
101+
--- This is called in every loop when we approach the start of the row, the location where
102+
--- the plow must be lowered. Currently AIDriveStrategyFieldworkCourse takes care of the lowering,
103+
--- here we only make sure that the plow is rotated to the work position (from the center position)
104+
--- in time.
105+
---@param workStartNode number node where the work starts as calculated by TurnContext
106+
---@param isLeftTurn boolean is this a left turn?
107+
function PlowController:onTurnEndProgress(workStartNode, isLeftTurn)
108+
if self:isRotatablePlow() and not self:isFullyRotated() and not self:isRotationActive() then
109+
-- more or less aligned with the first waypoint of the row, start rotating to working position
110+
if CpMathUtil.isSameDirection(self.implement.rootNode, workStartNode, 30) then
111+
self.implement:setRotationMax(isLeftTurn)
112+
end
113+
end
114+
end
115+
116+
function PlowController:canContinueWork()
117+
if self:isRotatablePlow() then
118+
return self:isFullyRotated()
119+
else
120+
return true
121+
end
75122
end

scripts/ai/turns/AITurn.lua

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ function AITurn:finishRow(dt)
246246
-- keep driving straight until we need to raise our implements
247247
if self.driveStrategy:shouldRaiseImplements(self:getRaiseImplementNode()) then
248248
self.driveStrategy:raiseImplements()
249+
self.driveStrategy:raiseControllerEvent(AIDriveStrategyCourse.onFinishRowEvent, self.turnContext:isHeadlandCorner())
249250
self:debug('Row finished, starting turn.')
250251
self:startTurn()
251252
end
@@ -307,16 +308,12 @@ end
307308
function KTurn:startTurn()
308309
AITurn.startTurn(self)
309310
self.state = self.states.FORWARD
310-
self.vehicle:raiseAIEvent("onAIFieldWorkerTurnProgress", "onAIImplementTurnProgress", 0, self.turnContext:isLeftTurn())
311-
self:debug('Turn progress 0')
312311
end
313312

314313
function KTurn:turn(dt)
315314
-- we end the K turn with a temporary course leading straight into the next row. During this turn the
316315
-- AI driver's state remains TURNING and thus calls AITurn:drive() which wil take care of raising the implements
317316
local endTurn = function(course)
318-
self:debug('Turn progress 100')
319-
self.vehicle:raiseAIEvent("onAIFieldWorkerTurnProgress", "onAIImplementTurnProgress", 100, self.turnContext:isLeftTurn())
320317
self.state = self.states.ENDING_TURN
321318
self.ppc:setCourse(course)
322319
self.ppc:initialize(1)
@@ -346,7 +343,7 @@ function KTurn:turn(dt)
346343
endTurn(self.endingTurnCourse)
347344
else
348345
-- reverse until we can make turn to the turn end point
349-
self.vehicle:raiseAIEvent("onAIFieldWorkerTurnProgress", "onAIImplementTurnProgress", 50, self.turnContext:isLeftTurn())
346+
self.vehicle:raiseAIEvent("onAIFieldWorkerTurnProgress", "onAIImplementTurnProgress", 0.5, self.turnContext:isLeftTurn())
350347
self:debug('Turn progress 50')
351348
self.state = self.states.REVERSE
352349
self.endingTurnCourse = TurnEndingManeuver(self.vehicle, self.turnContext,
@@ -573,8 +570,6 @@ function CourseTurn:turn()
573570

574571
local gx, gz, moveForwards, maxSpeed = AITurn.turn(self)
575572

576-
self:updateTurnProgress()
577-
578573
self:changeDirectionWhenAligned()
579574
self:changeToFwdWhenWaypointReached()
580575

@@ -589,6 +584,8 @@ end
589584
---@return boolean true if it is ok the continue driving, false when the vehicle should stop
590585
function CourseTurn:endTurn(dt)
591586
-- keep driving on the turn course until we need to lower our implements
587+
self.driveStrategy:raiseControllerEvent(AIDriveStrategyCourse.onTurnEndProgressEvent,
588+
self.turnContext.workStartNode, self.turnContext:isLeftTurn())
592589
local shouldLower, dz = self.driveStrategy:shouldLowerImplements(self.turnContext.workStartNode, self.ppc:isReversing())
593590
if shouldLower then
594591
if not self.implementsLowered then
@@ -605,7 +602,7 @@ function CourseTurn:endTurn(dt)
605602
-- for those people who set insanely high turn speeds...
606603
local implementCheckDistance = math.max(1, 0.1 * self.vehicle:getLastSpeed())
607604
if dz and dz > -implementCheckDistance then
608-
if self.vehicle:getCanAIFieldWorkerContinueWork() then
605+
if self.driveStrategy:getCanContinueWork() then
609606
self:debug("implements lowered, resume fieldwork")
610607
self:resumeFieldworkAfterTurn(self.turnContext.turnEndWpIx)
611608
else
@@ -620,21 +617,6 @@ function CourseTurn:endTurn(dt)
620617
return true
621618
end
622619

623-
function CourseTurn:updateTurnProgress()
624-
if self.turnCourse and not self.turnContext:isHeadlandCorner() then
625-
-- turn progress is for example rotating plows, no need to worry about that during headland turns
626-
local progress = self.turnCourse:getCurrentWaypointIx() / self.turnCourse:getNumberOfWaypoints()
627-
if (progress - (self.lastProgress or 0)) > 0.1 then
628-
-- just send 0 and 1 as it looks like some plows won't turn fully if they receive something in between
629-
-- also, start turning a bit before we reach the middle of the turn to make sure it is ready
630-
local progressToSend = progress <= 0.3 and 0 or 1
631-
self.vehicle:raiseAIEvent("onAIFieldWorkerTurnProgress", "onAIImplementTurnProgress", progressToSend, self.turnContext:isLeftTurn())
632-
self:debug('progress %.1f (left: %s)', progressToSend, self.turnContext:isLeftTurn())
633-
self.lastProgress = progress
634-
end
635-
end
636-
end
637-
638620
function CourseTurn:onWaypointChange(ix)
639621
AITurn.onWaypointChange(self, ix)
640622
if self.turnCourse then
@@ -967,10 +949,6 @@ function FinishRowOnly:startTurn()
967949
end
968950
end
969951

970-
function FinishRowOnly:updateTurnProgress()
971-
-- do nothing since this isn't really a turn
972-
end
973-
974952
--- A turn which really isn't a turn just a course to start a field work row using the supplied course and
975953
--- making sure we start working at the start point defined by the turn context with all implements lowered in time.
976954
--- This does not actually drive the course like the other AITurn derivates to keep full control in the strategy
@@ -1045,7 +1023,7 @@ function StartRowOnly:getDriveData()
10451023
-- for those people who set insanely high turn speeds...
10461024
local implementCheckDistance = math.max(1, 0.1 * self.vehicle:getLastSpeed())
10471025
if dz and dz > -implementCheckDistance then
1048-
if self.vehicle:getCanAIFieldWorkerContinueWork() then
1026+
if self.driveStrategy:getCanContinueWork() then
10491027
self:debug("implements lowered, resume fieldwork")
10501028
self:resumeFieldworkAfterTurn(self.turnContext.turnEndWpIx)
10511029
else

0 commit comments

Comments
 (0)