-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathSoilSamplerController.lua
More file actions
65 lines (54 loc) · 1.88 KB
/
SoilSamplerController.lua
File metadata and controls
65 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--- Enables soil sampling for the precision farming dlc.
---@class SoilSamplerController : ImplementController
SoilSamplerController = CpObject(ImplementController)
function SoilSamplerController:init(vehicle, implement)
ImplementController.init(self, vehicle, implement)
local name = CpUtil.getSoilSamplerSpecName()
if name ~= nil then
self.soilSamplerSpec = implement[name]
else
CpUtil.errorImplement(implement, "Soil sampler is nil!")
end
self.lastSampleTaken = nil
-- The sampling radius is a hexagon, so we shrink this to roughly math a square.
self.distBetweenProbes = self.soilSamplerSpec.samplingRadius
self.isRaised = false
end
function SoilSamplerController:onLowering()
self:startSampling()
self.isRaised = false
end
function SoilSamplerController:onRaising()
self:startSampling()
self.isRaised = true
end
function SoilSamplerController:onStart()
self.implement:setFoldDirection(1)
end
function SoilSamplerController:onFinished()
self.implement:sendTakenSoilSamples()
end
function SoilSamplerController:getDriveData()
local maxSpeed = nil
if not self.lastSampleTaken then
maxSpeed = 0
if not self.soilSamplerSpec.isSampling then
local vx, _, vz = getWorldTranslation(self.soilSamplerSpec.samplingNode)
self.lastSampleTaken = {vx, vz, self.vehicle.lastMovedDistance}
self.implement:aiImplementEndLine()
end
elseif not self.isRaised then
local x, z, lastDistMoved = unpack(self.lastSampleTaken)
local vx, _, vz = getWorldTranslation(self.soilSamplerSpec.samplingNode)
if MathUtil.vector2Length(x-vx, z-vz) > self.distBetweenProbes or (self.vehicle.lastMovedDistance - lastDistMoved) > self.distBetweenProbes then
self:startSampling()
end
end
return nil, nil, nil, maxSpeed
end
function SoilSamplerController:startSampling()
if not self.soilSamplerSpec.isSampling then
self.implement:startSoilSampling()
self.lastSampleTaken = nil
end
end