nwo
stringlengths 10
28
| sha
stringlengths 40
40
| path
stringlengths 11
97
| identifier
stringlengths 1
64
| parameters
stringlengths 2
2.24k
| return_statement
stringlengths 0
2.17k
| docstring
stringlengths 0
5.45k
| docstring_summary
stringlengths 0
3.83k
| func_begin
int64 1
13.4k
| func_end
int64 2
13.4k
| function
stringlengths 28
56.4k
| url
stringlengths 106
209
| project
int64 1
48
| executed_lines
list | executed_lines_pc
float64 0
153
| missing_lines
list | missing_lines_pc
float64 0
100
| covered
bool 2
classes | filecoverage
float64 2.53
100
| function_lines
int64 2
1.46k
| mccabe
int64 1
253
| coverage
float64 0
100
| docstring_lines
int64 0
112
| function_nodoc
stringlengths 9
56.4k
| id
int64 0
29.8k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
calc_rs_path_cost
|
(reed_shepp_path)
|
return cost
| 208 | 240 |
def calc_rs_path_cost(reed_shepp_path):
cost = 0.0
for length in reed_shepp_path.lengths:
if length >= 0: # forward
cost += length
else: # back
cost += abs(length) * BACK_COST
# switch back penalty
for i in range(len(reed_shepp_path.lengths) - 1):
# switch back
if reed_shepp_path.lengths[i] * reed_shepp_path.lengths[i + 1] < 0.0:
cost += SB_COST
# steer penalty
for course_type in reed_shepp_path.ctypes:
if course_type != "S": # curve
cost += STEER_COST * abs(MAX_STEER)
# ==steer change penalty
# calc steer profile
n_ctypes = len(reed_shepp_path.ctypes)
u_list = [0.0] * n_ctypes
for i in range(n_ctypes):
if reed_shepp_path.ctypes[i] == "R":
u_list[i] = - MAX_STEER
elif reed_shepp_path.ctypes[i] == "L":
u_list[i] = MAX_STEER
for i in range(len(reed_shepp_path.ctypes) - 1):
cost += STEER_CHANGE_COST * abs(u_list[i + 1] - u_list[i])
return cost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L208-L240
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
28,
29,
30,
31,
32
] | 93.939394 |
[
27
] | 3.030303 | false | 90.37037 | 33 | 11 | 96.969697 | 0 |
def calc_rs_path_cost(reed_shepp_path):
cost = 0.0
for length in reed_shepp_path.lengths:
if length >= 0: # forward
cost += length
else: # back
cost += abs(length) * BACK_COST
# switch back penalty
for i in range(len(reed_shepp_path.lengths) - 1):
# switch back
if reed_shepp_path.lengths[i] * reed_shepp_path.lengths[i + 1] < 0.0:
cost += SB_COST
# steer penalty
for course_type in reed_shepp_path.ctypes:
if course_type != "S": # curve
cost += STEER_COST * abs(MAX_STEER)
# ==steer change penalty
# calc steer profile
n_ctypes = len(reed_shepp_path.ctypes)
u_list = [0.0] * n_ctypes
for i in range(n_ctypes):
if reed_shepp_path.ctypes[i] == "R":
u_list[i] = - MAX_STEER
elif reed_shepp_path.ctypes[i] == "L":
u_list[i] = MAX_STEER
for i in range(len(reed_shepp_path.ctypes) - 1):
cost += STEER_CHANGE_COST * abs(u_list[i + 1] - u_list[i])
return cost
| 1,201 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
hybrid_a_star_planning
|
(start, goal, ox, oy, xy_resolution, yaw_resolution)
|
return path
|
start: start node
goal: goal node
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
xy_resolution: grid resolution [m]
yaw_resolution: yaw angle resolution [rad]
|
start: start node
goal: goal node
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
xy_resolution: grid resolution [m]
yaw_resolution: yaw angle resolution [rad]
| 243 | 322 |
def hybrid_a_star_planning(start, goal, ox, oy, xy_resolution, yaw_resolution):
"""
start: start node
goal: goal node
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
xy_resolution: grid resolution [m]
yaw_resolution: yaw angle resolution [rad]
"""
start[2], goal[2] = rs.pi_2_pi(start[2]), rs.pi_2_pi(goal[2])
tox, toy = ox[:], oy[:]
obstacle_kd_tree = cKDTree(np.vstack((tox, toy)).T)
config = Config(tox, toy, xy_resolution, yaw_resolution)
start_node = Node(round(start[0] / xy_resolution),
round(start[1] / xy_resolution),
round(start[2] / yaw_resolution), True,
[start[0]], [start[1]], [start[2]], [True], cost=0)
goal_node = Node(round(goal[0] / xy_resolution),
round(goal[1] / xy_resolution),
round(goal[2] / yaw_resolution), True,
[goal[0]], [goal[1]], [goal[2]], [True])
openList, closedList = {}, {}
h_dp = calc_distance_heuristic(
goal_node.x_list[-1], goal_node.y_list[-1],
ox, oy, xy_resolution, BUBBLE_R)
pq = []
openList[calc_index(start_node, config)] = start_node
heapq.heappush(pq, (calc_cost(start_node, h_dp, config),
calc_index(start_node, config)))
final_path = None
while True:
if not openList:
print("Error: Cannot find path, No open set")
return [], [], []
cost, c_id = heapq.heappop(pq)
if c_id in openList:
current = openList.pop(c_id)
closedList[c_id] = current
else:
continue
if show_animation: # pragma: no cover
plt.plot(current.x_list[-1], current.y_list[-1], "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closedList.keys()) % 10 == 0:
plt.pause(0.001)
is_updated, final_path = update_node_with_analytic_expansion(
current, goal_node, config, ox, oy, obstacle_kd_tree)
if is_updated:
print("path found")
break
for neighbor in get_neighbors(current, config, ox, oy,
obstacle_kd_tree):
neighbor_index = calc_index(neighbor, config)
if neighbor_index in closedList:
continue
if neighbor not in openList \
or openList[neighbor_index].cost > neighbor.cost:
heapq.heappush(
pq, (calc_cost(neighbor, h_dp, config),
neighbor_index))
openList[neighbor_index] = neighbor
path = get_final_path(closedList, final_path)
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L243-L322
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79
] | 104 |
[
40,
41
] | 2.666667 | false | 90.37037 | 80 | 11 | 97.333333 | 6 |
def hybrid_a_star_planning(start, goal, ox, oy, xy_resolution, yaw_resolution):
start[2], goal[2] = rs.pi_2_pi(start[2]), rs.pi_2_pi(goal[2])
tox, toy = ox[:], oy[:]
obstacle_kd_tree = cKDTree(np.vstack((tox, toy)).T)
config = Config(tox, toy, xy_resolution, yaw_resolution)
start_node = Node(round(start[0] / xy_resolution),
round(start[1] / xy_resolution),
round(start[2] / yaw_resolution), True,
[start[0]], [start[1]], [start[2]], [True], cost=0)
goal_node = Node(round(goal[0] / xy_resolution),
round(goal[1] / xy_resolution),
round(goal[2] / yaw_resolution), True,
[goal[0]], [goal[1]], [goal[2]], [True])
openList, closedList = {}, {}
h_dp = calc_distance_heuristic(
goal_node.x_list[-1], goal_node.y_list[-1],
ox, oy, xy_resolution, BUBBLE_R)
pq = []
openList[calc_index(start_node, config)] = start_node
heapq.heappush(pq, (calc_cost(start_node, h_dp, config),
calc_index(start_node, config)))
final_path = None
while True:
if not openList:
print("Error: Cannot find path, No open set")
return [], [], []
cost, c_id = heapq.heappop(pq)
if c_id in openList:
current = openList.pop(c_id)
closedList[c_id] = current
else:
continue
if show_animation: # pragma: no cover
plt.plot(current.x_list[-1], current.y_list[-1], "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closedList.keys()) % 10 == 0:
plt.pause(0.001)
is_updated, final_path = update_node_with_analytic_expansion(
current, goal_node, config, ox, oy, obstacle_kd_tree)
if is_updated:
print("path found")
break
for neighbor in get_neighbors(current, config, ox, oy,
obstacle_kd_tree):
neighbor_index = calc_index(neighbor, config)
if neighbor_index in closedList:
continue
if neighbor not in openList \
or openList[neighbor_index].cost > neighbor.cost:
heapq.heappush(
pq, (calc_cost(neighbor, h_dp, config),
neighbor_index))
openList[neighbor_index] = neighbor
path = get_final_path(closedList, final_path)
return path
| 1,202 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
calc_cost
|
(n, h_dp, c)
|
return n.cost + H_COST * h_dp[ind].cost
| 325 | 329 |
def calc_cost(n, h_dp, c):
ind = (n.y_index - c.min_y) * c.x_w + (n.x_index - c.min_x)
if ind not in h_dp:
return n.cost + 999999999 # collision cost
return n.cost + H_COST * h_dp[ind].cost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L325-L329
| 2 |
[
0,
1,
2,
4
] | 80 |
[
3
] | 20 | false | 90.37037 | 5 | 2 | 80 | 0 |
def calc_cost(n, h_dp, c):
ind = (n.y_index - c.min_y) * c.x_w + (n.x_index - c.min_x)
if ind not in h_dp:
return n.cost + 999999999 # collision cost
return n.cost + H_COST * h_dp[ind].cost
| 1,203 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
get_final_path
|
(closed, goal_node)
|
return path
| 332 | 359 |
def get_final_path(closed, goal_node):
reversed_x, reversed_y, reversed_yaw = \
list(reversed(goal_node.x_list)), list(reversed(goal_node.y_list)), \
list(reversed(goal_node.yaw_list))
direction = list(reversed(goal_node.directions))
nid = goal_node.parent_index
final_cost = goal_node.cost
while nid:
n = closed[nid]
reversed_x.extend(list(reversed(n.x_list)))
reversed_y.extend(list(reversed(n.y_list)))
reversed_yaw.extend(list(reversed(n.yaw_list)))
direction.extend(list(reversed(n.directions)))
nid = n.parent_index
reversed_x = list(reversed(reversed_x))
reversed_y = list(reversed(reversed_y))
reversed_yaw = list(reversed(reversed_yaw))
direction = list(reversed(direction))
# adjust first direction
direction[0] = direction[1]
path = Path(reversed_x, reversed_y, reversed_yaw, direction, final_cost)
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L332-L359
| 2 |
[
0,
1,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27
] | 92.857143 |
[] | 0 | false | 90.37037 | 28 | 2 | 100 | 0 |
def get_final_path(closed, goal_node):
reversed_x, reversed_y, reversed_yaw = \
list(reversed(goal_node.x_list)), list(reversed(goal_node.y_list)), \
list(reversed(goal_node.yaw_list))
direction = list(reversed(goal_node.directions))
nid = goal_node.parent_index
final_cost = goal_node.cost
while nid:
n = closed[nid]
reversed_x.extend(list(reversed(n.x_list)))
reversed_y.extend(list(reversed(n.y_list)))
reversed_yaw.extend(list(reversed(n.yaw_list)))
direction.extend(list(reversed(n.directions)))
nid = n.parent_index
reversed_x = list(reversed(reversed_x))
reversed_y = list(reversed(reversed_y))
reversed_yaw = list(reversed(reversed_yaw))
direction = list(reversed(direction))
# adjust first direction
direction[0] = direction[1]
path = Path(reversed_x, reversed_y, reversed_yaw, direction, final_cost)
return path
| 1,204 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
verify_index
|
(node, c)
|
return False
| 362 | 367 |
def verify_index(node, c):
x_ind, y_ind = node.x_index, node.y_index
if c.min_x <= x_ind <= c.max_x and c.min_y <= y_ind <= c.max_y:
return True
return False
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L362-L367
| 2 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 90.37037 | 6 | 3 | 83.333333 | 0 |
def verify_index(node, c):
x_ind, y_ind = node.x_index, node.y_index
if c.min_x <= x_ind <= c.max_x and c.min_y <= y_ind <= c.max_y:
return True
return False
| 1,205 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
calc_index
|
(node, c)
|
return ind
| 370 | 377 |
def calc_index(node, c):
ind = (node.yaw_index - c.min_yaw) * c.x_w * c.y_w + \
(node.y_index - c.min_y) * c.x_w + (node.x_index - c.min_x)
if ind <= 0:
print("Error(calc_index):", ind)
return ind
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L370-L377
| 2 |
[
0,
1,
3,
4,
6,
7
] | 75 |
[
5
] | 12.5 | false | 90.37037 | 8 | 2 | 87.5 | 0 |
def calc_index(node, c):
ind = (node.yaw_index - c.min_yaw) * c.x_w * c.y_w + \
(node.y_index - c.min_y) * c.x_w + (node.x_index - c.min_x)
if ind <= 0:
print("Error(calc_index):", ind)
return ind
| 1,206 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
main
|
()
| 380 | 436 |
def main():
print("Start Hybrid A* planning")
ox, oy = [], []
for i in range(60):
ox.append(i)
oy.append(0.0)
for i in range(60):
ox.append(60.0)
oy.append(i)
for i in range(61):
ox.append(i)
oy.append(60.0)
for i in range(61):
ox.append(0.0)
oy.append(i)
for i in range(40):
ox.append(20.0)
oy.append(i)
for i in range(40):
ox.append(40.0)
oy.append(60.0 - i)
# Set Initial parameters
start = [10.0, 10.0, np.deg2rad(90.0)]
goal = [50.0, 50.0, np.deg2rad(-90.0)]
print("start : ", start)
print("goal : ", goal)
if show_animation:
plt.plot(ox, oy, ".k")
rs.plot_arrow(start[0], start[1], start[2], fc='g')
rs.plot_arrow(goal[0], goal[1], goal[2])
plt.grid(True)
plt.axis("equal")
path = hybrid_a_star_planning(
start, goal, ox, oy, XY_GRID_RESOLUTION, YAW_GRID_RESOLUTION)
x = path.x_list
y = path.y_list
yaw = path.yaw_list
if show_animation:
for i_x, i_y, i_yaw in zip(x, y, yaw):
plt.cla()
plt.plot(ox, oy, ".k")
plt.plot(x, y, "-r", label="Hybrid A* path")
plt.grid(True)
plt.axis("equal")
plot_car(i_x, i_y, i_yaw)
plt.pause(0.0001)
print(__file__ + " done!!")
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L380-L436
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
38,
39,
41,
42,
43,
44,
45,
46,
55,
56
] | 73.684211 |
[
32,
33,
34,
36,
37,
47,
48,
49,
50,
51,
52,
53,
54
] | 22.807018 | false | 90.37037 | 57 | 10 | 77.192982 | 0 |
def main():
print("Start Hybrid A* planning")
ox, oy = [], []
for i in range(60):
ox.append(i)
oy.append(0.0)
for i in range(60):
ox.append(60.0)
oy.append(i)
for i in range(61):
ox.append(i)
oy.append(60.0)
for i in range(61):
ox.append(0.0)
oy.append(i)
for i in range(40):
ox.append(20.0)
oy.append(i)
for i in range(40):
ox.append(40.0)
oy.append(60.0 - i)
# Set Initial parameters
start = [10.0, 10.0, np.deg2rad(90.0)]
goal = [50.0, 50.0, np.deg2rad(-90.0)]
print("start : ", start)
print("goal : ", goal)
if show_animation:
plt.plot(ox, oy, ".k")
rs.plot_arrow(start[0], start[1], start[2], fc='g')
rs.plot_arrow(goal[0], goal[1], goal[2])
plt.grid(True)
plt.axis("equal")
path = hybrid_a_star_planning(
start, goal, ox, oy, XY_GRID_RESOLUTION, YAW_GRID_RESOLUTION)
x = path.x_list
y = path.y_list
yaw = path.yaw_list
if show_animation:
for i_x, i_y, i_yaw in zip(x, y, yaw):
plt.cla()
plt.plot(ox, oy, ".k")
plt.plot(x, y, "-r", label="Hybrid A* path")
plt.grid(True)
plt.axis("equal")
plot_car(i_x, i_y, i_yaw)
plt.pause(0.0001)
print(__file__ + " done!!")
| 1,207 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
Node.__init__
|
(self, x_ind, y_ind, yaw_ind, direction,
x_list, y_list, yaw_list, directions,
steer=0.0, parent_index=None, cost=None)
| 38 | 51 |
def __init__(self, x_ind, y_ind, yaw_ind, direction,
x_list, y_list, yaw_list, directions,
steer=0.0, parent_index=None, cost=None):
self.x_index = x_ind
self.y_index = y_ind
self.yaw_index = yaw_ind
self.direction = direction
self.x_list = x_list
self.y_list = y_list
self.yaw_list = yaw_list
self.directions = directions
self.steer = steer
self.parent_index = parent_index
self.cost = cost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L38-L51
| 2 |
[
0,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 85.714286 |
[] | 0 | false | 90.37037 | 14 | 1 | 100 | 0 |
def __init__(self, x_ind, y_ind, yaw_ind, direction,
x_list, y_list, yaw_list, directions,
steer=0.0, parent_index=None, cost=None):
self.x_index = x_ind
self.y_index = y_ind
self.yaw_index = yaw_ind
self.direction = direction
self.x_list = x_list
self.y_list = y_list
self.yaw_list = yaw_list
self.directions = directions
self.steer = steer
self.parent_index = parent_index
self.cost = cost
| 1,208 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
Path.__init__
|
(self, x_list, y_list, yaw_list, direction_list, cost)
| 56 | 61 |
def __init__(self, x_list, y_list, yaw_list, direction_list, cost):
self.x_list = x_list
self.y_list = y_list
self.yaw_list = yaw_list
self.direction_list = direction_list
self.cost = cost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L56-L61
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 90.37037 | 6 | 1 | 100 | 0 |
def __init__(self, x_list, y_list, yaw_list, direction_list, cost):
self.x_list = x_list
self.y_list = y_list
self.yaw_list = yaw_list
self.direction_list = direction_list
self.cost = cost
| 1,209 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/hybrid_a_star.py
|
Config.__init__
|
(self, ox, oy, xy_resolution, yaw_resolution)
| 66 | 87 |
def __init__(self, ox, oy, xy_resolution, yaw_resolution):
min_x_m = min(ox)
min_y_m = min(oy)
max_x_m = max(ox)
max_y_m = max(oy)
ox.append(min_x_m)
oy.append(min_y_m)
ox.append(max_x_m)
oy.append(max_y_m)
self.min_x = round(min_x_m / xy_resolution)
self.min_y = round(min_y_m / xy_resolution)
self.max_x = round(max_x_m / xy_resolution)
self.max_y = round(max_y_m / xy_resolution)
self.x_w = round(self.max_x - self.min_x)
self.y_w = round(self.max_y - self.min_y)
self.min_yaw = round(- math.pi / yaw_resolution) - 1
self.max_yaw = round(math.pi / yaw_resolution)
self.yaw_w = round(self.max_yaw - self.min_yaw)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L66-L87
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 100 |
[] | 0 | true | 90.37037 | 22 | 1 | 100 | 0 |
def __init__(self, ox, oy, xy_resolution, yaw_resolution):
min_x_m = min(ox)
min_y_m = min(oy)
max_x_m = max(ox)
max_y_m = max(oy)
ox.append(min_x_m)
oy.append(min_y_m)
ox.append(max_x_m)
oy.append(max_y_m)
self.min_x = round(min_x_m / xy_resolution)
self.min_y = round(min_y_m / xy_resolution)
self.max_x = round(max_x_m / xy_resolution)
self.max_y = round(max_y_m / xy_resolution)
self.x_w = round(self.max_x - self.min_x)
self.y_w = round(self.max_y - self.min_y)
self.min_yaw = round(- math.pi / yaw_resolution) - 1
self.max_yaw = round(math.pi / yaw_resolution)
self.yaw_w = round(self.max_yaw - self.min_yaw)
| 1,210 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
check_car_collision
|
(x_list, y_list, yaw_list, ox, oy, kd_tree)
|
return True
| 35 | 49 |
def check_car_collision(x_list, y_list, yaw_list, ox, oy, kd_tree):
for i_x, i_y, i_yaw in zip(x_list, y_list, yaw_list):
cx = i_x + BUBBLE_DIST * cos(i_yaw)
cy = i_y + BUBBLE_DIST * sin(i_yaw)
ids = kd_tree.query_ball_point([cx, cy], BUBBLE_R)
if not ids:
continue
if not rectangle_check(i_x, i_y, i_yaw,
[ox[i] for i in ids], [oy[i] for i in ids]):
return False # collision
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L35-L49
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13,
14
] | 93.333333 |
[] | 0 | false | 70.588235 | 15 | 6 | 100 | 0 |
def check_car_collision(x_list, y_list, yaw_list, ox, oy, kd_tree):
for i_x, i_y, i_yaw in zip(x_list, y_list, yaw_list):
cx = i_x + BUBBLE_DIST * cos(i_yaw)
cy = i_y + BUBBLE_DIST * sin(i_yaw)
ids = kd_tree.query_ball_point([cx, cy], BUBBLE_R)
if not ids:
continue
if not rectangle_check(i_x, i_y, i_yaw,
[ox[i] for i in ids], [oy[i] for i in ids]):
return False # collision
return True
| 1,211 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
rectangle_check
|
(x, y, yaw, ox, oy)
|
return True
| 52 | 64 |
def rectangle_check(x, y, yaw, ox, oy):
# transform obstacles to base link frame
rot = rot_mat_2d(yaw)
for iox, ioy in zip(ox, oy):
tx = iox - x
ty = ioy - y
converted_xy = np.stack([tx, ty]).T @ rot
rx, ry = converted_xy[0], converted_xy[1]
if not (rx > LF or rx < -LB or ry > W / 2.0 or ry < -W / 2.0):
return False # no collision
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L52-L64
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 100 |
[] | 0 | true | 70.588235 | 13 | 6 | 100 | 0 |
def rectangle_check(x, y, yaw, ox, oy):
# transform obstacles to base link frame
rot = rot_mat_2d(yaw)
for iox, ioy in zip(ox, oy):
tx = iox - x
ty = ioy - y
converted_xy = np.stack([tx, ty]).T @ rot
rx, ry = converted_xy[0], converted_xy[1]
if not (rx > LF or rx < -LB or ry > W / 2.0 or ry < -W / 2.0):
return False # no collision
return True
| 1,212 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
plot_arrow
|
(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k")
|
Plot arrow.
|
Plot arrow.
| 67 | 74 |
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
"""Plot arrow."""
if not isinstance(x, float):
for (i_x, i_y, i_yaw) in zip(x, y, yaw):
plot_arrow(i_x, i_y, i_yaw)
else:
plt.arrow(x, y, length * cos(yaw), length * sin(yaw),
fc=fc, ec=ec, head_width=width, head_length=width, alpha=0.4)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L67-L74
| 2 |
[
0,
1
] | 25 |
[
2,
3,
4,
6
] | 50 | false | 70.588235 | 8 | 3 | 50 | 1 |
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
if not isinstance(x, float):
for (i_x, i_y, i_yaw) in zip(x, y, yaw):
plot_arrow(i_x, i_y, i_yaw)
else:
plt.arrow(x, y, length * cos(yaw), length * sin(yaw),
fc=fc, ec=ec, head_width=width, head_length=width, alpha=0.4)
| 1,213 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
plot_car
|
(x, y, yaw)
| 77 | 90 |
def plot_car(x, y, yaw):
car_color = '-k'
c, s = cos(yaw), sin(yaw)
rot = rot_mat_2d(-yaw)
car_outline_x, car_outline_y = [], []
for rx, ry in zip(VRX, VRY):
converted_xy = np.stack([rx, ry]).T @ rot
car_outline_x.append(converted_xy[0]+x)
car_outline_y.append(converted_xy[1]+y)
arrow_x, arrow_y, arrow_yaw = c * 1.5 + x, s * 1.5 + y, yaw
plot_arrow(arrow_x, arrow_y, arrow_yaw)
plt.plot(car_outline_x, car_outline_y, car_color)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L77-L90
| 2 |
[
0
] | 7.142857 |
[
1,
2,
3,
4,
5,
6,
7,
8,
10,
11,
13
] | 78.571429 | false | 70.588235 | 14 | 2 | 21.428571 | 0 |
def plot_car(x, y, yaw):
car_color = '-k'
c, s = cos(yaw), sin(yaw)
rot = rot_mat_2d(-yaw)
car_outline_x, car_outline_y = [], []
for rx, ry in zip(VRX, VRY):
converted_xy = np.stack([rx, ry]).T @ rot
car_outline_x.append(converted_xy[0]+x)
car_outline_y.append(converted_xy[1]+y)
arrow_x, arrow_y, arrow_yaw = c * 1.5 + x, s * 1.5 + y, yaw
plot_arrow(arrow_x, arrow_y, arrow_yaw)
plt.plot(car_outline_x, car_outline_y, car_color)
| 1,214 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
pi_2_pi
|
(angle)
|
return (angle + pi) % (2 * pi) - pi
| 93 | 94 |
def pi_2_pi(angle):
return (angle + pi) % (2 * pi) - pi
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L93-L94
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 70.588235 | 2 | 1 | 100 | 0 |
def pi_2_pi(angle):
return (angle + pi) % (2 * pi) - pi
| 1,215 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
move
|
(x, y, yaw, distance, steer, L=WB)
|
return x, y, yaw
| 97 | 102 |
def move(x, y, yaw, distance, steer, L=WB):
x += distance * cos(yaw)
y += distance * sin(yaw)
yaw += pi_2_pi(distance * tan(steer) / L) # distance/2
return x, y, yaw
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L97-L102
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 70.588235 | 6 | 1 | 100 | 0 |
def move(x, y, yaw, distance, steer, L=WB):
x += distance * cos(yaw)
y += distance * sin(yaw)
yaw += pi_2_pi(distance * tan(steer) / L) # distance/2
return x, y, yaw
| 1,216 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/car.py
|
main
|
()
| 105 | 109 |
def main():
x, y, yaw = 0., 0., 1.
plt.axis('equal')
plot_car(x, y, yaw)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/car.py#L105-L109
| 2 |
[
0
] | 20 |
[
1,
2,
3,
4
] | 80 | false | 70.588235 | 5 | 1 | 20 | 0 |
def main():
x, y, yaw = 0., 0., 1.
plt.axis('equal')
plot_car(x, y, yaw)
plt.show()
| 1,217 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
calc_final_path
|
(goal_node, closed_node_set, resolution)
|
return rx, ry
| 32 | 42 |
def calc_final_path(goal_node, closed_node_set, resolution):
# generate final course
rx, ry = [goal_node.x * resolution], [goal_node.y * resolution]
parent_index = goal_node.parent_index
while parent_index != -1:
n = closed_node_set[parent_index]
rx.append(n.x * resolution)
ry.append(n.y * resolution)
parent_index = n.parent_index
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L32-L42
| 2 |
[
0,
1
] | 18.181818 |
[
2,
3,
4,
5,
6,
7,
8,
10
] | 72.727273 | false | 85.227273 | 11 | 2 | 27.272727 | 0 |
def calc_final_path(goal_node, closed_node_set, resolution):
# generate final course
rx, ry = [goal_node.x * resolution], [goal_node.y * resolution]
parent_index = goal_node.parent_index
while parent_index != -1:
n = closed_node_set[parent_index]
rx.append(n.x * resolution)
ry.append(n.y * resolution)
parent_index = n.parent_index
return rx, ry
| 1,218 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
calc_distance_heuristic
|
(gx, gy, ox, oy, resolution, rr)
|
return closed_set
|
gx: goal x position [m]
gx: goal x position [m]
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
|
gx: goal x position [m]
gx: goal x position [m]
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
| 45 | 117 |
def calc_distance_heuristic(gx, gy, ox, oy, resolution, rr):
"""
gx: goal x position [m]
gx: goal x position [m]
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
"""
goal_node = Node(round(gx / resolution), round(gy / resolution), 0.0, -1)
ox = [iox / resolution for iox in ox]
oy = [ioy / resolution for ioy in oy]
obstacle_map, min_x, min_y, max_x, max_y, x_w, y_w = calc_obstacle_map(
ox, oy, resolution, rr)
motion = get_motion_model()
open_set, closed_set = dict(), dict()
open_set[calc_index(goal_node, x_w, min_x, min_y)] = goal_node
priority_queue = [(0, calc_index(goal_node, x_w, min_x, min_y))]
while True:
if not priority_queue:
break
cost, c_id = heapq.heappop(priority_queue)
if c_id in open_set:
current = open_set[c_id]
closed_set[c_id] = current
open_set.pop(c_id)
else:
continue
# show graph
if show_animation: # pragma: no cover
plt.plot(current.x * resolution, current.y * resolution, "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closed_set.keys()) % 10 == 0:
plt.pause(0.001)
# Remove the item from the open set
# expand search grid based on motion model
for i, _ in enumerate(motion):
node = Node(current.x + motion[i][0],
current.y + motion[i][1],
current.cost + motion[i][2], c_id)
n_id = calc_index(node, x_w, min_x, min_y)
if n_id in closed_set:
continue
if not verify_node(node, obstacle_map, min_x, min_y, max_x, max_y):
continue
if n_id not in open_set:
open_set[n_id] = node # Discover a new node
heapq.heappush(
priority_queue,
(node.cost, calc_index(node, x_w, min_x, min_y)))
else:
if open_set[n_id].cost >= node.cost:
# This path is the best until now. record it!
open_set[n_id] = node
heapq.heappush(
priority_queue,
(node.cost, calc_index(node, x_w, min_x, min_y)))
return closed_set
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L45-L117
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72
] | 107.352941 |
[] | 0 | true | 85.227273 | 73 | 13 | 100 | 6 |
def calc_distance_heuristic(gx, gy, ox, oy, resolution, rr):
goal_node = Node(round(gx / resolution), round(gy / resolution), 0.0, -1)
ox = [iox / resolution for iox in ox]
oy = [ioy / resolution for ioy in oy]
obstacle_map, min_x, min_y, max_x, max_y, x_w, y_w = calc_obstacle_map(
ox, oy, resolution, rr)
motion = get_motion_model()
open_set, closed_set = dict(), dict()
open_set[calc_index(goal_node, x_w, min_x, min_y)] = goal_node
priority_queue = [(0, calc_index(goal_node, x_w, min_x, min_y))]
while True:
if not priority_queue:
break
cost, c_id = heapq.heappop(priority_queue)
if c_id in open_set:
current = open_set[c_id]
closed_set[c_id] = current
open_set.pop(c_id)
else:
continue
# show graph
if show_animation: # pragma: no cover
plt.plot(current.x * resolution, current.y * resolution, "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closed_set.keys()) % 10 == 0:
plt.pause(0.001)
# Remove the item from the open set
# expand search grid based on motion model
for i, _ in enumerate(motion):
node = Node(current.x + motion[i][0],
current.y + motion[i][1],
current.cost + motion[i][2], c_id)
n_id = calc_index(node, x_w, min_x, min_y)
if n_id in closed_set:
continue
if not verify_node(node, obstacle_map, min_x, min_y, max_x, max_y):
continue
if n_id not in open_set:
open_set[n_id] = node # Discover a new node
heapq.heappush(
priority_queue,
(node.cost, calc_index(node, x_w, min_x, min_y)))
else:
if open_set[n_id].cost >= node.cost:
# This path is the best until now. record it!
open_set[n_id] = node
heapq.heappush(
priority_queue,
(node.cost, calc_index(node, x_w, min_x, min_y)))
return closed_set
| 1,219 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
verify_node
|
(node, obstacle_map, min_x, min_y, max_x, max_y)
|
return True
| 120 | 133 |
def verify_node(node, obstacle_map, min_x, min_y, max_x, max_y):
if node.x < min_x:
return False
elif node.y < min_y:
return False
elif node.x >= max_x:
return False
elif node.y >= max_y:
return False
if obstacle_map[node.x][node.y]:
return False
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L120-L133
| 2 |
[
0,
1,
3,
5,
7,
9,
10,
11,
12,
13
] | 71.428571 |
[
2,
4,
6,
8
] | 28.571429 | false | 85.227273 | 14 | 6 | 71.428571 | 0 |
def verify_node(node, obstacle_map, min_x, min_y, max_x, max_y):
if node.x < min_x:
return False
elif node.y < min_y:
return False
elif node.x >= max_x:
return False
elif node.y >= max_y:
return False
if obstacle_map[node.x][node.y]:
return False
return True
| 1,220 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
calc_obstacle_map
|
(ox, oy, resolution, vr)
|
return obstacle_map, min_x, min_y, max_x, max_y, x_width, y_width
| 136 | 158 |
def calc_obstacle_map(ox, oy, resolution, vr):
min_x = round(min(ox))
min_y = round(min(oy))
max_x = round(max(ox))
max_y = round(max(oy))
x_width = round(max_x - min_x)
y_width = round(max_y - min_y)
# obstacle map generation
obstacle_map = [[False for _ in range(y_width)] for _ in range(x_width)]
for ix in range(x_width):
x = ix + min_x
for iy in range(y_width):
y = iy + min_y
# print(x, y)
for iox, ioy in zip(ox, oy):
d = math.sqrt((iox - x) ** 2 + (ioy - y) ** 2)
if d <= vr / resolution:
obstacle_map[ix][iy] = True
break
return obstacle_map, min_x, min_y, max_x, max_y, x_width, y_width
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L136-L158
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22
] | 100 |
[] | 0 | true | 85.227273 | 23 | 7 | 100 | 0 |
def calc_obstacle_map(ox, oy, resolution, vr):
min_x = round(min(ox))
min_y = round(min(oy))
max_x = round(max(ox))
max_y = round(max(oy))
x_width = round(max_x - min_x)
y_width = round(max_y - min_y)
# obstacle map generation
obstacle_map = [[False for _ in range(y_width)] for _ in range(x_width)]
for ix in range(x_width):
x = ix + min_x
for iy in range(y_width):
y = iy + min_y
# print(x, y)
for iox, ioy in zip(ox, oy):
d = math.sqrt((iox - x) ** 2 + (ioy - y) ** 2)
if d <= vr / resolution:
obstacle_map[ix][iy] = True
break
return obstacle_map, min_x, min_y, max_x, max_y, x_width, y_width
| 1,221 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
calc_index
|
(node, x_width, x_min, y_min)
|
return (node.y - y_min) * x_width + (node.x - x_min)
| 161 | 162 |
def calc_index(node, x_width, x_min, y_min):
return (node.y - y_min) * x_width + (node.x - x_min)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L161-L162
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 85.227273 | 2 | 1 | 100 | 0 |
def calc_index(node, x_width, x_min, y_min):
return (node.y - y_min) * x_width + (node.x - x_min)
| 1,222 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
get_motion_model
|
()
|
return motion
| 165 | 176 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L165-L176
| 2 |
[
0,
1,
2,
10,
11
] | 41.666667 |
[] | 0 | false | 85.227273 | 12 | 1 | 100 | 0 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
| 1,223 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
Node.__init__
|
(self, x, y, cost, parent_index)
| 21 | 25 |
def __init__(self, x, y, cost, parent_index):
self.x = x
self.y = y
self.cost = cost
self.parent_index = parent_index
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L21-L25
| 2 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 85.227273 | 5 | 1 | 100 | 0 |
def __init__(self, x, y, cost, parent_index):
self.x = x
self.y = y
self.cost = cost
self.parent_index = parent_index
| 1,224 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/HybridAStar/dynamic_programming_heuristic.py
|
Node.__str__
|
(self)
|
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.parent_index)
| 27 | 29 |
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.parent_index)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/dynamic_programming_heuristic.py#L27-L29
| 2 |
[
0
] | 33.333333 |
[
1
] | 33.333333 | false | 85.227273 | 3 | 1 | 66.666667 | 0 |
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.parent_index)
| 1,225 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
draw_horizontal_line
|
(start_x, start_y, length, o_x, o_y, o_dict)
| 24 | 29 |
def draw_horizontal_line(start_x, start_y, length, o_x, o_y, o_dict):
for i in range(start_x, start_x + length):
for j in range(start_y, start_y + 2):
o_x.append(i)
o_y.append(j)
o_dict[(i, j)] = True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L24-L29
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 89.473684 | 6 | 3 | 100 | 0 |
def draw_horizontal_line(start_x, start_y, length, o_x, o_y, o_dict):
for i in range(start_x, start_x + length):
for j in range(start_y, start_y + 2):
o_x.append(i)
o_y.append(j)
o_dict[(i, j)] = True
| 1,226 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
draw_vertical_line
|
(start_x, start_y, length, o_x, o_y, o_dict)
| 32 | 37 |
def draw_vertical_line(start_x, start_y, length, o_x, o_y, o_dict):
for i in range(start_x, start_x + 2):
for j in range(start_y, start_y + length):
o_x.append(i)
o_y.append(j)
o_dict[(i, j)] = True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L32-L37
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 89.473684 | 6 | 3 | 100 | 0 |
def draw_vertical_line(start_x, start_y, length, o_x, o_y, o_dict):
for i in range(start_x, start_x + 2):
for j in range(start_y, start_y + length):
o_x.append(i)
o_y.append(j)
o_dict[(i, j)] = True
| 1,227 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
in_line_of_sight
|
(obs_grid, x1, y1, x2, y2)
|
return True, dist
| 40 | 53 |
def in_line_of_sight(obs_grid, x1, y1, x2, y2):
t = 0
while t <= 0.5:
xt = (1 - t) * x1 + t * x2
yt = (1 - t) * y1 + t * y2
if obs_grid[(int(xt), int(yt))]:
return False, None
xt = (1 - t) * x2 + t * x1
yt = (1 - t) * y2 + t * y1
if obs_grid[(int(xt), int(yt))]:
return False, None
t += 0.001
dist = np.linalg.norm(np.array([x1, y1] - np.array([x2, y2])))
return True, dist
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L40-L53
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 89.473684 | 14 | 4 | 100 | 0 |
def in_line_of_sight(obs_grid, x1, y1, x2, y2):
t = 0
while t <= 0.5:
xt = (1 - t) * x1 + t * x2
yt = (1 - t) * y1 + t * y2
if obs_grid[(int(xt), int(yt))]:
return False, None
xt = (1 - t) * x2 + t * x1
yt = (1 - t) * y2 + t * y1
if obs_grid[(int(xt), int(yt))]:
return False, None
t += 0.001
dist = np.linalg.norm(np.array([x1, y1] - np.array([x2, y2])))
return True, dist
| 1,228 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
key_points
|
(o_dict)
|
return c_list + e_list
| 56 | 112 |
def key_points(o_dict):
offsets1 = [(1, 0), (0, 1), (-1, 0), (1, 0)]
offsets2 = [(1, 1), (-1, 1), (-1, -1), (1, -1)]
offsets3 = [(0, 1), (-1, 0), (0, -1), (0, -1)]
c_list = []
for grid_point, obs_status in o_dict.items():
if obs_status:
continue
empty_space = True
x, y = grid_point
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if (x + i, y + j) not in o_dict.keys():
continue
if o_dict[(x + i, y + j)]:
empty_space = False
break
if empty_space:
continue
for offset1, offset2, offset3 in zip(offsets1, offsets2, offsets3):
i1, j1 = offset1
i2, j2 = offset2
i3, j3 = offset3
if ((x + i1, y + j1) not in o_dict.keys()) or \
((x + i2, y + j2) not in o_dict.keys()) or \
((x + i3, y + j3) not in o_dict.keys()):
continue
obs_count = 0
if o_dict[(x + i1, y + j1)]:
obs_count += 1
if o_dict[(x + i2, y + j2)]:
obs_count += 1
if o_dict[(x + i3, y + j3)]:
obs_count += 1
if obs_count == 3 or obs_count == 1:
c_list.append((x, y))
if show_animation:
plt.plot(x, y, ".y")
break
if only_corners:
return c_list
e_list = []
for corner in c_list:
x1, y1 = corner
for other_corner in c_list:
x2, y2 = other_corner
if x1 == x2 and y1 == y2:
continue
reachable, _ = in_line_of_sight(o_dict, x1, y1, x2, y2)
if not reachable:
continue
x_m, y_m = int((x1 + x2) / 2), int((y1 + y2) / 2)
e_list.append((x_m, y_m))
if show_animation:
plt.plot(x_m, y_m, ".y")
return c_list + e_list
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L56-L112
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
38,
39,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
56
] | 91.22807 |
[
37,
40,
55
] | 5.263158 | false | 89.473684 | 57 | 25 | 94.736842 | 0 |
def key_points(o_dict):
offsets1 = [(1, 0), (0, 1), (-1, 0), (1, 0)]
offsets2 = [(1, 1), (-1, 1), (-1, -1), (1, -1)]
offsets3 = [(0, 1), (-1, 0), (0, -1), (0, -1)]
c_list = []
for grid_point, obs_status in o_dict.items():
if obs_status:
continue
empty_space = True
x, y = grid_point
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if (x + i, y + j) not in o_dict.keys():
continue
if o_dict[(x + i, y + j)]:
empty_space = False
break
if empty_space:
continue
for offset1, offset2, offset3 in zip(offsets1, offsets2, offsets3):
i1, j1 = offset1
i2, j2 = offset2
i3, j3 = offset3
if ((x + i1, y + j1) not in o_dict.keys()) or \
((x + i2, y + j2) not in o_dict.keys()) or \
((x + i3, y + j3) not in o_dict.keys()):
continue
obs_count = 0
if o_dict[(x + i1, y + j1)]:
obs_count += 1
if o_dict[(x + i2, y + j2)]:
obs_count += 1
if o_dict[(x + i3, y + j3)]:
obs_count += 1
if obs_count == 3 or obs_count == 1:
c_list.append((x, y))
if show_animation:
plt.plot(x, y, ".y")
break
if only_corners:
return c_list
e_list = []
for corner in c_list:
x1, y1 = corner
for other_corner in c_list:
x2, y2 = other_corner
if x1 == x2 and y1 == y2:
continue
reachable, _ = in_line_of_sight(o_dict, x1, y1, x2, y2)
if not reachable:
continue
x_m, y_m = int((x1 + x2) / 2), int((y1 + y2) / 2)
e_list.append((x_m, y_m))
if show_animation:
plt.plot(x_m, y_m, ".y")
return c_list + e_list
| 1,229 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
main
|
()
| 433 | 479 |
def main():
# set obstacle positions
obs_dict = {}
for i in range(51):
for j in range(51):
obs_dict[(i, j)] = False
o_x, o_y = [], []
s_x = 5.0
s_y = 5.0
g_x = 35.0
g_y = 45.0
# draw outer border of maze
draw_vertical_line(0, 0, 50, o_x, o_y, obs_dict)
draw_vertical_line(48, 0, 50, o_x, o_y, obs_dict)
draw_horizontal_line(0, 0, 50, o_x, o_y, obs_dict)
draw_horizontal_line(0, 48, 50, o_x, o_y, obs_dict)
# draw inner walls
all_x = [10, 10, 10, 15, 20, 20, 30, 30, 35, 30, 40, 45]
all_y = [10, 30, 45, 20, 5, 40, 10, 40, 5, 40, 10, 25]
all_len = [10, 10, 5, 10, 10, 5, 20, 10, 25, 10, 35, 15]
for x, y, l in zip(all_x, all_y, all_len):
draw_vertical_line(x, y, l, o_x, o_y, obs_dict)
all_x[:], all_y[:], all_len[:] = [], [], []
all_x = [35, 40, 15, 10, 45, 20, 10, 15, 25, 45, 10, 30, 10, 40]
all_y = [5, 10, 15, 20, 20, 25, 30, 35, 35, 35, 40, 40, 45, 45]
all_len = [10, 5, 10, 10, 5, 5, 10, 5, 10, 5, 10, 5, 5, 5]
for x, y, l in zip(all_x, all_y, all_len):
draw_horizontal_line(x, y, l, o_x, o_y, obs_dict)
if show_animation:
plt.plot(o_x, o_y, ".k")
plt.plot(s_x, s_y, "og")
plt.plot(g_x, g_y, "xb")
plt.grid(True)
if use_jump_point:
keypoint_list = key_points(obs_dict)
search_obj = SearchAlgo(obs_dict, g_x, g_y, s_x, s_y, 101, 101,
keypoint_list)
search_obj.jump_point()
else:
search_obj = SearchAlgo(obs_dict, g_x, g_y, s_x, s_y, 101, 101)
search_obj.a_star()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L433-L479
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
38,
39,
40,
41,
43,
45,
46
] | 87.234043 |
[
34,
35,
36,
37
] | 8.510638 | false | 89.473684 | 47 | 7 | 91.489362 | 0 |
def main():
# set obstacle positions
obs_dict = {}
for i in range(51):
for j in range(51):
obs_dict[(i, j)] = False
o_x, o_y = [], []
s_x = 5.0
s_y = 5.0
g_x = 35.0
g_y = 45.0
# draw outer border of maze
draw_vertical_line(0, 0, 50, o_x, o_y, obs_dict)
draw_vertical_line(48, 0, 50, o_x, o_y, obs_dict)
draw_horizontal_line(0, 0, 50, o_x, o_y, obs_dict)
draw_horizontal_line(0, 48, 50, o_x, o_y, obs_dict)
# draw inner walls
all_x = [10, 10, 10, 15, 20, 20, 30, 30, 35, 30, 40, 45]
all_y = [10, 30, 45, 20, 5, 40, 10, 40, 5, 40, 10, 25]
all_len = [10, 10, 5, 10, 10, 5, 20, 10, 25, 10, 35, 15]
for x, y, l in zip(all_x, all_y, all_len):
draw_vertical_line(x, y, l, o_x, o_y, obs_dict)
all_x[:], all_y[:], all_len[:] = [], [], []
all_x = [35, 40, 15, 10, 45, 20, 10, 15, 25, 45, 10, 30, 10, 40]
all_y = [5, 10, 15, 20, 20, 25, 30, 35, 35, 35, 40, 40, 45, 45]
all_len = [10, 5, 10, 10, 5, 5, 10, 5, 10, 5, 10, 5, 5, 5]
for x, y, l in zip(all_x, all_y, all_len):
draw_horizontal_line(x, y, l, o_x, o_y, obs_dict)
if show_animation:
plt.plot(o_x, o_y, ".k")
plt.plot(s_x, s_y, "og")
plt.plot(g_x, g_y, "xb")
plt.grid(True)
if use_jump_point:
keypoint_list = key_points(obs_dict)
search_obj = SearchAlgo(obs_dict, g_x, g_y, s_x, s_y, 101, 101,
keypoint_list)
search_obj.jump_point()
else:
search_obj = SearchAlgo(obs_dict, g_x, g_y, s_x, s_y, 101, 101)
search_obj.a_star()
| 1,230 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.__init__
|
(self, obs_grid, goal_x, goal_y, start_x, start_y,
limit_x, limit_y, corner_list=None)
| 116 | 150 |
def __init__(self, obs_grid, goal_x, goal_y, start_x, start_y,
limit_x, limit_y, corner_list=None):
self.start_pt = [start_x, start_y]
self.goal_pt = [goal_x, goal_y]
self.obs_grid = obs_grid
g_cost, h_cost = 0, self.get_hval(start_x, start_y, goal_x, goal_y)
f_cost = g_cost + h_cost
self.all_nodes, self.open_set = {}, []
if use_jump_point:
for corner in corner_list:
i, j = corner
h_c = self.get_hval(i, j, goal_x, goal_y)
self.all_nodes[(i, j)] = {'pos': [i, j], 'pred': None,
'gcost': np.inf, 'hcost': h_c,
'fcost': np.inf,
'open': True, 'in_open_list': False}
self.all_nodes[tuple(self.goal_pt)] = \
{'pos': self.goal_pt, 'pred': None,
'gcost': np.inf, 'hcost': 0, 'fcost': np.inf,
'open': True, 'in_open_list': True}
else:
for i in range(limit_x):
for j in range(limit_y):
h_c = self.get_hval(i, j, goal_x, goal_y)
self.all_nodes[(i, j)] = {'pos': [i, j], 'pred': None,
'gcost': np.inf, 'hcost': h_c,
'fcost': np.inf,
'open': True,
'in_open_list': False}
self.all_nodes[tuple(self.start_pt)] = \
{'pos': self.start_pt, 'pred': None,
'gcost': g_cost, 'hcost': h_cost, 'fcost': f_cost,
'open': True, 'in_open_list': True}
self.open_set.append(self.all_nodes[tuple(self.start_pt)])
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L116-L150
| 2 |
[
0,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
17,
22,
23,
24,
25,
30,
34
] | 57.142857 |
[] | 0 | false | 89.473684 | 35 | 5 | 100 | 0 |
def __init__(self, obs_grid, goal_x, goal_y, start_x, start_y,
limit_x, limit_y, corner_list=None):
self.start_pt = [start_x, start_y]
self.goal_pt = [goal_x, goal_y]
self.obs_grid = obs_grid
g_cost, h_cost = 0, self.get_hval(start_x, start_y, goal_x, goal_y)
f_cost = g_cost + h_cost
self.all_nodes, self.open_set = {}, []
if use_jump_point:
for corner in corner_list:
i, j = corner
h_c = self.get_hval(i, j, goal_x, goal_y)
self.all_nodes[(i, j)] = {'pos': [i, j], 'pred': None,
'gcost': np.inf, 'hcost': h_c,
'fcost': np.inf,
'open': True, 'in_open_list': False}
self.all_nodes[tuple(self.goal_pt)] = \
{'pos': self.goal_pt, 'pred': None,
'gcost': np.inf, 'hcost': 0, 'fcost': np.inf,
'open': True, 'in_open_list': True}
else:
for i in range(limit_x):
for j in range(limit_y):
h_c = self.get_hval(i, j, goal_x, goal_y)
self.all_nodes[(i, j)] = {'pos': [i, j], 'pred': None,
'gcost': np.inf, 'hcost': h_c,
'fcost': np.inf,
'open': True,
'in_open_list': False}
self.all_nodes[tuple(self.start_pt)] = \
{'pos': self.start_pt, 'pred': None,
'gcost': g_cost, 'hcost': h_cost, 'fcost': f_cost,
'open': True, 'in_open_list': True}
self.open_set.append(self.all_nodes[tuple(self.start_pt)])
| 1,231 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.get_hval
|
(x1, y1, x2, y2)
|
return val
| 153 | 162 |
def get_hval(x1, y1, x2, y2):
x, y = x1, y1
val = 0
while x != x2 or y != y2:
if x != x2 and y != y2:
val += 14
else:
val += 10
x, y = x + np.sign(x2 - x), y + np.sign(y2 - y)
return val
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L153-L162
| 2 |
[
0,
1,
2,
3,
4,
5,
7,
8,
9
] | 90 |
[] | 0 | false | 89.473684 | 10 | 5 | 100 | 0 |
def get_hval(x1, y1, x2, y2):
x, y = x1, y1
val = 0
while x != x2 or y != y2:
if x != x2 and y != y2:
val += 14
else:
val += 10
x, y = x + np.sign(x2 - x), y + np.sign(y2 - y)
return val
| 1,232 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.get_farthest_point
|
(self, x, y, i, j)
|
return i_temp - 2*i, j_temp - 2*j, counter, got_goal
| 164 | 178 |
def get_farthest_point(self, x, y, i, j):
i_temp, j_temp = i, j
counter = 1
got_goal = False
while not self.obs_grid[(x + i_temp, y + j_temp)] and \
counter < max_theta:
i_temp += i
j_temp += j
counter += 1
if [x + i_temp, y + j_temp] == self.goal_pt:
got_goal = True
break
if (x + i_temp, y + j_temp) not in self.obs_grid.keys():
break
return i_temp - 2*i, j_temp - 2*j, counter, got_goal
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L164-L178
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
11,
12,
14
] | 86.666667 |
[
13
] | 6.666667 | false | 89.473684 | 15 | 5 | 93.333333 | 0 |
def get_farthest_point(self, x, y, i, j):
i_temp, j_temp = i, j
counter = 1
got_goal = False
while not self.obs_grid[(x + i_temp, y + j_temp)] and \
counter < max_theta:
i_temp += i
j_temp += j
counter += 1
if [x + i_temp, y + j_temp] == self.goal_pt:
got_goal = True
break
if (x + i_temp, y + j_temp) not in self.obs_grid.keys():
break
return i_temp - 2*i, j_temp - 2*j, counter, got_goal
| 1,233 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.jump_point
|
(self)
|
Jump point: Instead of exploring all empty spaces of the
map, just explore the corners.
|
Jump point: Instead of exploring all empty spaces of the
map, just explore the corners.
| 180 | 265 |
def jump_point(self):
"""Jump point: Instead of exploring all empty spaces of the
map, just explore the corners."""
goal_found = False
while len(self.open_set) > 0:
self.open_set = sorted(self.open_set, key=lambda x: x['fcost'])
lowest_f = self.open_set[0]['fcost']
lowest_h = self.open_set[0]['hcost']
lowest_g = self.open_set[0]['gcost']
p = 0
for p_n in self.open_set[1:]:
if p_n['fcost'] == lowest_f and \
p_n['gcost'] < lowest_g:
lowest_g = p_n['gcost']
p += 1
elif p_n['fcost'] == lowest_f and \
p_n['gcost'] == lowest_g and \
p_n['hcost'] < lowest_h:
lowest_h = p_n['hcost']
p += 1
else:
break
current_node = self.all_nodes[tuple(self.open_set[p]['pos'])]
x1, y1 = current_node['pos']
for cand_pt, cand_node in self.all_nodes.items():
x2, y2 = cand_pt
if x1 == x2 and y1 == y2:
continue
if np.linalg.norm(np.array([x1, y1] -
np.array([x2, y2]))) > max_corner:
continue
reachable, offset = in_line_of_sight(self.obs_grid, x1,
y1, x2, y2)
if not reachable:
continue
if list(cand_pt) == self.goal_pt:
current_node['open'] = False
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
goal_found = True
break
g_cost = offset + current_node['gcost']
h_cost = self.all_nodes[cand_pt]['hcost']
f_cost = g_cost + h_cost
cand_pt = tuple(cand_pt)
if f_cost < self.all_nodes[cand_pt]['fcost']:
self.all_nodes[cand_pt]['pred'] = current_node['pos']
self.all_nodes[cand_pt]['gcost'] = g_cost
self.all_nodes[cand_pt]['fcost'] = f_cost
if not self.all_nodes[cand_pt]['in_open_list']:
self.open_set.append(self.all_nodes[cand_pt])
self.all_nodes[cand_pt]['in_open_list'] = True
if show_animation:
plt.plot(cand_pt[0], cand_pt[1], "r*")
if goal_found:
break
if show_animation:
plt.pause(0.001)
if goal_found:
current_node = self.all_nodes[tuple(self.goal_pt)]
while goal_found:
if current_node['pred'] is None:
break
x = [current_node['pos'][0], current_node['pred'][0]]
y = [current_node['pos'][1], current_node['pred'][1]]
current_node = self.all_nodes[tuple(current_node['pred'])]
if show_animation:
plt.plot(x, y, "b")
plt.pause(0.001)
if goal_found:
break
current_node['open'] = False
current_node['in_open_list'] = False
if show_animation:
plt.plot(current_node['pos'][0], current_node['pos'][1], "g*")
del self.open_set[p]
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
if show_animation:
plt.title('Jump Point')
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L180-L265
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
16,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
35,
36,
37,
38,
39,
40,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
58,
59,
61,
63,
64,
65,
66,
67,
68,
69,
70,
71,
74,
75,
76,
77,
78,
79,
81,
82,
83
] | 77.906977 |
[
14,
15,
19,
20,
57,
60,
62,
72,
73,
80,
84,
85
] | 13.953488 | false | 89.473684 | 86 | 26 | 86.046512 | 2 |
def jump_point(self):
goal_found = False
while len(self.open_set) > 0:
self.open_set = sorted(self.open_set, key=lambda x: x['fcost'])
lowest_f = self.open_set[0]['fcost']
lowest_h = self.open_set[0]['hcost']
lowest_g = self.open_set[0]['gcost']
p = 0
for p_n in self.open_set[1:]:
if p_n['fcost'] == lowest_f and \
p_n['gcost'] < lowest_g:
lowest_g = p_n['gcost']
p += 1
elif p_n['fcost'] == lowest_f and \
p_n['gcost'] == lowest_g and \
p_n['hcost'] < lowest_h:
lowest_h = p_n['hcost']
p += 1
else:
break
current_node = self.all_nodes[tuple(self.open_set[p]['pos'])]
x1, y1 = current_node['pos']
for cand_pt, cand_node in self.all_nodes.items():
x2, y2 = cand_pt
if x1 == x2 and y1 == y2:
continue
if np.linalg.norm(np.array([x1, y1] -
np.array([x2, y2]))) > max_corner:
continue
reachable, offset = in_line_of_sight(self.obs_grid, x1,
y1, x2, y2)
if not reachable:
continue
if list(cand_pt) == self.goal_pt:
current_node['open'] = False
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
goal_found = True
break
g_cost = offset + current_node['gcost']
h_cost = self.all_nodes[cand_pt]['hcost']
f_cost = g_cost + h_cost
cand_pt = tuple(cand_pt)
if f_cost < self.all_nodes[cand_pt]['fcost']:
self.all_nodes[cand_pt]['pred'] = current_node['pos']
self.all_nodes[cand_pt]['gcost'] = g_cost
self.all_nodes[cand_pt]['fcost'] = f_cost
if not self.all_nodes[cand_pt]['in_open_list']:
self.open_set.append(self.all_nodes[cand_pt])
self.all_nodes[cand_pt]['in_open_list'] = True
if show_animation:
plt.plot(cand_pt[0], cand_pt[1], "r*")
if goal_found:
break
if show_animation:
plt.pause(0.001)
if goal_found:
current_node = self.all_nodes[tuple(self.goal_pt)]
while goal_found:
if current_node['pred'] is None:
break
x = [current_node['pos'][0], current_node['pred'][0]]
y = [current_node['pos'][1], current_node['pred'][1]]
current_node = self.all_nodes[tuple(current_node['pred'])]
if show_animation:
plt.plot(x, y, "b")
plt.pause(0.001)
if goal_found:
break
current_node['open'] = False
current_node['in_open_list'] = False
if show_animation:
plt.plot(current_node['pos'][0], current_node['pos'][1], "g*")
del self.open_set[p]
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
if show_animation:
plt.title('Jump Point')
plt.show()
| 1,234 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.a_star
|
(self)
|
Beam search: Maintain an open list of just 30 nodes.
If more than 30 nodes, then get rid of nodes with high
f values.
Iterative deepening: At every iteration, get a cut-off
value for the f cost. This cut-off is minimum of the f
value of all nodes whose f value is higher than the
current cut-off value. Nodes with f value higher than
the current cut off value are not put in the open set.
Dynamic weighting: Multiply heuristic with the following:
(1 + epsilon - (epsilon*d)/N) where d is the current
iteration of loop and N is upper bound on number of
iterations.
Theta star: Same as A star but you don't need to move
one neighbor at a time. In fact, you can look for the
next node as far out as you can as long as there is a
clear line of sight from your current node to that node.
|
Beam search: Maintain an open list of just 30 nodes.
If more than 30 nodes, then get rid of nodes with high
f values.
Iterative deepening: At every iteration, get a cut-off
value for the f cost. This cut-off is minimum of the f
value of all nodes whose f value is higher than the
current cut-off value. Nodes with f value higher than
the current cut off value are not put in the open set.
Dynamic weighting: Multiply heuristic with the following:
(1 + epsilon - (epsilon*d)/N) where d is the current
iteration of loop and N is upper bound on number of
iterations.
Theta star: Same as A star but you don't need to move
one neighbor at a time. In fact, you can look for the
next node as far out as you can as long as there is a
clear line of sight from your current node to that node.
| 267 | 404 |
def a_star(self):
"""Beam search: Maintain an open list of just 30 nodes.
If more than 30 nodes, then get rid of nodes with high
f values.
Iterative deepening: At every iteration, get a cut-off
value for the f cost. This cut-off is minimum of the f
value of all nodes whose f value is higher than the
current cut-off value. Nodes with f value higher than
the current cut off value are not put in the open set.
Dynamic weighting: Multiply heuristic with the following:
(1 + epsilon - (epsilon*d)/N) where d is the current
iteration of loop and N is upper bound on number of
iterations.
Theta star: Same as A star but you don't need to move
one neighbor at a time. In fact, you can look for the
next node as far out as you can as long as there is a
clear line of sight from your current node to that node."""
if show_animation:
if use_beam_search:
plt.title('A* with beam search')
elif use_iterative_deepening:
plt.title('A* with iterative deepening')
elif use_dynamic_weighting:
plt.title('A* with dynamic weighting')
elif use_theta_star:
plt.title('Theta*')
else:
plt.title('A*')
goal_found = False
curr_f_thresh = np.inf
depth = 0
no_valid_f = False
w = None
while len(self.open_set) > 0:
self.open_set = sorted(self.open_set, key=lambda x: x['fcost'])
lowest_f = self.open_set[0]['fcost']
lowest_h = self.open_set[0]['hcost']
lowest_g = self.open_set[0]['gcost']
p = 0
for p_n in self.open_set[1:]:
if p_n['fcost'] == lowest_f and \
p_n['gcost'] < lowest_g:
lowest_g = p_n['gcost']
p += 1
elif p_n['fcost'] == lowest_f and \
p_n['gcost'] == lowest_g and \
p_n['hcost'] < lowest_h:
lowest_h = p_n['hcost']
p += 1
else:
break
current_node = self.all_nodes[tuple(self.open_set[p]['pos'])]
while len(self.open_set) > beam_capacity and use_beam_search:
del self.open_set[-1]
f_cost_list = []
if use_dynamic_weighting:
w = (1 + epsilon - epsilon*depth/upper_bound_depth)
for i in range(-1, 2):
for j in range(-1, 2):
x, y = current_node['pos']
if (i == 0 and j == 0) or \
((x + i, y + j) not in self.obs_grid.keys()):
continue
if (i, j) in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
offset = 10
else:
offset = 14
if use_theta_star:
new_i, new_j, counter, goal_found = \
self.get_farthest_point(x, y, i, j)
offset = offset * counter
cand_pt = [current_node['pos'][0] + new_i,
current_node['pos'][1] + new_j]
else:
cand_pt = [current_node['pos'][0] + i,
current_node['pos'][1] + j]
if use_theta_star and goal_found:
current_node['open'] = False
cand_pt = self.goal_pt
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
break
if cand_pt == self.goal_pt:
current_node['open'] = False
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
goal_found = True
break
cand_pt = tuple(cand_pt)
no_valid_f = self.update_node_cost(cand_pt, curr_f_thresh,
current_node,
f_cost_list, no_valid_f,
offset, w)
if goal_found:
break
if show_animation:
plt.pause(0.001)
if goal_found:
current_node = self.all_nodes[tuple(self.goal_pt)]
while goal_found:
if current_node['pred'] is None:
break
if use_theta_star or use_jump_point:
x, y = [current_node['pos'][0], current_node['pred'][0]], \
[current_node['pos'][1], current_node['pred'][1]]
if show_animation:
plt.plot(x, y, "b")
else:
if show_animation:
plt.plot(current_node['pred'][0],
current_node['pred'][1], "b*")
current_node = self.all_nodes[tuple(current_node['pred'])]
if goal_found:
break
if use_iterative_deepening and f_cost_list:
curr_f_thresh = min(f_cost_list)
if use_iterative_deepening and not f_cost_list:
curr_f_thresh = np.inf
if use_iterative_deepening and not f_cost_list and no_valid_f:
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
continue
current_node['open'] = False
current_node['in_open_list'] = False
if show_animation:
plt.plot(current_node['pos'][0], current_node['pos'][1], "g*")
del self.open_set[p]
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
depth += 1
if show_animation:
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L267-L404
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
43,
44,
45,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
65,
66,
67,
69,
70,
71,
73,
74,
77,
79,
80,
81,
82,
83,
85,
86,
87,
88,
89,
91,
92,
93,
94,
95,
99,
100,
101,
103,
104,
105,
106,
107,
108,
109,
111,
114,
117,
118,
119,
120,
121,
122,
123,
124,
125,
126,
127,
128,
129,
130,
131,
133,
134,
135,
136
] | 74.637681 |
[
18,
19,
20,
21,
22,
23,
24,
25,
27,
48,
49,
102,
112,
115,
132,
137
] | 11.594203 | false | 89.473684 | 138 | 45 | 88.405797 | 16 |
def a_star(self):
if show_animation:
if use_beam_search:
plt.title('A* with beam search')
elif use_iterative_deepening:
plt.title('A* with iterative deepening')
elif use_dynamic_weighting:
plt.title('A* with dynamic weighting')
elif use_theta_star:
plt.title('Theta*')
else:
plt.title('A*')
goal_found = False
curr_f_thresh = np.inf
depth = 0
no_valid_f = False
w = None
while len(self.open_set) > 0:
self.open_set = sorted(self.open_set, key=lambda x: x['fcost'])
lowest_f = self.open_set[0]['fcost']
lowest_h = self.open_set[0]['hcost']
lowest_g = self.open_set[0]['gcost']
p = 0
for p_n in self.open_set[1:]:
if p_n['fcost'] == lowest_f and \
p_n['gcost'] < lowest_g:
lowest_g = p_n['gcost']
p += 1
elif p_n['fcost'] == lowest_f and \
p_n['gcost'] == lowest_g and \
p_n['hcost'] < lowest_h:
lowest_h = p_n['hcost']
p += 1
else:
break
current_node = self.all_nodes[tuple(self.open_set[p]['pos'])]
while len(self.open_set) > beam_capacity and use_beam_search:
del self.open_set[-1]
f_cost_list = []
if use_dynamic_weighting:
w = (1 + epsilon - epsilon*depth/upper_bound_depth)
for i in range(-1, 2):
for j in range(-1, 2):
x, y = current_node['pos']
if (i == 0 and j == 0) or \
((x + i, y + j) not in self.obs_grid.keys()):
continue
if (i, j) in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
offset = 10
else:
offset = 14
if use_theta_star:
new_i, new_j, counter, goal_found = \
self.get_farthest_point(x, y, i, j)
offset = offset * counter
cand_pt = [current_node['pos'][0] + new_i,
current_node['pos'][1] + new_j]
else:
cand_pt = [current_node['pos'][0] + i,
current_node['pos'][1] + j]
if use_theta_star and goal_found:
current_node['open'] = False
cand_pt = self.goal_pt
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
break
if cand_pt == self.goal_pt:
current_node['open'] = False
self.all_nodes[tuple(cand_pt)]['pred'] = \
current_node['pos']
goal_found = True
break
cand_pt = tuple(cand_pt)
no_valid_f = self.update_node_cost(cand_pt, curr_f_thresh,
current_node,
f_cost_list, no_valid_f,
offset, w)
if goal_found:
break
if show_animation:
plt.pause(0.001)
if goal_found:
current_node = self.all_nodes[tuple(self.goal_pt)]
while goal_found:
if current_node['pred'] is None:
break
if use_theta_star or use_jump_point:
x, y = [current_node['pos'][0], current_node['pred'][0]], \
[current_node['pos'][1], current_node['pred'][1]]
if show_animation:
plt.plot(x, y, "b")
else:
if show_animation:
plt.plot(current_node['pred'][0],
current_node['pred'][1], "b*")
current_node = self.all_nodes[tuple(current_node['pred'])]
if goal_found:
break
if use_iterative_deepening and f_cost_list:
curr_f_thresh = min(f_cost_list)
if use_iterative_deepening and not f_cost_list:
curr_f_thresh = np.inf
if use_iterative_deepening and not f_cost_list and no_valid_f:
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
continue
current_node['open'] = False
current_node['in_open_list'] = False
if show_animation:
plt.plot(current_node['pos'][0], current_node['pos'][1], "g*")
del self.open_set[p]
current_node['fcost'], current_node['hcost'] = np.inf, np.inf
depth += 1
if show_animation:
plt.show()
| 1,235 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_variants.py
|
SearchAlgo.update_node_cost
|
(self, cand_pt, curr_f_thresh, current_node,
f_cost_list, no_valid_f, offset, w)
|
return no_valid_f
| 406 | 430 |
def update_node_cost(self, cand_pt, curr_f_thresh, current_node,
f_cost_list, no_valid_f, offset, w):
if not self.obs_grid[tuple(cand_pt)] and \
self.all_nodes[cand_pt]['open']:
g_cost = offset + current_node['gcost']
h_cost = self.all_nodes[cand_pt]['hcost']
if use_dynamic_weighting:
h_cost = h_cost * w
f_cost = g_cost + h_cost
if f_cost < self.all_nodes[cand_pt]['fcost'] and \
f_cost <= curr_f_thresh:
f_cost_list.append(f_cost)
self.all_nodes[cand_pt]['pred'] = \
current_node['pos']
self.all_nodes[cand_pt]['gcost'] = g_cost
self.all_nodes[cand_pt]['fcost'] = f_cost
if not self.all_nodes[cand_pt]['in_open_list']:
self.open_set.append(self.all_nodes[cand_pt])
self.all_nodes[cand_pt]['in_open_list'] = True
if show_animation:
plt.plot(cand_pt[0], cand_pt[1], "r*")
if curr_f_thresh < f_cost < \
self.all_nodes[cand_pt]['fcost']:
no_valid_f = True
return no_valid_f
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_variants.py#L406-L430
| 2 |
[
0,
2,
4,
5,
6,
7,
8,
9,
11,
12,
14,
15,
16,
17,
18,
19,
21,
23,
24
] | 76 |
[
20
] | 4 | false | 89.473684 | 25 | 9 | 96 | 0 |
def update_node_cost(self, cand_pt, curr_f_thresh, current_node,
f_cost_list, no_valid_f, offset, w):
if not self.obs_grid[tuple(cand_pt)] and \
self.all_nodes[cand_pt]['open']:
g_cost = offset + current_node['gcost']
h_cost = self.all_nodes[cand_pt]['hcost']
if use_dynamic_weighting:
h_cost = h_cost * w
f_cost = g_cost + h_cost
if f_cost < self.all_nodes[cand_pt]['fcost'] and \
f_cost <= curr_f_thresh:
f_cost_list.append(f_cost)
self.all_nodes[cand_pt]['pred'] = \
current_node['pos']
self.all_nodes[cand_pt]['gcost'] = g_cost
self.all_nodes[cand_pt]['fcost'] = f_cost
if not self.all_nodes[cand_pt]['in_open_list']:
self.open_set.append(self.all_nodes[cand_pt])
self.all_nodes[cand_pt]['in_open_list'] = True
if show_animation:
plt.plot(cand_pt[0], cand_pt[1], "r*")
if curr_f_thresh < f_cost < \
self.all_nodes[cand_pt]['fcost']:
no_valid_f = True
return no_valid_f
| 1,236 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
hcost
|
(node_coordinate, goal)
|
return hcost
| 29 | 33 |
def hcost(node_coordinate, goal):
dx = abs(node_coordinate[0] - goal[0])
dy = abs(node_coordinate[1] - goal[1])
hcost = dx + dy
return hcost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L29-L33
| 2 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 78.991597 | 5 | 1 | 100 | 0 |
def hcost(node_coordinate, goal):
dx = abs(node_coordinate[0] - goal[0])
dy = abs(node_coordinate[1] - goal[1])
hcost = dx + dy
return hcost
| 1,237 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
gcost
|
(fixed_node, update_node_coordinate)
|
return gcost
| 36 | 41 |
def gcost(fixed_node, update_node_coordinate):
dx = abs(fixed_node.coordinate[0] - update_node_coordinate[0])
dy = abs(fixed_node.coordinate[1] - update_node_coordinate[1])
gc = math.hypot(dx, dy) # gc = move from fixed_node to update_node
gcost = fixed_node.G + gc # gcost = move from start point to update_node
return gcost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L36-L41
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 78.991597 | 6 | 1 | 100 | 0 |
def gcost(fixed_node, update_node_coordinate):
dx = abs(fixed_node.coordinate[0] - update_node_coordinate[0])
dy = abs(fixed_node.coordinate[1] - update_node_coordinate[1])
gc = math.hypot(dx, dy) # gc = move from fixed_node to update_node
gcost = fixed_node.G + gc # gcost = move from start point to update_node
return gcost
| 1,238 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
boundary_and_obstacles
|
(start, goal, top_vertex, bottom_vertex, obs_number)
|
return bound_obs, obstacle
|
:param start: start coordinate
:param goal: goal coordinate
:param top_vertex: top right vertex coordinate of boundary
:param bottom_vertex: bottom left vertex coordinate of boundary
:param obs_number: number of obstacles generated in the map
:return: boundary_obstacle array, obstacle list
|
:param start: start coordinate
:param goal: goal coordinate
:param top_vertex: top right vertex coordinate of boundary
:param bottom_vertex: bottom left vertex coordinate of boundary
:param obs_number: number of obstacles generated in the map
:return: boundary_obstacle array, obstacle list
| 44 | 77 |
def boundary_and_obstacles(start, goal, top_vertex, bottom_vertex, obs_number):
"""
:param start: start coordinate
:param goal: goal coordinate
:param top_vertex: top right vertex coordinate of boundary
:param bottom_vertex: bottom left vertex coordinate of boundary
:param obs_number: number of obstacles generated in the map
:return: boundary_obstacle array, obstacle list
"""
# below can be merged into a rectangle boundary
ay = list(range(bottom_vertex[1], top_vertex[1]))
ax = [bottom_vertex[0]] * len(ay)
cy = ay
cx = [top_vertex[0]] * len(cy)
bx = list(range(bottom_vertex[0] + 1, top_vertex[0]))
by = [bottom_vertex[1]] * len(bx)
dx = [bottom_vertex[0]] + bx + [top_vertex[0]]
dy = [top_vertex[1]] * len(dx)
# generate random obstacles
ob_x = np.random.randint(bottom_vertex[0] + 1,
top_vertex[0], obs_number).tolist()
ob_y = np.random.randint(bottom_vertex[1] + 1,
top_vertex[1], obs_number).tolist()
# x y coordinate in certain order for boundary
x = ax + bx + cx + dx
y = ay + by + cy + dy
obstacle = np.vstack((ob_x, ob_y)).T.tolist()
# remove start and goal coordinate in obstacle list
obstacle = [coor for coor in obstacle if coor != start and coor != goal]
obs_array = np.array(obstacle)
bound = np.vstack((x, y)).T
bound_obs = np.vstack((bound, obs_array))
return bound_obs, obstacle
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L44-L77
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33
] | 100 |
[] | 0 | true | 78.991597 | 34 | 3 | 100 | 6 |
def boundary_and_obstacles(start, goal, top_vertex, bottom_vertex, obs_number):
# below can be merged into a rectangle boundary
ay = list(range(bottom_vertex[1], top_vertex[1]))
ax = [bottom_vertex[0]] * len(ay)
cy = ay
cx = [top_vertex[0]] * len(cy)
bx = list(range(bottom_vertex[0] + 1, top_vertex[0]))
by = [bottom_vertex[1]] * len(bx)
dx = [bottom_vertex[0]] + bx + [top_vertex[0]]
dy = [top_vertex[1]] * len(dx)
# generate random obstacles
ob_x = np.random.randint(bottom_vertex[0] + 1,
top_vertex[0], obs_number).tolist()
ob_y = np.random.randint(bottom_vertex[1] + 1,
top_vertex[1], obs_number).tolist()
# x y coordinate in certain order for boundary
x = ax + bx + cx + dx
y = ay + by + cy + dy
obstacle = np.vstack((ob_x, ob_y)).T.tolist()
# remove start and goal coordinate in obstacle list
obstacle = [coor for coor in obstacle if coor != start and coor != goal]
obs_array = np.array(obstacle)
bound = np.vstack((x, y)).T
bound_obs = np.vstack((bound, obs_array))
return bound_obs, obstacle
| 1,239 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
find_neighbor
|
(node, ob, closed)
|
return neighbor
| 80 | 117 |
def find_neighbor(node, ob, closed):
# generate neighbors in certain condition
ob_list = ob.tolist()
neighbor: list = []
for x in range(node.coordinate[0] - 1, node.coordinate[0] + 2):
for y in range(node.coordinate[1] - 1, node.coordinate[1] + 2):
if [x, y] not in ob_list:
# find all possible neighbor nodes
neighbor.append([x, y])
# remove node violate the motion rule
# 1. remove node.coordinate itself
neighbor.remove(node.coordinate)
# 2. remove neighbor nodes who cross through two diagonal
# positioned obstacles since there is no enough space for
# robot to go through two diagonal positioned obstacles
# top bottom left right neighbors of node
top_nei = [node.coordinate[0], node.coordinate[1] + 1]
bottom_nei = [node.coordinate[0], node.coordinate[1] - 1]
left_nei = [node.coordinate[0] - 1, node.coordinate[1]]
right_nei = [node.coordinate[0] + 1, node.coordinate[1]]
# neighbors in four vertex
lt_nei = [node.coordinate[0] - 1, node.coordinate[1] + 1]
rt_nei = [node.coordinate[0] + 1, node.coordinate[1] + 1]
lb_nei = [node.coordinate[0] - 1, node.coordinate[1] - 1]
rb_nei = [node.coordinate[0] + 1, node.coordinate[1] - 1]
# remove the unnecessary neighbors
if top_nei and left_nei in ob_list and lt_nei in neighbor:
neighbor.remove(lt_nei)
if top_nei and right_nei in ob_list and rt_nei in neighbor:
neighbor.remove(rt_nei)
if bottom_nei and left_nei in ob_list and lb_nei in neighbor:
neighbor.remove(lb_nei)
if bottom_nei and right_nei in ob_list and rb_nei in neighbor:
neighbor.remove(rb_nei)
neighbor = [x for x in neighbor if x not in closed]
return neighbor
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L80-L117
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37
] | 100 |
[] | 0 | true | 78.991597 | 38 | 17 | 100 | 0 |
def find_neighbor(node, ob, closed):
# generate neighbors in certain condition
ob_list = ob.tolist()
neighbor: list = []
for x in range(node.coordinate[0] - 1, node.coordinate[0] + 2):
for y in range(node.coordinate[1] - 1, node.coordinate[1] + 2):
if [x, y] not in ob_list:
# find all possible neighbor nodes
neighbor.append([x, y])
# remove node violate the motion rule
# 1. remove node.coordinate itself
neighbor.remove(node.coordinate)
# 2. remove neighbor nodes who cross through two diagonal
# positioned obstacles since there is no enough space for
# robot to go through two diagonal positioned obstacles
# top bottom left right neighbors of node
top_nei = [node.coordinate[0], node.coordinate[1] + 1]
bottom_nei = [node.coordinate[0], node.coordinate[1] - 1]
left_nei = [node.coordinate[0] - 1, node.coordinate[1]]
right_nei = [node.coordinate[0] + 1, node.coordinate[1]]
# neighbors in four vertex
lt_nei = [node.coordinate[0] - 1, node.coordinate[1] + 1]
rt_nei = [node.coordinate[0] + 1, node.coordinate[1] + 1]
lb_nei = [node.coordinate[0] - 1, node.coordinate[1] - 1]
rb_nei = [node.coordinate[0] + 1, node.coordinate[1] - 1]
# remove the unnecessary neighbors
if top_nei and left_nei in ob_list and lt_nei in neighbor:
neighbor.remove(lt_nei)
if top_nei and right_nei in ob_list and rt_nei in neighbor:
neighbor.remove(rt_nei)
if bottom_nei and left_nei in ob_list and lb_nei in neighbor:
neighbor.remove(lb_nei)
if bottom_nei and right_nei in ob_list and rb_nei in neighbor:
neighbor.remove(rb_nei)
neighbor = [x for x in neighbor if x not in closed]
return neighbor
| 1,240 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
find_node_index
|
(coordinate, node_list)
|
return ind
| 120 | 128 |
def find_node_index(coordinate, node_list):
# find node index in the node list via its coordinate
ind = 0
for node in node_list:
if node.coordinate == coordinate:
target_node = node
ind = node_list.index(target_node)
break
return ind
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L120-L128
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 78.991597 | 9 | 3 | 100 | 0 |
def find_node_index(coordinate, node_list):
# find node index in the node list via its coordinate
ind = 0
for node in node_list:
if node.coordinate == coordinate:
target_node = node
ind = node_list.index(target_node)
break
return ind
| 1,241 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
find_path
|
(open_list, closed_list, goal, obstacle)
|
return open_list, closed_list
| 131 | 158 |
def find_path(open_list, closed_list, goal, obstacle):
# searching for the path, update open and closed list
# obstacle = obstacle and boundary
flag = len(open_list)
for i in range(flag):
node = open_list[0]
open_coordinate_list = [node.coordinate for node in open_list]
closed_coordinate_list = [node.coordinate for node in closed_list]
temp = find_neighbor(node, obstacle, closed_coordinate_list)
for element in temp:
if element in closed_list:
continue
elif element in open_coordinate_list:
# if node in open list, update g value
ind = open_coordinate_list.index(element)
new_g = gcost(node, element)
if new_g <= open_list[ind].G:
open_list[ind].G = new_g
open_list[ind].reset_f()
open_list[ind].parent = node
else: # new coordinate, create corresponding node
ele_node = Node(coordinate=element, parent=node,
G=gcost(node, element), H=hcost(element, goal))
open_list.append(ele_node)
open_list.remove(node)
closed_list.append(node)
open_list.sort(key=lambda x: x.F)
return open_list, closed_list
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L131-L158
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13,
14,
15,
16,
17,
18,
19,
21,
23,
24,
25,
26,
27
] | 89.285714 |
[
11
] | 3.571429 | false | 78.991597 | 28 | 8 | 96.428571 | 0 |
def find_path(open_list, closed_list, goal, obstacle):
# searching for the path, update open and closed list
# obstacle = obstacle and boundary
flag = len(open_list)
for i in range(flag):
node = open_list[0]
open_coordinate_list = [node.coordinate for node in open_list]
closed_coordinate_list = [node.coordinate for node in closed_list]
temp = find_neighbor(node, obstacle, closed_coordinate_list)
for element in temp:
if element in closed_list:
continue
elif element in open_coordinate_list:
# if node in open list, update g value
ind = open_coordinate_list.index(element)
new_g = gcost(node, element)
if new_g <= open_list[ind].G:
open_list[ind].G = new_g
open_list[ind].reset_f()
open_list[ind].parent = node
else: # new coordinate, create corresponding node
ele_node = Node(coordinate=element, parent=node,
G=gcost(node, element), H=hcost(element, goal))
open_list.append(ele_node)
open_list.remove(node)
closed_list.append(node)
open_list.sort(key=lambda x: x.F)
return open_list, closed_list
| 1,242 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
node_to_coordinate
|
(node_list)
|
return coordinate_list
| 161 | 164 |
def node_to_coordinate(node_list):
# convert node list into coordinate list and array
coordinate_list = [node.coordinate for node in node_list]
return coordinate_list
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L161-L164
| 2 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 78.991597 | 4 | 2 | 100 | 0 |
def node_to_coordinate(node_list):
# convert node list into coordinate list and array
coordinate_list = [node.coordinate for node in node_list]
return coordinate_list
| 1,243 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
check_node_coincide
|
(close_ls1, closed_ls2)
|
return intersect_ls
|
:param close_ls1: node closed list for searching from start
:param closed_ls2: node closed list for searching from end
:return: intersect node list for above two
|
:param close_ls1: node closed list for searching from start
:param closed_ls2: node closed list for searching from end
:return: intersect node list for above two
| 167 | 177 |
def check_node_coincide(close_ls1, closed_ls2):
"""
:param close_ls1: node closed list for searching from start
:param closed_ls2: node closed list for searching from end
:return: intersect node list for above two
"""
# check if node in close_ls1 intersect with node in closed_ls2
cl1 = node_to_coordinate(close_ls1)
cl2 = node_to_coordinate(closed_ls2)
intersect_ls = [node for node in cl1 if node in cl2]
return intersect_ls
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L167-L177
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
] | 100 |
[] | 0 | true | 78.991597 | 11 | 2 | 100 | 3 |
def check_node_coincide(close_ls1, closed_ls2):
# check if node in close_ls1 intersect with node in closed_ls2
cl1 = node_to_coordinate(close_ls1)
cl2 = node_to_coordinate(closed_ls2)
intersect_ls = [node for node in cl1 if node in cl2]
return intersect_ls
| 1,244 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
find_surrounding
|
(coordinate, obstacle)
|
return boundary
| 180 | 187 |
def find_surrounding(coordinate, obstacle):
# find obstacles around node, help to draw the borderline
boundary: list = []
for x in range(coordinate[0] - 1, coordinate[0] + 2):
for y in range(coordinate[1] - 1, coordinate[1] + 2):
if [x, y] in obstacle:
boundary.append([x, y])
return boundary
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L180-L187
| 2 |
[
0,
1
] | 25 |
[
2,
3,
4,
5,
6,
7
] | 75 | false | 78.991597 | 8 | 4 | 25 | 0 |
def find_surrounding(coordinate, obstacle):
# find obstacles around node, help to draw the borderline
boundary: list = []
for x in range(coordinate[0] - 1, coordinate[0] + 2):
for y in range(coordinate[1] - 1, coordinate[1] + 2):
if [x, y] in obstacle:
boundary.append([x, y])
return boundary
| 1,245 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
get_border_line
|
(node_closed_ls, obstacle)
|
return border_ary
| 190 | 198 |
def get_border_line(node_closed_ls, obstacle):
# if no path, find border line which confine goal or robot
border: list = []
coordinate_closed_ls = node_to_coordinate(node_closed_ls)
for coordinate in coordinate_closed_ls:
temp = find_surrounding(coordinate, obstacle)
border = border + temp
border_ary = np.array(border)
return border_ary
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L190-L198
| 2 |
[
0,
1
] | 22.222222 |
[
2,
3,
4,
5,
6,
7,
8
] | 77.777778 | false | 78.991597 | 9 | 2 | 22.222222 | 0 |
def get_border_line(node_closed_ls, obstacle):
# if no path, find border line which confine goal or robot
border: list = []
coordinate_closed_ls = node_to_coordinate(node_closed_ls)
for coordinate in coordinate_closed_ls:
temp = find_surrounding(coordinate, obstacle)
border = border + temp
border_ary = np.array(border)
return border_ary
| 1,246 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
get_path
|
(org_list, goal_list, coordinate)
|
return path
| 201 | 220 |
def get_path(org_list, goal_list, coordinate):
# get path from start to end
path_org: list = []
path_goal: list = []
ind = find_node_index(coordinate, org_list)
node = org_list[ind]
while node != org_list[0]:
path_org.append(node.coordinate)
node = node.parent
path_org.append(org_list[0].coordinate)
ind = find_node_index(coordinate, goal_list)
node = goal_list[ind]
while node != goal_list[0]:
path_goal.append(node.coordinate)
node = node.parent
path_goal.append(goal_list[0].coordinate)
path_org.reverse()
path = path_org + path_goal
path = np.array(path)
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L201-L220
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 78.991597 | 20 | 3 | 100 | 0 |
def get_path(org_list, goal_list, coordinate):
# get path from start to end
path_org: list = []
path_goal: list = []
ind = find_node_index(coordinate, org_list)
node = org_list[ind]
while node != org_list[0]:
path_org.append(node.coordinate)
node = node.parent
path_org.append(org_list[0].coordinate)
ind = find_node_index(coordinate, goal_list)
node = goal_list[ind]
while node != goal_list[0]:
path_goal.append(node.coordinate)
node = node.parent
path_goal.append(goal_list[0].coordinate)
path_org.reverse()
path = path_org + path_goal
path = np.array(path)
return path
| 1,247 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
random_coordinate
|
(bottom_vertex, top_vertex)
|
return coordinate
| 223 | 227 |
def random_coordinate(bottom_vertex, top_vertex):
# generate random coordinates inside maze
coordinate = [np.random.randint(bottom_vertex[0] + 1, top_vertex[0]),
np.random.randint(bottom_vertex[1] + 1, top_vertex[1])]
return coordinate
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L223-L227
| 2 |
[
0,
1,
2,
4
] | 80 |
[] | 0 | false | 78.991597 | 5 | 1 | 100 | 0 |
def random_coordinate(bottom_vertex, top_vertex):
# generate random coordinates inside maze
coordinate = [np.random.randint(bottom_vertex[0] + 1, top_vertex[0]),
np.random.randint(bottom_vertex[1] + 1, top_vertex[1])]
return coordinate
| 1,248 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
draw
|
(close_origin, close_goal, start, end, bound)
| 230 | 248 |
def draw(close_origin, close_goal, start, end, bound):
# plot the map
if not close_goal.tolist(): # ensure the close_goal not empty
# in case of the obstacle number is really large (>4500), the
# origin is very likely blocked at the first search, and then
# the program is over and the searching from goal to origin
# will not start, which remain the closed_list for goal == []
# in order to plot the map, add the end coordinate to array
close_goal = np.array([end])
plt.cla()
plt.gcf().set_size_inches(11, 9, forward=True)
plt.axis('equal')
plt.plot(close_origin[:, 0], close_origin[:, 1], 'oy')
plt.plot(close_goal[:, 0], close_goal[:, 1], 'og')
plt.plot(bound[:, 0], bound[:, 1], 'sk')
plt.plot(end[0], end[1], '*b', label='Goal')
plt.plot(start[0], start[1], '^b', label='Origin')
plt.legend()
plt.pause(0.0001)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L230-L248
| 2 |
[
0,
1
] | 10.526316 |
[
2,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
] | 63.157895 | false | 78.991597 | 19 | 2 | 36.842105 | 0 |
def draw(close_origin, close_goal, start, end, bound):
# plot the map
if not close_goal.tolist(): # ensure the close_goal not empty
# in case of the obstacle number is really large (>4500), the
# origin is very likely blocked at the first search, and then
# the program is over and the searching from goal to origin
# will not start, which remain the closed_list for goal == []
# in order to plot the map, add the end coordinate to array
close_goal = np.array([end])
plt.cla()
plt.gcf().set_size_inches(11, 9, forward=True)
plt.axis('equal')
plt.plot(close_origin[:, 0], close_origin[:, 1], 'oy')
plt.plot(close_goal[:, 0], close_goal[:, 1], 'og')
plt.plot(bound[:, 0], bound[:, 1], 'sk')
plt.plot(end[0], end[1], '*b', label='Goal')
plt.plot(start[0], start[1], '^b', label='Origin')
plt.legend()
plt.pause(0.0001)
| 1,249 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
draw_control
|
(org_closed, goal_closed, flag, start, end, bound, obstacle)
|
return stop_loop, path
|
control the plot process, evaluate if the searching finished
flag == 0 : draw the searching process and plot path
flag == 1 or 2 : start or end is blocked, draw the border line
|
control the plot process, evaluate if the searching finished
flag == 0 : draw the searching process and plot path
flag == 1 or 2 : start or end is blocked, draw the border line
| 251 | 298 |
def draw_control(org_closed, goal_closed, flag, start, end, bound, obstacle):
"""
control the plot process, evaluate if the searching finished
flag == 0 : draw the searching process and plot path
flag == 1 or 2 : start or end is blocked, draw the border line
"""
stop_loop = 0 # stop sign for the searching
org_closed_ls = node_to_coordinate(org_closed)
org_array = np.array(org_closed_ls)
goal_closed_ls = node_to_coordinate(goal_closed)
goal_array = np.array(goal_closed_ls)
path = None
if show_animation: # draw the searching process
draw(org_array, goal_array, start, end, bound)
if flag == 0:
node_intersect = check_node_coincide(org_closed, goal_closed)
if node_intersect: # a path is find
path = get_path(org_closed, goal_closed, node_intersect[0])
stop_loop = 1
print('Path found!')
if show_animation: # draw the path
plt.plot(path[:, 0], path[:, 1], '-r')
plt.title('Robot Arrived', size=20, loc='center')
plt.pause(0.01)
plt.show()
elif flag == 1: # start point blocked first
stop_loop = 1
print('There is no path to the goal! Start point is blocked!')
elif flag == 2: # end point blocked first
stop_loop = 1
print('There is no path to the goal! End point is blocked!')
if show_animation: # blocked case, draw the border line
info = 'There is no path to the goal!' \
' Robot&Goal are split by border' \
' shown in red \'x\'!'
if flag == 1:
border = get_border_line(org_closed, obstacle)
plt.plot(border[:, 0], border[:, 1], 'xr')
plt.title(info, size=14, loc='center')
plt.pause(0.01)
plt.show()
elif flag == 2:
border = get_border_line(goal_closed, obstacle)
plt.plot(border[:, 0], border[:, 1], 'xr')
plt.title(info, size=14, loc='center')
plt.pause(0.01)
plt.show()
return stop_loop, path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L251-L298
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
14,
15,
16,
17,
18,
19,
20,
25,
28,
29,
30,
31,
47
] | 54.166667 |
[
13,
21,
22,
23,
24,
26,
27,
32,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46
] | 41.666667 | false | 78.991597 | 48 | 10 | 58.333333 | 3 |
def draw_control(org_closed, goal_closed, flag, start, end, bound, obstacle):
stop_loop = 0 # stop sign for the searching
org_closed_ls = node_to_coordinate(org_closed)
org_array = np.array(org_closed_ls)
goal_closed_ls = node_to_coordinate(goal_closed)
goal_array = np.array(goal_closed_ls)
path = None
if show_animation: # draw the searching process
draw(org_array, goal_array, start, end, bound)
if flag == 0:
node_intersect = check_node_coincide(org_closed, goal_closed)
if node_intersect: # a path is find
path = get_path(org_closed, goal_closed, node_intersect[0])
stop_loop = 1
print('Path found!')
if show_animation: # draw the path
plt.plot(path[:, 0], path[:, 1], '-r')
plt.title('Robot Arrived', size=20, loc='center')
plt.pause(0.01)
plt.show()
elif flag == 1: # start point blocked first
stop_loop = 1
print('There is no path to the goal! Start point is blocked!')
elif flag == 2: # end point blocked first
stop_loop = 1
print('There is no path to the goal! End point is blocked!')
if show_animation: # blocked case, draw the border line
info = 'There is no path to the goal!' \
' Robot&Goal are split by border' \
' shown in red \'x\'!'
if flag == 1:
border = get_border_line(org_closed, obstacle)
plt.plot(border[:, 0], border[:, 1], 'xr')
plt.title(info, size=14, loc='center')
plt.pause(0.01)
plt.show()
elif flag == 2:
border = get_border_line(goal_closed, obstacle)
plt.plot(border[:, 0], border[:, 1], 'xr')
plt.title(info, size=14, loc='center')
plt.pause(0.01)
plt.show()
return stop_loop, path
| 1,250 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
searching_control
|
(start, end, bound, obstacle)
|
return path
|
manage the searching process, start searching from two side
|
manage the searching process, start searching from two side
| 301 | 345 |
def searching_control(start, end, bound, obstacle):
"""manage the searching process, start searching from two side"""
# initial origin node and end node
origin = Node(coordinate=start, H=hcost(start, end))
goal = Node(coordinate=end, H=hcost(end, start))
# list for searching from origin to goal
origin_open: list = [origin]
origin_close: list = []
# list for searching from goal to origin
goal_open = [goal]
goal_close: list = []
# initial target
target_goal = end
# flag = 0 (not blocked) 1 (start point blocked) 2 (end point blocked)
flag = 0 # init flag
path = None
while True:
# searching from start to end
origin_open, origin_close = \
find_path(origin_open, origin_close, target_goal, bound)
if not origin_open: # no path condition
flag = 1 # origin node is blocked
draw_control(origin_close, goal_close, flag, start, end, bound,
obstacle)
break
# update target for searching from end to start
target_origin = min(origin_open, key=lambda x: x.F).coordinate
# searching from end to start
goal_open, goal_close = \
find_path(goal_open, goal_close, target_origin, bound)
if not goal_open: # no path condition
flag = 2 # goal is blocked
draw_control(origin_close, goal_close, flag, start, end, bound,
obstacle)
break
# update target for searching from start to end
target_goal = min(goal_open, key=lambda x: x.F).coordinate
# continue searching, draw the process
stop_sign, path = draw_control(origin_close, goal_close, flag, start,
end, bound, obstacle)
if stop_sign:
break
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L301-L345
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44
] | 91.111111 |
[
21,
22,
24
] | 6.666667 | false | 78.991597 | 45 | 5 | 93.333333 | 1 |
def searching_control(start, end, bound, obstacle):
# initial origin node and end node
origin = Node(coordinate=start, H=hcost(start, end))
goal = Node(coordinate=end, H=hcost(end, start))
# list for searching from origin to goal
origin_open: list = [origin]
origin_close: list = []
# list for searching from goal to origin
goal_open = [goal]
goal_close: list = []
# initial target
target_goal = end
# flag = 0 (not blocked) 1 (start point blocked) 2 (end point blocked)
flag = 0 # init flag
path = None
while True:
# searching from start to end
origin_open, origin_close = \
find_path(origin_open, origin_close, target_goal, bound)
if not origin_open: # no path condition
flag = 1 # origin node is blocked
draw_control(origin_close, goal_close, flag, start, end, bound,
obstacle)
break
# update target for searching from end to start
target_origin = min(origin_open, key=lambda x: x.F).coordinate
# searching from end to start
goal_open, goal_close = \
find_path(goal_open, goal_close, target_origin, bound)
if not goal_open: # no path condition
flag = 2 # goal is blocked
draw_control(origin_close, goal_close, flag, start, end, bound,
obstacle)
break
# update target for searching from start to end
target_goal = min(goal_open, key=lambda x: x.F).coordinate
# continue searching, draw the process
stop_sign, path = draw_control(origin_close, goal_close, flag, start,
end, bound, obstacle)
if stop_sign:
break
return path
| 1,251 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
main
|
(obstacle_number=1500)
| 348 | 365 |
def main(obstacle_number=1500):
print(__file__ + ' start!')
top_vertex = [60, 60] # top right vertex of boundary
bottom_vertex = [0, 0] # bottom left vertex of boundary
# generate start and goal point randomly
start = random_coordinate(bottom_vertex, top_vertex)
end = random_coordinate(bottom_vertex, top_vertex)
# generate boundary and obstacles
bound, obstacle = boundary_and_obstacles(start, end, top_vertex,
bottom_vertex,
obstacle_number)
path = searching_control(start, end, bound, obstacle)
if not show_animation:
print(path)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L348-L365
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
14,
15,
16,
17
] | 88.888889 |
[] | 0 | false | 78.991597 | 18 | 2 | 100 | 0 |
def main(obstacle_number=1500):
print(__file__ + ' start!')
top_vertex = [60, 60] # top right vertex of boundary
bottom_vertex = [0, 0] # bottom left vertex of boundary
# generate start and goal point randomly
start = random_coordinate(bottom_vertex, top_vertex)
end = random_coordinate(bottom_vertex, top_vertex)
# generate boundary and obstacles
bound, obstacle = boundary_and_obstacles(start, end, top_vertex,
bottom_vertex,
obstacle_number)
path = searching_control(start, end, bound, obstacle)
if not show_animation:
print(path)
| 1,252 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
Node.__init__
|
(self, G=0, H=0, coordinate=None, parent=None)
| 18 | 23 |
def __init__(self, G=0, H=0, coordinate=None, parent=None):
self.G = G
self.H = H
self.F = G + H
self.parent = parent
self.coordinate = coordinate
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L18-L23
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 78.991597 | 6 | 1 | 100 | 0 |
def __init__(self, G=0, H=0, coordinate=None, parent=None):
self.G = G
self.H = H
self.F = G + H
self.parent = parent
self.coordinate = coordinate
| 1,253 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star_searching_from_two_side.py
|
Node.reset_f
|
(self)
| 25 | 26 |
def reset_f(self):
self.F = self.G + self.H
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star_searching_from_two_side.py#L25-L26
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 78.991597 | 2 | 1 | 100 | 0 |
def reset_f(self):
self.F = self.G + self.H
| 1,254 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
main
|
()
| 233 | 278 |
def main():
print(__file__ + " start!!")
# start and goal position
sx = 10.0 # [m]
sy = 10.0 # [m]
gx = 50.0 # [m]
gy = 50.0 # [m]
grid_size = 2.0 # [m]
robot_radius = 1.0 # [m]
# set obstacle positions
ox, oy = [], []
for i in range(-10, 60):
ox.append(i)
oy.append(-10.0)
for i in range(-10, 60):
ox.append(60.0)
oy.append(i)
for i in range(-10, 61):
ox.append(i)
oy.append(60.0)
for i in range(-10, 61):
ox.append(-10.0)
oy.append(i)
for i in range(-10, 40):
ox.append(20.0)
oy.append(i)
for i in range(0, 40):
ox.append(40.0)
oy.append(60.0 - i)
if show_animation: # pragma: no cover
plt.plot(ox, oy, ".k")
plt.plot(sx, sy, "og")
plt.plot(gx, gy, "xb")
plt.grid(True)
plt.axis("equal")
a_star = AStarPlanner(ox, oy, grid_size, robot_radius)
rx, ry = a_star.planning(sx, sy, gx, gy)
if show_animation: # pragma: no cover
plt.plot(rx, ry, "-r")
plt.pause(0.001)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L233-L278
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
38,
39,
40,
41
] | 100 |
[] | 0 | true | 95.172414 | 46 | 9 | 100 | 0 |
def main():
print(__file__ + " start!!")
# start and goal position
sx = 10.0 # [m]
sy = 10.0 # [m]
gx = 50.0 # [m]
gy = 50.0 # [m]
grid_size = 2.0 # [m]
robot_radius = 1.0 # [m]
# set obstacle positions
ox, oy = [], []
for i in range(-10, 60):
ox.append(i)
oy.append(-10.0)
for i in range(-10, 60):
ox.append(60.0)
oy.append(i)
for i in range(-10, 61):
ox.append(i)
oy.append(60.0)
for i in range(-10, 61):
ox.append(-10.0)
oy.append(i)
for i in range(-10, 40):
ox.append(20.0)
oy.append(i)
for i in range(0, 40):
ox.append(40.0)
oy.append(60.0 - i)
if show_animation: # pragma: no cover
plt.plot(ox, oy, ".k")
plt.plot(sx, sy, "og")
plt.plot(gx, gy, "xb")
plt.grid(True)
plt.axis("equal")
a_star = AStarPlanner(ox, oy, grid_size, robot_radius)
rx, ry = a_star.planning(sx, sy, gx, gy)
if show_animation: # pragma: no cover
plt.plot(rx, ry, "-r")
plt.pause(0.001)
plt.show()
| 1,255 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.__init__
|
(self, ox, oy, resolution, rr)
|
Initialize grid map for a star planning
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
|
Initialize grid map for a star planning
| 21 | 38 |
def __init__(self, ox, oy, resolution, rr):
"""
Initialize grid map for a star planning
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
"""
self.resolution = resolution
self.rr = rr
self.min_x, self.min_y = 0, 0
self.max_x, self.max_y = 0, 0
self.obstacle_map = None
self.x_width, self.y_width = 0, 0
self.motion = self.get_motion_model()
self.calc_obstacle_map(ox, oy)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L21-L38
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 100 |
[] | 0 | true | 95.172414 | 18 | 1 | 100 | 6 |
def __init__(self, ox, oy, resolution, rr):
self.resolution = resolution
self.rr = rr
self.min_x, self.min_y = 0, 0
self.max_x, self.max_y = 0, 0
self.obstacle_map = None
self.x_width, self.y_width = 0, 0
self.motion = self.get_motion_model()
self.calc_obstacle_map(ox, oy)
| 1,256 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.planning
|
(self, sx, sy, gx, gy)
|
return rx, ry
|
A star path search
input:
s_x: start x position [m]
s_y: start y position [m]
gx: goal x position [m]
gy: goal y position [m]
output:
rx: x position list of the final path
ry: y position list of the final path
|
A star path search
| 51 | 132 |
def planning(self, sx, sy, gx, gy):
"""
A star path search
input:
s_x: start x position [m]
s_y: start y position [m]
gx: goal x position [m]
gy: goal y position [m]
output:
rx: x position list of the final path
ry: y position list of the final path
"""
start_node = self.Node(self.calc_xy_index(sx, self.min_x),
self.calc_xy_index(sy, self.min_y), 0.0, -1)
goal_node = self.Node(self.calc_xy_index(gx, self.min_x),
self.calc_xy_index(gy, self.min_y), 0.0, -1)
open_set, closed_set = dict(), dict()
open_set[self.calc_grid_index(start_node)] = start_node
while True:
if len(open_set) == 0:
print("Open set is empty..")
break
c_id = min(
open_set,
key=lambda o: open_set[o].cost + self.calc_heuristic(goal_node,
open_set[
o]))
current = open_set[c_id]
# show graph
if show_animation: # pragma: no cover
plt.plot(self.calc_grid_position(current.x, self.min_x),
self.calc_grid_position(current.y, self.min_y), "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(
0) if event.key == 'escape' else None])
if len(closed_set.keys()) % 10 == 0:
plt.pause(0.001)
if current.x == goal_node.x and current.y == goal_node.y:
print("Find goal")
goal_node.parent_index = current.parent_index
goal_node.cost = current.cost
break
# Remove the item from the open set
del open_set[c_id]
# Add it to the closed set
closed_set[c_id] = current
# expand_grid search grid based on motion model
for i, _ in enumerate(self.motion):
node = self.Node(current.x + self.motion[i][0],
current.y + self.motion[i][1],
current.cost + self.motion[i][2], c_id)
n_id = self.calc_grid_index(node)
# If the node is not safe, do nothing
if not self.verify_node(node):
continue
if n_id in closed_set:
continue
if n_id not in open_set:
open_set[n_id] = node # discovered a new node
else:
if open_set[n_id].cost > node.cost:
# This path is the best until now. record it
open_set[n_id] = node
rx, ry = self.calc_final_path(goal_node, closed_set)
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L51-L132
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81
] | 103.896104 |
[
25,
26
] | 2.597403 | false | 95.172414 | 82 | 12 | 97.402597 | 11 |
def planning(self, sx, sy, gx, gy):
start_node = self.Node(self.calc_xy_index(sx, self.min_x),
self.calc_xy_index(sy, self.min_y), 0.0, -1)
goal_node = self.Node(self.calc_xy_index(gx, self.min_x),
self.calc_xy_index(gy, self.min_y), 0.0, -1)
open_set, closed_set = dict(), dict()
open_set[self.calc_grid_index(start_node)] = start_node
while True:
if len(open_set) == 0:
print("Open set is empty..")
break
c_id = min(
open_set,
key=lambda o: open_set[o].cost + self.calc_heuristic(goal_node,
open_set[
o]))
current = open_set[c_id]
# show graph
if show_animation: # pragma: no cover
plt.plot(self.calc_grid_position(current.x, self.min_x),
self.calc_grid_position(current.y, self.min_y), "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(
0) if event.key == 'escape' else None])
if len(closed_set.keys()) % 10 == 0:
plt.pause(0.001)
if current.x == goal_node.x and current.y == goal_node.y:
print("Find goal")
goal_node.parent_index = current.parent_index
goal_node.cost = current.cost
break
# Remove the item from the open set
del open_set[c_id]
# Add it to the closed set
closed_set[c_id] = current
# expand_grid search grid based on motion model
for i, _ in enumerate(self.motion):
node = self.Node(current.x + self.motion[i][0],
current.y + self.motion[i][1],
current.cost + self.motion[i][2], c_id)
n_id = self.calc_grid_index(node)
# If the node is not safe, do nothing
if not self.verify_node(node):
continue
if n_id in closed_set:
continue
if n_id not in open_set:
open_set[n_id] = node # discovered a new node
else:
if open_set[n_id].cost > node.cost:
# This path is the best until now. record it
open_set[n_id] = node
rx, ry = self.calc_final_path(goal_node, closed_set)
return rx, ry
| 1,257 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_final_path
|
(self, goal_node, closed_set)
|
return rx, ry
| 134 | 145 |
def calc_final_path(self, goal_node, closed_set):
# generate final course
rx, ry = [self.calc_grid_position(goal_node.x, self.min_x)], [
self.calc_grid_position(goal_node.y, self.min_y)]
parent_index = goal_node.parent_index
while parent_index != -1:
n = closed_set[parent_index]
rx.append(self.calc_grid_position(n.x, self.min_x))
ry.append(self.calc_grid_position(n.y, self.min_y))
parent_index = n.parent_index
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L134-L145
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9,
10,
11
] | 91.666667 |
[] | 0 | false | 95.172414 | 12 | 2 | 100 | 0 |
def calc_final_path(self, goal_node, closed_set):
# generate final course
rx, ry = [self.calc_grid_position(goal_node.x, self.min_x)], [
self.calc_grid_position(goal_node.y, self.min_y)]
parent_index = goal_node.parent_index
while parent_index != -1:
n = closed_set[parent_index]
rx.append(self.calc_grid_position(n.x, self.min_x))
ry.append(self.calc_grid_position(n.y, self.min_y))
parent_index = n.parent_index
return rx, ry
| 1,258 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_heuristic
|
(n1, n2)
|
return d
| 148 | 151 |
def calc_heuristic(n1, n2):
w = 1.0 # weight of heuristic
d = w * math.hypot(n1.x - n2.x, n1.y - n2.y)
return d
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L148-L151
| 2 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 95.172414 | 4 | 1 | 100 | 0 |
def calc_heuristic(n1, n2):
w = 1.0 # weight of heuristic
d = w * math.hypot(n1.x - n2.x, n1.y - n2.y)
return d
| 1,259 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_grid_position
|
(self, index, min_position)
|
return pos
|
calc grid position
:param index:
:param min_position:
:return:
|
calc grid position
| 153 | 162 |
def calc_grid_position(self, index, min_position):
"""
calc grid position
:param index:
:param min_position:
:return:
"""
pos = index * self.resolution + min_position
return pos
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L153-L162
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 95.172414 | 10 | 1 | 100 | 5 |
def calc_grid_position(self, index, min_position):
pos = index * self.resolution + min_position
return pos
| 1,260 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_xy_index
|
(self, position, min_pos)
|
return round((position - min_pos) / self.resolution)
| 164 | 165 |
def calc_xy_index(self, position, min_pos):
return round((position - min_pos) / self.resolution)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L164-L165
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 95.172414 | 2 | 1 | 100 | 0 |
def calc_xy_index(self, position, min_pos):
return round((position - min_pos) / self.resolution)
| 1,261 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_grid_index
|
(self, node)
|
return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
| 167 | 168 |
def calc_grid_index(self, node):
return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L167-L168
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 95.172414 | 2 | 1 | 100 | 0 |
def calc_grid_index(self, node):
return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
| 1,262 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.verify_node
|
(self, node)
|
return True
| 170 | 187 |
def verify_node(self, node):
px = self.calc_grid_position(node.x, self.min_x)
py = self.calc_grid_position(node.y, self.min_y)
if px < self.min_x:
return False
elif py < self.min_y:
return False
elif px >= self.max_x:
return False
elif py >= self.max_y:
return False
# collision check
if self.obstacle_map[node.x][node.y]:
return False
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L170-L187
| 2 |
[
0,
1,
2,
3,
4,
6,
8,
10,
11,
12,
13,
14,
15,
16,
17
] | 83.333333 |
[
5,
7,
9
] | 16.666667 | false | 95.172414 | 18 | 6 | 83.333333 | 0 |
def verify_node(self, node):
px = self.calc_grid_position(node.x, self.min_x)
py = self.calc_grid_position(node.y, self.min_y)
if px < self.min_x:
return False
elif py < self.min_y:
return False
elif px >= self.max_x:
return False
elif py >= self.max_y:
return False
# collision check
if self.obstacle_map[node.x][node.y]:
return False
return True
| 1,263 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.calc_obstacle_map
|
(self, ox, oy)
| 189 | 216 |
def calc_obstacle_map(self, ox, oy):
self.min_x = round(min(ox))
self.min_y = round(min(oy))
self.max_x = round(max(ox))
self.max_y = round(max(oy))
print("min_x:", self.min_x)
print("min_y:", self.min_y)
print("max_x:", self.max_x)
print("max_y:", self.max_y)
self.x_width = round((self.max_x - self.min_x) / self.resolution)
self.y_width = round((self.max_y - self.min_y) / self.resolution)
print("x_width:", self.x_width)
print("y_width:", self.y_width)
# obstacle map generation
self.obstacle_map = [[False for _ in range(self.y_width)]
for _ in range(self.x_width)]
for ix in range(self.x_width):
x = self.calc_grid_position(ix, self.min_x)
for iy in range(self.y_width):
y = self.calc_grid_position(iy, self.min_y)
for iox, ioy in zip(ox, oy):
d = math.hypot(iox - x, ioy - y)
if d <= self.rr:
self.obstacle_map[ix][iy] = True
break
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L189-L216
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
19,
20,
21,
22,
23,
24,
25,
26,
27
] | 96.428571 |
[] | 0 | false | 95.172414 | 28 | 7 | 100 | 0 |
def calc_obstacle_map(self, ox, oy):
self.min_x = round(min(ox))
self.min_y = round(min(oy))
self.max_x = round(max(ox))
self.max_y = round(max(oy))
print("min_x:", self.min_x)
print("min_y:", self.min_y)
print("max_x:", self.max_x)
print("max_y:", self.max_y)
self.x_width = round((self.max_x - self.min_x) / self.resolution)
self.y_width = round((self.max_y - self.min_y) / self.resolution)
print("x_width:", self.x_width)
print("y_width:", self.y_width)
# obstacle map generation
self.obstacle_map = [[False for _ in range(self.y_width)]
for _ in range(self.x_width)]
for ix in range(self.x_width):
x = self.calc_grid_position(ix, self.min_x)
for iy in range(self.y_width):
y = self.calc_grid_position(iy, self.min_y)
for iox, ioy in zip(ox, oy):
d = math.hypot(iox - x, ioy - y)
if d <= self.rr:
self.obstacle_map[ix][iy] = True
break
| 1,264 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/AStar/a_star.py
|
AStarPlanner.get_motion_model
|
()
|
return motion
| 219 | 230 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/AStar/a_star.py#L219-L230
| 2 |
[
0,
1,
2,
10,
11
] | 41.666667 |
[] | 0 | false | 95.172414 | 12 | 1 | 100 | 0 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
| 1,265 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
main
|
()
| 208 | 234 |
def main():
print("Start " + __file__)
# ====Search Path with RRT====
obstacleList = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2)
] # [x,y,size(radius)]
# Set Initial parameters
start = [0.0, 0.0, np.deg2rad(0.0)]
goal = [10.0, 10.0, np.deg2rad(0.0)]
rrt_dubins = RRTDubins(start, goal, obstacleList, [-2.0, 15.0])
path = rrt_dubins.planning(animation=show_animation)
# Draw final path
if show_animation: # pragma: no cover
rrt_dubins.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.001)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L208-L234
| 2 |
[
0,
1,
2,
3,
4,
13,
14,
15,
16,
17,
18,
19,
20
] | 61.904762 |
[] | 0 | false | 88.288288 | 27 | 4 | 100 | 0 |
def main():
print("Start " + __file__)
# ====Search Path with RRT====
obstacleList = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2)
] # [x,y,size(radius)]
# Set Initial parameters
start = [0.0, 0.0, np.deg2rad(0.0)]
goal = [10.0, 10.0, np.deg2rad(0.0)]
rrt_dubins = RRTDubins(start, goal, obstacleList, [-2.0, 15.0])
path = rrt_dubins.planning(animation=show_animation)
# Draw final path
if show_animation: # pragma: no cover
rrt_dubins.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.001)
plt.show()
| 1,266 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.__init__
|
(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
robot_radius=0.0
)
|
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacleList:obstacle Positions [[x,y,size],...]
randArea:Random Sampling Area [min,max]
robot_radius: robot body modeled as circle with given radius
|
Setting Parameter
| 40 | 66 |
def __init__(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
robot_radius=0.0
):
"""
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacleList:obstacle Positions [[x,y,size],...]
randArea:Random Sampling Area [min,max]
robot_radius: robot body modeled as circle with given radius
"""
self.start = self.Node(start[0], start[1], start[2])
self.end = self.Node(goal[0], goal[1], goal[2])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.curvature = 1.0 # for dubins path
self.goal_yaw_th = np.deg2rad(1.0)
self.goal_xy_th = 0.5
self.robot_radius = robot_radius
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L40-L66
| 2 |
[
0,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
] | 51.851852 |
[] | 0 | false | 88.288288 | 27 | 1 | 100 | 7 |
def __init__(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
robot_radius=0.0
):
self.start = self.Node(start[0], start[1], start[2])
self.end = self.Node(goal[0], goal[1], goal[2])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.curvature = 1.0 # for dubins path
self.goal_yaw_th = np.deg2rad(1.0)
self.goal_xy_th = 0.5
self.robot_radius = robot_radius
| 1,267 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.planning
|
(self, animation=True, search_until_max_iter=True)
|
return None
|
execute planning
animation: flag for animation on or off
|
execute planning
| 68 | 103 |
def planning(self, animation=True, search_until_max_iter=True):
"""
execute planning
animation: flag for animation on or off
"""
self.node_list = [self.start]
for i in range(self.max_iter):
print("Iter:", i, ", number of nodes:", len(self.node_list))
rnd = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd)
new_node = self.steer(self.node_list[nearest_ind], rnd)
if self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
self.node_list.append(new_node)
if animation and i % 5 == 0:
self.plot_start_goal_arrow()
self.draw_graph(rnd)
if (not search_until_max_iter) and new_node: # check reaching the goal
last_index = self.search_best_goal_node()
if last_index:
return self.generate_final_course(last_index)
print("reached max iteration")
last_index = self.search_best_goal_node()
if last_index:
return self.generate_final_course(last_index)
else:
print("Cannot find path")
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L68-L103
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
21,
22,
26,
27,
28,
29,
30,
31,
32
] | 77.777778 |
[
19,
20,
23,
24,
25,
33,
35
] | 19.444444 | false | 88.288288 | 36 | 9 | 80.555556 | 3 |
def planning(self, animation=True, search_until_max_iter=True):
self.node_list = [self.start]
for i in range(self.max_iter):
print("Iter:", i, ", number of nodes:", len(self.node_list))
rnd = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd)
new_node = self.steer(self.node_list[nearest_ind], rnd)
if self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
self.node_list.append(new_node)
if animation and i % 5 == 0:
self.plot_start_goal_arrow()
self.draw_graph(rnd)
if (not search_until_max_iter) and new_node: # check reaching the goal
last_index = self.search_best_goal_node()
if last_index:
return self.generate_final_course(last_index)
print("reached max iteration")
last_index = self.search_best_goal_node()
if last_index:
return self.generate_final_course(last_index)
else:
print("Cannot find path")
return None
| 1,268 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.draw_graph
|
(self, rnd=None)
| 105 | 124 |
def draw_graph(self, rnd=None): # pragma: no cover
plt.clf()
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list:
if node.parent:
plt.plot(node.path_x, node.path_y, "-g")
for (ox, oy, size) in self.obstacle_list:
plt.plot(ox, oy, "ok", ms=30 * size)
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
self.plot_start_goal_arrow()
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L105-L124
| 2 |
[] | 0 |
[] | 0 | false | 88.288288 | 20 | 5 | 100 | 0 |
def draw_graph(self, rnd=None): # pragma: no cover
plt.clf()
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list:
if node.parent:
plt.plot(node.path_x, node.path_y, "-g")
for (ox, oy, size) in self.obstacle_list:
plt.plot(ox, oy, "ok", ms=30 * size)
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
self.plot_start_goal_arrow()
plt.pause(0.01)
| 1,269 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.plot_start_goal_arrow
|
(self)
| 126 | 128 |
def plot_start_goal_arrow(self): # pragma: no cover
plot_arrow(self.start.x, self.start.y, self.start.yaw)
plot_arrow(self.end.x, self.end.y, self.end.yaw)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L126-L128
| 2 |
[] | 0 |
[] | 0 | false | 88.288288 | 3 | 1 | 100 | 0 |
def plot_start_goal_arrow(self): # pragma: no cover
plot_arrow(self.start.x, self.start.y, self.start.yaw)
plot_arrow(self.end.x, self.end.y, self.end.yaw)
| 1,270 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.steer
|
(self, from_node, to_node)
|
return new_node
| 130 | 151 |
def steer(self, from_node, to_node):
px, py, pyaw, mode, course_lengths = \
dubins_path_planner.plan_dubins_path(
from_node.x, from_node.y, from_node.yaw,
to_node.x, to_node.y, to_node.yaw, self.curvature)
if len(px) <= 1: # cannot find a dubins path
return None
new_node = copy.deepcopy(from_node)
new_node.x = px[-1]
new_node.y = py[-1]
new_node.yaw = pyaw[-1]
new_node.path_x = px
new_node.path_y = py
new_node.path_yaw = pyaw
new_node.cost += sum([abs(c) for c in course_lengths])
new_node.parent = from_node
return new_node
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L130-L151
| 2 |
[
0,
1,
2,
6,
7,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 81.818182 |
[
8
] | 4.545455 | false | 88.288288 | 22 | 3 | 95.454545 | 0 |
def steer(self, from_node, to_node):
px, py, pyaw, mode, course_lengths = \
dubins_path_planner.plan_dubins_path(
from_node.x, from_node.y, from_node.yaw,
to_node.x, to_node.y, to_node.yaw, self.curvature)
if len(px) <= 1: # cannot find a dubins path
return None
new_node = copy.deepcopy(from_node)
new_node.x = px[-1]
new_node.y = py[-1]
new_node.yaw = pyaw[-1]
new_node.path_x = px
new_node.path_y = py
new_node.path_yaw = pyaw
new_node.cost += sum([abs(c) for c in course_lengths])
new_node.parent = from_node
return new_node
| 1,271 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.calc_new_cost
|
(self, from_node, to_node)
|
return from_node.cost + course_length
| 153 | 159 |
def calc_new_cost(self, from_node, to_node):
_, _, _, _, course_length = dubins_path_planner.plan_dubins_path(
from_node.x, from_node.y, from_node.yaw,
to_node.x, to_node.y, to_node.yaw, self.curvature)
return from_node.cost + course_length
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L153-L159
| 2 |
[
0,
1
] | 28.571429 |
[
2,
6
] | 28.571429 | false | 88.288288 | 7 | 1 | 71.428571 | 0 |
def calc_new_cost(self, from_node, to_node):
_, _, _, _, course_length = dubins_path_planner.plan_dubins_path(
from_node.x, from_node.y, from_node.yaw,
to_node.x, to_node.y, to_node.yaw, self.curvature)
return from_node.cost + course_length
| 1,272 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.get_random_node
|
(self)
|
return rnd
| 161 | 171 |
def get_random_node(self):
if random.randint(0, 100) > self.goal_sample_rate:
rnd = self.Node(random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand),
random.uniform(-math.pi, math.pi)
)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y, self.end.yaw)
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L161-L171
| 2 |
[
0,
1,
2,
3,
8,
9,
10
] | 63.636364 |
[] | 0 | false | 88.288288 | 11 | 2 | 100 | 0 |
def get_random_node(self):
if random.randint(0, 100) > self.goal_sample_rate:
rnd = self.Node(random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand),
random.uniform(-math.pi, math.pi)
)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y, self.end.yaw)
return rnd
| 1,273 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.search_best_goal_node
|
(self)
|
return None
| 173 | 194 |
def search_best_goal_node(self):
goal_indexes = []
for (i, node) in enumerate(self.node_list):
if self.calc_dist_to_goal(node.x, node.y) <= self.goal_xy_th:
goal_indexes.append(i)
# angle check
final_goal_indexes = []
for i in goal_indexes:
if abs(self.node_list[i].yaw - self.end.yaw) <= self.goal_yaw_th:
final_goal_indexes.append(i)
if not final_goal_indexes:
return None
min_cost = min([self.node_list[i].cost for i in final_goal_indexes])
for i in final_goal_indexes:
if self.node_list[i].cost == min_cost:
return i
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L173-L194
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
15,
16,
17,
18,
19,
20
] | 90.909091 |
[
14,
21
] | 9.090909 | false | 88.288288 | 22 | 9 | 90.909091 | 0 |
def search_best_goal_node(self):
goal_indexes = []
for (i, node) in enumerate(self.node_list):
if self.calc_dist_to_goal(node.x, node.y) <= self.goal_xy_th:
goal_indexes.append(i)
# angle check
final_goal_indexes = []
for i in goal_indexes:
if abs(self.node_list[i].yaw - self.end.yaw) <= self.goal_yaw_th:
final_goal_indexes.append(i)
if not final_goal_indexes:
return None
min_cost = min([self.node_list[i].cost for i in final_goal_indexes])
for i in final_goal_indexes:
if self.node_list[i].cost == min_cost:
return i
return None
| 1,274 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTDubins/rrt_dubins.py
|
RRTDubins.generate_final_course
|
(self, goal_index)
|
return path
| 196 | 205 |
def generate_final_course(self, goal_index):
print("final")
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_index]
while node.parent:
for (ix, iy) in zip(reversed(node.path_x), reversed(node.path_y)):
path.append([ix, iy])
node = node.parent
path.append([self.start.x, self.start.y])
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTDubins/rrt_dubins.py#L196-L205
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 88.288288 | 10 | 3 | 100 | 0 |
def generate_final_course(self, goal_index):
print("final")
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_index]
while node.parent:
for (ix, iy) in zip(reversed(node.path_x), reversed(node.path_y)):
path.append([ix, iy])
node = node.parent
path.append([self.start.x, self.start.y])
return path
| 1,275 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
main
|
()
| 206 | 251 |
def main():
print(__file__ + " start!!")
# start and goal position
sx = 10.0 # [m]
sy = 10.0 # [m]
gx = 50.0 # [m]
gy = 50.0 # [m]
grid_size = 2.0 # [m]
robot_radius = 1.0 # [m]
# set obstacle positions
ox, oy = [], []
for i in range(-10, 60):
ox.append(i)
oy.append(-10.0)
for i in range(-10, 60):
ox.append(60.0)
oy.append(i)
for i in range(-10, 61):
ox.append(i)
oy.append(60.0)
for i in range(-10, 61):
ox.append(-10.0)
oy.append(i)
for i in range(-10, 40):
ox.append(20.0)
oy.append(i)
for i in range(0, 40):
ox.append(40.0)
oy.append(60.0 - i)
if show_animation: # pragma: no cover
plt.plot(ox, oy, ".k")
plt.plot(sx, sy, "og")
plt.plot(gx, gy, "xb")
plt.grid(True)
plt.axis("equal")
dfs = DepthFirstSearchPlanner(ox, oy, grid_size, robot_radius)
rx, ry = dfs.planning(sx, sy, gx, gy)
if show_animation: # pragma: no cover
plt.plot(rx, ry, "-r")
plt.pause(0.01)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L206-L251
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
38,
39,
40,
41
] | 100 |
[] | 0 | true | 95.454545 | 46 | 9 | 100 | 0 |
def main():
print(__file__ + " start!!")
# start and goal position
sx = 10.0 # [m]
sy = 10.0 # [m]
gx = 50.0 # [m]
gy = 50.0 # [m]
grid_size = 2.0 # [m]
robot_radius = 1.0 # [m]
# set obstacle positions
ox, oy = [], []
for i in range(-10, 60):
ox.append(i)
oy.append(-10.0)
for i in range(-10, 60):
ox.append(60.0)
oy.append(i)
for i in range(-10, 61):
ox.append(i)
oy.append(60.0)
for i in range(-10, 61):
ox.append(-10.0)
oy.append(i)
for i in range(-10, 40):
ox.append(20.0)
oy.append(i)
for i in range(0, 40):
ox.append(40.0)
oy.append(60.0 - i)
if show_animation: # pragma: no cover
plt.plot(ox, oy, ".k")
plt.plot(sx, sy, "og")
plt.plot(gx, gy, "xb")
plt.grid(True)
plt.axis("equal")
dfs = DepthFirstSearchPlanner(ox, oy, grid_size, robot_radius)
rx, ry = dfs.planning(sx, sy, gx, gy)
if show_animation: # pragma: no cover
plt.plot(rx, ry, "-r")
plt.pause(0.01)
plt.show()
| 1,276 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.__init__
|
(self, ox, oy, reso, rr)
|
Initialize grid map for Depth-First planning
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
|
Initialize grid map for Depth-First planning
| 20 | 33 |
def __init__(self, ox, oy, reso, rr):
"""
Initialize grid map for Depth-First planning
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
"""
self.reso = reso
self.rr = rr
self.calc_obstacle_map(ox, oy)
self.motion = self.get_motion_model()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L20-L33
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 95.454545 | 14 | 1 | 100 | 6 |
def __init__(self, ox, oy, reso, rr):
self.reso = reso
self.rr = rr
self.calc_obstacle_map(ox, oy)
self.motion = self.get_motion_model()
| 1,277 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.planning
|
(self, sx, sy, gx, gy)
|
return rx, ry
|
Depth First search
input:
s_x: start x position [m]
s_y: start y position [m]
gx: goal x position [m]
gy: goal y position [m]
output:
rx: x position list of the final path
ry: y position list of the final path
|
Depth First search
| 47 | 112 |
def planning(self, sx, sy, gx, gy):
"""
Depth First search
input:
s_x: start x position [m]
s_y: start y position [m]
gx: goal x position [m]
gy: goal y position [m]
output:
rx: x position list of the final path
ry: y position list of the final path
"""
nstart = self.Node(self.calc_xyindex(sx, self.minx),
self.calc_xyindex(sy, self.miny), 0.0, -1, None)
ngoal = self.Node(self.calc_xyindex(gx, self.minx),
self.calc_xyindex(gy, self.miny), 0.0, -1, None)
open_set, closed_set = dict(), dict()
open_set[self.calc_grid_index(nstart)] = nstart
while True:
if len(open_set) == 0:
print("Open set is empty..")
break
current = open_set.pop(list(open_set.keys())[-1])
c_id = self.calc_grid_index(current)
# show graph
if show_animation: # pragma: no cover
plt.plot(self.calc_grid_position(current.x, self.minx),
self.calc_grid_position(current.y, self.miny), "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event:
[exit(0) if event.key == 'escape'
else None])
plt.pause(0.01)
if current.x == ngoal.x and current.y == ngoal.y:
print("Find goal")
ngoal.parent_index = current.parent_index
ngoal.cost = current.cost
break
# expand_grid search grid based on motion model
for i, _ in enumerate(self.motion):
node = self.Node(current.x + self.motion[i][0],
current.y + self.motion[i][1],
current.cost + self.motion[i][2], c_id, None)
n_id = self.calc_grid_index(node)
# If the node is not safe, do nothing
if not self.verify_node(node):
continue
if n_id not in closed_set:
open_set[n_id] = node
closed_set[n_id] = node
node.parent = current
rx, ry = self.calc_final_path(ngoal, closed_set)
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L47-L112
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65
] | 103.225806 |
[
25,
26
] | 3.225806 | false | 95.454545 | 66 | 9 | 96.774194 | 11 |
def planning(self, sx, sy, gx, gy):
nstart = self.Node(self.calc_xyindex(sx, self.minx),
self.calc_xyindex(sy, self.miny), 0.0, -1, None)
ngoal = self.Node(self.calc_xyindex(gx, self.minx),
self.calc_xyindex(gy, self.miny), 0.0, -1, None)
open_set, closed_set = dict(), dict()
open_set[self.calc_grid_index(nstart)] = nstart
while True:
if len(open_set) == 0:
print("Open set is empty..")
break
current = open_set.pop(list(open_set.keys())[-1])
c_id = self.calc_grid_index(current)
# show graph
if show_animation: # pragma: no cover
plt.plot(self.calc_grid_position(current.x, self.minx),
self.calc_grid_position(current.y, self.miny), "xc")
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event:
[exit(0) if event.key == 'escape'
else None])
plt.pause(0.01)
if current.x == ngoal.x and current.y == ngoal.y:
print("Find goal")
ngoal.parent_index = current.parent_index
ngoal.cost = current.cost
break
# expand_grid search grid based on motion model
for i, _ in enumerate(self.motion):
node = self.Node(current.x + self.motion[i][0],
current.y + self.motion[i][1],
current.cost + self.motion[i][2], c_id, None)
n_id = self.calc_grid_index(node)
# If the node is not safe, do nothing
if not self.verify_node(node):
continue
if n_id not in closed_set:
open_set[n_id] = node
closed_set[n_id] = node
node.parent = current
rx, ry = self.calc_final_path(ngoal, closed_set)
return rx, ry
| 1,278 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.calc_final_path
|
(self, ngoal, closedset)
|
return rx, ry
| 114 | 124 |
def calc_final_path(self, ngoal, closedset):
# generate final course
rx, ry = [self.calc_grid_position(ngoal.x, self.minx)], [
self.calc_grid_position(ngoal.y, self.miny)]
n = closedset[ngoal.parent_index]
while n is not None:
rx.append(self.calc_grid_position(n.x, self.minx))
ry.append(self.calc_grid_position(n.y, self.miny))
n = n.parent
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L114-L124
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9,
10
] | 90.909091 |
[] | 0 | false | 95.454545 | 11 | 2 | 100 | 0 |
def calc_final_path(self, ngoal, closedset):
# generate final course
rx, ry = [self.calc_grid_position(ngoal.x, self.minx)], [
self.calc_grid_position(ngoal.y, self.miny)]
n = closedset[ngoal.parent_index]
while n is not None:
rx.append(self.calc_grid_position(n.x, self.minx))
ry.append(self.calc_grid_position(n.y, self.miny))
n = n.parent
return rx, ry
| 1,279 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.calc_grid_position
|
(self, index, minp)
|
return pos
|
calc grid position
:param index:
:param minp:
:return:
|
calc grid position
| 126 | 135 |
def calc_grid_position(self, index, minp):
"""
calc grid position
:param index:
:param minp:
:return:
"""
pos = index * self.reso + minp
return pos
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L126-L135
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 95.454545 | 10 | 1 | 100 | 5 |
def calc_grid_position(self, index, minp):
pos = index * self.reso + minp
return pos
| 1,280 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.calc_xyindex
|
(self, position, min_pos)
|
return round((position - min_pos) / self.reso)
| 137 | 138 |
def calc_xyindex(self, position, min_pos):
return round((position - min_pos) / self.reso)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L137-L138
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 95.454545 | 2 | 1 | 100 | 0 |
def calc_xyindex(self, position, min_pos):
return round((position - min_pos) / self.reso)
| 1,281 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.calc_grid_index
|
(self, node)
|
return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
| 140 | 141 |
def calc_grid_index(self, node):
return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L140-L141
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 95.454545 | 2 | 1 | 100 | 0 |
def calc_grid_index(self, node):
return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
| 1,282 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.verify_node
|
(self, node)
|
return True
| 143 | 160 |
def verify_node(self, node):
px = self.calc_grid_position(node.x, self.minx)
py = self.calc_grid_position(node.y, self.miny)
if px < self.minx:
return False
elif py < self.miny:
return False
elif px >= self.maxx:
return False
elif py >= self.maxy:
return False
# collision check
if self.obmap[node.x][node.y]:
return False
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L143-L160
| 2 |
[
0,
1,
2,
3,
4,
6,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 88.888889 |
[
5,
7
] | 11.111111 | false | 95.454545 | 18 | 6 | 88.888889 | 0 |
def verify_node(self, node):
px = self.calc_grid_position(node.x, self.minx)
py = self.calc_grid_position(node.y, self.miny)
if px < self.minx:
return False
elif py < self.miny:
return False
elif px >= self.maxx:
return False
elif py >= self.maxy:
return False
# collision check
if self.obmap[node.x][node.y]:
return False
return True
| 1,283 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.calc_obstacle_map
|
(self, ox, oy)
| 162 | 189 |
def calc_obstacle_map(self, ox, oy):
self.minx = round(min(ox))
self.miny = round(min(oy))
self.maxx = round(max(ox))
self.maxy = round(max(oy))
print("min_x:", self.minx)
print("min_y:", self.miny)
print("max_x:", self.maxx)
print("max_y:", self.maxy)
self.xwidth = round((self.maxx - self.minx) / self.reso)
self.ywidth = round((self.maxy - self.miny) / self.reso)
print("x_width:", self.xwidth)
print("y_width:", self.ywidth)
# obstacle map generation
self.obmap = [[False for _ in range(self.ywidth)]
for _ in range(self.xwidth)]
for ix in range(self.xwidth):
x = self.calc_grid_position(ix, self.minx)
for iy in range(self.ywidth):
y = self.calc_grid_position(iy, self.miny)
for iox, ioy in zip(ox, oy):
d = math.hypot(iox - x, ioy - y)
if d <= self.rr:
self.obmap[ix][iy] = True
break
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L162-L189
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
19,
20,
21,
22,
23,
24,
25,
26,
27
] | 96.428571 |
[] | 0 | false | 95.454545 | 28 | 7 | 100 | 0 |
def calc_obstacle_map(self, ox, oy):
self.minx = round(min(ox))
self.miny = round(min(oy))
self.maxx = round(max(ox))
self.maxy = round(max(oy))
print("min_x:", self.minx)
print("min_y:", self.miny)
print("max_x:", self.maxx)
print("max_y:", self.maxy)
self.xwidth = round((self.maxx - self.minx) / self.reso)
self.ywidth = round((self.maxy - self.miny) / self.reso)
print("x_width:", self.xwidth)
print("y_width:", self.ywidth)
# obstacle map generation
self.obmap = [[False for _ in range(self.ywidth)]
for _ in range(self.xwidth)]
for ix in range(self.xwidth):
x = self.calc_grid_position(ix, self.minx)
for iy in range(self.ywidth):
y = self.calc_grid_position(iy, self.miny)
for iox, ioy in zip(ox, oy):
d = math.hypot(iox - x, ioy - y)
if d <= self.rr:
self.obmap[ix][iy] = True
break
| 1,284 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/DepthFirstSearch/depth_first_search.py
|
DepthFirstSearchPlanner.get_motion_model
|
()
|
return motion
| 192 | 203 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DepthFirstSearch/depth_first_search.py#L192-L203
| 2 |
[
0,
1,
2,
10,
11
] | 41.666667 |
[] | 0 | false | 95.454545 | 12 | 1 | 100 | 0 |
def get_motion_model():
# dx, dy, cost
motion = [[1, 0, 1],
[0, 1, 1],
[-1, 0, 1],
[0, -1, 1],
[-1, -1, math.sqrt(2)],
[-1, 1, math.sqrt(2)],
[1, -1, math.sqrt(2)],
[1, 1, math.sqrt(2)]]
return motion
| 1,285 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
main
|
()
| 248 | 283 |
def main():
print("Start " + __file__)
# ====Search Path with RRT====
obstacle_list = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2),
(8, 10, 1),
(6, 12, 1),
] # [x,y,size(radius)]
# Set Initial parameters
rrt_star = RRTStar(
start=[0, 0],
goal=[6, 10],
rand_area=[-2, 15],
obstacle_list=obstacle_list,
expand_dis=1,
robot_radius=0.8)
path = rrt_star.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt_star.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], 'r--')
plt.grid(True)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L248-L283
| 2 |
[
0,
1,
2,
3,
4,
15,
16,
23,
24,
25,
26,
35
] | 33.333333 |
[
28,
31,
32,
33,
34
] | 13.888889 | false | 90.47619 | 36 | 5 | 86.111111 | 0 |
def main():
print("Start " + __file__)
# ====Search Path with RRT====
obstacle_list = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2),
(8, 10, 1),
(6, 12, 1),
] # [x,y,size(radius)]
# Set Initial parameters
rrt_star = RRTStar(
start=[0, 0],
goal=[6, 10],
rand_area=[-2, 15],
obstacle_list=obstacle_list,
expand_dis=1,
robot_radius=0.8)
path = rrt_star.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt_star.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], 'r--')
plt.grid(True)
plt.show()
| 1,286 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.__init__
|
(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=30.0,
path_resolution=1.0,
goal_sample_rate=20,
max_iter=300,
connect_circle_dist=50.0,
search_until_max_iter=False,
robot_radius=0.0)
|
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacleList:obstacle Positions [[x,y,size],...]
randArea:Random Sampling Area [min,max]
|
Setting Parameter
| 30 | 57 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=30.0,
path_resolution=1.0,
goal_sample_rate=20,
max_iter=300,
connect_circle_dist=50.0,
search_until_max_iter=False,
robot_radius=0.0):
"""
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacleList:obstacle Positions [[x,y,size],...]
randArea:Random Sampling Area [min,max]
"""
super().__init__(start, goal, obstacle_list, rand_area, expand_dis,
path_resolution, goal_sample_rate, max_iter,
robot_radius=robot_radius)
self.connect_circle_dist = connect_circle_dist
self.goal_node = self.Node(goal[0], goal[1])
self.search_until_max_iter = search_until_max_iter
self.node_list = []
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L30-L57
| 2 |
[
0,
20,
21,
22,
23,
24,
25,
26,
27
] | 32.142857 |
[] | 0 | false | 90.47619 | 28 | 1 | 100 | 6 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=30.0,
path_resolution=1.0,
goal_sample_rate=20,
max_iter=300,
connect_circle_dist=50.0,
search_until_max_iter=False,
robot_radius=0.0):
super().__init__(start, goal, obstacle_list, rand_area, expand_dis,
path_resolution, goal_sample_rate, max_iter,
robot_radius=robot_radius)
self.connect_circle_dist = connect_circle_dist
self.goal_node = self.Node(goal[0], goal[1])
self.search_until_max_iter = search_until_max_iter
self.node_list = []
| 1,287 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.planning
|
(self, animation=True)
|
return None
|
rrt star path planning
animation: flag for animation on or off .
|
rrt star path planning
| 59 | 104 |
def planning(self, animation=True):
"""
rrt star path planning
animation: flag for animation on or off .
"""
self.node_list = [self.start]
for i in range(self.max_iter):
print("Iter:", i, ", number of nodes:", len(self.node_list))
rnd = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd)
new_node = self.steer(self.node_list[nearest_ind], rnd,
self.expand_dis)
near_node = self.node_list[nearest_ind]
new_node.cost = near_node.cost + \
math.hypot(new_node.x-near_node.x,
new_node.y-near_node.y)
if self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
near_inds = self.find_near_nodes(new_node)
node_with_updated_parent = self.choose_parent(
new_node, near_inds)
if node_with_updated_parent:
self.rewire(node_with_updated_parent, near_inds)
self.node_list.append(node_with_updated_parent)
else:
self.node_list.append(new_node)
if animation:
self.draw_graph(rnd)
if ((not self.search_until_max_iter)
and new_node): # if reaches goal
last_index = self.search_best_goal_node()
if last_index is not None:
return self.generate_final_course(last_index)
print("reached max iteration")
last_index = self.search_best_goal_node()
if last_index is not None:
return self.generate_final_course(last_index)
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L59-L104
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
44,
45
] | 95.652174 |
[
31,
43
] | 4.347826 | false | 90.47619 | 46 | 9 | 95.652174 | 3 |
def planning(self, animation=True):
self.node_list = [self.start]
for i in range(self.max_iter):
print("Iter:", i, ", number of nodes:", len(self.node_list))
rnd = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd)
new_node = self.steer(self.node_list[nearest_ind], rnd,
self.expand_dis)
near_node = self.node_list[nearest_ind]
new_node.cost = near_node.cost + \
math.hypot(new_node.x-near_node.x,
new_node.y-near_node.y)
if self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
near_inds = self.find_near_nodes(new_node)
node_with_updated_parent = self.choose_parent(
new_node, near_inds)
if node_with_updated_parent:
self.rewire(node_with_updated_parent, near_inds)
self.node_list.append(node_with_updated_parent)
else:
self.node_list.append(new_node)
if animation:
self.draw_graph(rnd)
if ((not self.search_until_max_iter)
and new_node): # if reaches goal
last_index = self.search_best_goal_node()
if last_index is not None:
return self.generate_final_course(last_index)
print("reached max iteration")
last_index = self.search_best_goal_node()
if last_index is not None:
return self.generate_final_course(last_index)
return None
| 1,288 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.choose_parent
|
(self, new_node, near_inds)
|
return new_node
|
Computes the cheapest point to new_node contained in the list
near_inds and set such a node as the parent of new_node.
Arguments:
--------
new_node, Node
randomly generated node with a path from its neared point
There are not coalitions between this node and th tree.
near_inds: list
Indices of indices of the nodes what are near to new_node
Returns.
------
Node, a copy of new_node
|
Computes the cheapest point to new_node contained in the list
near_inds and set such a node as the parent of new_node.
Arguments:
--------
new_node, Node
randomly generated node with a path from its neared point
There are not coalitions between this node and th tree.
near_inds: list
Indices of indices of the nodes what are near to new_node
| 106 | 145 |
def choose_parent(self, new_node, near_inds):
"""
Computes the cheapest point to new_node contained in the list
near_inds and set such a node as the parent of new_node.
Arguments:
--------
new_node, Node
randomly generated node with a path from its neared point
There are not coalitions between this node and th tree.
near_inds: list
Indices of indices of the nodes what are near to new_node
Returns.
------
Node, a copy of new_node
"""
if not near_inds:
return None
# search nearest cost in near_inds
costs = []
for i in near_inds:
near_node = self.node_list[i]
t_node = self.steer(near_node, new_node)
if t_node and self.check_collision(
t_node, self.obstacle_list, self.robot_radius):
costs.append(self.calc_new_cost(near_node, new_node))
else:
costs.append(float("inf")) # the cost of collision node
min_cost = min(costs)
if min_cost == float("inf"):
print("There is no good path.(min_cost is inf)")
return None
min_ind = near_inds[costs.index(min_cost)]
new_node = self.steer(self.node_list[min_ind], new_node)
new_node.cost = min_cost
return new_node
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L106-L145
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
34,
35,
36,
37,
38,
39
] | 95 |
[
32,
33
] | 5 | false | 90.47619 | 40 | 6 | 95 | 13 |
def choose_parent(self, new_node, near_inds):
if not near_inds:
return None
# search nearest cost in near_inds
costs = []
for i in near_inds:
near_node = self.node_list[i]
t_node = self.steer(near_node, new_node)
if t_node and self.check_collision(
t_node, self.obstacle_list, self.robot_radius):
costs.append(self.calc_new_cost(near_node, new_node))
else:
costs.append(float("inf")) # the cost of collision node
min_cost = min(costs)
if min_cost == float("inf"):
print("There is no good path.(min_cost is inf)")
return None
min_ind = near_inds[costs.index(min_cost)]
new_node = self.steer(self.node_list[min_ind], new_node)
new_node.cost = min_cost
return new_node
| 1,289 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.search_best_goal_node
|
(self)
|
return None
| 147 | 171 |
def search_best_goal_node(self):
dist_to_goal_list = [
self.calc_dist_to_goal(n.x, n.y) for n in self.node_list
]
goal_inds = [
dist_to_goal_list.index(i) for i in dist_to_goal_list
if i <= self.expand_dis
]
safe_goal_inds = []
for goal_ind in goal_inds:
t_node = self.steer(self.node_list[goal_ind], self.goal_node)
if self.check_collision(
t_node, self.obstacle_list, self.robot_radius):
safe_goal_inds.append(goal_ind)
if not safe_goal_inds:
return None
min_cost = min([self.node_list[i].cost for i in safe_goal_inds])
for i in safe_goal_inds:
if self.node_list[i].cost == min_cost:
return i
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L147-L171
| 2 |
[
0,
1,
4,
8,
9,
10,
11,
12,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23
] | 72 |
[
24
] | 4 | false | 90.47619 | 25 | 9 | 96 | 0 |
def search_best_goal_node(self):
dist_to_goal_list = [
self.calc_dist_to_goal(n.x, n.y) for n in self.node_list
]
goal_inds = [
dist_to_goal_list.index(i) for i in dist_to_goal_list
if i <= self.expand_dis
]
safe_goal_inds = []
for goal_ind in goal_inds:
t_node = self.steer(self.node_list[goal_ind], self.goal_node)
if self.check_collision(
t_node, self.obstacle_list, self.robot_radius):
safe_goal_inds.append(goal_ind)
if not safe_goal_inds:
return None
min_cost = min([self.node_list[i].cost for i in safe_goal_inds])
for i in safe_goal_inds:
if self.node_list[i].cost == min_cost:
return i
return None
| 1,290 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.find_near_nodes
|
(self, new_node)
|
return near_inds
|
1) defines a ball centered on new_node
2) Returns all nodes of the three that are inside this ball
Arguments:
---------
new_node: Node
new randomly generated node, without collisions between
its nearest node
Returns:
-------
list
List with the indices of the nodes inside the ball of
radius r
|
1) defines a ball centered on new_node
2) Returns all nodes of the three that are inside this ball
Arguments:
---------
new_node: Node
new randomly generated node, without collisions between
its nearest node
Returns:
-------
list
List with the indices of the nodes inside the ball of
radius r
| 173 | 197 |
def find_near_nodes(self, new_node):
"""
1) defines a ball centered on new_node
2) Returns all nodes of the three that are inside this ball
Arguments:
---------
new_node: Node
new randomly generated node, without collisions between
its nearest node
Returns:
-------
list
List with the indices of the nodes inside the ball of
radius r
"""
nnode = len(self.node_list) + 1
r = self.connect_circle_dist * math.sqrt((math.log(nnode) / nnode))
# if expand_dist exists, search vertices in a range no more than
# expand_dist
if hasattr(self, 'expand_dis'):
r = min(r, self.expand_dis)
dist_list = [(node.x - new_node.x)**2 + (node.y - new_node.y)**2
for node in self.node_list]
near_inds = [dist_list.index(i) for i in dist_list if i <= r**2]
return near_inds
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L173-L197
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24
] | 100 |
[] | 0 | true | 90.47619 | 25 | 4 | 100 | 12 |
def find_near_nodes(self, new_node):
nnode = len(self.node_list) + 1
r = self.connect_circle_dist * math.sqrt((math.log(nnode) / nnode))
# if expand_dist exists, search vertices in a range no more than
# expand_dist
if hasattr(self, 'expand_dis'):
r = min(r, self.expand_dis)
dist_list = [(node.x - new_node.x)**2 + (node.y - new_node.y)**2
for node in self.node_list]
near_inds = [dist_list.index(i) for i in dist_list if i <= r**2]
return near_inds
| 1,291 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.rewire
|
(self, new_node, near_inds)
|
For each node in near_inds, this will check if it is cheaper to
arrive to them from new_node.
In such a case, this will re-assign the parent of the nodes in
near_inds to new_node.
Parameters:
----------
new_node, Node
Node randomly added which can be joined to the tree
near_inds, list of uints
A list of indices of the self.new_node which contains
nodes within a circle of a given radius.
Remark: parent is designated in choose_parent.
|
For each node in near_inds, this will check if it is cheaper to
arrive to them from new_node.
In such a case, this will re-assign the parent of the nodes in
near_inds to new_node.
Parameters:
----------
new_node, Node
Node randomly added which can be joined to the tree
| 199 | 234 |
def rewire(self, new_node, near_inds):
"""
For each node in near_inds, this will check if it is cheaper to
arrive to them from new_node.
In such a case, this will re-assign the parent of the nodes in
near_inds to new_node.
Parameters:
----------
new_node, Node
Node randomly added which can be joined to the tree
near_inds, list of uints
A list of indices of the self.new_node which contains
nodes within a circle of a given radius.
Remark: parent is designated in choose_parent.
"""
for i in near_inds:
near_node = self.node_list[i]
edge_node = self.steer(new_node, near_node)
if not edge_node:
continue
edge_node.cost = self.calc_new_cost(new_node, near_node)
no_collision = self.check_collision(
edge_node, self.obstacle_list, self.robot_radius)
improved_cost = near_node.cost > edge_node.cost
if no_collision and improved_cost:
near_node.x = edge_node.x
near_node.y = edge_node.y
near_node.cost = edge_node.cost
near_node.path_x = edge_node.path_x
near_node.path_y = edge_node.path_y
near_node.parent = edge_node.parent
self.propagate_cost_to_leaves(new_node)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L199-L234
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
] | 97.222222 |
[
21
] | 2.777778 | false | 90.47619 | 36 | 5 | 97.222222 | 13 |
def rewire(self, new_node, near_inds):
for i in near_inds:
near_node = self.node_list[i]
edge_node = self.steer(new_node, near_node)
if not edge_node:
continue
edge_node.cost = self.calc_new_cost(new_node, near_node)
no_collision = self.check_collision(
edge_node, self.obstacle_list, self.robot_radius)
improved_cost = near_node.cost > edge_node.cost
if no_collision and improved_cost:
near_node.x = edge_node.x
near_node.y = edge_node.y
near_node.cost = edge_node.cost
near_node.path_x = edge_node.path_x
near_node.path_y = edge_node.path_y
near_node.parent = edge_node.parent
self.propagate_cost_to_leaves(new_node)
| 1,292 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.calc_new_cost
|
(self, from_node, to_node)
|
return from_node.cost + d
| 236 | 238 |
def calc_new_cost(self, from_node, to_node):
d, _ = self.calc_distance_and_angle(from_node, to_node)
return from_node.cost + d
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L236-L238
| 2 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 90.47619 | 3 | 1 | 100 | 0 |
def calc_new_cost(self, from_node, to_node):
d, _ = self.calc_distance_and_angle(from_node, to_node)
return from_node.cost + d
| 1,293 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRTStar/rrt_star.py
|
RRTStar.propagate_cost_to_leaves
|
(self, parent_node)
| 240 | 245 |
def propagate_cost_to_leaves(self, parent_node):
for node in self.node_list:
if node.parent == parent_node:
node.cost = self.calc_new_cost(parent_node, node)
self.propagate_cost_to_leaves(node)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStar/rrt_star.py#L240-L245
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 90.47619 | 6 | 3 | 100 | 0 |
def propagate_cost_to_leaves(self, parent_node):
for node in self.node_list:
if node.parent == parent_node:
node.cost = self.calc_new_cost(parent_node, node)
self.propagate_cost_to_leaves(node)
| 1,294 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/Quadrotor.py
|
Quadrotor.__init__
|
(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True)
| 12 | 32 |
def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True):
self.p1 = np.array([size / 2, 0, 0, 1]).T
self.p2 = np.array([-size / 2, 0, 0, 1]).T
self.p3 = np.array([0, size / 2, 0, 1]).T
self.p4 = np.array([0, -size / 2, 0, 1]).T
self.x_data = []
self.y_data = []
self.z_data = []
self.show_animation = show_animation
if self.show_animation:
plt.ion()
fig = plt.figure()
# for stopping simulation with the esc key.
fig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
self.ax = fig.add_subplot(111, projection='3d')
self.update_pose(x, y, z, roll, pitch, yaw)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/Quadrotor.py#L12-L32
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
19,
20
] | 66.666667 |
[
12,
13,
15,
18
] | 19.047619 | false | 69.230769 | 21 | 2 | 80.952381 | 0 |
def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True):
self.p1 = np.array([size / 2, 0, 0, 1]).T
self.p2 = np.array([-size / 2, 0, 0, 1]).T
self.p3 = np.array([0, size / 2, 0, 1]).T
self.p4 = np.array([0, -size / 2, 0, 1]).T
self.x_data = []
self.y_data = []
self.z_data = []
self.show_animation = show_animation
if self.show_animation:
plt.ion()
fig = plt.figure()
# for stopping simulation with the esc key.
fig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
self.ax = fig.add_subplot(111, projection='3d')
self.update_pose(x, y, z, roll, pitch, yaw)
| 1,295 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/Quadrotor.py
|
Quadrotor.update_pose
|
(self, x, y, z, roll, pitch, yaw)
| 34 | 46 |
def update_pose(self, x, y, z, roll, pitch, yaw):
self.x = x
self.y = y
self.z = z
self.roll = roll
self.pitch = pitch
self.yaw = yaw
self.x_data.append(x)
self.y_data.append(y)
self.z_data.append(z)
if self.show_animation:
self.plot()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/Quadrotor.py#L34-L46
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
] | 92.307692 |
[
12
] | 7.692308 | false | 69.230769 | 13 | 2 | 92.307692 | 0 |
def update_pose(self, x, y, z, roll, pitch, yaw):
self.x = x
self.y = y
self.z = z
self.roll = roll
self.pitch = pitch
self.yaw = yaw
self.x_data.append(x)
self.y_data.append(y)
self.z_data.append(z)
if self.show_animation:
self.plot()
| 1,296 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/Quadrotor.py
|
Quadrotor.transformation_matrix
|
(self)
|
return np.array(
[[cos(yaw) * cos(pitch), -sin(yaw) * cos(roll) + cos(yaw) * sin(pitch) * sin(roll), sin(yaw) * sin(roll) + cos(yaw) * sin(pitch) * cos(roll), x],
[sin(yaw) * cos(pitch), cos(yaw) * cos(roll) + sin(yaw) * sin(pitch)
* sin(roll), -cos(yaw) * sin(roll) + sin(yaw) * sin(pitch) * cos(roll), y],
[-sin(pitch), cos(pitch) * sin(roll), cos(pitch) * cos(yaw), z]
])
| 48 | 60 |
def transformation_matrix(self):
x = self.x
y = self.y
z = self.z
roll = self.roll
pitch = self.pitch
yaw = self.yaw
return np.array(
[[cos(yaw) * cos(pitch), -sin(yaw) * cos(roll) + cos(yaw) * sin(pitch) * sin(roll), sin(yaw) * sin(roll) + cos(yaw) * sin(pitch) * cos(roll), x],
[sin(yaw) * cos(pitch), cos(yaw) * cos(roll) + sin(yaw) * sin(pitch)
* sin(roll), -cos(yaw) * sin(roll) + sin(yaw) * sin(pitch) * cos(roll), y],
[-sin(pitch), cos(pitch) * sin(roll), cos(pitch) * cos(yaw), z]
])
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/Quadrotor.py#L48-L60
| 2 |
[
0
] | 7.692308 |
[
1,
2,
3,
4,
5,
6,
7
] | 53.846154 | false | 69.230769 | 13 | 1 | 46.153846 | 0 |
def transformation_matrix(self):
x = self.x
y = self.y
z = self.z
roll = self.roll
pitch = self.pitch
yaw = self.yaw
return np.array(
[[cos(yaw) * cos(pitch), -sin(yaw) * cos(roll) + cos(yaw) * sin(pitch) * sin(roll), sin(yaw) * sin(roll) + cos(yaw) * sin(pitch) * cos(roll), x],
[sin(yaw) * cos(pitch), cos(yaw) * cos(roll) + sin(yaw) * sin(pitch)
* sin(roll), -cos(yaw) * sin(roll) + sin(yaw) * sin(pitch) * cos(roll), y],
[-sin(pitch), cos(pitch) * sin(roll), cos(pitch) * cos(yaw), z]
])
| 1,297 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/Quadrotor.py
|
Quadrotor.plot
|
(self)
| 62 | 87 |
def plot(self): # pragma: no cover
T = self.transformation_matrix()
p1_t = np.matmul(T, self.p1)
p2_t = np.matmul(T, self.p2)
p3_t = np.matmul(T, self.p3)
p4_t = np.matmul(T, self.p4)
plt.cla()
self.ax.plot([p1_t[0], p2_t[0], p3_t[0], p4_t[0]],
[p1_t[1], p2_t[1], p3_t[1], p4_t[1]],
[p1_t[2], p2_t[2], p3_t[2], p4_t[2]], 'k.')
self.ax.plot([p1_t[0], p2_t[0]], [p1_t[1], p2_t[1]],
[p1_t[2], p2_t[2]], 'r-')
self.ax.plot([p3_t[0], p4_t[0]], [p3_t[1], p4_t[1]],
[p3_t[2], p4_t[2]], 'r-')
self.ax.plot(self.x_data, self.y_data, self.z_data, 'b:')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
self.ax.set_zlim(0, 10)
plt.pause(0.001)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/Quadrotor.py#L62-L87
| 2 |
[] | 0 |
[] | 0 | false | 69.230769 | 26 | 1 | 100 | 0 |
def plot(self): # pragma: no cover
T = self.transformation_matrix()
p1_t = np.matmul(T, self.p1)
p2_t = np.matmul(T, self.p2)
p3_t = np.matmul(T, self.p3)
p4_t = np.matmul(T, self.p4)
plt.cla()
self.ax.plot([p1_t[0], p2_t[0], p3_t[0], p4_t[0]],
[p1_t[1], p2_t[1], p3_t[1], p4_t[1]],
[p1_t[2], p2_t[2], p3_t[2], p4_t[2]], 'k.')
self.ax.plot([p1_t[0], p2_t[0]], [p1_t[1], p2_t[1]],
[p1_t[2], p2_t[2]], 'r-')
self.ax.plot([p3_t[0], p4_t[0]], [p3_t[1], p4_t[1]],
[p3_t[2], p4_t[2]], 'r-')
self.ax.plot(self.x_data, self.y_data, self.z_data, 'b:')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
self.ax.set_zlim(0, 10)
plt.pause(0.001)
| 1,298 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/TrajectoryGenerator.py
|
TrajectoryGenerator.__init__
|
(self, start_pos, des_pos, T, start_vel=[0,0,0], des_vel=[0,0,0], start_acc=[0,0,0], des_acc=[0,0,0])
| 10 | 35 |
def __init__(self, start_pos, des_pos, T, start_vel=[0,0,0], des_vel=[0,0,0], start_acc=[0,0,0], des_acc=[0,0,0]):
self.start_x = start_pos[0]
self.start_y = start_pos[1]
self.start_z = start_pos[2]
self.des_x = des_pos[0]
self.des_y = des_pos[1]
self.des_z = des_pos[2]
self.start_x_vel = start_vel[0]
self.start_y_vel = start_vel[1]
self.start_z_vel = start_vel[2]
self.des_x_vel = des_vel[0]
self.des_y_vel = des_vel[1]
self.des_z_vel = des_vel[2]
self.start_x_acc = start_acc[0]
self.start_y_acc = start_acc[1]
self.start_z_acc = start_acc[2]
self.des_x_acc = des_acc[0]
self.des_y_acc = des_acc[1]
self.des_z_acc = des_acc[2]
self.T = T
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/TrajectoryGenerator.py#L10-L35
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25
] | 100 |
[] | 0 | true | 100 | 26 | 1 | 100 | 0 |
def __init__(self, start_pos, des_pos, T, start_vel=[0,0,0], des_vel=[0,0,0], start_acc=[0,0,0], des_acc=[0,0,0]):
self.start_x = start_pos[0]
self.start_y = start_pos[1]
self.start_z = start_pos[2]
self.des_x = des_pos[0]
self.des_y = des_pos[1]
self.des_z = des_pos[2]
self.start_x_vel = start_vel[0]
self.start_y_vel = start_vel[1]
self.start_z_vel = start_vel[2]
self.des_x_vel = des_vel[0]
self.des_y_vel = des_vel[1]
self.des_z_vel = des_vel[2]
self.start_x_acc = start_acc[0]
self.start_y_acc = start_acc[1]
self.start_z_acc = start_acc[2]
self.des_x_acc = des_acc[0]
self.des_y_acc = des_acc[1]
self.des_z_acc = des_acc[2]
self.T = T
| 1,299 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
AerialNavigation/drone_3d_trajectory_following/TrajectoryGenerator.py
|
TrajectoryGenerator.solve
|
(self)
| 37 | 76 |
def solve(self):
A = np.array(
[[0, 0, 0, 0, 0, 1],
[self.T**5, self.T**4, self.T**3, self.T**2, self.T, 1],
[0, 0, 0, 0, 1, 0],
[5*self.T**4, 4*self.T**3, 3*self.T**2, 2*self.T, 1, 0],
[0, 0, 0, 2, 0, 0],
[20*self.T**3, 12*self.T**2, 6*self.T, 2, 0, 0]
])
b_x = np.array(
[[self.start_x],
[self.des_x],
[self.start_x_vel],
[self.des_x_vel],
[self.start_x_acc],
[self.des_x_acc]
])
b_y = np.array(
[[self.start_y],
[self.des_y],
[self.start_y_vel],
[self.des_y_vel],
[self.start_y_acc],
[self.des_y_acc]
])
b_z = np.array(
[[self.start_z],
[self.des_z],
[self.start_z_vel],
[self.des_z_vel],
[self.start_z_acc],
[self.des_z_acc]
])
self.x_c = np.linalg.solve(A, b_x)
self.y_c = np.linalg.solve(A, b_y)
self.z_c = np.linalg.solve(A, b_z)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/AerialNavigation/drone_3d_trajectory_following/TrajectoryGenerator.py#L37-L76
| 2 |
[
0,
1,
9,
10,
18,
19,
27,
28,
36,
37,
38,
39
] | 30 |
[] | 0 | false | 100 | 40 | 1 | 100 | 0 |
def solve(self):
A = np.array(
[[0, 0, 0, 0, 0, 1],
[self.T**5, self.T**4, self.T**3, self.T**2, self.T, 1],
[0, 0, 0, 0, 1, 0],
[5*self.T**4, 4*self.T**3, 3*self.T**2, 2*self.T, 1, 0],
[0, 0, 0, 2, 0, 0],
[20*self.T**3, 12*self.T**2, 6*self.T, 2, 0, 0]
])
b_x = np.array(
[[self.start_x],
[self.des_x],
[self.start_x_vel],
[self.des_x_vel],
[self.start_x_acc],
[self.des_x_acc]
])
b_y = np.array(
[[self.start_y],
[self.des_y],
[self.start_y_vel],
[self.des_y_vel],
[self.start_y_acc],
[self.des_y_acc]
])
b_z = np.array(
[[self.start_z],
[self.des_z],
[self.start_z_vel],
[self.des_z_vel],
[self.start_z_acc],
[self.des_z_acc]
])
self.x_c = np.linalg.solve(A, b_x)
self.y_c = np.linalg.solve(A, b_y)
self.z_c = np.linalg.solve(A, b_z)
| 1,300 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.