From bb0c9ffdbc0d00720c992bc44cb752044485aa49 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Thu, 25 Oct 2018 13:59:26 +0200 Subject: [PATCH] Change Python examples to use the recommended spawn points --- PythonAPI/manual_control.py | 7 +++---- PythonAPI/tutorial.py | 8 +++----- PythonAPI/vehicle_gallery.py | 24 ++++++++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/PythonAPI/manual_control.py b/PythonAPI/manual_control.py index ae0537ac0..420bec018 100755 --- a/PythonAPI/manual_control.py +++ b/PythonAPI/manual_control.py @@ -108,9 +108,6 @@ except ImportError: # ============================================================================== -START_POSITION = carla.Transform(carla.Location(x=180.0, y=199.0, z=40.0)) - - def find_weather_presets(): rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) @@ -123,7 +120,9 @@ class World(object): self.world = carla_world self.hud = hud blueprint = self._get_random_blueprint() - self.vehicle = self.world.spawn_actor(blueprint, START_POSITION) + spawn_points = self.world.get_map().get_spawn_points() + spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform() + self.vehicle = self.world.spawn_actor(blueprint, spawn_point) self.collision_sensor = CollisionSensor(self.vehicle, self.hud) self.camera_manager = CameraManager(self.vehicle, self.hud) self.camera_manager.set_sensor(0, notify=False) diff --git a/PythonAPI/tutorial.py b/PythonAPI/tutorial.py index 0d06cc78f..ca60b6222 100755 --- a/PythonAPI/tutorial.py +++ b/PythonAPI/tutorial.py @@ -50,11 +50,9 @@ def main(): color = random.choice(bp.get_attribute('color').recommended_values) bp.set_attribute('color', color) - # Now we need to give an initial transform to the vehicle. This is a - # nice spot in Town01. - transform = carla.Transform( - carla.Location(x=140.0, y=199.0, z=40.0), - carla.Rotation(yaw=0.0)) + # Now we need to give an initial transform to the vehicle. We choose a + # random transform from the list of recommended spawn points of the map. + transform = random.choice(world.get_map().get_spawn_points()) # So let's tell the world to spawn the vehicle. vehicle = world.spawn_actor(bp, transform) diff --git a/PythonAPI/vehicle_gallery.py b/PythonAPI/vehicle_gallery.py index d00fd03cc..26e6b9394 100755 --- a/PythonAPI/vehicle_gallery.py +++ b/PythonAPI/vehicle_gallery.py @@ -15,34 +15,38 @@ except IndexError: import carla import math +import random import time -# Nice spot in Town01. -LOCATION = carla.Location(x=155.5, y=55.8, z=39) - -def get_transform(angle, d=6.5): +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) + LOCATION - return carla.Transform(location, carla.Rotation(yaw=180 + angle, pitch=-15)) + 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=-20)) 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)) + transform = carla.Transform(location, carla.Rotation(yaw=-45.0)) vehicle = world.spawn_actor(blueprint, transform) try: print(vehicle.type_id) - for x in range(2, 360, 2): - spectator.set_transform(get_transform(x - 90)) - time.sleep(0.02) + + angle = 0 + while angle < 356: + timestamp = world.wait_for_tick() + angle += timestamp.delta_seconds * 60.0 + spectator.set_transform(get_transform(location, angle - 90)) finally: