Skip to content

Commit 83a8c1b

Browse files
author
Peter Vaiko
committed
test: include path
1 parent d8bf0c3 commit 83a8c1b

6 files changed

Lines changed: 11605 additions & 210 deletions

File tree

.github/workflows/unit-test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
luaVersion: "5.2.4"
3232
- name: Run unit tests
3333
run: |
34-
cd FS25_Courseplay/scripts/courseGenerator/test
34+
pushd FS25_Courseplay/scripts/courseGenerator/test
3535
lua BlockSequencerTest.lua
3636
lua CacheMapTest.lua
3737
lua FieldTest.lua
@@ -48,5 +48,6 @@ jobs:
4848
lua TransformTest.lua
4949
lua VertexTest.lua
5050
lua WrapAroundIndexTest.lua
51-
cd FS25_Courseplay/scripts/pathfinder/test
51+
popd
52+
pushd FS25_Courseplay/scripts/pathfinder/test
5253
lua GraphPathfinderTest.lua

include.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package.path = package.path .. ";FS25_Courseplay/scripts/?.lua"
22
package.path = package.path .. ";FS25_Courseplay/scripts/util/?.lua"
33
package.path = package.path .. ";FS25_Courseplay/scripts/test/?.lua"
4+
package.path = package.path .. ";FS25_Courseplay/scripts/graph/?.lua"
45
package.path = package.path .. ";FS25_Courseplay/scripts/pathfinder/?.lua"
56
package.path = package.path .. ";FS25_Courseplay/scripts/geometry/?.lua"
67
package.path = package.path .. ";FS25_Courseplay/scripts/courseGenerator/?.lua"

main.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ dofile('include.lua')
1414
local logger = Logger('main', Logger.level.debug)
1515
local parameters = {}
1616
-- working width of the equipment
17-
local workingWidth = AdjustableParameter(12, 'width', 'W', 'w', 0.1, 0, 100)
17+
local workingWidth = AdjustableParameter(6, 'width', 'W', 'w', 0.1, 0, 100)
1818
table.insert(parameters, workingWidth)
1919
local turningRadius = AdjustableParameter(5, 'radius', 'T', 't', 0.1, 0, 20)
2020
table.insert(parameters, turningRadius)
2121
local fieldMargin = AdjustableParameter(0, 'margin', 'N', 'n', 0.1, -5, 5)
2222
table.insert(parameters, fieldMargin)
2323
-- number of headland passes around the field boundary
24-
local nHeadlandPasses = AdjustableParameter(4, 'headlands', 'P', 'p', 1, 0, 100)
24+
local nHeadlandPasses = AdjustableParameter(3, 'headlands', 'P', 'p', 1, 0, 100)
2525
table.insert(parameters, nHeadlandPasses)
2626
local nHeadlandsWithRoundCorners = AdjustableParameter(1, 'headlands with round corners', 'R', 'r', 1, 0, 100)
2727
table.insert(parameters, nHeadlandsWithRoundCorners)
@@ -45,7 +45,7 @@ local autoRowAngle = ToggleParameter('auto row angle', true, '6')
4545
table.insert(parameters, autoRowAngle)
4646
local rowAngleDeg = AdjustableParameter(0, 'row angle', 'A', 'a', 10, -90, 90)
4747
table.insert(parameters, rowAngleDeg)
48-
local rowPattern = ListParameter(CourseGenerator.RowPattern.ALTERNATING, 'row pattern', 'O', 'o',
48+
local rowPattern = ListParameter(CourseGenerator.RowPattern.LANDS, 'row pattern', 'O', 'o',
4949
{ CourseGenerator.RowPattern.ALTERNATING,
5050
CourseGenerator.RowPattern.SKIP,
5151
CourseGenerator.RowPattern.SPIRAL,
@@ -60,7 +60,7 @@ local rowPattern = ListParameter(CourseGenerator.RowPattern.ALTERNATING, 'row pa
6060
'racetrack'
6161
})
6262
table.insert(parameters, rowPattern)
63-
local nRows = AdjustableParameter(1, 'rows to skip/rows per land', 'K', 'k', 1, 0, 10)
63+
local nRows = AdjustableParameter(3, 'rows to skip/rows per land', 'K', 'k', 1, 0, 10)
6464
table.insert(parameters, nRows)
6565
local leaveSkippedRowsUnworked = ToggleParameter('skipped rows unworked', false, 'u')
6666
table.insert(parameters, leaveSkippedRowsUnworked)

pathfinder/main.lua

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--[[
2-
32
LOVE app to test the Courseplay turn maneuvers and pathfinding
43
4+
55
]]--
66

77
dofile( 'include.lua' )
@@ -17,18 +17,19 @@ require('Waypoint')
1717
require('Course')
1818
require('ai.util.AIUtil')
1919
require('pathfinder.pathfinder')
20-
dofile('pathfinder/network.lua')
2120

2221
local parameterNameColor = { 1, 1, 1 }
2322
local parameterKeyColor = { 0, 1, 1 }
2423
local parameterValueColor = { 1, 1, 0 }
2524

26-
local startHeading = 2 * math.pi / 4
27-
local startPosition = State3D(185, 135, startHeading, 0)
25+
local startHeading = 4 * math.pi / 4
26+
local startPosition = State3D(-25, 25, startHeading, 0)
27+
local startPosition = State3D(185, 139, startHeading, 0)
2828
local lastStartPosition = State3D.copy(startPosition)
2929

30-
local goalHeading = 6 * math.pi / 4
31-
local goalPosition = State3D(126, 100, goalHeading, 0)
30+
local goalHeading = 4 * math.pi / 4
31+
local goalPosition = State3D(-360, 65, goalHeading, 0)
32+
local goalPosition = State3D(153, 201, goalHeading, 0)
3233
local lastGoalPosition = State3D.copy(goalPosition)
3334

3435
local vehicle
@@ -41,14 +42,14 @@ table.insert(parameters, turningRadius)
4142

4243
local hybrid = ToggleParameter('hybrid', true, 'h')
4344
table.insert(parameters, hybrid)
44-
local penalty = AdjustableParameter(20, 'Penalty', 'P', 'p', 5, -100, 100)
45+
local penalty = AdjustableParameter(400, 'Penalty', 'P', 'p', 5, -100, 100)
4546
table.insert(parameters, penalty)
4647
local stepSize = AdjustableParameter(1, 'Dubins step size', 'D', 'd', 0.05, 0.1, 2)
4748
table.insert(parameters, stepSize)
4849

4950
startPosition:setTrailerHeading(startHeading)
5051

51-
local scale, width, height = 5, 800, 360
52+
local scale, width, height = 3, 800, 360
5253
local xOffset, yOffset = -100 + width / scale / 4, 100 + height / scale
5354

5455
local vehicleData ={name = 'name', turningRadius = turningRadius:get(), dFront = 4, dRear = 2, dLeft = 1.5, dRight = 1.5}
@@ -63,8 +64,6 @@ local rsSolver = ReedsSheppSolver()
6364
local dubinsSolver = DubinsSolver()
6465

6566
local currentHighlight = 1
66-
local currentPathfinderIndex = 1
67-
local done, path, goalNodeInvalid
6867

6968
local nTotalNodes = 0
7069
local nStartNodes = 0
@@ -86,7 +85,6 @@ local function find(start, goal, allowReverse)
8685
io.stdout:flush()
8786
lastStartPosition = State3D.copy(startPosition)
8887
lastGoalPosition = State3D.copy(goalPosition)
89-
return done, path, goalNodeInvalid
9088
end
9189

9290
local dtTotal = 0
@@ -99,10 +97,15 @@ function love.update(dt)
9997
end
10098
end
10199

102-
function love.load()
100+
function love.load(arg)
101+
-- initialize the pathfinder
102+
TestPathfinder.setGraph(GraphPathfinder.loadGraphEdgesFromXml(arg[1]))
103+
104+
-- initialize the LOVE window
105+
love.window.setTitle('Courseplay Pathfinding Test')
103106
love.window.setMode(1000, 700)
104107
love.graphics.setPointSize(3)
105-
find(startPosition, goalPosition)
108+
--find(startPosition, goalPosition)
106109
end
107110

108111
local logger = Logger()
@@ -165,10 +168,7 @@ local function drawPath(path, pointSize, r, g, b)
165168
end
166169

167170
local function drawProhibitedAreas()
168-
love.graphics.setColor(0.2, 0.2, 0.2)
169-
for _, p in ipairs(TestPathfinder.getProhibitedPolygons()) do
170-
love.graphics.polygon('line', p:getUnpackedVertices())
171-
end
171+
172172
end
173173

174174
local function drawPathFinderNodes()
@@ -274,7 +274,9 @@ function love.draw()
274274
love.graphics.line(0, -1000, 0, 1000)
275275
love.graphics.setColor( 0.2, 0.2, 0.2, 0.5)
276276
love.graphics.setLineWidth(0.1)
277-
drawGrid(3)
277+
--drawGrid(3)
278+
279+
TestPathfinder.drawGraph()
278280

279281
love.graphics.setColor( 0, 1, 0 )
280282
love.graphics.setPointSize(3)
@@ -287,51 +289,31 @@ function love.draw()
287289
love.graphics.setColor(0, 0.8, 0)
288290

289291
love.graphics.setPointSize(5)
290-
drawProhibitedAreas()
292+
TestPathfinder.drawProhibitedAreas()
291293
drawPathFinderNodes()
292294

293295
--drawPath(dubinsPath, 3, 0.8, 0.8, 0)
294296
--drawPath(rsPath, 2, 0, 0.3, 0.8)
295297
if TestPathfinder.getPath() then
296-
drawPath(TestPathfinder.getPath(), 0.3, 0, 0.6, 1)
297-
end
298-
299-
if path then
300-
love.graphics.setPointSize(0.5 * scale)
301-
for i = 2, #path do
302-
local p = path[i]
303-
if p.gear == Gear.Backward then
304-
love.graphics.setColor(0, 0.4, 1)
305-
elseif p.gear == Gear.Forward then
306-
love.graphics.setColor( 1, 1, 1 )
307-
else
308-
love.graphics.setColor(0.4, 0, 0)
309-
end
310-
love.graphics.setLineWidth(0.1)
311-
love.graphics.line(p.x, p.y, path[i-1].x, path[i - 1].y)
312-
--love.graphics.points(p.x, p.y)
313-
drawVehicle(p, i)
314-
end
298+
drawPath(TestPathfinder.getPath(), 0.5, 0, 0.6, 1)
315299
end
316-
drawGraph()
317300

318301
love.graphics.setColor( 0.3, 0.3, 0.3 )
319302
love.graphics.pop()
320303

321-
322304
showStatus()
323305
end
324306

325307
function love.keypressed(key, scancode, isrepeat)
326308
local headingStepDeg = 15
327309
if key == 'left' then
328-
if love.keyboard.isDown('lshift') then
310+
if love.keyboard.isDown('lalt') then
329311
startPosition:addHeading(math.rad(headingStepDeg))
330312
else
331313
goalPosition:addHeading(math.rad(headingStepDeg))
332314
end
333315
elseif key == 'right' then
334-
if love.keyboard.isDown('lshift') then
316+
if love.keyboard.isDown('lalt') then
335317
startPosition:addHeading(-math.rad(headingStepDeg))
336318
else
337319
goalPosition:addHeading(-math.rad(headingStepDeg))
@@ -358,16 +340,7 @@ function love.mousepressed(x, y, button, istouch)
358340
if love.keyboard.isDown('lshift') or love.keyboard.isDown('lctrl') then
359341
goalPosition.x, goalPosition.y = love2real( x, y )
360342
--print(love.profiler.report(profilerReportLength))
361-
done, path, goalNodeInvalid = find(startPosition, goalPosition, love.keyboard.isDown('lctrl'))
362-
363-
if path then
364-
debug('Path found with %d nodes', #path)
365-
elseif done then
366-
debug('No path found')
367-
if goalNodeInvalid then
368-
debug('Goal node invalid')
369-
end
370-
end
343+
find(startPosition, goalPosition, love.keyboard.isDown('lctrl'))
371344
elseif love.keyboard.isDown('lalt') then
372345
startPosition.x, startPosition.y = love2real( x, y )
373346
else

0 commit comments

Comments
 (0)