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/RRTStarDubins/rrt_star_dubins.py
RRTStarDubins.calc_new_cost
(self, from_node, to_node)
return from_node.cost + cost
158
166
def calc_new_cost(self, from_node, to_node): _, _, _, _, course_lengths = dubins_path_planner.plan_dubins_path( from_node.x, from_node.y, from_node.yaw, to_node.x, to_node.y, to_node.yaw, self.curvature) cost = sum([abs(c) for c in course_lengths]) return from_node.cost + cost
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStarDubins/rrt_star_dubins.py#L158-L166
2
[ 0, 1, 2, 5, 6, 7, 8 ]
77.777778
[]
0
false
80
9
2
100
0
def calc_new_cost(self, from_node, to_node): _, _, _, _, course_lengths = dubins_path_planner.plan_dubins_path( from_node.x, from_node.y, from_node.yaw, to_node.x, to_node.y, to_node.yaw, self.curvature) cost = sum([abs(c) for c in course_lengths]) return from_node.cost + cost
997
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/RRTStarDubins/rrt_star_dubins.py
RRTStarDubins.get_random_node
(self)
return rnd
168
178
def get_random_node(self): if random.randint(0, 100) > self.goal_sample_rate: rnd = self.Node(random.uniform(self.min_rand, self.max_rand), random.uniform(self.min_rand, self.max_rand), random.uniform(-math.pi, math.pi) ) else: # goal point sampling rnd = self.Node(self.end.x, self.end.y, self.end.yaw) return rnd
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStarDubins/rrt_star_dubins.py#L168-L178
2
[ 0, 1, 2, 3, 8, 9, 10 ]
63.636364
[]
0
false
80
11
2
100
0
def get_random_node(self): if random.randint(0, 100) > self.goal_sample_rate: rnd = self.Node(random.uniform(self.min_rand, self.max_rand), random.uniform(self.min_rand, self.max_rand), random.uniform(-math.pi, math.pi) ) else: # goal point sampling rnd = self.Node(self.end.x, self.end.y, self.end.yaw) return rnd
998
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/RRTStarDubins/rrt_star_dubins.py
RRTStarDubins.search_best_goal_node
(self)
return None
180
201
def search_best_goal_node(self): goal_indexes = [] for (i, node) in enumerate(self.node_list): if self.calc_dist_to_goal(node.x, node.y) <= self.goal_xy_th: goal_indexes.append(i) # angle check final_goal_indexes = [] for i in goal_indexes: if abs(self.node_list[i].yaw - self.end.yaw) <= self.goal_yaw_th: final_goal_indexes.append(i) if not final_goal_indexes: return None min_cost = min([self.node_list[i].cost for i in final_goal_indexes]) for i in final_goal_indexes: if self.node_list[i].cost == min_cost: return i return None
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/RRTStarDubins/rrt_star_dubins.py#L180-L201
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20 ]
90.909091
[ 14, 21 ]
9.090909
false
80
22
9
90.909091
0
def search_best_goal_node(self): goal_indexes = [] for (i, node) in enumerate(self.node_list): if self.calc_dist_to_goal(node.x, node.y) <= self.goal_xy_th: goal_indexes.append(i) # angle check final_goal_indexes = [] for i in goal_indexes: if abs(self.node_list[i].yaw - self.end.yaw) <= self.goal_yaw_th: final_goal_indexes.append(i) if not final_goal_indexes: return None min_cost = min([self.node_list[i].cost for i in final_goal_indexes]) for i in final_goal_indexes: if self.node_list[i].cost == min_cost: return i return None
999
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/RRTStarDubins/rrt_star_dubins.py
RRTStarDubins.generate_final_course
(self, goal_index)
return path
203
212
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/RRTStarDubins/rrt_star_dubins.py#L203-L212
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
80
10
3
100
0
def generate_final_course(self, goal_index): print("final") path = [[self.end.x, self.end.y]] node = self.node_list[goal_index] while node.parent: for (ix, iy) in zip(reversed(node.path_x), reversed(node.path_y)): path.append([ix, iy]) node = node.parent path.append([self.start.x, self.start.y]) return path
1,000
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
calc_spline_course
(x, y, ds=0.1)
return rx, ry, ryaw, rk, s
311
323
def calc_spline_course(x, y, ds=0.1): sp = CubicSpline2D(x, y) s = list(np.arange(0, sp.s[-1], ds)) rx, ry, ryaw, rk = [], [], [], [] for i_s in s: ix, iy = sp.calc_position(i_s) rx.append(ix) ry.append(iy) ryaw.append(sp.calc_yaw(i_s)) rk.append(sp.calc_curvature(i_s)) return rx, ry, ryaw, rk, s
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L311-L323
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
84.166667
13
2
100
0
def calc_spline_course(x, y, ds=0.1): sp = CubicSpline2D(x, y) s = list(np.arange(0, sp.s[-1], ds)) rx, ry, ryaw, rk = [], [], [], [] for i_s in s: ix, iy = sp.calc_position(i_s) rx.append(ix) ry.append(iy) ryaw.append(sp.calc_yaw(i_s)) rk.append(sp.calc_curvature(i_s)) return rx, ry, ryaw, rk, s
1,001
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
main_1d
()
326
339
def main_1d(): print("CubicSpline1D test") import matplotlib.pyplot as plt x = np.arange(5) y = [1.7, -6, 5, 6.5, 0.0] sp = CubicSpline1D(x, y) xi = np.linspace(0.0, 5.0) plt.plot(x, y, "xb", label="Data points") plt.plot(xi, [sp.calc_position(x) for x in xi], "r", label="Cubic spline interpolation") plt.grid(True) plt.legend() plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L326-L339
2
[ 0 ]
7.142857
[ 1, 2, 3, 4, 5, 6, 8, 9, 11, 12, 13 ]
78.571429
false
84.166667
14
2
21.428571
0
def main_1d(): print("CubicSpline1D test") import matplotlib.pyplot as plt x = np.arange(5) y = [1.7, -6, 5, 6.5, 0.0] sp = CubicSpline1D(x, y) xi = np.linspace(0.0, 5.0) plt.plot(x, y, "xb", label="Data points") plt.plot(xi, [sp.calc_position(x) for x in xi], "r", label="Cubic spline interpolation") plt.grid(True) plt.legend() plt.show()
1,002
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
main_2d
()
342
383
def main_2d(): # pragma: no cover print("CubicSpline1D 2D test") import matplotlib.pyplot as plt x = [-2.5, 0.0, 2.5, 5.0, 7.5, 3.0, -1.0] y = [0.7, -6, 5, 6.5, 0.0, 5.0, -2.0] ds = 0.1 # [m] distance of each interpolated points sp = CubicSpline2D(x, y) s = np.arange(0, sp.s[-1], ds) rx, ry, ryaw, rk = [], [], [], [] for i_s in s: ix, iy = sp.calc_position(i_s) rx.append(ix) ry.append(iy) ryaw.append(sp.calc_yaw(i_s)) rk.append(sp.calc_curvature(i_s)) plt.subplots(1) plt.plot(x, y, "xb", label="Data points") plt.plot(rx, ry, "-r", label="Cubic spline path") plt.grid(True) plt.axis("equal") plt.xlabel("x[m]") plt.ylabel("y[m]") plt.legend() plt.subplots(1) plt.plot(s, [np.rad2deg(iyaw) for iyaw in ryaw], "-r", label="yaw") plt.grid(True) plt.legend() plt.xlabel("line length[m]") plt.ylabel("yaw angle[deg]") plt.subplots(1) plt.plot(s, rk, "-r", label="curvature") plt.grid(True) plt.legend() plt.xlabel("line length[m]") plt.ylabel("curvature [1/m]") plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L342-L383
2
[]
0
[]
0
false
84.166667
42
3
100
0
def main_2d(): # pragma: no cover print("CubicSpline1D 2D test") import matplotlib.pyplot as plt x = [-2.5, 0.0, 2.5, 5.0, 7.5, 3.0, -1.0] y = [0.7, -6, 5, 6.5, 0.0, 5.0, -2.0] ds = 0.1 # [m] distance of each interpolated points sp = CubicSpline2D(x, y) s = np.arange(0, sp.s[-1], ds) rx, ry, ryaw, rk = [], [], [], [] for i_s in s: ix, iy = sp.calc_position(i_s) rx.append(ix) ry.append(iy) ryaw.append(sp.calc_yaw(i_s)) rk.append(sp.calc_curvature(i_s)) plt.subplots(1) plt.plot(x, y, "xb", label="Data points") plt.plot(rx, ry, "-r", label="Cubic spline path") plt.grid(True) plt.axis("equal") plt.xlabel("x[m]") plt.ylabel("y[m]") plt.legend() plt.subplots(1) plt.plot(s, [np.rad2deg(iyaw) for iyaw in ryaw], "-r", label="yaw") plt.grid(True) plt.legend() plt.xlabel("line length[m]") plt.ylabel("yaw angle[deg]") plt.subplots(1) plt.plot(s, rk, "-r", label="curvature") plt.grid(True) plt.legend() plt.xlabel("line length[m]") plt.ylabel("curvature [1/m]") plt.show()
1,003
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.__init__
(self, x, y)
46
71
def __init__(self, x, y): h = np.diff(x) if np.any(h < 0): raise ValueError("x coordinates must be sorted in ascending order") self.a, self.b, self.c, self.d = [], [], [], [] self.x = x self.y = y self.nx = len(x) # dimension of x # calc coefficient a self.a = [iy for iy in y] # calc coefficient c A = self.__calc_A(h) B = self.__calc_B(h, self.a) self.c = np.linalg.solve(A, B) # calc spline coefficient b and d for i in range(self.nx - 1): d = (self.c[i + 1] - self.c[i]) / (3.0 * h[i]) b = 1.0 / h[i] * (self.a[i + 1] - self.a[i]) \ - h[i] / 3.0 * (2.0 * self.c[i] + self.c[i + 1]) self.d.append(d) self.b.append(b)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L46-L71
2
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25 ]
92.307692
[ 4 ]
3.846154
false
84.166667
26
4
96.153846
0
def __init__(self, x, y): h = np.diff(x) if np.any(h < 0): raise ValueError("x coordinates must be sorted in ascending order") self.a, self.b, self.c, self.d = [], [], [], [] self.x = x self.y = y self.nx = len(x) # dimension of x # calc coefficient a self.a = [iy for iy in y] # calc coefficient c A = self.__calc_A(h) B = self.__calc_B(h, self.a) self.c = np.linalg.solve(A, B) # calc spline coefficient b and d for i in range(self.nx - 1): d = (self.c[i + 1] - self.c[i]) / (3.0 * h[i]) b = 1.0 / h[i] * (self.a[i + 1] - self.a[i]) \ - h[i] / 3.0 * (2.0 * self.c[i] + self.c[i + 1]) self.d.append(d) self.b.append(b)
1,004
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.calc_position
(self, x)
return position
Calc `y` position for given `x`. if `x` is outside the data point's `x` range, return None. Returns ------- y : float y position for given x.
Calc `y` position for given `x`.
73
94
def calc_position(self, x): """ Calc `y` position for given `x`. if `x` is outside the data point's `x` range, return None. Returns ------- y : float y position for given x. """ if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] position = self.a[i] + self.b[i] * dx + \ self.c[i] * dx ** 2.0 + self.d[i] * dx ** 3.0 return position
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L73-L94
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 16, 17, 18, 19, 20, 21 ]
90.909091
[ 12, 14 ]
9.090909
false
84.166667
22
3
90.909091
8
def calc_position(self, x): if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] position = self.a[i] + self.b[i] * dx + \ self.c[i] * dx ** 2.0 + self.d[i] * dx ** 3.0 return position
1,005
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.calc_first_derivative
(self, x)
return dy
Calc first derivative at given x. if x is outside the input x, return None Returns ------- dy : float first derivative for given x.
Calc first derivative at given x.
96
116
def calc_first_derivative(self, x): """ Calc first derivative at given x. if x is outside the input x, return None Returns ------- dy : float first derivative for given x. """ if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx ** 2.0 return dy
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L96-L116
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18, 19, 20 ]
90.47619
[ 13, 15 ]
9.52381
false
84.166667
21
3
90.47619
8
def calc_first_derivative(self, x): if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx ** 2.0 return dy
1,006
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.calc_second_derivative
(self, x)
return ddy
Calc second derivative at given x. if x is outside the input x, return None Returns ------- ddy : float second derivative for given x.
Calc second derivative at given x.
118
138
def calc_second_derivative(self, x): """ Calc second derivative at given x. if x is outside the input x, return None Returns ------- ddy : float second derivative for given x. """ if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] ddy = 2.0 * self.c[i] + 6.0 * self.d[i] * dx return ddy
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L118-L138
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18, 19, 20 ]
90.47619
[ 13, 15 ]
9.52381
false
84.166667
21
3
90.47619
8
def calc_second_derivative(self, x): if x < self.x[0]: return None elif x > self.x[-1]: return None i = self.__search_index(x) dx = x - self.x[i] ddy = 2.0 * self.c[i] + 6.0 * self.d[i] * dx return ddy
1,007
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.__search_index
(self, x)
return bisect.bisect(self.x, x) - 1
search data segment index
search data segment index
140
144
def __search_index(self, x): """ search data segment index """ return bisect.bisect(self.x, x) - 1
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L140-L144
2
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
84.166667
5
1
100
1
def __search_index(self, x): return bisect.bisect(self.x, x) - 1
1,008
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.__calc_A
(self, h)
return A
calc matrix A for spline coefficient c
calc matrix A for spline coefficient c
146
161
def __calc_A(self, h): """ calc matrix A for spline coefficient c """ A = np.zeros((self.nx, self.nx)) A[0, 0] = 1.0 for i in range(self.nx - 1): if i != (self.nx - 2): A[i + 1, i + 1] = 2.0 * (h[i] + h[i + 1]) A[i + 1, i] = h[i] A[i, i + 1] = h[i] A[0, 1] = 0.0 A[self.nx - 1, self.nx - 2] = 0.0 A[self.nx - 1, self.nx - 1] = 1.0 return A
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L146-L161
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
84.166667
16
3
100
1
def __calc_A(self, h): A = np.zeros((self.nx, self.nx)) A[0, 0] = 1.0 for i in range(self.nx - 1): if i != (self.nx - 2): A[i + 1, i + 1] = 2.0 * (h[i] + h[i + 1]) A[i + 1, i] = h[i] A[i, i + 1] = h[i] A[0, 1] = 0.0 A[self.nx - 1, self.nx - 2] = 0.0 A[self.nx - 1, self.nx - 1] = 1.0 return A
1,009
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline1D.__calc_B
(self, h, a)
return B
calc matrix B for spline coefficient c
calc matrix B for spline coefficient c
163
171
def __calc_B(self, h, a): """ calc matrix B for spline coefficient c """ B = np.zeros(self.nx) for i in range(self.nx - 2): B[i + 1] = 3.0 * (a[i + 2] - a[i + 1]) / h[i + 1]\ - 3.0 * (a[i + 1] - a[i]) / h[i] return B
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L163-L171
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
84.166667
9
2
100
1
def __calc_B(self, h, a): B = np.zeros(self.nx) for i in range(self.nx - 2): B[i + 1] = 3.0 * (a[i + 2] - a[i + 1]) / h[i + 1]\ - 3.0 * (a[i + 1] - a[i]) / h[i] return B
1,010
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline2D.__init__
(self, x, y)
233
236
def __init__(self, x, y): self.s = self.__calc_s(x, y) self.sx = CubicSpline1D(self.s, x) self.sy = CubicSpline1D(self.s, y)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L233-L236
2
[ 0, 1, 2, 3 ]
100
[]
0
true
84.166667
4
1
100
0
def __init__(self, x, y): self.s = self.__calc_s(x, y) self.sx = CubicSpline1D(self.s, x) self.sy = CubicSpline1D(self.s, y)
1,011
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline2D.__calc_s
(self, x, y)
return s
238
244
def __calc_s(self, x, y): dx = np.diff(x) dy = np.diff(y) self.ds = np.hypot(dx, dy) s = [0] s.extend(np.cumsum(self.ds)) return s
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L238-L244
2
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
84.166667
7
1
100
0
def __calc_s(self, x, y): dx = np.diff(x) dy = np.diff(y) self.ds = np.hypot(dx, dy) s = [0] s.extend(np.cumsum(self.ds)) return s
1,012
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline2D.calc_position
(self, s)
return x, y
calc position Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- x : float x position for given s. y : float y position for given s.
calc position
246
266
def calc_position(self, s): """ calc position Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- x : float x position for given s. y : float y position for given s. """ x = self.sx.calc_position(s) y = self.sy.calc_position(s) return x, y
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L246-L266
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
100
[]
0
true
84.166667
21
1
100
14
def calc_position(self, s): x = self.sx.calc_position(s) y = self.sy.calc_position(s) return x, y
1,013
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline2D.calc_curvature
(self, s)
return k
calc curvature Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- k : float curvature for given s.
calc curvature
268
288
def calc_curvature(self, s): """ calc curvature Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- k : float curvature for given s. """ dx = self.sx.calc_first_derivative(s) ddx = self.sx.calc_second_derivative(s) dy = self.sy.calc_first_derivative(s) ddy = self.sy.calc_second_derivative(s) k = (ddy * dx - ddx * dy) / ((dx ** 2 + dy ** 2)**(3 / 2)) return k
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L268-L288
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
100
[]
0
true
84.166667
21
1
100
12
def calc_curvature(self, s): dx = self.sx.calc_first_derivative(s) ddx = self.sx.calc_second_derivative(s) dy = self.sy.calc_first_derivative(s) ddy = self.sy.calc_second_derivative(s) k = (ddy * dx - ddx * dy) / ((dx ** 2 + dy ** 2)**(3 / 2)) return k
1,014
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/CubicSpline/cubic_spline_planner.py
CubicSpline2D.calc_yaw
(self, s)
return yaw
calc yaw Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- yaw : float yaw angle (tangent vector) for given s.
calc yaw
290
308
def calc_yaw(self, s): """ calc yaw Parameters ---------- s : float distance from the start point. if `s` is outside the data point's range, return None. Returns ------- yaw : float yaw angle (tangent vector) for given s. """ dx = self.sx.calc_first_derivative(s) dy = self.sy.calc_first_derivative(s) yaw = math.atan2(dy, dx) return yaw
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/CubicSpline/cubic_spline_planner.py#L290-L308
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
100
[]
0
true
84.166667
19
1
100
12
def calc_yaw(self, s): dx = self.sx.calc_first_derivative(s) dy = self.sy.calc_first_derivative(s) yaw = math.atan2(dy, dx) return yaw
1,015
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
main
()
303
309
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) img = plt.imread(os.path.join(dir_path, 'map', 'test_2.png')) STC_planner = SpiralSpanningTreeCoveragePlanner(img) start = (10, 0) edge, route, path = STC_planner.plan(start) STC_planner.visualize_path(edge, path, start)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L303-L309
2
[ 0 ]
14.285714
[ 1, 2, 3, 4, 5, 6 ]
85.714286
false
63.77551
7
1
14.285714
0
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) img = plt.imread(os.path.join(dir_path, 'map', 'test_2.png')) STC_planner = SpiralSpanningTreeCoveragePlanner(img) start = (10, 0) edge, route, path = STC_planner.plan(start) STC_planner.visualize_path(edge, path, start)
1,020
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.__init__
(self, occ_map)
21
34
def __init__(self, occ_map): self.origin_map_height = occ_map.shape[0] self.origin_map_width = occ_map.shape[1] # original map resolution must be even if self.origin_map_height % 2 == 1 or self.origin_map_width % 2 == 1: sys.exit('original map width/height must be even \ in grayscale .png format') self.occ_map = occ_map self.merged_map_height = self.origin_map_height // 2 self.merged_map_width = self.origin_map_width // 2 self.edge = []
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L21-L34
2
[ 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 ]
85.714286
[ 6 ]
7.142857
false
63.77551
14
3
92.857143
0
def __init__(self, occ_map): self.origin_map_height = occ_map.shape[0] self.origin_map_width = occ_map.shape[1] # original map resolution must be even if self.origin_map_height % 2 == 1 or self.origin_map_width % 2 == 1: sys.exit('original map width/height must be even \ in grayscale .png format') self.occ_map = occ_map self.merged_map_height = self.origin_map_height // 2 self.merged_map_width = self.origin_map_width // 2 self.edge = []
1,021
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.plan
(self, start)
return self.edge, route, path
plan performing Spiral Spanning Tree Coverage path planning :param start: the start node of Spiral Spanning Tree Coverage
plan
36
71
def plan(self, start): """plan performing Spiral Spanning Tree Coverage path planning :param start: the start node of Spiral Spanning Tree Coverage """ visit_times = np.zeros( (self.merged_map_height, self.merged_map_width), dtype=int) visit_times[start[0]][start[1]] = 1 # generate route by # recusively call perform_spanning_tree_coverage() from start node route = [] self.perform_spanning_tree_coverage(start, visit_times, route) path = [] # generate path from route for idx in range(len(route)-1): dp = abs(route[idx][0] - route[idx+1][0]) + \ abs(route[idx][1] - route[idx+1][1]) if dp == 0: # special handle for round-trip path path.append(self.get_round_trip_path(route[idx-1], route[idx])) elif dp == 1: path.append(self.move(route[idx], route[idx+1])) elif dp == 2: # special handle for non-adjacent route nodes mid_node = self.get_intermediate_node(route[idx], route[idx+1]) path.append(self.move(route[idx], mid_node)) path.append(self.move(mid_node, route[idx+1])) else: sys.exit('adjacent path node distance larger than 2') return self.edge, route, path
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L36-L71
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, 34, 35 ]
97.222222
[ 33 ]
2.777778
false
63.77551
36
5
97.222222
5
def plan(self, start): visit_times = np.zeros( (self.merged_map_height, self.merged_map_width), dtype=int) visit_times[start[0]][start[1]] = 1 # generate route by # recusively call perform_spanning_tree_coverage() from start node route = [] self.perform_spanning_tree_coverage(start, visit_times, route) path = [] # generate path from route for idx in range(len(route)-1): dp = abs(route[idx][0] - route[idx+1][0]) + \ abs(route[idx][1] - route[idx+1][1]) if dp == 0: # special handle for round-trip path path.append(self.get_round_trip_path(route[idx-1], route[idx])) elif dp == 1: path.append(self.move(route[idx], route[idx+1])) elif dp == 2: # special handle for non-adjacent route nodes mid_node = self.get_intermediate_node(route[idx], route[idx+1]) path.append(self.move(route[idx], mid_node)) path.append(self.move(mid_node, route[idx+1])) else: sys.exit('adjacent path node distance larger than 2') return self.edge, route, path
1,022
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.perform_spanning_tree_coverage
(self, current_node, visit_times, route)
return route
perform_spanning_tree_coverage recursive function for function <plan> :param current_node: current node
perform_spanning_tree_coverage
73
130
def perform_spanning_tree_coverage(self, current_node, visit_times, route): """perform_spanning_tree_coverage recursive function for function <plan> :param current_node: current node """ def is_valid_node(i, j): is_i_valid_bounded = 0 <= i < self.merged_map_height is_j_valid_bounded = 0 <= j < self.merged_map_width if is_i_valid_bounded and is_j_valid_bounded: # free only when the 4 sub-cells are all free return bool( self.occ_map[2*i][2*j] and self.occ_map[2*i+1][2*j] and self.occ_map[2*i][2*j+1] and self.occ_map[2*i+1][2*j+1]) return False # counter-clockwise neighbor finding order order = [[1, 0], [0, 1], [-1, 0], [0, -1]] found = False route.append(current_node) for inc in order: ni, nj = current_node[0] + inc[0], current_node[1] + inc[1] if is_valid_node(ni, nj) and visit_times[ni][nj] == 0: neighbor_node = (ni, nj) self.edge.append((current_node, neighbor_node)) found = True visit_times[ni][nj] += 1 self.perform_spanning_tree_coverage( neighbor_node, visit_times, route) # backtrace route from node with neighbors all visited # to first node with unvisited neighbor if not found: has_node_with_unvisited_ngb = False for node in reversed(route): # drop nodes that have been visited twice if visit_times[node[0]][node[1]] == 2: continue visit_times[node[0]][node[1]] += 1 route.append(node) for inc in order: ni, nj = node[0] + inc[0], node[1] + inc[1] if is_valid_node(ni, nj) and visit_times[ni][nj] == 0: has_node_with_unvisited_ngb = True break if has_node_with_unvisited_ngb: break return route
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L73-L130
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 ]
100
[]
0
true
63.77551
58
17
100
5
def perform_spanning_tree_coverage(self, current_node, visit_times, route): def is_valid_node(i, j): is_i_valid_bounded = 0 <= i < self.merged_map_height is_j_valid_bounded = 0 <= j < self.merged_map_width if is_i_valid_bounded and is_j_valid_bounded: # free only when the 4 sub-cells are all free return bool( self.occ_map[2*i][2*j] and self.occ_map[2*i+1][2*j] and self.occ_map[2*i][2*j+1] and self.occ_map[2*i+1][2*j+1]) return False # counter-clockwise neighbor finding order order = [[1, 0], [0, 1], [-1, 0], [0, -1]] found = False route.append(current_node) for inc in order: ni, nj = current_node[0] + inc[0], current_node[1] + inc[1] if is_valid_node(ni, nj) and visit_times[ni][nj] == 0: neighbor_node = (ni, nj) self.edge.append((current_node, neighbor_node)) found = True visit_times[ni][nj] += 1 self.perform_spanning_tree_coverage( neighbor_node, visit_times, route) # backtrace route from node with neighbors all visited # to first node with unvisited neighbor if not found: has_node_with_unvisited_ngb = False for node in reversed(route): # drop nodes that have been visited twice if visit_times[node[0]][node[1]] == 2: continue visit_times[node[0]][node[1]] += 1 route.append(node) for inc in order: ni, nj = node[0] + inc[0], node[1] + inc[1] if is_valid_node(ni, nj) and visit_times[ni][nj] == 0: has_node_with_unvisited_ngb = True break if has_node_with_unvisited_ngb: break return route
1,023
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.move
(self, p, q)
return [p, q]
132
152
def move(self, p, q): direction = self.get_vector_direction(p, q) # move east if direction == 'E': p = self.get_sub_node(p, 'SE') q = self.get_sub_node(q, 'SW') # move west elif direction == 'W': p = self.get_sub_node(p, 'NW') q = self.get_sub_node(q, 'NE') # move south elif direction == 'S': p = self.get_sub_node(p, 'SW') q = self.get_sub_node(q, 'NW') # move north elif direction == 'N': p = self.get_sub_node(p, 'NE') q = self.get_sub_node(q, 'SE') else: sys.exit('move direction error...') return [p, q]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L132-L152
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20 ]
90.47619
[ 19 ]
4.761905
false
63.77551
21
5
95.238095
0
def move(self, p, q): direction = self.get_vector_direction(p, q) # move east if direction == 'E': p = self.get_sub_node(p, 'SE') q = self.get_sub_node(q, 'SW') # move west elif direction == 'W': p = self.get_sub_node(p, 'NW') q = self.get_sub_node(q, 'NE') # move south elif direction == 'S': p = self.get_sub_node(p, 'SW') q = self.get_sub_node(q, 'NW') # move north elif direction == 'N': p = self.get_sub_node(p, 'NE') q = self.get_sub_node(q, 'SE') else: sys.exit('move direction error...') return [p, q]
1,024
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.get_round_trip_path
(self, last, pivot)
154
169
def get_round_trip_path(self, last, pivot): direction = self.get_vector_direction(last, pivot) if direction == 'E': return [self.get_sub_node(pivot, 'SE'), self.get_sub_node(pivot, 'NE')] elif direction == 'S': return [self.get_sub_node(pivot, 'SW'), self.get_sub_node(pivot, 'SE')] elif direction == 'W': return [self.get_sub_node(pivot, 'NW'), self.get_sub_node(pivot, 'SW')] elif direction == 'N': return [self.get_sub_node(pivot, 'NE'), self.get_sub_node(pivot, 'NW')] else: sys.exit('get_round_trip_path: last->pivot direction error.')
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L154-L169
2
[ 0, 1, 2, 5, 6, 8, 11, 12 ]
50
[ 3, 9, 15 ]
18.75
false
63.77551
16
5
81.25
0
def get_round_trip_path(self, last, pivot): direction = self.get_vector_direction(last, pivot) if direction == 'E': return [self.get_sub_node(pivot, 'SE'), self.get_sub_node(pivot, 'NE')] elif direction == 'S': return [self.get_sub_node(pivot, 'SW'), self.get_sub_node(pivot, 'SE')] elif direction == 'W': return [self.get_sub_node(pivot, 'NW'), self.get_sub_node(pivot, 'SW')] elif direction == 'N': return [self.get_sub_node(pivot, 'NE'), self.get_sub_node(pivot, 'NW')] else: sys.exit('get_round_trip_path: last->pivot direction error.')
1,025
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.get_vector_direction
(self, p, q)
171
185
def get_vector_direction(self, p, q): # east if p[0] == q[0] and p[1] < q[1]: return 'E' # west elif p[0] == q[0] and p[1] > q[1]: return 'W' # south elif p[0] < q[0] and p[1] == q[1]: return 'S' # north elif p[0] > q[0] and p[1] == q[1]: return 'N' else: sys.exit('get_vector_direction: Only E/W/S/N direction supported.')
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L171-L185
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
86.666667
[ 14 ]
6.666667
false
63.77551
15
9
93.333333
0
def get_vector_direction(self, p, q): # east if p[0] == q[0] and p[1] < q[1]: return 'E' # west elif p[0] == q[0] and p[1] > q[1]: return 'W' # south elif p[0] < q[0] and p[1] == q[1]: return 'S' # north elif p[0] > q[0] and p[1] == q[1]: return 'N' else: sys.exit('get_vector_direction: Only E/W/S/N direction supported.')
1,026
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.get_sub_node
(self, node, direction)
187
197
def get_sub_node(self, node, direction): if direction == 'SE': return [2*node[0]+1, 2*node[1]+1] elif direction == 'SW': return [2*node[0]+1, 2*node[1]] elif direction == 'NE': return [2*node[0], 2*node[1]+1] elif direction == 'NW': return [2*node[0], 2*node[1]] else: sys.exit('get_sub_node: sub-node direction error.')
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L187-L197
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
81.818182
[ 10 ]
9.090909
false
63.77551
11
5
90.909091
0
def get_sub_node(self, node, direction): if direction == 'SE': return [2*node[0]+1, 2*node[1]+1] elif direction == 'SW': return [2*node[0]+1, 2*node[1]] elif direction == 'NE': return [2*node[0], 2*node[1]+1] elif direction == 'NW': return [2*node[0], 2*node[1]] else: sys.exit('get_sub_node: sub-node direction error.')
1,027
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.get_interpolated_path
(self, p, q)
return ipx, ipy
199
208
def get_interpolated_path(self, p, q): # direction p->q: southwest / northeast if (p[0] < q[0]) ^ (p[1] < q[1]): ipx = [p[0], p[0], q[0]] ipy = [p[1], q[1], q[1]] # direction p->q: southeast / northwest else: ipx = [p[0], q[0], q[0]] ipy = [p[1], p[1], q[1]] return ipx, ipy
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L199-L208
2
[ 0, 1 ]
20
[ 2, 3, 4, 7, 8, 9 ]
60
false
63.77551
10
2
40
0
def get_interpolated_path(self, p, q): # direction p->q: southwest / northeast if (p[0] < q[0]) ^ (p[1] < q[1]): ipx = [p[0], p[0], q[0]] ipy = [p[1], q[1], q[1]] # direction p->q: southeast / northwest else: ipx = [p[0], q[0], q[0]] ipy = [p[1], p[1], q[1]] return ipx, ipy
1,028
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.get_intermediate_node
(self, p, q)
210
231
def get_intermediate_node(self, p, q): p_ngb, q_ngb = set(), set() for m, n in self.edge: if m == p: p_ngb.add(n) if n == p: p_ngb.add(m) if m == q: q_ngb.add(n) if n == q: q_ngb.add(m) itsc = p_ngb.intersection(q_ngb) if len(itsc) == 0: sys.exit('get_intermediate_node: \ no intermediate node between', p, q) elif len(itsc) == 1: return list(itsc)[0] else: sys.exit('get_intermediate_node: \ more than 1 intermediate node between', p, q)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L210-L231
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18 ]
77.272727
[ 15, 20 ]
9.090909
false
63.77551
22
8
90.909091
0
def get_intermediate_node(self, p, q): p_ngb, q_ngb = set(), set() for m, n in self.edge: if m == p: p_ngb.add(n) if n == p: p_ngb.add(m) if m == q: q_ngb.add(n) if n == q: q_ngb.add(m) itsc = p_ngb.intersection(q_ngb) if len(itsc) == 0: sys.exit('get_intermediate_node: \ no intermediate node between', p, q) elif len(itsc) == 1: return list(itsc)[0] else: sys.exit('get_intermediate_node: \ more than 1 intermediate node between', p, q)
1,029
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py
SpiralSpanningTreeCoveragePlanner.visualize_path
(self, edge, path, start)
233
300
def visualize_path(self, edge, path, start): def coord_transform(p): return [2*p[1] + 0.5, 2*p[0] + 0.5] if do_animation: last = path[0][0] trajectory = [[last[1]], [last[0]]] for p, q in path: distance = math.hypot(p[0]-last[0], p[1]-last[1]) if distance <= 1.0: trajectory[0].append(p[1]) trajectory[1].append(p[0]) else: ipx, ipy = self.get_interpolated_path(last, p) trajectory[0].extend(ipy) trajectory[1].extend(ipx) last = q trajectory[0].append(last[1]) trajectory[1].append(last[0]) for idx, state in enumerate(np.transpose(trajectory)): plt.cla() # 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]) # draw spanning tree plt.imshow(self.occ_map, 'gray') for p, q in edge: p = coord_transform(p) q = coord_transform(q) plt.plot([p[0], q[0]], [p[1], q[1]], '-oc') sx, sy = coord_transform(start) plt.plot([sx], [sy], 'pr', markersize=10) # draw move path plt.plot(trajectory[0][:idx+1], trajectory[1][:idx+1], '-k') plt.plot(state[0], state[1], 'or') plt.axis('equal') plt.grid(True) plt.pause(0.01) else: # draw spanning tree plt.imshow(self.occ_map, 'gray') for p, q in edge: p = coord_transform(p) q = coord_transform(q) plt.plot([p[0], q[0]], [p[1], q[1]], '-oc') sx, sy = coord_transform(start) plt.plot([sx], [sy], 'pr', markersize=10) # draw move path last = path[0][0] for p, q in path: distance = math.hypot(p[0]-last[0], p[1]-last[1]) if distance == 1.0: plt.plot([last[1], p[1]], [last[0], p[0]], '-k') else: ipx, ipy = self.get_interpolated_path(last, p) plt.plot(ipy, ipx, '-k') plt.arrow(p[1], p[0], q[1]-p[1], q[0]-p[0], head_width=0.2) last = q plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py#L233-L300
2
[ 0 ]
1.470588
[ 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 19, 20, 22, 23, 25, 30, 31, 32, 33, 34, 35, 36, 39, 40, 41, 42, 43, 47, 48, 49, 50, 51, 52, 53, 56, 57, 58, 59, 60, 62, 63, 64, 65, 67 ]
70.588235
false
63.77551
68
10
29.411765
0
def visualize_path(self, edge, path, start): def coord_transform(p): return [2*p[1] + 0.5, 2*p[0] + 0.5] if do_animation: last = path[0][0] trajectory = [[last[1]], [last[0]]] for p, q in path: distance = math.hypot(p[0]-last[0], p[1]-last[1]) if distance <= 1.0: trajectory[0].append(p[1]) trajectory[1].append(p[0]) else: ipx, ipy = self.get_interpolated_path(last, p) trajectory[0].extend(ipy) trajectory[1].extend(ipx) last = q trajectory[0].append(last[1]) trajectory[1].append(last[0]) for idx, state in enumerate(np.transpose(trajectory)): plt.cla() # 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]) # draw spanning tree plt.imshow(self.occ_map, 'gray') for p, q in edge: p = coord_transform(p) q = coord_transform(q) plt.plot([p[0], q[0]], [p[1], q[1]], '-oc') sx, sy = coord_transform(start) plt.plot([sx], [sy], 'pr', markersize=10) # draw move path plt.plot(trajectory[0][:idx+1], trajectory[1][:idx+1], '-k') plt.plot(state[0], state[1], 'or') plt.axis('equal') plt.grid(True) plt.pause(0.01) else: # draw spanning tree plt.imshow(self.occ_map, 'gray') for p, q in edge: p = coord_transform(p) q = coord_transform(q) plt.plot([p[0], q[0]], [p[1], q[1]], '-oc') sx, sy = coord_transform(start) plt.plot([sx], [sy], 'pr', markersize=10) # draw move path last = path[0][0] for p, q in path: distance = math.hypot(p[0]-last[0], p[1]-last[1]) if distance == 1.0: plt.plot([last[1], p[1]], [last[0], p[0]], '-k') else: ipx, ipy = self.get_interpolated_path(last, p) plt.plot(ipy, ipx, '-k') plt.arrow(p[1], p[0], q[1]-p[1], q[0]-p[0], head_width=0.2) last = q plt.show()
1,030
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
main
(bug_0, bug_1, bug_2)
277
329
def main(bug_0, bug_1, bug_2): # set obstacle positions o_x, o_y = [], [] s_x = 0.0 s_y = 0.0 g_x = 167.0 g_y = 50.0 for i in range(20, 40): for j in range(20, 40): o_x.append(i) o_y.append(j) for i in range(60, 100): for j in range(40, 80): o_x.append(i) o_y.append(j) for i in range(120, 140): for j in range(80, 100): o_x.append(i) o_y.append(j) for i in range(80, 140): for j in range(0, 20): o_x.append(i) o_y.append(j) for i in range(0, 20): for j in range(60, 100): o_x.append(i) o_y.append(j) for i in range(20, 40): for j in range(80, 100): o_x.append(i) o_y.append(j) for i in range(120, 160): for j in range(40, 60): o_x.append(i) o_y.append(j) if bug_0: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug0() if bug_1: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug1() if bug_2: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug2()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L277-L329
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 ]
100
[]
0
true
86.100386
53
18
100
0
def main(bug_0, bug_1, bug_2): # set obstacle positions o_x, o_y = [], [] s_x = 0.0 s_y = 0.0 g_x = 167.0 g_y = 50.0 for i in range(20, 40): for j in range(20, 40): o_x.append(i) o_y.append(j) for i in range(60, 100): for j in range(40, 80): o_x.append(i) o_y.append(j) for i in range(120, 140): for j in range(80, 100): o_x.append(i) o_y.append(j) for i in range(80, 140): for j in range(0, 20): o_x.append(i) o_y.append(j) for i in range(0, 20): for j in range(60, 100): o_x.append(i) o_y.append(j) for i in range(20, 40): for j in range(80, 100): o_x.append(i) o_y.append(j) for i in range(120, 160): for j in range(40, 60): o_x.append(i) o_y.append(j) if bug_0: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug0() if bug_1: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug1() if bug_2: my_Bug = BugPlanner(s_x, s_y, g_x, g_y, o_x, o_y) my_Bug.bug2()
1,031
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.__init__
(self, start_x, start_y, goal_x, goal_y, obs_x, obs_y)
14
33
def __init__(self, start_x, start_y, goal_x, goal_y, obs_x, obs_y): self.goal_x = goal_x self.goal_y = goal_y self.obs_x = obs_x self.obs_y = obs_y self.r_x = [start_x] self.r_y = [start_y] self.out_x = [] self.out_y = [] for o_x, o_y in zip(obs_x, obs_y): for add_x, add_y in zip([1, 0, -1, -1, -1, 0, 1, 1], [1, 1, 1, 0, -1, -1, -1, 0]): cand_x, cand_y = o_x+add_x, o_y+add_y valid_point = True for _x, _y in zip(obs_x, obs_y): if cand_x == _x and cand_y == _y: valid_point = False break if valid_point: self.out_x.append(cand_x), self.out_y.append(cand_y)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L14-L33
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19 ]
95
[]
0
false
86.100386
20
7
100
0
def __init__(self, start_x, start_y, goal_x, goal_y, obs_x, obs_y): self.goal_x = goal_x self.goal_y = goal_y self.obs_x = obs_x self.obs_y = obs_y self.r_x = [start_x] self.r_y = [start_y] self.out_x = [] self.out_y = [] for o_x, o_y in zip(obs_x, obs_y): for add_x, add_y in zip([1, 0, -1, -1, -1, 0, 1, 1], [1, 1, 1, 0, -1, -1, -1, 0]): cand_x, cand_y = o_x+add_x, o_y+add_y valid_point = True for _x, _y in zip(obs_x, obs_y): if cand_x == _x and cand_y == _y: valid_point = False break if valid_point: self.out_x.append(cand_x), self.out_y.append(cand_y)
1,032
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.mov_normal
(self)
return self.r_x[-1] + np.sign(self.goal_x - self.r_x[-1]), \ self.r_y[-1] + np.sign(self.goal_y - self.r_y[-1])
35
37
def mov_normal(self): return self.r_x[-1] + np.sign(self.goal_x - self.r_x[-1]), \ self.r_y[-1] + np.sign(self.goal_y - self.r_y[-1])
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L35-L37
2
[ 0, 1 ]
66.666667
[]
0
false
86.100386
3
1
100
0
def mov_normal(self): return self.r_x[-1] + np.sign(self.goal_x - self.r_x[-1]), \ self.r_y[-1] + np.sign(self.goal_y - self.r_y[-1])
1,033
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.mov_to_next_obs
(self, visited_x, visited_y)
return self.r_x[-1], self.r_y[-1], True
39
53
def mov_to_next_obs(self, visited_x, visited_y): for add_x, add_y in zip([1, 0, -1, 0], [0, 1, 0, -1]): c_x, c_y = self.r_x[-1] + add_x, self.r_y[-1] + add_y for _x, _y in zip(self.out_x, self.out_y): use_pt = True if c_x == _x and c_y == _y: for v_x, v_y in zip(visited_x, visited_y): if c_x == v_x and c_y == v_y: use_pt = False break if use_pt: return c_x, c_y, False if not use_pt: break return self.r_x[-1], self.r_y[-1], True
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L39-L53
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
86.100386
15
10
100
0
def mov_to_next_obs(self, visited_x, visited_y): for add_x, add_y in zip([1, 0, -1, 0], [0, 1, 0, -1]): c_x, c_y = self.r_x[-1] + add_x, self.r_y[-1] + add_y for _x, _y in zip(self.out_x, self.out_y): use_pt = True if c_x == _x and c_y == _y: for v_x, v_y in zip(visited_x, visited_y): if c_x == v_x and c_y == v_y: use_pt = False break if use_pt: return c_x, c_y, False if not use_pt: break return self.r_x[-1], self.r_y[-1], True
1,034
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.bug0
(self)
Greedy algorithm where you move towards goal until you hit an obstacle. Then you go around it (pick an arbitrary direction), until it is possible for you to start moving towards goal in a greedy manner again
Greedy algorithm where you move towards goal until you hit an obstacle. Then you go around it (pick an arbitrary direction), until it is possible for you to start moving towards goal in a greedy manner again
55
114
def bug0(self): """ Greedy algorithm where you move towards goal until you hit an obstacle. Then you go around it (pick an arbitrary direction), until it is possible for you to start moving towards goal in a greedy manner again """ mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") plt.grid(True) plt.title('BUG 0') for x_ob, y_ob in zip(self.out_x, self.out_y): if self.r_x[-1] == x_ob and self.r_y[-1] == y_ob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x and \ self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, _ = self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) mov_dir = 'obs' found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': can_go_normal = True for x_ob, y_ob in zip(self.obs_x, self.obs_y): if self.mov_normal()[0] == x_ob and \ self.mov_normal()[1] == y_ob: can_go_normal = False break if can_go_normal: mov_dir = 'normal' else: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L55-L114
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 18, 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, 58 ]
81.666667
[ 10, 11, 12, 13, 14, 15, 19, 20, 56, 57, 59 ]
18.333333
false
86.100386
60
22
81.666667
4
def bug0(self): mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") plt.grid(True) plt.title('BUG 0') for x_ob, y_ob in zip(self.out_x, self.out_y): if self.r_x[-1] == x_ob and self.r_y[-1] == y_ob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x and \ self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, _ = self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) mov_dir = 'obs' found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': can_go_normal = True for x_ob, y_ob in zip(self.obs_x, self.obs_y): if self.mov_normal()[0] == x_ob and \ self.mov_normal()[1] == y_ob: can_go_normal = False break if can_go_normal: mov_dir = 'normal' else: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
1,035
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.bug1
(self)
Move towards goal in a greedy manner. When you hit an obstacle, you go around it and back to where you hit the obstacle initially. Then, you go to the point on the obstacle that is closest to your goal and you start moving towards goal in a greedy manner from that new point.
Move towards goal in a greedy manner. When you hit an obstacle, you go around it and back to where you hit the obstacle initially. Then, you go to the point on the obstacle that is closest to your goal and you start moving towards goal in a greedy manner from that new point.
116
191
def bug1(self): """ Move towards goal in a greedy manner. When you hit an obstacle, you go around it and back to where you hit the obstacle initially. Then, you go to the point on the obstacle that is closest to your goal and you start moving towards goal in a greedy manner from that new point. """ mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf exit_x, exit_y = -np.inf, -np.inf dist = np.inf back_to_start = False second_round = False if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") plt.grid(True) plt.title('BUG 1') for xob, yob in zip(self.out_x, self.out_y): if self.r_x[-1] == xob and self.r_y[-1] == yob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x and \ self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, back_to_start = \ self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) mov_dir = 'obs' dist = np.inf back_to_start = False second_round = False found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': d = np.linalg.norm(np.array([cand_x, cand_y] - np.array([self.goal_x, self.goal_y]))) if d < dist and not second_round: exit_x, exit_y = cand_x, cand_y dist = d if back_to_start and not second_round: second_round = True del self.r_x[-len(visited_x):] del self.r_y[-len(visited_y):] visited_x[:], visited_y[:] = [], [] self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) if cand_x == exit_x and \ cand_y == exit_y and \ second_round: mov_dir = 'normal' if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L116-L191
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 74 ]
85.526316
[ 16, 17, 18, 19, 20, 21, 25, 26, 72, 73, 75 ]
14.473684
false
86.100386
76
25
85.526316
6
def bug1(self): mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf exit_x, exit_y = -np.inf, -np.inf dist = np.inf back_to_start = False second_round = False if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") plt.grid(True) plt.title('BUG 1') for xob, yob in zip(self.out_x, self.out_y): if self.r_x[-1] == xob and self.r_y[-1] == yob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x and \ self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, back_to_start = \ self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) mov_dir = 'obs' dist = np.inf back_to_start = False second_round = False found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': d = np.linalg.norm(np.array([cand_x, cand_y] - np.array([self.goal_x, self.goal_y]))) if d < dist and not second_round: exit_x, exit_y = cand_x, cand_y dist = d if back_to_start and not second_round: second_round = True del self.r_x[-len(visited_x):] del self.r_y[-len(visited_y):] visited_x[:], visited_y[:] = [], [] self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) if cand_x == exit_x and \ cand_y == exit_y and \ second_round: mov_dir = 'normal' if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
1,036
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BugPlanning/bug.py
BugPlanner.bug2
(self)
Move towards goal in a greedy manner. When you hit an obstacle, you go around it and keep track of your distance from the goal. If the distance from your goal was decreasing before and now it starts increasing, that means the current point is probably the closest point to the goal (this may or may not be true because the algorithm doesn't explore the entire boundary around the obstacle). So, you depart from this point and continue towards the goal in a greedy manner
Move towards goal in a greedy manner. When you hit an obstacle, you go around it and keep track of your distance from the goal. If the distance from your goal was decreasing before and now it starts increasing, that means the current point is probably the closest point to the goal (this may or may not be true because the algorithm doesn't explore the entire boundary around the obstacle). So, you depart from this point and continue towards the goal in a greedy manner
193
274
def bug2(self): """ Move towards goal in a greedy manner. When you hit an obstacle, you go around it and keep track of your distance from the goal. If the distance from your goal was decreasing before and now it starts increasing, that means the current point is probably the closest point to the goal (this may or may not be true because the algorithm doesn't explore the entire boundary around the obstacle). So, you depart from this point and continue towards the goal in a greedy manner """ mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") straight_x, straight_y = [self.r_x[-1]], [self.r_y[-1]] hit_x, hit_y = [], [] while True: if straight_x[-1] == self.goal_x and \ straight_y[-1] == self.goal_y: break c_x = straight_x[-1] + np.sign(self.goal_x - straight_x[-1]) c_y = straight_y[-1] + np.sign(self.goal_y - straight_y[-1]) for x_ob, y_ob in zip(self.out_x, self.out_y): if c_x == x_ob and c_y == y_ob: hit_x.append(c_x), hit_y.append(c_y) break straight_x.append(c_x), straight_y.append(c_y) if show_animation: plt.plot(straight_x, straight_y, ",") plt.plot(hit_x, hit_y, "d") plt.grid(True) plt.title('BUG 2') for x_ob, y_ob in zip(self.out_x, self.out_y): if self.r_x[-1] == x_ob and self.r_y[-1] == y_ob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x \ and self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, _ = self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) del hit_x[0] del hit_y[0] mov_dir = 'obs' found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) for i_x, i_y in zip(range(len(hit_x)), range(len(hit_y))): if cand_x == hit_x[i_x] and cand_y == hit_y[i_y]: del hit_x[i_x] del hit_y[i_y] mov_dir = 'normal' break if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BugPlanning/bug.py#L193-L274
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 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, 80 ]
84.146341
[ 16, 17, 18, 19, 35, 36, 37, 38, 42, 43, 78, 79, 81 ]
15.853659
false
86.100386
82
28
84.146341
10
def bug2(self): mov_dir = 'normal' cand_x, cand_y = -np.inf, -np.inf if show_animation: plt.plot(self.obs_x, self.obs_y, ".k") plt.plot(self.r_x[-1], self.r_y[-1], "og") plt.plot(self.goal_x, self.goal_y, "xb") plt.plot(self.out_x, self.out_y, ".") straight_x, straight_y = [self.r_x[-1]], [self.r_y[-1]] hit_x, hit_y = [], [] while True: if straight_x[-1] == self.goal_x and \ straight_y[-1] == self.goal_y: break c_x = straight_x[-1] + np.sign(self.goal_x - straight_x[-1]) c_y = straight_y[-1] + np.sign(self.goal_y - straight_y[-1]) for x_ob, y_ob in zip(self.out_x, self.out_y): if c_x == x_ob and c_y == y_ob: hit_x.append(c_x), hit_y.append(c_y) break straight_x.append(c_x), straight_y.append(c_y) if show_animation: plt.plot(straight_x, straight_y, ",") plt.plot(hit_x, hit_y, "d") plt.grid(True) plt.title('BUG 2') for x_ob, y_ob in zip(self.out_x, self.out_y): if self.r_x[-1] == x_ob and self.r_y[-1] == y_ob: mov_dir = 'obs' break visited_x, visited_y = [], [] while True: if self.r_x[-1] == self.goal_x \ and self.r_y[-1] == self.goal_y: break if mov_dir == 'normal': cand_x, cand_y = self.mov_normal() if mov_dir == 'obs': cand_x, cand_y, _ = self.mov_to_next_obs(visited_x, visited_y) if mov_dir == 'normal': found_boundary = False for x_ob, y_ob in zip(self.out_x, self.out_y): if cand_x == x_ob and cand_y == y_ob: self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x[:], visited_y[:] = [], [] visited_x.append(cand_x), visited_y.append(cand_y) del hit_x[0] del hit_y[0] mov_dir = 'obs' found_boundary = True break if not found_boundary: self.r_x.append(cand_x), self.r_y.append(cand_y) elif mov_dir == 'obs': self.r_x.append(cand_x), self.r_y.append(cand_y) visited_x.append(cand_x), visited_y.append(cand_y) for i_x, i_y in zip(range(len(hit_x)), range(len(hit_y))): if cand_x == hit_x[i_x] and cand_y == hit_y[i_y]: del hit_x[i_x] del hit_y[i_y] mov_dir = 'normal' break if show_animation: plt.plot(self.r_x, self.r_y, "-r") plt.pause(0.001) if show_animation: plt.show()
1,037
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
quintic_polynomials_planner
(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_accel, max_jerk, dt)
return time, rx, ry, ryaw, rv, ra, rj
quintic polynomial planner input s_x: start x position [m] s_y: start y position [m] s_yaw: start yaw angle [rad] sa: start accel [m/ss] gx: goal x position [m] gy: goal y position [m] gyaw: goal yaw angle [rad] ga: goal accel [m/ss] max_accel: maximum accel [m/ss] max_jerk: maximum jerk [m/sss] dt: time tick [s] return time: time result rx: x position result list ry: y position result list ryaw: yaw angle result list rv: velocity result list ra: accel result list
quintic polynomial planner
69
162
def quintic_polynomials_planner(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_accel, max_jerk, dt): """ quintic polynomial planner input s_x: start x position [m] s_y: start y position [m] s_yaw: start yaw angle [rad] sa: start accel [m/ss] gx: goal x position [m] gy: goal y position [m] gyaw: goal yaw angle [rad] ga: goal accel [m/ss] max_accel: maximum accel [m/ss] max_jerk: maximum jerk [m/sss] dt: time tick [s] return time: time result rx: x position result list ry: y position result list ryaw: yaw angle result list rv: velocity result list ra: accel result list """ vxs = sv * math.cos(syaw) vys = sv * math.sin(syaw) vxg = gv * math.cos(gyaw) vyg = gv * math.sin(gyaw) axs = sa * math.cos(syaw) ays = sa * math.sin(syaw) axg = ga * math.cos(gyaw) ayg = ga * math.sin(gyaw) time, rx, ry, ryaw, rv, ra, rj = [], [], [], [], [], [], [] for T in np.arange(MIN_T, MAX_T, MIN_T): xqp = QuinticPolynomial(sx, vxs, axs, gx, vxg, axg, T) yqp = QuinticPolynomial(sy, vys, ays, gy, vyg, ayg, T) time, rx, ry, ryaw, rv, ra, rj = [], [], [], [], [], [], [] for t in np.arange(0.0, T + dt, dt): time.append(t) rx.append(xqp.calc_point(t)) ry.append(yqp.calc_point(t)) vx = xqp.calc_first_derivative(t) vy = yqp.calc_first_derivative(t) v = np.hypot(vx, vy) yaw = math.atan2(vy, vx) rv.append(v) ryaw.append(yaw) ax = xqp.calc_second_derivative(t) ay = yqp.calc_second_derivative(t) a = np.hypot(ax, ay) if len(rv) >= 2 and rv[-1] - rv[-2] < 0.0: a *= -1 ra.append(a) jx = xqp.calc_third_derivative(t) jy = yqp.calc_third_derivative(t) j = np.hypot(jx, jy) if len(ra) >= 2 and ra[-1] - ra[-2] < 0.0: j *= -1 rj.append(j) if max([abs(i) for i in ra]) <= max_accel and max([abs(i) for i in rj]) <= max_jerk: print("find path!!") break if show_animation: # pragma: no cover for i, _ in enumerate(time): plt.cla() # 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.grid(True) plt.axis("equal") plot_arrow(sx, sy, syaw) plot_arrow(gx, gy, gyaw) plot_arrow(rx[i], ry[i], ryaw[i]) plt.title("Time[s]:" + str(time[i])[0:4] + " v[m/s]:" + str(rv[i])[0:4] + " a[m/ss]:" + str(ra[i])[0:4] + " jerk[m/sss]:" + str(rj[i])[0:4], ) plt.pause(0.001) return time, rx, ry, ryaw, rv, ra, rj
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L69-L162
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 ]
113.253012
[]
0
true
98.850575
94
13
100
22
def quintic_polynomials_planner(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_accel, max_jerk, dt): vxs = sv * math.cos(syaw) vys = sv * math.sin(syaw) vxg = gv * math.cos(gyaw) vyg = gv * math.sin(gyaw) axs = sa * math.cos(syaw) ays = sa * math.sin(syaw) axg = ga * math.cos(gyaw) ayg = ga * math.sin(gyaw) time, rx, ry, ryaw, rv, ra, rj = [], [], [], [], [], [], [] for T in np.arange(MIN_T, MAX_T, MIN_T): xqp = QuinticPolynomial(sx, vxs, axs, gx, vxg, axg, T) yqp = QuinticPolynomial(sy, vys, ays, gy, vyg, ayg, T) time, rx, ry, ryaw, rv, ra, rj = [], [], [], [], [], [], [] for t in np.arange(0.0, T + dt, dt): time.append(t) rx.append(xqp.calc_point(t)) ry.append(yqp.calc_point(t)) vx = xqp.calc_first_derivative(t) vy = yqp.calc_first_derivative(t) v = np.hypot(vx, vy) yaw = math.atan2(vy, vx) rv.append(v) ryaw.append(yaw) ax = xqp.calc_second_derivative(t) ay = yqp.calc_second_derivative(t) a = np.hypot(ax, ay) if len(rv) >= 2 and rv[-1] - rv[-2] < 0.0: a *= -1 ra.append(a) jx = xqp.calc_third_derivative(t) jy = yqp.calc_third_derivative(t) j = np.hypot(jx, jy) if len(ra) >= 2 and ra[-1] - ra[-2] < 0.0: j *= -1 rj.append(j) if max([abs(i) for i in ra]) <= max_accel and max([abs(i) for i in rj]) <= max_jerk: print("find path!!") break if show_animation: # pragma: no cover for i, _ in enumerate(time): plt.cla() # 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.grid(True) plt.axis("equal") plot_arrow(sx, sy, syaw) plot_arrow(gx, gy, gyaw) plot_arrow(rx[i], ry[i], ryaw[i]) plt.title("Time[s]:" + str(time[i])[0:4] + " v[m/s]:" + str(rv[i])[0:4] + " a[m/ss]:" + str(ra[i])[0:4] + " jerk[m/sss]:" + str(rj[i])[0:4], ) plt.pause(0.001) return time, rx, ry, ryaw, rv, ra, rj
1,038
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
plot_arrow
(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k")
Plot arrow
Plot arrow
165
176
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"): # pragma: no cover """ Plot arrow """ if not isinstance(x, float): for (ix, iy, iyaw) in zip(x, y, yaw): plot_arrow(ix, iy, iyaw) else: plt.arrow(x, y, length * math.cos(yaw), length * math.sin(yaw), fc=fc, ec=ec, head_width=width, head_length=width) plt.plot(x, y)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L165-L176
2
[]
0
[]
0
false
98.850575
12
3
100
1
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"): # pragma: no cover if not isinstance(x, float): for (ix, iy, iyaw) in zip(x, y, yaw): plot_arrow(ix, iy, iyaw) else: plt.arrow(x, y, length * math.cos(yaw), length * math.sin(yaw), fc=fc, ec=ec, head_width=width, head_length=width) plt.plot(x, y)
1,039
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
main
()
179
226
def main(): print(__file__ + " start!!") sx = 10.0 # start x position [m] sy = 10.0 # start y position [m] syaw = np.deg2rad(10.0) # start yaw angle [rad] sv = 1.0 # start speed [m/s] sa = 0.1 # start accel [m/ss] gx = 30.0 # goal x position [m] gy = -10.0 # goal y position [m] gyaw = np.deg2rad(20.0) # goal yaw angle [rad] gv = 1.0 # goal speed [m/s] ga = 0.1 # goal accel [m/ss] max_accel = 1.0 # max accel [m/ss] max_jerk = 0.5 # max jerk [m/sss] dt = 0.1 # time tick [s] time, x, y, yaw, v, a, j = quintic_polynomials_planner( sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_accel, max_jerk, dt) if show_animation: # pragma: no cover plt.plot(x, y, "-r") plt.subplots() plt.plot(time, [np.rad2deg(i) for i in yaw], "-r") plt.xlabel("Time[s]") plt.ylabel("Yaw[deg]") plt.grid(True) plt.subplots() plt.plot(time, v, "-r") plt.xlabel("Time[s]") plt.ylabel("Speed[m/s]") plt.grid(True) plt.subplots() plt.plot(time, a, "-r") plt.xlabel("Time[s]") plt.ylabel("accel[m/ss]") plt.grid(True) plt.subplots() plt.plot(time, j, "-r") plt.xlabel("Time[s]") plt.ylabel("jerk[m/sss]") plt.grid(True) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L179-L226
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
72
[]
0
false
98.850575
48
3
100
0
def main(): print(__file__ + " start!!") sx = 10.0 # start x position [m] sy = 10.0 # start y position [m] syaw = np.deg2rad(10.0) # start yaw angle [rad] sv = 1.0 # start speed [m/s] sa = 0.1 # start accel [m/ss] gx = 30.0 # goal x position [m] gy = -10.0 # goal y position [m] gyaw = np.deg2rad(20.0) # goal yaw angle [rad] gv = 1.0 # goal speed [m/s] ga = 0.1 # goal accel [m/ss] max_accel = 1.0 # max accel [m/ss] max_jerk = 0.5 # max jerk [m/sss] dt = 0.1 # time tick [s] time, x, y, yaw, v, a, j = quintic_polynomials_planner( sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_accel, max_jerk, dt) if show_animation: # pragma: no cover plt.plot(x, y, "-r") plt.subplots() plt.plot(time, [np.rad2deg(i) for i in yaw], "-r") plt.xlabel("Time[s]") plt.ylabel("Yaw[deg]") plt.grid(True) plt.subplots() plt.plot(time, v, "-r") plt.xlabel("Time[s]") plt.ylabel("Speed[m/s]") plt.grid(True) plt.subplots() plt.plot(time, a, "-r") plt.xlabel("Time[s]") plt.ylabel("accel[m/ss]") plt.grid(True) plt.subplots() plt.plot(time, j, "-r") plt.xlabel("Time[s]") plt.ylabel("jerk[m/sss]") plt.grid(True) plt.show()
1,040
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
QuinticPolynomial.__init__
(self, xs, vxs, axs, xe, vxe, axe, time)
27
44
def __init__(self, xs, vxs, axs, xe, vxe, axe, time): # calc coefficient of quintic polynomial # See jupyter notebook document for derivation of this equation. self.a0 = xs self.a1 = vxs self.a2 = axs / 2.0 A = np.array([[time ** 3, time ** 4, time ** 5], [3 * time ** 2, 4 * time ** 3, 5 * time ** 4], [6 * time, 12 * time ** 2, 20 * time ** 3]]) b = np.array([xe - self.a0 - self.a1 * time - self.a2 * time ** 2, vxe - self.a1 - 2 * self.a2 * time, axe - 2 * self.a2]) x = np.linalg.solve(A, b) self.a3 = x[0] self.a4 = x[1] self.a5 = x[2]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L27-L44
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 10, 13, 14, 15, 16, 17 ]
77.777778
[]
0
false
98.850575
18
1
100
0
def __init__(self, xs, vxs, axs, xe, vxe, axe, time): # calc coefficient of quintic polynomial # See jupyter notebook document for derivation of this equation. self.a0 = xs self.a1 = vxs self.a2 = axs / 2.0 A = np.array([[time ** 3, time ** 4, time ** 5], [3 * time ** 2, 4 * time ** 3, 5 * time ** 4], [6 * time, 12 * time ** 2, 20 * time ** 3]]) b = np.array([xe - self.a0 - self.a1 * time - self.a2 * time ** 2, vxe - self.a1 - 2 * self.a2 * time, axe - 2 * self.a2]) x = np.linalg.solve(A, b) self.a3 = x[0] self.a4 = x[1] self.a5 = x[2]
1,041
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
QuinticPolynomial.calc_point
(self, t)
return xt
46
50
def calc_point(self, t): xt = self.a0 + self.a1 * t + self.a2 * t ** 2 + \ self.a3 * t ** 3 + self.a4 * t ** 4 + self.a5 * t ** 5 return xt
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L46-L50
2
[ 0, 1, 3, 4 ]
80
[]
0
false
98.850575
5
1
100
0
def calc_point(self, t): xt = self.a0 + self.a1 * t + self.a2 * t ** 2 + \ self.a3 * t ** 3 + self.a4 * t ** 4 + self.a5 * t ** 5 return xt
1,042
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
QuinticPolynomial.calc_first_derivative
(self, t)
return xt
52
56
def calc_first_derivative(self, t): xt = self.a1 + 2 * self.a2 * t + \ 3 * self.a3 * t ** 2 + 4 * self.a4 * t ** 3 + 5 * self.a5 * t ** 4 return xt
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L52-L56
2
[ 0, 1, 3, 4 ]
80
[]
0
false
98.850575
5
1
100
0
def calc_first_derivative(self, t): xt = self.a1 + 2 * self.a2 * t + \ 3 * self.a3 * t ** 2 + 4 * self.a4 * t ** 3 + 5 * self.a5 * t ** 4 return xt
1,043
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
QuinticPolynomial.calc_second_derivative
(self, t)
return xt
58
61
def calc_second_derivative(self, t): xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t ** 2 + 20 * self.a5 * t ** 3 return xt
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L58-L61
2
[ 0, 1, 2, 3 ]
100
[]
0
true
98.850575
4
1
100
0
def calc_second_derivative(self, t): xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t ** 2 + 20 * self.a5 * t ** 3 return xt
1,044
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py
QuinticPolynomial.calc_third_derivative
(self, t)
return xt
63
66
def calc_third_derivative(self, t): xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t ** 2 return xt
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py#L63-L66
2
[ 0, 1, 2, 3 ]
100
[]
0
true
98.850575
4
1
100
0
def calc_third_derivative(self, t): xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t ** 2 return xt
1,045
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
plot_arrow
(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k")
33
40
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"): if isinstance(x, list): for (ix, iy, iyaw) in zip(x, y, yaw): plot_arrow(ix, iy, iyaw) else: plt.arrow(x, y, length * math.cos(yaw), length * math.sin(yaw), fc=fc, ec=ec, head_width=width, head_length=width) plt.plot(x, y)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L33-L40
2
[ 0 ]
12.5
[ 1, 2, 3, 5, 7 ]
62.5
false
96.25
8
3
37.5
0
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"): if isinstance(x, list): for (ix, iy, iyaw) in zip(x, y, yaw): plot_arrow(ix, iy, iyaw) else: plt.arrow(x, y, length * math.cos(yaw), length * math.sin(yaw), fc=fc, ec=ec, head_width=width, head_length=width) plt.plot(x, y)
1,046
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
mod2pi
(x)
return v
43
51
def mod2pi(x): # Be consistent with fmod in cplusplus here. v = np.mod(x, np.copysign(2.0 * math.pi, x)) if v < -math.pi: v += 2.0 * math.pi else: if v > math.pi: v -= 2.0 * math.pi return v
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L43-L51
2
[ 0, 1, 2, 3, 4, 6, 7, 8 ]
88.888889
[]
0
false
96.25
9
3
100
0
def mod2pi(x): # Be consistent with fmod in cplusplus here. v = np.mod(x, np.copysign(2.0 * math.pi, x)) if v < -math.pi: v += 2.0 * math.pi else: if v > math.pi: v -= 2.0 * math.pi return v
1,047
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
straight_left_straight
(x, y, phi)
return False, 0.0, 0.0, 0.0
54
69
def straight_left_straight(x, y, phi): phi = mod2pi(phi) if y > 0.0 and 0.0 < phi < math.pi * 0.99: xd = - y / math.tan(phi) + x t = xd - math.tan(phi / 2.0) u = phi v = math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0) return True, t, u, v elif y < 0.0 < phi < math.pi * 0.99: xd = - y / math.tan(phi) + x t = xd - math.tan(phi / 2.0) u = phi v = -math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0) return True, t, u, v return False, 0.0, 0.0, 0.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L54-L69
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
96.25
16
4
100
0
def straight_left_straight(x, y, phi): phi = mod2pi(phi) if y > 0.0 and 0.0 < phi < math.pi * 0.99: xd = - y / math.tan(phi) + x t = xd - math.tan(phi / 2.0) u = phi v = math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0) return True, t, u, v elif y < 0.0 < phi < math.pi * 0.99: xd = - y / math.tan(phi) + x t = xd - math.tan(phi / 2.0) u = phi v = -math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0) return True, t, u, v return False, 0.0, 0.0, 0.0
1,048
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
set_path
(paths, lengths, ctypes, step_size)
return paths
72
90
def set_path(paths, lengths, ctypes, step_size): path = Path() path.ctypes = ctypes path.lengths = lengths path.L = sum(np.abs(lengths)) # check same path exist for i_path in paths: type_is_same = (i_path.ctypes == path.ctypes) length_is_close = (sum(np.abs(i_path.lengths)) - path.L) <= step_size if type_is_same and length_is_close: return paths # same path found, so do not insert path # check path is long enough if path.L <= step_size: return paths # too short, so do not insert path paths.append(path) return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L72-L90
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18 ]
94.736842
[ 15 ]
5.263158
false
96.25
19
5
94.736842
0
def set_path(paths, lengths, ctypes, step_size): path = Path() path.ctypes = ctypes path.lengths = lengths path.L = sum(np.abs(lengths)) # check same path exist for i_path in paths: type_is_same = (i_path.ctypes == path.ctypes) length_is_close = (sum(np.abs(i_path.lengths)) - path.L) <= step_size if type_is_same and length_is_close: return paths # same path found, so do not insert path # check path is long enough if path.L <= step_size: return paths # too short, so do not insert path paths.append(path) return paths
1,049
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
straight_curve_straight
(x, y, phi, paths, step_size)
return paths
93
102
def straight_curve_straight(x, y, phi, paths, step_size): flag, t, u, v = straight_left_straight(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["S", "L", "S"], step_size) flag, t, u, v = straight_left_straight(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["S", "R", "S"], step_size) return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L93-L102
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
96.25
10
3
100
0
def straight_curve_straight(x, y, phi, paths, step_size): flag, t, u, v = straight_left_straight(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["S", "L", "S"], step_size) flag, t, u, v = straight_left_straight(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["S", "R", "S"], step_size) return paths
1,050
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
polar
(x, y)
return r, theta
105
108
def polar(x, y): r = math.sqrt(x ** 2 + y ** 2) theta = math.atan2(y, x) return r, theta
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L105-L108
2
[ 0, 1, 2, 3 ]
100
[]
0
true
96.25
4
1
100
0
def polar(x, y): r = math.sqrt(x ** 2 + y ** 2) theta = math.atan2(y, x) return r, theta
1,051
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
left_straight_left
(x, y, phi)
return False, 0.0, 0.0, 0.0
111
118
def left_straight_left(x, y, phi): u, t = polar(x - math.sin(phi), y - 1.0 + math.cos(phi)) if t >= 0.0: v = mod2pi(phi - t) if v >= 0.0: return True, t, u, v return False, 0.0, 0.0, 0.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L111-L118
2
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
96.25
8
3
100
0
def left_straight_left(x, y, phi): u, t = polar(x - math.sin(phi), y - 1.0 + math.cos(phi)) if t >= 0.0: v = mod2pi(phi - t) if v >= 0.0: return True, t, u, v return False, 0.0, 0.0, 0.0
1,052
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
left_right_left
(x, y, phi)
return False, 0.0, 0.0, 0.0
121
132
def left_right_left(x, y, phi): u1, t1 = polar(x - math.sin(phi), y - 1.0 + math.cos(phi)) if u1 <= 4.0: u = -2.0 * math.asin(0.25 * u1) t = mod2pi(t1 + 0.5 * u + math.pi) v = mod2pi(phi - t + u) if t >= 0.0 >= u: return True, t, u, v return False, 0.0, 0.0, 0.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L121-L132
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
96.25
12
3
100
0
def left_right_left(x, y, phi): u1, t1 = polar(x - math.sin(phi), y - 1.0 + math.cos(phi)) if u1 <= 4.0: u = -2.0 * math.asin(0.25 * u1) t = mod2pi(t1 + 0.5 * u + math.pi) v = mod2pi(phi - t + u) if t >= 0.0 >= u: return True, t, u, v return False, 0.0, 0.0, 0.0
1,053
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
curve_curve_curve
(x, y, phi, paths, step_size)
return paths
135
172
def curve_curve_curve(x, y, phi, paths, step_size): flag, t, u, v = left_right_left(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "L", "R"], step_size) flag, t, u, v = left_right_left(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "L", "R"], step_size) # backwards xb = x * math.cos(phi) + y * math.sin(phi) yb = x * math.sin(phi) - y * math.cos(phi) flag, t, u, v = left_right_left(xb, yb, phi) if flag: paths = set_path(paths, [v, u, t], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(-xb, yb, -phi) if flag: paths = set_path(paths, [-v, -u, -t], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(xb, -yb, -phi) if flag: paths = set_path(paths, [v, u, t], ["R", "L", "R"], step_size) flag, t, u, v = left_right_left(-xb, -yb, phi) if flag: paths = set_path(paths, [-v, -u, -t], ["R", "L", "R"], step_size) return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L135-L172
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 ]
100
[]
0
true
96.25
38
9
100
0
def curve_curve_curve(x, y, phi, paths, step_size): flag, t, u, v = left_right_left(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "L", "R"], step_size) flag, t, u, v = left_right_left(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "L", "R"], step_size) # backwards xb = x * math.cos(phi) + y * math.sin(phi) yb = x * math.sin(phi) - y * math.cos(phi) flag, t, u, v = left_right_left(xb, yb, phi) if flag: paths = set_path(paths, [v, u, t], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(-xb, yb, -phi) if flag: paths = set_path(paths, [-v, -u, -t], ["L", "R", "L"], step_size) flag, t, u, v = left_right_left(xb, -yb, -phi) if flag: paths = set_path(paths, [v, u, t], ["R", "L", "R"], step_size) flag, t, u, v = left_right_left(-xb, -yb, phi) if flag: paths = set_path(paths, [-v, -u, -t], ["R", "L", "R"], step_size) return paths
1,054
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
curve_straight_curve
(x, y, phi, paths, step_size)
return paths
175
208
def curve_straight_curve(x, y, phi, paths, step_size): flag, t, u, v = left_straight_left(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "S", "L"], step_size) flag, t, u, v = left_straight_left(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "S", "L"], step_size) flag, t, u, v = left_straight_left(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "S", "R"], step_size) flag, t, u, v = left_straight_left(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "S", "R"], step_size) flag, t, u, v = left_straight_right(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "S", "R"], step_size) flag, t, u, v = left_straight_right(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "S", "R"], step_size) flag, t, u, v = left_straight_right(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "S", "L"], step_size) flag, t, u, v = left_straight_right(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "S", "L"], step_size) return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L175-L208
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 ]
100
[]
0
true
96.25
34
9
100
0
def curve_straight_curve(x, y, phi, paths, step_size): flag, t, u, v = left_straight_left(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "S", "L"], step_size) flag, t, u, v = left_straight_left(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "S", "L"], step_size) flag, t, u, v = left_straight_left(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "S", "R"], step_size) flag, t, u, v = left_straight_left(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "S", "R"], step_size) flag, t, u, v = left_straight_right(x, y, phi) if flag: paths = set_path(paths, [t, u, v], ["L", "S", "R"], step_size) flag, t, u, v = left_straight_right(-x, y, -phi) if flag: paths = set_path(paths, [-t, -u, -v], ["L", "S", "R"], step_size) flag, t, u, v = left_straight_right(x, -y, -phi) if flag: paths = set_path(paths, [t, u, v], ["R", "S", "L"], step_size) flag, t, u, v = left_straight_right(-x, -y, phi) if flag: paths = set_path(paths, [-t, -u, -v], ["R", "S", "L"], step_size) return paths
1,055
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
left_straight_right
(x, y, phi)
return False, 0.0, 0.0, 0.0
211
223
def left_straight_right(x, y, phi): u1, t1 = polar(x + math.sin(phi), y - 1.0 - math.cos(phi)) u1 = u1 ** 2 if u1 >= 4.0: u = math.sqrt(u1 - 4.0) theta = math.atan2(2.0, u) t = mod2pi(t1 + theta) v = mod2pi(t - phi) if t >= 0.0 and v >= 0.0: return True, t, u, v return False, 0.0, 0.0, 0.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L211-L223
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
96.25
13
4
100
0
def left_straight_right(x, y, phi): u1, t1 = polar(x + math.sin(phi), y - 1.0 - math.cos(phi)) u1 = u1 ** 2 if u1 >= 4.0: u = math.sqrt(u1 - 4.0) theta = math.atan2(2.0, u) t = mod2pi(t1 + theta) v = mod2pi(t - phi) if t >= 0.0 and v >= 0.0: return True, t, u, v return False, 0.0, 0.0, 0.0
1,056
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
generate_path
(q0, q1, max_curvature, step_size)
return paths
226
240
def generate_path(q0, q1, max_curvature, step_size): dx = q1[0] - q0[0] dy = q1[1] - q0[1] dth = q1[2] - q0[2] c = math.cos(q0[2]) s = math.sin(q0[2]) x = (c * dx + s * dy) * max_curvature y = (-s * dx + c * dy) * max_curvature paths = [] paths = straight_curve_straight(x, y, dth, paths, step_size) paths = curve_straight_curve(x, y, dth, paths, step_size) paths = curve_curve_curve(x, y, dth, paths, step_size) return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L226-L240
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
96.25
15
1
100
0
def generate_path(q0, q1, max_curvature, step_size): dx = q1[0] - q0[0] dy = q1[1] - q0[1] dth = q1[2] - q0[2] c = math.cos(q0[2]) s = math.sin(q0[2]) x = (c * dx + s * dy) * max_curvature y = (-s * dx + c * dy) * max_curvature paths = [] paths = straight_curve_straight(x, y, dth, paths, step_size) paths = curve_straight_curve(x, y, dth, paths, step_size) paths = curve_curve_curve(x, y, dth, paths, step_size) return paths
1,057
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
calc_interpolate_dists_list
(lengths, step_size)
return interpolate_dists_list
243
251
def calc_interpolate_dists_list(lengths, step_size): interpolate_dists_list = [] for length in lengths: d_dist = step_size if length >= 0.0 else -step_size interp_dists = np.arange(0.0, length, d_dist) interp_dists = np.append(interp_dists, length) interpolate_dists_list.append(interp_dists) return interpolate_dists_list
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L243-L251
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
96.25
9
2
100
0
def calc_interpolate_dists_list(lengths, step_size): interpolate_dists_list = [] for length in lengths: d_dist = step_size if length >= 0.0 else -step_size interp_dists = np.arange(0.0, length, d_dist) interp_dists = np.append(interp_dists, length) interpolate_dists_list.append(interp_dists) return interpolate_dists_list
1,058
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
generate_local_course
(lengths, modes, max_curvature, step_size)
return xs, ys, yaws, directions
254
275
def generate_local_course(lengths, modes, max_curvature, step_size): interpolate_dists_list = calc_interpolate_dists_list(lengths, step_size) origin_x, origin_y, origin_yaw = 0.0, 0.0, 0.0 xs, ys, yaws, directions = [], [], [], [] for (interp_dists, mode, length) in zip(interpolate_dists_list, modes, lengths): for dist in interp_dists: x, y, yaw, direction = interpolate(dist, length, mode, max_curvature, origin_x, origin_y, origin_yaw) xs.append(x) ys.append(y) yaws.append(yaw) directions.append(direction) origin_x = xs[-1] origin_y = ys[-1] origin_yaw = yaws[-1] return xs, ys, yaws, directions
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L254-L275
2
[ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
86.363636
[]
0
false
96.25
22
3
100
0
def generate_local_course(lengths, modes, max_curvature, step_size): interpolate_dists_list = calc_interpolate_dists_list(lengths, step_size) origin_x, origin_y, origin_yaw = 0.0, 0.0, 0.0 xs, ys, yaws, directions = [], [], [], [] for (interp_dists, mode, length) in zip(interpolate_dists_list, modes, lengths): for dist in interp_dists: x, y, yaw, direction = interpolate(dist, length, mode, max_curvature, origin_x, origin_y, origin_yaw) xs.append(x) ys.append(y) yaws.append(yaw) directions.append(direction) origin_x = xs[-1] origin_y = ys[-1] origin_yaw = yaws[-1] return xs, ys, yaws, directions
1,059
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
interpolate
(dist, length, mode, max_curvature, origin_x, origin_y, origin_yaw)
return x, y, yaw, 1 if length > 0.0 else -1
278
299
def interpolate(dist, length, mode, max_curvature, origin_x, origin_y, origin_yaw): if mode == "S": x = origin_x + dist / max_curvature * math.cos(origin_yaw) y = origin_y + dist / max_curvature * math.sin(origin_yaw) yaw = origin_yaw else: # curve ldx = math.sin(dist) / max_curvature ldy = 0.0 yaw = None if mode == "L": # left turn ldy = (1.0 - math.cos(dist)) / max_curvature yaw = origin_yaw + dist elif mode == "R": # right turn ldy = (1.0 - math.cos(dist)) / -max_curvature yaw = origin_yaw - dist gdx = math.cos(-origin_yaw) * ldx + math.sin(-origin_yaw) * ldy gdy = -math.sin(-origin_yaw) * ldx + math.cos(-origin_yaw) * ldy x = origin_x + gdx y = origin_y + gdy return x, y, yaw, 1 if length > 0.0 else -1
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L278-L299
2
[ 0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
90.909091
[]
0
false
96.25
22
4
100
0
def interpolate(dist, length, mode, max_curvature, origin_x, origin_y, origin_yaw): if mode == "S": x = origin_x + dist / max_curvature * math.cos(origin_yaw) y = origin_y + dist / max_curvature * math.sin(origin_yaw) yaw = origin_yaw else: # curve ldx = math.sin(dist) / max_curvature ldy = 0.0 yaw = None if mode == "L": # left turn ldy = (1.0 - math.cos(dist)) / max_curvature yaw = origin_yaw + dist elif mode == "R": # right turn ldy = (1.0 - math.cos(dist)) / -max_curvature yaw = origin_yaw - dist gdx = math.cos(-origin_yaw) * ldx + math.sin(-origin_yaw) * ldy gdy = -math.sin(-origin_yaw) * ldx + math.cos(-origin_yaw) * ldy x = origin_x + gdx y = origin_y + gdy return x, y, yaw, 1 if length > 0.0 else -1
1,060
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
pi_2_pi
(angle)
return (angle + math.pi) % (2 * math.pi) - math.pi
302
303
def pi_2_pi(angle): return (angle + math.pi) % (2 * math.pi) - math.pi
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L302-L303
2
[ 0, 1 ]
100
[]
0
true
96.25
2
1
100
0
def pi_2_pi(angle): return (angle + math.pi) % (2 * math.pi) - math.pi
1,061
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
calc_paths
(sx, sy, syaw, gx, gy, gyaw, maxc, step_size)
return paths
306
326
def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size): q0 = [sx, sy, syaw] q1 = [gx, gy, gyaw] paths = generate_path(q0, q1, maxc, step_size) for path in paths: xs, ys, yaws, directions = generate_local_course(path.lengths, path.ctypes, maxc, step_size * maxc) # convert global coordinate path.x = [math.cos(-q0[2]) * ix + math.sin(-q0[2]) * iy + q0[0] for (ix, iy) in zip(xs, ys)] path.y = [-math.sin(-q0[2]) * ix + math.cos(-q0[2]) * iy + q0[1] for (ix, iy) in zip(xs, ys)] path.yaw = [pi_2_pi(yaw + q0[2]) for yaw in yaws] path.directions = directions path.lengths = [length / maxc for length in path.lengths] path.L = path.L / maxc return paths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L306-L326
2
[ 0, 1, 2, 3, 4, 5, 6, 10, 11, 13, 15, 16, 17, 18, 19, 20 ]
76.190476
[]
0
false
96.25
21
6
100
0
def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size): q0 = [sx, sy, syaw] q1 = [gx, gy, gyaw] paths = generate_path(q0, q1, maxc, step_size) for path in paths: xs, ys, yaws, directions = generate_local_course(path.lengths, path.ctypes, maxc, step_size * maxc) # convert global coordinate path.x = [math.cos(-q0[2]) * ix + math.sin(-q0[2]) * iy + q0[0] for (ix, iy) in zip(xs, ys)] path.y = [-math.sin(-q0[2]) * ix + math.cos(-q0[2]) * iy + q0[1] for (ix, iy) in zip(xs, ys)] path.yaw = [pi_2_pi(yaw + q0[2]) for yaw in yaws] path.directions = directions path.lengths = [length / maxc for length in path.lengths] path.L = path.L / maxc return paths
1,062
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
reeds_shepp_path_planning
(sx, sy, syaw, gx, gy, gyaw, maxc, step_size=0.2)
return b_path.x, b_path.y, b_path.yaw, b_path.ctypes, b_path.lengths
329
338
def reeds_shepp_path_planning(sx, sy, syaw, gx, gy, gyaw, maxc, step_size=0.2): paths = calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size) if not paths: return None, None, None, None, None # could not generate any path # search minimum cost path best_path_index = paths.index(min(paths, key=lambda p: abs(p.L))) b_path = paths[best_path_index] return b_path.x, b_path.y, b_path.yaw, b_path.ctypes, b_path.lengths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L329-L338
2
[ 0, 1, 2, 5, 6, 7, 8, 9 ]
80
[ 3 ]
10
false
96.25
10
2
90
0
def reeds_shepp_path_planning(sx, sy, syaw, gx, gy, gyaw, maxc, step_size=0.2): paths = calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size) if not paths: return None, None, None, None, None # could not generate any path # search minimum cost path best_path_index = paths.index(min(paths, key=lambda p: abs(p.L))) b_path = paths[best_path_index] return b_path.x, b_path.y, b_path.yaw, b_path.ctypes, b_path.lengths
1,063
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py
Path.__init__
(self)
21
30
def __init__(self): # course segment length (negative value is backward segment) self.lengths = [] # course segment type char ("S": straight, "L": left, "R": right) self.ctypes = [] self.L = 0.0 # Total lengths of the path self.x = [] # x positions self.y = [] # y positions self.yaw = [] # orientations [rad] self.directions = []
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py#L21-L30
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
96.25
10
1
100
0
def __init__(self): # course segment length (negative value is backward segment) self.lengths = [] # course segment type char ("S": straight, "L": left, "R": right) self.ctypes = [] self.L = 0.0 # Total lengths of the path self.x = [] # x positions self.y = [] # y positions self.yaw = [] # orientations [rad] self.directions = []
1,064
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
main
()
recreate path from reference (see Table 1)
recreate path from reference (see Table 1)
351
357
def main(): """ recreate path from reference (see Table 1) """ test1() test2() test3()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L351-L357
2
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
88.108108
7
1
100
1
def main(): test1() test2() test3()
1,065
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
Eta3Path.__init__
(self, segments)
33
40
def __init__(self, segments): # ensure input has the correct form assert(isinstance(segments, list) and isinstance( segments[0], Eta3PathSegment)) # ensure that each segment begins from the previous segment's end (continuity) for r, s in zip(segments[:-1], segments[1:]): assert(np.array_equal(r.end_pose, s.start_pose)) self.segments = segments
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L33-L40
2
[ 0, 1, 2, 4, 5, 6, 7 ]
87.5
[]
0
false
88.108108
8
5
100
0
def __init__(self, segments): # ensure input has the correct form assert(isinstance(segments, list) and isinstance( segments[0], Eta3PathSegment)) # ensure that each segment begins from the previous segment's end (continuity) for r, s in zip(segments[:-1], segments[1:]): assert(np.array_equal(r.end_pose, s.start_pose)) self.segments = segments
1,066
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
Eta3Path.calc_path_point
(self, u)
return self.segments[segment_idx].calc_point(u)
Eta3Path::calc_path_point input normalized interpolation point along path object, 0 <= u <= len(self.segments) returns 2d (x,y) position vector
Eta3Path::calc_path_point
42
59
def calc_path_point(self, u): """ Eta3Path::calc_path_point input normalized interpolation point along path object, 0 <= u <= len(self.segments) returns 2d (x,y) position vector """ assert(0 <= u <= len(self.segments)) if np.isclose(u, len(self.segments)): segment_idx = len(self.segments) - 1 u = 1. else: segment_idx = int(np.floor(u)) u -= segment_idx return self.segments[segment_idx].calc_point(u)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L42-L59
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
88.108108
18
3
100
6
def calc_path_point(self, u): assert(0 <= u <= len(self.segments)) if np.isclose(u, len(self.segments)): segment_idx = len(self.segments) - 1 u = 1. else: segment_idx = int(np.floor(u)) u -= segment_idx return self.segments[segment_idx].calc_point(u)
1,067
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
Eta3PathSegment.__init__
(self, start_pose, end_pose, eta=None, kappa=None)
76
189
def __init__(self, start_pose, end_pose, eta=None, kappa=None): # make sure inputs are of the correct size assert(len(start_pose) == 3 and len(start_pose) == len(end_pose)) self.start_pose = start_pose self.end_pose = end_pose # if no eta is passed, initialize it to array of zeros if not eta: eta = np.zeros((6,)) else: # make sure that eta has correct size assert(len(eta) == 6) # if no kappa is passed, initialize to array of zeros if not kappa: kappa = np.zeros((4,)) else: assert(len(kappa) == 4) # set up angle cosines and sines for simpler computations below ca = np.cos(start_pose[2]) sa = np.sin(start_pose[2]) cb = np.cos(end_pose[2]) sb = np.sin(end_pose[2]) # 2 dimensions (x,y) x 8 coefficients per dimension self.coeffs = np.empty((2, 8)) # constant terms (u^0) self.coeffs[0, 0] = start_pose[0] self.coeffs[1, 0] = start_pose[1] # linear (u^1) self.coeffs[0, 1] = eta[0] * ca self.coeffs[1, 1] = eta[0] * sa # quadratic (u^2) self.coeffs[0, 2] = 1. / 2 * eta[2] * \ ca - 1. / 2 * eta[0]**2 * kappa[0] * sa self.coeffs[1, 2] = 1. / 2 * eta[2] * \ sa + 1. / 2 * eta[0]**2 * kappa[0] * ca # cubic (u^3) self.coeffs[0, 3] = 1. / 6 * eta[4] * ca - 1. / 6 * \ (eta[0]**3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * sa self.coeffs[1, 3] = 1. / 6 * eta[4] * sa + 1. / 6 * \ (eta[0]**3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * ca # quartic (u^4) tmp1 = 35. * (end_pose[0] - start_pose[0]) tmp2 = (20. * eta[0] + 5 * eta[2] + 2. / 3 * eta[4]) * ca tmp3 = (5. * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (15. * eta[1] - 5. / 2 * eta[3] + 1. / 6 * eta[5]) * cb tmp5 = (5. / 2 * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 4] = tmp1 - tmp2 + tmp3 - tmp4 - tmp5 tmp1 = 35. * (end_pose[1] - start_pose[1]) tmp2 = (20. * eta[0] + 5. * eta[2] + 2. / 3 * eta[4]) * sa tmp3 = (5. * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (15. * eta[1] - 5. / 2 * eta[3] + 1. / 6 * eta[5]) * sb tmp5 = (5. / 2 * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 4] = tmp1 - tmp2 - tmp3 - tmp4 + tmp5 # quintic (u^5) tmp1 = -84. * (end_pose[0] - start_pose[0]) tmp2 = (45. * eta[0] + 10. * eta[2] + eta[4]) * ca tmp3 = (10. * eta[0] ** 2 * kappa[0] + eta[0] ** 3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (39. * eta[1] - 7. * eta[3] + 1. / 2 * eta[5]) * cb tmp5 = + (7. * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 5] = tmp1 + tmp2 - tmp3 + tmp4 + tmp5 tmp1 = -84. * (end_pose[1] - start_pose[1]) tmp2 = (45. * eta[0] + 10. * eta[2] + eta[4]) * sa tmp3 = (10. * eta[0] ** 2 * kappa[0] + eta[0] ** 3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (39. * eta[1] - 7. * eta[3] + 1. / 2 * eta[5]) * sb tmp5 = - (7. * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 5] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 # sextic (u^6) tmp1 = 70. * (end_pose[0] - start_pose[0]) tmp2 = (36. * eta[0] + 15. / 2 * eta[2] + 2. / 3 * eta[4]) * ca tmp3 = + (15. / 2 * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (34. * eta[1] - 13. / 2 * eta[3] + 1. / 2 * eta[5]) * cb tmp5 = - (13. / 2 * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 6] = tmp1 - tmp2 + tmp3 - tmp4 + tmp5 tmp1 = 70. * (end_pose[1] - start_pose[1]) tmp2 = - (36. * eta[0] + 15. / 2 * eta[2] + 2. / 3 * eta[4]) * sa tmp3 = - (15. / 2 * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = - (34. * eta[1] - 13. / 2 * eta[3] + 1. / 2 * eta[5]) * sb tmp5 = + (13. / 2 * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 6] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 # septic (u^7) tmp1 = -20. * (end_pose[0] - start_pose[0]) tmp2 = (10. * eta[0] + 2. * eta[2] + 1. / 6 * eta[4]) * ca tmp3 = - (2. * eta[0] ** 2 * kappa[0] + 1. / 6 * eta[0] ** 3 * kappa[1] + 1. / 2 * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (10. * eta[1] - 2. * eta[3] + 1. / 6 * eta[5]) * cb tmp5 = (2. * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 7] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 tmp1 = -20. * (end_pose[1] - start_pose[1]) tmp2 = (10. * eta[0] + 2. * eta[2] + 1. / 6 * eta[4]) * sa tmp3 = (2. * eta[0] ** 2 * kappa[0] + 1. / 6 * eta[0] ** 3 * kappa[1] + 1. / 2 * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (10. * eta[1] - 2. * eta[3] + 1. / 6 * eta[5]) * sb tmp5 = - (2. * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 7] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 self.s_dot = lambda u: max(np.linalg.norm( self.coeffs[:, 1:].dot(np.array( [1, 2. * u, 3. * u**2, 4. * u**3, 5. * u**4, 6. * u**5, 7. * u**6]))), 1e-6) self.f_length = lambda ue: quad(lambda u: self.s_dot(u), 0, ue) self.segment_length = self.f_length(1)[0]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L76-L189
2
[ 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 35, 37, 39, 40, 41, 42, 44, 45, 47, 48, 49, 50, 52, 53, 55, 56, 57, 58, 59, 61, 62, 64, 65, 66, 67, 69, 70, 72, 73, 74, 75, 76, 78, 79, 81, 82, 83, 84, 86, 87, 89, 90, 91, 92, 93, 95, 96, 98, 99, 100, 101, 102, 104, 105, 107, 108, 112, 113 ]
76.315789
[ 7, 13 ]
1.754386
false
88.108108
114
7
98.245614
0
def __init__(self, start_pose, end_pose, eta=None, kappa=None): # make sure inputs are of the correct size assert(len(start_pose) == 3 and len(start_pose) == len(end_pose)) self.start_pose = start_pose self.end_pose = end_pose # if no eta is passed, initialize it to array of zeros if not eta: eta = np.zeros((6,)) else: # make sure that eta has correct size assert(len(eta) == 6) # if no kappa is passed, initialize to array of zeros if not kappa: kappa = np.zeros((4,)) else: assert(len(kappa) == 4) # set up angle cosines and sines for simpler computations below ca = np.cos(start_pose[2]) sa = np.sin(start_pose[2]) cb = np.cos(end_pose[2]) sb = np.sin(end_pose[2]) # 2 dimensions (x,y) x 8 coefficients per dimension self.coeffs = np.empty((2, 8)) # constant terms (u^0) self.coeffs[0, 0] = start_pose[0] self.coeffs[1, 0] = start_pose[1] # linear (u^1) self.coeffs[0, 1] = eta[0] * ca self.coeffs[1, 1] = eta[0] * sa # quadratic (u^2) self.coeffs[0, 2] = 1. / 2 * eta[2] * \ ca - 1. / 2 * eta[0]**2 * kappa[0] * sa self.coeffs[1, 2] = 1. / 2 * eta[2] * \ sa + 1. / 2 * eta[0]**2 * kappa[0] * ca # cubic (u^3) self.coeffs[0, 3] = 1. / 6 * eta[4] * ca - 1. / 6 * \ (eta[0]**3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * sa self.coeffs[1, 3] = 1. / 6 * eta[4] * sa + 1. / 6 * \ (eta[0]**3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * ca # quartic (u^4) tmp1 = 35. * (end_pose[0] - start_pose[0]) tmp2 = (20. * eta[0] + 5 * eta[2] + 2. / 3 * eta[4]) * ca tmp3 = (5. * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (15. * eta[1] - 5. / 2 * eta[3] + 1. / 6 * eta[5]) * cb tmp5 = (5. / 2 * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 4] = tmp1 - tmp2 + tmp3 - tmp4 - tmp5 tmp1 = 35. * (end_pose[1] - start_pose[1]) tmp2 = (20. * eta[0] + 5. * eta[2] + 2. / 3 * eta[4]) * sa tmp3 = (5. * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (15. * eta[1] - 5. / 2 * eta[3] + 1. / 6 * eta[5]) * sb tmp5 = (5. / 2 * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 4] = tmp1 - tmp2 - tmp3 - tmp4 + tmp5 # quintic (u^5) tmp1 = -84. * (end_pose[0] - start_pose[0]) tmp2 = (45. * eta[0] + 10. * eta[2] + eta[4]) * ca tmp3 = (10. * eta[0] ** 2 * kappa[0] + eta[0] ** 3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (39. * eta[1] - 7. * eta[3] + 1. / 2 * eta[5]) * cb tmp5 = + (7. * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 5] = tmp1 + tmp2 - tmp3 + tmp4 + tmp5 tmp1 = -84. * (end_pose[1] - start_pose[1]) tmp2 = (45. * eta[0] + 10. * eta[2] + eta[4]) * sa tmp3 = (10. * eta[0] ** 2 * kappa[0] + eta[0] ** 3 * kappa[1] + 3. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (39. * eta[1] - 7. * eta[3] + 1. / 2 * eta[5]) * sb tmp5 = - (7. * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 5] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 # sextic (u^6) tmp1 = 70. * (end_pose[0] - start_pose[0]) tmp2 = (36. * eta[0] + 15. / 2 * eta[2] + 2. / 3 * eta[4]) * ca tmp3 = + (15. / 2 * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (34. * eta[1] - 13. / 2 * eta[3] + 1. / 2 * eta[5]) * cb tmp5 = - (13. / 2 * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 6] = tmp1 - tmp2 + tmp3 - tmp4 + tmp5 tmp1 = 70. * (end_pose[1] - start_pose[1]) tmp2 = - (36. * eta[0] + 15. / 2 * eta[2] + 2. / 3 * eta[4]) * sa tmp3 = - (15. / 2 * eta[0] ** 2 * kappa[0] + 2. / 3 * eta[0] ** 3 * kappa[1] + 2. * eta[0] * eta[2] * kappa[0]) * ca tmp4 = - (34. * eta[1] - 13. / 2 * eta[3] + 1. / 2 * eta[5]) * sb tmp5 = + (13. / 2 * eta[1] ** 2 * kappa[2] - 1. / 2 * eta[1] ** 3 * kappa[3] - 3. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 6] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 # septic (u^7) tmp1 = -20. * (end_pose[0] - start_pose[0]) tmp2 = (10. * eta[0] + 2. * eta[2] + 1. / 6 * eta[4]) * ca tmp3 = - (2. * eta[0] ** 2 * kappa[0] + 1. / 6 * eta[0] ** 3 * kappa[1] + 1. / 2 * eta[0] * eta[2] * kappa[0]) * sa tmp4 = (10. * eta[1] - 2. * eta[3] + 1. / 6 * eta[5]) * cb tmp5 = (2. * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * sb self.coeffs[0, 7] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 tmp1 = -20. * (end_pose[1] - start_pose[1]) tmp2 = (10. * eta[0] + 2. * eta[2] + 1. / 6 * eta[4]) * sa tmp3 = (2. * eta[0] ** 2 * kappa[0] + 1. / 6 * eta[0] ** 3 * kappa[1] + 1. / 2 * eta[0] * eta[2] * kappa[0]) * ca tmp4 = (10. * eta[1] - 2. * eta[3] + 1. / 6 * eta[5]) * sb tmp5 = - (2. * eta[1] ** 2 * kappa[2] - 1. / 6 * eta[1] ** 3 * kappa[3] - 1. / 2 * eta[1] * eta[3] * kappa[2]) * cb self.coeffs[1, 7] = tmp1 + tmp2 + tmp3 + tmp4 + tmp5 self.s_dot = lambda u: max(np.linalg.norm( self.coeffs[:, 1:].dot(np.array( [1, 2. * u, 3. * u**2, 4. * u**3, 5. * u**4, 6. * u**5, 7. * u**6]))), 1e-6) self.f_length = lambda ue: quad(lambda u: self.s_dot(u), 0, ue) self.segment_length = self.f_length(1)[0]
1,068
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
Eta3PathSegment.calc_point
(self, u)
return self.coeffs.dot(np.array([1, u, u**2, u**3, u**4, u**5, u**6, u**7]))
Eta3PathSegment::calc_point input u - parametric representation of a point along the segment, 0 <= u <= 1 returns (x,y) of point along the segment
Eta3PathSegment::calc_point
191
201
def calc_point(self, u): """ Eta3PathSegment::calc_point input u - parametric representation of a point along the segment, 0 <= u <= 1 returns (x,y) of point along the segment """ assert(0 <= u <= 1) return self.coeffs.dot(np.array([1, u, u**2, u**3, u**4, u**5, u**6, u**7]))
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L191-L201
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
88.108108
11
2
100
6
def calc_point(self, u): assert(0 <= u <= 1) return self.coeffs.dot(np.array([1, u, u**2, u**3, u**4, u**5, u**6, u**7]))
1,069
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Eta3SplinePath/eta3_spline_path.py
Eta3PathSegment.calc_deriv
(self, u, order=1)
return self.coeffs[:, 2:].dot(np.array([2, 6. * u, 12. * u**2, 20. * u**3, 30. * u**4, 42. * u**5]))
Eta3PathSegment::calc_deriv input u - parametric representation of a point along the segment, 0 <= u <= 1 returns (d^nx/du^n,d^ny/du^n) of point along the segment, for 0 < n <= 2
Eta3PathSegment::calc_deriv
203
218
def calc_deriv(self, u, order=1): """ Eta3PathSegment::calc_deriv input u - parametric representation of a point along the segment, 0 <= u <= 1 returns (d^nx/du^n,d^ny/du^n) of point along the segment, for 0 < n <= 2 """ assert(0 <= u <= 1) assert(0 < order <= 2) if order == 1: return self.coeffs[:, 1:].dot(np.array([1, 2. * u, 3. * u**2, 4. * u**3, 5. * u**4, 6. * u**5, 7. * u**6])) return self.coeffs[:, 2:].dot(np.array([2, 6. * u, 12. * u**2, 20. * u**3, 30. * u**4, 42. * u**5]))
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Eta3SplinePath/eta3_spline_path.py#L203-L218
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
62.5
[ 10, 11, 12, 13, 15 ]
31.25
false
88.108108
16
4
68.75
6
def calc_deriv(self, u, order=1): assert(0 <= u <= 1) assert(0 < order <= 2) if order == 1: return self.coeffs[:, 1:].dot(np.array([1, 2. * u, 3. * u**2, 4. * u**3, 5. * u**4, 6. * u**5, 7. * u**6])) return self.coeffs[:, 2:].dot(np.array([2, 6. * u, 12. * u**2, 20. * u**3, 30. * u**4, 42. * u**5]))
1,070
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
main
()
179
217
def main(): print(__file__ + " start!!") # start and goal position sx, sy = 10.0, 10.0 # [m] gx, gy = 50.0, 50.0 # [m] expand_distance = 5.0 # [m] obstacles = [ ObstaclePolygon( [20.0, 30.0, 15.0], [20.0, 20.0, 30.0], ), ObstaclePolygon( [40.0, 45.0, 50.0, 40.0], [50.0, 40.0, 20.0, 40.0], ), ObstaclePolygon( [20.0, 30.0, 30.0, 20.0], [40.0, 45.0, 60.0, 50.0], ) ] if show_animation: # pragma: no cover plt.plot(sx, sy, "or") plt.plot(gx, gy, "ob") for ob in obstacles: ob.plot() plt.axis("equal") plt.pause(1.0) rx, ry = VisibilityRoadMap(expand_distance, do_plot=show_animation)\ .planning(sx, sy, gx, gy, obstacles) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.1) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L179-L217
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 31, 32 ]
42.857143
[]
0
false
92.792793
39
4
100
0
def main(): print(__file__ + " start!!") # start and goal position sx, sy = 10.0, 10.0 # [m] gx, gy = 50.0, 50.0 # [m] expand_distance = 5.0 # [m] obstacles = [ ObstaclePolygon( [20.0, 30.0, 15.0], [20.0, 20.0, 30.0], ), ObstaclePolygon( [40.0, 45.0, 50.0, 40.0], [50.0, 40.0, 20.0, 40.0], ), ObstaclePolygon( [20.0, 30.0, 30.0, 20.0], [40.0, 45.0, 60.0, 50.0], ) ] if show_animation: # pragma: no cover plt.plot(sx, sy, "or") plt.plot(gx, gy, "ob") for ob in obstacles: ob.plot() plt.axis("equal") plt.pause(1.0) rx, ry = VisibilityRoadMap(expand_distance, do_plot=show_animation)\ .planning(sx, sy, gx, gy, obstacles) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.1) plt.show()
1,071
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.__init__
(self, expand_distance, do_plot=False)
24
26
def __init__(self, expand_distance, do_plot=False): self.expand_distance = expand_distance self.do_plot = do_plot
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L24-L26
2
[ 0, 1, 2 ]
100
[]
0
true
92.792793
3
1
100
0
def __init__(self, expand_distance, do_plot=False): self.expand_distance = expand_distance self.do_plot = do_plot
1,072
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.planning
(self, start_x, start_y, goal_x, goal_y, obstacles)
return rx, ry
28
47
def planning(self, start_x, start_y, goal_x, goal_y, obstacles): nodes = self.generate_visibility_nodes(start_x, start_y, goal_x, goal_y, obstacles) road_map_info = self.generate_road_map_info(nodes, obstacles) if self.do_plot: self.plot_road_map(nodes, road_map_info) plt.pause(1.0) rx, ry = DijkstraSearch(show_animation).search( start_x, start_y, goal_x, goal_y, [node.x for node in nodes], [node.y for node in nodes], road_map_info ) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L28-L47
2
[ 0, 1, 2, 4, 5, 6, 7, 10, 11, 18, 19 ]
55
[ 8, 9 ]
10
false
92.792793
20
4
90
0
def planning(self, start_x, start_y, goal_x, goal_y, obstacles): nodes = self.generate_visibility_nodes(start_x, start_y, goal_x, goal_y, obstacles) road_map_info = self.generate_road_map_info(nodes, obstacles) if self.do_plot: self.plot_road_map(nodes, road_map_info) plt.pause(1.0) rx, ry = DijkstraSearch(show_animation).search( start_x, start_y, goal_x, goal_y, [node.x for node in nodes], [node.y for node in nodes], road_map_info ) return rx, ry
1,073
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.generate_visibility_nodes
(self, start_x, start_y, goal_x, goal_y, obstacles)
return nodes
49
68
def generate_visibility_nodes(self, start_x, start_y, goal_x, goal_y, obstacles): # add start and goal as nodes nodes = [DijkstraSearch.Node(start_x, start_y), DijkstraSearch.Node(goal_x, goal_y, 0, None)] # add vertexes in configuration space as nodes for obstacle in obstacles: cvx_list, cvy_list = self.calc_vertexes_in_configuration_space( obstacle.x_list, obstacle.y_list) for (vx, vy) in zip(cvx_list, cvy_list): nodes.append(DijkstraSearch.Node(vx, vy)) for node in nodes: plt.plot(node.x, node.y, "xr") return nodes
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L49-L68
2
[ 0, 3, 4, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19 ]
75
[]
0
false
92.792793
20
4
100
0
def generate_visibility_nodes(self, start_x, start_y, goal_x, goal_y, obstacles): # add start and goal as nodes nodes = [DijkstraSearch.Node(start_x, start_y), DijkstraSearch.Node(goal_x, goal_y, 0, None)] # add vertexes in configuration space as nodes for obstacle in obstacles: cvx_list, cvy_list = self.calc_vertexes_in_configuration_space( obstacle.x_list, obstacle.y_list) for (vx, vy) in zip(cvx_list, cvy_list): nodes.append(DijkstraSearch.Node(vx, vy)) for node in nodes: plt.plot(node.x, node.y, "xr") return nodes
1,074
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.calc_vertexes_in_configuration_space
(self, x_list, y_list)
return cvx_list, cvy_list
70
86
def calc_vertexes_in_configuration_space(self, x_list, y_list): x_list = x_list[0:-1] y_list = y_list[0:-1] cvx_list, cvy_list = [], [] n_data = len(x_list) for index in range(n_data): offset_x, offset_y = self.calc_offset_xy( x_list[index - 1], y_list[index - 1], x_list[index], y_list[index], x_list[(index + 1) % n_data], y_list[(index + 1) % n_data], ) cvx_list.append(offset_x) cvy_list.append(offset_y) return cvx_list, cvy_list
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L70-L86
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 15, 16 ]
76.470588
[]
0
false
92.792793
17
2
100
0
def calc_vertexes_in_configuration_space(self, x_list, y_list): x_list = x_list[0:-1] y_list = y_list[0:-1] cvx_list, cvy_list = [], [] n_data = len(x_list) for index in range(n_data): offset_x, offset_y = self.calc_offset_xy( x_list[index - 1], y_list[index - 1], x_list[index], y_list[index], x_list[(index + 1) % n_data], y_list[(index + 1) % n_data], ) cvx_list.append(offset_x) cvy_list.append(offset_y) return cvx_list, cvy_list
1,075
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.generate_road_map_info
(self, nodes, obstacles)
return road_map_info_list
88
109
def generate_road_map_info(self, nodes, obstacles): road_map_info_list = [] for target_node in nodes: road_map_info = [] for node_id, node in enumerate(nodes): if np.hypot(target_node.x - node.x, target_node.y - node.y) <= 0.1: continue is_valid = True for obstacle in obstacles: if not self.is_edge_valid(target_node, node, obstacle): is_valid = False break if is_valid: road_map_info.append(node_id) road_map_info_list.append(road_map_info) return road_map_info_list
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L88-L109
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
95.454545
[]
0
false
92.792793
22
7
100
0
def generate_road_map_info(self, nodes, obstacles): road_map_info_list = [] for target_node in nodes: road_map_info = [] for node_id, node in enumerate(nodes): if np.hypot(target_node.x - node.x, target_node.y - node.y) <= 0.1: continue is_valid = True for obstacle in obstacles: if not self.is_edge_valid(target_node, node, obstacle): is_valid = False break if is_valid: road_map_info.append(node_id) road_map_info_list.append(road_map_info) return road_map_info_list
1,076
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.is_edge_valid
(target_node, node, obstacle)
return True
112
123
def is_edge_valid(target_node, node, obstacle): for i in range(len(obstacle.x_list) - 1): p1 = Geometry.Point(target_node.x, target_node.y) p2 = Geometry.Point(node.x, node.y) p3 = Geometry.Point(obstacle.x_list[i], obstacle.y_list[i]) p4 = Geometry.Point(obstacle.x_list[i + 1], obstacle.y_list[i + 1]) if Geometry.is_seg_intersect(p1, p2, p3, p4): return False return True
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L112-L123
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
92.792793
12
3
100
0
def is_edge_valid(target_node, node, obstacle): for i in range(len(obstacle.x_list) - 1): p1 = Geometry.Point(target_node.x, target_node.y) p2 = Geometry.Point(node.x, node.y) p3 = Geometry.Point(obstacle.x_list[i], obstacle.y_list[i]) p4 = Geometry.Point(obstacle.x_list[i + 1], obstacle.y_list[i + 1]) if Geometry.is_seg_intersect(p1, p2, p3, p4): return False return True
1,077
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.calc_offset_xy
(self, px, py, x, y, nx, ny)
return offset_x, offset_y
125
133
def calc_offset_xy(self, px, py, x, y, nx, ny): p_vec = math.atan2(y - py, x - px) n_vec = math.atan2(ny - y, nx - x) offset_vec = math.atan2(math.sin(p_vec) + math.sin(n_vec), math.cos(p_vec) + math.cos( n_vec)) + math.pi / 2.0 offset_x = x + self.expand_distance * math.cos(offset_vec) offset_y = y + self.expand_distance * math.sin(offset_vec) return offset_x, offset_y
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L125-L133
2
[ 0, 1, 2, 3, 6, 7, 8 ]
77.777778
[]
0
false
92.792793
9
1
100
0
def calc_offset_xy(self, px, py, x, y, nx, ny): p_vec = math.atan2(y - py, x - px) n_vec = math.atan2(ny - y, nx - x) offset_vec = math.atan2(math.sin(p_vec) + math.sin(n_vec), math.cos(p_vec) + math.cos( n_vec)) + math.pi / 2.0 offset_x = x + self.expand_distance * math.cos(offset_vec) offset_y = y + self.expand_distance * math.sin(offset_vec) return offset_x, offset_y
1,078
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
VisibilityRoadMap.plot_road_map
(nodes, road_map_info_list)
136
140
def plot_road_map(nodes, road_map_info_list): for i, node in enumerate(nodes): for index in road_map_info_list[i]: plt.plot([node.x, nodes[index].x], [node.y, nodes[index].y], "-b")
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L136-L140
2
[ 0 ]
20
[ 1, 2, 3 ]
60
false
92.792793
5
3
40
0
def plot_road_map(nodes, road_map_info_list): for i, node in enumerate(nodes): for index in road_map_info_list[i]: plt.plot([node.x, nodes[index].x], [node.y, nodes[index].y], "-b")
1,079
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
ObstaclePolygon.__init__
(self, x_list, y_list)
145
150
def __init__(self, x_list, y_list): self.x_list = x_list self.y_list = y_list self.close_polygon() self.make_clockwise()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L145-L150
2
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.792793
6
1
100
0
def __init__(self, x_list, y_list): self.x_list = x_list self.y_list = y_list self.close_polygon() self.make_clockwise()
1,080
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
ObstaclePolygon.make_clockwise
(self)
152
155
def make_clockwise(self): if not self.is_clockwise(): self.x_list = list(reversed(self.x_list)) self.y_list = list(reversed(self.y_list))
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L152-L155
2
[ 0, 1, 2, 3 ]
100
[]
0
true
92.792793
4
2
100
0
def make_clockwise(self): if not self.is_clockwise(): self.x_list = list(reversed(self.x_list)) self.y_list = list(reversed(self.y_list))
1,081
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
ObstaclePolygon.is_clockwise
(self)
return eval_sum >= 0
157
164
def is_clockwise(self): n_data = len(self.x_list) eval_sum = sum([(self.x_list[i + 1] - self.x_list[i]) * (self.y_list[i + 1] + self.y_list[i]) for i in range(n_data - 1)]) eval_sum += (self.x_list[0] - self.x_list[n_data - 1]) * \ (self.y_list[0] + self.y_list[n_data - 1]) return eval_sum >= 0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L157-L164
2
[ 0, 1, 2, 5, 7 ]
62.5
[]
0
false
92.792793
8
2
100
0
def is_clockwise(self): n_data = len(self.x_list) eval_sum = sum([(self.x_list[i + 1] - self.x_list[i]) * (self.y_list[i + 1] + self.y_list[i]) for i in range(n_data - 1)]) eval_sum += (self.x_list[0] - self.x_list[n_data - 1]) * \ (self.y_list[0] + self.y_list[n_data - 1]) return eval_sum >= 0
1,082
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
ObstaclePolygon.close_polygon
(self)
166
173
def close_polygon(self): is_x_same = self.x_list[0] == self.x_list[-1] is_y_same = self.y_list[0] == self.y_list[-1] if is_x_same and is_y_same: return # no need to close self.x_list.append(self.x_list[0]) self.y_list.append(self.y_list[0])
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L166-L173
2
[ 0, 1, 2, 3, 5, 6, 7 ]
87.5
[ 4 ]
12.5
false
92.792793
8
3
87.5
0
def close_polygon(self): is_x_same = self.x_list[0] == self.x_list[-1] is_y_same = self.y_list[0] == self.y_list[-1] if is_x_same and is_y_same: return # no need to close self.x_list.append(self.x_list[0]) self.y_list.append(self.y_list[0])
1,083
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/visibility_road_map.py
ObstaclePolygon.plot
(self)
175
176
def plot(self): plt.plot(self.x_list, self.y_list, "-k")
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/visibility_road_map.py#L175-L176
2
[ 0 ]
50
[ 1 ]
50
false
92.792793
2
1
50
0
def plot(self): plt.plot(self.x_list, self.y_list, "-k")
1,084
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VisibilityRoadMap/geometry.py
Geometry.is_seg_intersect
(p1, q1, p2, q2)
return False
9
44
def is_seg_intersect(p1, q1, p2, q2): def on_segment(p, q, r): if ((q.x <= max(p.x, r.x)) and (q.x >= min(p.x, r.x)) and (q.y <= max(p.y, r.y)) and (q.y >= min(p.y, r.y))): return True return False def orientation(p, q, r): val = (float(q.y - p.y) * (r.x - q.x)) - ( float(q.x - p.x) * (r.y - q.y)) if val > 0: return 1 if val < 0: return 2 return 0 # Find the 4 orientations required for # the general and special cases o1 = orientation(p1, q1, p2) o2 = orientation(p1, q1, q2) o3 = orientation(p2, q2, p1) o4 = orientation(p2, q2, q1) if (o1 != o2) and (o3 != o4): return True if (o1 == 0) and on_segment(p1, p2, q1): return True if (o2 == 0) and on_segment(p1, q2, q1): return True if (o3 == 0) and on_segment(p2, p1, q2): return True if (o4 == 0) and on_segment(p2, q1, q2): return True return False
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VisibilityRoadMap/geometry.py#L9-L44
2
[ 0, 1, 2, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 32, 34, 35 ]
75
[ 3, 5, 6, 27, 29, 31, 33 ]
19.444444
false
78.787879
36
19
80.555556
0
def is_seg_intersect(p1, q1, p2, q2): def on_segment(p, q, r): if ((q.x <= max(p.x, r.x)) and (q.x >= min(p.x, r.x)) and (q.y <= max(p.y, r.y)) and (q.y >= min(p.y, r.y))): return True return False def orientation(p, q, r): val = (float(q.y - p.y) * (r.x - q.x)) - ( float(q.x - p.x) * (r.y - q.y)) if val > 0: return 1 if val < 0: return 2 return 0 # Find the 4 orientations required for # the general and special cases o1 = orientation(p1, q1, p2) o2 = orientation(p1, q1, q2) o3 = orientation(p2, q2, p1) o4 = orientation(p2, q2, q1) if (o1 != o2) and (o3 != o4): return True if (o1 == 0) and on_segment(p1, p2, q1): return True if (o2 == 0) and on_segment(p1, q2, q1): return True if (o3 == 0) and on_segment(p2, p1, q2): return True if (o4 == 0) and on_segment(p2, q1, q2): return True return False
1,085
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
main
()
135
182
def main(): print(__file__ + " start!!") # start and goal position sx = 10.0 # [m] sy = 10.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] robot_size = 5.0 # [m] ox = [] oy = [] for i in range(60): ox.append(i) oy.append(0.0) for i in range(60): ox.append(60.0) oy.append(i) for i in range(61): ox.append(i) oy.append(60.0) for i in range(61): ox.append(0.0) oy.append(i) for i in range(40): ox.append(20.0) oy.append(i) for i in range(40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "^r") plt.plot(gx, gy, "^c") plt.grid(True) plt.axis("equal") rx, ry = VoronoiRoadMapPlanner().planning(sx, sy, gx, gy, ox, oy, robot_size) assert rx, 'Cannot found path' if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.1) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L135-L182
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 38, 39, 41, 42, 43 ]
97.368421
[]
0
false
98.989899
48
10
100
0
def main(): print(__file__ + " start!!") # start and goal position sx = 10.0 # [m] sy = 10.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] robot_size = 5.0 # [m] ox = [] oy = [] for i in range(60): ox.append(i) oy.append(0.0) for i in range(60): ox.append(60.0) oy.append(i) for i in range(61): ox.append(i) oy.append(60.0) for i in range(61): ox.append(0.0) oy.append(i) for i in range(40): ox.append(20.0) oy.append(i) for i in range(40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "^r") plt.plot(gx, gy, "^c") plt.grid(True) plt.axis("equal") rx, ry = VoronoiRoadMapPlanner().planning(sx, sy, gx, gy, ox, oy, robot_size) assert rx, 'Cannot found path' if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.1) plt.show()
1,086
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.__init__
(self)
24
27
def __init__(self): # parameter self.N_KNN = 10 # number of edge from one sampled point self.MAX_EDGE_LEN = 30.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L24-L27
2
[ 0, 1, 2, 3 ]
100
[]
0
true
98.989899
4
1
100
0
def __init__(self): # parameter self.N_KNN = 10 # number of edge from one sampled point self.MAX_EDGE_LEN = 30.0
1,087
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.planning
(self, sx, sy, gx, gy, ox, oy, robot_radius)
return rx, ry
29
42
def planning(self, sx, sy, gx, gy, ox, oy, robot_radius): obstacle_tree = cKDTree(np.vstack((ox, oy)).T) sample_x, sample_y = self.voronoi_sampling(sx, sy, gx, gy, ox, oy) if show_animation: # pragma: no cover plt.plot(sample_x, sample_y, ".b") road_map_info = self.generate_road_map_info( sample_x, sample_y, robot_radius, obstacle_tree) rx, ry = DijkstraSearch(show_animation).search(sx, sy, gx, gy, sample_x, sample_y, road_map_info) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L29-L42
2
[ 0, 1, 2, 3, 6, 7, 9, 10, 13 ]
75
[]
0
false
98.989899
14
2
100
0
def planning(self, sx, sy, gx, gy, ox, oy, robot_radius): obstacle_tree = cKDTree(np.vstack((ox, oy)).T) sample_x, sample_y = self.voronoi_sampling(sx, sy, gx, gy, ox, oy) if show_animation: # pragma: no cover plt.plot(sample_x, sample_y, ".b") road_map_info = self.generate_road_map_info( sample_x, sample_y, robot_radius, obstacle_tree) rx, ry = DijkstraSearch(show_animation).search(sx, sy, gx, gy, sample_x, sample_y, road_map_info) return rx, ry
1,088
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.is_collision
(self, sx, sy, gx, gy, rr, obstacle_kd_tree)
return False
44
70
def is_collision(self, sx, sy, gx, gy, rr, obstacle_kd_tree): x = sx y = sy dx = gx - sx dy = gy - sy yaw = math.atan2(gy - sy, gx - sx) d = math.hypot(dx, dy) if d >= self.MAX_EDGE_LEN: return True D = rr n_step = round(d / D) for i in range(n_step): dist, _ = obstacle_kd_tree.query([x, y]) if dist <= rr: return True # collision x += D * math.cos(yaw) y += D * math.sin(yaw) # goal point check dist, _ = obstacle_kd_tree.query([gx, gy]) if dist <= rr: return True # collision return False
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L44-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 ]
100
[]
0
true
98.989899
27
5
100
0
def is_collision(self, sx, sy, gx, gy, rr, obstacle_kd_tree): x = sx y = sy dx = gx - sx dy = gy - sy yaw = math.atan2(gy - sy, gx - sx) d = math.hypot(dx, dy) if d >= self.MAX_EDGE_LEN: return True D = rr n_step = round(d / D) for i in range(n_step): dist, _ = obstacle_kd_tree.query([x, y]) if dist <= rr: return True # collision x += D * math.cos(yaw) y += D * math.sin(yaw) # goal point check dist, _ = obstacle_kd_tree.query([gx, gy]) if dist <= rr: return True # collision return False
1,089
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.generate_road_map_info
(self, node_x, node_y, rr, obstacle_tree)
return road_map
Road map generation node_x: [m] x positions of sampled points node_y: [m] y positions of sampled points rr: Robot Radius[m] obstacle_tree: KDTree object of obstacles
Road map generation
72
106
def generate_road_map_info(self, node_x, node_y, rr, obstacle_tree): """ Road map generation node_x: [m] x positions of sampled points node_y: [m] y positions of sampled points rr: Robot Radius[m] obstacle_tree: KDTree object of obstacles """ road_map = [] n_sample = len(node_x) node_tree = cKDTree(np.vstack((node_x, node_y)).T) for (i, ix, iy) in zip(range(n_sample), node_x, node_y): dists, indexes = node_tree.query([ix, iy], k=n_sample) edge_id = [] for ii in range(1, len(indexes)): nx = node_x[indexes[ii]] ny = node_y[indexes[ii]] if not self.is_collision(ix, iy, nx, ny, rr, obstacle_tree): edge_id.append(indexes[ii]) if len(edge_id) >= self.N_KNN: break road_map.append(edge_id) # plot_road_map(road_map, sample_x, sample_y) return road_map
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L72-L106
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 ]
100
[]
0
true
98.989899
35
5
100
6
def generate_road_map_info(self, node_x, node_y, rr, obstacle_tree): road_map = [] n_sample = len(node_x) node_tree = cKDTree(np.vstack((node_x, node_y)).T) for (i, ix, iy) in zip(range(n_sample), node_x, node_y): dists, indexes = node_tree.query([ix, iy], k=n_sample) edge_id = [] for ii in range(1, len(indexes)): nx = node_x[indexes[ii]] ny = node_y[indexes[ii]] if not self.is_collision(ix, iy, nx, ny, rr, obstacle_tree): edge_id.append(indexes[ii]) if len(edge_id) >= self.N_KNN: break road_map.append(edge_id) # plot_road_map(road_map, sample_x, sample_y) return road_map
1,090
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.plot_road_map
(road_map, sample_x, sample_y)
109
116
def plot_road_map(road_map, sample_x, sample_y): # pragma: no cover for i, _ in enumerate(road_map): for ii in range(len(road_map[i])): ind = road_map[i][ii] plt.plot([sample_x[i], sample_x[ind]], [sample_y[i], sample_y[ind]], "-k")
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L109-L116
2
[]
0
[]
0
false
98.989899
8
3
100
0
def plot_road_map(road_map, sample_x, sample_y): # pragma: no cover for i, _ in enumerate(road_map): for ii in range(len(road_map[i])): ind = road_map[i][ii] plt.plot([sample_x[i], sample_x[ind]], [sample_y[i], sample_y[ind]], "-k")
1,091
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/voronoi_road_map.py
VoronoiRoadMapPlanner.voronoi_sampling
(sx, sy, gx, gy, ox, oy)
return sample_x, sample_y
119
132
def voronoi_sampling(sx, sy, gx, gy, ox, oy): oxy = np.vstack((ox, oy)).T # generate voronoi point vor = Voronoi(oxy) sample_x = [ix for [ix, _] in vor.vertices] sample_y = [iy for [_, iy] in vor.vertices] sample_x.append(sx) sample_y.append(sy) sample_x.append(gx) sample_y.append(gy) return sample_x, sample_y
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/voronoi_road_map.py#L119-L132
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
98.989899
14
3
100
0
def voronoi_sampling(sx, sy, gx, gy, ox, oy): oxy = np.vstack((ox, oy)).T # generate voronoi point vor = Voronoi(oxy) sample_x = [ix for [ix, _] in vor.vertices] sample_y = [iy for [_, iy] in vor.vertices] sample_x.append(sx) sample_y.append(sy) sample_x.append(gx) sample_y.append(gy) return sample_x, sample_y
1,092
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.__init__
(self, show_animation)
31
32
def __init__(self, show_animation): self.show_animation = show_animation
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L31-L32
2
[ 0, 1 ]
100
[]
0
true
94.805195
2
1
100
0
def __init__(self, show_animation): self.show_animation = show_animation
1,093
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.search
(self, sx, sy, gx, gy, node_x, node_y, edge_ids_list)
return rx, ry
Search shortest path s_x: start x positions [m] s_y: start y positions [m] gx: goal x position [m] gx: goal x position [m] node_x: node x position node_y: node y position edge_ids_list: edge_list each item includes a list of edge ids
Search shortest path
34
103
def search(self, sx, sy, gx, gy, node_x, node_y, edge_ids_list): """ Search shortest path s_x: start x positions [m] s_y: start y positions [m] gx: goal x position [m] gx: goal x position [m] node_x: node x position node_y: node y position edge_ids_list: edge_list each item includes a list of edge ids """ start_node = self.Node(sx, sy, 0.0, -1) goal_node = self.Node(gx, gy, 0.0, -1) current_node = None open_set, close_set = dict(), dict() open_set[self.find_id(node_x, node_y, start_node)] = start_node while True: if self.has_node_in_set(close_set, goal_node): print("goal is found!") goal_node.parent = current_node.parent goal_node.cost = current_node.cost break elif not open_set: print("Cannot find path") break current_id = min(open_set, key=lambda o: open_set[o].cost) current_node = open_set[current_id] # show graph if self.show_animation and len( close_set.keys()) % 2 == 0: # pragma: no cover plt.plot(current_node.x, current_node.y, "xg") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) plt.pause(0.1) # Remove the item from the open set del open_set[current_id] # Add it to the closed set close_set[current_id] = current_node # expand search grid based on motion model for i in range(len(edge_ids_list[current_id])): n_id = edge_ids_list[current_id][i] dx = node_x[n_id] - current_node.x dy = node_y[n_id] - current_node.y d = math.hypot(dx, dy) node = self.Node(node_x[n_id], node_y[n_id], current_node.cost + d, current_id) if n_id in close_set: continue # Otherwise if it is already in the open set if n_id in open_set: if open_set[n_id].cost > node.cost: open_set[n_id] = node else: open_set[n_id] = node # generate final course rx, ry = self.generate_final_path(close_set, goal_node) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L34-L103
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, 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 ]
103.030303
[ 27, 28 ]
3.030303
false
94.805195
70
10
96.969697
9
def search(self, sx, sy, gx, gy, node_x, node_y, edge_ids_list): start_node = self.Node(sx, sy, 0.0, -1) goal_node = self.Node(gx, gy, 0.0, -1) current_node = None open_set, close_set = dict(), dict() open_set[self.find_id(node_x, node_y, start_node)] = start_node while True: if self.has_node_in_set(close_set, goal_node): print("goal is found!") goal_node.parent = current_node.parent goal_node.cost = current_node.cost break elif not open_set: print("Cannot find path") break current_id = min(open_set, key=lambda o: open_set[o].cost) current_node = open_set[current_id] # show graph if self.show_animation and len( close_set.keys()) % 2 == 0: # pragma: no cover plt.plot(current_node.x, current_node.y, "xg") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) plt.pause(0.1) # Remove the item from the open set del open_set[current_id] # Add it to the closed set close_set[current_id] = current_node # expand search grid based on motion model for i in range(len(edge_ids_list[current_id])): n_id = edge_ids_list[current_id][i] dx = node_x[n_id] - current_node.x dy = node_y[n_id] - current_node.y d = math.hypot(dx, dy) node = self.Node(node_x[n_id], node_y[n_id], current_node.cost + d, current_id) if n_id in close_set: continue # Otherwise if it is already in the open set if n_id in open_set: if open_set[n_id].cost > node.cost: open_set[n_id] = node else: open_set[n_id] = node # generate final course rx, ry = self.generate_final_path(close_set, goal_node) return rx, ry
1,094
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.generate_final_path
(close_set, goal_node)
return rx, ry
106
115
def generate_final_path(close_set, goal_node): rx, ry = [goal_node.x], [goal_node.y] parent = goal_node.parent while parent != -1: n = close_set[parent] rx.append(n.x) ry.append(n.y) parent = n.parent rx, ry = rx[::-1], ry[::-1] # reverse it return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L106-L115
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
94.805195
10
2
100
0
def generate_final_path(close_set, goal_node): rx, ry = [goal_node.x], [goal_node.y] parent = goal_node.parent while parent != -1: n = close_set[parent] rx.append(n.x) ry.append(n.y) parent = n.parent rx, ry = rx[::-1], ry[::-1] # reverse it return rx, ry
1,095
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.has_node_in_set
(self, target_set, node)
return False
117
121
def has_node_in_set(self, target_set, node): for key in target_set: if self.is_same_node(target_set[key], node): return True return False
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L117-L121
2
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
94.805195
5
3
100
0
def has_node_in_set(self, target_set, node): for key in target_set: if self.is_same_node(target_set[key], node): return True return False
1,096
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.find_id
(self, node_x_list, node_y_list, target_node)
return None
123
128
def find_id(self, node_x_list, node_y_list, target_node): for i, _ in enumerate(node_x_list): if self.is_same_node_with_xy(node_x_list[i], node_y_list[i], target_node): return i return None
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L123-L128
2
[ 0, 1, 2, 4 ]
66.666667
[ 5 ]
16.666667
false
94.805195
6
3
83.333333
0
def find_id(self, node_x_list, node_y_list, target_node): for i, _ in enumerate(node_x_list): if self.is_same_node_with_xy(node_x_list[i], node_y_list[i], target_node): return i return None
1,097
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.is_same_node_with_xy
(node_x, node_y, node_b)
return dist <= 0.1
131
134
def is_same_node_with_xy(node_x, node_y, node_b): dist = np.hypot(node_x - node_b.x, node_y - node_b.y) return dist <= 0.1
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L131-L134
2
[ 0, 1, 3 ]
75
[]
0
false
94.805195
4
1
100
0
def is_same_node_with_xy(node_x, node_y, node_b): dist = np.hypot(node_x - node_b.x, node_y - node_b.y) return dist <= 0.1
1,098
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/VoronoiRoadMap/dijkstra_search.py
DijkstraSearch.is_same_node
(node_a, node_b)
return dist <= 0.1
137
140
def is_same_node(node_a, node_b): dist = np.hypot(node_a.x - node_b.x, node_a.y - node_b.y) return dist <= 0.1
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/VoronoiRoadMap/dijkstra_search.py#L137-L140
2
[ 0, 1, 3 ]
75
[]
0
false
94.805195
4
1
100
0
def is_same_node(node_a, node_b): dist = np.hypot(node_a.x - node_b.x, node_a.y - node_b.y) return dist <= 0.1
1,099
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
search_nearest_one_from_lookup_table
(t_x, t_y, t_yaw, lookup_table)
return lookup_table[minid]
35
48
def search_nearest_one_from_lookup_table(t_x, t_y, t_yaw, lookup_table): mind = float("inf") minid = -1 for (i, table) in enumerate(lookup_table): dx = t_x - table[0] dy = t_y - table[1] dyaw = t_yaw - table[2] d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2) if d <= mind: minid = i mind = d return lookup_table[minid]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L35-L48
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
88.601036
14
3
100
0
def search_nearest_one_from_lookup_table(t_x, t_y, t_yaw, lookup_table): mind = float("inf") minid = -1 for (i, table) in enumerate(lookup_table): dx = t_x - table[0] dy = t_y - table[1] dyaw = t_yaw - table[2] d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2) if d <= mind: minid = i mind = d return lookup_table[minid]
1,100