-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutonomous_SAMMiCA.py
96 lines (75 loc) · 2.72 KB
/
Autonomous_SAMMiCA.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
#!/usr/bin/env python
from collections import deque
from ai28.msgs import BBox3d, Waypoint, Accident, Perception, weather
import rospy
class Wrapper():
def init(self):
self.bbox3d_deque = deque(30)
self.waypoint_deque = deque(30)
self.accident_deque = deque(30)
self.weather_deque = deque(30)
self.bbox3d_subscriber = rospy.Subscriber(
"/ai28/bbox3d",
BBox3d,
self.bbox3d_callback,
queue_size=1
)
self.waypoint_subscriber = rospy.Subscriber(
"/ai28/waypoint",
Waypoint,
self._waypont_callback,
queue_size=1
)
self.accident_subscriber = rospy.Subscriber(
"/ai28/accident",
Accident,
self._accident_callback,
queue_size=1
)
self.perception_msg_publisher = rospy.Publisher(
"/ai28/weather",
weather,
self._weather_callback,
queue_size=1
)
self.perception_msg_publisher = rospy.Publisher(
"/ai28/perception",
Perception,
queue_size=1
)
def _bbox3d_callback(self, msg):
self.bbox3d_deque.append(msg)
def _wayponit_callback(self, msg):
self.wayponit_deque.append(msg)
def accident_callback(self, msg):
self.accident_deque.append(msg)
def weather_callback(self, msg):
self.weather_deque.append(msg)
def run_step():
if len(self.bbox3d_deque==0) or len(self.waypoint_deque==0) or len(self.accident_deque==0):
return
last_bbox3d_msg = self.bbox3d_deque.pop()
last_waypoint_msg = self.waypoint_deque.pop()
last_accident_msg = self.accident_deque.pop()
perception_msg = Perception(
last_bbox3d_msg,
last_waypoint_msg,
last_accident_msg
)
self.perception_msg_publisher.publish(perception_msg)
if __name__ == "__main__":
rospy.init_node("vehicle_controller_node")
print("SAMMiCA autonomous module start")
print("Insert module to CARLA-ROS autonomous vehicle")
try:
wrapper = Wrapper()
frame_rate = rospy.get_param("~frame_rate", 200)
rate = rospy.Rate(frame_rate)
while not rospy.is_shutdown():
wrapper.run_step()
rate.sleep()
except (rospy.ROSInterruptException, rospy.ROSException) as e:
if not rospy.is_shutdown():
rospy.logwarn("ROS Error during execution: {}".format(e))
except KeyboardInterrupt:
rospy.loginfo("User requested shut down.")