Skip to content

Commit d4a3789

Browse files
committed
modified to use occupency grid for collision checking
1 parent a9ac021 commit d4a3789

2 files changed

Lines changed: 38 additions & 9 deletions

File tree

GEMstack/knowledge/defaults/rrt_param.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ map:
55
upper_x: 20
66
lower_y: -5
77
upper_y: 20
8+
grid_resolution: 10 # grids per meter for occupency grid
9+
obstacle_radius: 0.2 # meter for determining the size of the obstacle in occupency grid
810
# vehicle info
911
vehicle:
1012
heading_limit: 0.5235987756 # pi/6 in radians

GEMstack/onboard/planning/RRT.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ def __init__(self, start : list, goal : list, obstacles : list, update_rate : Op
3434
# (will revert back after route found)
3535
self.end_point = Point(goal[0],goal[1],self.angle_inverse(goal[2]))
3636
self.end_point.cost = 0
37-
38-
# obstacles and map boundary
39-
self.OBSTACLE_LIST = []
40-
for obstacle in obstacles:
41-
self.OBSTACLE_LIST.append(Obstacle(obstacle[0],obstacle[1]))
4237

4338
yaml_path = "../../knowledge/defaults/rrt_param.yaml"
4439
with open(yaml_path,'r') as file:
@@ -69,6 +64,34 @@ def __init__(self, start : list, goal : list, obstacles : list, update_rate : Op
6964
self.MAP_Y_LOW = params['map']['lower_y']
7065
self.MAP_Y_HIGH = params['map']['upper_y']
7166

67+
self.obstacle_radius = params['map']['obstacle_radius'] # meter
68+
69+
# occupency grid
70+
self.grid = None
71+
self.grid_resolution = params['map']['grid_resolution'] # grids per meter
72+
# the coordiante in start frame where in occupency grid is (0,0)
73+
self.map_zero = [self.MAP_X_LOW , self.MAP_Y_LOW]
74+
# initialize occupency grid
75+
self.build_grid(obstacles)
76+
77+
# Build occupency grid from obstacle list
78+
def build_grid(self, obstacles):
79+
80+
grid_height = (self.MAP_Y_HIGH - self.MAP_Y_LOW)*self.grid_resolution
81+
grid_width = (self.MAP_X_HIGH - self.MAP_X_LOW)*self.grid_resolution
82+
self.grid = np.zeros((round(grid_width),round(grid_height)))
83+
84+
margin_low = -round((self.obstacle_radius + self.OFFSET)*self.grid_resolution)
85+
margin_high = round((self.obstacle_radius + self.OFFSET)*self.grid_resolution)
86+
for obstacle in obstacles :
87+
obstacle_center = [round((obstacle[0]-self.map_zero[0])*self.grid_resolution),
88+
round((obstacle[1]-self.map_zero[1])*self.grid_resolution)]
89+
90+
self.grid[obstacle_center[0],obstacle_center[1]] = 1
91+
for x_margin in range(margin_low,margin_high):
92+
for y_margin in range(margin_low,margin_high):
93+
self.grid[obstacle_center[0] + x_margin, obstacle_center[1] + y_margin] = 1
94+
7295

7396
def search(self):
7497
# initialize two tree
@@ -228,11 +251,15 @@ def angle_inverse(self,angle):
228251
return angle + math.pi
229252
return angle-math.pi
230253

254+
# collision checking
231255
def is_valid(self,point):
232-
for obstacle in self.OBSTACLE_LIST:
233-
if self.distance(point, obstacle) < obstacle.radius + self.OFFSET:
234-
return False
235-
return True
256+
xi = round((point.x - self.map_zero[0])*self.grid_resolution)
257+
yi = round((point.y - self.map_zero[1])*self.grid_resolution)
258+
259+
if xi < 0 or yi < 0 or xi >= self.grid.shape[0] or yi >= self.grid.shape[1]:
260+
print("out boundary")
261+
return False # Out of bounds is considered collision
262+
return 1 - self.grid[xi][yi]
236263

237264
# return the nearest point in the tree
238265
def Nearest(self,tree,sample_p):

0 commit comments

Comments
 (0)