-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.py
88 lines (69 loc) · 2.21 KB
/
car.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
import os
import carla
import time
from queue import Queue
from sensors import IMU, GNSS
class Car:
def __init__(self, world, client, spawn_point):
self.world = world
self.client = client
vehicle_bp = world.get_blueprint_library().filter('vehicle.dodge.charger_2020')[0]
self.vehicle = world.spawn_actor(vehicle_bp, spawn_point)
print(self.vehicle)
self.imu = IMU(world, self.vehicle)
self.gnss = GNSS(world, self.vehicle)
self.imu_queue = Queue()
self.gnss_queue = Queue()
self.imu.listen(self.imu_queue)
self.gnss.listen(self.gnss_queue)
def start(self):
'''
Start the car autopilot
'''
self.vehicle.set_autopilot(True)
def stop(self):
'''
Stop the car autopilot
'''
self.vehicle.set_autopilot(False)
time.sleep(15)
def get_id(self):
'''
Get car actor ID as defined by CARLA
'''
return self.vehicle.id
def get_location(self, snapshot):
'''
Get car location in the world for a specific frame
'''
return snapshot.find(self.get_id()).get_transform().location
def get_orientation(self, snapshot):
'''
Get car orientation in the world for a specific frame
'''
return snapshot.find(self.get_id()).get_transform().rotation
def get_imu_data(self, frame):
'''
Get IMU data for a specific frame
'''
while not self.imu_queue.empty():
imu_data = self.imu_queue.get()
if imu_data.frame == frame:
self.imu_queue.task_done()
return imu_data
self.imu_queue.task_done()
return None
def get_gnss_data(self, frame):
'''
Get GNSS data for a specific frame
'''
while not self.gnss_queue.empty():
gnss_data = self.gnss_queue.get()
if gnss_data.frame == frame:
self.gnss_queue.task_done()
return gnss_data
self.gnss_queue.task_done()
def destroy(self):
self.imu.sensor.destroy()
self.gnss.sensor.destroy()
self.vehicle.destroy()