Skip to content

Commit c9d52c2

Browse files
author
Peter Vaiko
committed
feat: enable/disable JPS
Also log should now indicate which pathfinder is being used.
1 parent abf5308 commit c9d52c2

6 files changed

Lines changed: 19 additions & 4 deletions

File tree

config/VehicleSettingsSetup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<Setting classType="AIParameterBooleanSetting" name="turnOnField" defaultBool="true" isVisible="areCourseSettingsVisible"/>
3434
<!--Avoid Fruit-->
3535
<Setting classType="AIParameterBooleanSetting" name="avoidFruit" defaultBool="true" isExpertModeOnly="true"/>
36+
<Setting classType="AIParameterBooleanSetting" name="useJps" defaultBool="true" isExpertModeOnly="true"/>
3637
<Setting classType="AIParameterSettingList" name="penaltyFactor" min="1" max="10" incremental="0.1" default="1" />
3738
<!--Pathfinder Reverse-->
3839
<Setting classType="AIParameterBooleanSetting" name="allowReversePathfinding" defaultBool="true" isExpertModeOnly="true" isVisible="areCourseSettingsVisible"/>

scripts/pathfinder/AStar.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AStar = CpObject(HybridAStar)
66

77
function AStar:init(vehicle, yieldAfter, maxIterations)
88
HybridAStar.init(self, vehicle, yieldAfter, maxIterations)
9+
self.name = 'AStar'
910
-- this needs to be small enough that no vehicle fit between the grid points (and remain undetected)
1011
self.deltaPos = 3
1112
self.deltaPosGoal = self.deltaPos

scripts/pathfinder/HybridAStar.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ HybridAStar.defaultMaxIterations = 40000
494494
---@param maxIterations number
495495
---@param mustBeAccurate boolean|nil
496496
function HybridAStar:init(vehicle, yieldAfter, maxIterations, mustBeAccurate)
497-
self.logger = Logger('HybridAStar', Logger.level.error, CpDebug.DBG_PATHFINDER)
497+
self.name = 'HybridAStar'
498+
self.logger = Logger(self.name, Logger.level.error, CpDebug.DBG_PATHFINDER)
498499
self.vehicle = vehicle
499500
self.iterationsSinceYield = 0
500501
self.yields = 0
@@ -545,7 +546,7 @@ end
545546
--- rear axle of the trailer), can be nil
546547
---@return PathfinderResult
547548
function HybridAStar:initRun(start, goal, turnRadius, allowReverse, constraints, hitchLength)
548-
self:debug('Start pathfinding between %s and %s', tostring(start), tostring(goal))
549+
self:debug('Start %s pathfinding between %s and %s', self.name, tostring(start), tostring(goal))
549550
self:debug(' turnRadius = %.1f, allowReverse: %s', turnRadius, tostring(allowReverse))
550551
self.goal = goal
551552
self.turnRadius = turnRadius

scripts/pathfinder/HybridAStarWithAStarInTheMiddle.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ HybridAStarWithAStarInTheMiddle = CpObject(PathfinderInterface)
1010
---@param mustBeAccurate boolean must be accurately find the goal position/angle (optional)
1111
---@param analyticSolver AnalyticSolver the analytic solver the use (optional)
1212
function HybridAStarWithAStarInTheMiddle:init(vehicle, yieldAfter, maxIterations, mustBeAccurate, analyticSolver)
13-
-- path generation phases
13+
self.name = 'HybridAStarWithAStarInTheMiddle'
1414
self.vehicle = vehicle
15+
-- path generation phases
1516
self.START_TO_MIDDLE = 1
1617
self.FAST = 2
1718
self.MIDDLE_TO_END = 3
@@ -250,6 +251,7 @@ function HybridAStarWithPathInTheMiddle:init(vehicle, yieldAfter, path, mustBeAc
250251
self.vehicle = vehicle
251252
self.path = path
252253
HybridAStarWithAStarInTheMiddle.init(self, vehicle, yieldAfter, 10000, mustBeAccurate, analyticSolver)
254+
self.name = 'HybridAStarWithPathInTheMiddle'
253255
end
254256

255257
function HybridAStarWithPathInTheMiddle:start(...)

scripts/pathfinder/JumpPointSearch.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
JumpPointSearch = CpObject(AStar)
44
JumpPointSearch.markers = {}
55

6+
function JumpPointSearch:init(vehicle, yieldAfter, maxIterations)
7+
AStar.init(self, vehicle, yieldAfter, maxIterations)
8+
self.name = "JumpPointSearch"
9+
end
10+
611
function JumpPointSearch:initRun(start, goal, turnRadius, allowReverse, constraints, hitchLength)
712
self.logger:setLevel(Logger.level.debug)
813
return AStar.initRun(self, start, goal, turnRadius, allowReverse, constraints, hitchLength)

scripts/pathfinder/PathfinderUtil.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,12 @@ end
428428
---@param maxIterations number maximum number of iterations
429429
function PathfinderUtil.startPathfinding(vehicle, start, goal, constraints, allowReverse, mustBeAccurate, maxIterations)
430430
PathfinderUtil.overlapBoxes = {}
431-
local pathfinder = HybridAStarWithJpsInTheMiddle(vehicle, 100, maxIterations, mustBeAccurate)
431+
local pathfinder
432+
if vehicle:getCpSettings().useJps:getValue() then
433+
pathfinder = HybridAStarWithJpsInTheMiddle(vehicle, 100, maxIterations, mustBeAccurate)
434+
else
435+
pathfinder = HybridAStarWithAStarInTheMiddle(vehicle, 100, maxIterations, mustBeAccurate)
436+
end
432437
return pathfinder, pathfinder:start(start, goal, constraints.turnRadius, allowReverse,
433438
constraints, constraints.trailerHitchLength)
434439
end

0 commit comments

Comments
 (0)