def run(self, Reversed = True, xrobot = None): if Reversed: if xrobot is None: self.x0 = tuple(self.env.goal) self.xt = tuple(self.env.start) else: self.x0 = tuple(self.env.goal) self.xt = xrobot xnew = self.env.goal else: xnew = self.env.start self.V.append(self.x0) while self.ind < self.maxiter: 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 if self.Flag is not None: self.Flag[xnew] = 'Valid' 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)) if self.Flag is not None: self.Flag[self.xt] = 'Valid' break # visualization(self) self.i += 1 self.ind += 1
def Sample(self, xstart, xgoal, cmax, bias=0.05): # sample within a eclipse if cmax < np.inf: cmin = getDist(xgoal, xstart) xcenter = np.array([(xgoal[0] + xstart[0]) / 2, (xgoal[1] + xstart[1]) / 2, (xgoal[2] + xstart[2]) / 2]) C = self.RotationToWorldFrame(xstart, xgoal) r = np.zeros(3) r[0] = cmax / 2 for i in range(1, 3): r[i] = np.sqrt(cmax**2 - cmin**2) / 2 L = np.diag(r) # R3*3 xball = self.SampleUnitBall() # np.array x = C @ L @ xball + xcenter self.C = C # save to global var self.xcenter = xcenter self.L = L if not isinside(self, x): # intersection with the state space xrand = x else: return self.Sample(xstart, xgoal, cmax) else: xrand = sampleFree(self, bias=bias) return xrand
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()
def Sample(self, m, cmax, bias=0.05, xrand=set()): # sample within a eclipse print('new sample') if cmax < np.inf: cmin = getDist(self.xgoal, self.xstart) xcenter = np.array([(self.xgoal[0] + self.xstart[0]) / 2, (self.xgoal[1] + self.xstart[1]) / 2, (self.xgoal[2] + self.xstart[2]) / 2]) C = self.RotationToWorldFrame(self.xstart, self.xgoal) r = np.zeros(3) r[0] = cmax / 2 for i in range(1, 3): r[i] = np.sqrt(cmax**2 - cmin**2) / 2 L = np.diag(r) # R3*3 xball = self.SampleUnitBall(m) # np.array x = (C @ L @ xball).T + repmat(xcenter, len(xball.T), 1) # x2 = set(map(tuple, x)) self.C = C # save to global var self.xcenter = xcenter self.L = L x2 = set( map( tuple, x[np.array([ not isinside(self, state) and isinbound(self.env.boundary, state) for state in x ])])) # intersection with the state space xrand.update(x2) # if there are samples inside obstacle: recursion if len(x2) < m: return self.Sample(m - len(x2), cmax, bias=bias, xrand=xrand) else: for i in range(m): xrand.add(tuple(sampleFree(self, bias=bias))) return xrand
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()
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()
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()
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()
def RandomState(self): # generate a random, obstacle free state xrand = sampleFree(self, bias=0) return xrand
def RANDOM_CONFIG(self): return tuple(sampleFree(self))
def generateSampleSet(self, n): V = set() for i in range(n): V.add(tuple(sampleFree(self, bias=0.0))) return V