-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai_parser.py
58 lines (47 loc) · 2.12 KB
/
ai_parser.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
#!/usr/bin/env python
import glob
import os
import sys
try:
sys.path.append(glob.glob('**/*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass
import weakref
import carla
import ai_knowledge as data
# Monitor is responsible for reading the data from the sensors and telling it to the knowledge
# TODO: Implement other sensors (lidar and depth sensors mainly)
# TODO: Use carla API to read whether car is at traffic lights and their status, update it into knowledge
class Monitor(object):
def __init__(self, knowledge,vehicle):
self.vehicle = vehicle
self.knowledge = knowledge
weak_self = weakref.ref(self)
self.knowledge.update_data('location', self.vehicle.get_transform().location)
self.knowledge.update_data('rotation', self.vehicle.get_transform().rotation)
world = self.vehicle.get_world()
bp = world.get_blueprint_library().find('sensor.other.lane_detector')
self.lane_detector = world.spawn_actor(bp, carla.Transform(), attach_to=self.vehicle)
self.lane_detector.listen(lambda event: Monitor._on_invasion(weak_self, event))
#Function that is called at time intervals to update ai-state
def update(self, time_elapsed):
# Update the position of vehicle into knowledge
self.knowledge.update_data('location', self.vehicle.get_transform().location)
self.knowledge.update_data('rotation', self.vehicle.get_transform().rotation)
@staticmethod
def _on_invasion(weak_self, event):
self = weak_self()
if not self:
return
self.knowledge.update_data('lane_invasion',event.crossed_lane_markings)
# Analyser is responsible for parsing all the data that the knowledge has received from Monitor and turning it into something usable
# TODO: During the update step parse the data inside knowledge into information that could be used by planner to plan the route
class Analyser(object):
def __init__(self, knowledge):
self.knowledge = knowledge
#Function that is called at time intervals to update ai-state
def update(self, time_elapsed):
return