コード例 #1
0
    def run(self):
        self.V.append(tuple(self.env.start))
        self.ind = 0
        self.fig = plt.figure(figsize=(10, 8))
        xnew = self.env.start
        while self.ind < self.maxiter and getDist(
                xnew, self.env.goal) > self.stepsize:
            xrand = sampleFree(self)
            xnearest = nearest(self, xrand)
            xnew = steer(self, xnearest, xrand)
            collide, _ = isCollide(self, xnearest, xnew)
            if not collide:
                self.V.append(xnew)  # add point
                self.wireup(xnew, xnearest)

                if getDist(xnew, self.env.goal) <= self.stepsize:
                    goal = tuple(self.env.goal)
                    self.wireup(goal, xnew)
                    self.Path, D = path(self)
                    print('Total distance = ' + str(D))
                # visualization(self)
                self.i += 1
            self.ind += 1
            # if the goal is really reached

        self.done = True
        visualization(self)
        plt.show()
コード例 #2
0
ファイル: rrt_star3D.py プロジェクト: kingdwd/PathPlanning-1
 def run(self):
     xnew = self.x0
     print('start rrt*... ')
     self.fig = plt.figure(figsize=(10, 8))
     while self.ind < self.maxiter:
         xrand = sampleFree(self)
         xnearest = nearest(self, xrand)
         xnew, dist = steer(self, xnearest, xrand)
         collide, _ = isCollide(self, xnearest, xnew, dist=dist)
         if not collide:
             Xnear = near(self, xnew)
             self.V.append(xnew)  # add point
             # visualization(self)
             # minimal path and minimal cost
             xmin, cmin = xnearest, cost(self, xnearest) + getDist(
                 xnearest, xnew)
             # connecting along minimal cost path
             Collide = []
             for xnear in Xnear:
                 xnear = tuple(xnear)
                 c1 = cost(self, xnear) + getDist(xnew, xnear)
                 collide, _ = isCollide(self, xnew, xnear)
                 Collide.append(collide)
                 if not collide and c1 < cmin:
                     xmin, cmin = xnear, c1
             self.wireup(xnew, xmin)
             # rewire
             for i in range(len(Xnear)):
                 collide = Collide[i]
                 xnear = tuple(Xnear[i])
                 c2 = cost(self, xnew) + getDist(xnew, xnear)
                 if not collide and c2 < cost(self, xnear):
                     # self.removewire(xnear)
                     self.wireup(xnear, xnew)
             self.i += 1
         self.ind += 1
     # max sample reached
     self.reached()
     print('time used = ' + str(time.time() - starttime))
     print('Total distance = ' + str(self.D))
     visualization(self)
     plt.show()
コード例 #3
0
 def run(self):
     self.V.append(self.env.start)
     self.ind = 0
     self.fig = plt.figure(figsize=(10, 8))
     xnew = self.env.start
     while self.ind < self.maxiter and getDist(xnew, self.env.goal) > 1:
         xrand = sampleFree(self)
         xnearest = nearest(self, xrand)
         xnew = steer(self, xnearest, xrand)
         if not isCollide(self, xnearest, xnew):
             self.V.append(xnew)  # add point
             self.wireup(xnew, xnearest)
             visualization(self)
             self.i += 1
         self.ind += 1
         if getDist(xnew, self.env.goal) <= 1:
             self.wireup(self.env.goal, xnew)
             self.Path, D = path(self)
             print('Total distance = ' + str(D))
     self.done = True
     visualization(self)
     plt.show()
コード例 #4
0
 def Main(self):
     qgoal = tuple(self.env.start)
     qstart = tuple(self.env.goal)
     self.GrowRRT()
     self.done = True
     # visualization(self)
     self.done = False
     # change the enviroment
     new0,old0 = self.env.move_block(a=[0, 0, -2], s=0.5, block_to_move=1, mode='translation')
     while qgoal != qstart:
         qgoal = self.Parent[qgoal]
         # TODO move to qgoal and check for new obs
         xrobot = qstart
         # TODO if any new obstacle are observed
         self.InvalidateNodes(new0, mode = 'translation')
         for xi in self.Path:
             if self.Flag[tuple(xi[0])] == 'Invalid':
                 self.RegrowRRT(tuple(self.env.start))
     self.done = True
     self.Path, D = path(self)
     visualization(self)
     plt.show()
コード例 #5
0
 def run(self):
     self.V.append(self.env.start)
     self.ind = 0
     xnew = self.env.start
     print('start rrt*... ')
     self.fig = plt.figure(figsize=(10, 8))
     while self.ind < self.maxiter:
         xrand = sampleFree(self)
         xnearest = nearest(self, xrand)
         xnew = steer(self, xnearest, xrand)
         if not isCollide(self, xnearest, xnew):
             Xnear = near(self, xnew)
             self.V.append(xnew)  # add point
             visualization(self)
             # minimal path and minimal cost
             xmin, cmin = xnearest, cost(self, xnearest) + getDist(
                 xnearest, xnew)
             # connecting along minimal cost path
             for xnear in Xnear:
                 c1 = cost(self, xnear) + getDist(xnew, xnear)
                 if not isCollide(self, xnew, xnear) and c1 < cmin:
                     xmin, cmin = xnear, c1
             self.wireup(xnew, xmin)
             # rewire
             for xnear in Xnear:
                 c2 = cost(self, xnew) + getDist(xnew, xnear)
                 if not isCollide(self, xnew,
                                  xnear) and c2 < cost(self, xnear):
                     self.removewire(xnear)
                     self.wireup(xnear, xnew)
             self.i += 1
         self.ind += 1
     # max sample reached
     self.reached()
     print('time used = ' + str(time.time() - starttime))
     print('Total distance = ' + str(self.D))
     visualization(self)
     plt.show()
コード例 #6
0
    def RRTplan(self, env, initial, goal):
        threshold = self.stepsize
        nearest = initial  # state structure
        self.V.append(initial)
        rrt_tree = initial  # TODO KDtree structure
        while self.ind <= self.maxiter:
            target = self.ChooseTarget(goal)
            nearest = self.Nearest(rrt_tree, target)
            extended, collide = self.Extend(env, nearest, target)
            if not collide:
                self.AddNode(rrt_tree, nearest, extended)
                if getDist(nearest, goal) <= threshold:
                    self.AddNode(rrt_tree, nearest, self.xt)
                    break
                self.i += 1
            self.ind += 1
            visualization(self)

        # return rrt_tree
        self.done = True
        self.Path, D = path(self)
        visualization(self)
        plt.show()
コード例 #7
0
ファイル: rrt3D.py プロジェクト: kingdwd/PathPlanning-1
    def run(self):
        self.V.append(self.x0)
        while self.ind < self.maxiter:
            xrand = sampleFree(self)
            xnearest = nearest(self, xrand)
            xnew, dist = steer(self, xnearest, xrand)
            collide, _ = isCollide(self, xnearest, xnew, dist=dist)
            if not collide:
                self.V.append(xnew)  # add point
                self.wireup(xnew, xnearest)

                if getDist(xnew, self.xt) <= self.stepsize:
                    self.wireup(self.xt, xnew)
                    self.Path, D = path(self)
                    print('Total distance = ' + str(D))
                    break
                # visualization(self)
                self.i += 1
            self.ind += 1
            # if the goal is really reached

        self.done = True
        visualization(self)
        plt.show()