@@ -24,6 +24,7 @@ AIDriveStrategyFieldWorkCourse = CpObject(AIDriveStrategyCourse)
2424
2525AIDriveStrategyFieldWorkCourse .myStates = {
2626 WORKING = {},
27+ PREPARING = {},
2728 WAITING_FOR_LOWER = {},
2829 WAITING_FOR_LOWER_DELAYED = {},
2930 WAITING_FOR_STOP = {},
@@ -89,19 +90,11 @@ function AIDriveStrategyFieldWorkCourse:start(course, startIx, jobParameters)
8990 self :debug (' Close enough to start waypoint %d, no alignment course needed' , startIx )
9091 self :startCourse (course , startIx )
9192 self .state = self .states .INITIAL
92- self :prepareForFieldWork ()
9393 end
9494 --- Store a reference to the original generated course
9595 self .originalGeneratedFieldWorkCourse = self .vehicle :getFieldWorkCourse ()
9696end
9797
98- --- If the strategy needs a field polygon to work, it won't transition out of the INITIAL state
99- --- until the field detection, an asynchronous process that may have started only when the job was started, is finished.
100- --- @return boolean true if the strategy needs the field polygon to work
101- function AIDriveStrategyFieldWorkCourse :needsFieldPolygon ()
102- return false
103- end
104-
10598--- Make sure all implements are in the working state
10699function AIDriveStrategyFieldWorkCourse :prepareForFieldWork ()
107100 self .vehicle :raiseAIEvent (' onAIFieldWorkerPrepareForWork' , ' onAIImplementPrepareForWork' )
@@ -164,6 +157,10 @@ function AIDriveStrategyFieldWorkCourse:getDriveData(dt, vX, vY, vZ)
164157 end
165158 ---- ------------------------------------------------------------
166159 if self .state == self .states .INITIAL then
160+ self :setMaxSpeed (0 )
161+ self :prepareForFieldWork ()
162+ self .state = self .states .PREPARING
163+ elseif self .state == self .states .PREPARING then
167164 self :setMaxSpeed (0 )
168165 self :startWaitingForLower ()
169166 self :lowerImplements ()
@@ -328,7 +325,7 @@ function AIDriveStrategyFieldWorkCourse:onWaypointChange(ix, course)
328325 self :calculateTightTurnOffset ()
329326 if not self .state ~= self .states .TURNING
330327 and self .course :isTurnStartAtIx (ix ) then
331- if self .state == self .states .INITIAL then
328+ if self .state == self .states .INITIAL or self . state == self . states . PREPARING then
332329 self :debug (' Waypoint change (%d) to turn start right after starting work, lowering implements.' , ix )
333330 self :startWaitingForLower ()
334331 self :lowerImplements ()
@@ -483,8 +480,8 @@ function AIDriveStrategyFieldWorkCourse:startAlignmentTurn(fieldWorkCourse, star
483480 alignmentCourse = self :createAlignmentCourse (fieldWorkCourse , startIx )
484481 end
485482 self .ppc :setShortLookaheadDistance ()
486- self :prepareForFieldWork ()
487483 if alignmentCourse then
484+ self :prepareForFieldWork ()
488485 local fm , bm = self :getFrontAndBackMarkers ()
489486 self .turnContext = RowStartOrFinishContext (self .vehicle , fieldWorkCourse , startIx , startIx , self .turnNodes ,
490487 self :getWorkWidth (), fm , bm , self :getTurnEndSideOffset (false ), self :getTurnEndForwardOffset ())
@@ -495,7 +492,6 @@ function AIDriveStrategyFieldWorkCourse:startAlignmentTurn(fieldWorkCourse, star
495492 self :debug (' Could not create alignment course to first up/down row waypoint, continue without it' )
496493 self :startCourse (fieldWorkCourse , startIx )
497494 self .state = self .states .INITIAL
498- self :prepareForFieldWork ()
499495 end
500496end
501497
0 commit comments