in CARLA_0.9.6/PythonAPI/carla/agents/navigation/carla_env.py [0:0]
def reset_other_vehicles(self):
if not self.is_other_cars:
return
# clear out old vehicles
self.client.apply_batch([carla.command.DestroyActor(x) for x in self.vehicles_list])
self.world.tick()
self.vehicles_list = []
blueprints = self.world.get_blueprint_library().filter('vehicle.*')
blueprints = [x for x in blueprints if int(x.get_attribute('number_of_wheels')) == 4]
num_vehicles = 10
other_car_transforms = []
for _ in range(num_vehicles):
lane_id = random.choice([1, 2, 3, 4])
start_x = 1.5 + 3.5 * lane_id
start_y = random.uniform(-40., 40.)
transform = carla.Transform(carla.Location(x=start_x, y=start_y, z=0.1), carla.Rotation(yaw=-90))
other_car_transforms.append(transform)
# Spawn vehicles
batch = []
for n, transform in enumerate(other_car_transforms):
blueprint = random.choice(blueprints)
if blueprint.has_attribute('color'):
color = random.choice(blueprint.get_attribute('color').recommended_values)
blueprint.set_attribute('color', color)
if blueprint.has_attribute('driver_id'):
driver_id = random.choice(blueprint.get_attribute('driver_id').recommended_values)
blueprint.set_attribute('driver_id', driver_id)
blueprint.set_attribute('role_name', 'autopilot')
batch.append(carla.command.SpawnActor(blueprint, transform).then(
carla.command.SetAutopilot(carla.command.FutureActor, True)))
for response in self.client.apply_batch_sync(batch, False):
self.vehicles_list.append(response.actor_id)
for response in self.client.apply_batch_sync(batch):
if response.error:
pass
# print(response.error)
else:
self.vehicles_list.append(response.actor_id)