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/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.compute_distance_cost
|
(self, vid, xid)
|
return np.linalg.norm(stop - start, 2)
| 389 | 394 |
def compute_distance_cost(self, vid, xid):
# L2 norm distance
start = np.array(self.tree.node_id_to_real_world_coord(vid))
stop = np.array(self.tree.node_id_to_real_world_coord(xid))
return np.linalg.norm(stop - start, 2)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L389-L394
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 82.681564 | 6 | 1 | 100 | 0 |
def compute_distance_cost(self, vid, xid):
# L2 norm distance
start = np.array(self.tree.node_id_to_real_world_coord(vid))
stop = np.array(self.tree.node_id_to_real_world_coord(xid))
return np.linalg.norm(stop - start, 2)
| 792 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.informed_sample
|
(self, m, cMax, cMin, xCenter, C)
|
return samples
| 397 | 415 |
def informed_sample(self, m, cMax, cMin, xCenter, C):
samples = dict()
print("g_Score goal id: ", self.g_scores[self.goalId])
for i in range(m + 1):
if cMax < float('inf'):
r = [cMax / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0]
L = np.diag(r)
xBall = self.sample_unit_ball()
rnd = np.dot(np.dot(C, L), xBall) + xCenter
rnd = [rnd[(0, 0)], rnd[(1, 0)]]
random_id = self.tree.real_world_to_node_id(rnd)
samples[random_id] = rnd
else:
rnd = self.sample_free_space()
random_id = self.tree.real_world_to_node_id(rnd)
samples[random_id] = rnd
return samples
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L397-L415
| 2 |
[
0,
1,
2,
3,
4,
15,
16,
17,
18
] | 47.368421 |
[
5,
8,
9,
10,
11,
12,
13
] | 36.842105 | false | 82.681564 | 19 | 3 | 63.157895 | 0 |
def informed_sample(self, m, cMax, cMin, xCenter, C):
samples = dict()
print("g_Score goal id: ", self.g_scores[self.goalId])
for i in range(m + 1):
if cMax < float('inf'):
r = [cMax / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0]
L = np.diag(r)
xBall = self.sample_unit_ball()
rnd = np.dot(np.dot(C, L), xBall) + xCenter
rnd = [rnd[(0, 0)], rnd[(1, 0)]]
random_id = self.tree.real_world_to_node_id(rnd)
samples[random_id] = rnd
else:
rnd = self.sample_free_space()
random_id = self.tree.real_world_to_node_id(rnd)
samples[random_id] = rnd
return samples
| 793 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.sample_unit_ball
|
()
|
return np.array([[sample[0]], [sample[1]], [0]])
| 419 | 428 |
def sample_unit_ball():
a = random.random()
b = random.random()
if b < a:
a, b = b, a
sample = (b * math.cos(2 * math.pi * a / b),
b * math.sin(2 * math.pi * a / b))
return np.array([[sample[0]], [sample[1]], [0]])
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L419-L428
| 2 |
[
0
] | 10 |
[
1,
2,
4,
5,
7,
9
] | 60 | false | 82.681564 | 10 | 2 | 40 | 0 |
def sample_unit_ball():
a = random.random()
b = random.random()
if b < a:
a, b = b, a
sample = (b * math.cos(2 * math.pi * a / b),
b * math.sin(2 * math.pi * a / b))
return np.array([[sample[0]], [sample[1]], [0]])
| 794 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.sample_free_space
|
(self)
|
return rnd
| 430 | 434 |
def sample_free_space(self):
rnd = [random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand)]
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L430-L434
| 2 |
[
0,
1,
3,
4
] | 80 |
[] | 0 | false | 82.681564 | 5 | 1 | 100 | 0 |
def sample_free_space(self):
rnd = [random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand)]
return rnd
| 795 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.best_vertex_queue_value
|
(self)
|
return values[0]
| 436 | 443 |
def best_vertex_queue_value(self):
if len(self.vertex_queue) == 0:
return float('inf')
values = [self.g_scores[v]
+ self.compute_heuristic_cost(v, self.goalId) for v in
self.vertex_queue]
values.sort()
return values[0]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L436-L443
| 2 |
[
0,
1,
2,
3,
6,
7
] | 75 |
[] | 0 | false | 82.681564 | 8 | 3 | 100 | 0 |
def best_vertex_queue_value(self):
if len(self.vertex_queue) == 0:
return float('inf')
values = [self.g_scores[v]
+ self.compute_heuristic_cost(v, self.goalId) for v in
self.vertex_queue]
values.sort()
return values[0]
| 796 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.best_edge_queue_value
|
(self)
|
return values[0]
| 445 | 453 |
def best_edge_queue_value(self):
if len(self.edge_queue) == 0:
return float('inf')
# return the best value in the queue by score g_tau[v] + c(v,x) + h(x)
values = [self.g_scores[e[0]] + self.compute_distance_cost(e[0], e[1])
+ self.compute_heuristic_cost(e[1], self.goalId) for e in
self.edge_queue]
values.sort(reverse=True)
return values[0]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L445-L453
| 2 |
[
0,
1,
2,
3,
4,
7,
8
] | 77.777778 |
[] | 0 | false | 82.681564 | 9 | 3 | 100 | 0 |
def best_edge_queue_value(self):
if len(self.edge_queue) == 0:
return float('inf')
# return the best value in the queue by score g_tau[v] + c(v,x) + h(x)
values = [self.g_scores[e[0]] + self.compute_distance_cost(e[0], e[1])
+ self.compute_heuristic_cost(e[1], self.goalId) for e in
self.edge_queue]
values.sort(reverse=True)
return values[0]
| 797 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.best_in_vertex_queue
|
(self)
|
return v_plus_values[0][0]
| 455 | 462 |
def best_in_vertex_queue(self):
# return the best value in the vertex queue
v_plus_values = [(v, self.g_scores[v] +
self.compute_heuristic_cost(v, self.goalId))
for v in self.vertex_queue]
v_plus_values = sorted(v_plus_values, key=lambda x: x[1])
# print(v_plus_values)
return v_plus_values[0][0]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L455-L462
| 2 |
[
0,
1,
2,
5,
6,
7
] | 75 |
[] | 0 | false | 82.681564 | 8 | 2 | 100 | 0 |
def best_in_vertex_queue(self):
# return the best value in the vertex queue
v_plus_values = [(v, self.g_scores[v] +
self.compute_heuristic_cost(v, self.goalId))
for v in self.vertex_queue]
v_plus_values = sorted(v_plus_values, key=lambda x: x[1])
# print(v_plus_values)
return v_plus_values[0][0]
| 798 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.best_in_edge_queue
|
(self)
|
return e_and_values[0][0], e_and_values[0][1]
| 464 | 471 |
def best_in_edge_queue(self):
e_and_values = [
(e[0], e[1], self.g_scores[e[0]] + self.compute_distance_cost(
e[0], e[1]) + self.compute_heuristic_cost(e[1], self.goalId))
for e in self.edge_queue]
e_and_values = sorted(e_and_values, key=lambda x: x[2])
return e_and_values[0][0], e_and_values[0][1]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L464-L471
| 2 |
[
0,
1,
5,
6,
7
] | 62.5 |
[] | 0 | false | 82.681564 | 8 | 2 | 100 | 0 |
def best_in_edge_queue(self):
e_and_values = [
(e[0], e[1], self.g_scores[e[0]] + self.compute_distance_cost(
e[0], e[1]) + self.compute_heuristic_cost(e[1], self.goalId))
for e in self.edge_queue]
e_and_values = sorted(e_and_values, key=lambda x: x[2])
return e_and_values[0][0], e_and_values[0][1]
| 799 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.expand_vertex
|
(self, vid)
| 473 | 498 |
def expand_vertex(self, vid):
self.vertex_queue.remove(vid)
# get the coordinates for given vid
currCoord = np.array(self.tree.node_id_to_real_world_coord(vid))
# get the nearest value in vertex for every one in samples where difference is
# less than the radius
neighbors = []
for sid, s_coord in self.samples.items():
s_coord = np.array(s_coord)
if np.linalg.norm(s_coord - currCoord, 2) <= self.r and sid != vid:
neighbors.append((sid, s_coord))
# add an edge to the edge queue is the path might improve the solution
for neighbor in neighbors:
sid = neighbor[0]
h_cost = self.compute_heuristic_cost(sid, self.goalId)
estimated_f_score = self.compute_distance_cost(
self.startId, vid) + h_cost + self.compute_distance_cost(vid,
sid)
if estimated_f_score < self.g_scores[self.goalId]:
self.edge_queue.append((vid, sid))
# add the vertex to the edge queue
self.add_vertex_to_edge_queue(vid, currCoord)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L473-L498
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
21,
22,
23,
24,
25
] | 92.307692 |
[] | 0 | false | 82.681564 | 26 | 6 | 100 | 0 |
def expand_vertex(self, vid):
self.vertex_queue.remove(vid)
# get the coordinates for given vid
currCoord = np.array(self.tree.node_id_to_real_world_coord(vid))
# get the nearest value in vertex for every one in samples where difference is
# less than the radius
neighbors = []
for sid, s_coord in self.samples.items():
s_coord = np.array(s_coord)
if np.linalg.norm(s_coord - currCoord, 2) <= self.r and sid != vid:
neighbors.append((sid, s_coord))
# add an edge to the edge queue is the path might improve the solution
for neighbor in neighbors:
sid = neighbor[0]
h_cost = self.compute_heuristic_cost(sid, self.goalId)
estimated_f_score = self.compute_distance_cost(
self.startId, vid) + h_cost + self.compute_distance_cost(vid,
sid)
if estimated_f_score < self.g_scores[self.goalId]:
self.edge_queue.append((vid, sid))
# add the vertex to the edge queue
self.add_vertex_to_edge_queue(vid, currCoord)
| 800 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.add_vertex_to_edge_queue
|
(self, vid, currCoord)
| 500 | 519 |
def add_vertex_to_edge_queue(self, vid, currCoord):
if vid not in self.old_vertices:
neighbors = []
for v, edges in self.tree.vertices.items():
if v != vid and (v, vid) not in self.edge_queue and \
(vid, v) not in self.edge_queue:
v_coord = self.tree.node_id_to_real_world_coord(v)
if np.linalg.norm(currCoord - v_coord, 2) <= self.r:
neighbors.append((vid, v_coord))
for neighbor in neighbors:
sid = neighbor[0]
estimated_f_score = self.compute_distance_cost(
self.startId, vid) + self.compute_distance_cost(
vid, sid) + self.compute_heuristic_cost(sid, self.goalId)
if estimated_f_score < self.g_scores[self.goalId] and (
self.g_scores[vid] +
self.compute_distance_cost(vid, sid)) < \
self.g_scores[sid]:
self.edge_queue.append((vid, sid))
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L500-L519
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
11,
12,
15
] | 65 |
[
19
] | 5 | false | 82.681564 | 20 | 10 | 95 | 0 |
def add_vertex_to_edge_queue(self, vid, currCoord):
if vid not in self.old_vertices:
neighbors = []
for v, edges in self.tree.vertices.items():
if v != vid and (v, vid) not in self.edge_queue and \
(vid, v) not in self.edge_queue:
v_coord = self.tree.node_id_to_real_world_coord(v)
if np.linalg.norm(currCoord - v_coord, 2) <= self.r:
neighbors.append((vid, v_coord))
for neighbor in neighbors:
sid = neighbor[0]
estimated_f_score = self.compute_distance_cost(
self.startId, vid) + self.compute_distance_cost(
vid, sid) + self.compute_heuristic_cost(sid, self.goalId)
if estimated_f_score < self.g_scores[self.goalId] and (
self.g_scores[vid] +
self.compute_distance_cost(vid, sid)) < \
self.g_scores[sid]:
self.edge_queue.append((vid, sid))
| 801 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.update_graph
|
(self)
| 521 | 563 |
def update_graph(self):
closedSet = []
openSet = []
currId = self.startId
openSet.append(currId)
while len(openSet) != 0:
# get the element with lowest f_score
currId = min(openSet, key=lambda x: self.f_scores[x])
# remove element from open set
openSet.remove(currId)
# Check if we're at the goal
if currId == self.goalId:
break
if currId not in closedSet:
closedSet.append(currId)
# find a non visited successor to the current node
successors = self.tree.vertices[currId]
for successor in successors:
if successor in closedSet:
continue
else:
# calculate tentative g score
g_score = self.g_scores[currId] + \
self.compute_distance_cost(currId, successor)
if successor not in openSet:
# add the successor to open set
openSet.append(successor)
elif g_score >= self.g_scores[successor]:
continue
# update g and f scores
self.g_scores[successor] = g_score
self.f_scores[
successor] = g_score + self.compute_heuristic_cost(
successor, self.goalId)
# store the parent and child
self.nodes[successor] = currId
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L521-L563
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
16,
17,
18,
19,
20,
21,
22,
23,
24,
26,
27,
29,
30,
31,
35,
36,
37,
41,
42
] | 79.069767 |
[
15,
32,
33
] | 6.976744 | false | 82.681564 | 43 | 8 | 93.023256 | 0 |
def update_graph(self):
closedSet = []
openSet = []
currId = self.startId
openSet.append(currId)
while len(openSet) != 0:
# get the element with lowest f_score
currId = min(openSet, key=lambda x: self.f_scores[x])
# remove element from open set
openSet.remove(currId)
# Check if we're at the goal
if currId == self.goalId:
break
if currId not in closedSet:
closedSet.append(currId)
# find a non visited successor to the current node
successors = self.tree.vertices[currId]
for successor in successors:
if successor in closedSet:
continue
else:
# calculate tentative g score
g_score = self.g_scores[currId] + \
self.compute_distance_cost(currId, successor)
if successor not in openSet:
# add the successor to open set
openSet.append(successor)
elif g_score >= self.g_scores[successor]:
continue
# update g and f scores
self.g_scores[successor] = g_score
self.f_scores[
successor] = g_score + self.compute_heuristic_cost(
successor, self.goalId)
# store the parent and child
self.nodes[successor] = currId
| 802 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.draw_graph
|
(self, xCenter=None, cBest=None, cMin=None, eTheta=None,
samples=None, start=None, end=None)
| 565 | 588 |
def draw_graph(self, xCenter=None, cBest=None, cMin=None, eTheta=None,
samples=None, start=None, end=None):
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])
for rnd in samples:
if rnd is not None:
plt.plot(rnd[0], rnd[1], "^k")
if cBest != float('inf'):
self.plot_ellipse(xCenter, cBest, cMin, eTheta)
if start is not None and end is not None:
plt.plot([start[0], start[1]], [end[0], end[1]], "-g")
for (ox, oy, size) in self.obstacleList:
plt.plot(ox, oy, "ok", ms=30 * size)
plt.plot(self.start[0], self.start[1], "xr")
plt.plot(self.goal[0], self.goal[1], "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L565-L588
| 2 |
[
0
] | 4.166667 |
[
2,
4,
7,
8,
9,
10,
11,
13,
14,
16,
17,
19,
20,
21,
22,
23
] | 66.666667 | false | 82.681564 | 24 | 7 | 33.333333 | 0 |
def draw_graph(self, xCenter=None, cBest=None, cMin=None, eTheta=None,
samples=None, start=None, end=None):
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])
for rnd in samples:
if rnd is not None:
plt.plot(rnd[0], rnd[1], "^k")
if cBest != float('inf'):
self.plot_ellipse(xCenter, cBest, cMin, eTheta)
if start is not None and end is not None:
plt.plot([start[0], start[1]], [end[0], end[1]], "-g")
for (ox, oy, size) in self.obstacleList:
plt.plot(ox, oy, "ok", ms=30 * size)
plt.plot(self.start[0], self.start[1], "xr")
plt.plot(self.goal[0], self.goal[1], "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
| 803 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py
|
BITStar.plot_ellipse
|
(xCenter, cBest, cMin, eTheta)
| 591 | 608 |
def plot_ellipse(xCenter, cBest, cMin, eTheta): # pragma: no cover
a = math.sqrt(cBest ** 2 - cMin ** 2) / 2.0
b = cBest / 2.0
angle = math.pi / 2.0 - eTheta
cx = xCenter[0]
cy = xCenter[1]
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
x = [a * math.cos(it) for it in t]
y = [b * math.sin(it) for it in t]
R = np.array([[math.cos(angle), math.sin(angle)],
[-math.sin(angle), math.cos(angle)]])
fx = R @ np.array([x, y])
px = np.array(fx[0, :] + cx).flatten()
py = np.array(fx[1, :] + cy).flatten()
plt.plot(cx, cy, "xc")
plt.plot(px, py, "--c")
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py#L591-L608
| 2 |
[] | 0 |
[] | 0 | false | 82.681564 | 18 | 3 | 100 | 0 |
def plot_ellipse(xCenter, cBest, cMin, eTheta): # pragma: no cover
a = math.sqrt(cBest ** 2 - cMin ** 2) / 2.0
b = cBest / 2.0
angle = math.pi / 2.0 - eTheta
cx = xCenter[0]
cy = xCenter[1]
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
x = [a * math.cos(it) for it in t]
y = [b * math.sin(it) for it in t]
R = np.array([[math.cos(angle), math.sin(angle)],
[-math.sin(angle), math.cos(angle)]])
fx = R @ np.array([x, y])
px = np.array(fx[0, :] + cx).flatten()
py = np.array(fx[1, :] + cy).flatten()
plt.plot(cx, cy, "xc")
plt.plot(px, py, "--c")
| 804 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
main
|
(gx=6.0, gy=10.0)
| 259 | 287 |
def main(gx=6.0, gy=10.0):
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), (8, 10, 1)] # [x, y, radius]
# Set Initial parameters
rrt = RRT(
start=[0, 0],
goal=[gx, gy],
rand_area=[-2, 15],
obstacle_list=obstacleList,
# play_area=[0, 10, 0, 14]
robot_radius=0.8
)
path = rrt.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L259-L287
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
15,
16,
17,
20,
21,
22,
23
] | 48.275862 |
[
18,
24,
25,
26,
27,
28
] | 20.689655 | false | 76.433121 | 29 | 5 | 79.310345 | 0 |
def main(gx=6.0, gy=10.0):
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), (8, 10, 1)] # [x, y, radius]
# Set Initial parameters
rrt = RRT(
start=[0, 0],
goal=[gx, gy],
rand_area=[-2, 15],
obstacle_list=obstacleList,
# play_area=[0, 10, 0, 14]
robot_radius=0.8
)
path = rrt.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
| 805 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.__init__
|
(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
play_area=None,
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]
play_area:stay inside this area [xmin,xmax,ymin,ymax]
robot_radius: robot body modeled as circle with given radius
|
Setting Parameter
| 44 | 81 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
play_area=None,
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]
play_area:stay inside this area [xmin,xmax,ymin,ymax]
robot_radius: robot body modeled as circle with given radius
"""
self.start = self.Node(start[0], start[1])
self.end = self.Node(goal[0], goal[1])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
if play_area is not None:
self.play_area = self.AreaBounds(play_area)
else:
self.play_area = None
self.expand_dis = expand_dis
self.path_resolution = path_resolution
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.node_list = []
self.robot_radius = robot_radius
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L44-L81
| 2 |
[
0,
22,
23,
24,
25,
26,
27,
29,
30,
31,
32,
33,
34,
35,
36,
37
] | 42.105263 |
[
28
] | 2.631579 | false | 76.433121 | 38 | 2 | 97.368421 | 8 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
play_area=None,
robot_radius=0.0,
):
self.start = self.Node(start[0], start[1])
self.end = self.Node(goal[0], goal[1])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
if play_area is not None:
self.play_area = self.AreaBounds(play_area)
else:
self.play_area = None
self.expand_dis = expand_dis
self.path_resolution = path_resolution
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.node_list = []
self.robot_radius = robot_radius
| 806 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.planning
|
(self, animation=True)
|
return None
|
rrt path planning
animation: flag for animation on or off
|
rrt path planning
| 83 | 117 |
def planning(self, animation=True):
"""
rrt path planning
animation: flag for animation on or off
"""
self.node_list = [self.start]
for i in range(self.max_iter):
rnd_node = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd_node)
nearest_node = self.node_list[nearest_ind]
new_node = self.steer(nearest_node, rnd_node, self.expand_dis)
if self.check_if_outside_play_area(new_node, self.play_area) and \
self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
self.node_list.append(new_node)
if animation and i % 5 == 0:
self.draw_graph(rnd_node)
if self.calc_dist_to_goal(self.node_list[-1].x,
self.node_list[-1].y) <= self.expand_dis:
final_node = self.steer(self.node_list[-1], self.end,
self.expand_dis)
if self.check_collision(
final_node, self.obstacle_list, self.robot_radius):
return self.generate_final_course(len(self.node_list) - 1)
if animation and i % 5:
self.draw_graph(rnd_node)
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L83-L117
| 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
] | 88.571429 |
[
21,
32,
34
] | 8.571429 | false | 76.433121 | 35 | 10 | 91.428571 | 3 |
def planning(self, animation=True):
self.node_list = [self.start]
for i in range(self.max_iter):
rnd_node = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd_node)
nearest_node = self.node_list[nearest_ind]
new_node = self.steer(nearest_node, rnd_node, self.expand_dis)
if self.check_if_outside_play_area(new_node, self.play_area) and \
self.check_collision(
new_node, self.obstacle_list, self.robot_radius):
self.node_list.append(new_node)
if animation and i % 5 == 0:
self.draw_graph(rnd_node)
if self.calc_dist_to_goal(self.node_list[-1].x,
self.node_list[-1].y) <= self.expand_dis:
final_node = self.steer(self.node_list[-1], self.end,
self.expand_dis)
if self.check_collision(
final_node, self.obstacle_list, self.robot_radius):
return self.generate_final_course(len(self.node_list) - 1)
if animation and i % 5:
self.draw_graph(rnd_node)
return None
| 807 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.steer
|
(self, from_node, to_node, extend_length=float("inf"))
|
return new_node
| 119 | 147 |
def steer(self, from_node, to_node, extend_length=float("inf")):
new_node = self.Node(from_node.x, from_node.y)
d, theta = self.calc_distance_and_angle(new_node, to_node)
new_node.path_x = [new_node.x]
new_node.path_y = [new_node.y]
if extend_length > d:
extend_length = d
n_expand = math.floor(extend_length / self.path_resolution)
for _ in range(n_expand):
new_node.x += self.path_resolution * math.cos(theta)
new_node.y += self.path_resolution * math.sin(theta)
new_node.path_x.append(new_node.x)
new_node.path_y.append(new_node.y)
d, _ = self.calc_distance_and_angle(new_node, to_node)
if d <= self.path_resolution:
new_node.path_x.append(to_node.x)
new_node.path_y.append(to_node.y)
new_node.x = to_node.x
new_node.y = to_node.y
new_node.parent = from_node
return new_node
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L119-L147
| 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
] | 100 |
[] | 0 | true | 76.433121 | 29 | 4 | 100 | 0 |
def steer(self, from_node, to_node, extend_length=float("inf")):
new_node = self.Node(from_node.x, from_node.y)
d, theta = self.calc_distance_and_angle(new_node, to_node)
new_node.path_x = [new_node.x]
new_node.path_y = [new_node.y]
if extend_length > d:
extend_length = d
n_expand = math.floor(extend_length / self.path_resolution)
for _ in range(n_expand):
new_node.x += self.path_resolution * math.cos(theta)
new_node.y += self.path_resolution * math.sin(theta)
new_node.path_x.append(new_node.x)
new_node.path_y.append(new_node.y)
d, _ = self.calc_distance_and_angle(new_node, to_node)
if d <= self.path_resolution:
new_node.path_x.append(to_node.x)
new_node.path_y.append(to_node.y)
new_node.x = to_node.x
new_node.y = to_node.y
new_node.parent = from_node
return new_node
| 808 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.generate_final_course
|
(self, goal_ind)
|
return path
| 149 | 157 |
def generate_final_course(self, goal_ind):
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_ind]
while node.parent is not None:
path.append([node.x, node.y])
node = node.parent
path.append([node.x, node.y])
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L149-L157
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 76.433121 | 9 | 2 | 100 | 0 |
def generate_final_course(self, goal_ind):
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_ind]
while node.parent is not None:
path.append([node.x, node.y])
node = node.parent
path.append([node.x, node.y])
return path
| 809 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.calc_dist_to_goal
|
(self, x, y)
|
return math.hypot(dx, dy)
| 159 | 162 |
def calc_dist_to_goal(self, x, y):
dx = x - self.end.x
dy = y - self.end.y
return math.hypot(dx, dy)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L159-L162
| 2 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 76.433121 | 4 | 1 | 100 | 0 |
def calc_dist_to_goal(self, x, y):
dx = x - self.end.x
dy = y - self.end.y
return math.hypot(dx, dy)
| 810 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.get_random_node
|
(self)
|
return rnd
| 164 | 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))
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L164-L171
| 2 |
[
0,
1,
2,
6,
7
] | 62.5 |
[] | 0 | false | 76.433121 | 8 | 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))
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
| 811 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.draw_graph
|
(self, rnd=None)
| 173 | 204 |
def draw_graph(self, rnd=None):
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")
if self.robot_radius > 0.0:
self.plot_circle(rnd.x, rnd.y, self.robot_radius, '-r')
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:
self.plot_circle(ox, oy, size)
if self.play_area is not None:
plt.plot([self.play_area.xmin, self.play_area.xmax,
self.play_area.xmax, self.play_area.xmin,
self.play_area.xmin],
[self.play_area.ymin, self.play_area.ymin,
self.play_area.ymax, self.play_area.ymax,
self.play_area.ymin],
"-k")
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis("equal")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L173-L204
| 2 |
[
0
] | 3.125 |
[
1,
3,
6,
7,
8,
9,
10,
11,
12,
14,
15,
17,
18,
26,
27,
28,
29,
30,
31
] | 59.375 | false | 76.433121 | 32 | 7 | 40.625 | 0 |
def draw_graph(self, rnd=None):
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")
if self.robot_radius > 0.0:
self.plot_circle(rnd.x, rnd.y, self.robot_radius, '-r')
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:
self.plot_circle(ox, oy, size)
if self.play_area is not None:
plt.plot([self.play_area.xmin, self.play_area.xmax,
self.play_area.xmax, self.play_area.xmin,
self.play_area.xmin],
[self.play_area.ymin, self.play_area.ymin,
self.play_area.ymax, self.play_area.ymax,
self.play_area.ymin],
"-k")
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis("equal")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
| 812 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.plot_circle
|
(x, y, size, color="-b")
| 207 | 212 |
def plot_circle(x, y, size, color="-b"): # pragma: no cover
deg = list(range(0, 360, 5))
deg.append(0)
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
plt.plot(xl, yl, color)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L207-L212
| 2 |
[] | 0 |
[] | 0 | false | 76.433121 | 6 | 3 | 100 | 0 |
def plot_circle(x, y, size, color="-b"): # pragma: no cover
deg = list(range(0, 360, 5))
deg.append(0)
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
plt.plot(xl, yl, color)
| 813 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.get_nearest_node_index
|
(node_list, rnd_node)
|
return minind
| 215 | 220 |
def get_nearest_node_index(node_list, rnd_node):
dlist = [(node.x - rnd_node.x)**2 + (node.y - rnd_node.y)**2
for node in node_list]
minind = dlist.index(min(dlist))
return minind
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L215-L220
| 2 |
[
0,
1,
3,
4,
5
] | 83.333333 |
[] | 0 | false | 76.433121 | 6 | 2 | 100 | 0 |
def get_nearest_node_index(node_list, rnd_node):
dlist = [(node.x - rnd_node.x)**2 + (node.y - rnd_node.y)**2
for node in node_list]
minind = dlist.index(min(dlist))
return minind
| 814 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.check_if_outside_play_area
|
(node, play_area)
| 223 | 232 |
def check_if_outside_play_area(node, play_area):
if play_area is None:
return True # no play_area was defined, every pos should be ok
if node.x < play_area.xmin or node.x > play_area.xmax or \
node.y < play_area.ymin or node.y > play_area.ymax:
return False # outside - bad
else:
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L223-L232
| 2 |
[
0,
1,
2,
3,
4
] | 50 |
[
5,
7,
9
] | 30 | false | 76.433121 | 10 | 6 | 70 | 0 |
def check_if_outside_play_area(node, play_area):
if play_area is None:
return True # no play_area was defined, every pos should be ok
if node.x < play_area.xmin or node.x > play_area.xmax or \
node.y < play_area.ymin or node.y > play_area.ymax:
return False # outside - bad
else:
return True
| 815 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.check_collision
|
(node, obstacleList, robot_radius)
|
return True
| 235 | 248 |
def check_collision(node, obstacleList, robot_radius):
if node is None:
return False
for (ox, oy, size) in obstacleList:
dx_list = [ox - x for x in node.path_x]
dy_list = [oy - y for y in node.path_y]
d_list = [dx * dx + dy * dy for (dx, dy) in zip(dx_list, dy_list)]
if min(d_list) <= (size+robot_radius)**2:
return False # collision
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L235-L248
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 76.433121 | 14 | 7 | 100 | 0 |
def check_collision(node, obstacleList, robot_radius):
if node is None:
return False
for (ox, oy, size) in obstacleList:
dx_list = [ox - x for x in node.path_x]
dy_list = [oy - y for y in node.path_y]
d_list = [dx * dx + dy * dy for (dx, dy) in zip(dx_list, dy_list)]
if min(d_list) <= (size+robot_radius)**2:
return False # collision
return True
| 816 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt.py
|
RRT.calc_distance_and_angle
|
(from_node, to_node)
|
return d, theta
| 251 | 256 |
def calc_distance_and_angle(from_node, to_node):
dx = to_node.x - from_node.x
dy = to_node.y - from_node.y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
return d, theta
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt.py#L251-L256
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 76.433121 | 6 | 1 | 100 | 0 |
def calc_distance_and_angle(from_node, to_node):
dx = to_node.x - from_node.x
dy = to_node.y - from_node.y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
return d, theta
| 817 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_pathsmoothing.py
|
get_path_length
|
(path)
|
return le
| 21 | 29 |
def get_path_length(path):
le = 0
for i in range(len(path) - 1):
dx = path[i + 1][0] - path[i][0]
dy = path[i + 1][1] - path[i][1]
d = math.sqrt(dx * dx + dy * dy)
le += d
return le
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_pathsmoothing.py#L21-L29
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 88.505747 | 9 | 2 | 100 | 0 |
def get_path_length(path):
le = 0
for i in range(len(path) - 1):
dx = path[i + 1][0] - path[i][0]
dy = path[i + 1][1] - path[i][1]
d = math.sqrt(dx * dx + dy * dy)
le += d
return le
| 818 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_pathsmoothing.py
|
get_target_point
|
(path, targetL)
|
return [x, y, ti]
| 32 | 51 |
def get_target_point(path, targetL):
le = 0
ti = 0
lastPairLen = 0
for i in range(len(path) - 1):
dx = path[i + 1][0] - path[i][0]
dy = path[i + 1][1] - path[i][1]
d = math.sqrt(dx * dx + dy * dy)
le += d
if le >= targetL:
ti = i - 1
lastPairLen = d
break
partRatio = (le - targetL) / lastPairLen
x = path[ti][0] + (path[ti + 1][0] - path[ti][0]) * partRatio
y = path[ti][1] + (path[ti + 1][1] - path[ti][1]) * partRatio
return [x, y, ti]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_pathsmoothing.py#L32-L51
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 88.505747 | 20 | 3 | 100 | 0 |
def get_target_point(path, targetL):
le = 0
ti = 0
lastPairLen = 0
for i in range(len(path) - 1):
dx = path[i + 1][0] - path[i][0]
dy = path[i + 1][1] - path[i][1]
d = math.sqrt(dx * dx + dy * dy)
le += d
if le >= targetL:
ti = i - 1
lastPairLen = d
break
partRatio = (le - targetL) / lastPairLen
x = path[ti][0] + (path[ti + 1][0] - path[ti][0]) * partRatio
y = path[ti][1] + (path[ti + 1][1] - path[ti][1]) * partRatio
return [x, y, ti]
| 819 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_pathsmoothing.py
|
line_collision_check
|
(first, second, obstacleList)
|
return True
| 54 | 74 |
def line_collision_check(first, second, obstacleList):
# Line Equation
x1 = first[0]
y1 = first[1]
x2 = second[0]
y2 = second[1]
try:
a = y2 - y1
b = -(x2 - x1)
c = y2 * (x2 - x1) - x2 * (y2 - y1)
except ZeroDivisionError:
return False
for (ox, oy, size) in obstacleList:
d = abs(a * ox + b * oy + c) / (math.sqrt(a * a + b * b))
if d <= size:
return False
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_pathsmoothing.py#L54-L74
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
14,
15,
16,
17,
18,
19,
20
] | 90.47619 |
[
12,
13
] | 9.52381 | false | 88.505747 | 21 | 4 | 90.47619 | 0 |
def line_collision_check(first, second, obstacleList):
# Line Equation
x1 = first[0]
y1 = first[1]
x2 = second[0]
y2 = second[1]
try:
a = y2 - y1
b = -(x2 - x1)
c = y2 * (x2 - x1) - x2 * (y2 - y1)
except ZeroDivisionError:
return False
for (ox, oy, size) in obstacleList:
d = abs(a * ox + b * oy + c) / (math.sqrt(a * a + b * b))
if d <= size:
return False
return True
| 820 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_pathsmoothing.py
|
path_smoothing
|
(path, max_iter, obstacle_list)
|
return path
| 77 | 109 |
def path_smoothing(path, max_iter, obstacle_list):
le = get_path_length(path)
for i in range(max_iter):
# Sample two points
pickPoints = [random.uniform(0, le), random.uniform(0, le)]
pickPoints.sort()
first = get_target_point(path, pickPoints[0])
second = get_target_point(path, pickPoints[1])
if first[2] <= 0 or second[2] <= 0:
continue
if (second[2] + 1) > len(path):
continue
if second[2] == first[2]:
continue
# collision check
if not line_collision_check(first, second, obstacle_list):
continue
# Create New path
newPath = []
newPath.extend(path[:first[2] + 1])
newPath.append([first[0], first[1]])
newPath.append([second[0], second[1]])
newPath.extend(path[second[2] + 1:])
path = newPath
le = get_path_length(path)
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_pathsmoothing.py#L77-L109
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32
] | 96.969697 |
[
14
] | 3.030303 | false | 88.505747 | 33 | 7 | 96.969697 | 0 |
def path_smoothing(path, max_iter, obstacle_list):
le = get_path_length(path)
for i in range(max_iter):
# Sample two points
pickPoints = [random.uniform(0, le), random.uniform(0, le)]
pickPoints.sort()
first = get_target_point(path, pickPoints[0])
second = get_target_point(path, pickPoints[1])
if first[2] <= 0 or second[2] <= 0:
continue
if (second[2] + 1) > len(path):
continue
if second[2] == first[2]:
continue
# collision check
if not line_collision_check(first, second, obstacle_list):
continue
# Create New path
newPath = []
newPath.extend(path[:first[2] + 1])
newPath.append([first[0], first[1]])
newPath.append([second[0], second[1]])
newPath.extend(path[second[2] + 1:])
path = newPath
le = get_path_length(path)
return path
| 821 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_pathsmoothing.py
|
main
|
()
| 112 | 141 |
def main():
# ====Search Path with RRT====
# Parameter
obstacleList = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2)
] # [x,y,size]
rrt = RRT(start=[0, 0], goal=[6, 10],
rand_area=[-2, 15], obstacle_list=obstacleList)
path = rrt.planning(animation=show_animation)
# Path smoothing
maxIter = 1000
smoothedPath = path_smoothing(path, maxIter, obstacleList)
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.plot([x for (x, y) in smoothedPath], [
y for (x, y) in smoothedPath], '-c')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_pathsmoothing.py#L112-L141
| 2 |
[
0,
1,
2,
3,
11,
13,
14,
15,
16,
17,
18,
19,
20
] | 43.333333 |
[
21,
22,
24,
27,
28,
29
] | 20 | false | 88.505747 | 30 | 6 | 80 | 0 |
def main():
# ====Search Path with RRT====
# Parameter
obstacleList = [
(5, 5, 1),
(3, 6, 2),
(3, 8, 2),
(3, 10, 2),
(7, 5, 2),
(9, 5, 2)
] # [x,y,size]
rrt = RRT(start=[0, 0], goal=[6, 10],
rand_area=[-2, 15], obstacle_list=obstacleList)
path = rrt.planning(animation=show_animation)
# Path smoothing
maxIter = 1000
smoothedPath = path_smoothing(path, maxIter, obstacleList)
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.plot([x for (x, y) in smoothedPath], [
y for (x, y) in smoothedPath], '-c')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
| 822 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
main
|
(gx=6.0, gy=10.0)
| 248 | 274 |
def main(gx=6.0, gy=10.0):
print("start " + __file__)
# ====Search Path with RRTSobol====
obstacle_list = [(5, 5, 1), (3, 6, 2), (3, 8, 2), (3, 10, 2), (7, 5, 2),
(9, 5, 2), (8, 10, 1)] # [x, y, radius]
# Set Initial parameters
rrt = RRTSobol(
start=[0, 0],
goal=[gx, gy],
rand_area=[-2, 15],
obstacle_list=obstacle_list,
robot_radius=0.8)
path = rrt.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L248-L274
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
13,
14,
15,
18,
19,
20,
21
] | 51.851852 |
[
16,
22,
23,
24,
25,
26
] | 22.222222 | false | 79.310345 | 27 | 5 | 77.777778 | 0 |
def main(gx=6.0, gy=10.0):
print("start " + __file__)
# ====Search Path with RRTSobol====
obstacle_list = [(5, 5, 1), (3, 6, 2), (3, 8, 2), (3, 10, 2), (7, 5, 2),
(9, 5, 2), (8, 10, 1)] # [x, y, radius]
# Set Initial parameters
rrt = RRTSobol(
start=[0, 0],
goal=[gx, gy],
rand_area=[-2, 15],
obstacle_list=obstacle_list,
robot_radius=0.8)
path = rrt.planning(animation=show_animation)
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
| 823 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.__init__
|
(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
robot_radius=0.0)
|
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacle_list:obstacle Positions [[x,y,size],...]
randArea:Random Sampling Area [min,max]
robot_radius: robot body modeled as circle with given radius
|
Setting Parameter
| 57 | 88 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
robot_radius=0.0):
"""
Setting Parameter
start:Start Position [x,y]
goal:Goal Position [x,y]
obstacle_list: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])
self.end = self.Node(goal[0], goal[1])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
self.expand_dis = expand_dis
self.path_resolution = path_resolution
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.node_list = []
self.sobol_inter_ = 0
self.robot_radius = robot_radius
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L57-L88
| 2 |
[
0,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31
] | 43.75 |
[] | 0 | false | 79.310345 | 32 | 1 | 100 | 7 |
def __init__(self,
start,
goal,
obstacle_list,
rand_area,
expand_dis=3.0,
path_resolution=0.5,
goal_sample_rate=5,
max_iter=500,
robot_radius=0.0):
self.start = self.Node(start[0], start[1])
self.end = self.Node(goal[0], goal[1])
self.min_rand = rand_area[0]
self.max_rand = rand_area[1]
self.expand_dis = expand_dis
self.path_resolution = path_resolution
self.goal_sample_rate = goal_sample_rate
self.max_iter = max_iter
self.obstacle_list = obstacle_list
self.node_list = []
self.sobol_inter_ = 0
self.robot_radius = robot_radius
| 824 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.planning
|
(self, animation=True)
|
return None
|
rrt path planning
animation: flag for animation on or off
|
rrt path planning
| 90 | 123 |
def planning(self, animation=True):
"""
rrt path planning
animation: flag for animation on or off
"""
self.node_list = [self.start]
for i in range(self.max_iter):
rnd_node = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd_node)
nearest_node = self.node_list[nearest_ind]
new_node = self.steer(nearest_node, rnd_node, self.expand_dis)
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.draw_graph(rnd_node)
if self.calc_dist_to_goal(self.node_list[-1].x,
self.node_list[-1].y) <= self.expand_dis:
final_node = self.steer(self.node_list[-1], self.end,
self.expand_dis)
if self.check_collision(
final_node, self.obstacle_list, self.robot_radius):
return self.generate_final_course(len(self.node_list) - 1)
if animation and i % 5:
self.draw_graph(rnd_node)
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L90-L123
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30
] | 88.235294 |
[
20,
31,
33
] | 8.823529 | false | 79.310345 | 34 | 9 | 91.176471 | 3 |
def planning(self, animation=True):
self.node_list = [self.start]
for i in range(self.max_iter):
rnd_node = self.get_random_node()
nearest_ind = self.get_nearest_node_index(self.node_list, rnd_node)
nearest_node = self.node_list[nearest_ind]
new_node = self.steer(nearest_node, rnd_node, self.expand_dis)
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.draw_graph(rnd_node)
if self.calc_dist_to_goal(self.node_list[-1].x,
self.node_list[-1].y) <= self.expand_dis:
final_node = self.steer(self.node_list[-1], self.end,
self.expand_dis)
if self.check_collision(
final_node, self.obstacle_list, self.robot_radius):
return self.generate_final_course(len(self.node_list) - 1)
if animation and i % 5:
self.draw_graph(rnd_node)
return None
| 825 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.steer
|
(self, from_node, to_node, extend_length=float("inf"))
|
return new_node
| 125 | 153 |
def steer(self, from_node, to_node, extend_length=float("inf")):
new_node = self.Node(from_node.x, from_node.y)
d, theta = self.calc_distance_and_angle(new_node, to_node)
new_node.path_x = [new_node.x]
new_node.path_y = [new_node.y]
if extend_length > d:
extend_length = d
n_expand = math.floor(extend_length / self.path_resolution)
for _ in range(n_expand):
new_node.x += self.path_resolution * math.cos(theta)
new_node.y += self.path_resolution * math.sin(theta)
new_node.path_x.append(new_node.x)
new_node.path_y.append(new_node.y)
d, _ = self.calc_distance_and_angle(new_node, to_node)
if d <= self.path_resolution:
new_node.path_x.append(to_node.x)
new_node.path_y.append(to_node.y)
new_node.x = to_node.x
new_node.y = to_node.y
new_node.parent = from_node
return new_node
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L125-L153
| 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
] | 100 |
[] | 0 | true | 79.310345 | 29 | 4 | 100 | 0 |
def steer(self, from_node, to_node, extend_length=float("inf")):
new_node = self.Node(from_node.x, from_node.y)
d, theta = self.calc_distance_and_angle(new_node, to_node)
new_node.path_x = [new_node.x]
new_node.path_y = [new_node.y]
if extend_length > d:
extend_length = d
n_expand = math.floor(extend_length / self.path_resolution)
for _ in range(n_expand):
new_node.x += self.path_resolution * math.cos(theta)
new_node.y += self.path_resolution * math.sin(theta)
new_node.path_x.append(new_node.x)
new_node.path_y.append(new_node.y)
d, _ = self.calc_distance_and_angle(new_node, to_node)
if d <= self.path_resolution:
new_node.path_x.append(to_node.x)
new_node.path_y.append(to_node.y)
new_node.x = to_node.x
new_node.y = to_node.y
new_node.parent = from_node
return new_node
| 826 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.generate_final_course
|
(self, goal_ind)
|
return path
| 155 | 163 |
def generate_final_course(self, goal_ind):
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_ind]
while node.parent is not None:
path.append([node.x, node.y])
node = node.parent
path.append([node.x, node.y])
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L155-L163
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 79.310345 | 9 | 2 | 100 | 0 |
def generate_final_course(self, goal_ind):
path = [[self.end.x, self.end.y]]
node = self.node_list[goal_ind]
while node.parent is not None:
path.append([node.x, node.y])
node = node.parent
path.append([node.x, node.y])
return path
| 827 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.calc_dist_to_goal
|
(self, x, y)
|
return math.hypot(dx, dy)
| 165 | 168 |
def calc_dist_to_goal(self, x, y):
dx = x - self.end.x
dy = y - self.end.y
return math.hypot(dx, dy)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L165-L168
| 2 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 79.310345 | 4 | 1 | 100 | 0 |
def calc_dist_to_goal(self, x, y):
dx = x - self.end.x
dy = y - self.end.y
return math.hypot(dx, dy)
| 828 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.get_random_node
|
(self)
|
return rnd
| 170 | 181 |
def get_random_node(self):
if random.randint(0, 100) > self.goal_sample_rate:
rand_coordinates, n = sobol_quasirand(2, self.sobol_inter_)
rand_coordinates = self.min_rand + \
rand_coordinates*(self.max_rand - self.min_rand)
self.sobol_inter_ = n
rnd = self.Node(*rand_coordinates)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L170-L181
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
8,
11
] | 75 |
[
10
] | 8.333333 | false | 79.310345 | 12 | 2 | 91.666667 | 0 |
def get_random_node(self):
if random.randint(0, 100) > self.goal_sample_rate:
rand_coordinates, n = sobol_quasirand(2, self.sobol_inter_)
rand_coordinates = self.min_rand + \
rand_coordinates*(self.max_rand - self.min_rand)
self.sobol_inter_ = n
rnd = self.Node(*rand_coordinates)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
| 829 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.draw_graph
|
(self, rnd=None)
| 183 | 205 |
def draw_graph(self, rnd=None):
plt.clf()
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [sys.exit(0) if event.key == 'escape' else None])
if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k")
if self.robot_radius >= 0.0:
self.plot_circle(rnd.x, rnd.y, self.robot_radius, '-r')
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:
self.plot_circle(ox, oy, size)
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis("equal")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L183-L205
| 2 |
[
0
] | 4.347826 |
[
1,
3,
6,
7,
8,
9,
10,
11,
12,
14,
15,
17,
18,
19,
20,
21,
22
] | 73.913043 | false | 79.310345 | 23 | 6 | 26.086957 | 0 |
def draw_graph(self, rnd=None):
plt.clf()
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [sys.exit(0) if event.key == 'escape' else None])
if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k")
if self.robot_radius >= 0.0:
self.plot_circle(rnd.x, rnd.y, self.robot_radius, '-r')
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:
self.plot_circle(ox, oy, size)
plt.plot(self.start.x, self.start.y, "xr")
plt.plot(self.end.x, self.end.y, "xr")
plt.axis("equal")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
| 830 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.plot_circle
|
(x, y, size, color="-b")
| 208 | 213 |
def plot_circle(x, y, size, color="-b"): # pragma: no cover
deg = list(range(0, 360, 5))
deg.append(0)
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
plt.plot(xl, yl, color)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L208-L213
| 2 |
[] | 0 |
[] | 0 | false | 79.310345 | 6 | 3 | 100 | 0 |
def plot_circle(x, y, size, color="-b"): # pragma: no cover
deg = list(range(0, 360, 5))
deg.append(0)
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
plt.plot(xl, yl, color)
| 831 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.get_nearest_node_index
|
(node_list, rnd_node)
|
return minind
| 216 | 221 |
def get_nearest_node_index(node_list, rnd_node):
dlist = [(node.x - rnd_node.x)**2 + (node.y - rnd_node.y)**2
for node in node_list]
minind = dlist.index(min(dlist))
return minind
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L216-L221
| 2 |
[
0,
1,
3,
4,
5
] | 83.333333 |
[] | 0 | false | 79.310345 | 6 | 2 | 100 | 0 |
def get_nearest_node_index(node_list, rnd_node):
dlist = [(node.x - rnd_node.x)**2 + (node.y - rnd_node.y)**2
for node in node_list]
minind = dlist.index(min(dlist))
return minind
| 832 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.check_collision
|
(node, obstacle_list, robot_radius)
|
return True
| 224 | 237 |
def check_collision(node, obstacle_list, robot_radius):
if node is None:
return False
for (ox, oy, size) in obstacle_list:
dx_list = [ox - x for x in node.path_x]
dy_list = [oy - y for y in node.path_y]
d_list = [dx * dx + dy * dy for (dx, dy) in zip(dx_list, dy_list)]
if min(d_list) <= (size+robot_radius)**2:
return False # collision
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L224-L237
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9,
10,
12,
13
] | 85.714286 |
[
3,
11
] | 14.285714 | false | 79.310345 | 14 | 7 | 85.714286 | 0 |
def check_collision(node, obstacle_list, robot_radius):
if node is None:
return False
for (ox, oy, size) in obstacle_list:
dx_list = [ox - x for x in node.path_x]
dy_list = [oy - y for y in node.path_y]
d_list = [dx * dx + dy * dy for (dx, dy) in zip(dx_list, dy_list)]
if min(d_list) <= (size+robot_radius)**2:
return False # collision
return True
| 833 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/rrt_with_sobol_sampler.py
|
RRTSobol.calc_distance_and_angle
|
(from_node, to_node)
|
return d, theta
| 240 | 245 |
def calc_distance_and_angle(from_node, to_node):
dx = to_node.x - from_node.x
dy = to_node.y - from_node.y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
return d, theta
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/rrt_with_sobol_sampler.py#L240-L245
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 79.310345 | 6 | 1 | 100 | 0 |
def calc_distance_and_angle(from_node, to_node):
dx = to_node.x - from_node.x
dy = to_node.y - from_node.y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
return d, theta
| 834 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
i4_bit_hi1
|
(n)
|
return bit
|
I4_BIT_HI1 returns the position of the high 1 bit base 2 in an I4.
Discussion:
An I4 is an integer ( kind = 4 ) value.
Example:
N Binary Hi 1
---- -------- ----
0 0 0
1 1 1
2 10 2
3 11 2
4 100 3
5 101 3
6 110 3
7 111 3
8 1000 4
9 1001 4
10 1010 4
11 1011 4
12 1100 4
13 1101 4
14 1110 4
15 1111 4
16 10000 5
17 10001 5
1023 1111111111 10
1024 10000000000 11
1025 10000000001 11
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
26 October 2014
Author:
John Burkardt
Parameters:
Input, integer N, the integer to be measured.
N should be nonnegative. If N is nonpositive, the function
will always be 0.
Output, integer BIT, the position of the highest bit.
|
I4_BIT_HI1 returns the position of the high 1 bit base 2 in an I4.
| 42 | 108 |
def i4_bit_hi1(n):
"""
I4_BIT_HI1 returns the position of the high 1 bit base 2 in an I4.
Discussion:
An I4 is an integer ( kind = 4 ) value.
Example:
N Binary Hi 1
---- -------- ----
0 0 0
1 1 1
2 10 2
3 11 2
4 100 3
5 101 3
6 110 3
7 111 3
8 1000 4
9 1001 4
10 1010 4
11 1011 4
12 1100 4
13 1101 4
14 1110 4
15 1111 4
16 10000 5
17 10001 5
1023 1111111111 10
1024 10000000000 11
1025 10000000001 11
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
26 October 2014
Author:
John Burkardt
Parameters:
Input, integer N, the integer to be measured.
N should be nonnegative. If N is nonpositive, the function
will always be 0.
Output, integer BIT, the position of the highest bit.
"""
i = n
bit = 0
while True:
if i <= 0:
break
bit = bit + 1
i = i // 2
return bit
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L42-L108
| 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
] | 100 |
[] | 0 | true | 53.535354 | 67 | 3 | 100 | 51 |
def i4_bit_hi1(n):
i = n
bit = 0
while True:
if i <= 0:
break
bit = bit + 1
i = i // 2
return bit
| 835 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
i4_bit_lo0
|
(n)
|
return bit
|
I4_BIT_LO0 returns the position of the low 0 bit base 2 in an I4.
Discussion:
An I4 is an integer ( kind = 4 ) value.
Example:
N Binary Lo 0
---- -------- ----
0 0 1
1 1 2
2 10 1
3 11 3
4 100 1
5 101 2
6 110 1
7 111 4
8 1000 1
9 1001 2
10 1010 1
11 1011 3
12 1100 1
13 1101 2
14 1110 1
15 1111 5
16 10000 1
17 10001 2
1023 1111111111 11
1024 10000000000 1
1025 10000000001 2
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
08 February 2018
Author:
John Burkardt
Parameters:
Input, integer N, the integer to be measured.
N should be nonnegative.
Output, integer BIT, the position of the low 1 bit.
|
I4_BIT_LO0 returns the position of the low 0 bit base 2 in an I4.
| 111 | 178 |
def i4_bit_lo0(n):
"""
I4_BIT_LO0 returns the position of the low 0 bit base 2 in an I4.
Discussion:
An I4 is an integer ( kind = 4 ) value.
Example:
N Binary Lo 0
---- -------- ----
0 0 1
1 1 2
2 10 1
3 11 3
4 100 1
5 101 2
6 110 1
7 111 4
8 1000 1
9 1001 2
10 1010 1
11 1011 3
12 1100 1
13 1101 2
14 1110 1
15 1111 5
16 10000 1
17 10001 2
1023 1111111111 11
1024 10000000000 1
1025 10000000001 2
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
08 February 2018
Author:
John Burkardt
Parameters:
Input, integer N, the integer to be measured.
N should be nonnegative.
Output, integer BIT, the position of the low 1 bit.
"""
bit = 0
i = n
while True:
bit = bit + 1
i2 = i // 2
if i == 2 * i2:
break
i = i2
return bit
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L111-L178
| 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
] | 100 |
[] | 0 | true | 53.535354 | 68 | 3 | 100 | 50 |
def i4_bit_lo0(n):
bit = 0
i = n
while True:
bit = bit + 1
i2 = i // 2
if i == 2 * i2:
break
i = i2
return bit
| 836 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
i4_sobol_generate
|
(m, n, skip)
|
return r
|
I4_SOBOL_GENERATE generates a Sobol dataset.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Parameters:
Input, integer M, the spatial dimension.
Input, integer N, the number of points to generate.
Input, integer SKIP, the number of initial points to skip.
Output, real R(M,N), the points.
| 181 | 215 |
def i4_sobol_generate(m, n, skip):
"""
I4_SOBOL_GENERATE generates a Sobol dataset.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Parameters:
Input, integer M, the spatial dimension.
Input, integer N, the number of points to generate.
Input, integer SKIP, the number of initial points to skip.
Output, real R(M,N), the points.
"""
r = np.zeros((m, n))
for j in range(1, n + 1):
seed = skip + j - 2
[r[0:m, j - 1], seed] = i4_sobol(m, seed)
return r
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L181-L215
| 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
] | 85.714286 |
[
30,
31,
32,
33,
34
] | 14.285714 | false | 53.535354 | 35 | 2 | 85.714286 | 24 |
def i4_sobol_generate(m, n, skip):
r = np.zeros((m, n))
for j in range(1, n + 1):
seed = skip + j - 2
[r[0:m, j - 1], seed] = i4_sobol(m, seed)
return r
| 837 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
i4_sobol
|
(dim_num, seed)
|
return [quasi, seed]
|
I4_SOBOL generates a new quasirandom Sobol vector with each call.
Discussion:
The routine adapts the ideas of Antonov and Saleev.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original FORTRAN77 version by Bennett Fox.
MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Reference:
Antonov, Saleev,
USSR Computational Mathematics and Mathematical Physics,
olume 19, 19, pages 252 - 256.
Paul Bratley, Bennett Fox,
Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 14, Number 1, pages 88-100, 1988.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, pages 362-376, 1986.
Ilya Sobol,
USSR Computational Mathematics and Mathematical Physics,
Volume 16, pages 236-242, 1977.
Ilya Sobol, Levitan,
The Production of Points Uniformly Distributed in a Multidimensional
Cube (in Russian),
Preprint IPM Akad. Nauk SSSR,
Number 40, Moscow 1976.
Parameters:
Input, integer DIM_NUM, the number of spatial dimensions.
DIM_NUM must satisfy 1 <= DIM_NUM <= 40.
Input/output, integer SEED, the "seed" for the sequence.
This is essentially the index in the sequence of the quasirandom
value to be generated. On output, SEED has been set to the
appropriate next value, usually simply SEED+1.
If SEED is less than 0 on input, it is treated as though it were 0.
An input value of 0 requests the first (0-th) element of the sequence.
Output, real QUASI(DIM_NUM), the next quasirandom vector.
| 218 | 491 |
def i4_sobol(dim_num, seed):
"""
I4_SOBOL generates a new quasirandom Sobol vector with each call.
Discussion:
The routine adapts the ideas of Antonov and Saleev.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original FORTRAN77 version by Bennett Fox.
MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Reference:
Antonov, Saleev,
USSR Computational Mathematics and Mathematical Physics,
olume 19, 19, pages 252 - 256.
Paul Bratley, Bennett Fox,
Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 14, Number 1, pages 88-100, 1988.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, pages 362-376, 1986.
Ilya Sobol,
USSR Computational Mathematics and Mathematical Physics,
Volume 16, pages 236-242, 1977.
Ilya Sobol, Levitan,
The Production of Points Uniformly Distributed in a Multidimensional
Cube (in Russian),
Preprint IPM Akad. Nauk SSSR,
Number 40, Moscow 1976.
Parameters:
Input, integer DIM_NUM, the number of spatial dimensions.
DIM_NUM must satisfy 1 <= DIM_NUM <= 40.
Input/output, integer SEED, the "seed" for the sequence.
This is essentially the index in the sequence of the quasirandom
value to be generated. On output, SEED has been set to the
appropriate next value, usually simply SEED+1.
If SEED is less than 0 on input, it is treated as though it were 0.
An input value of 0 requests the first (0-th) element of the sequence.
Output, real QUASI(DIM_NUM), the next quasirandom vector.
"""
global atmost
global dim_max
global dim_num_save
global initialized
global lastq
global log_max
global maxcol
global poly
global recipd
global seed_save
global v
if not initialized or dim_num != dim_num_save:
initialized = 1
dim_max = 40
dim_num_save = -1
log_max = 30
seed_save = -1
#
# Initialize (part of) V.
#
v = np.zeros((dim_max, log_max))
v[0:40, 0] = np.transpose([
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
])
v[2:40, 1] = np.transpose([
1, 3, 1, 3, 1, 3, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3,
3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3
])
v[3:40, 2] = np.transpose([
7, 5, 1, 3, 3, 7, 5, 5, 7, 7, 1, 3, 3, 7, 5, 1, 1, 5, 3, 3, 1, 7,
5, 1, 3, 3, 7, 5, 1, 1, 5, 7, 7, 5, 1, 3, 3
])
v[5:40, 3] = np.transpose([
1, 7, 9, 13, 11, 1, 3, 7, 9, 5, 13, 13, 11, 3, 15, 5, 3, 15, 7, 9,
13, 9, 1, 11, 7, 5, 15, 1, 15, 11, 5, 3, 1, 7, 9
])
v[7:40, 4] = np.transpose([
9, 3, 27, 15, 29, 21, 23, 19, 11, 25, 7, 13, 17, 1, 25, 29, 3, 31,
11, 5, 23, 27, 19, 21, 5, 1, 17, 13, 7, 15, 9, 31, 9
])
v[13:40, 5] = np.transpose([
37, 33, 7, 5, 11, 39, 63, 27, 17, 15, 23, 29, 3, 21, 13, 31, 25, 9,
49, 33, 19, 29, 11, 19, 27, 15, 25
])
v[19:40, 6] = np.transpose([
13, 33, 115, 41, 79, 17, 29, 119, 75, 73, 105, 7, 59, 65, 21, 3,
113, 61, 89, 45, 107
])
v[37:40, 7] = np.transpose([7, 23, 39])
#
# Set POLY.
#
poly = [
1, 3, 7, 11, 13, 19, 25, 37, 59, 47, 61, 55, 41, 67, 97, 91, 109,
103, 115, 131, 193, 137, 145, 143, 241, 157, 185, 167, 229, 171,
213, 191, 253, 203, 211, 239, 247, 285, 369, 299
]
atmost = 2**log_max - 1
#
# Find the number of bits in ATMOST.
#
maxcol = i4_bit_hi1(atmost)
#
# Initialize row 1 of V.
#
v[0, 0:maxcol] = 1
# Things to do only if the dimension changed.
if dim_num != dim_num_save:
#
# Check parameters.
#
if (dim_num < 1 or dim_max < dim_num):
print('I4_SOBOL - Fatal error!')
print(' The spatial dimension DIM_NUM should satisfy:')
print(' 1 <= DIM_NUM <= %d' % dim_max)
print(' But this input value is DIM_NUM = %d' % dim_num)
return None
dim_num_save = dim_num
#
# Initialize the remaining rows of V.
#
for i in range(2, dim_num + 1):
#
# The bits of the integer POLY(I) gives the form of polynomial
# I.
#
# Find the degree of polynomial I from binary encoding.
#
j = poly[i - 1]
m = 0
while True:
j = math.floor(j / 2.)
if (j <= 0):
break
m = m + 1
#
# Expand this bit pattern to separate components of the logical
# array INCLUD.
#
j = poly[i - 1]
includ = np.zeros(m)
for k in range(m, 0, -1):
j2 = math.floor(j / 2.)
includ[k - 1] = (j != 2 * j2)
j = j2
#
# Calculate the remaining elements of row I as explained
# in Bratley and Fox, section 2.
#
for j in range(m + 1, maxcol + 1):
newv = v[i - 1, j - m - 1]
l_var = 1
for k in range(1, m + 1):
l_var = 2 * l_var
if (includ[k - 1]):
newv = np.bitwise_xor(
int(newv), int(l_var * v[i - 1, j - k - 1]))
v[i - 1, j - 1] = newv
#
# Multiply columns of V by appropriate power of 2.
#
l_var = 1
for j in range(maxcol - 1, 0, -1):
l_var = 2 * l_var
v[0:dim_num, j - 1] = v[0:dim_num, j - 1] * l_var
#
# RECIPD is 1/(common denominator of the elements in V).
#
recipd = 1.0 / (2 * l_var)
lastq = np.zeros(dim_num)
seed = int(math.floor(seed))
if (seed < 0):
seed = 0
if (seed == 0):
l_var = 1
lastq = np.zeros(dim_num)
elif (seed == seed_save + 1):
#
# Find the position of the right-hand zero in SEED.
#
l_var = i4_bit_lo0(seed)
elif (seed <= seed_save):
seed_save = 0
lastq = np.zeros(dim_num)
for seed_temp in range(int(seed_save), int(seed)):
l_var = i4_bit_lo0(seed_temp)
for i in range(1, dim_num + 1):
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
l_var = i4_bit_lo0(seed)
elif (seed_save + 1 < seed):
for seed_temp in range(int(seed_save + 1), int(seed)):
l_var = i4_bit_lo0(seed_temp)
for i in range(1, dim_num + 1):
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
l_var = i4_bit_lo0(seed)
#
# Check that the user is not calling too many times!
#
if maxcol < l_var:
print('I4_SOBOL - Fatal error!')
print(' Too many calls!')
print(' MAXCOL = %d\n' % maxcol)
print(' L = %d\n' % l_var)
return None
#
# Calculate the new components of QUASI.
#
quasi = np.zeros(dim_num)
for i in range(1, dim_num + 1):
quasi[i - 1] = lastq[i - 1] * recipd
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
seed_save = seed
seed = seed + 1
return [quasi, seed]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L218-L491
| 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,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
123,
124,
125,
126,
127,
128,
129,
130,
131,
132,
133,
134,
135,
136,
137,
138,
139,
140,
141,
142,
143,
144,
145,
146,
147,
148,
149,
150,
151,
152,
158,
159,
160,
161,
162,
163,
164,
165,
166,
167,
168,
169,
170,
171,
172,
173,
174,
175,
176,
177,
178,
179,
180,
181,
182,
183,
184,
185,
186,
187,
188,
189,
190,
191,
192,
193,
194,
195,
196,
197,
198,
199,
200,
201,
202,
203,
204,
205,
206,
207,
208,
209,
210,
211,
212,
213,
214,
215,
217,
218,
219,
220,
221,
222,
223,
224,
225,
226,
227,
252,
253,
263,
264,
265,
266,
267,
268,
269,
270,
271,
272,
273
] | 85.766423 |
[
153,
154,
155,
156,
157,
216,
228,
230,
231,
233,
234,
235,
236,
239,
241,
243,
244,
245,
246,
249,
254,
255,
256,
257,
258
] | 9.124088 | false | 53.535354 | 274 | 25 | 90.875912 | 62 |
def i4_sobol(dim_num, seed):
global atmost
global dim_max
global dim_num_save
global initialized
global lastq
global log_max
global maxcol
global poly
global recipd
global seed_save
global v
if not initialized or dim_num != dim_num_save:
initialized = 1
dim_max = 40
dim_num_save = -1
log_max = 30
seed_save = -1
#
# Initialize (part of) V.
#
v = np.zeros((dim_max, log_max))
v[0:40, 0] = np.transpose([
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
])
v[2:40, 1] = np.transpose([
1, 3, 1, 3, 1, 3, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3,
3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3
])
v[3:40, 2] = np.transpose([
7, 5, 1, 3, 3, 7, 5, 5, 7, 7, 1, 3, 3, 7, 5, 1, 1, 5, 3, 3, 1, 7,
5, 1, 3, 3, 7, 5, 1, 1, 5, 7, 7, 5, 1, 3, 3
])
v[5:40, 3] = np.transpose([
1, 7, 9, 13, 11, 1, 3, 7, 9, 5, 13, 13, 11, 3, 15, 5, 3, 15, 7, 9,
13, 9, 1, 11, 7, 5, 15, 1, 15, 11, 5, 3, 1, 7, 9
])
v[7:40, 4] = np.transpose([
9, 3, 27, 15, 29, 21, 23, 19, 11, 25, 7, 13, 17, 1, 25, 29, 3, 31,
11, 5, 23, 27, 19, 21, 5, 1, 17, 13, 7, 15, 9, 31, 9
])
v[13:40, 5] = np.transpose([
37, 33, 7, 5, 11, 39, 63, 27, 17, 15, 23, 29, 3, 21, 13, 31, 25, 9,
49, 33, 19, 29, 11, 19, 27, 15, 25
])
v[19:40, 6] = np.transpose([
13, 33, 115, 41, 79, 17, 29, 119, 75, 73, 105, 7, 59, 65, 21, 3,
113, 61, 89, 45, 107
])
v[37:40, 7] = np.transpose([7, 23, 39])
#
# Set POLY.
#
poly = [
1, 3, 7, 11, 13, 19, 25, 37, 59, 47, 61, 55, 41, 67, 97, 91, 109,
103, 115, 131, 193, 137, 145, 143, 241, 157, 185, 167, 229, 171,
213, 191, 253, 203, 211, 239, 247, 285, 369, 299
]
atmost = 2**log_max - 1
#
# Find the number of bits in ATMOST.
#
maxcol = i4_bit_hi1(atmost)
#
# Initialize row 1 of V.
#
v[0, 0:maxcol] = 1
# Things to do only if the dimension changed.
if dim_num != dim_num_save:
#
# Check parameters.
#
if (dim_num < 1 or dim_max < dim_num):
print('I4_SOBOL - Fatal error!')
print(' The spatial dimension DIM_NUM should satisfy:')
print(' 1 <= DIM_NUM <= %d' % dim_max)
print(' But this input value is DIM_NUM = %d' % dim_num)
return None
dim_num_save = dim_num
#
# Initialize the remaining rows of V.
#
for i in range(2, dim_num + 1):
#
# The bits of the integer POLY(I) gives the form of polynomial
# I.
#
# Find the degree of polynomial I from binary encoding.
#
j = poly[i - 1]
m = 0
while True:
j = math.floor(j / 2.)
if (j <= 0):
break
m = m + 1
#
# Expand this bit pattern to separate components of the logical
# array INCLUD.
#
j = poly[i - 1]
includ = np.zeros(m)
for k in range(m, 0, -1):
j2 = math.floor(j / 2.)
includ[k - 1] = (j != 2 * j2)
j = j2
#
# Calculate the remaining elements of row I as explained
# in Bratley and Fox, section 2.
#
for j in range(m + 1, maxcol + 1):
newv = v[i - 1, j - m - 1]
l_var = 1
for k in range(1, m + 1):
l_var = 2 * l_var
if (includ[k - 1]):
newv = np.bitwise_xor(
int(newv), int(l_var * v[i - 1, j - k - 1]))
v[i - 1, j - 1] = newv
#
# Multiply columns of V by appropriate power of 2.
#
l_var = 1
for j in range(maxcol - 1, 0, -1):
l_var = 2 * l_var
v[0:dim_num, j - 1] = v[0:dim_num, j - 1] * l_var
#
# RECIPD is 1/(common denominator of the elements in V).
#
recipd = 1.0 / (2 * l_var)
lastq = np.zeros(dim_num)
seed = int(math.floor(seed))
if (seed < 0):
seed = 0
if (seed == 0):
l_var = 1
lastq = np.zeros(dim_num)
elif (seed == seed_save + 1):
#
# Find the position of the right-hand zero in SEED.
#
l_var = i4_bit_lo0(seed)
elif (seed <= seed_save):
seed_save = 0
lastq = np.zeros(dim_num)
for seed_temp in range(int(seed_save), int(seed)):
l_var = i4_bit_lo0(seed_temp)
for i in range(1, dim_num + 1):
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
l_var = i4_bit_lo0(seed)
elif (seed_save + 1 < seed):
for seed_temp in range(int(seed_save + 1), int(seed)):
l_var = i4_bit_lo0(seed_temp)
for i in range(1, dim_num + 1):
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
l_var = i4_bit_lo0(seed)
#
# Check that the user is not calling too many times!
#
if maxcol < l_var:
print('I4_SOBOL - Fatal error!')
print(' Too many calls!')
print(' MAXCOL = %d\n' % maxcol)
print(' L = %d\n' % l_var)
return None
#
# Calculate the new components of QUASI.
#
quasi = np.zeros(dim_num)
for i in range(1, dim_num + 1):
quasi[i - 1] = lastq[i - 1] * recipd
lastq[i - 1] = np.bitwise_xor(
int(lastq[i - 1]), int(v[i - 1, l_var - 1]))
seed_save = seed
seed = seed + 1
return [quasi, seed]
| 838 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
i4_uniform_ab
|
(a, b, seed)
|
return value, seed
|
I4_UNIFORM_AB returns a scaled pseudorandom I4.
Discussion:
The pseudorandom number will be scaled to be uniformly distributed
between A and B.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
05 April 2013
Author:
John Burkardt
Reference:
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, December 1986, pages 362-376.
Pierre L'Ecuyer,
Random Number Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
Peter Lewis, Allen Goodman, James Miller,
A Pseudo-Random Number Generator for the System/360,
IBM Systems Journal,
Volume 8, Number 2, 1969, pages 136-143.
Parameters:
Input, integer A, B, the minimum and maximum acceptable values.
Input, integer SEED, a seed for the random number generator.
Output, integer C, the randomly chosen integer.
Output, integer SEED, the updated seed.
| 494 | 598 |
def i4_uniform_ab(a, b, seed):
"""
I4_UNIFORM_AB returns a scaled pseudorandom I4.
Discussion:
The pseudorandom number will be scaled to be uniformly distributed
between A and B.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
05 April 2013
Author:
John Burkardt
Reference:
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, December 1986, pages 362-376.
Pierre L'Ecuyer,
Random Number Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
Peter Lewis, Allen Goodman, James Miller,
A Pseudo-Random Number Generator for the System/360,
IBM Systems Journal,
Volume 8, Number 2, 1969, pages 136-143.
Parameters:
Input, integer A, B, the minimum and maximum acceptable values.
Input, integer SEED, a seed for the random number generator.
Output, integer C, the randomly chosen integer.
Output, integer SEED, the updated seed.
"""
i4_huge = 2147483647
seed = int(seed)
seed = (seed % i4_huge)
if seed < 0:
seed = seed + i4_huge
if seed == 0:
print('')
print('I4_UNIFORM_AB - Fatal error!')
print(' Input SEED = 0!')
sys.exit('I4_UNIFORM_AB - Fatal error!')
k = (seed // 127773)
seed = 167 * (seed - k * 127773) - k * 2836
if seed < 0:
seed = seed + i4_huge
r = seed * 4.656612875E-10
#
# Scale R to lie between A-0.5 and B+0.5.
#
a = round(a)
b = round(b)
r = (1.0 - r) * (min(a, b) - 0.5) \
+ r * (max(a, b) + 0.5)
#
# Use rounding to convert R to an integer between A and B.
#
value = round(r)
value = max(value, min(a, b))
value = min(value, max(a, b))
value = int(value)
return value, seed
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L494-L598
| 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
] | 60.952381 |
[
64,
66,
68,
70,
71,
73,
74,
75,
76,
77,
79,
81,
83,
84,
86,
90,
91,
93,
98,
100,
101,
102,
104
] | 21.904762 | false | 53.535354 | 105 | 4 | 78.095238 | 57 |
def i4_uniform_ab(a, b, seed):
i4_huge = 2147483647
seed = int(seed)
seed = (seed % i4_huge)
if seed < 0:
seed = seed + i4_huge
if seed == 0:
print('')
print('I4_UNIFORM_AB - Fatal error!')
print(' Input SEED = 0!')
sys.exit('I4_UNIFORM_AB - Fatal error!')
k = (seed // 127773)
seed = 167 * (seed - k * 127773) - k * 2836
if seed < 0:
seed = seed + i4_huge
r = seed * 4.656612875E-10
#
# Scale R to lie between A-0.5 and B+0.5.
#
a = round(a)
b = round(b)
r = (1.0 - r) * (min(a, b) - 0.5) \
+ r * (max(a, b) + 0.5)
#
# Use rounding to convert R to an integer between A and B.
#
value = round(r)
value = max(value, min(a, b))
value = min(value, max(a, b))
value = int(value)
return value, seed
| 839 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
prime_ge
|
(n)
|
return p
|
PRIME_GE returns the smallest prime greater than or equal to N.
Example:
N PRIME_GE
-10 2
1 2
2 2
3 3
4 5
5 5
6 7
7 7
8 11
9 11
10 11
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Parameters:
Input, integer N, the number to be bounded.
Output, integer P, the smallest prime number that is greater
than or equal to N.
| 601 | 648 |
def prime_ge(n):
"""
PRIME_GE returns the smallest prime greater than or equal to N.
Example:
N PRIME_GE
-10 2
1 2
2 2
3 3
4 5
5 5
6 7
7 7
8 11
9 11
10 11
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Parameters:
Input, integer N, the number to be bounded.
Output, integer P, the smallest prime number that is greater
than or equal to N.
"""
p = max(math.ceil(n), 2)
while not isprime(p):
p = p + 1
return p
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L601-L648
| 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
] | 89.583333 |
[
43,
44,
45,
47
] | 8.333333 | false | 53.535354 | 48 | 2 | 91.666667 | 37 |
def prime_ge(n):
p = max(math.ceil(n), 2)
while not isprime(p):
p = p + 1
return p
| 840 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
isprime
|
(n)
|
return True
|
IS_PRIME returns True if N is a prime number, False otherwise
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Corrado Chisari
Parameters:
Input, integer N, the number to be checked.
Output, boolean value, True or False
| 651 | 684 |
def isprime(n):
"""
IS_PRIME returns True if N is a prime number, False otherwise
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Corrado Chisari
Parameters:
Input, integer N, the number to be checked.
Output, boolean value, True or False
"""
if n != int(n) or n < 1:
return False
p = 2
while p < n:
if n % p == 0:
return False
p += 1
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L651-L684
| 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
] | 73.529412 |
[
25,
26,
27,
28,
29,
30,
31,
33
] | 23.529412 | false | 53.535354 | 34 | 5 | 76.470588 | 19 |
def isprime(n):
if n != int(n) or n < 1:
return False
p = 2
while p < n:
if n % p == 0:
return False
p += 1
return True
| 841 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
r4_uniform_01
|
(seed)
|
return r, seed
|
R4_UNIFORM_01 returns a unit pseudorandom R4.
Discussion:
This routine implements the recursion
seed = 167 * seed mod ( 2^31 - 1 )
r = seed / ( 2^31 - 1 )
The integer arithmetic never requires more than 32 bits,
including a sign bit.
If the initial seed is 12345, then the first three computations are
Input Output R4_UNIFORM_01
SEED SEED
12345 207482415 0.096616
207482415 1790989824 0.833995
1790989824 2035175616 0.947702
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
04 April 2013
Author:
John Burkardt
Reference:
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, December 1986, pages 362-376.
Pierre L'Ecuyer,
Random Number Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
Peter Lewis, Allen Goodman, James Miller,
A Pseudo-Random Number Generator for the System/360,
IBM Systems Journal,
Volume 8, Number 2, 1969, pages 136-143.
Parameters:
Input, integer SEED, the integer "seed" used to generate
the output random number. SEED should not be 0.
Output, real R, a random value between 0 and 1.
Output, integer SEED, the updated seed. This would
normally be used as the input seed on the next call.
| 687 | 787 |
def r4_uniform_01(seed):
"""
R4_UNIFORM_01 returns a unit pseudorandom R4.
Discussion:
This routine implements the recursion
seed = 167 * seed mod ( 2^31 - 1 )
r = seed / ( 2^31 - 1 )
The integer arithmetic never requires more than 32 bits,
including a sign bit.
If the initial seed is 12345, then the first three computations are
Input Output R4_UNIFORM_01
SEED SEED
12345 207482415 0.096616
207482415 1790989824 0.833995
1790989824 2035175616 0.947702
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
04 April 2013
Author:
John Burkardt
Reference:
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, December 1986, pages 362-376.
Pierre L'Ecuyer,
Random Number Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
Peter Lewis, Allen Goodman, James Miller,
A Pseudo-Random Number Generator for the System/360,
IBM Systems Journal,
Volume 8, Number 2, 1969, pages 136-143.
Parameters:
Input, integer SEED, the integer "seed" used to generate
the output random number. SEED should not be 0.
Output, real R, a random value between 0 and 1.
Output, integer SEED, the updated seed. This would
normally be used as the input seed on the next call.
"""
i4_huge = 2147483647
if (seed == 0):
print('')
print('R4_UNIFORM_01 - Fatal error!')
print(' Input SEED = 0!')
sys.exit('R4_UNIFORM_01 - Fatal error!')
seed = (seed % i4_huge)
if seed < 0:
seed = seed + i4_huge
k = (seed // 127773)
seed = 167 * (seed - k * 127773) - k * 2836
if seed < 0:
seed = seed + i4_huge
r = seed * 4.656612875E-10
return r, seed
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L687-L787
| 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,
73,
74,
75,
76,
77
] | 77.227723 |
[
78,
80,
81,
82,
83,
84,
86,
88,
89,
91,
93,
95,
96,
98,
100
] | 14.851485 | false | 53.535354 | 101 | 4 | 85.148515 | 71 |
def r4_uniform_01(seed):
i4_huge = 2147483647
if (seed == 0):
print('')
print('R4_UNIFORM_01 - Fatal error!')
print(' Input SEED = 0!')
sys.exit('R4_UNIFORM_01 - Fatal error!')
seed = (seed % i4_huge)
if seed < 0:
seed = seed + i4_huge
k = (seed // 127773)
seed = 167 * (seed - k * 127773) - k * 2836
if seed < 0:
seed = seed + i4_huge
r = seed * 4.656612875E-10
return r, seed
| 842 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
r8mat_write
|
(filename, m, n, a)
|
R8MAT_WRITE writes an R8MAT to a file.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
12 October 2014
Author:
John Burkardt
Parameters:
Input, string FILENAME, the name of the output file.
Input, integer M, the number of rows in A.
Input, integer N, the number of columns in A.
Input, real A(M,N), the matrix.
| 790 | 824 |
def r8mat_write(filename, m, n, a):
"""
R8MAT_WRITE writes an R8MAT to a file.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
12 October 2014
Author:
John Burkardt
Parameters:
Input, string FILENAME, the name of the output file.
Input, integer M, the number of rows in A.
Input, integer N, the number of columns in A.
Input, real A(M,N), the matrix.
"""
with open(filename, 'w') as output:
for i in range(0, m):
for j in range(0, n):
s = ' %g' % (a[i, j])
output.write(s)
output.write('\n')
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L790-L824
| 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
] | 82.857143 |
[
29,
30,
31,
32,
33,
34
] | 17.142857 | false | 53.535354 | 35 | 4 | 82.857143 | 23 |
def r8mat_write(filename, m, n, a):
with open(filename, 'w') as output:
for i in range(0, m):
for j in range(0, n):
s = ' %g' % (a[i, j])
output.write(s)
output.write('\n')
| 843 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/RRT/sobol/sobol.py
|
tau_sobol
|
(dim_num)
|
return tau
|
TAU_SOBOL defines favorable starting seeds for Sobol sequences.
Discussion:
For spatial dimensions 1 through 13, this routine returns
a "favorable" value TAU by which an appropriate starting point
in the Sobol sequence can be determined.
These starting points have the form N = 2**K, where
for integration problems, it is desirable that
TAU + DIM_NUM - 1 <= K
while for optimization problems, it is desirable that
TAU < K.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original FORTRAN77 version by Bennett Fox.
MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Reference:
IA Antonov, VM Saleev,
USSR Computational Mathematics and Mathematical Physics,
Volume 19, 19, pages 252 - 256.
Paul Bratley, Bennett Fox,
Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 14, Number 1, pages 88-100, 1988.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, pages 362-376, 1986.
Stephen Joe, Frances Kuo
Remark on Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 29, Number 1, pages 49-57, March 2003.
Ilya Sobol,
USSR Computational Mathematics and Mathematical Physics,
Volume 16, pages 236-242, 1977.
Ilya Sobol, YL Levitan,
The Production of Points Uniformly Distributed in a Multidimensional
Cube (in Russian),
Preprint IPM Akad. Nauk SSSR,
Number 40, Moscow 1976.
Parameters:
Input, integer DIM_NUM, the spatial dimension. Only values
of 1 through 13 will result in useful responses.
Output, integer TAU, the value TAU.
| 827 | 911 |
def tau_sobol(dim_num):
"""
TAU_SOBOL defines favorable starting seeds for Sobol sequences.
Discussion:
For spatial dimensions 1 through 13, this routine returns
a "favorable" value TAU by which an appropriate starting point
in the Sobol sequence can be determined.
These starting points have the form N = 2**K, where
for integration problems, it is desirable that
TAU + DIM_NUM - 1 <= K
while for optimization problems, it is desirable that
TAU < K.
Licensing:
This code is distributed under the MIT license.
Modified:
22 February 2011
Author:
Original FORTRAN77 version by Bennett Fox.
MATLAB version by John Burkardt.
PYTHON version by Corrado Chisari
Reference:
IA Antonov, VM Saleev,
USSR Computational Mathematics and Mathematical Physics,
Volume 19, 19, pages 252 - 256.
Paul Bratley, Bennett Fox,
Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 14, Number 1, pages 88-100, 1988.
Bennett Fox,
Algorithm 647:
Implementation and Relative Efficiency of Quasirandom
Sequence Generators,
ACM Transactions on Mathematical Software,
Volume 12, Number 4, pages 362-376, 1986.
Stephen Joe, Frances Kuo
Remark on Algorithm 659:
Implementing Sobol's Quasirandom Sequence Generator,
ACM Transactions on Mathematical Software,
Volume 29, Number 1, pages 49-57, March 2003.
Ilya Sobol,
USSR Computational Mathematics and Mathematical Physics,
Volume 16, pages 236-242, 1977.
Ilya Sobol, YL Levitan,
The Production of Points Uniformly Distributed in a Multidimensional
Cube (in Russian),
Preprint IPM Akad. Nauk SSSR,
Number 40, Moscow 1976.
Parameters:
Input, integer DIM_NUM, the spatial dimension. Only values
of 1 through 13 will result in useful responses.
Output, integer TAU, the value TAU.
"""
dim_max = 13
tau_table = [0, 0, 1, 3, 5, 8, 11, 15, 19, 23, 27, 31, 35]
if 1 <= dim_num <= dim_max:
tau = tau_table[dim_num]
else:
tau = -1
return tau
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRT/sobol/sobol.py#L827-L911
| 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,
73,
74
] | 88.235294 |
[
75,
77,
79,
80,
82,
84
] | 7.058824 | false | 53.535354 | 85 | 2 | 92.941176 | 69 |
def tau_sobol(dim_num):
dim_max = 13
tau_table = [0, 0, 1, 3, 5, 8, 11, 15, 19, 23, 27, 31, 35]
if 1 <= dim_num <= dim_max:
tau = tau_table[dim_num]
else:
tau = -1
return tau
| 844 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
main
|
(maxIter=200)
| 207 | 237 |
def main(maxIter=200):
print("Start " + __file__)
# ====Search Path with RRT====
obstacleList = [
(5, 5, 1),
(4, 6, 1),
(4, 7.5, 1),
(4, 9, 1),
(6, 5, 1),
(7, 5, 1)
] # [x,y,size]
# Set Initial parameters
start = [0.0, 0.0]
goal = [6.0, 7.0]
lqr_rrt_star = LQRRRTStar(start, goal,
obstacleList,
[-2.0, 15.0])
path = lqr_rrt_star.planning(animation=show_animation)
# Draw final path
if show_animation: # pragma: no cover
lqr_rrt_star.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()
print("Done")
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L207-L237
| 2 |
[
0,
1,
2,
3,
4,
13,
14,
15,
16,
17,
20,
21,
22,
29,
30
] | 60 |
[] | 0 | false | 80.769231 | 31 | 4 | 100 | 0 |
def main(maxIter=200):
print("Start " + __file__)
# ====Search Path with RRT====
obstacleList = [
(5, 5, 1),
(4, 6, 1),
(4, 7.5, 1),
(4, 9, 1),
(6, 5, 1),
(7, 5, 1)
] # [x,y,size]
# Set Initial parameters
start = [0.0, 0.0]
goal = [6.0, 7.0]
lqr_rrt_star = LQRRRTStar(start, goal,
obstacleList,
[-2.0, 15.0])
path = lqr_rrt_star.planning(animation=show_animation)
# Draw final path
if show_animation: # pragma: no cover
lqr_rrt_star.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()
print("Done")
| 845 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.__init__
|
(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
connect_circle_dist=50.0,
step_size=0.2,
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
| 28 | 59 |
def __init__(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
connect_circle_dist=50.0,
step_size=0.2,
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])
self.end = self.Node(goal[0], goal[1])
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.connect_circle_dist = connect_circle_dist
self.curvature = 1.0
self.goal_xy_th = 0.5
self.step_size = step_size
self.robot_radius = robot_radius
self.lqr_planner = LQRPlanner()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L28-L59
| 2 |
[
0,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31
] | 53.125 |
[] | 0 | false | 80.769231 | 32 | 1 | 100 | 7 |
def __init__(self, start, goal, obstacle_list, rand_area,
goal_sample_rate=10,
max_iter=200,
connect_circle_dist=50.0,
step_size=0.2,
robot_radius=0.0,
):
self.start = self.Node(start[0], start[1])
self.end = self.Node(goal[0], goal[1])
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.connect_circle_dist = connect_circle_dist
self.curvature = 1.0
self.goal_xy_th = 0.5
self.step_size = step_size
self.robot_radius = robot_radius
self.lqr_planner = LQRPlanner()
| 846 |
|
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.planning
|
(self, animation=True, search_until_max_iter=True)
|
return None
|
RRT Star planning
animation: flag for animation on or off
|
RRT Star planning
| 61 | 99 |
def planning(self, animation=True, search_until_max_iter=True):
"""
RRT Star 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):
near_indexes = self.find_near_nodes(new_node)
new_node = self.choose_parent(new_node, near_indexes)
if new_node:
self.node_list.append(new_node)
self.rewire(new_node, near_indexes)
if animation and i % 5 == 0:
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/LQRRRTStar/lqr_rrt_star.py#L61-L99
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
24,
25,
29,
30,
31,
32,
33,
34,
35
] | 82.051282 |
[
23,
26,
27,
28,
36,
38
] | 15.384615 | false | 80.769231 | 39 | 10 | 84.615385 | 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):
near_indexes = self.find_near_nodes(new_node)
new_node = self.choose_parent(new_node, near_indexes)
if new_node:
self.node_list.append(new_node)
self.rewire(new_node, near_indexes)
if animation and i % 5 == 0:
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
| 847 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.draw_graph
|
(self, rnd=None)
| 101 | 119 |
def draw_graph(self, rnd=None):
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)
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L101-L119
| 2 |
[
0
] | 5.263158 |
[
1,
3,
5,
6,
7,
8,
9,
11,
12,
14,
15,
16,
17,
18
] | 73.684211 | false | 80.769231 | 19 | 5 | 26.315789 | 0 |
def draw_graph(self, rnd=None):
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)
plt.pause(0.01)
| 848 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.search_best_goal_node
|
(self)
|
return None
| 121 | 133 |
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.goal_xy_th]
if not goal_inds:
return None
min_cost = min([self.node_list[i].cost for i in goal_inds])
for i in goal_inds:
if self.node_list[i].cost == min_cost:
return i
return None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L121-L133
| 2 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
11
] | 84.615385 |
[
5,
12
] | 15.384615 | false | 80.769231 | 13 | 7 | 84.615385 | 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.goal_xy_th]
if not goal_inds:
return None
min_cost = min([self.node_list[i].cost for i in goal_inds])
for i in goal_inds:
if self.node_list[i].cost == min_cost:
return i
return None
| 849 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.calc_new_cost
|
(self, from_node, to_node)
|
return from_node.cost + sum(course_lengths)
| 135 | 145 |
def calc_new_cost(self, from_node, to_node):
wx, wy = self.lqr_planner.lqr_planning(
from_node.x, from_node.y, to_node.x, to_node.y, show_animation=False)
px, py, course_lengths = self.sample_path(wx, wy, self.step_size)
if not course_lengths:
return float("inf")
return from_node.cost + sum(course_lengths)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L135-L145
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
9,
10
] | 81.818182 |
[
8
] | 9.090909 | false | 80.769231 | 11 | 2 | 90.909091 | 0 |
def calc_new_cost(self, from_node, to_node):
wx, wy = self.lqr_planner.lqr_planning(
from_node.x, from_node.y, to_node.x, to_node.y, show_animation=False)
px, py, course_lengths = self.sample_path(wx, wy, self.step_size)
if not course_lengths:
return float("inf")
return from_node.cost + sum(course_lengths)
| 850 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.get_random_node
|
(self)
|
return rnd
| 147 | 156 |
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)
)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L147-L156
| 2 |
[
0,
1,
2,
3,
7,
8,
9
] | 70 |
[] | 0 | false | 80.769231 | 10 | 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)
)
else: # goal point sampling
rnd = self.Node(self.end.x, self.end.y)
return rnd
| 851 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.generate_final_course
|
(self, goal_index)
|
return path
| 158 | 167 |
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/LQRRRTStar/lqr_rrt_star.py#L158-L167
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 80.769231 | 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
| 852 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.sample_path
|
(self, wx, wy, step)
|
return px, py, clen
| 169 | 184 |
def sample_path(self, wx, wy, step):
px, py, clen = [], [], []
for i in range(len(wx) - 1):
for t in np.arange(0.0, 1.0, step):
px.append(t * wx[i + 1] + (1.0 - t) * wx[i])
py.append(t * wy[i + 1] + (1.0 - t) * wy[i])
dx = np.diff(px)
dy = np.diff(py)
clen = [math.sqrt(idx ** 2 + idy ** 2) for (idx, idy) in zip(dx, dy)]
return px, py, clen
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L169-L184
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 80.769231 | 16 | 4 | 100 | 0 |
def sample_path(self, wx, wy, step):
px, py, clen = [], [], []
for i in range(len(wx) - 1):
for t in np.arange(0.0, 1.0, step):
px.append(t * wx[i + 1] + (1.0 - t) * wx[i])
py.append(t * wy[i + 1] + (1.0 - t) * wy[i])
dx = np.diff(px)
dy = np.diff(py)
clen = [math.sqrt(idx ** 2 + idy ** 2) for (idx, idy) in zip(dx, dy)]
return px, py, clen
| 853 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRRRTStar/lqr_rrt_star.py
|
LQRRRTStar.steer
|
(self, from_node, to_node)
|
return newNode
| 186 | 204 |
def steer(self, from_node, to_node):
wx, wy = self.lqr_planner.lqr_planning(
from_node.x, from_node.y, to_node.x, to_node.y, show_animation=False)
px, py, course_lens = self.sample_path(wx, wy, self.step_size)
if px is None:
return None
newNode = copy.deepcopy(from_node)
newNode.x = px[-1]
newNode.y = py[-1]
newNode.path_x = px
newNode.path_y = py
newNode.cost += sum([abs(c) for c in course_lens])
newNode.parent = from_node
return newNode
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRRRTStar/lqr_rrt_star.py#L186-L204
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
] | 89.473684 |
[
8
] | 5.263158 | false | 80.769231 | 19 | 3 | 94.736842 | 0 |
def steer(self, from_node, to_node):
wx, wy = self.lqr_planner.lqr_planning(
from_node.x, from_node.y, to_node.x, to_node.y, show_animation=False)
px, py, course_lens = self.sample_path(wx, wy, self.step_size)
if px is None:
return None
newNode = copy.deepcopy(from_node)
newNode.x = px[-1]
newNode.y = py[-1]
newNode.path_x = px
newNode.path_y = py
newNode.cost += sum([abs(c) for c in course_lens])
newNode.parent = from_node
return newNode
| 854 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
main
|
()
| 331 | 356 |
def main():
print("Start informed rrt star planning")
# create obstacles
obstacleList = [
(5, 5, 0.5),
(9, 6, 1),
(7, 5, 1),
(1, 5, 1),
(3, 6, 1),
(7, 9, 1)
]
# Set params
rrt = InformedRRTStar(start=[0, 0], goal=[5, 10],
randArea=[-2, 15], obstacleList=obstacleList)
path = rrt.informed_rrt_star_search(animation=show_animation)
print("Done!!")
# Plot path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01)
plt.show()
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L331-L356
| 2 |
[
0,
1,
2,
3,
4,
13,
14,
16,
17,
18,
19,
20
] | 46.153846 |
[
21,
22,
23,
24,
25
] | 19.230769 | false | 87.383178 | 26 | 4 | 80.769231 | 0 |
def main():
print("Start informed rrt star planning")
# create obstacles
obstacleList = [
(5, 5, 0.5),
(9, 6, 1),
(7, 5, 1),
(1, 5, 1),
(3, 6, 1),
(7, 9, 1)
]
# Set params
rrt = InformedRRTStar(start=[0, 0], goal=[5, 10],
randArea=[-2, 15], obstacleList=obstacleList)
path = rrt.informed_rrt_star_search(animation=show_animation)
print("Done!!")
# Plot path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
plt.grid(True)
plt.pause(0.01)
plt.show()
| 855 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.__init__
|
(self, start, goal,
obstacleList, randArea,
expandDis=0.5, goalSampleRate=10, maxIter=200)
| 30 | 42 |
def __init__(self, start, goal,
obstacleList, randArea,
expandDis=0.5, goalSampleRate=10, maxIter=200):
self.start = Node(start[0], start[1])
self.goal = Node(goal[0], goal[1])
self.min_rand = randArea[0]
self.max_rand = randArea[1]
self.expand_dis = expandDis
self.goal_sample_rate = goalSampleRate
self.max_iter = maxIter
self.obstacle_list = obstacleList
self.node_list = None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L30-L42
| 2 |
[
0,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 84.615385 |
[] | 0 | false | 87.383178 | 13 | 1 | 100 | 0 |
def __init__(self, start, goal,
obstacleList, randArea,
expandDis=0.5, goalSampleRate=10, maxIter=200):
self.start = Node(start[0], start[1])
self.goal = Node(goal[0], goal[1])
self.min_rand = randArea[0]
self.max_rand = randArea[1]
self.expand_dis = expandDis
self.goal_sample_rate = goalSampleRate
self.max_iter = maxIter
self.obstacle_list = obstacleList
self.node_list = None
| 856 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.informed_rrt_star_search
|
(self, animation=True)
|
return path
| 44 | 108 |
def informed_rrt_star_search(self, animation=True):
self.node_list = [self.start]
# max length we expect to find in our 'informed' sample space,
# starts as infinite
cBest = float('inf')
solutionSet = set()
path = None
# Computing the sampling space
cMin = math.sqrt(pow(self.start.x - self.goal.x, 2)
+ pow(self.start.y - self.goal.y, 2))
xCenter = np.array([[(self.start.x + self.goal.x) / 2.0],
[(self.start.y + self.goal.y) / 2.0], [0]])
a1 = np.array([[(self.goal.x - self.start.x) / cMin],
[(self.goal.y - self.start.y) / cMin], [0]])
e_theta = math.atan2(a1[1], a1[0])
# first column of identity matrix transposed
id1_t = np.array([1.0, 0.0, 0.0]).reshape(1, 3)
M = a1 @ id1_t
U, S, Vh = np.linalg.svd(M, True, True)
C = np.dot(np.dot(U, np.diag(
[1.0, 1.0, np.linalg.det(U) * np.linalg.det(np.transpose(Vh))])),
Vh)
for i in range(self.max_iter):
# Sample space is defined by cBest
# cMin is the minimum distance between the start point and the goal
# xCenter is the midpoint between the start and the goal
# cBest changes when a new path is found
rnd = self.informed_sample(cBest, cMin, xCenter, C)
n_ind = self.get_nearest_list_index(self.node_list, rnd)
nearestNode = self.node_list[n_ind]
# steer
theta = math.atan2(rnd[1] - nearestNode.y, rnd[0] - nearestNode.x)
newNode = self.get_new_node(theta, n_ind, nearestNode)
d = self.line_cost(nearestNode, newNode)
noCollision = self.check_collision(nearestNode, theta, d)
if noCollision:
nearInds = self.find_near_nodes(newNode)
newNode = self.choose_parent(newNode, nearInds)
self.node_list.append(newNode)
self.rewire(newNode, nearInds)
if self.is_near_goal(newNode):
if self.check_segment_collision(newNode.x, newNode.y,
self.goal.x, self.goal.y):
solutionSet.add(newNode)
lastIndex = len(self.node_list) - 1
tempPath = self.get_final_course(lastIndex)
tempPathLen = self.get_path_len(tempPath)
if tempPathLen < cBest:
path = tempPath
cBest = tempPathLen
if animation:
self.draw_graph(xCenter=xCenter,
cBest=cBest, cMin=cMin,
e_theta=e_theta, rnd=rnd)
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L44-L108
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
14,
16,
17,
18,
19,
20,
21,
22,
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,
52,
53,
54,
55,
56,
57,
58,
59,
63,
64
] | 86.153846 |
[
60
] | 1.538462 | false | 87.383178 | 65 | 7 | 98.461538 | 0 |
def informed_rrt_star_search(self, animation=True):
self.node_list = [self.start]
# max length we expect to find in our 'informed' sample space,
# starts as infinite
cBest = float('inf')
solutionSet = set()
path = None
# Computing the sampling space
cMin = math.sqrt(pow(self.start.x - self.goal.x, 2)
+ pow(self.start.y - self.goal.y, 2))
xCenter = np.array([[(self.start.x + self.goal.x) / 2.0],
[(self.start.y + self.goal.y) / 2.0], [0]])
a1 = np.array([[(self.goal.x - self.start.x) / cMin],
[(self.goal.y - self.start.y) / cMin], [0]])
e_theta = math.atan2(a1[1], a1[0])
# first column of identity matrix transposed
id1_t = np.array([1.0, 0.0, 0.0]).reshape(1, 3)
M = a1 @ id1_t
U, S, Vh = np.linalg.svd(M, True, True)
C = np.dot(np.dot(U, np.diag(
[1.0, 1.0, np.linalg.det(U) * np.linalg.det(np.transpose(Vh))])),
Vh)
for i in range(self.max_iter):
# Sample space is defined by cBest
# cMin is the minimum distance between the start point and the goal
# xCenter is the midpoint between the start and the goal
# cBest changes when a new path is found
rnd = self.informed_sample(cBest, cMin, xCenter, C)
n_ind = self.get_nearest_list_index(self.node_list, rnd)
nearestNode = self.node_list[n_ind]
# steer
theta = math.atan2(rnd[1] - nearestNode.y, rnd[0] - nearestNode.x)
newNode = self.get_new_node(theta, n_ind, nearestNode)
d = self.line_cost(nearestNode, newNode)
noCollision = self.check_collision(nearestNode, theta, d)
if noCollision:
nearInds = self.find_near_nodes(newNode)
newNode = self.choose_parent(newNode, nearInds)
self.node_list.append(newNode)
self.rewire(newNode, nearInds)
if self.is_near_goal(newNode):
if self.check_segment_collision(newNode.x, newNode.y,
self.goal.x, self.goal.y):
solutionSet.add(newNode)
lastIndex = len(self.node_list) - 1
tempPath = self.get_final_course(lastIndex)
tempPathLen = self.get_path_len(tempPath)
if tempPathLen < cBest:
path = tempPath
cBest = tempPathLen
if animation:
self.draw_graph(xCenter=xCenter,
cBest=cBest, cMin=cMin,
e_theta=e_theta, rnd=rnd)
return path
| 857 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.choose_parent
|
(self, newNode, nearInds)
|
return newNode
| 110 | 135 |
def choose_parent(self, newNode, nearInds):
if len(nearInds) == 0:
return newNode
dList = []
for i in nearInds:
dx = newNode.x - self.node_list[i].x
dy = newNode.y - self.node_list[i].y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
if self.check_collision(self.node_list[i], theta, d):
dList.append(self.node_list[i].cost + d)
else:
dList.append(float('inf'))
minCost = min(dList)
minInd = nearInds[dList.index(minCost)]
if minCost == float('inf'):
print("min cost is inf")
return newNode
newNode.cost = minCost
newNode.parent = minInd
return newNode
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L110-L135
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17,
18,
21,
22,
23,
24,
25
] | 88.461538 |
[
19,
20
] | 7.692308 | false | 87.383178 | 26 | 5 | 92.307692 | 0 |
def choose_parent(self, newNode, nearInds):
if len(nearInds) == 0:
return newNode
dList = []
for i in nearInds:
dx = newNode.x - self.node_list[i].x
dy = newNode.y - self.node_list[i].y
d = math.hypot(dx, dy)
theta = math.atan2(dy, dx)
if self.check_collision(self.node_list[i], theta, d):
dList.append(self.node_list[i].cost + d)
else:
dList.append(float('inf'))
minCost = min(dList)
minInd = nearInds[dList.index(minCost)]
if minCost == float('inf'):
print("min cost is inf")
return newNode
newNode.cost = minCost
newNode.parent = minInd
return newNode
| 858 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.find_near_nodes
|
(self, newNode)
|
return near_inds
| 137 | 143 |
def find_near_nodes(self, newNode):
n_node = len(self.node_list)
r = 50.0 * math.sqrt((math.log(n_node) / n_node))
d_list = [(node.x - newNode.x) ** 2 + (node.y - newNode.y) ** 2
for node in self.node_list]
near_inds = [d_list.index(i) for i in d_list if i <= r ** 2]
return near_inds
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L137-L143
| 2 |
[
0,
1,
2,
3,
5,
6
] | 85.714286 |
[] | 0 | false | 87.383178 | 7 | 3 | 100 | 0 |
def find_near_nodes(self, newNode):
n_node = len(self.node_list)
r = 50.0 * math.sqrt((math.log(n_node) / n_node))
d_list = [(node.x - newNode.x) ** 2 + (node.y - newNode.y) ** 2
for node in self.node_list]
near_inds = [d_list.index(i) for i in d_list if i <= r ** 2]
return near_inds
| 859 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.informed_sample
|
(self, cMax, cMin, xCenter, C)
|
return rnd
| 145 | 157 |
def informed_sample(self, cMax, cMin, xCenter, C):
if cMax < float('inf'):
r = [cMax / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0]
L = np.diag(r)
xBall = self.sample_unit_ball()
rnd = np.dot(np.dot(C, L), xBall) + xCenter
rnd = [rnd[(0, 0)], rnd[(1, 0)]]
else:
rnd = self.sample_free_space()
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L145-L157
| 2 |
[
0,
1,
2,
5,
6,
7,
8,
10,
11,
12
] | 76.923077 |
[] | 0 | false | 87.383178 | 13 | 2 | 100 | 0 |
def informed_sample(self, cMax, cMin, xCenter, C):
if cMax < float('inf'):
r = [cMax / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0,
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0]
L = np.diag(r)
xBall = self.sample_unit_ball()
rnd = np.dot(np.dot(C, L), xBall) + xCenter
rnd = [rnd[(0, 0)], rnd[(1, 0)]]
else:
rnd = self.sample_free_space()
return rnd
| 860 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.sample_unit_ball
|
()
|
return np.array([[sample[0]], [sample[1]], [0]])
| 160 | 169 |
def sample_unit_ball():
a = random.random()
b = random.random()
if b < a:
a, b = b, a
sample = (b * math.cos(2 * math.pi * a / b),
b * math.sin(2 * math.pi * a / b))
return np.array([[sample[0]], [sample[1]], [0]])
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L160-L169
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
9
] | 90 |
[] | 0 | false | 87.383178 | 10 | 2 | 100 | 0 |
def sample_unit_ball():
a = random.random()
b = random.random()
if b < a:
a, b = b, a
sample = (b * math.cos(2 * math.pi * a / b),
b * math.sin(2 * math.pi * a / b))
return np.array([[sample[0]], [sample[1]], [0]])
| 861 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.sample_free_space
|
(self)
|
return rnd
| 171 | 178 |
def sample_free_space(self):
if random.randint(0, 100) > self.goal_sample_rate:
rnd = [random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand)]
else:
rnd = [self.goal.x, self.goal.y]
return rnd
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L171-L178
| 2 |
[
0,
1,
2,
5,
6,
7
] | 75 |
[] | 0 | false | 87.383178 | 8 | 2 | 100 | 0 |
def sample_free_space(self):
if random.randint(0, 100) > self.goal_sample_rate:
rnd = [random.uniform(self.min_rand, self.max_rand),
random.uniform(self.min_rand, self.max_rand)]
else:
rnd = [self.goal.x, self.goal.y]
return rnd
| 862 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.get_path_len
|
(path)
|
return pathLen
| 181 | 191 |
def get_path_len(path):
pathLen = 0
for i in range(1, len(path)):
node1_x = path[i][0]
node1_y = path[i][1]
node2_x = path[i - 1][0]
node2_y = path[i - 1][1]
pathLen += math.sqrt((node1_x - node2_x)
** 2 + (node1_y - node2_y) ** 2)
return pathLen
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L181-L191
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
9,
10
] | 90.909091 |
[] | 0 | false | 87.383178 | 11 | 2 | 100 | 0 |
def get_path_len(path):
pathLen = 0
for i in range(1, len(path)):
node1_x = path[i][0]
node1_y = path[i][1]
node2_x = path[i - 1][0]
node2_y = path[i - 1][1]
pathLen += math.sqrt((node1_x - node2_x)
** 2 + (node1_y - node2_y) ** 2)
return pathLen
| 863 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.line_cost
|
(node1, node2)
|
return math.sqrt((node1.x - node2.x) ** 2 + (node1.y - node2.y) ** 2)
| 194 | 195 |
def line_cost(node1, node2):
return math.sqrt((node1.x - node2.x) ** 2 + (node1.y - node2.y) ** 2)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L194-L195
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 87.383178 | 2 | 1 | 100 | 0 |
def line_cost(node1, node2):
return math.sqrt((node1.x - node2.x) ** 2 + (node1.y - node2.y) ** 2)
| 864 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.get_nearest_list_index
|
(nodes, rnd)
|
return minIndex
| 198 | 202 |
def get_nearest_list_index(nodes, rnd):
dList = [(node.x - rnd[0]) ** 2
+ (node.y - rnd[1]) ** 2 for node in nodes]
minIndex = dList.index(min(dList))
return minIndex
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L198-L202
| 2 |
[
0,
1,
3,
4
] | 80 |
[] | 0 | false | 87.383178 | 5 | 2 | 100 | 0 |
def get_nearest_list_index(nodes, rnd):
dList = [(node.x - rnd[0]) ** 2
+ (node.y - rnd[1]) ** 2 for node in nodes]
minIndex = dList.index(min(dList))
return minIndex
| 865 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.get_new_node
|
(self, theta, n_ind, nearestNode)
|
return newNode
| 204 | 212 |
def get_new_node(self, theta, n_ind, nearestNode):
newNode = copy.deepcopy(nearestNode)
newNode.x += self.expand_dis * math.cos(theta)
newNode.y += self.expand_dis * math.sin(theta)
newNode.cost += self.expand_dis
newNode.parent = n_ind
return newNode
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L204-L212
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 87.383178 | 9 | 1 | 100 | 0 |
def get_new_node(self, theta, n_ind, nearestNode):
newNode = copy.deepcopy(nearestNode)
newNode.x += self.expand_dis * math.cos(theta)
newNode.y += self.expand_dis * math.sin(theta)
newNode.cost += self.expand_dis
newNode.parent = n_ind
return newNode
| 866 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.is_near_goal
|
(self, node)
|
return False
| 214 | 218 |
def is_near_goal(self, node):
d = self.line_cost(node, self.goal)
if d < self.expand_dis:
return True
return False
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L214-L218
| 2 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 87.383178 | 5 | 2 | 100 | 0 |
def is_near_goal(self, node):
d = self.line_cost(node, self.goal)
if d < self.expand_dis:
return True
return False
| 867 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.rewire
|
(self, newNode, nearInds)
| 220 | 235 |
def rewire(self, newNode, nearInds):
n_node = len(self.node_list)
for i in nearInds:
nearNode = self.node_list[i]
d = math.sqrt((nearNode.x - newNode.x) ** 2
+ (nearNode.y - newNode.y) ** 2)
s_cost = newNode.cost + d
if nearNode.cost > s_cost:
theta = math.atan2(newNode.y - nearNode.y,
newNode.x - nearNode.x)
if self.check_collision(nearNode, theta, d):
nearNode.parent = n_node - 1
nearNode.cost = s_cost
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L220-L235
| 2 |
[
0,
1,
2,
3,
4,
5,
7,
8,
9,
10,
11,
13,
14,
15
] | 87.5 |
[] | 0 | false | 87.383178 | 16 | 4 | 100 | 0 |
def rewire(self, newNode, nearInds):
n_node = len(self.node_list)
for i in nearInds:
nearNode = self.node_list[i]
d = math.sqrt((nearNode.x - newNode.x) ** 2
+ (nearNode.y - newNode.y) ** 2)
s_cost = newNode.cost + d
if nearNode.cost > s_cost:
theta = math.atan2(newNode.y - nearNode.y,
newNode.x - nearNode.x)
if self.check_collision(nearNode, theta, d):
nearNode.parent = n_node - 1
nearNode.cost = s_cost
| 868 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.distance_squared_point_to_segment
|
(v, w, p)
|
return (p - projection).dot(p - projection)
| 238 | 250 |
def distance_squared_point_to_segment(v, w, p):
# Return minimum distance between line segment vw and point p
if np.array_equal(v, w):
return (p - v).dot(p - v) # v == w case
l2 = (w - v).dot(w - v) # i.e. |w-v|^2 - avoid a sqrt
# Consider the line extending the segment,
# parameterized as v + t (w - v).
# We find projection of point p onto the line.
# It falls where t = [(p-v) . (w-v)] / |w-v|^2
# We clamp t from [0,1] to handle points outside the segment vw.
t = max(0, min(1, (p - v).dot(w - v) / l2))
projection = v + t * (w - v) # Projection falls on the segment
return (p - projection).dot(p - projection)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L238-L250
| 2 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 92.307692 |
[
3
] | 7.692308 | false | 87.383178 | 13 | 2 | 92.307692 | 0 |
def distance_squared_point_to_segment(v, w, p):
# Return minimum distance between line segment vw and point p
if np.array_equal(v, w):
return (p - v).dot(p - v) # v == w case
l2 = (w - v).dot(w - v) # i.e. |w-v|^2 - avoid a sqrt
# Consider the line extending the segment,
# parameterized as v + t (w - v).
# We find projection of point p onto the line.
# It falls where t = [(p-v) . (w-v)] / |w-v|^2
# We clamp t from [0,1] to handle points outside the segment vw.
t = max(0, min(1, (p - v).dot(w - v) / l2))
projection = v + t * (w - v) # Projection falls on the segment
return (p - projection).dot(p - projection)
| 869 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.check_segment_collision
|
(self, x1, y1, x2, y2)
|
return True
| 252 | 260 |
def check_segment_collision(self, x1, y1, x2, y2):
for (ox, oy, size) in self.obstacle_list:
dd = self.distance_squared_point_to_segment(
np.array([x1, y1]),
np.array([x2, y2]),
np.array([ox, oy]))
if dd <= size ** 2:
return False # collision
return True
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L252-L260
| 2 |
[
0,
1,
2,
6,
7,
8
] | 66.666667 |
[] | 0 | false | 87.383178 | 9 | 3 | 100 | 0 |
def check_segment_collision(self, x1, y1, x2, y2):
for (ox, oy, size) in self.obstacle_list:
dd = self.distance_squared_point_to_segment(
np.array([x1, y1]),
np.array([x2, y2]),
np.array([ox, oy]))
if dd <= size ** 2:
return False # collision
return True
| 870 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.check_collision
|
(self, nearNode, theta, d)
|
return self.check_segment_collision(tmpNode.x, tmpNode.y, end_x, end_y)
| 262 | 266 |
def check_collision(self, nearNode, theta, d):
tmpNode = copy.deepcopy(nearNode)
end_x = tmpNode.x + math.cos(theta) * d
end_y = tmpNode.y + math.sin(theta) * d
return self.check_segment_collision(tmpNode.x, tmpNode.y, end_x, end_y)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L262-L266
| 2 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 87.383178 | 5 | 1 | 100 | 0 |
def check_collision(self, nearNode, theta, d):
tmpNode = copy.deepcopy(nearNode)
end_x = tmpNode.x + math.cos(theta) * d
end_y = tmpNode.y + math.sin(theta) * d
return self.check_segment_collision(tmpNode.x, tmpNode.y, end_x, end_y)
| 871 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.get_final_course
|
(self, lastIndex)
|
return path
| 268 | 275 |
def get_final_course(self, lastIndex):
path = [[self.goal.x, self.goal.y]]
while self.node_list[lastIndex].parent is not None:
node = self.node_list[lastIndex]
path.append([node.x, node.y])
lastIndex = node.parent
path.append([self.start.x, self.start.y])
return path
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L268-L275
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 87.383178 | 8 | 2 | 100 | 0 |
def get_final_course(self, lastIndex):
path = [[self.goal.x, self.goal.y]]
while self.node_list[lastIndex].parent is not None:
node = self.node_list[lastIndex]
path.append([node.x, node.y])
lastIndex = node.parent
path.append([self.start.x, self.start.y])
return path
| 872 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.draw_graph
|
(self, xCenter=None, cBest=None, cMin=None, e_theta=None,
rnd=None)
| 277 | 302 |
def draw_graph(self, xCenter=None, cBest=None, cMin=None, e_theta=None,
rnd=None):
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[0], rnd[1], "^k")
if cBest != float('inf'):
self.plot_ellipse(xCenter, cBest, cMin, e_theta)
for node in self.node_list:
if node.parent is not None:
if node.x or node.y is not None:
plt.plot([node.x, self.node_list[node.parent].x], [
node.y, self.node_list[node.parent].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.goal.x, self.goal.y, "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L277-L302
| 2 |
[
0
] | 3.846154 |
[
2,
4,
7,
8,
9,
10,
12,
13,
14,
15,
18,
19,
21,
22,
23,
24,
25
] | 65.384615 | false | 87.383178 | 26 | 8 | 34.615385 | 0 |
def draw_graph(self, xCenter=None, cBest=None, cMin=None, e_theta=None,
rnd=None):
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[0], rnd[1], "^k")
if cBest != float('inf'):
self.plot_ellipse(xCenter, cBest, cMin, e_theta)
for node in self.node_list:
if node.parent is not None:
if node.x or node.y is not None:
plt.plot([node.x, self.node_list[node.parent].x], [
node.y, self.node_list[node.parent].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.goal.x, self.goal.y, "xr")
plt.axis([-2, 15, -2, 15])
plt.grid(True)
plt.pause(0.01)
| 873 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
InformedRRTStar.plot_ellipse
|
(xCenter, cBest, cMin, e_theta)
| 305 | 319 |
def plot_ellipse(xCenter, cBest, cMin, e_theta): # pragma: no cover
a = math.sqrt(cBest ** 2 - cMin ** 2) / 2.0
b = cBest / 2.0
angle = math.pi / 2.0 - e_theta
cx = xCenter[0]
cy = xCenter[1]
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
x = [a * math.cos(it) for it in t]
y = [b * math.sin(it) for it in t]
fx = rot_mat_2d(-angle) @ np.array([x, y])
px = np.array(fx[0, :] + cx).flatten()
py = np.array(fx[1, :] + cy).flatten()
plt.plot(cx, cy, "xc")
plt.plot(px, py, "--c")
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L305-L319
| 2 |
[] | 0 |
[] | 0 | false | 87.383178 | 15 | 3 | 100 | 0 |
def plot_ellipse(xCenter, cBest, cMin, e_theta): # pragma: no cover
a = math.sqrt(cBest ** 2 - cMin ** 2) / 2.0
b = cBest / 2.0
angle = math.pi / 2.0 - e_theta
cx = xCenter[0]
cy = xCenter[1]
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
x = [a * math.cos(it) for it in t]
y = [b * math.sin(it) for it in t]
fx = rot_mat_2d(-angle) @ np.array([x, y])
px = np.array(fx[0, :] + cx).flatten()
py = np.array(fx[1, :] + cy).flatten()
plt.plot(cx, cy, "xc")
plt.plot(px, py, "--c")
| 874 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/InformedRRTStar/informed_rrt_star.py
|
Node.__init__
|
(self, x, y)
| 324 | 328 |
def __init__(self, x, y):
self.x = x
self.y = y
self.cost = 0.0
self.parent = None
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/InformedRRTStar/informed_rrt_star.py#L324-L328
| 2 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 87.383178 | 5 | 1 | 100 | 0 |
def __init__(self, x, y):
self.x = x
self.y = y
self.cost = 0.0
self.parent = None
| 875 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
main
|
()
| 121 | 142 |
def main():
print(__file__ + " start!!")
ntest = 10 # number of goal
area = 100.0 # sampling area
lqr_planner = LQRPlanner()
for i in range(ntest):
sx = 6.0
sy = 6.0
gx = random.uniform(-area, area)
gy = random.uniform(-area, area)
rx, ry = lqr_planner.lqr_planning(sx, sy, gx, gy, show_animation=SHOW_ANIMATION)
if SHOW_ANIMATION: # pragma: no cover
plt.plot(sx, sy, "or")
plt.plot(gx, gy, "ob")
plt.plot(rx, ry, "-r")
plt.axis("equal")
plt.pause(1.0)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L121-L142
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 95.522388 | 22 | 3 | 100 | 0 |
def main():
print(__file__ + " start!!")
ntest = 10 # number of goal
area = 100.0 # sampling area
lqr_planner = LQRPlanner()
for i in range(ntest):
sx = 6.0
sy = 6.0
gx = random.uniform(-area, area)
gy = random.uniform(-area, area)
rx, ry = lqr_planner.lqr_planning(sx, sy, gx, gy, show_animation=SHOW_ANIMATION)
if SHOW_ANIMATION: # pragma: no cover
plt.plot(sx, sy, "or")
plt.plot(gx, gy, "ob")
plt.plot(rx, ry, "-r")
plt.axis("equal")
plt.pause(1.0)
| 876 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.__init__
|
(self)
| 21 | 26 |
def __init__(self):
self.MAX_TIME = 100.0 # Maximum simulation time
self.DT = 0.1 # Time tick
self.GOAL_DIST = 0.1
self.MAX_ITER = 150
self.EPS = 0.01
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L21-L26
| 2 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 95.522388 | 6 | 1 | 100 | 0 |
def __init__(self):
self.MAX_TIME = 100.0 # Maximum simulation time
self.DT = 0.1 # Time tick
self.GOAL_DIST = 0.1
self.MAX_ITER = 150
self.EPS = 0.01
| 877 |
|||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.lqr_planning
|
(self, sx, sy, gx, gy, show_animation=True)
|
return rx, ry
| 28 | 70 |
def lqr_planning(self, sx, sy, gx, gy, show_animation=True):
rx, ry = [sx], [sy]
x = np.array([sx - gx, sy - gy]).reshape(2, 1) # State vector
# Linear system model
A, B = self.get_system_model()
found_path = False
time = 0.0
while time <= self.MAX_TIME:
time += self.DT
u = self.lqr_control(A, B, x)
x = A @ x + B @ u
rx.append(x[0, 0] + gx)
ry.append(x[1, 0] + gy)
d = math.sqrt((gx - rx[-1]) ** 2 + (gy - ry[-1]) ** 2)
if d <= self.GOAL_DIST:
found_path = True
break
# animation
if show_animation: # pragma: no cover
# 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.plot(sx, sy, "or")
plt.plot(gx, gy, "ob")
plt.plot(rx, ry, "-r")
plt.axis("equal")
plt.pause(1.0)
if not found_path:
print("Cannot found path")
return [], []
return rx, ry
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L28-L70
| 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,
37,
38,
41,
42
] | 88.888889 |
[
39,
40
] | 5.555556 | false | 95.522388 | 43 | 5 | 94.444444 | 0 |
def lqr_planning(self, sx, sy, gx, gy, show_animation=True):
rx, ry = [sx], [sy]
x = np.array([sx - gx, sy - gy]).reshape(2, 1) # State vector
# Linear system model
A, B = self.get_system_model()
found_path = False
time = 0.0
while time <= self.MAX_TIME:
time += self.DT
u = self.lqr_control(A, B, x)
x = A @ x + B @ u
rx.append(x[0, 0] + gx)
ry.append(x[1, 0] + gy)
d = math.sqrt((gx - rx[-1]) ** 2 + (gy - ry[-1]) ** 2)
if d <= self.GOAL_DIST:
found_path = True
break
# animation
if show_animation: # pragma: no cover
# 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.plot(sx, sy, "or")
plt.plot(gx, gy, "ob")
plt.plot(rx, ry, "-r")
plt.axis("equal")
plt.pause(1.0)
if not found_path:
print("Cannot found path")
return [], []
return rx, ry
| 878 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.solve_dare
|
(self, A, B, Q, R)
|
return Xn
|
solve a discrete time_Algebraic Riccati equation (DARE)
|
solve a discrete time_Algebraic Riccati equation (DARE)
| 72 | 85 |
def solve_dare(self, A, B, Q, R):
"""
solve a discrete time_Algebraic Riccati equation (DARE)
"""
X, Xn = Q, Q
for i in range(self.MAX_ITER):
Xn = A.T * X * A - A.T * X * B * \
la.inv(R + B.T * X * B) * B.T * X * A + Q
if (abs(Xn - X)).max() < self.EPS:
break
X = Xn
return Xn
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L72-L85
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 95.522388 | 14 | 3 | 100 | 1 |
def solve_dare(self, A, B, Q, R):
X, Xn = Q, Q
for i in range(self.MAX_ITER):
Xn = A.T * X * A - A.T * X * B * \
la.inv(R + B.T * X * B) * B.T * X * A + Q
if (abs(Xn - X)).max() < self.EPS:
break
X = Xn
return Xn
| 879 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.dlqr
|
(self, A, B, Q, R)
|
return K, X, eigValues
|
Solve the discrete time lqr controller.
x[k+1] = A x[k] + B u[k]
cost = sum x[k].T*Q*x[k] + u[k].T*R*u[k]
# ref Bertsekas, p.151
|
Solve the discrete time lqr controller.
x[k+1] = A x[k] + B u[k]
cost = sum x[k].T*Q*x[k] + u[k].T*R*u[k]
# ref Bertsekas, p.151
| 87 | 102 |
def dlqr(self, A, B, Q, R):
"""Solve the discrete time lqr controller.
x[k+1] = A x[k] + B u[k]
cost = sum x[k].T*Q*x[k] + u[k].T*R*u[k]
# ref Bertsekas, p.151
"""
# first, try to solve the ricatti equation
X = self.solve_dare(A, B, Q, R)
# compute the LQR gain
K = la.inv(B.T @ X @ B + R) @ (B.T @ X @ A)
eigValues = la.eigvals(A - B @ K)
return K, X, eigValues
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L87-L102
| 2 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 95.522388 | 16 | 1 | 100 | 4 |
def dlqr(self, A, B, Q, R):
# first, try to solve the ricatti equation
X = self.solve_dare(A, B, Q, R)
# compute the LQR gain
K = la.inv(B.T @ X @ B + R) @ (B.T @ X @ A)
eigValues = la.eigvals(A - B @ K)
return K, X, eigValues
| 880 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.get_system_model
|
(self)
|
return A, B
| 104 | 110 |
def get_system_model(self):
A = np.array([[self.DT, 1.0],
[0.0, self.DT]])
B = np.array([0.0, 1.0]).reshape(2, 1)
return A, B
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L104-L110
| 2 |
[
0,
1,
2,
4,
5,
6
] | 85.714286 |
[] | 0 | false | 95.522388 | 7 | 1 | 100 | 0 |
def get_system_model(self):
A = np.array([[self.DT, 1.0],
[0.0, self.DT]])
B = np.array([0.0, 1.0]).reshape(2, 1)
return A, B
| 881 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/LQRPlanner/lqr_planner.py
|
LQRPlanner.lqr_control
|
(self, A, B, x)
|
return u
| 112 | 118 |
def lqr_control(self, A, B, x):
Kopt, X, ev = self.dlqr(A, B, np.eye(2), np.eye(1))
u = -Kopt @ x
return u
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/LQRPlanner/lqr_planner.py#L112-L118
| 2 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 95.522388 | 7 | 1 | 100 | 0 |
def lqr_control(self, A, B, x):
Kopt, X, ev = self.dlqr(A, B, np.eye(2), np.eye(1))
u = -Kopt @ x
return u
| 882 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
generate_clothoid_paths
|
(start_point, start_yaw_list,
goal_point, goal_yaw_list,
n_path_points)
|
return clothoids
|
Generate clothoid path list. This function generate multiple clothoid paths
from multiple orientations(yaw) at start points to multiple orientations
(yaw) at goal point.
:param start_point: Start point of the path
:param start_yaw_list: Orientation list at start point in radian
:param goal_point: Goal point of the path
:param goal_yaw_list: Orientation list at goal point in radian
:param n_path_points: number of path points
:return: clothoid path list
|
Generate clothoid path list. This function generate multiple clothoid paths
from multiple orientations(yaw) at start points to multiple orientations
(yaw) at goal point.
| 22 | 44 |
def generate_clothoid_paths(start_point, start_yaw_list,
goal_point, goal_yaw_list,
n_path_points):
"""
Generate clothoid path list. This function generate multiple clothoid paths
from multiple orientations(yaw) at start points to multiple orientations
(yaw) at goal point.
:param start_point: Start point of the path
:param start_yaw_list: Orientation list at start point in radian
:param goal_point: Goal point of the path
:param goal_yaw_list: Orientation list at goal point in radian
:param n_path_points: number of path points
:return: clothoid path list
"""
clothoids = []
for start_yaw in start_yaw_list:
for goal_yaw in goal_yaw_list:
clothoid = generate_clothoid_path(start_point, start_yaw,
goal_point, goal_yaw,
n_path_points)
clothoids.append(clothoid)
return clothoids
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L22-L44
| 2 |
[
0,
14,
15,
16,
17,
18,
19,
20,
21,
22
] | 43.478261 |
[] | 0 | false | 63.265306 | 23 | 3 | 100 | 10 |
def generate_clothoid_paths(start_point, start_yaw_list,
goal_point, goal_yaw_list,
n_path_points):
clothoids = []
for start_yaw in start_yaw_list:
for goal_yaw in goal_yaw_list:
clothoid = generate_clothoid_path(start_point, start_yaw,
goal_point, goal_yaw,
n_path_points)
clothoids.append(clothoid)
return clothoids
| 883 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
generate_clothoid_path
|
(start_point, start_yaw,
goal_point, goal_yaw, n_path_points)
|
return points
|
Generate a clothoid path list.
:param start_point: Start point of the path
:param start_yaw: Orientation at start point in radian
:param goal_point: Goal point of the path
:param goal_yaw: Orientation at goal point in radian
:param n_path_points: number of path points
:return: a clothoid path
|
Generate a clothoid path list.
| 47 | 92 |
def generate_clothoid_path(start_point, start_yaw,
goal_point, goal_yaw, n_path_points):
"""
Generate a clothoid path list.
:param start_point: Start point of the path
:param start_yaw: Orientation at start point in radian
:param goal_point: Goal point of the path
:param goal_yaw: Orientation at goal point in radian
:param n_path_points: number of path points
:return: a clothoid path
"""
dx = goal_point.x - start_point.x
dy = goal_point.y - start_point.y
r = hypot(dx, dy)
phi = atan2(dy, dx)
phi1 = normalize_angle(start_yaw - phi)
phi2 = normalize_angle(goal_yaw - phi)
delta = phi2 - phi1
try:
# Step1: Solve g function
A = solve_g_for_root(phi1, phi2, delta)
# Step2: Calculate path parameters
L = compute_path_length(r, phi1, delta, A)
curvature = compute_curvature(delta, A, L)
curvature_rate = compute_curvature_rate(A, L)
except Exception as e:
print(f"Failed to generate clothoid points: {e}")
return None
# Step3: Construct a path with Fresnel integral
points = []
for s in np.linspace(0, L, n_path_points):
try:
x = start_point.x + s * X(curvature_rate * s ** 2, curvature * s,
start_yaw)
y = start_point.y + s * Y(curvature_rate * s ** 2, curvature * s,
start_yaw)
points.append(Point(x, y))
except Exception as e:
print(f"Skipping failed clothoid point: {e}")
return points
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L47-L92
| 2 |
[
0,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
33,
34,
35,
36,
37,
38,
39,
40,
41,
44,
45
] | 65.217391 |
[
29,
30,
31,
42,
43
] | 10.869565 | false | 63.265306 | 46 | 4 | 89.130435 | 8 |
def generate_clothoid_path(start_point, start_yaw,
goal_point, goal_yaw, n_path_points):
dx = goal_point.x - start_point.x
dy = goal_point.y - start_point.y
r = hypot(dx, dy)
phi = atan2(dy, dx)
phi1 = normalize_angle(start_yaw - phi)
phi2 = normalize_angle(goal_yaw - phi)
delta = phi2 - phi1
try:
# Step1: Solve g function
A = solve_g_for_root(phi1, phi2, delta)
# Step2: Calculate path parameters
L = compute_path_length(r, phi1, delta, A)
curvature = compute_curvature(delta, A, L)
curvature_rate = compute_curvature_rate(A, L)
except Exception as e:
print(f"Failed to generate clothoid points: {e}")
return None
# Step3: Construct a path with Fresnel integral
points = []
for s in np.linspace(0, L, n_path_points):
try:
x = start_point.x + s * X(curvature_rate * s ** 2, curvature * s,
start_yaw)
y = start_point.y + s * Y(curvature_rate * s ** 2, curvature * s,
start_yaw)
points.append(Point(x, y))
except Exception as e:
print(f"Skipping failed clothoid point: {e}")
return points
| 884 |
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
X
|
(a, b, c)
|
return integrate.quad(lambda t: cos((a/2)*t**2 + b*t + c), 0, 1)[0]
| 95 | 96 |
def X(a, b, c):
return integrate.quad(lambda t: cos((a/2)*t**2 + b*t + c), 0, 1)[0]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L95-L96
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def X(a, b, c):
return integrate.quad(lambda t: cos((a/2)*t**2 + b*t + c), 0, 1)[0]
| 885 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
Y
|
(a, b, c)
|
return integrate.quad(lambda t: sin((a/2)*t**2 + b*t + c), 0, 1)[0]
| 99 | 100 |
def Y(a, b, c):
return integrate.quad(lambda t: sin((a/2)*t**2 + b*t + c), 0, 1)[0]
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L99-L100
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def Y(a, b, c):
return integrate.quad(lambda t: sin((a/2)*t**2 + b*t + c), 0, 1)[0]
| 886 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
solve_g_for_root
|
(theta1, theta2, delta)
|
return fsolve(lambda A: Y(2*A, delta - A, theta1), [initial_guess])
| 103 | 105 |
def solve_g_for_root(theta1, theta2, delta):
initial_guess = 3*(theta1 + theta2)
return fsolve(lambda A: Y(2*A, delta - A, theta1), [initial_guess])
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L103-L105
| 2 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 63.265306 | 3 | 1 | 100 | 0 |
def solve_g_for_root(theta1, theta2, delta):
initial_guess = 3*(theta1 + theta2)
return fsolve(lambda A: Y(2*A, delta - A, theta1), [initial_guess])
| 887 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
compute_path_length
|
(r, theta1, delta, A)
|
return r / X(2*A, delta - A, theta1)
| 108 | 109 |
def compute_path_length(r, theta1, delta, A):
return r / X(2*A, delta - A, theta1)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L108-L109
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def compute_path_length(r, theta1, delta, A):
return r / X(2*A, delta - A, theta1)
| 888 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
compute_curvature
|
(delta, A, L)
|
return (delta - A) / L
| 112 | 113 |
def compute_curvature(delta, A, L):
return (delta - A) / L
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L112-L113
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def compute_curvature(delta, A, L):
return (delta - A) / L
| 889 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
compute_curvature_rate
|
(A, L)
|
return 2 * A / (L**2)
| 116 | 117 |
def compute_curvature_rate(A, L):
return 2 * A / (L**2)
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L116-L117
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def compute_curvature_rate(A, L):
return 2 * A / (L**2)
| 890 |
||
AtsushiSakai/PythonRobotics
|
15ab19688b2f6c03ee91a853f1f8cc9def84d162
|
PathPlanning/ClothoidPath/clothoid_path_planner.py
|
normalize_angle
|
(angle_rad)
|
return (angle_rad + pi) % (2 * pi) - pi
| 120 | 121 |
def normalize_angle(angle_rad):
return (angle_rad + pi) % (2 * pi) - pi
|
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClothoidPath/clothoid_path_planner.py#L120-L121
| 2 |
[
0,
1
] | 100 |
[] | 0 | true | 63.265306 | 2 | 1 | 100 | 0 |
def normalize_angle(angle_rad):
return (angle_rad + pi) % (2 * pi) - pi
| 891 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.