-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObstacle.py
65 lines (55 loc) · 2.2 KB
/
Obstacle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Obstacle:
def __init__(self, clearance):
self.x = 10
self.y = 10
self.clearance = clearance
self.robot_radius = 0.354 / 2
self.clearance = self.robot_radius + self.clearance
self.dynamic_Obstacle = False
# self.rect1_corner1_x = 3
# self.rect1_corner1_y = 0
self.rect1_corner1_x = 0
self.rect1_corner1_y = 2.75
self.rect1_length = 3
self.rect1_width = 0.01
# self.rect2_corner1_x = 6
# self.rect2_corner1_y = 0
self.rect2_corner1_x = 0
self.rect2_corner1_y = 6.25
self.rect2_length = 3
self.rect2_width = 0.01
def isInObstacleSpace(self, x, y):
if (x < 1 or x > 9 or y < 1 or y > 9):
#print('Out of boundary !')
return 1
#rectangle obstacle 1
x1 = self.rect1_corner1_x - self.clearance
x2 = x1 + self.rect1_length + 2*self.clearance
y1 = self.rect1_corner1_y - self.clearance
y2 = y1 + self.rect1_width + 2*self.clearance
if (x >= x1 and x <= x2 and y >= y1 and y <= y2):
#print('Inside rectangle 1, avoid')
return 1
#rectangle obstacle 2
x1 = self.rect2_corner1_x - self.clearance
x2 = x1 + self.rect2_length + 2*self.clearance
y1 = self.rect2_corner1_y - self.clearance
y2 = y1 + self.rect2_width + 2*self.clearance
if (x >= x1 and x <= x2 and y >= y1 and y <= y2):
#print('Inside rectangle 1, avoid')
return 1
if self.dynamic_Obstacle == True:
x1 = self.dynamic_obs_corner_x - self.clearance
x2 = x1 + self.dynamic_obs_length + 2*self.clearance
y1 = self.dynamic_obs_corner_y - self.clearance
y2 = y1 + self.dynamic_obs_width + 2*self.clearance
if (x >= x1 and x <= x2 and y >= y1 and y <= y2):
# print('Hitting new dynamic obstacle')
return 1
return 0
def addNewObstacle(self, x, y, length, width):
self.dynamic_obs_corner_x = x
self.dynamic_obs_corner_y = y
self.dynamic_obs_length = length
self.dynamic_obs_width = width
self.dynamic_Obstacle = True