Skip to content

Commit d53d013

Browse files
author
Peter Vaiko
committed
feat: export headland to CSV
1 parent 82c6e57 commit d53d013

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

Exporter.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Export the generated course or parts of it
2+
Exporter = CpObject()
3+
4+
---@param fieldworkCourse CourseGenerator.FieldworkCourse
5+
function Exporter:init(fieldworkCourse)
6+
self.fieldworkCourse = fieldworkCourse
7+
end
8+
9+
--- Export a headland as a CSV file. Only includes the given headland, without the
10+
---@param headlandNumber number The headland to export, 1 ist the outermost
11+
---@param filename string The filename to save the CSV file as, under the export/ directory
12+
function Exporter:exportHeadlandAsCsv(headlandNumber, filename)
13+
local file = io.open('export/' .. filename, 'w')
14+
for _, v in self.fieldworkCourse:getHeadlandPath():vertices() do
15+
if v:getAttributes():getHeadlandPassNumber() == headlandNumber and
16+
not v:getAttributes():isHeadlandTransition() and
17+
not v:getAttributes():isOnConnectingPath() then
18+
file:write(string.format('%.2f,%.2f\n', v.x, v.y))
19+
end
20+
end
21+
file:close()
22+
end

export/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.gitignore

include.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ package.path = package.path .. ";FS25_Courseplay/scripts/courseGenerator/Genetic
99
dofile('FS25_Courseplay/scripts/courseGenerator/test/require.lua')
1010
require('AdjustableParameter')
1111
require('ToggleParameter')
12-
require('ListParameter')
12+
require('ListParameter')
13+
require('Exporter')

main.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010
--
1111
--
1212
dofile('include.lua')
13-
require('pathfinder.pathfinder')
1413

1514
local logger = Logger('main', Logger.level.debug)
1615
local parameters = {}
1716
-- working width of the equipment
18-
local workingWidth = AdjustableParameter(10, 'width', 'W', 'w', 0.1, 0, 100)
17+
local workingWidth = AdjustableParameter(5, 'width', 'W', 'w', 0.1, 0, 100)
1918
table.insert(parameters, workingWidth)
20-
local turningRadius = AdjustableParameter(7, 'radius', 'T', 't', 0.1, 0, 20)
19+
local turningRadius = AdjustableParameter(3, 'radius', 'T', 't', 0.1, 0, 20)
2120
table.insert(parameters, turningRadius)
2221
local fieldMargin = AdjustableParameter(0, 'margin', 'N', 'n', 0.1, -5, 5)
2322
table.insert(parameters, fieldMargin)
2423
-- number of headland passes around the field boundary
2524
local nHeadlandPasses = AdjustableParameter(1, 'headlands', 'P', 'p', 1, 0, 100)
2625
table.insert(parameters, nHeadlandPasses)
27-
local nHeadlandsWithRoundCorners = AdjustableParameter(2, 'headlands with round corners', 'R', 'r', 1, 0, 100)
26+
local nHeadlandsWithRoundCorners = AdjustableParameter(0, 'headlands with round corners', 'R', 'r', 1, 0, 100)
2827
table.insert(parameters, nHeadlandsWithRoundCorners)
2928
local headlandClockwise = ToggleParameter('headlands clockwise', true, 'c')
3029
table.insert(parameters, headlandClockwise)
@@ -83,7 +82,7 @@ local reverseCourse = ToggleParameter('reverse', false, 'v', true)
8382
table.insert(parameters, reverseCourse)
8483
local smallOverlaps = ToggleParameter('small overlaps', false, 'm', true)
8584
table.insert(parameters, smallOverlaps)
86-
local nVehicles = AdjustableParameter(2, 'number of vehicles', 'Y', 'y', 1, 1, 5)
85+
local nVehicles = AdjustableParameter(1, 'number of vehicles', 'Y', 'y', 1, 1, 5)
8786
table.insert(parameters, nVehicles)
8887
local useSameTurnWidth = ToggleParameter('use same turn width', false, 'u')
8988
table.insert(parameters, useSameTurnWidth)
@@ -229,6 +228,9 @@ local function generate()
229228
love.profiler.reset()
230229
love.profiler.stop()
231230
end
231+
-- export the first headland as CSV
232+
local exporter = Exporter(course)
233+
exporter:exportHeadlandAsCsv(1, 'headland-1.csv')
232234
-- make sure all logs are now visible
233235
io.stdout:flush()
234236
errors = context:getErrors()

0 commit comments

Comments
 (0)