forked from carla-simulator/carla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle_gallery.py
executable file
·64 lines (45 loc) · 1.62 KB
/
vehicle_gallery.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
#!/usr/bin/env python
# Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma de
# Barcelona (UAB).
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
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 carla
import math
import random
import time
def get_transform(vehicle_location, angle, d=6.4):
a = math.radians(angle)
location = carla.Location(d * math.cos(a), d * math.sin(a), 2.0) + vehicle_location
return carla.Transform(location, carla.Rotation(yaw=180 + angle, pitch=-15))
def main():
client = carla.Client('localhost', 2000)
client.set_timeout(2.0)
world = client.get_world()
spectator = world.get_spectator()
vehicle_blueprints = world.get_blueprint_library().filter('vehicle')
location = random.choice(world.get_map().get_spawn_points()).location
for blueprint in vehicle_blueprints:
transform = carla.Transform(location, carla.Rotation(yaw=-45.0))
vehicle = world.spawn_actor(blueprint, transform)
try:
print(vehicle.type_id)
angle = 0
while angle < 356:
timestamp = world.wait_for_tick()
angle += timestamp.delta_seconds * 60.0
spectator.set_transform(get_transform(vehicle.get_location(), angle - 90))
finally:
vehicle.destroy()
if __name__ == '__main__':
main()