Change Python examples to use the recommended spawn points
This commit is contained in:
parent
89f30ee49c
commit
bb0c9ffdbc
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue