Skip to content

Commit e102b5d

Browse files
author
zks
committed
hybrid_a_star python 3.5
1 parent a382689 commit e102b5d

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

PathPlanning/HybridAStar/a_star.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import math
1414
import heapq
1515

16-
_round = round
17-
def round(x):
18-
return int(_round(x))
16+
# _round = round
17+
# def round(x):
18+
# return int(_round(x))
1919

2020
show_animation = False
2121

@@ -73,7 +73,7 @@ def dp_planning(sx, sy, gx, gy, ox, oy, reso, rr):
7373
if not pq:
7474
break
7575
cost, c_id = heapq.heappop(pq)
76-
if openset.has_key(c_id):
76+
if c_id in openset:
7777
current = openset[c_id]
7878
closedset[c_id] = current
7979
openset.pop(c_id)

PathPlanning/HybridAStar/car.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def check_car_collision(xlist, ylist, yawlist, ox, oy, kdtree):
2323

2424
ids = kdtree.search_in_distance([cx, cy], WBUBBLE_R)
2525

26-
if len(ids) == 0:
26+
if not ids:
2727
continue
2828

2929
if not rectangle_check(x, y, yaw,

PathPlanning/HybridAStar/hybrid_a_star.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import reeds_shepp_path_planning as rs
1717
import heapq
1818
from car import move, check_car_collision, MAX_STEER, WB, plot_car
19-
from a_star import dp_planning, calc_obstacle_map
19+
from a_star import dp_planning #, calc_obstacle_map
2020

2121
XY_GRID_RESOLUTION = 2.0 #[m]
2222
YAW_GRID_RESOLUTION = np.deg2rad(15.0) #[rad]
@@ -38,9 +38,9 @@
3838

3939
show_animation = True
4040

41-
_round = round
42-
def round(x):
43-
return int(_round(x))
41+
# _round = round
42+
# def round(x):
43+
# return int(_round(x))
4444

4545
class Node:
4646

@@ -92,9 +92,9 @@ def search(self, inp, k=1):
9292
dist.append(idist)
9393

9494
return index, dist
95-
else:
96-
dist, index = self.tree.query(inp, k=k)
97-
return index, dist
95+
96+
dist, index = self.tree.query(inp, k=k)
97+
return index, dist
9898

9999
def search_in_distance(self, inp, r):
100100
"""
@@ -211,7 +211,7 @@ def analytic_expantion(current, goal, c, ox, oy, kdtree):
211211
paths = rs.calc_paths(sx,sy,syaw,gx, gy, gyaw,
212212
max_curvature, step_size=MOTION_RESOLUTION)
213213

214-
if not len(paths):
214+
if not paths:
215215
return None
216216

217217
best_path, best = None, None
@@ -223,7 +223,7 @@ def analytic_expantion(current, goal, c, ox, oy, kdtree):
223223
best = cost
224224
best_path = path
225225

226-
return best_path # no update
226+
return best_path
227227

228228

229229
def update_node_with_analystic_expantion(current, goal,
@@ -309,7 +309,6 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
309309
True, [goal[0]], [goal[1]], [goal[2]], [True])
310310

311311
openList, closedList = {}, {}
312-
h = []
313312

314313
_, _, h_dp = dp_planning(nstart.xlist[-1], nstart.ylist[-1],
315314
ngoal.xlist[-1], ngoal.ylist[-1], ox, oy, xyreso, VR)
@@ -324,9 +323,12 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
324323
return [], [], []
325324

326325
cost, c_id = heapq.heappop(pq)
327-
if openList.has_key(c_id):
326+
# if openList.has_key(c_id): # python 2.7
327+
if c_id in openList:
328328
current = openList.pop(c_id)
329329
closedList[c_id] = current
330+
else:
331+
continue
330332

331333
if show_animation: # pragma: no cover
332334
plt.plot(current.xlist[-1], current.ylist[-1], "xc")
@@ -341,23 +343,21 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
341343

342344
for neighbor in get_neighbors(current, config, ox, oy, obkdtree):
343345
neighbor_index = calc_index(neighbor, config)
344-
if closedList.has_key(neighbor_index):
346+
# if closedList.has_key(neighbor_index):
347+
if neighbor_index in closedList:
345348
continue
346-
if not openList.has_key(neighbor_index) \
347-
or openList[neighbor_index].cost > neighbor.cost: # TODO huristic
349+
if not neighbor in openList \
350+
or openList[neighbor_index].cost > neighbor.cost:
348351
heapq.heappush(pq, (calc_cost(neighbor, h_dp, ngoal, config), neighbor_index))
349352
openList[neighbor_index] = neighbor
350353

351-
# print(current)
352-
353-
rx, ry, ryaw = [], [], []
354354

355355
path = get_final_path(closedList, fpath, nstart, config)
356356
return path
357357

358358
def calc_cost(n, h_dp, goal, c):
359359
ind = (n.yind - c.miny) * c.xw + (n.xind - c.minx)
360-
if not h_dp.has_key(ind):
360+
if not ind in h_dp:
361361
return (n.cost + 999999999) # collision cost
362362
return (n.cost + H_COST*h_dp[ind].cost)
363363

@@ -451,7 +451,7 @@ def main():
451451
x = path.xlist
452452
y = path.ylist
453453
yaw = path.yawlist
454-
direction = path.directionlist
454+
# direction = path.directionlist
455455

456456
for ix, iy, iyaw in zip(x, y, yaw):
457457
plt.cla()

0 commit comments

Comments
 (0)