2019-03-20 02:27:08 +08:00
|
|
|
# Copyright (c) 2019 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
|
|
|
|
import random
|
|
|
|
|
|
|
|
from . import SmokeTest
|
2021-07-06 17:33:11 +08:00
|
|
|
import time
|
2019-03-20 02:27:08 +08:00
|
|
|
|
|
|
|
class TestMap(SmokeTest):
|
|
|
|
def test_reload_world(self):
|
2020-07-31 22:17:00 +08:00
|
|
|
print("TestMap.test_reload_world")
|
2019-03-20 02:27:08 +08:00
|
|
|
map_name = self.client.get_world().get_map().name
|
|
|
|
world = self.client.reload_world()
|
|
|
|
self.assertEqual(map_name, world.get_map().name)
|
|
|
|
|
|
|
|
def test_load_all_maps(self):
|
2020-07-31 22:17:00 +08:00
|
|
|
print("TestMap.test_load_all_maps")
|
2019-03-20 02:27:08 +08:00
|
|
|
map_names = list(self.client.get_available_maps())
|
|
|
|
random.shuffle(map_names)
|
|
|
|
for map_name in map_names:
|
2022-09-16 22:45:40 +08:00
|
|
|
# ignore empty or large maps by now
|
|
|
|
if map_name != '/Game/Carla/Maps/BaseMap/BaseMap' and
|
|
|
|
map_name != '/Game/Carla/Maps/Town12/Town12':
|
|
|
|
:
|
2019-03-20 02:27:08 +08:00
|
|
|
world = self.client.load_world(map_name)
|
2021-07-06 17:33:11 +08:00
|
|
|
# workaround: give time to UE4 to clean memory after loading (old assets)
|
|
|
|
time.sleep(5)
|
2019-03-20 02:27:08 +08:00
|
|
|
m = world.get_map()
|
2021-07-21 17:37:23 +08:00
|
|
|
self.assertEqual(map_name.split('/')[-1], m.name.split('/')[-1])
|
2019-03-20 02:27:08 +08:00
|
|
|
self._check_map(m)
|
|
|
|
|
|
|
|
def _check_map(self, m):
|
|
|
|
for spawn_point in m.get_spawn_points():
|
|
|
|
waypoint = m.get_waypoint(spawn_point.location, project_to_road=False)
|
|
|
|
self.assertIsNotNone(waypoint)
|
|
|
|
topology = m.get_topology()
|
|
|
|
self.assertGreater(len(topology), 0)
|
|
|
|
waypoints = list(m.generate_waypoints(2))
|
|
|
|
self.assertGreater(len(waypoints), 0)
|
|
|
|
random.shuffle(waypoints)
|
|
|
|
for waypoint in waypoints[:200]:
|
|
|
|
for _ in range(0, 20):
|
|
|
|
self.assertGreaterEqual(waypoint.lane_width, 0.0)
|
|
|
|
_ = waypoint.get_right_lane()
|
|
|
|
_ = waypoint.get_left_lane()
|
|
|
|
next_waypoints = waypoint.next(4)
|
|
|
|
if not next_waypoints:
|
|
|
|
break
|
|
|
|
waypoint = random.choice(next_waypoints)
|
|
|
|
_ = m.transform_to_geolocation(carla.Location())
|
|
|
|
self.assertTrue(str(m.to_opendrive()))
|