Skip to content

Commit 2d4e7c9

Browse files
committed
code clean up
1 parent 7473364 commit 2d4e7c9

File tree

3 files changed

+18
-42
lines changed

3 files changed

+18
-42
lines changed

PathPlanning/HybridAStar/a_star.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,9 @@ def calc_obstacle_map(ox, oy, reso, vr):
142142
miny = round(min(oy))
143143
maxx = round(max(ox))
144144
maxy = round(max(oy))
145-
# print("minx:", minx)
146-
# print("miny:", miny)
147-
# print("maxx:", maxx)
148-
# print("maxy:", maxy)
149145

150146
xwidth = round(maxx - minx)
151147
ywidth = round(maxy - miny)
152-
# print("xwidth:", xwidth)
153-
# print("ywidth:", ywidth)
154148

155149
# obstacle map generation
156150
obmap = [[False for i in range(xwidth)] for i in range(ywidth)]

PathPlanning/HybridAStar/car.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def rectangle_check(x, y, yaw, ox, oy):
5151
ry = s * tx + c * ty
5252

5353
if not (rx > LF or rx < -LB or ry > W / 2.0 or ry < -W / 2.0):
54-
# print (x, y, yaw, iox, ioy, c, s, rx, ry)
5554
return False # no collision
5655

5756
return True # collision

PathPlanning/HybridAStar/hybrid_a_star.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
"""
88

99
import heapq
10-
import matplotlib.pyplot as plt
1110
import scipy.spatial
1211
import numpy as np
1312
import math
14-
13+
import matplotlib.pyplot as plt
1514
import sys
1615
sys.path.append("../ReedsSheppPath/")
1716
try:
@@ -24,32 +23,25 @@
2423

2524
XY_GRID_RESOLUTION = 2.0 # [m]
2625
YAW_GRID_RESOLUTION = np.deg2rad(15.0) # [rad]
27-
GOAL_TYAW_TH = np.deg2rad(5.0) # [rad]
2826
MOTION_RESOLUTION = 0.1 # [m] path interporate resolution
2927
N_STEER = 20.0 # number of steer command
30-
EXTEND_AREA = 0.0 # [m]
3128
H_COST = 1.0
32-
MOTION_RESOLUTION = 0.1
33-
SKIP_COLLISION_CHECK = 4
3429
VR = 1.0 # robot radius
3530

3631
SB_COST = 100.0 # switch back penalty cost
3732
BACK_COST = 5.0 # backward penalty cost
3833
STEER_CHANGE_COST = 5.0 # steer angle change penalty cost
3934
STEER_COST = 1.0 # steer angle change penalty cost
40-
# JACKKNIF_COST= 200.0 # Jackknif cost
4135
H_COST = 5.0 # Heuristic cost
4236

4337
show_animation = True
4438

45-
# _round = round
46-
# def round(x):
47-
# return int(_round(x))
48-
4939

5040
class Node:
5141

52-
def __init__(self, xind, yind, yawind, direction, xlist, ylist, yawlist, directions, steer=0.0, pind=None, cost=None):
42+
def __init__(self, xind, yind, yawind, direction,
43+
xlist, ylist, yawlist, directions,
44+
steer=0.0, pind=None, cost=None):
5345
self.xind = xind
5446
self.yind = yind
5547
self.yawind = yawind
@@ -114,10 +106,10 @@ def search_in_distance(self, inp, r):
114106
class Config:
115107

116108
def __init__(self, ox, oy, xyreso, yawreso):
117-
min_x_m = min(ox) # - EXTEND_AREA
118-
min_y_m = min(oy) # - EXTEND_AREA
119-
max_x_m = max(ox) # + EXTEND_AREA
120-
max_y_m = max(oy) # + EXTEND_AREA
109+
min_x_m = min(ox)
110+
min_y_m = min(oy)
111+
max_x_m = max(ox)
112+
max_y_m = max(oy)
121113

122114
ox.append(min_x_m)
123115
oy.append(min_y_m)
@@ -137,10 +129,6 @@ def __init__(self, ox, oy, xyreso, yawreso):
137129
self.yaww = round(self.maxyaw - self.minyaw)
138130

139131

140-
def show_expansion_tree():
141-
pass
142-
143-
144132
def calc_motion_inputs():
145133

146134
for steer in np.linspace(-MAX_STEER, MAX_STEER, N_STEER):
@@ -168,7 +156,6 @@ def calc_next_node(current, steer, direction, config, ox, oy, kdtree):
168156
ylist.append(y)
169157
yawlist.append(yaw)
170158

171-
# plt.plot(xlist, ylist)
172159
if not check_car_collision(xlist, ylist, yawlist, ox, oy, kdtree):
173160
return None
174161

@@ -252,7 +239,8 @@ def update_node_with_analystic_expantion(current, goal,
252239

253240
fsteer = 0.0
254241
fpath = Node(current.xind, current.yind, current.yawind,
255-
current.direction, fx, fy, fyaw, fd, cost=fcost, pind=fpind, steer=fsteer)
242+
current.direction, fx, fy, fyaw, fd,
243+
cost=fcost, pind=fpind, steer=fsteer)
256244
return True, fpath
257245

258246
return False, None
@@ -331,7 +319,6 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
331319
return [], [], []
332320

333321
cost, c_id = heapq.heappop(pq)
334-
# if openList.has_key(c_id): # python 2.7
335322
if c_id in openList:
336323
current = openList.pop(c_id)
337324
closedList[c_id] = current
@@ -351,13 +338,13 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
351338

352339
for neighbor in get_neighbors(current, config, ox, oy, obkdtree):
353340
neighbor_index = calc_index(neighbor, config)
354-
# if closedList.has_key(neighbor_index):
355341
if neighbor_index in closedList:
356342
continue
357-
if not neighbor in openList \
343+
if neighbor not in openList \
358344
or openList[neighbor_index].cost > neighbor.cost:
359345
heapq.heappush(
360-
pq, (calc_cost(neighbor, h_dp, ngoal, config), neighbor_index))
346+
pq, (calc_cost(neighbor, h_dp, ngoal, config),
347+
neighbor_index))
361348
openList[neighbor_index] = neighbor
362349

363350
path = get_final_path(closedList, fpath, nstart, config)
@@ -366,9 +353,9 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
366353

367354
def calc_cost(n, h_dp, goal, c):
368355
ind = (n.yind - c.miny) * c.xw + (n.xind - c.minx)
369-
if not ind in h_dp:
370-
return (n.cost + 999999999) # collision cost
371-
return (n.cost + H_COST * h_dp[ind].cost)
356+
if ind not in h_dp:
357+
return n.cost + 999999999 # collision cost
358+
return n.cost + H_COST * h_dp[ind].cost
372359

373360

374361
def get_final_path(closed, ngoal, nstart, config):
@@ -392,7 +379,7 @@ def get_final_path(closed, ngoal, nstart, config):
392379
ryaw = list(reversed(ryaw))
393380
direction = list(reversed(direction))
394381

395-
# adjuct first direction
382+
# adjust first direction
396383
direction[0] = direction[1]
397384

398385
path = Path(rx, ry, ryaw, direction, finalcost)
@@ -457,12 +444,9 @@ def main():
457444
path = hybrid_a_star_planning(
458445
start, goal, ox, oy, XY_GRID_RESOLUTION, YAW_GRID_RESOLUTION)
459446

460-
# plot_car(*start)
461-
# plot_car(*goal)
462447
x = path.xlist
463448
y = path.ylist
464449
yaw = path.yawlist
465-
# direction = path.directionlist
466450

467451
for ix, iy, iyaw in zip(x, y, yaw):
468452
plt.cla()
@@ -473,8 +457,7 @@ def main():
473457
plot_car(ix, iy, iyaw)
474458
plt.pause(0.0001)
475459

476-
plt.show()
477-
print(__file__ + " start!!")
460+
print(__file__ + " done!!")
478461

479462

480463
if __name__ == '__main__':

0 commit comments

Comments
 (0)