Skip to content

Commit 3efbc94

Browse files
authored
fix d_star (AtsushiSakai#898)
1 parent 313ce19 commit 3efbc94

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

PathPlanning/DStar/dstar.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010
import math
1111

12+
1213
from sys import maxsize
1314

1415
import matplotlib.pyplot as plt
@@ -103,7 +104,7 @@ def process_state(self):
103104
if y.h <= k_old and x.h > y.h + x.cost(y):
104105
x.parent = y
105106
x.h = y.h + x.cost(y)
106-
elif k_old == x.h:
107+
if k_old == x.h:
107108
for y in self.map.get_neighbors(x):
108109
if y.t == "new" or y.parent == x and y.h != x.h + x.cost(y) \
109110
or y.parent != x and y.h > x.h + x.cost(y):
@@ -116,7 +117,7 @@ def process_state(self):
116117
self.insert(y, x.h + x.cost(y))
117118
else:
118119
if y.parent != x and y.h > x.h + x.cost(y):
119-
self.insert(y, x.h)
120+
self.insert(x, x.h)
120121
else:
121122
if y.parent != x and x.h > y.h + x.cost(y) \
122123
and y.t == "close" and y.h > k_old:
@@ -173,6 +174,8 @@ def run(self, start, end):
173174
s.set_state("e")
174175
tmp = start
175176

177+
AddNewObstacle(self.map) # add new obstacle after the first search finished
178+
176179
while tmp != end:
177180
tmp.set_state("*")
178181
rx.append(tmp.x)
@@ -195,6 +198,15 @@ def modify(self, state):
195198
if k_min >= state.h:
196199
break
197200

201+
def AddNewObstacle(map:Map):
202+
ox, oy = [], []
203+
for i in range(5, 21):
204+
ox.append(i)
205+
oy.append(40)
206+
map.set_obstacle([(i, j) for i, j in zip(ox, oy)])
207+
if show_animation:
208+
plt.pause(0.001)
209+
plt.plot(ox, oy, ".g")
198210

199211
def main():
200212
m = Map(100, 100)
@@ -217,7 +229,6 @@ def main():
217229
for i in range(0, 40):
218230
ox.append(40)
219231
oy.append(60 - i)
220-
print([(i, j) for i, j in zip(ox, oy)])
221232
m.set_obstacle([(i, j) for i, j in zip(ox, oy)])
222233

223234
start = [10, 10]
@@ -234,7 +245,7 @@ def main():
234245
rx, ry = dstar.run(start, end)
235246

236247
if show_animation:
237-
plt.plot(rx, ry, "-r")
248+
# plt.plot(rx, ry, "-r")
238249
plt.show()
239250

240251

0 commit comments

Comments
 (0)