Skip to content

Commit

Permalink
6.01.00197 Mode 4 and 6 improvements for Courseplay#3626
Browse files Browse the repository at this point in the history
Always use an alignment course when driving on the field a the waypoint
on the field to start work.

Use animation durations to figure out how long it takes to lower tools.
For now, don't use the measured time as it was unreliable.
  • Loading branch information
pvaiko committed Apr 27, 2019
1 parent 2249764 commit 3252242
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion AIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ end
function AIDriver:startCourseWithAlignment(course, ix)
self.turnIsDriving = false
local alignmentCourse = nil
if self.vehicle.cp.alignment.enabled and self:isAlignmentCourseNeeded(course, ix) then
if self:isAlignmentCourseNeeded(course, ix) then
alignmentCourse = self:setUpAlignmentCourse(course, ix)
end
if alignmentCourse then
Expand Down
59 changes: 52 additions & 7 deletions FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ function FieldworkAIDriver:init(vehicle)
self.heldForUnloadRefillTimestamp = 0
-- stop and raise implements while refilling/unloading on field
self.stopImplementsWhileUnloadOrRefillOnField = true
-- time to lower all implements. This is a default value and will
-- be adjusted by the driver as it learns and then used to start lowering implements in time
-- so they reach the working position before the row starts.
self.loweringDurationMs = 3000
-- duration of the last turn maneuver. This is a default value and the driver will measure
-- the actual turn times. Used to calculate the remaining fieldwork time
self.turnDurationMs = 20000
Expand Down Expand Up @@ -140,6 +136,11 @@ end
function FieldworkAIDriver:start(ix)
self:debug('Starting in mode %d', self.mode)
self:beforeStart()
-- time to lower all implements
self:findLoweringDurationMs()
-- always enable alignment with first waypoint, this is needed to properly start/continue fieldwork
self.alignmentEnabled = self.vehicle.cp.alignment.enabled
self.vehicle.cp.alignment.enabled = true
-- stop at the last waypoint by default
self.vehicle.cp.stopAtEnd = true
-- any offset imposed by the driver itself (tight turns, end of course, etc.), addtional to any
Expand Down Expand Up @@ -185,6 +186,8 @@ end
function FieldworkAIDriver:stop(msgReference)
self:stopWork()
AIDriver.stop(self, msgReference)
-- Restore alignment settings. TODO: remove this setting from the HUD and always enable it
self.vehicle.cp.alignment.enabled = self.alignmentEnabled
end

function FieldworkAIDriver:drive(dt)
Expand Down Expand Up @@ -232,7 +235,6 @@ function FieldworkAIDriver:driveFieldwork()
self:debug('all tools ready, start working')
self.fieldworkState = self.states.WORKING
self:setSpeed(self:getFieldSpeed())
self:calculateLoweringDuration()
else
self:debugSparse('waiting for all tools to lower')
self:setSpeed(0)
Expand Down Expand Up @@ -406,7 +408,8 @@ function FieldworkAIDriver:onWaypointPassed(ix)
end

function FieldworkAIDriver:onWaypointChange(ix)
self:debug('onWaypointChange %d', ix)
self:debug('onWaypointChange %d, connecting: %s, temp: %s',
ix, tostring(self.course:isOnConnectingTrack(ix)), tostring(self.states == self.states.TEMPORARY))
if self.state == self.states.ON_FIELDWORK_COURSE then
self:updateRemainingTime(ix)
self:calculateTightTurnOffset()
Expand Down Expand Up @@ -821,7 +824,6 @@ function FieldworkAIDriver:lowerImplements()
implement.object:aiImplementStartLine()
end
self.vehicle:raiseStateChange(Vehicle.STATE_CHANGE_AI_START_LINE)
self:startLoweringDurationTimer()
end

function FieldworkAIDriver:raiseImplements()
Expand Down Expand Up @@ -853,3 +855,46 @@ function FieldworkAIDriver:getCanShowDriveOnButton()
return self.state == self.states.ON_FIELDWORK_COURSE
end

function FieldworkAIDriver:getLoweringDurationMs()
return self.loweringDurationMs
end

function FieldworkAIDriver:findLoweringDurationMs()
local function getLoweringDurationMs(object)
if object.spec_animatedVehicle then
-- TODO: implement these in the specifications?
return math.max(object.spec_animatedVehicle:getAnimationDuration('lowerAnimation'),
object.spec_animatedVehicle:getAnimationDuration('rotatePickup'))
else
return 0
end
end

self.loweringDurationMs = getLoweringDurationMs(self.vehicle)
self:debug('Lowering duration: %d ms', self.loweringDurationMs)

-- check all implements first
local implements = self.vehicle:getAttachedImplements()
for _, implement in ipairs(implements) do
local implementLoweringDurationMs = getLoweringDurationMs(implement.object)
self:debug('Lowering duration (%s): %d ms', implement.object:getName(), implementLoweringDurationMs)
if implementLoweringDurationMs > self.loweringDurationMs then
self.loweringDurationMs = implementLoweringDurationMs
end
local jointDescIndex = implement.jointDescIndex
-- now check the attacher joints
if self.vehicle.spec_attacherJoints and jointDescIndex then
local ajs = self.vehicle.spec_attacherJoints:getAttacherJoints()
local ajLoweringDurationMs = ajs[jointDescIndex] and ajs[jointDescIndex].moveDefaultTime or 0
self:debug('Lowering duration (%s attacher joint): %d ms', implement.object:getName(), ajLoweringDurationMs)
if ajLoweringDurationMs > self.loweringDurationMs then
self.loweringDurationMs = ajLoweringDurationMs
end
end
end
if not self.loweringDurationMs or self.loweringDurationMs <= 1 then
self.loweringDurationMs = 2000
self:debug('No lowering duration found, setting to: %d ms', self.loweringDurationMs)
end
self:debug('Final lowering duration: %d ms', self.loweringDurationMs)
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="40">
<version>6.01.00196</version>
<version>6.01.00197</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title>
<br>CoursePlay SIX</br>
Expand Down

0 comments on commit 3252242

Please sign in to comment.