Skip to content

Commit 88cc03d

Browse files
authored
refactor hybrid_a_star codes and clean up heuristic function names (AtsushiSakai#371)
* refactor hybrid_a_star code heuristic function names and codes * removed empty line
1 parent c90ef2c commit 88cc03d

File tree

3 files changed

+6
-70
lines changed

3 files changed

+6
-70
lines changed

.github/workflows/circleci-artifacts-redirector.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ jobs:
1111
repo-token: ${{ secrets.GITHUB_TOKEN }}
1212
artifact-path: 0/html/index.html
1313
circleci-jobs: build_doc
14-
- name: Check the URL
15-
run: |
16-
curl --fail ${{ steps.step1.outputs.url }} | grep $GITHUB_SHA

PathPlanning/HybridAStar/a_star_heuristic.py renamed to PathPlanning/HybridAStar/dynamic_programming_heuristic.py

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def calc_final_path(goal_node, closed_node_set, resolution):
4242
return rx, ry
4343

4444

45-
def dp_planning(sx, sy, gx, gy, ox, oy, resolution, rr):
45+
def calc_distance_heuristic(gx, gy, ox, oy, resolution, rr):
4646
"""
4747
gx: goal x position [m]
4848
gx: goal x position [m]
@@ -52,7 +52,6 @@ def dp_planning(sx, sy, gx, gy, ox, oy, resolution, rr):
5252
rr: robot radius[m]
5353
"""
5454

55-
start_node = Node(round(sx / resolution), round(sy / resolution), 0.0, -1)
5655
goal_node = Node(round(gx / resolution), round(gy / resolution), 0.0, -1)
5756
ox = [iox / resolution for iox in ox]
5857
oy = [ioy / resolution for ioy in oy]
@@ -115,16 +114,7 @@ def dp_planning(sx, sy, gx, gy, ox, oy, resolution, rr):
115114
priority_queue,
116115
(node.cost, calc_index(node, x_w, min_x, min_y)))
117116

118-
rx, ry = calc_final_path(closed_set[calc_index(
119-
start_node, x_w, min_x, min_y)], closed_set, resolution)
120-
121-
return rx, ry, closed_set
122-
123-
124-
def calc_heuristic(n1, n2):
125-
w = 1.0 # weight of heuristic
126-
d = w * math.sqrt((n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2)
127-
return d
117+
return closed_set
128118

129119

130120
def verify_node(node, obstacle_map, min_x, min_y, max_x, max_y):
@@ -184,54 +174,3 @@ def get_motion_model():
184174
[1, 1, math.sqrt(2)]]
185175

186176
return motion
187-
188-
189-
def main():
190-
print(__file__ + " start!!")
191-
192-
# start and goal position
193-
sx = 10.0 # [m]
194-
sy = 10.0 # [m]
195-
gx = 50.0 # [m]
196-
gy = 50.0 # [m]
197-
grid_size = 2.0 # [m]
198-
robot_size = 1.0 # [m]
199-
200-
ox, oy = [], []
201-
202-
for i in range(60):
203-
ox.append(i)
204-
oy.append(0.0)
205-
for i in range(60):
206-
ox.append(60.0)
207-
oy.append(i)
208-
for i in range(61):
209-
ox.append(i)
210-
oy.append(60.0)
211-
for i in range(61):
212-
ox.append(0.0)
213-
oy.append(i)
214-
for i in range(40):
215-
ox.append(20.0)
216-
oy.append(i)
217-
for i in range(40):
218-
ox.append(40.0)
219-
oy.append(60.0 - i)
220-
221-
if show_animation: # pragma: no cover
222-
plt.plot(ox, oy, ".k")
223-
plt.plot(sx, sy, "xr")
224-
plt.plot(gx, gy, "xb")
225-
plt.grid(True)
226-
plt.axis("equal")
227-
228-
rx, ry, _ = dp_planning(sx, sy, gx, gy, ox, oy, grid_size, robot_size)
229-
230-
if show_animation: # pragma: no cover
231-
plt.plot(rx, ry, "-r")
232-
plt.show()
233-
234-
235-
if __name__ == '__main__':
236-
show_animation = True
237-
main()

PathPlanning/HybridAStar/hybrid_a_star.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
sys.path.append(os.path.dirname(os.path.abspath(__file__))
1919
+ "/../ReedsSheppPath")
2020
try:
21-
from a_star_heuristic import dp_planning
21+
from dynamic_programming_heuristic import calc_distance_heuristic
2222
import reeds_shepp_path_planning as rs
2323
from car import move, check_car_collision, MAX_STEER, WB, plot_car
2424
except Exception:
@@ -274,9 +274,9 @@ def hybrid_a_star_planning(start, goal, ox, oy, xy_resolution, yaw_resolution):
274274

275275
openList, closedList = {}, {}
276276

277-
_, _, h_dp = dp_planning(start_node.x_list[-1], start_node.y_list[-1],
278-
goal_node.x_list[-1], goal_node.y_list[-1],
279-
ox, oy, xy_resolution, VR)
277+
h_dp = calc_distance_heuristic(
278+
goal_node.x_list[-1], goal_node.y_list[-1],
279+
ox, oy, xy_resolution, VR)
280280

281281
pq = []
282282
openList[calc_index(start_node, config)] = start_node

0 commit comments

Comments
 (0)