From 89a04e5cbd502c95066cc1b2f02c54cbd462b8b6 Mon Sep 17 00:00:00 2001 From: yue qi <391311qy@gmail.com> Date: Sun, 26 Jul 2020 00:42:09 -0700 Subject: [PATCH] 'rrt' --- .../__pycache__/plot_util3D.cpython-37.pyc | Bin 5797 -> 5797 bytes .../rrt_3D/__pycache__/utils3D.cpython-37.pyc | Bin 7020 -> 7138 bytes Sampling-based Planning/rrt_3D/rrt3D.py | 19 +++++++++++------- Sampling-based Planning/rrt_3D/utils3D.py | 16 +++++++++------ 4 files changed, 22 insertions(+), 13 deletions(-) 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 c82ed3ea42894ad6e3d8c553d95253901678cfe1..7cb6a21e0bd83dd91ad15b197fa593d0fee8c351 100644 GIT binary patch delta 19 ZcmZ3gyHuCUiI-N`tici``~zLg-%}A}vtRij+((`N_n@ z$pjgmFuss9}BJUu+aR-8?@5gM?%+_tzrgH{^!ZW{P z8FA1Wc)1VdK#4mB3=#cYp97*|?Pdewx^;6*CB{j8FM&z$0>azVDicSqXQg~Kr6%T6 zd)V;3)zn9No?QI?7#~o6$OT!8&h%(&v&n4wG&_9nM*6yL?V~U+iQddm#{nXn)y`$c z*_ik^BZ}nMvEVpqSO~JMR0&thQ87;3(iKP%e}rHR!AU{gD=}U{kVa);K^ox41zrig z*@EFl@wQ0UvU}M{aVz`pa-NKa3Dhn2ler0QwB$=8^dsmb5k-;af*Xc0946X0KRF2} zk#fw&jZ3q%9E6@qVMj&9B@`gZJ?Vxxg&FvP<@e^=^^GdRJUr@ zoaXQuV3<;)Yp~g<5YmnlzZwVEe5`4slUqnv6_%4+wggcL{IVY(4*FCl!7Z~d%#PAx9QebNoo2{cEl8wyBZH((#E z=$mZaSevRDTi?beyJEmB%DA|bJG_y-hy|_bi#isK%{VPk&kr5I9)gPm?+~;TP>A|) zs^sglA^EJEEZ3)kmI=1-(W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KK^FdNZgGkf2m`!Q z`Kq@i9#%=F?72^p-kdN?1;6lW&pQ*+NDB8O`%+SiU{?hTcX$FHM|t))KGHikwL-dl zf^~v2!FF6FMQS12o?yabl@^U0YMn$ 1: + 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) @@ -47,13 +48,17 @@ class rrtstar(): 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 getDist(xnew, self.env.goal) <= 1: - self.wireup(self.env.goal, xnew) - self.Path, D = path(self) - print('Total distance = ' + str(D)) + # if the goal is really reached + self.done = True visualization(self) plt.show() diff --git a/Sampling-based Planning/rrt_3D/utils3D.py b/Sampling-based Planning/rrt_3D/utils3D.py index 2c0d7d9..b256aa0 100644 --- a/Sampling-based Planning/rrt_3D/utils3D.py +++ b/Sampling-based Planning/rrt_3D/utils3D.py @@ -169,9 +169,12 @@ def nearest(initparams, x): def steer(initparams, x, y): - direc = (y - x) / np.linalg.norm(y - x) - xnew = x + initparams.stepsize * direc - return tuple(xnew) + dist, step = getDist(y, x), initparams.stepsize + increment = ((y[0] - x[0]) / dist * step, (y[1] - x[1]) / dist * step, (y[2] - x[2]) / dist * step) + xnew = (x[0] + increment[0], x[1] + increment[1], x[2] + increment[2]) + # direc = (y - x) / np.linalg.norm(y - x) + # xnew = x + initparams.stepsize * direc + return xnew def near(initparams, x): @@ -199,8 +202,8 @@ def cost(initparams, x): def path(initparams, Path=[], dist=0): - x = initparams.env.goal - while not all(x == initparams.env.start): + x = tuple(initparams.env.goal) + while x != tuple(initparams.env.start): x2 = initparams.Parent[x] Path.append(np.array([x, x2])) dist += getDist(x, x2) @@ -225,7 +228,8 @@ class edgeset(object): if x in self.E: self.E[x].add(y) else: - self.E[x] = set(y) + self.E[x] = set() + self.E[x].add(y) def remove_edge(self, edge): x, y = edge[0], edge[1]