diff --git a/AIDriver.lua b/AIDriver.lua index 2a64f41c2..2f8a65f2d 100644 --- a/AIDriver.lua +++ b/AIDriver.lua @@ -2052,8 +2052,11 @@ function AIDriver:checkProximitySensor(maxSpeed, allowedToDrive, moveForwards) -- check for nil and NaN if deg and deg == deg and self:isProximitySwerveEnabled(vehicle) and (not sameDirection or not vehicle:getIsCourseplayDriving()) then - local dx = dAvg * math.sin(math.rad(deg)) + local dx = dAvg * math.sin(math.rad(deg)) -- dx > 0 is left -- which direction to swerve (have a little bias for right, sorry UK folks :) + local gx, _, _ = self.ppc:getGoalPointLocalPosition() + local bias = gx - 1.2 + -- TODO: use bias here instead of -1.2 local dir = dx > -1.2 and 1 or -1 self:setInfoText('SLOWING_DOWN_FOR_TRAFFIC') self.ppc:setTemporaryShortLookaheadDistance(1000) @@ -2064,8 +2067,9 @@ function AIDriver:checkProximitySensor(maxSpeed, allowedToDrive, moveForwards) self.course:changeTemporaryOffsetX(offsetChange, 1000) -- always slow down when swerving newSpeed = slowSpeed - debug(AIDriver.psStateSwerve, 'dAvg = %.1f (%d), speed = %.1f, swerve dx = %.1f, setPoint = %.1f, error = %.1f, offsetChange = %.1f', - dAvg, 100 * normalizedD, newSpeed, dx, setPoint, error, offsetChange) + debug(AIDriver.psStateSwerve, + 'dAvg = %.1f (%d), speed = %.1f, swerve dx = %.1f, setPoint = %.1f, error = %.1f, offsetChange = %.1f, (%s)', + dAvg, 100 * normalizedD, newSpeed, dx, setPoint, error, offsetChange, nameNum(vehicle)) else if self:isProximitySlowDownEnabled(vehicle) then newSpeed = slowSpeed diff --git a/CombineUnloadAIDriver.lua b/CombineUnloadAIDriver.lua index b9fcf1673..030079efc 100644 --- a/CombineUnloadAIDriver.lua +++ b/CombineUnloadAIDriver.lua @@ -1684,18 +1684,27 @@ function CombineUnloadAIDriver:changeToUnloadWhenFull() end return false end ------------------------------------------------------------------------------------------------------------------------- --- Drive to stopped combine ------------------------------------------------------------------------------------------------------------------------- -function CombineUnloadAIDriver:driveToCombine() +function CombineUnloadAIDriver:checkForCombineProximity() -- do not swerve for our combine towards the end of the course, -- otherwise we won't be able to align with it when coming from -- the wrong angle if self.course:getDistanceToLastWaypoint(self.course:getCurrentWaypointIx()) < 20 then + if not self.doNotSwerveForVehicle:get() then + self:debug('Disable swerve for %s', nameNum(self.combineToUnload)) + end self.doNotSwerveForVehicle:set(self.combineToUnload, 2000) end +end + +------------------------------------------------------------------------------------------------------------------------ +-- Drive to stopped combine +------------------------------------------------------------------------------------------------------------------------ +function CombineUnloadAIDriver:driveToCombine() + + self:checkForCombineProximity() + courseplay:setInfoText(self.vehicle, "COURSEPLAY_DRIVE_TO_COMBINE"); self:setFieldSpeed() @@ -1711,12 +1720,8 @@ end -- Drive to moving combine ------------------------------------------------------------------------------------------------------------------------ function CombineUnloadAIDriver:driveToMovingCombine() - -- do not swerve for our combine towards the end of the course, - -- otherwise we won't be able to align with it when coming from - -- the wrong angle - if self.course:getDistanceToLastWaypoint(self.course:getCurrentWaypointIx()) < 20 then - self.doNotSwerveForVehicle:set(self.combineToUnload, 2000) - end + + self:checkForCombineProximity() courseplay:setInfoText(self.vehicle, "COURSEPLAY_DRIVE_TO_COMBINE"); diff --git a/DevHelper.lua b/DevHelper.lua index 4df273763..bb7cf826c 100644 --- a/DevHelper.lua +++ b/DevHelper.lua @@ -128,7 +128,9 @@ function DevHelper:updateProximitySensors(vehicle) if vehicle.cp.driver.forwardLookingProximitySensorPack then local d, otherVehicle, object, deg, dAvg = vehicle.cp.driver.forwardLookingProximitySensorPack:getClosestObjectDistanceAndRootVehicle() - end + --renderText(0.6, 0.4, 0.018, string.format('d=%.1f %s deg=%.1f dAvg=%.1f dx=%.1f (%s)', + -- d, nameNum(otherVehicle), deg, dAvg, dAvg * math.sin(math.rad(deg)), nameNum(vehicle))) + end if vehicle.cp.driver.backwardLookingProximitySensorPack then local d, otherVehicle, object, deg, dAvg = vehicle.cp.driver.backwardLookingProximitySensorPack:getClosestObjectDistanceAndRootVehicle() diff --git a/OverloaderAIDriver.lua b/OverloaderAIDriver.lua index 6a3b09069..603470655 100644 --- a/OverloaderAIDriver.lua +++ b/OverloaderAIDriver.lua @@ -132,9 +132,9 @@ function OverloaderAIDriver:isAugerPipeToolPositionsOkay(dt) return true end --- make sure we stay close to the trailer while overloading -function OverloaderAIDriver:isProximitySwerveEnabled() - return CombineUnloadAIDriver.isProximitySwerveEnabled(self) and not self.nearOverloadPoint +function OverloaderAIDriver:isProximitySwerveEnabled(vehicle) + -- make sure we stay close to the trailer while overloading + return CombineUnloadAIDriver.isProximitySwerveEnabled(self, vehicle) and not self.nearOverloadPoint end function OverloaderAIDriver:isProximitySpeedControlEnabled() diff --git a/modDesc.xml b/modDesc.xml index 6971eb307..776aa7443 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ - 6.03.00038 + 6.03.00039 <!-- en=English de=German fr=French es=Spanish ru=Russian pl=Polish it=Italian br=Brazilian-Portuguese cs=Chinese(Simplified) ct=Chinese(Traditional) cz=Czech nl=Netherlands hu=Hungary jp=Japanese kr=Korean pt=Portuguese ro=Romanian tr=Turkish --> <en>CoursePlay SIX</en>