|
9 | 9 | import sys |
10 | 10 | sys.path.append("../ReedsSheppPath/") |
11 | 11 |
|
12 | | -# import random |
13 | 12 | import math |
14 | | -# import numpy as np |
| 13 | +import numpy as np |
| 14 | +import scipy.spatial |
15 | 15 | import matplotlib.pyplot as plt |
16 | | -import reeds_shepp_path_planning |
| 16 | +import reeds_shepp_path_planning as rs |
| 17 | + |
| 18 | +EXTEND_AREA = 5.0 # [m] |
17 | 19 |
|
18 | 20 | show_animation = True |
19 | 21 |
|
20 | 22 |
|
| 23 | +class KDTree: |
| 24 | + """ |
| 25 | + Nearest neighbor search class with KDTree |
| 26 | + """ |
| 27 | + |
| 28 | + def __init__(self, data): |
| 29 | + # store kd-tree |
| 30 | + self.tree = scipy.spatial.cKDTree(data) |
| 31 | + |
| 32 | + def search(self, inp, k=1): |
| 33 | + """ |
| 34 | + Search NN |
| 35 | + inp: input data, single frame or multi frame |
| 36 | + """ |
| 37 | + |
| 38 | + if len(inp.shape) >= 2: # multi input |
| 39 | + index = [] |
| 40 | + dist = [] |
| 41 | + |
| 42 | + for i in inp.T: |
| 43 | + idist, iindex = self.tree.query(i, k=k) |
| 44 | + index.append(iindex) |
| 45 | + dist.append(idist) |
| 46 | + |
| 47 | + return index, dist |
| 48 | + else: |
| 49 | + dist, index = self.tree.query(inp, k=k) |
| 50 | + return index, dist |
| 51 | + |
| 52 | + def search_in_distance(self, inp, r): |
| 53 | + """ |
| 54 | + find points with in a distance r |
| 55 | + """ |
| 56 | + |
| 57 | + index = self.tree.query_ball_point(inp, r) |
| 58 | + return index |
| 59 | + |
| 60 | + |
| 61 | +class Config: |
| 62 | + |
| 63 | + def __init__(self, ox, oy, xyreso, yawreso): |
| 64 | + min_x_m = min(ox) - EXTEND_AREA |
| 65 | + min_y_m = min(oy) - EXTEND_AREA |
| 66 | + max_x_m = max(ox) + EXTEND_AREA |
| 67 | + max_y_m = max(oy) + EXTEND_AREA |
| 68 | + |
| 69 | + ox.append(min_x_m) |
| 70 | + oy.append(min_y_m) |
| 71 | + ox.append(max_x_m) |
| 72 | + oy.append(max_y_m) |
| 73 | + |
| 74 | + self.minx = int(min_x_m / xyreso) |
| 75 | + self.miny = int(min_y_m / xyreso) |
| 76 | + self.maxx = int(max_x_m / xyreso) |
| 77 | + self.maxy = int(max_y_m / xyreso) |
| 78 | + |
| 79 | + self.xw = int(self.maxx - self.minx) |
| 80 | + self.yw = int(self.maxy - self.miny) |
| 81 | + |
| 82 | + self.minyaw = int(- math.pi / yawreso) - 1 |
| 83 | + self.maxyaw = int(math.pi / yawreso) |
| 84 | + self.yaww = int(self.maxyaw - self.minyaw) |
| 85 | + |
| 86 | + |
21 | 87 | def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso): |
| 88 | + """ |
| 89 | + start |
| 90 | + goal |
| 91 | + ox: x position list of Obstacles [m] |
| 92 | + oy: y position list of Obstacles [m] |
| 93 | + xyreso: grid resolution [m] |
| 94 | + yawreso: yaw angle resolution [rad] |
| 95 | + """ |
| 96 | + |
| 97 | + start[2], goal[2] = rs.pi_2_pi(start[2]), rs.pi_2_pi(goal[2]) |
| 98 | + tox, toy = ox[:], oy[:] |
| 99 | + |
| 100 | + obkdtree = KDTree(np.vstack((tox, toy)).T) |
| 101 | + |
| 102 | + c = Config(tox, toy, xyreso, yawreso) |
22 | 103 |
|
23 | 104 | rx, ry, ryaw = [], [], [] |
24 | 105 |
|
@@ -61,10 +142,8 @@ def main(): |
61 | 142 | start, goal, ox, oy, xyreso, yawreso) |
62 | 143 |
|
63 | 144 | plt.plot(ox, oy, ".k") |
64 | | - reeds_shepp_path_planning.plot_arrow( |
65 | | - start[0], start[1], start[2]) |
66 | | - reeds_shepp_path_planning.plot_arrow( |
67 | | - goal[0], goal[1], goal[2]) |
| 145 | + rs.plot_arrow(start[0], start[1], start[2]) |
| 146 | + rs.plot_arrow(goal[0], goal[1], goal[2]) |
68 | 147 |
|
69 | 148 | plt.grid(True) |
70 | 149 | plt.axis("equal") |
|
0 commit comments