@@ -50,15 +50,15 @@ function AIDriveStrategyPlowCourse:getDriveData(dt, vX, vY, vZ)
5050 --- we still need to check if the rotation
5151 --- is in correct direction, as the course generator directed.
5252 self :rotatePlows ()
53- self :debug (" Needs to wait until the plow has finished rotating." )
54- self .state = self .states .ROTATING_PLOW
55- else
53+ self :debug (" Needs to wait until the plow has finished rotating." )
54+ self .state = self .states .ROTATING_PLOW
55+ else
5656 --- The plow can not be rotated,
5757 --- so we check if the plow is unfolded
5858 --- and try again to rotate the plow in the correct direction.
5959 self :debug (" Plows have to be unfolded first!" )
60- self .state = self .states .UNFOLDING_PLOW
61- end
60+ self .state = self .states .UNFOLDING_PLOW
61+ end
6262 elseif self .state == self .states .ROTATING_PLOW then
6363 self :setMaxSpeed (0 )
6464 if not self :isPlowRotating () then
@@ -70,13 +70,13 @@ function AIDriveStrategyPlowCourse:getDriveData(dt, vX, vY, vZ)
7070 end
7171 elseif self .state == self .states .UNFOLDING_PLOW then
7272 self :setMaxSpeed (0 )
73- if self :isPlowRotationAllowed () then
73+ if self :isPlowRotationAllowed () then
7474 --- The Unfolding has finished and
7575 --- we need to check if the rotation is correct.
7676 self :rotatePlows ()
7777 self :debug (" Plow was unfolded and rotation can begin" )
78- self .state = self .states .ROTATING_PLOW
79- elseif self :getCanContinueWork () then
78+ self .state = self .states .ROTATING_PLOW
79+ elseif self :getCanContinueWork () then
8080 --- Unfolding has finished and no extra rotation is needed.
8181 self :updatePlowOffset ()
8282 self :startWaitingForLower ()
104104--- Updates the X Offset based on the plows attached.
105105function AIDriveStrategyPlowCourse :updatePlowOffset ()
106106 local xOffset = 0
107- for _ , controller in pairs (self .controllers ) do
107+ for _ , controller in pairs (self .controllers ) do
108108 if controller .getAutomaticXOffset then
109109 local autoOffset = controller :getAutomaticXOffset ()
110110 if autoOffset == nil then
127127--- Is a plow currently rotating?
128128--- @return boolean
129129function AIDriveStrategyPlowCourse :isPlowRotating ()
130- for _ , controller in pairs (self .controllers ) do
131- if controller .isRotationActive and controller :isRotationActive () then
130+ for _ , controller in pairs (self .controllers ) do
131+ if controller .isRotationActive and controller :isRotationActive () then
132132 return true
133133 end
134134 end
139139--- @return boolean
140140function AIDriveStrategyPlowCourse :isPlowRotationAllowed ()
141141 local allowed = true
142- for _ , controller in pairs (self .controllers ) do
143- if controller .getIsPlowRotationAllowed and not controller :getIsPlowRotationAllowed () then
142+ for _ , controller in pairs (self .controllers ) do
143+ if controller .getIsPlowRotationAllowed and not controller :getIsPlowRotationAllowed () then
144144 allowed = false
145145 end
146146 end
@@ -153,29 +153,45 @@ function AIDriveStrategyPlowCourse:rotatePlows()
153153 local ix = self .ppc :getCurrentWaypointIx ()
154154 local plowShouldBeOnTheLeft = self .course :shouldPlowBeOnTheLeft (ix )
155155 for _ , controller in pairs (self .controllers ) do
156- if controller .rotate then
156+ if controller .rotate then
157157 controller :rotate (plowShouldBeOnTheLeft )
158158 end
159159 end
160160end
161161
162+ --- Do we have at least one plow that can be rotated?
163+ --- @return boolean
164+ function AIDriveStrategyPlowCourse :haveRotatablePlow ()
165+ for _ , controller in pairs (self .controllers ) do
166+ if controller .isRotatablePlow and controller :isRotatablePlow () then
167+ return true
168+ end
169+ end
170+ return false
171+ end
172+
162173---- -------------------------------------------------------------------------------------------------------------------
163174--- Dynamic parameters (may change while driving)
164175---- -------------------------------------------------------------------------------------------------------------------
165- function AIDriveStrategyPlowCourse :getTurnEndSideOffset ()
166- if self :isWorking () then
176+ function AIDriveStrategyPlowCourse :getTurnEndSideOffset (isHeadlandTurn )
177+ -- on headland turns we do not rotate the plow, and since the course already has the offset, nothing to do,
178+ -- the context will calculate with the offset of the course already, no additional side offset is needed
179+ if self :isWorking () and not isHeadlandTurn and self :haveRotatablePlow () then
167180 self :updatePlowOffset ()
168- -- need the double tool offset as the turn end still has the current offset, after the rotation it'll be
169- -- on the other side, (one toolOffsetX would put it to 0 only)
181+ -- need the double tool offset as the turn end waypoint still has the current offset, but after rotating,
182+ -- the plow will be on the other side, (one toolOffsetX would put it to 0 only)
183+ self :debug (' Setting turn end side offset to %.2f for the plow' , 2 * self .aiOffsetX )
170184 return 2 * self .aiOffsetX
171185 else
186+ self :debug (' No turn end side offset, working: %s, headland turn %s, have rotatable plow %s ' ,
187+ tostring (self :isWorking ()), tostring (isHeadlandTurn ), tostring (self :haveRotatablePlow ()))
172188 return 0
173189 end
174190end
175191
176192function AIDriveStrategyPlowCourse :updateFieldworkOffset (course )
177- --- Ignore the tool offset setting.
178- course :setOffset ((self .aiOffsetX or 0 ), (self .aiOffsetZ or 0 ))
193+ --- Ignore the tool offset setting.
194+ course :setOffset ((self .aiOffsetX or 0 ), (self .aiOffsetZ or 0 ))
179195end
180196
181197--- When we return from a turn, the offset is reverted and should immediately set, not waiting
0 commit comments