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/StateLatticePlanner/state_lattice_planner.py
get_lookup_table
(table_path)
return np.loadtxt(table_path, delimiter=',', skiprows=1)
51
52
def get_lookup_table(table_path): return np.loadtxt(table_path, delimiter=',', skiprows=1)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L51-L52
2
[ 0, 1 ]
100
[]
0
true
88.601036
2
1
100
0
def get_lookup_table(table_path): return np.loadtxt(table_path, delimiter=',', skiprows=1)
1,101
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
generate_path
(target_states, k0)
return result
55
76
def generate_path(target_states, k0): # x, y, yaw, s, km, kf lookup_table = get_lookup_table(TABLE_PATH) result = [] for state in target_states: bestp = search_nearest_one_from_lookup_table( state[0], state[1], state[2], lookup_table) target = motion_model.State(x=state[0], y=state[1], yaw=state[2]) init_p = np.array( [np.hypot(state[0], state[1]), bestp[4], bestp[5]]).reshape(3, 1) x, y, yaw, p = planner.optimize_trajectory(target, k0, init_p) if x is not None: print("find good path") result.append( [x[-1], y[-1], yaw[-1], float(p[0]), float(p[1]), float(p[2])]) print("finish path generation") return result
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L55-L76
2
[ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 20, 21 ]
86.363636
[]
0
false
88.601036
22
3
100
0
def generate_path(target_states, k0): # x, y, yaw, s, km, kf lookup_table = get_lookup_table(TABLE_PATH) result = [] for state in target_states: bestp = search_nearest_one_from_lookup_table( state[0], state[1], state[2], lookup_table) target = motion_model.State(x=state[0], y=state[1], yaw=state[2]) init_p = np.array( [np.hypot(state[0], state[1]), bestp[4], bestp[5]]).reshape(3, 1) x, y, yaw, p = planner.optimize_trajectory(target, k0, init_p) if x is not None: print("find good path") result.append( [x[-1], y[-1], yaw[-1], float(p[0]), float(p[1]), float(p[2])]) print("finish path generation") return result
1,102
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
calc_uniform_polar_states
(nxy, nh, d, a_min, a_max, p_min, p_max)
return states
Parameters ---------- nxy : number of position sampling nh : number of heading sampleing d : distance of terminal state a_min : position sampling min angle a_max : position sampling max angle p_min : heading sampling min angle p_max : heading sampling max angle Returns -------
79
106
def calc_uniform_polar_states(nxy, nh, d, a_min, a_max, p_min, p_max): """ Parameters ---------- nxy : number of position sampling nh : number of heading sampleing d : distance of terminal state a_min : position sampling min angle a_max : position sampling max angle p_min : heading sampling min angle p_max : heading sampling max angle Returns ------- """ angle_samples = [i / (nxy - 1) for i in range(nxy)] states = sample_states(angle_samples, a_min, a_max, d, p_max, p_min, nh) return states
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L79-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 ]
100
[]
0
true
88.601036
28
2
100
19
def calc_uniform_polar_states(nxy, nh, d, a_min, a_max, p_min, p_max): angle_samples = [i / (nxy - 1) for i in range(nxy)] states = sample_states(angle_samples, a_min, a_max, d, p_max, p_min, nh) return states
1,103
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
calc_biased_polar_states
(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
return states
calc biased state :param goal_angle: goal orientation for biased sampling :param ns: number of biased sampling :param nxy: number of position sampling :param nxy: number of position sampling :param nh: number of heading sampleing :param d: distance of terminal state :param a_min: position sampling min angle :param a_max: position sampling max angle :param p_min: heading sampling min angle :param p_max: heading sampling max angle :return: states list
calc biased state
109
148
def calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max): """ calc biased state :param goal_angle: goal orientation for biased sampling :param ns: number of biased sampling :param nxy: number of position sampling :param nxy: number of position sampling :param nh: number of heading sampleing :param d: distance of terminal state :param a_min: position sampling min angle :param a_max: position sampling max angle :param p_min: heading sampling min angle :param p_max: heading sampling max angle :return: states list """ asi = [a_min + (a_max - a_min) * i / (ns - 1) for i in range(ns - 1)] cnav = [math.pi - abs(i - goal_angle) for i in asi] cnav_sum = sum(cnav) cnav_max = max(cnav) # normalize cnav = [(cnav_max - cnav[i]) / (cnav_max * ns - cnav_sum) for i in range(ns - 1)] csumnav = np.cumsum(cnav) di = [] li = 0 for i in range(nxy): for ii in range(li, ns - 1): if ii / ns >= i / (nxy - 1): di.append(csumnav[ii]) li = ii - 1 break states = sample_states(di, a_min, a_max, d, p_max, p_min, nh) return states
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L109-L148
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 ]
100
[]
0
true
88.601036
40
7
100
13
def calc_biased_polar_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max): asi = [a_min + (a_max - a_min) * i / (ns - 1) for i in range(ns - 1)] cnav = [math.pi - abs(i - goal_angle) for i in asi] cnav_sum = sum(cnav) cnav_max = max(cnav) # normalize cnav = [(cnav_max - cnav[i]) / (cnav_max * ns - cnav_sum) for i in range(ns - 1)] csumnav = np.cumsum(cnav) di = [] li = 0 for i in range(nxy): for ii in range(li, ns - 1): if ii / ns >= i / (nxy - 1): di.append(csumnav[ii]) li = ii - 1 break states = sample_states(di, a_min, a_max, d, p_max, p_min, nh) return states
1,104
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
calc_lane_states
(l_center, l_heading, l_width, v_width, d, nxy)
return states
calc lane states :param l_center: lane lateral position :param l_heading: lane heading :param l_width: lane width :param v_width: vehicle width :param d: longitudinal position :param nxy: sampling number :return: state list
151
176
def calc_lane_states(l_center, l_heading, l_width, v_width, d, nxy): """ calc lane states :param l_center: lane lateral position :param l_heading: lane heading :param l_width: lane width :param v_width: vehicle width :param d: longitudinal position :param nxy: sampling number :return: state list """ xc = d yc = l_center states = [] for i in range(nxy): delta = -0.5 * (l_width - v_width) + \ (l_width - v_width) * i / (nxy - 1) xf = xc - delta * math.sin(l_heading) yf = yc + delta * math.cos(l_heading) yawf = l_heading states.append([xf, yf, yawf]) return states
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L151-L176
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]
100
[]
0
true
88.601036
26
2
100
9
def calc_lane_states(l_center, l_heading, l_width, v_width, d, nxy): xc = d yc = l_center states = [] for i in range(nxy): delta = -0.5 * (l_width - v_width) + \ (l_width - v_width) * i / (nxy - 1) xf = xc - delta * math.sin(l_heading) yf = yc + delta * math.cos(l_heading) yawf = l_heading states.append([xf, yf, yawf]) return states
1,105
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
sample_states
(angle_samples, a_min, a_max, d, p_max, p_min, nh)
return states
179
193
def sample_states(angle_samples, a_min, a_max, d, p_max, p_min, nh): states = [] for i in angle_samples: a = a_min + (a_max - a_min) * i for j in range(nh): xf = d * math.cos(a) yf = d * math.sin(a) if nh == 1: yawf = (p_max - p_min) / 2 + a else: yawf = p_min + (p_max - p_min) * j / (nh - 1) + a states.append([xf, yf, yawf]) return states
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L179-L193
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14 ]
93.333333
[]
0
false
88.601036
15
4
100
0
def sample_states(angle_samples, a_min, a_max, d, p_max, p_min, nh): states = [] for i in angle_samples: a = a_min + (a_max - a_min) * i for j in range(nh): xf = d * math.cos(a) yf = d * math.sin(a) if nh == 1: yawf = (p_max - p_min) / 2 + a else: yawf = p_min + (p_max - p_min) * j / (nh - 1) + a states.append([xf, yf, yawf]) return states
1,106
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/StateLatticePlanner/state_lattice_planner.py
main
()
333
339
def main(): planner.show_animation = show_animation uniform_terminal_state_sampling_test1() uniform_terminal_state_sampling_test2() biased_terminal_state_sampling_test1() biased_terminal_state_sampling_test2() lane_state_sampling_test1()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/StateLatticePlanner/state_lattice_planner.py#L333-L339
2
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
88.601036
7
1
100
0
def main(): planner.show_animation = show_animation uniform_terminal_state_sampling_test1() uniform_terminal_state_sampling_test2() biased_terminal_state_sampling_test1() biased_terminal_state_sampling_test2() lane_state_sampling_test1()
1,107
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
main
()
209
254
def main(): print(__file__ + " start!!") # start and goal position sx = 10.0 # [m] sy = 10.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] grid_size = 2.0 # [m] robot_radius = 1.0 # [m] # set obstacle positions ox, oy = [], [] for i in range(-10, 60): ox.append(i) oy.append(-10.0) for i in range(-10, 60): ox.append(60.0) oy.append(i) for i in range(-10, 61): ox.append(i) oy.append(60.0) for i in range(-10, 61): ox.append(-10.0) oy.append(i) for i in range(-10, 40): ox.append(20.0) oy.append(i) for i in range(0, 40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "og") plt.plot(gx, gy, "xb") plt.grid(True) plt.axis("equal") bfs = BreadthFirstSearchPlanner(ox, oy, grid_size, robot_radius) rx, ry = bfs.planning(sx, sy, gx, gy) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.01) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L209-L254
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 38, 39, 40, 41 ]
100
[]
0
true
95.454545
46
9
100
0
def main(): print(__file__ + " start!!") # start and goal position sx = 10.0 # [m] sy = 10.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] grid_size = 2.0 # [m] robot_radius = 1.0 # [m] # set obstacle positions ox, oy = [], [] for i in range(-10, 60): ox.append(i) oy.append(-10.0) for i in range(-10, 60): ox.append(60.0) oy.append(i) for i in range(-10, 61): ox.append(i) oy.append(60.0) for i in range(-10, 61): ox.append(-10.0) oy.append(i) for i in range(-10, 40): ox.append(20.0) oy.append(i) for i in range(0, 40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "og") plt.plot(gx, gy, "xb") plt.grid(True) plt.axis("equal") bfs = BreadthFirstSearchPlanner(ox, oy, grid_size, robot_radius) rx, ry = bfs.planning(sx, sy, gx, gy) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.01) plt.show()
1,108
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.__init__
(self, ox, oy, reso, rr)
Initialize grid map for bfs planning ox: x position list of Obstacles [m] oy: y position list of Obstacles [m] resolution: grid resolution [m] rr: robot radius[m]
Initialize grid map for bfs planning
20
33
def __init__(self, ox, oy, reso, rr): """ Initialize grid map for bfs planning ox: x position list of Obstacles [m] oy: y position list of Obstacles [m] resolution: grid resolution [m] rr: robot radius[m] """ self.reso = reso self.rr = rr self.calc_obstacle_map(ox, oy) self.motion = self.get_motion_model()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L20-L33
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
95.454545
14
1
100
6
def __init__(self, ox, oy, reso, rr): self.reso = reso self.rr = rr self.calc_obstacle_map(ox, oy) self.motion = self.get_motion_model()
1,109
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.planning
(self, sx, sy, gx, gy)
return rx, ry
Breadth First search based planning input: s_x: start x position [m] s_y: start y position [m] gx: goal x position [m] gy: goal y position [m] output: rx: x position list of the final path ry: y position list of the final path
Breadth First search based planning
47
115
def planning(self, sx, sy, gx, gy): """ Breadth First search based planning input: s_x: start x position [m] s_y: start y position [m] gx: goal x position [m] gy: goal y position [m] output: rx: x position list of the final path ry: y position list of the final path """ nstart = self.Node(self.calc_xyindex(sx, self.minx), self.calc_xyindex(sy, self.miny), 0.0, -1, None) ngoal = self.Node(self.calc_xyindex(gx, self.minx), self.calc_xyindex(gy, self.miny), 0.0, -1, None) open_set, closed_set = dict(), dict() open_set[self.calc_grid_index(nstart)] = nstart while True: if len(open_set) == 0: print("Open set is empty..") break current = open_set.pop(list(open_set.keys())[0]) c_id = self.calc_grid_index(current) closed_set[c_id] = current # show graph if show_animation: # pragma: no cover plt.plot(self.calc_grid_position(current.x, self.minx), self.calc_grid_position(current.y, self.miny), "xc") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect('key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) if len(closed_set.keys()) % 10 == 0: plt.pause(0.001) if current.x == ngoal.x and current.y == ngoal.y: print("Find goal") ngoal.parent_index = current.parent_index ngoal.cost = current.cost break # expand_grid search grid based on motion model for i, _ in enumerate(self.motion): node = self.Node(current.x + self.motion[i][0], current.y + self.motion[i][1], current.cost + self.motion[i][2], c_id, None) n_id = self.calc_grid_index(node) # If the node is not safe, do nothing if not self.verify_node(node): continue if (n_id not in closed_set) and (n_id not in open_set): node.parent = current open_set[n_id] = node rx, ry = self.calc_final_path(ngoal, closed_set) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L47-L115
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68 ]
104.6875
[ 25, 26 ]
3.125
false
95.454545
69
11
96.875
11
def planning(self, sx, sy, gx, gy): nstart = self.Node(self.calc_xyindex(sx, self.minx), self.calc_xyindex(sy, self.miny), 0.0, -1, None) ngoal = self.Node(self.calc_xyindex(gx, self.minx), self.calc_xyindex(gy, self.miny), 0.0, -1, None) open_set, closed_set = dict(), dict() open_set[self.calc_grid_index(nstart)] = nstart while True: if len(open_set) == 0: print("Open set is empty..") break current = open_set.pop(list(open_set.keys())[0]) c_id = self.calc_grid_index(current) closed_set[c_id] = current # show graph if show_animation: # pragma: no cover plt.plot(self.calc_grid_position(current.x, self.minx), self.calc_grid_position(current.y, self.miny), "xc") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect('key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) if len(closed_set.keys()) % 10 == 0: plt.pause(0.001) if current.x == ngoal.x and current.y == ngoal.y: print("Find goal") ngoal.parent_index = current.parent_index ngoal.cost = current.cost break # expand_grid search grid based on motion model for i, _ in enumerate(self.motion): node = self.Node(current.x + self.motion[i][0], current.y + self.motion[i][1], current.cost + self.motion[i][2], c_id, None) n_id = self.calc_grid_index(node) # If the node is not safe, do nothing if not self.verify_node(node): continue if (n_id not in closed_set) and (n_id not in open_set): node.parent = current open_set[n_id] = node rx, ry = self.calc_final_path(ngoal, closed_set) return rx, ry
1,110
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.calc_final_path
(self, ngoal, closedset)
return rx, ry
117
127
def calc_final_path(self, ngoal, closedset): # generate final course rx, ry = [self.calc_grid_position(ngoal.x, self.minx)], [ self.calc_grid_position(ngoal.y, self.miny)] n = closedset[ngoal.parent_index] while n is not None: rx.append(self.calc_grid_position(n.x, self.minx)) ry.append(self.calc_grid_position(n.y, self.miny)) n = n.parent return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L117-L127
2
[ 0, 1, 2, 4, 5, 6, 7, 8, 9, 10 ]
90.909091
[]
0
false
95.454545
11
2
100
0
def calc_final_path(self, ngoal, closedset): # generate final course rx, ry = [self.calc_grid_position(ngoal.x, self.minx)], [ self.calc_grid_position(ngoal.y, self.miny)] n = closedset[ngoal.parent_index] while n is not None: rx.append(self.calc_grid_position(n.x, self.minx)) ry.append(self.calc_grid_position(n.y, self.miny)) n = n.parent return rx, ry
1,111
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.calc_grid_position
(self, index, minp)
return pos
calc grid position :param index: :param minp: :return:
calc grid position
129
138
def calc_grid_position(self, index, minp): """ calc grid position :param index: :param minp: :return: """ pos = index * self.reso + minp return pos
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L129-L138
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
95.454545
10
1
100
5
def calc_grid_position(self, index, minp): pos = index * self.reso + minp return pos
1,112
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.calc_xyindex
(self, position, min_pos)
return round((position - min_pos) / self.reso)
140
141
def calc_xyindex(self, position, min_pos): return round((position - min_pos) / self.reso)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L140-L141
2
[ 0, 1 ]
100
[]
0
true
95.454545
2
1
100
0
def calc_xyindex(self, position, min_pos): return round((position - min_pos) / self.reso)
1,113
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.calc_grid_index
(self, node)
return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
143
144
def calc_grid_index(self, node): return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L143-L144
2
[ 0, 1 ]
100
[]
0
true
95.454545
2
1
100
0
def calc_grid_index(self, node): return (node.y - self.miny) * self.xwidth + (node.x - self.minx)
1,114
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.verify_node
(self, node)
return True
146
163
def verify_node(self, node): px = self.calc_grid_position(node.x, self.minx) py = self.calc_grid_position(node.y, self.miny) if px < self.minx: return False elif py < self.miny: return False elif px >= self.maxx: return False elif py >= self.maxy: return False # collision check if self.obmap[node.x][node.y]: return False return True
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L146-L163
2
[ 0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
88.888889
[ 5, 7 ]
11.111111
false
95.454545
18
6
88.888889
0
def verify_node(self, node): px = self.calc_grid_position(node.x, self.minx) py = self.calc_grid_position(node.y, self.miny) if px < self.minx: return False elif py < self.miny: return False elif px >= self.maxx: return False elif py >= self.maxy: return False # collision check if self.obmap[node.x][node.y]: return False return True
1,115
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.calc_obstacle_map
(self, ox, oy)
165
192
def calc_obstacle_map(self, ox, oy): self.minx = round(min(ox)) self.miny = round(min(oy)) self.maxx = round(max(ox)) self.maxy = round(max(oy)) print("min_x:", self.minx) print("min_y:", self.miny) print("max_x:", self.maxx) print("max_y:", self.maxy) self.xwidth = round((self.maxx - self.minx) / self.reso) self.ywidth = round((self.maxy - self.miny) / self.reso) print("x_width:", self.xwidth) print("y_width:", self.ywidth) # obstacle map generation self.obmap = [[False for _ in range(self.ywidth)] for _ in range(self.xwidth)] for ix in range(self.xwidth): x = self.calc_grid_position(ix, self.minx) for iy in range(self.ywidth): y = self.calc_grid_position(iy, self.miny) for iox, ioy in zip(ox, oy): d = math.hypot(iox - x, ioy - y) if d <= self.rr: self.obmap[ix][iy] = True break
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L165-L192
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
96.428571
[]
0
false
95.454545
28
7
100
0
def calc_obstacle_map(self, ox, oy): self.minx = round(min(ox)) self.miny = round(min(oy)) self.maxx = round(max(ox)) self.maxy = round(max(oy)) print("min_x:", self.minx) print("min_y:", self.miny) print("max_x:", self.maxx) print("max_y:", self.maxy) self.xwidth = round((self.maxx - self.minx) / self.reso) self.ywidth = round((self.maxy - self.miny) / self.reso) print("x_width:", self.xwidth) print("y_width:", self.ywidth) # obstacle map generation self.obmap = [[False for _ in range(self.ywidth)] for _ in range(self.xwidth)] for ix in range(self.xwidth): x = self.calc_grid_position(ix, self.minx) for iy in range(self.ywidth): y = self.calc_grid_position(iy, self.miny) for iox, ioy in zip(ox, oy): d = math.hypot(iox - x, ioy - y) if d <= self.rr: self.obmap[ix][iy] = True break
1,116
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BreadthFirstSearch/breadth_first_search.py
BreadthFirstSearchPlanner.get_motion_model
()
return motion
195
206
def get_motion_model(): # dx, dy, cost motion = [[1, 0, 1], [0, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, math.sqrt(2)], [-1, 1, math.sqrt(2)], [1, -1, math.sqrt(2)], [1, 1, math.sqrt(2)]] return motion
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BreadthFirstSearch/breadth_first_search.py#L195-L206
2
[ 0, 1, 2, 10, 11 ]
41.666667
[]
0
false
95.454545
12
1
100
0
def get_motion_model(): # dx, dy, cost motion = [[1, 0, 1], [0, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, math.sqrt(2)], [-1, 1, math.sqrt(2)], [1, -1, math.sqrt(2)], [1, 1, math.sqrt(2)]] return motion
1,117
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
prm_planning
(start_x, start_y, goal_x, goal_y, obstacle_x_list, obstacle_y_list, robot_radius, *, rng=None)
return rx, ry
Run probabilistic road map planning :param start_x: start x position :param start_y: start y position :param goal_x: goal x position :param goal_y: goal y position :param obstacle_x_list: obstacle x positions :param obstacle_y_list: obstacle y positions :param robot_radius: robot radius :param rng: (Optional) Random generator :return:
Run probabilistic road map planning
38
68
def prm_planning(start_x, start_y, goal_x, goal_y, obstacle_x_list, obstacle_y_list, robot_radius, *, rng=None): """ Run probabilistic road map planning :param start_x: start x position :param start_y: start y position :param goal_x: goal x position :param goal_y: goal y position :param obstacle_x_list: obstacle x positions :param obstacle_y_list: obstacle y positions :param robot_radius: robot radius :param rng: (Optional) Random generator :return: """ obstacle_kd_tree = KDTree(np.vstack((obstacle_x_list, obstacle_y_list)).T) sample_x, sample_y = sample_points(start_x, start_y, goal_x, goal_y, robot_radius, obstacle_x_list, obstacle_y_list, obstacle_kd_tree, rng) if show_animation: plt.plot(sample_x, sample_y, ".b") road_map = generate_road_map(sample_x, sample_y, robot_radius, obstacle_kd_tree) rx, ry = dijkstra_planning( start_x, start_y, goal_x, goal_y, road_map, sample_x, sample_y) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py#L38-L68
2
[ 0, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30 ]
54.83871
[ 22 ]
3.225806
false
86.982249
31
2
96.774194
11
def prm_planning(start_x, start_y, goal_x, goal_y, obstacle_x_list, obstacle_y_list, robot_radius, *, rng=None): obstacle_kd_tree = KDTree(np.vstack((obstacle_x_list, obstacle_y_list)).T) sample_x, sample_y = sample_points(start_x, start_y, goal_x, goal_y, robot_radius, obstacle_x_list, obstacle_y_list, obstacle_kd_tree, rng) if show_animation: plt.plot(sample_x, sample_y, ".b") road_map = generate_road_map(sample_x, sample_y, robot_radius, obstacle_kd_tree) rx, ry = dijkstra_planning( start_x, start_y, goal_x, goal_y, road_map, sample_x, sample_y) return rx, ry
1,118
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
is_collision
(sx, sy, gx, gy, rr, obstacle_kd_tree)
return False
71
97
def is_collision(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 >= 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/ProbabilisticRoadMap/probabilistic_road_map.py#L71-L97
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 25, 26 ]
88.888889
[ 9, 17, 24 ]
11.111111
false
86.982249
27
5
88.888889
0
def is_collision(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 >= 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,119
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
generate_road_map
(sample_x, sample_y, rr, obstacle_kd_tree)
return road_map
Road map generation sample_x: [m] x positions of sampled points sample_y: [m] y positions of sampled points robot_radius: Robot Radius[m] obstacle_kd_tree: KDTree object of obstacles
Road map generation
100
133
def generate_road_map(sample_x, sample_y, rr, obstacle_kd_tree): """ Road map generation sample_x: [m] x positions of sampled points sample_y: [m] y positions of sampled points robot_radius: Robot Radius[m] obstacle_kd_tree: KDTree object of obstacles """ road_map = [] n_sample = len(sample_x) sample_kd_tree = KDTree(np.vstack((sample_x, sample_y)).T) for (i, ix, iy) in zip(range(n_sample), sample_x, sample_y): dists, indexes = sample_kd_tree.query([ix, iy], k=n_sample) edge_id = [] for ii in range(1, len(indexes)): nx = sample_x[indexes[ii]] ny = sample_y[indexes[ii]] if not is_collision(ix, iy, nx, ny, rr, obstacle_kd_tree): edge_id.append(indexes[ii]) if len(edge_id) >= 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/ProbabilisticRoadMap/probabilistic_road_map.py#L100-L133
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
86.982249
34
5
100
6
def generate_road_map(sample_x, sample_y, rr, obstacle_kd_tree): road_map = [] n_sample = len(sample_x) sample_kd_tree = KDTree(np.vstack((sample_x, sample_y)).T) for (i, ix, iy) in zip(range(n_sample), sample_x, sample_y): dists, indexes = sample_kd_tree.query([ix, iy], k=n_sample) edge_id = [] for ii in range(1, len(indexes)): nx = sample_x[indexes[ii]] ny = sample_y[indexes[ii]] if not is_collision(ix, iy, nx, ny, rr, obstacle_kd_tree): edge_id.append(indexes[ii]) if len(edge_id) >= N_KNN: break road_map.append(edge_id) # plot_road_map(road_map, sample_x, sample_y) return road_map
1,120
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
dijkstra_planning
(sx, sy, gx, gy, road_map, sample_x, sample_y)
return rx, ry
s_x: start x position [m] s_y: start y position [m] goal_x: goal x position [m] goal_y: goal y position [m] obstacle_x_list: x position list of Obstacles [m] obstacle_y_list: y position list of Obstacles [m] robot_radius: robot radius [m] road_map: ??? [m] sample_x: ??? [m] sample_y: ??? [m] @return: Two lists of path coordinates ([x1, x2, ...], [y1, y2, ...]), empty list when no path was found
s_x: start x position [m] s_y: start y position [m] goal_x: goal x position [m] goal_y: goal y position [m] obstacle_x_list: x position list of Obstacles [m] obstacle_y_list: y position list of Obstacles [m] robot_radius: robot radius [m] road_map: ??? [m] sample_x: ??? [m] sample_y: ??? [m]
136
220
def dijkstra_planning(sx, sy, gx, gy, road_map, sample_x, sample_y): """ s_x: start x position [m] s_y: start y position [m] goal_x: goal x position [m] goal_y: goal y position [m] obstacle_x_list: x position list of Obstacles [m] obstacle_y_list: y position list of Obstacles [m] robot_radius: robot radius [m] road_map: ??? [m] sample_x: ??? [m] sample_y: ??? [m] @return: Two lists of path coordinates ([x1, x2, ...], [y1, y2, ...]), empty list when no path was found """ start_node = Node(sx, sy, 0.0, -1) goal_node = Node(gx, gy, 0.0, -1) open_set, closed_set = dict(), dict() open_set[len(road_map) - 2] = start_node path_found = True while True: if not open_set: print("Cannot find path") path_found = False break c_id = min(open_set, key=lambda o: open_set[o].cost) current = open_set[c_id] # show graph if show_animation and len(closed_set.keys()) % 2 == 0: # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) plt.plot(current.x, current.y, "xg") plt.pause(0.001) if c_id == (len(road_map) - 1): print("goal is found!") goal_node.parent_index = current.parent_index goal_node.cost = current.cost break # Remove the item from the open set del open_set[c_id] # Add it to the closed set closed_set[c_id] = current # expand search grid based on motion model for i in range(len(road_map[c_id])): n_id = road_map[c_id][i] dx = sample_x[n_id] - current.x dy = sample_y[n_id] - current.y d = math.hypot(dx, dy) node = Node(sample_x[n_id], sample_y[n_id], current.cost + d, c_id) if n_id in closed_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].cost = node.cost open_set[n_id].parent_index = c_id else: open_set[n_id] = node if path_found is False: return [], [] # generate final course rx, ry = [goal_node.x], [goal_node.y] parent_index = goal_node.parent_index while parent_index != -1: n = closed_set[parent_index] rx.append(n.x) ry.append(n.y) parent_index = n.parent_index return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py#L136-L220
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, 29, 30, 31, 32, 33, 34, 35, 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, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84 ]
88.235294
[ 26, 27, 28, 36, 39, 40, 73 ]
8.235294
false
86.982249
85
12
91.764706
12
def dijkstra_planning(sx, sy, gx, gy, road_map, sample_x, sample_y): start_node = Node(sx, sy, 0.0, -1) goal_node = Node(gx, gy, 0.0, -1) open_set, closed_set = dict(), dict() open_set[len(road_map) - 2] = start_node path_found = True while True: if not open_set: print("Cannot find path") path_found = False break c_id = min(open_set, key=lambda o: open_set[o].cost) current = open_set[c_id] # show graph if show_animation and len(closed_set.keys()) % 2 == 0: # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) plt.plot(current.x, current.y, "xg") plt.pause(0.001) if c_id == (len(road_map) - 1): print("goal is found!") goal_node.parent_index = current.parent_index goal_node.cost = current.cost break # Remove the item from the open set del open_set[c_id] # Add it to the closed set closed_set[c_id] = current # expand search grid based on motion model for i in range(len(road_map[c_id])): n_id = road_map[c_id][i] dx = sample_x[n_id] - current.x dy = sample_y[n_id] - current.y d = math.hypot(dx, dy) node = Node(sample_x[n_id], sample_y[n_id], current.cost + d, c_id) if n_id in closed_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].cost = node.cost open_set[n_id].parent_index = c_id else: open_set[n_id] = node if path_found is False: return [], [] # generate final course rx, ry = [goal_node.x], [goal_node.y] parent_index = goal_node.parent_index while parent_index != -1: n = closed_set[parent_index] rx.append(n.x) ry.append(n.y) parent_index = n.parent_index return rx, ry
1,121
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
plot_road_map
(road_map, sample_x, sample_y)
223
230
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/ProbabilisticRoadMap/probabilistic_road_map.py#L223-L230
2
[]
0
[]
0
false
86.982249
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,122
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
sample_points
(sx, sy, gx, gy, rr, ox, oy, obstacle_kd_tree, rng)
return sample_x, sample_y
233
259
def sample_points(sx, sy, gx, gy, rr, ox, oy, obstacle_kd_tree, rng): max_x = max(ox) max_y = max(oy) min_x = min(ox) min_y = min(oy) sample_x, sample_y = [], [] if rng is None: rng = np.random.default_rng() while len(sample_x) <= N_SAMPLE: tx = (rng.random() * (max_x - min_x)) + min_x ty = (rng.random() * (max_y - min_y)) + min_y dist, index = obstacle_kd_tree.query([tx, ty]) if dist >= rr: sample_x.append(tx) sample_y.append(ty) 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/ProbabilisticRoadMap/probabilistic_road_map.py#L233-L259
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 ]
96.296296
[ 9 ]
3.703704
false
86.982249
27
4
96.296296
0
def sample_points(sx, sy, gx, gy, rr, ox, oy, obstacle_kd_tree, rng): max_x = max(ox) max_y = max(oy) min_x = min(ox) min_y = min(oy) sample_x, sample_y = [], [] if rng is None: rng = np.random.default_rng() while len(sample_x) <= N_SAMPLE: tx = (rng.random() * (max_x - min_x)) + min_x ty = (rng.random() * (max_y - min_y)) + min_y dist, index = obstacle_kd_tree.query([tx, ty]) if dist >= rr: sample_x.append(tx) sample_y.append(ty) sample_x.append(sx) sample_y.append(sy) sample_x.append(gx) sample_y.append(gy) return sample_x, sample_y
1,123
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
main
(rng=None)
262
308
def main(rng=None): 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: plt.plot(ox, oy, ".k") plt.plot(sx, sy, "^r") plt.plot(gx, gy, "^c") plt.grid(True) plt.axis("equal") rx, ry = prm_planning(sx, sy, gx, gy, ox, oy, robot_size, rng=rng) assert rx, 'Cannot found path' if show_animation: plt.plot(rx, ry, "-r") plt.pause(0.001) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py#L262-L308
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, 38, 39, 40, 41, 42, 43 ]
82.978723
[ 33, 34, 35, 36, 37, 44, 45, 46 ]
17.021277
false
86.982249
47
10
82.978723
0
def main(rng=None): 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: plt.plot(ox, oy, ".k") plt.plot(sx, sy, "^r") plt.plot(gx, gy, "^c") plt.grid(True) plt.axis("equal") rx, ry = prm_planning(sx, sy, gx, gy, ox, oy, robot_size, rng=rng) assert rx, 'Cannot found path' if show_animation: plt.plot(rx, ry, "-r") plt.pause(0.001) plt.show()
1,124
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
Node.__init__
(self, x, y, cost, parent_index)
27
31
def __init__(self, x, y, cost, parent_index): self.x = x self.y = y self.cost = cost self.parent_index = parent_index
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py#L27-L31
2
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
86.982249
5
1
100
0
def __init__(self, x, y, cost, parent_index): self.x = x self.y = y self.cost = cost self.parent_index = parent_index
1,125
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py
Node.__str__
(self)
return str(self.x) + "," + str(self.y) + "," +\ str(self.cost) + "," + str(self.parent_index)
33
35
def __str__(self): return str(self.x) + "," + str(self.y) + "," +\ str(self.cost) + "," + str(self.parent_index)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py#L33-L35
2
[ 0 ]
33.333333
[ 1 ]
33.333333
false
86.982249
3
1
66.666667
0
def __str__(self): return str(self.x) + "," + str(self.y) + "," +\ str(self.cost) + "," + str(self.parent_index)
1,126
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
find_sweep_direction_and_start_position
(ox, oy)
return vec, sweep_start_pos
123
138
def find_sweep_direction_and_start_position(ox, oy): # find sweep_direction max_dist = 0.0 vec = [0.0, 0.0] sweep_start_pos = [0.0, 0.0] for i in range(len(ox) - 1): dx = ox[i + 1] - ox[i] dy = oy[i + 1] - oy[i] d = np.hypot(dx, dy) if d > max_dist: max_dist = d vec = [dx, dy] sweep_start_pos = [ox[i], oy[i]] return vec, sweep_start_pos
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L123-L138
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
95
16
3
100
0
def find_sweep_direction_and_start_position(ox, oy): # find sweep_direction max_dist = 0.0 vec = [0.0, 0.0] sweep_start_pos = [0.0, 0.0] for i in range(len(ox) - 1): dx = ox[i + 1] - ox[i] dy = oy[i + 1] - oy[i] d = np.hypot(dx, dy) if d > max_dist: max_dist = d vec = [dx, dy] sweep_start_pos = [ox[i], oy[i]] return vec, sweep_start_pos
1,127
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
convert_grid_coordinate
(ox, oy, sweep_vec, sweep_start_position)
return converted_xy[:, 0], converted_xy[:, 1]
141
147
def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position): tx = [ix - sweep_start_position[0] for ix in ox] ty = [iy - sweep_start_position[1] for iy in oy] th = math.atan2(sweep_vec[1], sweep_vec[0]) converted_xy = np.stack([tx, ty]).T @ rot_mat_2d(th) return converted_xy[:, 0], converted_xy[:, 1]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L141-L147
2
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
95
7
3
100
0
def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position): tx = [ix - sweep_start_position[0] for ix in ox] ty = [iy - sweep_start_position[1] for iy in oy] th = math.atan2(sweep_vec[1], sweep_vec[0]) converted_xy = np.stack([tx, ty]).T @ rot_mat_2d(th) return converted_xy[:, 0], converted_xy[:, 1]
1,128
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
convert_global_coordinate
(x, y, sweep_vec, sweep_start_position)
return rx, ry
150
155
def convert_global_coordinate(x, y, sweep_vec, sweep_start_position): th = math.atan2(sweep_vec[1], sweep_vec[0]) converted_xy = np.stack([x, y]).T @ rot_mat_2d(-th) rx = [ix + sweep_start_position[0] for ix in converted_xy[:, 0]] ry = [iy + sweep_start_position[1] for iy in converted_xy[:, 1]] return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L150-L155
2
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
95
6
3
100
0
def convert_global_coordinate(x, y, sweep_vec, sweep_start_position): th = math.atan2(sweep_vec[1], sweep_vec[0]) converted_xy = np.stack([x, y]).T @ rot_mat_2d(-th) rx = [ix + sweep_start_position[0] for ix in converted_xy[:, 0]] ry = [iy + sweep_start_position[1] for iy in converted_xy[:, 1]] return rx, ry
1,129
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
search_free_grid_index_at_edge_y
(grid_map, from_upper=False)
return x_indexes, y_index
158
177
def search_free_grid_index_at_edge_y(grid_map, from_upper=False): y_index = None x_indexes = [] if from_upper: x_range = range(grid_map.height)[::-1] y_range = range(grid_map.width)[::-1] else: x_range = range(grid_map.height) y_range = range(grid_map.width) for iy in x_range: for ix in y_range: if not grid_map.check_occupied_from_xy_index(ix, iy): y_index = iy x_indexes.append(ix) if y_index: break return x_indexes, y_index
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L158-L177
2
[ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
95
[]
0
false
95
20
6
100
0
def search_free_grid_index_at_edge_y(grid_map, from_upper=False): y_index = None x_indexes = [] if from_upper: x_range = range(grid_map.height)[::-1] y_range = range(grid_map.width)[::-1] else: x_range = range(grid_map.height) y_range = range(grid_map.width) for iy in x_range: for ix in y_range: if not grid_map.check_occupied_from_xy_index(ix, iy): y_index = iy x_indexes.append(ix) if y_index: break return x_indexes, y_index
1,130
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
setup_grid_map
(ox, oy, resolution, sweep_direction, offset_grid=10)
return grid_map, x_inds_goal_y, goal_y
180
200
def setup_grid_map(ox, oy, resolution, sweep_direction, offset_grid=10): width = math.ceil((max(ox) - min(ox)) / resolution) + offset_grid height = math.ceil((max(oy) - min(oy)) / resolution) + offset_grid center_x = (np.max(ox) + np.min(ox)) / 2.0 center_y = (np.max(oy) + np.min(oy)) / 2.0 grid_map = GridMap(width, height, resolution, center_x, center_y) grid_map.print_grid_map_info() grid_map.set_value_from_polygon(ox, oy, 1.0, inside=False) grid_map.expand_grid() x_inds_goal_y = [] goal_y = 0 if sweep_direction == SweepSearcher.SweepDirection.UP: x_inds_goal_y, goal_y = search_free_grid_index_at_edge_y( grid_map, from_upper=True) elif sweep_direction == SweepSearcher.SweepDirection.DOWN: x_inds_goal_y, goal_y = search_free_grid_index_at_edge_y( grid_map, from_upper=False) return grid_map, x_inds_goal_y, goal_y
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L180-L200
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20 ]
90.47619
[]
0
false
95
21
3
100
0
def setup_grid_map(ox, oy, resolution, sweep_direction, offset_grid=10): width = math.ceil((max(ox) - min(ox)) / resolution) + offset_grid height = math.ceil((max(oy) - min(oy)) / resolution) + offset_grid center_x = (np.max(ox) + np.min(ox)) / 2.0 center_y = (np.max(oy) + np.min(oy)) / 2.0 grid_map = GridMap(width, height, resolution, center_x, center_y) grid_map.print_grid_map_info() grid_map.set_value_from_polygon(ox, oy, 1.0, inside=False) grid_map.expand_grid() x_inds_goal_y = [] goal_y = 0 if sweep_direction == SweepSearcher.SweepDirection.UP: x_inds_goal_y, goal_y = search_free_grid_index_at_edge_y( grid_map, from_upper=True) elif sweep_direction == SweepSearcher.SweepDirection.DOWN: x_inds_goal_y, goal_y = search_free_grid_index_at_edge_y( grid_map, from_upper=False) return grid_map, x_inds_goal_y, goal_y
1,131
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
sweep_path_search
(sweep_searcher, grid_map, grid_search_animation=False)
return px, py
203
244
def sweep_path_search(sweep_searcher, grid_map, grid_search_animation=False): # search start grid c_x_index, c_y_index = sweep_searcher.search_start_grid(grid_map) if not grid_map.set_value_from_xy_index(c_x_index, c_y_index, 0.5): print("Cannot find start grid") return [], [] x, y = grid_map.calc_grid_central_xy_position_from_xy_index(c_x_index, c_y_index) px, py = [x], [y] fig, ax = None, None if grid_search_animation: fig, ax = plt.subplots() # for stopping simulation with the esc key. fig.canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) while True: c_x_index, c_y_index = sweep_searcher.move_target_grid(c_x_index, c_y_index, grid_map) if sweep_searcher.is_search_done(grid_map) or ( c_x_index is None or c_y_index is None): print("Done") break x, y = grid_map.calc_grid_central_xy_position_from_xy_index( c_x_index, c_y_index) px.append(x) py.append(y) grid_map.set_value_from_xy_index(c_x_index, c_y_index, 0.5) if grid_search_animation: grid_map.plot_grid_map(ax=ax) plt.pause(1.0) return px, py
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L203-L244
2
[ 0, 1, 2, 3, 6, 7, 9, 10, 11, 12, 18, 19, 20, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 40, 41 ]
66.666667
[ 4, 5, 13, 15, 38, 39 ]
14.285714
false
95
42
8
85.714286
0
def sweep_path_search(sweep_searcher, grid_map, grid_search_animation=False): # search start grid c_x_index, c_y_index = sweep_searcher.search_start_grid(grid_map) if not grid_map.set_value_from_xy_index(c_x_index, c_y_index, 0.5): print("Cannot find start grid") return [], [] x, y = grid_map.calc_grid_central_xy_position_from_xy_index(c_x_index, c_y_index) px, py = [x], [y] fig, ax = None, None if grid_search_animation: fig, ax = plt.subplots() # for stopping simulation with the esc key. fig.canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) while True: c_x_index, c_y_index = sweep_searcher.move_target_grid(c_x_index, c_y_index, grid_map) if sweep_searcher.is_search_done(grid_map) or ( c_x_index is None or c_y_index is None): print("Done") break x, y = grid_map.calc_grid_central_xy_position_from_xy_index( c_x_index, c_y_index) px.append(x) py.append(y) grid_map.set_value_from_xy_index(c_x_index, c_y_index, 0.5) if grid_search_animation: grid_map.plot_grid_map(ax=ax) plt.pause(1.0) return px, py
1,132
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
planning
(ox, oy, resolution, moving_direction=SweepSearcher.MovingDirection.RIGHT, sweeping_direction=SweepSearcher.SweepDirection.UP, )
return rx, ry
247
270
def planning(ox, oy, resolution, moving_direction=SweepSearcher.MovingDirection.RIGHT, sweeping_direction=SweepSearcher.SweepDirection.UP, ): sweep_vec, sweep_start_position = find_sweep_direction_and_start_position( ox, oy) rox, roy = convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position) grid_map, x_inds_goal_y, goal_y = setup_grid_map(rox, roy, resolution, sweeping_direction) sweep_searcher = SweepSearcher(moving_direction, sweeping_direction, x_inds_goal_y, goal_y) px, py = sweep_path_search(sweep_searcher, grid_map) rx, ry = convert_global_coordinate(px, py, sweep_vec, sweep_start_position) print("Path length:", len(rx)) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L247-L270
2
[ 0, 4, 6, 7, 9, 10, 12, 13, 15, 16, 17, 18, 20, 21, 22, 23 ]
66.666667
[]
0
false
95
24
1
100
0
def planning(ox, oy, resolution, moving_direction=SweepSearcher.MovingDirection.RIGHT, sweeping_direction=SweepSearcher.SweepDirection.UP, ): sweep_vec, sweep_start_position = find_sweep_direction_and_start_position( ox, oy) rox, roy = convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position) grid_map, x_inds_goal_y, goal_y = setup_grid_map(rox, roy, resolution, sweeping_direction) sweep_searcher = SweepSearcher(moving_direction, sweeping_direction, x_inds_goal_y, goal_y) px, py = sweep_path_search(sweep_searcher, grid_map) rx, ry = convert_global_coordinate(px, py, sweep_vec, sweep_start_position) print("Path length:", len(rx)) return rx, ry
1,133
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
planning_animation
(ox, oy, resolution)
273
297
def planning_animation(ox, oy, resolution): # pragma: no cover px, py = planning(ox, oy, resolution) # animation if do_animation: for ipx, ipy in zip(px, py): 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.plot(ox, oy, "-xb") plt.plot(px, py, "-r") plt.plot(ipx, ipy, "or") plt.axis("equal") plt.grid(True) plt.pause(0.1) plt.cla() plt.plot(ox, oy, "-xb") plt.plot(px, py, "-r") plt.axis("equal") plt.grid(True) plt.pause(0.1) plt.close()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L273-L297
2
[]
0
[]
0
false
95
25
3
100
0
def planning_animation(ox, oy, resolution): # pragma: no cover px, py = planning(ox, oy, resolution) # animation if do_animation: for ipx, ipy in zip(px, py): 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.plot(ox, oy, "-xb") plt.plot(px, py, "-r") plt.plot(ipx, ipy, "or") plt.axis("equal") plt.grid(True) plt.pause(0.1) plt.cla() plt.plot(ox, oy, "-xb") plt.plot(px, py, "-r") plt.axis("equal") plt.grid(True) plt.pause(0.1) plt.close()
1,134
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
main
()
300
320
def main(): # pragma: no cover print("start!!") ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0, 0.0] oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0, 0.0] resolution = 5.0 planning_animation(ox, oy, resolution) ox = [0.0, 50.0, 50.0, 0.0, 0.0] oy = [0.0, 0.0, 30.0, 30.0, 0.0] resolution = 1.3 planning_animation(ox, oy, resolution) ox = [0.0, 20.0, 50.0, 200.0, 130.0, 40.0, 0.0] oy = [0.0, -80.0, 0.0, 30.0, 60.0, 80.0, 0.0] resolution = 5.0 planning_animation(ox, oy, resolution) if do_animation: plt.show() print("done!!")
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L300-L320
2
[]
0
[]
0
false
95
21
2
100
0
def main(): # pragma: no cover print("start!!") ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0, 0.0] oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0, 0.0] resolution = 5.0 planning_animation(ox, oy, resolution) ox = [0.0, 50.0, 50.0, 0.0, 0.0] oy = [0.0, 0.0, 30.0, 30.0, 0.0] resolution = 1.3 planning_animation(ox, oy, resolution) ox = [0.0, 20.0, 50.0, 200.0, 130.0, 40.0, 0.0] oy = [0.0, -80.0, 0.0, 30.0, 60.0, 80.0, 0.0] resolution = 5.0 planning_animation(ox, oy, resolution) if do_animation: plt.show() print("done!!")
1,135
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.__init__
(self, moving_direction, sweep_direction, x_inds_goal_y, goal_y)
30
37
def __init__(self, moving_direction, sweep_direction, x_inds_goal_y, goal_y): self.moving_direction = moving_direction self.sweep_direction = sweep_direction self.turing_window = [] self.update_turning_window() self.x_indexes_goal_y = x_inds_goal_y self.goal_y = goal_y
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L30-L37
2
[ 0, 2, 3, 4, 5, 6, 7 ]
87.5
[]
0
false
95
8
1
100
0
def __init__(self, moving_direction, sweep_direction, x_inds_goal_y, goal_y): self.moving_direction = moving_direction self.sweep_direction = sweep_direction self.turing_window = [] self.update_turning_window() self.x_indexes_goal_y = x_inds_goal_y self.goal_y = goal_y
1,136
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.move_target_grid
(self, c_x_index, c_y_index, grid_map)
39
65
def move_target_grid(self, c_x_index, c_y_index, grid_map): n_x_index = self.moving_direction + c_x_index n_y_index = c_y_index # found safe grid if not grid_map.check_occupied_from_xy_index(n_x_index, n_y_index, occupied_val=0.5): return n_x_index, n_y_index else: # occupied next_c_x_index, next_c_y_index = self.find_safe_turning_grid( c_x_index, c_y_index, grid_map) if (next_c_x_index is None) and (next_c_y_index is None): # moving backward next_c_x_index = -self.moving_direction + c_x_index next_c_y_index = c_y_index if grid_map.check_occupied_from_xy_index(next_c_x_index, next_c_y_index): # moved backward, but the grid is occupied by obstacle return None, None else: # keep moving until end while not grid_map.check_occupied_from_xy_index( next_c_x_index + self.moving_direction, next_c_y_index, occupied_val=0.5): next_c_x_index += self.moving_direction self.swap_moving_direction() return next_c_x_index, next_c_y_index
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L39-L65
2
[ 0, 1, 2, 3, 4, 5, 7, 9, 11, 12, 13, 14, 15, 17, 18, 20, 21, 24, 25, 26 ]
74.074074
[]
0
false
95
27
6
100
0
def move_target_grid(self, c_x_index, c_y_index, grid_map): n_x_index = self.moving_direction + c_x_index n_y_index = c_y_index # found safe grid if not grid_map.check_occupied_from_xy_index(n_x_index, n_y_index, occupied_val=0.5): return n_x_index, n_y_index else: # occupied next_c_x_index, next_c_y_index = self.find_safe_turning_grid( c_x_index, c_y_index, grid_map) if (next_c_x_index is None) and (next_c_y_index is None): # moving backward next_c_x_index = -self.moving_direction + c_x_index next_c_y_index = c_y_index if grid_map.check_occupied_from_xy_index(next_c_x_index, next_c_y_index): # moved backward, but the grid is occupied by obstacle return None, None else: # keep moving until end while not grid_map.check_occupied_from_xy_index( next_c_x_index + self.moving_direction, next_c_y_index, occupied_val=0.5): next_c_x_index += self.moving_direction self.swap_moving_direction() return next_c_x_index, next_c_y_index
1,137
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.find_safe_turning_grid
(self, c_x_index, c_y_index, grid_map)
return None, None
67
80
def find_safe_turning_grid(self, c_x_index, c_y_index, grid_map): for (d_x_ind, d_y_ind) in self.turing_window: next_x_ind = d_x_ind + c_x_index next_y_ind = d_y_ind + c_y_index # found safe grid if not grid_map.check_occupied_from_xy_index(next_x_ind, next_y_ind, occupied_val=0.5): return next_x_ind, next_y_ind return None, None
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L67-L80
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13 ]
85.714286
[]
0
false
95
14
3
100
0
def find_safe_turning_grid(self, c_x_index, c_y_index, grid_map): for (d_x_ind, d_y_ind) in self.turing_window: next_x_ind = d_x_ind + c_x_index next_y_ind = d_y_ind + c_y_index # found safe grid if not grid_map.check_occupied_from_xy_index(next_x_ind, next_y_ind, occupied_val=0.5): return next_x_ind, next_y_ind return None, None
1,138
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.is_search_done
(self, grid_map)
return True
82
89
def is_search_done(self, grid_map): for ix in self.x_indexes_goal_y: if not grid_map.check_occupied_from_xy_index(ix, self.goal_y, occupied_val=0.5): return False # all lower grid is occupied return True
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L82-L89
2
[ 0, 1, 2, 4, 5, 6, 7 ]
87.5
[]
0
false
95
8
3
100
0
def is_search_done(self, grid_map): for ix in self.x_indexes_goal_y: if not grid_map.check_occupied_from_xy_index(ix, self.goal_y, occupied_val=0.5): return False # all lower grid is occupied return True
1,139
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.update_turning_window
(self)
91
99
def update_turning_window(self): # turning window definition # robot can move grid based on it. self.turing_window = [ (self.moving_direction, 0.0), (self.moving_direction, self.sweep_direction), (0, self.sweep_direction), (-self.moving_direction, self.sweep_direction), ]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L91-L99
2
[ 0, 1, 2, 3 ]
44.444444
[]
0
false
95
9
1
100
0
def update_turning_window(self): # turning window definition # robot can move grid based on it. self.turing_window = [ (self.moving_direction, 0.0), (self.moving_direction, self.sweep_direction), (0, self.sweep_direction), (-self.moving_direction, self.sweep_direction), ]
1,140
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.swap_moving_direction
(self)
101
103
def swap_moving_direction(self): self.moving_direction *= -1 self.update_turning_window()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L101-L103
2
[ 0, 1, 2 ]
100
[]
0
true
95
3
1
100
0
def swap_moving_direction(self): self.moving_direction *= -1 self.update_turning_window()
1,141
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py
SweepSearcher.search_start_grid
(self, grid_map)
105
120
def search_start_grid(self, grid_map): x_inds = [] y_ind = 0 if self.sweep_direction == self.SweepDirection.DOWN: x_inds, y_ind = search_free_grid_index_at_edge_y( grid_map, from_upper=True) elif self.sweep_direction == self.SweepDirection.UP: x_inds, y_ind = search_free_grid_index_at_edge_y( grid_map, from_upper=False) if self.moving_direction == self.MovingDirection.RIGHT: return min(x_inds), y_ind elif self.moving_direction == self.MovingDirection.LEFT: return max(x_inds), y_ind raise ValueError("self.moving direction is invalid ")
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py#L105-L120
2
[ 0, 1, 2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14 ]
81.25
[ 15 ]
6.25
false
95
16
5
93.75
0
def search_start_grid(self, grid_map): x_inds = [] y_ind = 0 if self.sweep_direction == self.SweepDirection.DOWN: x_inds, y_ind = search_free_grid_index_at_edge_y( grid_map, from_upper=True) elif self.sweep_direction == self.SweepDirection.UP: x_inds, y_ind = search_free_grid_index_at_edge_y( grid_map, from_upper=False) if self.moving_direction == self.MovingDirection.RIGHT: return min(x_inds), y_ind elif self.moving_direction == self.MovingDirection.LEFT: return max(x_inds), y_ind raise ValueError("self.moving direction is invalid ")
1,142
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
PIDControl
(target, current)
return a
29
37
def PIDControl(target, current): a = Kp * (target - current) if a > unicycle_model.accel_max: a = unicycle_model.accel_max elif a < -unicycle_model.accel_max: a = -unicycle_model.accel_max return a
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L29-L37
2
[ 0, 1, 2, 3, 4, 5, 7, 8 ]
88.888889
[ 6 ]
11.111111
false
95.454545
9
3
88.888889
0
def PIDControl(target, current): a = Kp * (target - current) if a > unicycle_model.accel_max: a = unicycle_model.accel_max elif a < -unicycle_model.accel_max: a = -unicycle_model.accel_max return a
1,143
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
pure_pursuit_control
(state, cx, cy, pind)
return delta, ind, dis
40
68
def pure_pursuit_control(state, cx, cy, pind): ind, dis = calc_target_index(state, cx, cy) if pind >= ind: ind = pind # print(parent_index, ind) if ind < len(cx): tx = cx[ind] ty = cy[ind] else: tx = cx[-1] ty = cy[-1] ind = len(cx) - 1 alpha = math.atan2(ty - state.y, tx - state.x) - state.yaw if state.v <= 0.0: # back alpha = math.pi - alpha delta = math.atan2(2.0 * unicycle_model.L * math.sin(alpha) / Lf, 1.0) if delta > unicycle_model.steer_max: delta = unicycle_model.steer_max elif delta < - unicycle_model.steer_max: delta = -unicycle_model.steer_max return delta, ind, dis
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L40-L68
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 ]
86.206897
[ 12, 13, 14 ]
10.344828
false
95.454545
29
6
89.655172
0
def pure_pursuit_control(state, cx, cy, pind): ind, dis = calc_target_index(state, cx, cy) if pind >= ind: ind = pind # print(parent_index, ind) if ind < len(cx): tx = cx[ind] ty = cy[ind] else: tx = cx[-1] ty = cy[-1] ind = len(cx) - 1 alpha = math.atan2(ty - state.y, tx - state.x) - state.yaw if state.v <= 0.0: # back alpha = math.pi - alpha delta = math.atan2(2.0 * unicycle_model.L * math.sin(alpha) / Lf, 1.0) if delta > unicycle_model.steer_max: delta = unicycle_model.steer_max elif delta < - unicycle_model.steer_max: delta = -unicycle_model.steer_max return delta, ind, dis
1,144
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
calc_target_index
(state, cx, cy)
return ind, mindis
71
89
def calc_target_index(state, cx, cy): dx = [state.x - icx for icx in cx] dy = [state.y - icy for icy in cy] d = np.hypot(dx, dy) mindis = min(d) ind = np.argmin(d) L = 0.0 while Lf > L and (ind + 1) < len(cx): dx = cx[ind + 1] - cx[ind] dy = cy[ind + 1] - cy[ind] L += math.hypot(dx, dy) ind += 1 # print(mindis) return ind, mindis
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L71-L89
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
100
[]
0
true
95.454545
19
5
100
0
def calc_target_index(state, cx, cy): dx = [state.x - icx for icx in cx] dy = [state.y - icy for icy in cy] d = np.hypot(dx, dy) mindis = min(d) ind = np.argmin(d) L = 0.0 while Lf > L and (ind + 1) < len(cx): dx = cx[ind + 1] - cx[ind] dy = cy[ind + 1] - cy[ind] L += math.hypot(dx, dy) ind += 1 # print(mindis) return ind, mindis
1,145
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
closed_loop_prediction
(cx, cy, cyaw, speed_profile, goal)
return t, x, y, yaw, v, a, d, find_goal
92
157
def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal): state = unicycle_model.State(x=-0.0, y=-0.0, yaw=0.0, v=0.0) # lastIndex = len(cx) - 1 time = 0.0 x = [state.x] y = [state.y] yaw = [state.yaw] v = [state.v] t = [0.0] a = [0.0] d = [0.0] target_ind, mindis = calc_target_index(state, cx, cy) find_goal = False maxdis = 0.5 while T >= time: di, target_ind, dis = pure_pursuit_control(state, cx, cy, target_ind) target_speed = speed_profile[target_ind] target_speed = target_speed * \ (maxdis - min(dis, maxdis - 0.1)) / maxdis ai = PIDControl(target_speed, state.v) state = unicycle_model.update(state, ai, di) if abs(state.v) <= stop_speed and target_ind <= len(cx) - 2: target_ind += 1 time = time + unicycle_model.dt # check goal dx = state.x - goal[0] dy = state.y - goal[1] if math.hypot(dx, dy) <= goal_dis: find_goal = True break x.append(state.x) y.append(state.y) yaw.append(state.yaw) v.append(state.v) t.append(time) a.append(ai) d.append(di) if target_ind % 1 == 0 and animation: # pragma: no cover 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.plot(cx, cy, "-r", label="course") plt.plot(x, y, "ob", label="trajectory") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.axis("equal") plt.grid(True) plt.title("speed:" + str(round(state.v, 2)) + "tind:" + str(target_ind)) plt.pause(0.0001) else: print("Time out!!") return t, x, y, yaw, v, a, d, find_goal
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L92-L157
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 64, 65 ]
87.5
[ 63 ]
1.785714
false
95.454545
66
7
98.214286
0
def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal): state = unicycle_model.State(x=-0.0, y=-0.0, yaw=0.0, v=0.0) # lastIndex = len(cx) - 1 time = 0.0 x = [state.x] y = [state.y] yaw = [state.yaw] v = [state.v] t = [0.0] a = [0.0] d = [0.0] target_ind, mindis = calc_target_index(state, cx, cy) find_goal = False maxdis = 0.5 while T >= time: di, target_ind, dis = pure_pursuit_control(state, cx, cy, target_ind) target_speed = speed_profile[target_ind] target_speed = target_speed * \ (maxdis - min(dis, maxdis - 0.1)) / maxdis ai = PIDControl(target_speed, state.v) state = unicycle_model.update(state, ai, di) if abs(state.v) <= stop_speed and target_ind <= len(cx) - 2: target_ind += 1 time = time + unicycle_model.dt # check goal dx = state.x - goal[0] dy = state.y - goal[1] if math.hypot(dx, dy) <= goal_dis: find_goal = True break x.append(state.x) y.append(state.y) yaw.append(state.yaw) v.append(state.v) t.append(time) a.append(ai) d.append(di) if target_ind % 1 == 0 and animation: # pragma: no cover 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.plot(cx, cy, "-r", label="course") plt.plot(x, y, "ob", label="trajectory") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.axis("equal") plt.grid(True) plt.title("speed:" + str(round(state.v, 2)) + "tind:" + str(target_ind)) plt.pause(0.0001) else: print("Time out!!") return t, x, y, yaw, v, a, d, find_goal
1,146
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
set_stop_point
(target_speed, cx, cy, cyaw)
return speed_profile, d
160
202
def set_stop_point(target_speed, cx, cy, cyaw): speed_profile = [target_speed] * len(cx) forward = True d = [] is_back = False # Set stop point for i in range(len(cx) - 1): dx = cx[i + 1] - cx[i] dy = cy[i + 1] - cy[i] d.append(math.hypot(dx, dy)) iyaw = cyaw[i] move_direction = math.atan2(dy, dx) is_back = abs(move_direction - iyaw) >= math.pi / 2.0 if dx == 0.0 and dy == 0.0: continue if is_back: speed_profile[i] = - target_speed else: speed_profile[i] = target_speed if is_back and forward: speed_profile[i] = 0.0 forward = False # plt.plot(cx[i], cy[i], "xb") # print(i_yaw, move_direction, dx, dy) elif not is_back and not forward: speed_profile[i] = 0.0 forward = True # plt.plot(cx[i], cy[i], "xb") # print(i_yaw, move_direction, dx, dy) speed_profile[0] = 0.0 if is_back: speed_profile[-1] = -stop_speed else: speed_profile[-1] = stop_speed d.append(d[-1]) return speed_profile, d
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L160-L202
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39, 40, 41, 42 ]
93.023256
[ 38 ]
2.325581
false
95.454545
43
10
97.674419
0
def set_stop_point(target_speed, cx, cy, cyaw): speed_profile = [target_speed] * len(cx) forward = True d = [] is_back = False # Set stop point for i in range(len(cx) - 1): dx = cx[i + 1] - cx[i] dy = cy[i + 1] - cy[i] d.append(math.hypot(dx, dy)) iyaw = cyaw[i] move_direction = math.atan2(dy, dx) is_back = abs(move_direction - iyaw) >= math.pi / 2.0 if dx == 0.0 and dy == 0.0: continue if is_back: speed_profile[i] = - target_speed else: speed_profile[i] = target_speed if is_back and forward: speed_profile[i] = 0.0 forward = False # plt.plot(cx[i], cy[i], "xb") # print(i_yaw, move_direction, dx, dy) elif not is_back and not forward: speed_profile[i] = 0.0 forward = True # plt.plot(cx[i], cy[i], "xb") # print(i_yaw, move_direction, dx, dy) speed_profile[0] = 0.0 if is_back: speed_profile[-1] = -stop_speed else: speed_profile[-1] = stop_speed d.append(d[-1]) return speed_profile, d
1,147
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
calc_speed_profile
(cx, cy, cyaw, target_speed)
return speed_profile
205
212
def calc_speed_profile(cx, cy, cyaw, target_speed): speed_profile, d = set_stop_point(target_speed, cx, cy, cyaw) if animation: # pragma: no cover plt.plot(speed_profile, "xb") return speed_profile
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L205-L212
2
[ 0, 1, 2, 3, 6, 7 ]
100
[]
0
true
95.454545
8
2
100
0
def calc_speed_profile(cx, cy, cyaw, target_speed): speed_profile, d = set_stop_point(target_speed, cx, cy, cyaw) if animation: # pragma: no cover plt.plot(speed_profile, "xb") return speed_profile
1,148
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
extend_path
(cx, cy, cyaw)
return cx, cy, cyaw
215
230
def extend_path(cx, cy, cyaw): dl = 0.1 dl_list = [dl] * (int(Lf / dl) + 1) move_direction = math.atan2(cy[-1] - cy[-3], cx[-1] - cx[-3]) is_back = abs(move_direction - cyaw[-1]) >= math.pi / 2.0 for idl in dl_list: if is_back: idl *= -1 cx = np.append(cx, cx[-1] + idl * math.cos(cyaw[-1])) cy = np.append(cy, cy[-1] + idl * math.sin(cyaw[-1])) cyaw = np.append(cyaw, cyaw[-1]) return cx, cy, cyaw
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L215-L230
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
95.454545
16
3
100
0
def extend_path(cx, cy, cyaw): dl = 0.1 dl_list = [dl] * (int(Lf / dl) + 1) move_direction = math.atan2(cy[-1] - cy[-3], cx[-1] - cx[-3]) is_back = abs(move_direction - cyaw[-1]) >= math.pi / 2.0 for idl in dl_list: if is_back: idl *= -1 cx = np.append(cx, cx[-1] + idl * math.cos(cyaw[-1])) cy = np.append(cy, cy[-1] + idl * math.sin(cyaw[-1])) cyaw = np.append(cyaw, cyaw[-1]) return cx, cy, cyaw
1,149
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
main
()
233
295
def main(): # pragma: no cover # target course cx = np.arange(0, 50, 0.1) cy = [math.sin(ix / 5.0) * ix / 2.0 for ix in cx] target_speed = 5.0 / 3.6 T = 15.0 # max simulation time state = unicycle_model.State(x=-0.0, y=-3.0, yaw=0.0, v=0.0) # state = unicycle_model.State(x=-1.0, y=-5.0, yaw=0.0, v=-30.0 / 3.6) # state = unicycle_model.State(x=10.0, y=5.0, yaw=0.0, v=-30.0 / 3.6) # state = unicycle_model.State( # x=3.0, y=5.0, yaw=np.deg2rad(-40.0), v=-10.0 / 3.6) # state = unicycle_model.State( # x=3.0, y=5.0, yaw=np.deg2rad(40.0), v=50.0 / 3.6) lastIndex = len(cx) - 1 time = 0.0 x = [state.x] y = [state.y] yaw = [state.yaw] v = [state.v] t = [0.0] target_ind, dis = calc_target_index(state, cx, cy) while T >= time and lastIndex > target_ind: ai = PIDControl(target_speed, state.v) di, target_ind, _ = pure_pursuit_control(state, cx, cy, target_ind) state = unicycle_model.update(state, ai, di) time = time + unicycle_model.dt x.append(state.x) y.append(state.y) yaw.append(state.yaw) v.append(state.v) t.append(time) # plt.cla() # plt.plot(cx, cy, ".r", label="course") # plt.plot(x, y, "-b", label="trajectory") # plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") # plt.axis("equal") # plt.grid(True) # plt.pause(0.1) # input() plt.subplots(1) plt.plot(cx, cy, ".r", label="course") plt.plot(x, y, "-b", label="trajectory") plt.legend() plt.xlabel("x[m]") plt.ylabel("y[m]") plt.axis("equal") plt.grid(True) plt.subplots(1) plt.plot(t, [iv * 3.6 for iv in v], "-r") plt.xlabel("Time[s]") plt.ylabel("Speed[km/h]") plt.grid(True) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py#L233-L295
2
[]
0
[]
0
false
95.454545
63
5
100
0
def main(): # pragma: no cover # target course cx = np.arange(0, 50, 0.1) cy = [math.sin(ix / 5.0) * ix / 2.0 for ix in cx] target_speed = 5.0 / 3.6 T = 15.0 # max simulation time state = unicycle_model.State(x=-0.0, y=-3.0, yaw=0.0, v=0.0) # state = unicycle_model.State(x=-1.0, y=-5.0, yaw=0.0, v=-30.0 / 3.6) # state = unicycle_model.State(x=10.0, y=5.0, yaw=0.0, v=-30.0 / 3.6) # state = unicycle_model.State( # x=3.0, y=5.0, yaw=np.deg2rad(-40.0), v=-10.0 / 3.6) # state = unicycle_model.State( # x=3.0, y=5.0, yaw=np.deg2rad(40.0), v=50.0 / 3.6) lastIndex = len(cx) - 1 time = 0.0 x = [state.x] y = [state.y] yaw = [state.yaw] v = [state.v] t = [0.0] target_ind, dis = calc_target_index(state, cx, cy) while T >= time and lastIndex > target_ind: ai = PIDControl(target_speed, state.v) di, target_ind, _ = pure_pursuit_control(state, cx, cy, target_ind) state = unicycle_model.update(state, ai, di) time = time + unicycle_model.dt x.append(state.x) y.append(state.y) yaw.append(state.yaw) v.append(state.v) t.append(time) # plt.cla() # plt.plot(cx, cy, ".r", label="course") # plt.plot(x, y, "-b", label="trajectory") # plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") # plt.axis("equal") # plt.grid(True) # plt.pause(0.1) # input() plt.subplots(1) plt.plot(cx, cy, ".r", label="course") plt.plot(x, y, "-b", label="trajectory") plt.legend() plt.xlabel("x[m]") plt.ylabel("y[m]") plt.axis("equal") plt.grid(True) plt.subplots(1) plt.plot(t, [iv * 3.6 for iv in v], "-r") plt.xlabel("Time[s]") plt.ylabel("Speed[km/h]") plt.grid(True) plt.show()
1,150
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
main
(gx=6.0, gy=7.0, gyaw=np.deg2rad(90.0), max_iter=100)
151
212
def main(gx=6.0, gy=7.0, gyaw=np.deg2rad(90.0), max_iter=100): print("Start" + __file__) # ====Search Path with RRT==== obstacle_list = [ (5, 5, 1), (4, 6, 1), (4, 8, 1), (4, 10, 1), (6, 5, 1), (7, 5, 1), (8, 6, 1), (8, 8, 1), (8, 10, 1) ] # [x,y,size(radius)] # Set Initial parameters start = [0.0, 0.0, np.deg2rad(0.0)] goal = [gx, gy, gyaw] closed_loop_rrt_star = ClosedLoopRRTStar(start, goal, obstacle_list, [-2.0, 20.0], max_iter=max_iter) flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning( animation=show_animation) if not flag: print("cannot find feasible path") # Draw final path if show_animation: closed_loop_rrt_star.draw_graph() plt.plot(x, y, '-r') plt.grid(True) plt.pause(0.001) plt.subplots(1) plt.plot(t, [np.rad2deg(iyaw) for iyaw in yaw[:-1]], '-r') plt.xlabel("time[s]") plt.ylabel("Yaw[deg]") plt.grid(True) plt.subplots(1) plt.plot(t, [iv * 3.6 for iv in v], '-r') plt.xlabel("time[s]") plt.ylabel("velocity[km/h]") plt.grid(True) plt.subplots(1) plt.plot(t, a, '-r') plt.xlabel("time[s]") plt.ylabel("accel[m/ss]") plt.grid(True) plt.subplots(1) plt.plot(t, [np.rad2deg(td) for td in d], '-r') plt.xlabel("time[s]") plt.ylabel("Steering angle[deg]") plt.grid(True) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L151-L212
2
[ 0, 1, 2, 3, 15, 16, 17, 18, 19, 23, 25, 26, 29, 30 ]
22.580645
[ 27, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42, 43, 45, 46, 47, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 61 ]
41.935484
false
70.338983
62
6
58.064516
0
def main(gx=6.0, gy=7.0, gyaw=np.deg2rad(90.0), max_iter=100): print("Start" + __file__) # ====Search Path with RRT==== obstacle_list = [ (5, 5, 1), (4, 6, 1), (4, 8, 1), (4, 10, 1), (6, 5, 1), (7, 5, 1), (8, 6, 1), (8, 8, 1), (8, 10, 1) ] # [x,y,size(radius)] # Set Initial parameters start = [0.0, 0.0, np.deg2rad(0.0)] goal = [gx, gy, gyaw] closed_loop_rrt_star = ClosedLoopRRTStar(start, goal, obstacle_list, [-2.0, 20.0], max_iter=max_iter) flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning( animation=show_animation) if not flag: print("cannot find feasible path") # Draw final path if show_animation: closed_loop_rrt_star.draw_graph() plt.plot(x, y, '-r') plt.grid(True) plt.pause(0.001) plt.subplots(1) plt.plot(t, [np.rad2deg(iyaw) for iyaw in yaw[:-1]], '-r') plt.xlabel("time[s]") plt.ylabel("Yaw[deg]") plt.grid(True) plt.subplots(1) plt.plot(t, [iv * 3.6 for iv in v], '-r') plt.xlabel("time[s]") plt.ylabel("velocity[km/h]") plt.grid(True) plt.subplots(1) plt.plot(t, a, '-r') plt.xlabel("time[s]") plt.ylabel("accel[m/ss]") plt.grid(True) plt.subplots(1) plt.plot(t, [np.rad2deg(td) for td in d], '-r') plt.xlabel("time[s]") plt.ylabel("Steering angle[deg]") plt.grid(True) plt.show()
1,151
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
ClosedLoopRRTStar.__init__
(self, start, goal, obstacle_list, rand_area, max_iter=200, connect_circle_dist=50.0, robot_radius=0.0 )
28
42
def __init__(self, start, goal, obstacle_list, rand_area, max_iter=200, connect_circle_dist=50.0, robot_radius=0.0 ): super().__init__(start, goal, obstacle_list, rand_area, max_iter=max_iter, connect_circle_dist=connect_circle_dist, robot_radius=robot_radius ) self.target_speed = 10.0 / 3.6 self.yaw_th = np.deg2rad(3.0) self.xy_th = 0.5 self.invalid_travel_ratio = 5.0
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L28-L42
2
[ 0, 5, 10, 11, 12, 13, 14 ]
46.666667
[]
0
false
70.338983
15
1
100
0
def __init__(self, start, goal, obstacle_list, rand_area, max_iter=200, connect_circle_dist=50.0, robot_radius=0.0 ): super().__init__(start, goal, obstacle_list, rand_area, max_iter=max_iter, connect_circle_dist=connect_circle_dist, robot_radius=robot_radius ) self.target_speed = 10.0 / 3.6 self.yaw_th = np.deg2rad(3.0) self.xy_th = 0.5 self.invalid_travel_ratio = 5.0
1,152
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
ClosedLoopRRTStar.planning
(self, animation=True)
return flag, x, y, yaw, v, t, a, d
do planning animation: flag for animation on or off
do planning
44
59
def planning(self, animation=True): """ do planning animation: flag for animation on or off """ # planning with RRTStarReedsShepp super().planning(animation=animation) # generate coruse path_indexs = self.get_goal_indexes() flag, x, y, yaw, v, t, a, d = self.search_best_feasible_path( path_indexs) return flag, x, y, yaw, v, t, a, d
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L44-L59
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
70.338983
16
1
100
3
def planning(self, animation=True): # planning with RRTStarReedsShepp super().planning(animation=animation) # generate coruse path_indexs = self.get_goal_indexes() flag, x, y, yaw, v, t, a, d = self.search_best_feasible_path( path_indexs) return flag, x, y, yaw, v, t, a, d
1,153
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
ClosedLoopRRTStar.search_best_feasible_path
(self, path_indexs)
return False, None, None, None, None, None, None, None
61
90
def search_best_feasible_path(self, path_indexs): print("Start search feasible path") best_time = float("inf") fx, fy, fyaw, fv, ft, fa, fd = None, None, None, None, None, None, None # pure pursuit tracking for ind in path_indexs: path = self.generate_final_course(ind) flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible( path) if flag and best_time >= t[-1]: print("feasible path is found") best_time = t[-1] fx, fy, fyaw, fv, ft, fa, fd = x, y, yaw, v, t, a, d print("best time is") print(best_time) if fx: fx.append(self.end.x) fy.append(self.end.y) fyaw.append(self.end.yaw) return True, fx, fy, fyaw, fv, ft, fa, fd return False, None, None, None, None, None, None, None
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L61-L90
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 ]
93.333333
[ 29 ]
3.333333
false
70.338983
30
5
96.666667
0
def search_best_feasible_path(self, path_indexs): print("Start search feasible path") best_time = float("inf") fx, fy, fyaw, fv, ft, fa, fd = None, None, None, None, None, None, None # pure pursuit tracking for ind in path_indexs: path = self.generate_final_course(ind) flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible( path) if flag and best_time >= t[-1]: print("feasible path is found") best_time = t[-1] fx, fy, fyaw, fv, ft, fa, fd = x, y, yaw, v, t, a, d print("best time is") print(best_time) if fx: fx.append(self.end.x) fy.append(self.end.y) fyaw.append(self.end.yaw) return True, fx, fy, fyaw, fv, ft, fa, fd return False, None, None, None, None, None, None, None
1,154
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
ClosedLoopRRTStar.check_tracking_path_is_feasible
(self, path)
return find_goal, x, y, yaw, v, t, a, d
92
130
def check_tracking_path_is_feasible(self, path): cx = np.array([state[0] for state in path])[::-1] cy = np.array([state[1] for state in path])[::-1] cyaw = np.array([state[2] for state in path])[::-1] goal = [cx[-1], cy[-1], cyaw[-1]] cx, cy, cyaw = pure_pursuit.extend_path(cx, cy, cyaw) speed_profile = pure_pursuit.calc_speed_profile( cx, cy, cyaw, self.target_speed) t, x, y, yaw, v, a, d, find_goal = pure_pursuit.closed_loop_prediction( cx, cy, cyaw, speed_profile, goal) yaw = [reeds_shepp_path_planning.pi_2_pi(iyaw) for iyaw in yaw] if not find_goal: print("cannot reach goal") if abs(yaw[-1] - goal[2]) >= self.yaw_th * 10.0: print("final angle is bad") find_goal = False travel = unicycle_model.dt * sum(np.abs(v)) origin_travel = sum(np.hypot(np.diff(cx), np.diff(cy))) if (travel / origin_travel) >= self.invalid_travel_ratio: print("path is too long") find_goal = False tmp_node = self.Node(x, y, 0) tmp_node.path_x = x tmp_node.path_y = y if not self.check_collision( tmp_node, self.obstacle_list, self.robot_radius): print("This path is collision") find_goal = False return find_goal, x, y, yaw, v, t, a, d
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L92-L130
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 14, 15, 16, 18, 19, 22, 23, 24, 25, 26, 29, 30, 31, 32, 33, 37, 38 ]
74.358974
[ 17, 20, 21, 27, 28, 35, 36 ]
17.948718
false
70.338983
39
9
82.051282
0
def check_tracking_path_is_feasible(self, path): cx = np.array([state[0] for state in path])[::-1] cy = np.array([state[1] for state in path])[::-1] cyaw = np.array([state[2] for state in path])[::-1] goal = [cx[-1], cy[-1], cyaw[-1]] cx, cy, cyaw = pure_pursuit.extend_path(cx, cy, cyaw) speed_profile = pure_pursuit.calc_speed_profile( cx, cy, cyaw, self.target_speed) t, x, y, yaw, v, a, d, find_goal = pure_pursuit.closed_loop_prediction( cx, cy, cyaw, speed_profile, goal) yaw = [reeds_shepp_path_planning.pi_2_pi(iyaw) for iyaw in yaw] if not find_goal: print("cannot reach goal") if abs(yaw[-1] - goal[2]) >= self.yaw_th * 10.0: print("final angle is bad") find_goal = False travel = unicycle_model.dt * sum(np.abs(v)) origin_travel = sum(np.hypot(np.diff(cx), np.diff(cy))) if (travel / origin_travel) >= self.invalid_travel_ratio: print("path is too long") find_goal = False tmp_node = self.Node(x, y, 0) tmp_node.path_x = x tmp_node.path_y = y if not self.check_collision( tmp_node, self.obstacle_list, self.robot_radius): print("This path is collision") find_goal = False return find_goal, x, y, yaw, v, t, a, d
1,155
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
ClosedLoopRRTStar.get_goal_indexes
(self)
return fgoalinds
132
148
def get_goal_indexes(self): goalinds = [] for (i, node) in enumerate(self.node_list): if self.calc_dist_to_goal(node.x, node.y) <= self.xy_th: goalinds.append(i) print("OK XY TH num is") print(len(goalinds)) # angle check fgoalinds = [] for i in goalinds: if abs(self.node_list[i].yaw - self.end.yaw) <= self.yaw_th: fgoalinds.append(i) print("OK YAW TH num is") print(len(fgoalinds)) return fgoalinds
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py#L132-L148
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
70.338983
17
5
100
0
def get_goal_indexes(self): goalinds = [] for (i, node) in enumerate(self.node_list): if self.calc_dist_to_goal(node.x, node.y) <= self.xy_th: goalinds.append(i) print("OK XY TH num is") print(len(goalinds)) # angle check fgoalinds = [] for i in goalinds: if abs(self.node_list[i].yaw - self.end.yaw) <= self.yaw_th: fgoalinds.append(i) print("OK YAW TH num is") print(len(fgoalinds)) return fgoalinds
1,156
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/unicycle_model.py
update
(state, a, delta)
return state
30
38
def update(state, a, delta): state.x = state.x + state.v * math.cos(state.yaw) * dt state.y = state.y + state.v * math.sin(state.yaw) * dt state.yaw = state.yaw + state.v / L * math.tan(delta) * dt state.yaw = pi_2_pi(state.yaw) state.v = state.v + a * dt return state
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/unicycle_model.py#L30-L38
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
1
100
0
def update(state, a, delta): state.x = state.x + state.v * math.cos(state.yaw) * dt state.y = state.y + state.v * math.sin(state.yaw) * dt state.yaw = state.yaw + state.v / L * math.tan(delta) * dt state.yaw = pi_2_pi(state.yaw) state.v = state.v + a * dt return state
1,157
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/unicycle_model.py
pi_2_pi
(angle)
return (angle + math.pi) % (2 * math.pi) - math.pi
41
42
def pi_2_pi(angle): return (angle + math.pi) % (2 * math.pi) - math.pi
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/unicycle_model.py#L41-L42
2
[ 0, 1 ]
100
[]
0
true
100
2
1
100
0
def pi_2_pi(angle): return (angle + math.pi) % (2 * math.pi) - math.pi
1,158
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/ClosedLoopRRTStar/unicycle_model.py
State.__init__
(self, x=0.0, y=0.0, yaw=0.0, v=0.0)
23
27
def __init__(self, x=0.0, y=0.0, yaw=0.0, v=0.0): self.x = x self.y = y self.yaw = yaw self.v = v
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/ClosedLoopRRTStar/unicycle_model.py#L23-L27
2
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
100
5
1
100
0
def __init__(self, x=0.0, y=0.0, yaw=0.0, v=0.0): self.x = x self.y = y self.yaw = yaw self.v = v
1,159
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
example_DMP
()
Creates a noisy trajectory, fits weights to it, and then adjusts the trajectory by moving its start position, goal position, or period
Creates a noisy trajectory, fits weights to it, and then adjusts the trajectory by moving its start position, goal position, or period
238
256
def example_DMP(): """ Creates a noisy trajectory, fits weights to it, and then adjusts the trajectory by moving its start position, goal position, or period """ t = np.arange(0, 3*np.pi/2, 0.01) t1 = np.arange(3*np.pi/2, 2*np.pi, 0.01)[:-1] t2 = np.arange(0, np.pi/2, 0.01)[:-1] t3 = np.arange(np.pi, 3*np.pi/2, 0.01) data_x = t + 0.02*np.random.rand(t.shape[0]) data_y = np.concatenate([np.cos(t1) + 0.1*np.random.rand(t1.shape[0]), np.cos(t2) + 0.1*np.random.rand(t2.shape[0]), np.sin(t3) + 0.1*np.random.rand(t3.shape[0])]) training_data = np.vstack([data_x, data_y]).T period = 3*np.pi/2 DMP_controller = DMP(training_data, period) DMP_controller.show_DMP_purpose()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L238-L256
2
[ 0, 1, 2, 3, 4 ]
26.315789
[ 5, 6, 7, 8, 9, 10, 13, 15, 16, 18 ]
52.631579
false
60
19
1
47.368421
2
def example_DMP(): t = np.arange(0, 3*np.pi/2, 0.01) t1 = np.arange(3*np.pi/2, 2*np.pi, 0.01)[:-1] t2 = np.arange(0, np.pi/2, 0.01)[:-1] t3 = np.arange(np.pi, 3*np.pi/2, 0.01) data_x = t + 0.02*np.random.rand(t.shape[0]) data_y = np.concatenate([np.cos(t1) + 0.1*np.random.rand(t1.shape[0]), np.cos(t2) + 0.1*np.random.rand(t2.shape[0]), np.sin(t3) + 0.1*np.random.rand(t3.shape[0])]) training_data = np.vstack([data_x, data_y]).T period = 3*np.pi/2 DMP_controller = DMP(training_data, period) DMP_controller.show_DMP_purpose()
1,160
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.__init__
(self, training_data, data_period, K=156.25, B=25)
Arguments: training_data - input data of form [N, dim] data_period - amount of time training data covers K and B - spring and damper constants to define DMP behavior
Arguments: training_data - input data of form [N, dim] data_period - amount of time training data covers K and B - spring and damper constants to define DMP behavior
23
43
def __init__(self, training_data, data_period, K=156.25, B=25): """ Arguments: training_data - input data of form [N, dim] data_period - amount of time training data covers K and B - spring and damper constants to define DMP behavior """ self.K = K # virtual spring constant self.B = B # virtual damper coefficient self.timesteps = training_data.shape[0] self.dt = data_period / self.timesteps self.weights = None # weights used to generate DMP trajectories self.T_orig = data_period self.training_data = training_data self.find_basis_functions_weights(training_data, data_period)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L23-L43
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
60
21
1
100
5
def __init__(self, training_data, data_period, K=156.25, B=25): self.K = K # virtual spring constant self.B = B # virtual damper coefficient self.timesteps = training_data.shape[0] self.dt = data_period / self.timesteps self.weights = None # weights used to generate DMP trajectories self.T_orig = data_period self.training_data = training_data self.find_basis_functions_weights(training_data, data_period)
1,161
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.find_basis_functions_weights
(self, training_data, data_period, num_weights=10)
Arguments: data [(steps x spacial dim) np array] - data to replicate with DMP data_period [float] - time duration of data
Arguments: data [(steps x spacial dim) np array] - data to replicate with DMP data_period [float] - time duration of data
45
109
def find_basis_functions_weights(self, training_data, data_period, num_weights=10): """ Arguments: data [(steps x spacial dim) np array] - data to replicate with DMP data_period [float] - time duration of data """ if not isinstance(training_data, np.ndarray): print("Warning: you should input training data as an np.ndarray") elif training_data.shape[0] < training_data.shape[1]: print("Warning: you probably need to transpose your training data") dt = data_period / len(training_data) init_state = training_data[0] goal_state = training_data[-1] # means (C) and std devs (H) of gaussian basis functions C = np.linspace(0, 1, num_weights) H = (0.65*(1./(num_weights-1))**2) for dim, _ in enumerate(training_data[0]): dimension_data = training_data[:, dim] q0 = init_state[dim] g = goal_state[dim] q = q0 qd_last = 0 phi_vals = [] f_vals = [] for i, _ in enumerate(dimension_data): if i + 1 == len(dimension_data): qd = 0 else: qd = (dimension_data[i+1] - dimension_data[i]) / dt phi = [np.exp(-0.5 * ((i * dt / data_period) - c)**2 / H) for c in C] phi = phi/np.sum(phi) qdd = (qd - qd_last)/dt f = (qdd * data_period**2 - self.K * (g - q) + self.B * qd * data_period) / (g - q0) phi_vals.append(phi) f_vals.append(f) qd_last = qd q += qd * dt phi_vals = np.asarray(phi_vals) f_vals = np.asarray(f_vals) w = np.linalg.lstsq(phi_vals, f_vals, rcond=None) if self.weights is None: self.weights = np.asarray(w[0]) else: self.weights = np.vstack([self.weights, w[0]])
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L45-L109
2
[ 0, 7, 8, 10, 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, 39, 40, 41, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 64 ]
81.538462
[ 9, 11 ]
3.076923
false
60
65
8
96.923077
3
def find_basis_functions_weights(self, training_data, data_period, num_weights=10): if not isinstance(training_data, np.ndarray): print("Warning: you should input training data as an np.ndarray") elif training_data.shape[0] < training_data.shape[1]: print("Warning: you probably need to transpose your training data") dt = data_period / len(training_data) init_state = training_data[0] goal_state = training_data[-1] # means (C) and std devs (H) of gaussian basis functions C = np.linspace(0, 1, num_weights) H = (0.65*(1./(num_weights-1))**2) for dim, _ in enumerate(training_data[0]): dimension_data = training_data[:, dim] q0 = init_state[dim] g = goal_state[dim] q = q0 qd_last = 0 phi_vals = [] f_vals = [] for i, _ in enumerate(dimension_data): if i + 1 == len(dimension_data): qd = 0 else: qd = (dimension_data[i+1] - dimension_data[i]) / dt phi = [np.exp(-0.5 * ((i * dt / data_period) - c)**2 / H) for c in C] phi = phi/np.sum(phi) qdd = (qd - qd_last)/dt f = (qdd * data_period**2 - self.K * (g - q) + self.B * qd * data_period) / (g - q0) phi_vals.append(phi) f_vals.append(f) qd_last = qd q += qd * dt phi_vals = np.asarray(phi_vals) f_vals = np.asarray(f_vals) w = np.linalg.lstsq(phi_vals, f_vals, rcond=None) if self.weights is None: self.weights = np.asarray(w[0]) else: self.weights = np.vstack([self.weights, w[0]])
1,162
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.recreate_trajectory
(self, init_state, goal_state, T)
return t, positions
init_state - initial state/position goal_state - goal state/position T - amount of time to travel q0 -> g
init_state - initial state/position goal_state - goal state/position T - amount of time to travel q0 -> g
111
160
def recreate_trajectory(self, init_state, goal_state, T): """ init_state - initial state/position goal_state - goal state/position T - amount of time to travel q0 -> g """ nrBasis = len(self.weights[0]) # number of gaussian basis functions # means (C) and std devs (H) of gaussian basis functions C = np.linspace(0, 1, nrBasis) H = (0.65*(1./(nrBasis-1))**2) # initialize virtual system time = 0 q = init_state dimensions = self.weights.shape[0] qd = np.zeros(dimensions) positions = np.array([]) for k in range(self.timesteps): time = time + self.dt qdd = np.zeros(dimensions) for dim in range(dimensions): if time <= T: phi = [np.exp(-0.5 * ((time / T) - c)**2 / H) for c in C] phi = phi / np.sum(phi) f = np.dot(phi, self.weights[dim]) else: f = 0 # simulate dynamics qdd[dim] = (self.K*(goal_state[dim] - q[dim])/T**2 - self.B*qd[dim]/T + (goal_state[dim] - init_state[dim])*f/T**2) qd = qd + qdd * self.dt q = q + qd * self.dt if positions.size == 0: positions = q else: positions = np.vstack([positions, q]) t = np.arange(0, self.timesteps * self.dt, self.dt) return t, positions
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L111-L160
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 ]
100
[]
0
true
60
50
6
100
3
def recreate_trajectory(self, init_state, goal_state, T): nrBasis = len(self.weights[0]) # number of gaussian basis functions # means (C) and std devs (H) of gaussian basis functions C = np.linspace(0, 1, nrBasis) H = (0.65*(1./(nrBasis-1))**2) # initialize virtual system time = 0 q = init_state dimensions = self.weights.shape[0] qd = np.zeros(dimensions) positions = np.array([]) for k in range(self.timesteps): time = time + self.dt qdd = np.zeros(dimensions) for dim in range(dimensions): if time <= T: phi = [np.exp(-0.5 * ((time / T) - c)**2 / H) for c in C] phi = phi / np.sum(phi) f = np.dot(phi, self.weights[dim]) else: f = 0 # simulate dynamics qdd[dim] = (self.K*(goal_state[dim] - q[dim])/T**2 - self.B*qd[dim]/T + (goal_state[dim] - init_state[dim])*f/T**2) qd = qd + qdd * self.dt q = q + qd * self.dt if positions.size == 0: positions = q else: positions = np.vstack([positions, q]) t = np.arange(0, self.timesteps * self.dt, self.dt) return t, positions
1,163
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.dist_between
(p1, p2)
return np.linalg.norm(p1 - p2)
163
164
def dist_between(p1, p2): return np.linalg.norm(p1 - p2)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L163-L164
2
[ 0 ]
50
[ 1 ]
50
false
60
2
1
50
0
def dist_between(p1, p2): return np.linalg.norm(p1 - p2)
1,164
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.view_trajectory
(self, path, title=None, demo=False)
166
189
def view_trajectory(self, path, title=None, demo=False): path = np.asarray(path) plt.cla() plt.plot(self.training_data[:, 0], self.training_data[:, 1], label="Training Data") plt.plot(path[:, 0], path[:, 1], linewidth=2, label="DMP Approximation") plt.xlabel("X Position") plt.ylabel("Y Position") plt.legend() if title is not None: plt.title(title) if demo: plt.xlim([-0.5, 5]) plt.ylim([-2, 2]) plt.draw() plt.pause(0.02) else: plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L166-L189
2
[ 0, 1 ]
8.333333
[ 2, 4, 5, 7, 10, 11, 12, 14, 15, 17, 18, 19, 20, 21, 23 ]
62.5
false
60
24
3
37.5
0
def view_trajectory(self, path, title=None, demo=False): path = np.asarray(path) plt.cla() plt.plot(self.training_data[:, 0], self.training_data[:, 1], label="Training Data") plt.plot(path[:, 0], path[:, 1], linewidth=2, label="DMP Approximation") plt.xlabel("X Position") plt.ylabel("Y Position") plt.legend() if title is not None: plt.title(title) if demo: plt.xlim([-0.5, 5]) plt.ylim([-2, 2]) plt.draw() plt.pause(0.02) else: plt.show()
1,165
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py
DMP.show_DMP_purpose
(self)
This function conveys the purpose of DMPs: to capture a trajectory and be able to stretch and squeeze it in terms of start and stop position or time
This function conveys the purpose of DMPs: to capture a trajectory and be able to stretch and squeeze it in terms of start and stop position or time
191
235
def show_DMP_purpose(self): """ This function conveys the purpose of DMPs: to capture a trajectory and be able to stretch and squeeze it in terms of start and stop position or time """ q0_orig = self.training_data[0] g_orig = self.training_data[-1] T_orig = self.T_orig data_range = (np.amax(self.training_data[:, 0]) - np.amin(self.training_data[:, 0])) / 4 q0_right = q0_orig + np.array([data_range, 0]) q0_up = q0_orig + np.array([0, data_range/2]) g_left = g_orig - np.array([data_range, 0]) g_down = g_orig - np.array([0, data_range/2]) q0_vals = np.vstack([np.linspace(q0_orig, q0_right, 20), np.linspace(q0_orig, q0_up, 20)]) g_vals = np.vstack([np.linspace(g_orig, g_left, 20), np.linspace(g_orig, g_down, 20)]) T_vals = np.linspace(T_orig, 2*T_orig, 20) for new_q0_value in q0_vals: plot_title = "Initial Position = [%s, %s]" % \ (round(new_q0_value[0], 2), round(new_q0_value[1], 2)) _, path = self.recreate_trajectory(new_q0_value, g_orig, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_g_value in g_vals: plot_title = "Goal Position = [%s, %s]" % \ (round(new_g_value[0], 2), round(new_g_value[1], 2)) _, path = self.recreate_trajectory(q0_orig, new_g_value, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_T_value in T_vals: plot_title = "Period = %s [sec]" % round(new_T_value, 2) _, path = self.recreate_trajectory(q0_orig, g_orig, new_T_value) self.view_trajectory(path, title=plot_title, demo=True)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py#L191-L235
2
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
17.777778
[ 8, 9, 10, 12, 15, 16, 17, 18, 20, 22, 24, 26, 27, 30, 31, 33, 34, 37, 38, 40, 41, 43, 44 ]
51.111111
false
60
45
4
48.888889
4
def show_DMP_purpose(self): q0_orig = self.training_data[0] g_orig = self.training_data[-1] T_orig = self.T_orig data_range = (np.amax(self.training_data[:, 0]) - np.amin(self.training_data[:, 0])) / 4 q0_right = q0_orig + np.array([data_range, 0]) q0_up = q0_orig + np.array([0, data_range/2]) g_left = g_orig - np.array([data_range, 0]) g_down = g_orig - np.array([0, data_range/2]) q0_vals = np.vstack([np.linspace(q0_orig, q0_right, 20), np.linspace(q0_orig, q0_up, 20)]) g_vals = np.vstack([np.linspace(g_orig, g_left, 20), np.linspace(g_orig, g_down, 20)]) T_vals = np.linspace(T_orig, 2*T_orig, 20) for new_q0_value in q0_vals: plot_title = "Initial Position = [%s, %s]" % \ (round(new_q0_value[0], 2), round(new_q0_value[1], 2)) _, path = self.recreate_trajectory(new_q0_value, g_orig, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_g_value in g_vals: plot_title = "Goal Position = [%s, %s]" % \ (round(new_g_value[0], 2), round(new_g_value[1], 2)) _, path = self.recreate_trajectory(q0_orig, new_g_value, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_T_value in T_vals: plot_title = "Period = %s [sec]" % round(new_T_value, 2) _, path = self.recreate_trajectory(q0_orig, g_orig, new_T_value) self.view_trajectory(path, title=plot_title, demo=True)
1,166
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
plan_dubins_path
(s_x, s_y, s_yaw, g_x, g_y, g_yaw, curvature, step_size=0.1, selected_types=None)
return x_list, y_list, yaw_list, modes, lengths
Plan dubins path Parameters ---------- s_x : float x position of the start point [m] s_y : float y position of the start point [m] s_yaw : float yaw angle of the start point [rad] g_x : float x position of the goal point [m] g_y : float y position of the end point [m] g_yaw : float yaw angle of the end point [rad] curvature : float curvature for curve [1/m] step_size : float (optional) step size between two path points [m]. Default is 0.1 selected_types : a list of string or None selected path planning types. If None, all types are used for path planning, and minimum path length result is returned. You can select used path plannings types by a string list. e.g.: ["RSL", "RSR"] Returns ------- x_list: array x positions of the path y_list: array y positions of the path yaw_list: array yaw angles of the path modes: array mode list of the path lengths: array arrow_length list of the path segments. Examples -------- You can generate a dubins path. >>> start_x = 1.0 # [m] >>> start_y = 1.0 # [m] >>> start_yaw = np.deg2rad(45.0) # [rad] >>> end_x = -3.0 # [m] >>> end_y = -3.0 # [m] >>> end_yaw = np.deg2rad(-45.0) # [rad] >>> curvature = 1.0 >>> path_x, path_y, path_yaw, mode, _ = plan_dubins_path( start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature) >>> plt.plot(path_x, path_y, label="final course " + "".join(mode)) >>> plot_arrow(start_x, start_y, start_yaw) >>> plot_arrow(end_x, end_y, end_yaw) >>> plt.legend() >>> plt.grid(True) >>> plt.axis("equal") >>> plt.show() .. image:: dubins_path.jpg
Plan dubins path
19
107
def plan_dubins_path(s_x, s_y, s_yaw, g_x, g_y, g_yaw, curvature, step_size=0.1, selected_types=None): """ Plan dubins path Parameters ---------- s_x : float x position of the start point [m] s_y : float y position of the start point [m] s_yaw : float yaw angle of the start point [rad] g_x : float x position of the goal point [m] g_y : float y position of the end point [m] g_yaw : float yaw angle of the end point [rad] curvature : float curvature for curve [1/m] step_size : float (optional) step size between two path points [m]. Default is 0.1 selected_types : a list of string or None selected path planning types. If None, all types are used for path planning, and minimum path length result is returned. You can select used path plannings types by a string list. e.g.: ["RSL", "RSR"] Returns ------- x_list: array x positions of the path y_list: array y positions of the path yaw_list: array yaw angles of the path modes: array mode list of the path lengths: array arrow_length list of the path segments. Examples -------- You can generate a dubins path. >>> start_x = 1.0 # [m] >>> start_y = 1.0 # [m] >>> start_yaw = np.deg2rad(45.0) # [rad] >>> end_x = -3.0 # [m] >>> end_y = -3.0 # [m] >>> end_yaw = np.deg2rad(-45.0) # [rad] >>> curvature = 1.0 >>> path_x, path_y, path_yaw, mode, _ = plan_dubins_path( start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature) >>> plt.plot(path_x, path_y, label="final course " + "".join(mode)) >>> plot_arrow(start_x, start_y, start_yaw) >>> plot_arrow(end_x, end_y, end_yaw) >>> plt.legend() >>> plt.grid(True) >>> plt.axis("equal") >>> plt.show() .. image:: dubins_path.jpg """ if selected_types is None: planning_funcs = _PATH_TYPE_MAP.values() else: planning_funcs = [_PATH_TYPE_MAP[ptype] for ptype in selected_types] # calculate local goal x, y, yaw l_rot = rot_mat_2d(s_yaw) le_xy = np.stack([g_x - s_x, g_y - s_y]).T @ l_rot local_goal_x = le_xy[0] local_goal_y = le_xy[1] local_goal_yaw = g_yaw - s_yaw lp_x, lp_y, lp_yaw, modes, lengths = _dubins_path_planning_from_origin( local_goal_x, local_goal_y, local_goal_yaw, curvature, step_size, planning_funcs) # Convert a local coordinate path to the global coordinate rot = rot_mat_2d(-s_yaw) converted_xy = np.stack([lp_x, lp_y]).T @ rot x_list = converted_xy[:, 0] + s_x y_list = converted_xy[:, 1] + s_y yaw_list = angle_mod(np.array(lp_yaw) + s_yaw) return x_list, y_list, yaw_list, modes, lengths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L19-L107
2
[ 0, 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 ]
29.213483
[]
0
false
94.152047
89
3
100
61
def plan_dubins_path(s_x, s_y, s_yaw, g_x, g_y, g_yaw, curvature, step_size=0.1, selected_types=None): if selected_types is None: planning_funcs = _PATH_TYPE_MAP.values() else: planning_funcs = [_PATH_TYPE_MAP[ptype] for ptype in selected_types] # calculate local goal x, y, yaw l_rot = rot_mat_2d(s_yaw) le_xy = np.stack([g_x - s_x, g_y - s_y]).T @ l_rot local_goal_x = le_xy[0] local_goal_y = le_xy[1] local_goal_yaw = g_yaw - s_yaw lp_x, lp_y, lp_yaw, modes, lengths = _dubins_path_planning_from_origin( local_goal_x, local_goal_y, local_goal_yaw, curvature, step_size, planning_funcs) # Convert a local coordinate path to the global coordinate rot = rot_mat_2d(-s_yaw) converted_xy = np.stack([lp_x, lp_y]).T @ rot x_list = converted_xy[:, 0] + s_x y_list = converted_xy[:, 1] + s_y yaw_list = angle_mod(np.array(lp_yaw) + s_yaw) return x_list, y_list, yaw_list, modes, lengths
1,167
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_mod2pi
(theta)
return angle_mod(theta, zero_2_2pi=True)
110
111
def _mod2pi(theta): return angle_mod(theta, zero_2_2pi=True)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L110-L111
2
[ 0, 1 ]
100
[]
0
true
94.152047
2
1
100
0
def _mod2pi(theta): return angle_mod(theta, zero_2_2pi=True)
1,168
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_calc_trig_funcs
(alpha, beta)
return sin_a, sin_b, cos_a, cos_b, cos_ab
114
120
def _calc_trig_funcs(alpha, beta): sin_a = sin(alpha) sin_b = sin(beta) cos_a = cos(alpha) cos_b = cos(beta) cos_ab = cos(alpha - beta) return sin_a, sin_b, cos_a, cos_b, cos_ab
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L114-L120
2
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
94.152047
7
1
100
0
def _calc_trig_funcs(alpha, beta): sin_a = sin(alpha) sin_b = sin(beta) cos_a = cos(alpha) cos_b = cos(beta) cos_ab = cos(alpha - beta) return sin_a, sin_b, cos_a, cos_b, cos_ab
1,169
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_LSL
(alpha, beta, d)
return d1, d2, d3, mode
123
133
def _LSL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["L", "S", "L"] p_squared = 2 + d ** 2 - (2 * cos_ab) + (2 * d * (sin_a - sin_b)) if p_squared < 0: # invalid configuration return None, None, None, mode tmp = atan2((cos_b - cos_a), d + sin_a - sin_b) d1 = _mod2pi(-alpha + tmp) d2 = sqrt(p_squared) d3 = _mod2pi(beta - tmp) return d1, d2, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L123-L133
2
[ 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 ]
90.909091
[ 5 ]
9.090909
false
94.152047
11
2
90.909091
0
def _LSL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["L", "S", "L"] p_squared = 2 + d ** 2 - (2 * cos_ab) + (2 * d * (sin_a - sin_b)) if p_squared < 0: # invalid configuration return None, None, None, mode tmp = atan2((cos_b - cos_a), d + sin_a - sin_b) d1 = _mod2pi(-alpha + tmp) d2 = sqrt(p_squared) d3 = _mod2pi(beta - tmp) return d1, d2, d3, mode
1,170
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_RSR
(alpha, beta, d)
return d1, d2, d3, mode
136
146
def _RSR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["R", "S", "R"] p_squared = 2 + d ** 2 - (2 * cos_ab) + (2 * d * (sin_b - sin_a)) if p_squared < 0: return None, None, None, mode tmp = atan2((cos_a - cos_b), d - sin_a + sin_b) d1 = _mod2pi(alpha - tmp) d2 = sqrt(p_squared) d3 = _mod2pi(-beta + tmp) return d1, d2, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L136-L146
2
[ 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 ]
90.909091
[ 5 ]
9.090909
false
94.152047
11
2
90.909091
0
def _RSR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["R", "S", "R"] p_squared = 2 + d ** 2 - (2 * cos_ab) + (2 * d * (sin_b - sin_a)) if p_squared < 0: return None, None, None, mode tmp = atan2((cos_a - cos_b), d - sin_a + sin_b) d1 = _mod2pi(alpha - tmp) d2 = sqrt(p_squared) d3 = _mod2pi(-beta + tmp) return d1, d2, d3, mode
1,171
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_LSR
(alpha, beta, d)
return d2, d1, d3, mode
149
159
def _LSR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) p_squared = -2 + d ** 2 + (2 * cos_ab) + (2 * d * (sin_a + sin_b)) mode = ["L", "S", "R"] if p_squared < 0: return None, None, None, mode d1 = sqrt(p_squared) tmp = atan2((-cos_a - cos_b), (d + sin_a + sin_b)) - atan2(-2.0, d1) d2 = _mod2pi(-alpha + tmp) d3 = _mod2pi(-_mod2pi(beta) + tmp) return d2, d1, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L149-L159
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
94.152047
11
2
100
0
def _LSR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) p_squared = -2 + d ** 2 + (2 * cos_ab) + (2 * d * (sin_a + sin_b)) mode = ["L", "S", "R"] if p_squared < 0: return None, None, None, mode d1 = sqrt(p_squared) tmp = atan2((-cos_a - cos_b), (d + sin_a + sin_b)) - atan2(-2.0, d1) d2 = _mod2pi(-alpha + tmp) d3 = _mod2pi(-_mod2pi(beta) + tmp) return d2, d1, d3, mode
1,172
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_RSL
(alpha, beta, d)
return d2, d1, d3, mode
162
172
def _RSL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) p_squared = d ** 2 - 2 + (2 * cos_ab) - (2 * d * (sin_a + sin_b)) mode = ["R", "S", "L"] if p_squared < 0: return None, None, None, mode d1 = sqrt(p_squared) tmp = atan2((cos_a + cos_b), (d - sin_a - sin_b)) - atan2(2.0, d1) d2 = _mod2pi(alpha - tmp) d3 = _mod2pi(beta - tmp) return d2, d1, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L162-L172
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
94.152047
11
2
100
0
def _RSL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) p_squared = d ** 2 - 2 + (2 * cos_ab) - (2 * d * (sin_a + sin_b)) mode = ["R", "S", "L"] if p_squared < 0: return None, None, None, mode d1 = sqrt(p_squared) tmp = atan2((cos_a + cos_b), (d - sin_a - sin_b)) - atan2(2.0, d1) d2 = _mod2pi(alpha - tmp) d3 = _mod2pi(beta - tmp) return d2, d1, d3, mode
1,173
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_RLR
(alpha, beta, d)
return d1, d2, d3, mode
175
184
def _RLR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["R", "L", "R"] tmp = (6.0 - d ** 2 + 2.0 * cos_ab + 2.0 * d * (sin_a - sin_b)) / 8.0 if abs(tmp) > 1.0: return None, None, None, mode d2 = _mod2pi(2 * pi - acos(tmp)) d1 = _mod2pi(alpha - atan2(cos_a - cos_b, d - sin_a + sin_b) + d2 / 2.0) d3 = _mod2pi(alpha - beta - d1 + d2) return d1, d2, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L175-L184
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
94.152047
10
2
100
0
def _RLR(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["R", "L", "R"] tmp = (6.0 - d ** 2 + 2.0 * cos_ab + 2.0 * d * (sin_a - sin_b)) / 8.0 if abs(tmp) > 1.0: return None, None, None, mode d2 = _mod2pi(2 * pi - acos(tmp)) d1 = _mod2pi(alpha - atan2(cos_a - cos_b, d - sin_a + sin_b) + d2 / 2.0) d3 = _mod2pi(alpha - beta - d1 + d2) return d1, d2, d3, mode
1,174
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_LRL
(alpha, beta, d)
return d1, d2, d3, mode
187
196
def _LRL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["L", "R", "L"] tmp = (6.0 - d ** 2 + 2.0 * cos_ab + 2.0 * d * (- sin_a + sin_b)) / 8.0 if abs(tmp) > 1.0: return None, None, None, mode d2 = _mod2pi(2 * pi - acos(tmp)) d1 = _mod2pi(-alpha - atan2(cos_a - cos_b, d + sin_a - sin_b) + d2 / 2.0) d3 = _mod2pi(_mod2pi(beta) - alpha - d1 + _mod2pi(d2)) return d1, d2, d3, mode
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L187-L196
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
94.152047
10
2
100
0
def _LRL(alpha, beta, d): sin_a, sin_b, cos_a, cos_b, cos_ab = _calc_trig_funcs(alpha, beta) mode = ["L", "R", "L"] tmp = (6.0 - d ** 2 + 2.0 * cos_ab + 2.0 * d * (- sin_a + sin_b)) / 8.0 if abs(tmp) > 1.0: return None, None, None, mode d2 = _mod2pi(2 * pi - acos(tmp)) d1 = _mod2pi(-alpha - atan2(cos_a - cos_b, d + sin_a - sin_b) + d2 / 2.0) d3 = _mod2pi(_mod2pi(beta) - alpha - d1 + _mod2pi(d2)) return d1, d2, d3, mode
1,175
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_dubins_path_planning_from_origin
(end_x, end_y, end_yaw, curvature, step_size, planning_funcs)
return x_list, y_list, yaw_list, b_mode, lengths
203
231
def _dubins_path_planning_from_origin(end_x, end_y, end_yaw, curvature, step_size, planning_funcs): dx = end_x dy = end_y d = hypot(dx, dy) * curvature theta = _mod2pi(atan2(dy, dx)) alpha = _mod2pi(-theta) beta = _mod2pi(end_yaw - theta) best_cost = float("inf") b_d1, b_d2, b_d3, b_mode = None, None, None, None for planner in planning_funcs: d1, d2, d3, mode = planner(alpha, beta, d) if d1 is None: continue cost = (abs(d1) + abs(d2) + abs(d3)) if best_cost > cost: # Select minimum length one. b_d1, b_d2, b_d3, b_mode, best_cost = d1, d2, d3, mode, cost lengths = [b_d1, b_d2, b_d3] x_list, y_list, yaw_list = _generate_local_course(lengths, b_mode, curvature, step_size) lengths = [length / curvature for length in lengths] return x_list, y_list, yaw_list, b_mode, lengths
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L203-L231
2
[ 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28 ]
93.103448
[]
0
false
94.152047
29
5
100
0
def _dubins_path_planning_from_origin(end_x, end_y, end_yaw, curvature, step_size, planning_funcs): dx = end_x dy = end_y d = hypot(dx, dy) * curvature theta = _mod2pi(atan2(dy, dx)) alpha = _mod2pi(-theta) beta = _mod2pi(end_yaw - theta) best_cost = float("inf") b_d1, b_d2, b_d3, b_mode = None, None, None, None for planner in planning_funcs: d1, d2, d3, mode = planner(alpha, beta, d) if d1 is None: continue cost = (abs(d1) + abs(d2) + abs(d3)) if best_cost > cost: # Select minimum length one. b_d1, b_d2, b_d3, b_mode, best_cost = d1, d2, d3, mode, cost lengths = [b_d1, b_d2, b_d3] x_list, y_list, yaw_list = _generate_local_course(lengths, b_mode, curvature, step_size) lengths = [length / curvature for length in lengths] return x_list, y_list, yaw_list, b_mode, lengths
1,176
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_interpolate
(length, mode, max_curvature, origin_x, origin_y, origin_yaw, path_x, path_y, path_yaw)
return path_x, path_y, path_yaw
234
257
def _interpolate(length, mode, max_curvature, origin_x, origin_y, origin_yaw, path_x, path_y, path_yaw): if mode == "S": path_x.append(origin_x + length / max_curvature * cos(origin_yaw)) path_y.append(origin_y + length / max_curvature * sin(origin_yaw)) path_yaw.append(origin_yaw) else: # curve ldx = sin(length) / max_curvature ldy = 0.0 if mode == "L": # left turn ldy = (1.0 - cos(length)) / max_curvature elif mode == "R": # right turn ldy = (1.0 - cos(length)) / -max_curvature gdx = cos(-origin_yaw) * ldx + sin(-origin_yaw) * ldy gdy = -sin(-origin_yaw) * ldx + cos(-origin_yaw) * ldy path_x.append(origin_x + gdx) path_y.append(origin_y + gdy) if mode == "L": # left turn path_yaw.append(origin_yaw + length) elif mode == "R": # right turn path_yaw.append(origin_yaw - length) return path_x, path_y, path_yaw
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L234-L257
2
[ 0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
91.666667
[]
0
false
94.152047
24
6
100
0
def _interpolate(length, mode, max_curvature, origin_x, origin_y, origin_yaw, path_x, path_y, path_yaw): if mode == "S": path_x.append(origin_x + length / max_curvature * cos(origin_yaw)) path_y.append(origin_y + length / max_curvature * sin(origin_yaw)) path_yaw.append(origin_yaw) else: # curve ldx = sin(length) / max_curvature ldy = 0.0 if mode == "L": # left turn ldy = (1.0 - cos(length)) / max_curvature elif mode == "R": # right turn ldy = (1.0 - cos(length)) / -max_curvature gdx = cos(-origin_yaw) * ldx + sin(-origin_yaw) * ldy gdy = -sin(-origin_yaw) * ldx + cos(-origin_yaw) * ldy path_x.append(origin_x + gdx) path_y.append(origin_y + gdy) if mode == "L": # left turn path_yaw.append(origin_yaw + length) elif mode == "R": # right turn path_yaw.append(origin_yaw - length) return path_x, path_y, path_yaw
1,177
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
_generate_local_course
(lengths, modes, max_curvature, step_size)
return p_x, p_y, p_yaw
260
280
def _generate_local_course(lengths, modes, max_curvature, step_size): p_x, p_y, p_yaw = [0.0], [0.0], [0.0] for (mode, length) in zip(modes, lengths): if length == 0.0: continue # set origin state origin_x, origin_y, origin_yaw = p_x[-1], p_y[-1], p_yaw[-1] current_length = step_size while abs(current_length + step_size) <= abs(length): p_x, p_y, p_yaw = _interpolate(current_length, mode, max_curvature, origin_x, origin_y, origin_yaw, p_x, p_y, p_yaw) current_length += step_size p_x, p_y, p_yaw = _interpolate(length, mode, max_curvature, origin_x, origin_y, origin_yaw, p_x, p_y, p_yaw) return p_x, p_y, p_yaw
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L260-L280
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 19, 20 ]
85.714286
[]
0
false
94.152047
21
4
100
0
def _generate_local_course(lengths, modes, max_curvature, step_size): p_x, p_y, p_yaw = [0.0], [0.0], [0.0] for (mode, length) in zip(modes, lengths): if length == 0.0: continue # set origin state origin_x, origin_y, origin_yaw = p_x[-1], p_y[-1], p_yaw[-1] current_length = step_size while abs(current_length + step_size) <= abs(length): p_x, p_y, p_yaw = _interpolate(current_length, mode, max_curvature, origin_x, origin_y, origin_yaw, p_x, p_y, p_yaw) current_length += step_size p_x, p_y, p_yaw = _interpolate(length, mode, max_curvature, origin_x, origin_y, origin_yaw, p_x, p_y, p_yaw) return p_x, p_y, p_yaw
1,178
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/DubinsPath/dubins_path_planner.py
main
()
283
313
def main(): print("Dubins path planner sample start!!") import matplotlib.pyplot as plt from utils.plot import plot_arrow start_x = 1.0 # [m] start_y = 1.0 # [m] start_yaw = np.deg2rad(45.0) # [rad] end_x = -3.0 # [m] end_y = -3.0 # [m] end_yaw = np.deg2rad(-45.0) # [rad] curvature = 1.0 path_x, path_y, path_yaw, mode, lengths = plan_dubins_path(start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature) if show_animation: plt.plot(path_x, path_y, label="".join(mode)) plot_arrow(start_x, start_y, start_yaw) plot_arrow(end_x, end_y, end_yaw) plt.legend() plt.grid(True) plt.axis("equal") plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/DubinsPath/dubins_path_planner.py#L283-L313
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23 ]
58.064516
[ 24, 25, 26, 27, 28, 29, 30 ]
22.580645
false
94.152047
31
2
77.419355
0
def main(): print("Dubins path planner sample start!!") import matplotlib.pyplot as plt from utils.plot import plot_arrow start_x = 1.0 # [m] start_y = 1.0 # [m] start_yaw = np.deg2rad(45.0) # [rad] end_x = -3.0 # [m] end_y = -3.0 # [m] end_yaw = np.deg2rad(-45.0) # [rad] curvature = 1.0 path_x, path_y, path_yaw, mode, lengths = plan_dubins_path(start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature) if show_animation: plt.plot(path_x, path_y, label="".join(mode)) plot_arrow(start_x, start_y, start_yaw) plot_arrow(end_x, end_y, end_yaw) plt.legend() plt.grid(True) plt.axis("equal") plt.show()
1,179
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BSplinePath/bspline_path.py
approximate_b_spline_path
(x: list, y: list, n_path_points: int, degree: int = 3, s=None, )
return _evaluate_spline(sampled, spl_i_x, spl_i_y)
Approximate points with a B-Spline path Parameters ---------- x : array_like x position list of approximated points y : array_like y position list of approximated points n_path_points : int number of path points degree : int, optional B Spline curve degree. Must be 2<= k <= 5. Default: 3. s : int, optional smoothing parameter. If this value is bigger, the path will be smoother, but it will be less accurate. If this value is smaller, the path will be more accurate, but it will be less smooth. When `s` is 0, it is equivalent to the interpolation. Default is None, in this case `s` will be `len(x)`. Returns ------- x : array x positions of the result path y : array y positions of the result path heading : array heading of the result path curvature : array curvature of the result path
Approximate points with a B-Spline path
19
63
def approximate_b_spline_path(x: list, y: list, n_path_points: int, degree: int = 3, s=None, ) -> tuple: """ Approximate points with a B-Spline path Parameters ---------- x : array_like x position list of approximated points y : array_like y position list of approximated points n_path_points : int number of path points degree : int, optional B Spline curve degree. Must be 2<= k <= 5. Default: 3. s : int, optional smoothing parameter. If this value is bigger, the path will be smoother, but it will be less accurate. If this value is smaller, the path will be more accurate, but it will be less smooth. When `s` is 0, it is equivalent to the interpolation. Default is None, in this case `s` will be `len(x)`. Returns ------- x : array x positions of the result path y : array y positions of the result path heading : array heading of the result path curvature : array curvature of the result path """ distances = _calc_distance_vector(x, y) spl_i_x = interpolate.UnivariateSpline(distances, x, k=degree, s=s) spl_i_y = interpolate.UnivariateSpline(distances, y, k=degree, s=s) sampled = np.linspace(0.0, distances[-1], n_path_points) return _evaluate_spline(sampled, spl_i_x, spl_i_y)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BSplinePath/bspline_path.py#L19-L63
2
[ 0, 37, 38, 39, 40, 41, 42, 43, 44 ]
20
[]
0
false
57.894737
45
1
100
29
def approximate_b_spline_path(x: list, y: list, n_path_points: int, degree: int = 3, s=None, ) -> tuple: distances = _calc_distance_vector(x, y) spl_i_x = interpolate.UnivariateSpline(distances, x, k=degree, s=s) spl_i_y = interpolate.UnivariateSpline(distances, y, k=degree, s=s) sampled = np.linspace(0.0, distances[-1], n_path_points) return _evaluate_spline(sampled, spl_i_x, spl_i_y)
1,180
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BSplinePath/bspline_path.py
interpolate_b_spline_path
(x, y, n_path_points: int, degree: int = 3)
return approximate_b_spline_path(x, y, n_path_points, degree, s=0.0)
Interpolate x-y points with a B-Spline path Parameters ---------- x : array_like x positions of interpolated points y : array_like y positions of interpolated points n_path_points : int number of path points degree : int, optional B-Spline degree. Must be 2<= k <= 5. Default: 3 Returns ------- x : array x positions of the result path y : array y positions of the result path heading : array heading of the result path curvature : array curvature of the result path
Interpolate x-y points with a B-Spline path
66
95
def interpolate_b_spline_path(x, y, n_path_points: int, degree: int = 3) -> tuple: """ Interpolate x-y points with a B-Spline path Parameters ---------- x : array_like x positions of interpolated points y : array_like y positions of interpolated points n_path_points : int number of path points degree : int, optional B-Spline degree. Must be 2<= k <= 5. Default: 3 Returns ------- x : array x positions of the result path y : array y positions of the result path heading : array heading of the result path curvature : array curvature of the result path """ return approximate_b_spline_path(x, y, n_path_points, degree, s=0.0)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BSplinePath/bspline_path.py#L66-L95
2
[ 0, 28, 29 ]
10
[]
0
false
57.894737
30
1
100
23
def interpolate_b_spline_path(x, y, n_path_points: int, degree: int = 3) -> tuple: return approximate_b_spline_path(x, y, n_path_points, degree, s=0.0)
1,181
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BSplinePath/bspline_path.py
_calc_distance_vector
(x, y)
return distances
98
103
def _calc_distance_vector(x, y): dx, dy = np.diff(x), np.diff(y) distances = np.cumsum([np.hypot(idx, idy) for idx, idy in zip(dx, dy)]) distances = np.concatenate(([0.0], distances)) distances /= distances[-1] return distances
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BSplinePath/bspline_path.py#L98-L103
2
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
57.894737
6
2
100
0
def _calc_distance_vector(x, y): dx, dy = np.diff(x), np.diff(y) distances = np.cumsum([np.hypot(idx, idy) for idx, idy in zip(dx, dy)]) distances = np.concatenate(([0.0], distances)) distances /= distances[-1] return distances
1,182
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BSplinePath/bspline_path.py
_evaluate_spline
(sampled, spl_i_x, spl_i_y)
return np.array(x), y, heading, curvature,
106
115
def _evaluate_spline(sampled, spl_i_x, spl_i_y): x = spl_i_x(sampled) y = spl_i_y(sampled) dx = spl_i_x.derivative(1)(sampled) dy = spl_i_y.derivative(1)(sampled) heading = np.arctan2(dy, dx) ddx = spl_i_x.derivative(2)(sampled) ddy = spl_i_y.derivative(2)(sampled) curvature = (ddy * dx - ddx * dy) / np.power(dx * dx + dy * dy, 2.0 / 3.0) return np.array(x), y, heading, curvature,
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BSplinePath/bspline_path.py#L106-L115
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
57.894737
10
1
100
0
def _evaluate_spline(sampled, spl_i_x, spl_i_y): x = spl_i_x(sampled) y = spl_i_y(sampled) dx = spl_i_x.derivative(1)(sampled) dy = spl_i_y.derivative(1)(sampled) heading = np.arctan2(dy, dx) ddx = spl_i_x.derivative(2)(sampled) ddy = spl_i_y.derivative(2)(sampled) curvature = (ddy * dx - ddx * dy) / np.power(dx * dx + dy * dy, 2.0 / 3.0) return np.array(x), y, heading, curvature,
1,183
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/BSplinePath/bspline_path.py
main
()
118
148
def main(): print(__file__ + " start!!") # way points way_point_x = [-1.0, 3.0, 4.0, 2.0, 1.0] way_point_y = [0.0, -3.0, 1.0, 1.0, 3.0] n_course_point = 50 # sampling number plt.subplots() rax, ray, heading, curvature = approximate_b_spline_path( way_point_x, way_point_y, n_course_point, s=0.5) plt.plot(rax, ray, '-r', label="Approximated B-Spline path") plot_curvature(rax, ray, heading, curvature) plt.title("B-Spline approximation") plt.plot(way_point_x, way_point_y, '-og', label="way points") plt.grid(True) plt.legend() plt.axis("equal") plt.subplots() rix, riy, heading, curvature = interpolate_b_spline_path( way_point_x, way_point_y, n_course_point) plt.plot(rix, riy, '-b', label="Interpolated B-Spline path") plot_curvature(rix, riy, heading, curvature) plt.title("B-Spline interpolation") plt.plot(way_point_x, way_point_y, '-og', label="way points") plt.grid(True) plt.legend() plt.axis("equal") plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/BSplinePath/bspline_path.py#L118-L148
2
[ 0 ]
3.225806
[ 1, 3, 4, 5, 7, 8, 10, 11, 13, 14, 15, 16, 17, 19, 20, 22, 23, 25, 26, 27, 28, 29, 30 ]
74.193548
false
57.894737
31
1
25.806452
0
def main(): print(__file__ + " start!!") # way points way_point_x = [-1.0, 3.0, 4.0, 2.0, 1.0] way_point_y = [0.0, -3.0, 1.0, 1.0, 3.0] n_course_point = 50 # sampling number plt.subplots() rax, ray, heading, curvature = approximate_b_spline_path( way_point_x, way_point_y, n_course_point, s=0.5) plt.plot(rax, ray, '-r', label="Approximated B-Spline path") plot_curvature(rax, ray, heading, curvature) plt.title("B-Spline approximation") plt.plot(way_point_x, way_point_y, '-og', label="way points") plt.grid(True) plt.legend() plt.axis("equal") plt.subplots() rix, riy, heading, curvature = interpolate_b_spline_path( way_point_x, way_point_y, n_course_point) plt.plot(rix, riy, '-b', label="Interpolated B-Spline path") plot_curvature(rix, riy, heading, curvature) plt.title("B-Spline interpolation") plt.plot(way_point_x, way_point_y, '-og', label="way points") plt.grid(True) plt.legend() plt.axis("equal") plt.show()
1,184
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
main
()
210
255
def main(): print(__file__ + " start!!") # start and goal position sx = -5.0 # [m] sy = -5.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] grid_size = 2.0 # [m] robot_radius = 1.0 # [m] # set obstacle positions ox, oy = [], [] for i in range(-10, 60): ox.append(i) oy.append(-10.0) for i in range(-10, 60): ox.append(60.0) oy.append(i) for i in range(-10, 61): ox.append(i) oy.append(60.0) for i in range(-10, 61): ox.append(-10.0) oy.append(i) for i in range(-10, 40): ox.append(20.0) oy.append(i) for i in range(0, 40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "og") plt.plot(gx, gy, "xb") plt.grid(True) plt.axis("equal") dijkstra = Dijkstra(ox, oy, grid_size, robot_radius) rx, ry = dijkstra.planning(sx, sy, gx, gy) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.01) plt.show()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L210-L255
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 38, 39, 40, 41 ]
100
[]
0
true
97.142857
46
9
100
0
def main(): print(__file__ + " start!!") # start and goal position sx = -5.0 # [m] sy = -5.0 # [m] gx = 50.0 # [m] gy = 50.0 # [m] grid_size = 2.0 # [m] robot_radius = 1.0 # [m] # set obstacle positions ox, oy = [], [] for i in range(-10, 60): ox.append(i) oy.append(-10.0) for i in range(-10, 60): ox.append(60.0) oy.append(i) for i in range(-10, 61): ox.append(i) oy.append(60.0) for i in range(-10, 61): ox.append(-10.0) oy.append(i) for i in range(-10, 40): ox.append(20.0) oy.append(i) for i in range(0, 40): ox.append(40.0) oy.append(60.0 - i) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "og") plt.plot(gx, gy, "xb") plt.grid(True) plt.axis("equal") dijkstra = Dijkstra(ox, oy, grid_size, robot_radius) rx, ry = dijkstra.planning(sx, sy, gx, gy) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.01) plt.show()
1,185
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.__init__
(self, ox, oy, resolution, robot_radius)
Initialize map for a star planning ox: x position list of Obstacles [m] oy: y position list of Obstacles [m] resolution: grid resolution [m] rr: robot radius[m]
Initialize map for a star planning
17
38
def __init__(self, ox, oy, resolution, robot_radius): """ Initialize map for a star planning ox: x position list of Obstacles [m] oy: y position list of Obstacles [m] resolution: grid resolution [m] rr: robot radius[m] """ self.min_x = None self.min_y = None self.max_x = None self.max_y = None self.x_width = None self.y_width = None self.obstacle_map = None self.resolution = resolution self.robot_radius = robot_radius self.calc_obstacle_map(ox, oy) self.motion = self.get_motion_model()
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L17-L38
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
100
[]
0
true
97.142857
22
1
100
6
def __init__(self, ox, oy, resolution, robot_radius): self.min_x = None self.min_y = None self.max_x = None self.max_y = None self.x_width = None self.y_width = None self.obstacle_map = None self.resolution = resolution self.robot_radius = robot_radius self.calc_obstacle_map(ox, oy) self.motion = self.get_motion_model()
1,186
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.planning
(self, sx, sy, gx, gy)
return rx, ry
dijkstra path search input: s_x: start x position [m] s_y: start y position [m] gx: goal x position [m] gx: goal x position [m] output: rx: x position list of the final path ry: y position list of the final path
dijkstra path search
51
123
def planning(self, sx, sy, gx, gy): """ dijkstra path search input: s_x: start x position [m] s_y: start y position [m] gx: goal x position [m] gx: goal x position [m] output: rx: x position list of the final path ry: y position list of the final path """ start_node = self.Node(self.calc_xy_index(sx, self.min_x), self.calc_xy_index(sy, self.min_y), 0.0, -1) goal_node = self.Node(self.calc_xy_index(gx, self.min_x), self.calc_xy_index(gy, self.min_y), 0.0, -1) open_set, closed_set = dict(), dict() open_set[self.calc_index(start_node)] = start_node while True: c_id = min(open_set, key=lambda o: open_set[o].cost) current = open_set[c_id] # show graph if show_animation: # pragma: no cover plt.plot(self.calc_position(current.x, self.min_x), self.calc_position(current.y, self.min_y), "xc") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) if len(closed_set.keys()) % 10 == 0: plt.pause(0.001) if current.x == goal_node.x and current.y == goal_node.y: print("Find goal") goal_node.parent_index = current.parent_index goal_node.cost = current.cost break # Remove the item from the open set del open_set[c_id] # Add it to the closed set closed_set[c_id] = current # expand search grid based on motion model for move_x, move_y, move_cost in self.motion: node = self.Node(current.x + move_x, current.y + move_y, current.cost + move_cost, c_id) n_id = self.calc_index(node) if n_id in closed_set: continue if not self.verify_node(node): continue if n_id not in open_set: open_set[n_id] = node # Discover a new node else: if open_set[n_id].cost >= node.cost: # This path is the best until now. record it! open_set[n_id] = node rx, ry = self.calc_final_path(goal_node, closed_set) return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L51-L123
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72 ]
107.352941
[]
0
true
97.142857
73
11
100
11
def planning(self, sx, sy, gx, gy): start_node = self.Node(self.calc_xy_index(sx, self.min_x), self.calc_xy_index(sy, self.min_y), 0.0, -1) goal_node = self.Node(self.calc_xy_index(gx, self.min_x), self.calc_xy_index(gy, self.min_y), 0.0, -1) open_set, closed_set = dict(), dict() open_set[self.calc_index(start_node)] = start_node while True: c_id = min(open_set, key=lambda o: open_set[o].cost) current = open_set[c_id] # show graph if show_animation: # pragma: no cover plt.plot(self.calc_position(current.x, self.min_x), self.calc_position(current.y, self.min_y), "xc") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect( 'key_release_event', lambda event: [exit(0) if event.key == 'escape' else None]) if len(closed_set.keys()) % 10 == 0: plt.pause(0.001) if current.x == goal_node.x and current.y == goal_node.y: print("Find goal") goal_node.parent_index = current.parent_index goal_node.cost = current.cost break # Remove the item from the open set del open_set[c_id] # Add it to the closed set closed_set[c_id] = current # expand search grid based on motion model for move_x, move_y, move_cost in self.motion: node = self.Node(current.x + move_x, current.y + move_y, current.cost + move_cost, c_id) n_id = self.calc_index(node) if n_id in closed_set: continue if not self.verify_node(node): continue if n_id not in open_set: open_set[n_id] = node # Discover a new node else: if open_set[n_id].cost >= node.cost: # This path is the best until now. record it! open_set[n_id] = node rx, ry = self.calc_final_path(goal_node, closed_set) return rx, ry
1,187
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.calc_final_path
(self, goal_node, closed_set)
return rx, ry
125
136
def calc_final_path(self, goal_node, closed_set): # generate final course rx, ry = [self.calc_position(goal_node.x, self.min_x)], [ self.calc_position(goal_node.y, self.min_y)] parent_index = goal_node.parent_index while parent_index != -1: n = closed_set[parent_index] rx.append(self.calc_position(n.x, self.min_x)) ry.append(self.calc_position(n.y, self.min_y)) parent_index = n.parent_index return rx, ry
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L125-L136
2
[ 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11 ]
91.666667
[]
0
false
97.142857
12
2
100
0
def calc_final_path(self, goal_node, closed_set): # generate final course rx, ry = [self.calc_position(goal_node.x, self.min_x)], [ self.calc_position(goal_node.y, self.min_y)] parent_index = goal_node.parent_index while parent_index != -1: n = closed_set[parent_index] rx.append(self.calc_position(n.x, self.min_x)) ry.append(self.calc_position(n.y, self.min_y)) parent_index = n.parent_index return rx, ry
1,188
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.calc_position
(self, index, minp)
return pos
138
140
def calc_position(self, index, minp): pos = index * self.resolution + minp return pos
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L138-L140
2
[ 0, 1, 2 ]
100
[]
0
true
97.142857
3
1
100
0
def calc_position(self, index, minp): pos = index * self.resolution + minp return pos
1,189
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.calc_xy_index
(self, position, minp)
return round((position - minp) / self.resolution)
142
143
def calc_xy_index(self, position, minp): return round((position - minp) / self.resolution)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L142-L143
2
[ 0, 1 ]
100
[]
0
true
97.142857
2
1
100
0
def calc_xy_index(self, position, minp): return round((position - minp) / self.resolution)
1,190
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.calc_index
(self, node)
return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
145
146
def calc_index(self, node): return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L145-L146
2
[ 0, 1 ]
100
[]
0
true
97.142857
2
1
100
0
def calc_index(self, node): return (node.y - self.min_y) * self.x_width + (node.x - self.min_x)
1,191
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.verify_node
(self, node)
return True
148
164
def verify_node(self, node): px = self.calc_position(node.x, self.min_x) py = self.calc_position(node.y, self.min_y) if px < self.min_x: return False if py < self.min_y: return False if px >= self.max_x: return False if py >= self.max_y: return False if self.obstacle_map[node.x][node.y]: return False return True
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L148-L164
2
[ 0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
88.235294
[ 5, 7 ]
11.764706
false
97.142857
17
6
88.235294
0
def verify_node(self, node): px = self.calc_position(node.x, self.min_x) py = self.calc_position(node.y, self.min_y) if px < self.min_x: return False if py < self.min_y: return False if px >= self.max_x: return False if py >= self.max_y: return False if self.obstacle_map[node.x][node.y]: return False return True
1,192
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.calc_obstacle_map
(self, ox, oy)
166
193
def calc_obstacle_map(self, ox, oy): self.min_x = round(min(ox)) self.min_y = round(min(oy)) self.max_x = round(max(ox)) self.max_y = round(max(oy)) print("min_x:", self.min_x) print("min_y:", self.min_y) print("max_x:", self.max_x) print("max_y:", self.max_y) self.x_width = round((self.max_x - self.min_x) / self.resolution) self.y_width = round((self.max_y - self.min_y) / self.resolution) print("x_width:", self.x_width) print("y_width:", self.y_width) # obstacle map generation self.obstacle_map = [[False for _ in range(self.y_width)] for _ in range(self.x_width)] for ix in range(self.x_width): x = self.calc_position(ix, self.min_x) for iy in range(self.y_width): y = self.calc_position(iy, self.min_y) for iox, ioy in zip(ox, oy): d = math.hypot(iox - x, ioy - y) if d <= self.robot_radius: self.obstacle_map[ix][iy] = True break
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L166-L193
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
96.428571
[]
0
false
97.142857
28
7
100
0
def calc_obstacle_map(self, ox, oy): self.min_x = round(min(ox)) self.min_y = round(min(oy)) self.max_x = round(max(ox)) self.max_y = round(max(oy)) print("min_x:", self.min_x) print("min_y:", self.min_y) print("max_x:", self.max_x) print("max_y:", self.max_y) self.x_width = round((self.max_x - self.min_x) / self.resolution) self.y_width = round((self.max_y - self.min_y) / self.resolution) print("x_width:", self.x_width) print("y_width:", self.y_width) # obstacle map generation self.obstacle_map = [[False for _ in range(self.y_width)] for _ in range(self.x_width)] for ix in range(self.x_width): x = self.calc_position(ix, self.min_x) for iy in range(self.y_width): y = self.calc_position(iy, self.min_y) for iox, ioy in zip(ox, oy): d = math.hypot(iox - x, ioy - y) if d <= self.robot_radius: self.obstacle_map[ix][iy] = True break
1,193
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/Dijkstra/dijkstra.py
Dijkstra.get_motion_model
()
return motion
196
207
def get_motion_model(): # dx, dy, cost motion = [[1, 0, 1], [0, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, math.sqrt(2)], [-1, 1, math.sqrt(2)], [1, -1, math.sqrt(2)], [1, 1, math.sqrt(2)]] return motion
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/Dijkstra/dijkstra.py#L196-L207
2
[ 0, 1, 2, 10, 11 ]
41.666667
[]
0
false
97.142857
12
1
100
0
def get_motion_model(): # dx, dy, cost motion = [[1, 0, 1], [0, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, math.sqrt(2)], [-1, 1, math.sqrt(2)], [1, -1, math.sqrt(2)], [1, 1, math.sqrt(2)]] return motion
1,194
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
calc_motion_inputs
()
90
94
def calc_motion_inputs(): for steer in np.concatenate((np.linspace(-MAX_STEER, MAX_STEER, N_STEER), [0.0])): for d in [1, -1]: yield [steer, d]
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L90-L94
2
[ 0, 1, 3, 4 ]
80
[]
0
false
90.37037
5
3
100
0
def calc_motion_inputs(): for steer in np.concatenate((np.linspace(-MAX_STEER, MAX_STEER, N_STEER), [0.0])): for d in [1, -1]: yield [steer, d]
1,195
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
get_neighbors
(current, config, ox, oy, kd_tree)
97
101
def get_neighbors(current, config, ox, oy, kd_tree): for steer, d in calc_motion_inputs(): node = calc_next_node(current, steer, d, config, ox, oy, kd_tree) if node and verify_index(node, config): yield node
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L97-L101
2
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
90.37037
5
4
100
0
def get_neighbors(current, config, ox, oy, kd_tree): for steer, d in calc_motion_inputs(): node = calc_next_node(current, steer, d, config, ox, oy, kd_tree) if node and verify_index(node, config): yield node
1,196
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
calc_next_node
(current, steer, direction, config, ox, oy, kd_tree)
return node
104
141
def calc_next_node(current, steer, direction, config, ox, oy, kd_tree): x, y, yaw = current.x_list[-1], current.y_list[-1], current.yaw_list[-1] arc_l = XY_GRID_RESOLUTION * 1.5 x_list, y_list, yaw_list = [], [], [] for _ in np.arange(0, arc_l, MOTION_RESOLUTION): x, y, yaw = move(x, y, yaw, MOTION_RESOLUTION * direction, steer) x_list.append(x) y_list.append(y) yaw_list.append(yaw) if not check_car_collision(x_list, y_list, yaw_list, ox, oy, kd_tree): return None d = direction == 1 x_ind = round(x / XY_GRID_RESOLUTION) y_ind = round(y / XY_GRID_RESOLUTION) yaw_ind = round(yaw / YAW_GRID_RESOLUTION) added_cost = 0.0 if d != current.direction: added_cost += SB_COST # steer penalty added_cost += STEER_COST * abs(steer) # steer change penalty added_cost += STEER_CHANGE_COST * abs(current.steer - steer) cost = current.cost + added_cost + arc_l node = Node(x_ind, y_ind, yaw_ind, d, x_list, y_list, yaw_list, [d], parent_index=calc_index(current, config), cost=cost, steer=steer) return node
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L104-L141
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 36, 37 ]
89.473684
[ 12 ]
2.631579
false
90.37037
38
4
97.368421
0
def calc_next_node(current, steer, direction, config, ox, oy, kd_tree): x, y, yaw = current.x_list[-1], current.y_list[-1], current.yaw_list[-1] arc_l = XY_GRID_RESOLUTION * 1.5 x_list, y_list, yaw_list = [], [], [] for _ in np.arange(0, arc_l, MOTION_RESOLUTION): x, y, yaw = move(x, y, yaw, MOTION_RESOLUTION * direction, steer) x_list.append(x) y_list.append(y) yaw_list.append(yaw) if not check_car_collision(x_list, y_list, yaw_list, ox, oy, kd_tree): return None d = direction == 1 x_ind = round(x / XY_GRID_RESOLUTION) y_ind = round(y / XY_GRID_RESOLUTION) yaw_ind = round(yaw / YAW_GRID_RESOLUTION) added_cost = 0.0 if d != current.direction: added_cost += SB_COST # steer penalty added_cost += STEER_COST * abs(steer) # steer change penalty added_cost += STEER_CHANGE_COST * abs(current.steer - steer) cost = current.cost + added_cost + arc_l node = Node(x_ind, y_ind, yaw_ind, d, x_list, y_list, yaw_list, [d], parent_index=calc_index(current, config), cost=cost, steer=steer) return node
1,197
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
is_same_grid
(n1, n2)
return False
144
149
def is_same_grid(n1, n2): if n1.x_index == n2.x_index \ and n1.y_index == n2.y_index \ and n1.yaw_index == n2.yaw_index: return True return False
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L144-L149
2
[ 0 ]
16.666667
[ 1, 4, 5 ]
50
false
90.37037
6
4
50
0
def is_same_grid(n1, n2): if n1.x_index == n2.x_index \ and n1.y_index == n2.y_index \ and n1.yaw_index == n2.yaw_index: return True return False
1,198
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
analytic_expansion
(current, goal, ox, oy, kd_tree)
return best_path
152
178
def analytic_expansion(current, goal, ox, oy, kd_tree): start_x = current.x_list[-1] start_y = current.y_list[-1] start_yaw = current.yaw_list[-1] goal_x = goal.x_list[-1] goal_y = goal.y_list[-1] goal_yaw = goal.yaw_list[-1] max_curvature = math.tan(MAX_STEER) / WB paths = rs.calc_paths(start_x, start_y, start_yaw, goal_x, goal_y, goal_yaw, max_curvature, step_size=MOTION_RESOLUTION) if not paths: return None best_path, best = None, None for path in paths: if check_car_collision(path.x, path.y, path.yaw, ox, oy, kd_tree): cost = calc_rs_path_cost(path) if not best or best > cost: best = cost best_path = path return best_path
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L152-L178
2
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 ]
88.888889
[ 15 ]
3.703704
false
90.37037
27
6
96.296296
0
def analytic_expansion(current, goal, ox, oy, kd_tree): start_x = current.x_list[-1] start_y = current.y_list[-1] start_yaw = current.yaw_list[-1] goal_x = goal.x_list[-1] goal_y = goal.y_list[-1] goal_yaw = goal.yaw_list[-1] max_curvature = math.tan(MAX_STEER) / WB paths = rs.calc_paths(start_x, start_y, start_yaw, goal_x, goal_y, goal_yaw, max_curvature, step_size=MOTION_RESOLUTION) if not paths: return None best_path, best = None, None for path in paths: if check_car_collision(path.x, path.y, path.yaw, ox, oy, kd_tree): cost = calc_rs_path_cost(path) if not best or best > cost: best = cost best_path = path return best_path
1,199
AtsushiSakai/PythonRobotics
15ab19688b2f6c03ee91a853f1f8cc9def84d162
PathPlanning/HybridAStar/hybrid_a_star.py
update_node_with_analytic_expansion
(current, goal, c, ox, oy, kd_tree)
return False, None
181
205
def update_node_with_analytic_expansion(current, goal, c, ox, oy, kd_tree): path = analytic_expansion(current, goal, ox, oy, kd_tree) if path: if show_animation: plt.plot(path.x, path.y) f_x = path.x[1:] f_y = path.y[1:] f_yaw = path.yaw[1:] f_cost = current.cost + calc_rs_path_cost(path) f_parent_index = calc_index(current, c) fd = [] for d in path.directions[1:]: fd.append(d >= 0) f_steer = 0.0 f_path = Node(current.x_index, current.y_index, current.yaw_index, current.direction, f_x, f_y, f_yaw, fd, cost=f_cost, parent_index=f_parent_index, steer=f_steer) return True, f_path return False, None
https://github.com/AtsushiSakai/PythonRobotics/blob/15ab19688b2f6c03ee91a853f1f8cc9def84d162/project2/PathPlanning/HybridAStar/hybrid_a_star.py#L181-L205
2
[ 0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24 ]
84
[ 6 ]
4
false
90.37037
25
4
96
0
def update_node_with_analytic_expansion(current, goal, c, ox, oy, kd_tree): path = analytic_expansion(current, goal, ox, oy, kd_tree) if path: if show_animation: plt.plot(path.x, path.y) f_x = path.x[1:] f_y = path.y[1:] f_yaw = path.yaw[1:] f_cost = current.cost + calc_rs_path_cost(path) f_parent_index = calc_index(current, c) fd = [] for d in path.directions[1:]: fd.append(d >= 0) f_steer = 0.0 f_path = Node(current.x_index, current.y_index, current.yaw_index, current.direction, f_x, f_y, f_yaw, fd, cost=f_cost, parent_index=f_parent_index, steer=f_steer) return True, f_path return False, None
1,200