diff --git a/Sampling-based Planning/rrt_3D/__pycache__/env3D.cpython-37.pyc b/Sampling-based Planning/rrt_3D/__pycache__/env3D.cpython-37.pyc index 03312dd..d34d296 100644 Binary files a/Sampling-based Planning/rrt_3D/__pycache__/env3D.cpython-37.pyc and b/Sampling-based Planning/rrt_3D/__pycache__/env3D.cpython-37.pyc differ diff --git a/Sampling-based Planning/rrt_3D/__pycache__/plot_util3D.cpython-37.pyc b/Sampling-based Planning/rrt_3D/__pycache__/plot_util3D.cpython-37.pyc index b0f8a3b..231d1af 100644 Binary files a/Sampling-based Planning/rrt_3D/__pycache__/plot_util3D.cpython-37.pyc and b/Sampling-based Planning/rrt_3D/__pycache__/plot_util3D.cpython-37.pyc differ diff --git a/Sampling-based Planning/rrt_3D/__pycache__/utils3D.cpython-37.pyc b/Sampling-based Planning/rrt_3D/__pycache__/utils3D.cpython-37.pyc index 530e52a..6e99341 100644 Binary files a/Sampling-based Planning/rrt_3D/__pycache__/utils3D.cpython-37.pyc and b/Sampling-based Planning/rrt_3D/__pycache__/utils3D.cpython-37.pyc differ diff --git a/Sampling-based Planning/rrt_3D/rrtstar3D.py b/Sampling-based Planning/rrt_3D/rrtstar3D.py index dadc702..3734e8b 100644 --- a/Sampling-based Planning/rrt_3D/rrtstar3D.py +++ b/Sampling-based Planning/rrt_3D/rrtstar3D.py @@ -23,7 +23,7 @@ class rrtstar(): self.E = edgeset() self.V = [] self.i = 0 - self.maxiter = 4000 # at least 4000 in this env + self.maxiter = 10000 # at least 4000 in this env self.stepsize = 0.5 self.gamma = 500 self.eta = 1.1*self.stepsize @@ -61,7 +61,7 @@ class rrtstar(): if not isCollide(self,xnearest,xnew): Xnear = near(self,xnew) self.V.append(xnew) # add point - visualization(self) + # visualization(self) # minimal path and minimal cost xmin, cmin = xnearest, cost(self, xnearest) + getDist(xnearest, xnew) # connecting along minimal cost path diff --git a/Search-based Planning/Astar_3D/Astar3D.py b/Search-based Planning/Astar_3D/Astar3D.py new file mode 100644 index 0000000..9ebe7a7 --- /dev/null +++ b/Search-based Planning/Astar_3D/Astar3D.py @@ -0,0 +1,38 @@ +# this is the three dimensional A* algo +# !/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@author: yue qi +""" +import numpy as np + +import os +import sys + +sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../Search-based Planning/") +from Astar_3D.env3D import env +from Astar_3D.utils3D import getAABB, getDist, getRay, StateSpace, Heuristic +from queue import QueuePrior + + +class Weighted_A_star(object): + def __init__(self): + self.Alldirec = np.array([[1 ,0,0],[0,1 ,0],[0,0, 1],[1 ,1 ,0],[1 ,0,1 ],[0, 1, 1],[ 1, 1, 1],\ + [-1,0,0],[0,-1,0],[0,0,-1],[-1,-1,0],[-1,0,-1],[0,-1,-1],[-1,-1,-1],\ + [1,-1,0],[-1,1,0],[1,0,-1],[-1,0, 1],[0,1, -1],[0, -1,1],\ + [1,-1,-1],[-1,1,-1],[-1,-1,1],[1,1,-1],[1,-1,1],[-1,1,1]]) + self.env = env() + self.Space = StateSpace(env.boundary) # key is the point, store g value + self.OPEN = QueuePrior() # store [point,priority] + self.start = getNearest(self.Space,env.start) + self.goal = getNearest(self.Space,env.goal) + self.h = Heuristic(self.Space,self.goal) + self.Parent = {} + self.CLOSED = {} + + + def run(self): + pass +if __name__ == '__main__': + Astar = Weighted_A_star() + \ No newline at end of file diff --git a/Search-based Planning/Astar_3D/__pycache__/Astar3D.cpython-37.pyc b/Search-based Planning/Astar_3D/__pycache__/Astar3D.cpython-37.pyc new file mode 100644 index 0000000..cf15227 Binary files /dev/null and b/Search-based Planning/Astar_3D/__pycache__/Astar3D.cpython-37.pyc differ diff --git a/Search-based Planning/Astar_3D/__pycache__/env3D.cpython-37.pyc b/Search-based Planning/Astar_3D/__pycache__/env3D.cpython-37.pyc new file mode 100644 index 0000000..a3ab9d0 Binary files /dev/null and b/Search-based Planning/Astar_3D/__pycache__/env3D.cpython-37.pyc differ diff --git a/Search-based Planning/Astar_3D/__pycache__/utils3D.cpython-37.pyc b/Search-based Planning/Astar_3D/__pycache__/utils3D.cpython-37.pyc new file mode 100644 index 0000000..aae19a2 Binary files /dev/null and b/Search-based Planning/Astar_3D/__pycache__/utils3D.cpython-37.pyc differ diff --git a/Search-based Planning/3D/env3D.py b/Search-based Planning/Astar_3D/env3D.py similarity index 100% rename from Search-based Planning/3D/env3D.py rename to Search-based Planning/Astar_3D/env3D.py diff --git a/Search-based Planning/3D/plot_util3D.py b/Search-based Planning/Astar_3D/plot_util3D.py similarity index 100% rename from Search-based Planning/3D/plot_util3D.py rename to Search-based Planning/Astar_3D/plot_util3D.py diff --git a/Search-based Planning/Astar_3D/utils3D.py b/Search-based Planning/Astar_3D/utils3D.py new file mode 100644 index 0000000..5db2fd9 --- /dev/null +++ b/Search-based Planning/Astar_3D/utils3D.py @@ -0,0 +1,66 @@ +import numpy as np + +def getRay(x, y): + direc = [y[0] - x[0], y[1] - x[1], y[2] - x[2]] + return np.array([x, direc]) + +def getAABB(blocks): + AABB = [] + for i in blocks: + AABB.append(np.array([np.add(i[0:3], -0), np.add(i[3:6], 0)])) # make AABBs alittle bit of larger + return AABB + +def getDist(pos1, pos2): + return np.sqrt(sum([(pos1[0] - pos2[0]) ** 2, (pos1[1] - pos2[1]) ** 2, (pos1[2] - pos2[2]) ** 2])) + +def getNearest(Space,pt): + '''get the nearest point on the grid''' + mindis,minpt = 1000,None + for strpts in Space.keys(): + pts = dehash(strpts) + dis = getDist(pts,pt) + if dis < mindis: + mindis,minpt = dis,pts + return minpt + +def Heuristic(Space,t): + '''Max norm distance''' + h = {} + for k in Space.keys(): + h[k] = max(abs(t-dehash(k))) + return h + +def hash3D(x): + return str(x[0])+' '+str(x[1])+' '+str(x[2]) + +def dehash(x): + return np.array([float(i) for i in x.split(' ')]) + +def isinbound(i, x): + if i[0] <= x[0] < i[3] and i[1] <= x[1] < i[4] and i[2] <= x[2] < i[5]: + return True + return False + +def StateSpace(boundary,factor=0): + '''This function is used to get nodes and discretize the space. + State space is by x*y*z,3 where each 3 is a point in 3D.''' + xmin,xmax = boundary[0]+factor,boundary[3]-factor + ymin,ymax = boundary[1]+factor,boundary[4]-factor + zmin,zmax = boundary[2]+factor,boundary[5]-factor + xarr = np.arange(xmin,xmax,1) + yarr = np.arange(ymin,ymax,1) + zarr = np.arange(zmin,zmax,1) + V = np.meshgrid(xarr,yarr,zarr) + VV = np.reshape(V,[3,len(xarr)*len(yarr)*len(zarr)]) # all points in 3D + Space = {} + for v in VV.T: + Space[hash3D(v)] = 0 # this hashmap initialize all g values at 0 + return Space + +if __name__ == "__main__": + from env3D import env + env = env(resolution=1) + Space = StateSpace(env.boundary,0) + t = np.array([3.0,4.0,5.0]) + h = Heuristic(Space,t) + print(h[hash3D(t)]) \ No newline at end of file