Skip to content

Commit

Permalink
ok it works sort of
Browse files Browse the repository at this point in the history
  • Loading branch information
pmusau17 committed May 17, 2021
1 parent 29fc013 commit eb9bbbb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
41 changes: 33 additions & 8 deletions kinodynamic_rrt/kinodynamic_rrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def extract_path(self, node_end):
newest node.
"""
def search_goal_parent(self):
def search_goal_parent(self,all_paths=False):
# create a list of distances to the goal
# random sampling allows you to add a node to the tree more than once (need to figure out how to prevent that)
# well we will only consider
Expand Down Expand Up @@ -294,13 +294,16 @@ def search_goal_parent(self):
# get the dist
dist = math.hypot(node_new.x - self.s_goal.x, node_new.y - self.s_goal.y)
dists.append(dist)
index = np.asarray(dists).argmin()
node = candidates[index]

if(len(candidates)>0):
print(dists)


path =[]
if(len(candidates)>0 and not all_paths):
index = np.asarray(dists).argmin()
node = candidates[index]
path = self.extract_path(node)

return path
return path,candidates


"""
Expand All @@ -309,7 +312,7 @@ def search_goal_parent(self):
def plot_final(self):

# get the index of the closest point to the goal
self.path = self.search_goal_parent()
self.path,_ = self.search_goal_parent()


# get the path
Expand All @@ -318,18 +321,40 @@ def plot_final(self):
# get the index of the minimum cost vertex within a step length of the goal
self.plotting.animation(self.list_of_vertices, self.path, "Porto Final Solution, N={}".format(self.iter_max),True,True)

"""
Function that plots each of the paths
"""
"""
Function that plots final solution obtained
"""
def plot_final_all(self):

# get the index of the closest point to the goal
self.path,candidates = self.search_goal_parent(all_paths=True)
paths = []
for node in candidates:
path = self.extract_path(node)
paths.append(path)
# get the path
# self.path = self.extract_path([])

# get the index of the minimum cost vertex within a step length of the goal
self.plotting.animation_all(self.list_of_vertices, paths, "All paths Porto Final Solution, N={}".format(self.iter_max),True,True)



if __name__ == "__main__":
x_start = (-0.006356, 0.030406, 0.322701, 0.1)
x_goal = (1.077466, 0.921832,0.750663, 0.1)
grid = 'porto_grid.npy'
time_forward = 0.2
n_samples = 1000
n_samples = 100
goal_sample_rate = 0.10
throttle_speed = 0.3
number_of_motion_primitives = 5

kinodynamic_rrt = KinodynamicRRTStar(x_start, x_goal, time_forward,goal_sample_rate, throttle_speed, number_of_motion_primitives, n_samples,grid,min_speed=0.1)
kinodynamic_rrt.planning()
kinodynamic_rrt.plot_final()
#kinodynamic_rrt.plot_final_all()

16 changes: 14 additions & 2 deletions kinodynamic_rrt/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def animation(self,nodelist,path,name, animation=False,block=False):
# plot the final path
self.plot_path(path,block=block)


def animation_all(self,nodelist,paths,name, animation=False,block=False):
# plot the grid
#self.ax.clear()
self.plot_grid(name)
# plot visited nodes
self.plot_visited(nodelist, animation)
# plot the final path

for path in paths[:-1]:
self.plot_path(path,block=False,marker='--')
self.plot_path(paths[-1],block=block,marker='--')
"""
I'm a visual learner so this method just shows me how points are sampled
"""
Expand Down Expand Up @@ -117,9 +129,9 @@ def plot_visited(self,nodelist, animation):

# plotting a path via list comprehensions
#@staticmethod
def plot_path(self,path,block=False):
def plot_path(self,path,block=False,marker='-r'):
if len(path) != 0:
self.ax.plot([x[0] for x in path], [x[1] for x in path], '-r', linewidth=2)
self.ax.plot([x[0] for x in path], [x[1] for x in path], marker, linewidth=2)
plt.pause(0.01)
plt.show(block=block)

Expand Down

0 comments on commit eb9bbbb

Please sign in to comment.