2018-07-30 05:52:13 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-10-28 18:23:59 +08:00
|
|
|
# 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>.
|
|
|
|
|
2018-10-10 00:04:50 +08:00
|
|
|
import glob
|
|
|
|
import os
|
2018-07-30 05:52:13 +08:00
|
|
|
import sys
|
|
|
|
|
2018-10-10 00:04:50 +08:00
|
|
|
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
|
2018-07-30 05:52:13 +08:00
|
|
|
|
|
|
|
import carla
|
|
|
|
|
|
|
|
import math
|
2018-10-25 19:59:26 +08:00
|
|
|
import random
|
2018-07-30 05:52:13 +08:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
2018-10-25 19:59:26 +08:00
|
|
|
def get_transform(vehicle_location, angle, d=6.4):
|
2018-07-30 05:52:13 +08:00
|
|
|
a = math.radians(angle)
|
2018-10-25 19:59:26 +08:00
|
|
|
location = carla.Location(d * math.cos(a), d * math.sin(a), 2.0) + vehicle_location
|
2018-10-30 19:52:38 +08:00
|
|
|
return carla.Transform(location, carla.Rotation(yaw=180 + angle, pitch=-15))
|
2018-07-30 05:52:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
client = carla.Client('localhost', 2000)
|
2018-10-25 19:59:26 +08:00
|
|
|
client.set_timeout(2.0)
|
2018-07-30 05:52:13 +08:00
|
|
|
world = client.get_world()
|
|
|
|
spectator = world.get_spectator()
|
2018-08-24 20:40:19 +08:00
|
|
|
vehicle_blueprints = world.get_blueprint_library().filter('vehicle')
|
2018-07-30 05:52:13 +08:00
|
|
|
|
2018-10-25 19:59:26 +08:00
|
|
|
location = random.choice(world.get_map().get_spawn_points()).location
|
|
|
|
|
2018-07-30 05:52:13 +08:00
|
|
|
for blueprint in vehicle_blueprints:
|
2018-10-25 19:59:26 +08:00
|
|
|
transform = carla.Transform(location, carla.Rotation(yaw=-45.0))
|
2018-07-30 05:52:13 +08:00
|
|
|
vehicle = world.spawn_actor(blueprint, transform)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
print(vehicle.type_id)
|
2018-10-25 19:59:26 +08:00
|
|
|
|
|
|
|
angle = 0
|
|
|
|
while angle < 356:
|
|
|
|
timestamp = world.wait_for_tick()
|
|
|
|
angle += timestamp.delta_seconds * 60.0
|
2018-10-30 19:52:38 +08:00
|
|
|
spectator.set_transform(get_transform(vehicle.get_location(), angle - 90))
|
2018-07-30 05:52:13 +08:00
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
vehicle.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
main()
|