From f9a4fc15809db6f0516b41c7752bbc8e2bd32538 Mon Sep 17 00:00:00 2001 From: Atsushi Sakai Date: Sat, 2 Feb 2019 10:38:37 +0900 Subject: [PATCH] code cleanup --- PathPlanning/RRTDubins/rrt_dubins.py | 2 +- .../RRTStarReedsShepp/rrt_star_reeds_shepp.py | 32 ++++++++++--------- appveyor.yml | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/PathPlanning/RRTDubins/rrt_dubins.py b/PathPlanning/RRTDubins/rrt_dubins.py index b385cff1..976d3c47 100644 --- a/PathPlanning/RRTDubins/rrt_dubins.py +++ b/PathPlanning/RRTDubins/rrt_dubins.py @@ -75,7 +75,7 @@ class RRT(): return path def choose_parent(self, newNode, nearinds): - if len(nearinds) == 0: + if not nearinds: return newNode dlist = [] diff --git a/PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py b/PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py index 8e4dd8e4..af817fc8 100644 --- a/PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py +++ b/PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py @@ -5,16 +5,18 @@ Path Planning Sample Code with RRT for car like robot. author: AtsushiSakai(@Atsushi_twi) """ - +import matplotlib.pyplot as plt +import numpy as np +import copy +import math +import random import sys sys.path.append("../ReedsSheppPath/") -import random -import math -import copy -import numpy as np -import reeds_shepp_path_planning -import matplotlib.pyplot as plt +try: + import reeds_shepp_path_planning +except: + raise show_animation = True STEP_SIZE = 0.1 @@ -80,7 +82,7 @@ class RRT(): return path def choose_parent(self, newNode, nearinds): - if len(nearinds) == 0: + if not nearinds: return newNode dlist = [] @@ -166,7 +168,7 @@ class RRT(): # print("OK YAW TH num is") # print(len(fgoalinds)) - if len(fgoalinds) == 0: + if not fgoalinds: return None mincost = min([self.nodeList[i].cost for i in fgoalinds]) @@ -194,9 +196,9 @@ class RRT(): nnode = len(self.nodeList) r = 50.0 * math.sqrt((math.log(nnode) / nnode)) # r = self.expandDis * 5.0 - dlist = [(node.x - newNode.x) ** 2 + - (node.y - newNode.y) ** 2 + - (node.yaw - newNode.yaw) ** 2 + dlist = [(node.x - newNode.x) ** 2 + + (node.y - newNode.y) ** 2 + + (node.yaw - newNode.yaw) ** 2 for node in self.nodeList] nearinds = [dlist.index(i) for i in dlist if i <= r ** 2] return nearinds @@ -247,9 +249,9 @@ class RRT(): # input() def GetNearestListIndex(self, nodeList, rnd): - dlist = [(node.x - rnd.x) ** 2 + - (node.y - rnd.y) ** 2 + - (node.yaw - rnd.yaw) ** 2 for node in nodeList] + dlist = [(node.x - rnd.x) ** 2 + + (node.y - rnd.y) ** 2 + + (node.yaw - rnd.yaw) ** 2 for node in nodeList] minind = dlist.index(min(dlist)) return minind diff --git a/appveyor.yml b/appveyor.yml index 62801f14..bb57d307 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ environment: init: - "ECHO %MINICONDA% %PYTHON_VERSION% %PYTHON_ARCH%" - + install: # If there is a newer build queued for the same PR, cancel this one. # The AppVeyor 'rollout builds' option is supposed to serve the same