-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobstacles.py
130 lines (99 loc) · 2.91 KB
/
obstacles.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import rospy
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32, Polygon
from costmap_converter.msg import ObstacleArrayMsg, ObstacleMsg
from world import World
world = World()
def to_point(pos):
x, y = pos
x, y = (x*0.6096, y*0.6096)
return Point32(x, y, 0)
def to_square(point, radius):
x, y = point
points = [
to_point((x + radius, y + radius)),
to_point((x + radius, y - radius)),
to_point((x - radius, y - radius)),
to_point((x - radius, y + radius)),
]
return Polygon(points)
def to_obsarray_bulked():
array = ObstacleArrayMsg()
array.header.frame_id = 'field'
oid = [0]
def next_id():
oid[0] += 1
return oid[0] - 1
lines = [
# small cone corner
((0, 0), (0, 2.125)),
((0, 0), (2.125, 0)),
((1, 0), (1, 2.125)),
((0, 1), (2.125, 1)),
# long cone corner
((6, 6), (6, 6 - 3.125)),
((6, 6), (6 - 3.125, 6)),
((5, 6), (5, 6 - 3.125)),
((6, 5), (6 - 3.125, 5)),
( # center cones
(2, 2), (2, 2.5),
(3.5, 4), (4, 4),
(4, 3.5), (2.5, 2)
),
# goal line
((0, 4.1), (1.9, 6)),
((4.1, 0), (6, 1.9))
]
for l in lines:
obs = ObstacleMsg(polygon=Polygon([to_point(p) for p in l]))
obs.id = next_id()
array.obstacles.append(obs)
for stationary in ((2, 4), (4, 2)):
obs = ObstacleMsg(polygon=to_square(stationary, 0.127))
obs.id = next_id()
array.obstacles.append(obs)
return array
def to_obsarray():
array = ObstacleArrayMsg()
array.header.frame_id = 'field'
oid = [0]
def next_id():
oid[0] += 1
return oid[0] - 1
red_line = [to_point((0, 4.1)), to_point((1.9, 6))]
blue_line = [to_point((4.1, 0)), to_point((6, 1.9))]
for l in (blue_line, red_line):
obs = ObstacleMsg(polygon=Polygon(l))
obs.id = next_id()
array.obstacles.append(obs)
for stationary in ((2, 4), (4, 2)):
obs = ObstacleMsg(polygon=to_square(stationary, 0.127))
obs.id = next_id()
array.obstacles.append(obs)
for color, pos in world.goals:
obs = ObstacleMsg(polygon=to_square(pos, 0.127))
obs.id = next_id()
array.obstacles.append(obs)
for pos in world.cones:
obs = ObstacleMsg(polygon=to_square(pos, 0.076))
obs.id = next_id()
array.obstacles.append(obs)
return array
def to_pointcloud():
pcl = PointCloud()
pcl.header.frame_id = 'field'
for color, pos in world.goals:
pcl.points.append(to_point(pos))
# for pos in world.cones:
# pcl.points.append(to_point(pos))
return pcl
if __name__ == '__main__':
rospy.init_node('obstacles')
# points = rospy.Publisher('/asgard/obstacles', PointCloud, queue_size=1)
obstacles = rospy.Publisher('/move_base/TebLocalPlannerROS/obstacles', ObstacleArrayMsg, queue_size=1)
rate = rospy.Rate(0.5)
while not rospy.is_shutdown():
# points.publish(to_pointcloud())
# obstacles.publish(to_obsarray())
obstacles.publish(to_obsarray_bulked())
rate.sleep()