11--[[
2-
32LOVE app to test the Courseplay turn maneuvers and pathfinding
43
4+
55]] --
66
77dofile ( ' include.lua' )
@@ -17,18 +17,19 @@ require('Waypoint')
1717require (' Course' )
1818require (' ai.util.AIUtil' )
1919require (' pathfinder.pathfinder' )
20- dofile (' pathfinder/network.lua' )
2120
2221local parameterNameColor = { 1 , 1 , 1 }
2322local parameterKeyColor = { 0 , 1 , 1 }
2423local 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 )
2828local 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 )
3233local lastGoalPosition = State3D .copy (goalPosition )
3334
3435local vehicle
@@ -41,14 +42,14 @@ table.insert(parameters, turningRadius)
4142
4243local hybrid = ToggleParameter (' hybrid' , true , ' h' )
4344table.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 )
4546table.insert (parameters , penalty )
4647 local stepSize = AdjustableParameter (1 , ' Dubins step size' , ' D' , ' d' , 0.05 , 0.1 , 2 )
4748table.insert (parameters , stepSize )
4849
4950startPosition :setTrailerHeading (startHeading )
5051
51- local scale , width , height = 5 , 800 , 360
52+ local scale , width , height = 3 , 800 , 360
5253local xOffset , yOffset = - 100 + width / scale / 4 , 100 + height / scale
5354
5455local vehicleData = {name = ' name' , turningRadius = turningRadius :get (), dFront = 4 , dRear = 2 , dLeft = 1.5 , dRight = 1.5 }
@@ -63,8 +64,6 @@ local rsSolver = ReedsSheppSolver()
6364local dubinsSolver = DubinsSolver ()
6465
6566local currentHighlight = 1
66- local currentPathfinderIndex = 1
67- local done , path , goalNodeInvalid
6867
6968local nTotalNodes = 0
7069local 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
9088end
9189
9290local dtTotal = 0
@@ -99,10 +97,15 @@ function love.update(dt)
9997 end
10098end
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)
106109end
107110
108111local logger = Logger ()
@@ -165,10 +168,7 @@ local function drawPath(path, pointSize, r, g, b)
165168end
166169
167170local 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+
172172end
173173
174174local 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 ()
323305end
324306
325307function 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