2020-05-07 20:53:30 +08:00
|
|
|
# Copyright (c) 2020 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 carla
|
2021-07-06 17:33:11 +08:00
|
|
|
import time
|
2020-05-07 20:53:30 +08:00
|
|
|
|
|
|
|
from . import SyncSmokeTest
|
|
|
|
|
|
|
|
|
|
|
|
class TestSpawnpoints(SyncSmokeTest):
|
|
|
|
def test_spawn_points(self):
|
2020-07-31 22:17:00 +08:00
|
|
|
print("TestSpawnpoints.test_spawn_points")
|
2020-05-07 20:53:30 +08:00
|
|
|
self.world = self.client.get_world()
|
|
|
|
blueprints = self.world.get_blueprint_library().filter("vehicle.*")
|
2022-11-28 22:59:29 +08:00
|
|
|
blueprints = self.filter_vehicles_for_old_towns(blueprints)
|
2020-07-31 22:17:00 +08:00
|
|
|
|
2020-05-07 20:53:30 +08:00
|
|
|
# get all available maps
|
|
|
|
maps = self.client.get_available_maps()
|
2020-05-11 20:05:08 +08:00
|
|
|
for m in maps:
|
2020-07-31 22:17:00 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
if m != '/Game/Carla/Maps/BaseMap/BaseMap' and m != '/Game/Carla/Maps/Town11/Town11' and m != '/Game/Carla/Maps/Town12/Town12':
|
2020-07-31 22:17:00 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
# load the map
|
|
|
|
self.client.load_world(m)
|
|
|
|
# workaround: give time to UE4 to clean memory after loading (old assets)
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
self.world = self.client.get_world()
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
# get all spawn points
|
|
|
|
spawn_points = self.world.get_map().get_spawn_points()
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
# Check why the world settings aren't applied after a reload
|
|
|
|
self.settings = self.world.get_settings()
|
|
|
|
settings = carla.WorldSettings(
|
|
|
|
no_rendering_mode=False,
|
|
|
|
synchronous_mode=True,
|
|
|
|
fixed_delta_seconds=0.05)
|
|
|
|
self.world.apply_settings(settings)
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
# spawn all kind of vehicle
|
|
|
|
for vehicle in blueprints:
|
|
|
|
batch = [(vehicle, t) for t in spawn_points]
|
|
|
|
batch = [carla.command.SpawnActor(*args) for args in batch]
|
|
|
|
response = self.client.apply_batch_sync(batch, False)
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
self.assertFalse(any(x.error for x in response))
|
|
|
|
ids = [x.actor_id for x in response]
|
|
|
|
self.assertEqual(len(ids), len(spawn_points))
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
frame = self.world.tick()
|
|
|
|
snapshot = self.world.get_snapshot()
|
|
|
|
self.assertEqual(frame, snapshot.timestamp.frame)
|
2020-05-07 20:53:30 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
actors = self.world.get_actors()
|
|
|
|
self.assertTrue(all(snapshot.has_actor(x.id) for x in actors))
|
2020-07-31 22:17:00 +08:00
|
|
|
|
2022-10-21 06:29:49 +08:00
|
|
|
for actor_id, t0 in zip(ids, spawn_points):
|
|
|
|
actor_snapshot = snapshot.find(actor_id)
|
|
|
|
self.assertIsNotNone(actor_snapshot)
|
|
|
|
t1 = actor_snapshot.get_transform()
|
|
|
|
# Ignore Z cause vehicle is falling.
|
|
|
|
self.assertAlmostEqual(t0.location.x, t1.location.x, places=2)
|
|
|
|
self.assertAlmostEqual(t0.location.y, t1.location.y, places=2)
|
|
|
|
self.assertAlmostEqual(t0.rotation.pitch, t1.rotation.pitch, places=2)
|
|
|
|
self.assertAlmostEqual(t0.rotation.yaw, t1.rotation.yaw, places=2)
|
|
|
|
self.assertAlmostEqual(t0.rotation.roll, t1.rotation.roll, places=2)
|
|
|
|
|
|
|
|
self.client.apply_batch_sync([carla.command.DestroyActor(x) for x in ids], True)
|
|
|
|
frame = self.world.tick()
|