Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
6.03.00032 Convoy and attach/detach fixes
Browse files Browse the repository at this point in the history
- Better progress calculation for convoy mode (fixes #6011)
- Reset mode when detaching/attaching implements (fixes #6727). This caused
some implements not reversing correctly.
  • Loading branch information
pvaiko committed Jan 26, 2021
1 parent e66886d commit 4f317d1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
44 changes: 38 additions & 6 deletions Waypoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ function Course:init(vehicle, waypoints, temporary, first, last)
self.currentWaypoint = 1
self.length = 0
self.headlandLength = 0
self.nHeadlandWaypoints = 0
self.totalTurns = 0
self:enrichWaypointData()
end
Expand All @@ -276,6 +275,7 @@ function Course.createFromGeneratedCourse(vehicle, waypoints, temporary, first,
for i = first or 1, last or #waypoints do
table.insert(course.waypoints, Waypoint.initFromGeneratedWp(waypoints[i], i))
end
course:enrichWaypointData()
return course
end

Expand Down Expand Up @@ -350,24 +350,24 @@ end
function Course:enrichWaypointData()
if #self.waypoints < 2 then return end
self.length = 0
self.nHeadlandWaypoints = 0
self.headlandLength = 0
self.firstHeadlandWpIx = nil
self.firstCenterWpIx = nil
local dOnHeadland = 0
for i = 1, #self.waypoints - 1 do
local cx, _, cz = self:getWaypointPosition(i)
local nx, _, nz = self:getWaypointPosition( i + 1)
local nx, _, nz = self:getWaypointPosition(i + 1)
local dToNext = courseplay:distance(cx, cz, nx, nz)
self.length = self.length + dToNext
if self:isOnHeadland(i) then
self.nHeadlandWaypoints = self.nHeadlandWaypoints + 1
self.headlandLength = self.headlandLength + dToNext
self.firstHeadlandWpIx = self.firstHeadlandWpIx or i
dOnHeadland = dOnHeadland + dToNext
else
-- TODO: this and firstHeadlandWpIx works only if there is one block on the field and
-- no islands, as then we have more than one group of headlands. But these are only
-- for the convoy mode anyway so it is ok if it does not work in all possible situations
self.firstCenterWpIx = self.firstCenterWpIx or i
self.firstCenterWpIx = self.firstCenterWpIx or i
end
if self:isTurnStartAtIx(i) then self.totalTurns = self.totalTurns + 1 end
if self:isTurnEndAtIx(i) then
Expand All @@ -377,6 +377,7 @@ function Course:enrichWaypointData()
end
self.waypoints[i].dToNext = dToNext
self.waypoints[i].dToHere = self.length
self.waypoints[i].dToHereOnHeadland = dOnHeadland
self.waypoints[i].turnsToHere = self.totalTurns
self.waypoints[i].dx, _, self.waypoints[i].dz, _ = courseplay:getWorldDirection(cx, 0, cz, nx, 0, nz)
local dx, dz = MathUtil.vector2Normalize(nx - cx, nz - cz)
Expand Down Expand Up @@ -405,6 +406,9 @@ function Course:enrichWaypointData()
self.waypoints[#self.waypoints].dz = self.waypoints[#self.waypoints - 1].dz
self.waypoints[#self.waypoints].dToNext = 0
self.waypoints[#self.waypoints].dToHere = self.length + self.waypoints[#self.waypoints - 1].dToNext
self.waypoints[#self.waypoints].dToHereOnHeadland = self:isOnHeadland(#self.waypoints - 1) and
self.waypoints[#self.waypoints - 1].dToHereOnHeadland + self.waypoints[#self.waypoints - 1].dToNext or
self.waypoints[#self.waypoints - 1].dToHereOnHeadland
self.waypoints[#self.waypoints].turnsToHere = self.totalTurns
self.waypoints[#self.waypoints].calculatedRadius = self:calculateRadius(#self.waypoints)
self.waypoints[#self.waypoints].reverseOffset = self:isReverseAt(#self.waypoints)
Expand Down Expand Up @@ -1390,6 +1394,20 @@ function Course:calculateOffsetCourse(nVehicles, position, width, useSameTurnWid
end
end
end
courseplay.debugFormat(7, 'Original headland length %.0f m, new headland length %.0f m (%.1f %%, %.1f m)',
self.headlandLength, offsetCourse.headlandLength, 100 * offsetCourse.headlandLength / self.headlandLength,
offsetCourse.headlandLength - self.headlandLength)
local originalNonHeadlandLength = self.length - self.headlandLength
local offsetNonHeadlandLength = offsetCourse.length - offsetCourse.headlandLength
courseplay.debugFormat(7, 'Original non-headland length %.0f m, new non-headland length %.0f m (%.1f %%, %.1f m)',
originalNonHeadlandLength, offsetNonHeadlandLength,
100 * offsetNonHeadlandLength / originalNonHeadlandLength,
offsetNonHeadlandLength - originalNonHeadlandLength)
-- remember this for the convoy progress calculation
offsetCourse.headlandLengthRatio = self.headlandLength / offsetCourse.headlandLength
offsetCourse.nonHeadlandLengthRatio = originalNonHeadlandLength / offsetNonHeadlandLength
offsetCourse.originalCourseLength = offsetCourse.nonHeadlandLengthRatio * offsetNonHeadlandLength
+ offsetCourse.headlandLengthRatio * offsetCourse.headlandLength
-- apply tool offset to new course
offsetCourse:setOffset(self.offsetX, self.offsetZ)
return offsetCourse
Expand Down Expand Up @@ -1519,6 +1537,20 @@ end

function Course:getProgress(ix)
ix = ix or self:getCurrentWaypointIx()
return self.waypoints[ix].dToHere / self.length
if self.originalCourseLength then
-- this is an offset course, measure progress in the original course
-- we assume that the non-headland part of the course is the same as the original ...
local dToHereOnNonHeadland = self.waypoints[ix].dToHere - self.waypoints[ix].dToHereOnHeadland
-- however, the headland part is shorter or longer for the inner and outer offsets (when using multiple tools
-- on the same field in a group, for example 3 combines, one on the original course, on on the left, one on
-- the right. When working clockwise, the headland for one on the right is shorter.
-- So, we project the distance elapsed on the actual offset headland back to the distance elapsed on the
-- original headland.
local dToHere = self.nonHeadlandLengthRatio * dToHereOnNonHeadland +
self.headlandLengthRatio * self.waypoints[ix].dToHereOnHeadland
return dToHere / self.originalCourseLength
else
return self.waypoints[ix].dToHere / self.length
end
end

2 changes: 1 addition & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="47">
<version>6.03.00031</version>
<version>6.03.00032</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title><!-- 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>
Expand Down
4 changes: 3 additions & 1 deletion test/mock-GiantsEngine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ function giantsVehicle.getSpeedLimit()
return 10
end

function giantsVehicle.setCruiseControlMaxSpeed() end
function giantsVehicle.setCruiseControlMaxSpeed() end

g_time = 0
6 changes: 3 additions & 3 deletions toolManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function courseplay:resetTools(vehicle)
vehicle.cp.hasAugerWagon = false;

vehicle.cp.workToolAttached = courseplay:updateWorkTools(vehicle, vehicle);
if not vehicle.cp.workToolAttached and not vehicle.cp.mode == courseplay.MODE_BUNKERSILO_COMPACTER then

This comment has been minimized.

Copy link
@pvaiko

pvaiko Jan 26, 2021

Author Contributor

@schwiti6190 this here was the problem :)

if not vehicle.cp.workToolAttached and vehicle.cp.mode ~= courseplay.MODE_BUNKERSILO_COMPACTER then
courseplay:setCpMode(vehicle, courseplay.MODE_TRANSPORT)
end

Expand Down Expand Up @@ -477,7 +477,7 @@ function courseplay:getAIMarkerWidth(object, logPrefix)
end
end

--this one enable the buttons and allowes the user to change the mode
--this one enable the buttons and allows the user to change the mode
function courseplay:getIsToolCombiValidForCpMode(vehicle,cpModeToCheck)
--5 is always valid
if cpModeToCheck == 5 then
Expand All @@ -493,7 +493,7 @@ function courseplay:getIsToolCombiValidForCpMode(vehicle,cpModeToCheck)
end

function courseplay:getIsToolValidForCpMode(object, mode, callback)
isAllowedOkay,isDisallowedOkay = CpManager.validModeSetupHandler:isModeValid(mode,object)
local isAllowedOkay,isDisallowedOkay = CpManager.validModeSetupHandler:isModeValid(mode,object)
callback.isAllowedOkay = callback.isAllowedOkay or isAllowedOkay
callback.isDisallowedOkay = callback.isDisallowedOkay and isDisallowedOkay
for _,impl in pairs(object:getAttachedImplements()) do
Expand Down

0 comments on commit 4f317d1

Please sign in to comment.