Skip to content

Commit dc612e6

Browse files
committed
minor fix in dijkstra.py
1 parent 763ca4f commit dc612e6

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ target/
7070
.ipynb_checkpoints
7171

7272
matplotrecorder/*
73+
.vscode/settings.json

PathPlanning/Dijkstra/dijkstra.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, x, y, cost, pind):
3333
self.x = x # index of grid
3434
self.y = y # index of grid
3535
self.cost = cost
36-
self.pind = pind
36+
self.pind = pind # index of previous Node
3737

3838
def __str__(self):
3939
return str(self.x) + "," + str(self.y) + "," + str(self.cost) + "," + str(self.pind)
@@ -88,10 +88,10 @@ def planning(self, sx, sy, gx, gy):
8888
closedset[c_id] = current
8989

9090
# expand search grid based on motion model
91-
for i, _ in enumerate(self.motion):
92-
node = self.Node(current.x + self.motion[i][0],
93-
current.y + self.motion[i][1],
94-
current.cost + self.motion[i][2], c_id)
91+
for move_x, move_y, move_cost in self.motion:
92+
node = self.Node(current.x + move_x,
93+
current.y + move_y,
94+
current.cost + move_cost, c_id)
9595
n_id = self.calc_index(node)
9696

9797
if n_id in closedset:
@@ -124,11 +124,6 @@ def calc_final_path(self, ngoal, closedset):
124124

125125
return rx, ry
126126

127-
def calc_heuristic(self, n1, n2):
128-
w = 1.0 # weight of heuristic
129-
d = w * math.hypot(n1.x - n2.x, n1.y - n2.y)
130-
return d
131-
132127
def calc_position(self, index, minp):
133128
pos = index*self.reso+minp
134129
return pos
@@ -242,6 +237,9 @@ def main():
242237
dijkstra = Dijkstra(ox, oy, grid_size, robot_radius)
243238
rx, ry = dijkstra.planning(sx, sy, gx, gy)
244239

240+
print(rx)
241+
print(ry)
242+
245243
if show_animation: # pragma: no cover
246244
plt.plot(rx, ry, "-r")
247245
plt.show()

0 commit comments

Comments
 (0)