#!/usr/bin/env python

# 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 glob
import os
import sys
import random
import pygame
import random
import time
import math


try:
    sys.path.append(glob.glob('../Downloads/CARLA/PythonAPI/carla/dist//carla-*%d.%d-%s.egg' % (
        sys.version_info.major,
        sys.version_info.minor,
        'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass

import carla


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


def main():
    actor_list = []

    # In this tutorial script, we are going to add a vehicle to the simulation
    # and let it drive in autopilot. We will also create a camera attached to
    # that vehicle, and save all the images generated by the camera to disk.

    try:
        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)

        # Once we have a client we can retrieve the world that is currently
        # running.
        world = client.get_world()


        # The world contains the list blueprints that we can use for adding new
        # actors into the simulation.
        blueprint_library = world.get_blueprint_library()
        blueprints = [bp for bp in world.get_blueprint_library().filter('*')]
        vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*.*')
        blueprint = random.choice(vehicle_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)
        if blueprint.has_attribute('is_invincible'):
            blueprint.set_attribute('is_invincible', 'true')
        # set the max speed
        if blueprint.has_attribute('speed'):
            self.player_max_speed = float(blueprint.get_attribute('speed').recommended_values[1])
            self.player_max_speed_fast = float(blueprint.get_attribute('speed').recommended_values[2])
        else:
            print("No recommended values for 'speed' attribute")
            
        # Spawn a vehicle
        spawn_points = world.get_map().get_spawn_points()
        print(len(spawn_points))
        spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()
        player = world.try_spawn_actor(blueprint, spawn_point)
        print(player)
                
        #Spectator view
        spectator = world.get_spectator()
        print(spectator)
        
        #Spawn a sensor to align spectator view
        camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        camera_transform = carla.Transform(carla.Location(x=-8.0, z=6.0), carla.Rotation(pitch=6.0))
        camera = world.spawn_actor(camera_bp, camera_transform, player, carla.AttachmentType.SpringArm)
        
        # Lets drive to another destination
        destination_point = random.choice(spawn_points) if spawn_points else carla.Transform()
        map = world.get_map()
        waypoint01 = map.get_waypoint(player.get_location(),project_to_road=True, lane_type=(carla.LaneType.Driving | carla.LaneType.Sidewalk))
#        waypoints_list = waypoint01.next_until_lane_end(2)
        player.set_simulate_physics(False)
        
        
        distance = 5.0
        ## Code to see all the waypoints
        waypoints = map.generate_waypoints(distance)
#        for w in waypoints:
#            world.debug.draw_string(w.transform.location, 'O', draw_shadow=False,
#                                               color=carla.Color(r=255, g=0, b=0), life_time=120.0,
#                                               persistent_lines=True)
        
        clock = pygame.time.Clock()
        count = 0
        vehicle = player
        while True:
#                timestamp = world.wait_for_tick()
#                spectator.set_transform(camera.get_transform())
#                vehicle.set_transform(waypoint_list[count].transform)
#                count= count+1
#                time.sleep(2)
                
                #clock.tick_busy_loop(60)
                timestamp = world.wait_for_tick(20)
                #world.render(display)
                #pygame.display.flip()
                if count % 10 == 0:
                        nexts = list(waypoint01.next(1.0))
                        print('Next(1.0) --> %d waypoints' % len(nexts))
                        if not nexts:
                            raise RuntimeError("No more waypoints!")
                        waypoint01 = random.choice(nexts)
                        text = "road id = %d, lane id = %d, transform = %s"
                        print(text % (waypoint01.road_id, waypoint01.lane_id, waypoint01.transform))
                        if count % 40 == 0:
                            draw_waypoints(world, waypoint01)
                            count = 0
                        t = waypoint01.transform
                        vehicle.set_transform(t)
                        spectator.set_transform(camera.get_transform())
                count += 1
        
        
        

#        for vehicle in vehicles:
#                print(vehicle.id)
#                
#        actor_list = world.get_actors()
#        for actor in actor_list:
#                print(actor)
##        for blueprint in blueprints:
#           print(blueprint.id)
##           for attr in blueprint:
##               print('  - {}'.format(attr))
#        spawn_points = world.get_map().get_spawn_points()
#        #print(spawn_points)
	


        # Now let's filter all the blueprints of type 'vehicle' and choose one
        # at random.
        # bp = random.choice(blueprint_library.filter('vehicle'))

        # A blueprint contains the list of attributes that define a vehicle's
        # instance, we can read them and modify some of them. For instance,
        # let's randomize its color.
#        if bp.has_attribute('color'):
#            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. 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)

#        # It is important to note that the actors we create won't be destroyed
#        # unless we call their "destroy" function. If we fail to call "destroy"
#        # they will stay in the simulation even after we quit the Python script.
#        # For that reason, we are storing all the actors we create so we can
#        # destroy them afterwards.
#        actor_list.append(vehicle)
#        print('created %s' % vehicle.type_id)

#        # Let's put the vehicle to drive around.
#        vehicle.set_autopilot(True)

#        # Let's add now a "depth" camera attached to the vehicle. Note that the
#        # transform we give here is now relative to the vehicle.
#        camera_bp = blueprint_library.find('sensor.camera.depth')
#        camera_transform = carla.Transform(carla.Location(x=1.5, z=2.4))
#        camera = world.spawn_actor(camera_bp, camera_transform, attach_to=vehicle)
#        actor_list.append(camera)
#        print('created %s' % camera.type_id)

#        # Now we register the function that will be called each time the sensor
#        # receives an image. In this example we are saving the image to disk
#        # converting the pixels to gray-scale.
#        cc = carla.ColorConverter.LogarithmicDepth
#        camera.listen(lambda image: image.save_to_disk('_out/%06d.png' % image.frame, cc))

#        # Oh wait, I don't like the location we gave to the vehicle, I'm going
#        # to move it a bit forward.
#        location = vehicle.get_location()
#        location.x += 40
#        vehicle.set_location(location)
#        print('moved vehicle to %s' % location)

#        # But the city now is probably quite empty, let's add a few more
#        # vehicles.
#        transform.location += carla.Location(x=40, y=-3.2)
#        transform.rotation.yaw = -180.0
#        for _ in range(0, 10):
#            transform.location.x += 8.0

#            bp = random.choice(blueprint_library.filter('vehicle'))

#            # This time we are using try_spawn_actor. If the spot is already
#            # occupied by another object, the function will return None.
#            npc = world.try_spawn_actor(bp, transform)
#            if npc is not None:
#                actor_list.append(npc)
#                npc.set_autopilot()
#                print('created %s' % npc.type_id)



    finally:

#        print('destroying actors')
#        for actor in actor_list:
#            actor.destroy()
        print('done.')


if __name__ == '__main__':

    main()

af0c82ce40698fc5bc02b9e57ccb0305a006733c
<mask token>


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


<mask token>

<mask token>


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


def main():
    actor_list = []
    try:
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)
        world = client.get_world()
        blueprint_library = world.get_blueprint_library()
        blueprints = [bp for bp in world.get_blueprint_library().filter('*')]
        vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*.*'
            )
        blueprint = random.choice(vehicle_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)
        if blueprint.has_attribute('is_invincible'):
            blueprint.set_attribute('is_invincible', 'true')
        if blueprint.has_attribute('speed'):
            self.player_max_speed = float(blueprint.get_attribute('speed').
                recommended_values[1])
            self.player_max_speed_fast = float(blueprint.get_attribute(
                'speed').recommended_values[2])
        else:
            print("No recommended values for 'speed' attribute")
        spawn_points = world.get_map().get_spawn_points()
        print(len(spawn_points))
        spawn_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        player = world.try_spawn_actor(blueprint, spawn_point)
        print(player)
        spectator = world.get_spectator()
        print(spectator)
        camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        camera_transform = carla.Transform(carla.Location(x=-8.0, z=6.0),
            carla.Rotation(pitch=6.0))
        camera = world.spawn_actor(camera_bp, camera_transform, player,
            carla.AttachmentType.SpringArm)
        destination_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        map = world.get_map()
        waypoint01 = map.get_waypoint(player.get_location(),
            project_to_road=True, lane_type=carla.LaneType.Driving | carla.
            LaneType.Sidewalk)
        player.set_simulate_physics(False)
        distance = 5.0
        waypoints = map.generate_waypoints(distance)
        clock = pygame.time.Clock()
        count = 0
        vehicle = player
        while True:
            timestamp = world.wait_for_tick(20)
            if count % 10 == 0:
                nexts = list(waypoint01.next(1.0))
                print('Next(1.0) --> %d waypoints' % len(nexts))
                if not nexts:
                    raise RuntimeError('No more waypoints!')
                waypoint01 = random.choice(nexts)
                text = 'road id = %d, lane id = %d, transform = %s'
                print(text % (waypoint01.road_id, waypoint01.lane_id,
                    waypoint01.transform))
                if count % 40 == 0:
                    draw_waypoints(world, waypoint01)
                    count = 0
                t = waypoint01.transform
                vehicle.set_transform(t)
                spectator.set_transform(camera.get_transform())
            count += 1
    finally:
        print('done.')


<mask token>

<mask token>
try:
    sys.path.append(glob.glob(
        '../Downloads/CARLA/PythonAPI/carla/dist//carla-*%d.%d-%s.egg' % (
        sys.version_info.major, sys.version_info.minor, 'win-amd64' if os.
        name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass
<mask token>


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


def main():
    actor_list = []
    try:
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)
        world = client.get_world()
        blueprint_library = world.get_blueprint_library()
        blueprints = [bp for bp in world.get_blueprint_library().filter('*')]
        vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*.*'
            )
        blueprint = random.choice(vehicle_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)
        if blueprint.has_attribute('is_invincible'):
            blueprint.set_attribute('is_invincible', 'true')
        if blueprint.has_attribute('speed'):
            self.player_max_speed = float(blueprint.get_attribute('speed').
                recommended_values[1])
            self.player_max_speed_fast = float(blueprint.get_attribute(
                'speed').recommended_values[2])
        else:
            print("No recommended values for 'speed' attribute")
        spawn_points = world.get_map().get_spawn_points()
        print(len(spawn_points))
        spawn_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        player = world.try_spawn_actor(blueprint, spawn_point)
        print(player)
        spectator = world.get_spectator()
        print(spectator)
        camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        camera_transform = carla.Transform(carla.Location(x=-8.0, z=6.0),
            carla.Rotation(pitch=6.0))
        camera = world.spawn_actor(camera_bp, camera_transform, player,
            carla.AttachmentType.SpringArm)
        destination_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        map = world.get_map()
        waypoint01 = map.get_waypoint(player.get_location(),
            project_to_road=True, lane_type=carla.LaneType.Driving | carla.
            LaneType.Sidewalk)
        player.set_simulate_physics(False)
        distance = 5.0
        waypoints = map.generate_waypoints(distance)
        clock = pygame.time.Clock()
        count = 0
        vehicle = player
        while True:
            timestamp = world.wait_for_tick(20)
            if count % 10 == 0:
                nexts = list(waypoint01.next(1.0))
                print('Next(1.0) --> %d waypoints' % len(nexts))
                if not nexts:
                    raise RuntimeError('No more waypoints!')
                waypoint01 = random.choice(nexts)
                text = 'road id = %d, lane id = %d, transform = %s'
                print(text % (waypoint01.road_id, waypoint01.lane_id,
                    waypoint01.transform))
                if count % 40 == 0:
                    draw_waypoints(world, waypoint01)
                    count = 0
                t = waypoint01.transform
                vehicle.set_transform(t)
                spectator.set_transform(camera.get_transform())
            count += 1
    finally:
        print('done.')


if __name__ == '__main__':
    main()

import glob
import os
import sys
import random
import pygame
import random
import time
import math
try:
    sys.path.append(glob.glob(
        '../Downloads/CARLA/PythonAPI/carla/dist//carla-*%d.%d-%s.egg' % (
        sys.version_info.major, sys.version_info.minor, 'win-amd64' if os.
        name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass
import carla


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


def main():
    actor_list = []
    try:
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)
        world = client.get_world()
        blueprint_library = world.get_blueprint_library()
        blueprints = [bp for bp in world.get_blueprint_library().filter('*')]
        vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*.*'
            )
        blueprint = random.choice(vehicle_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)
        if blueprint.has_attribute('is_invincible'):
            blueprint.set_attribute('is_invincible', 'true')
        if blueprint.has_attribute('speed'):
            self.player_max_speed = float(blueprint.get_attribute('speed').
                recommended_values[1])
            self.player_max_speed_fast = float(blueprint.get_attribute(
                'speed').recommended_values[2])
        else:
            print("No recommended values for 'speed' attribute")
        spawn_points = world.get_map().get_spawn_points()
        print(len(spawn_points))
        spawn_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        player = world.try_spawn_actor(blueprint, spawn_point)
        print(player)
        spectator = world.get_spectator()
        print(spectator)
        camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        camera_transform = carla.Transform(carla.Location(x=-8.0, z=6.0),
            carla.Rotation(pitch=6.0))
        camera = world.spawn_actor(camera_bp, camera_transform, player,
            carla.AttachmentType.SpringArm)
        destination_point = random.choice(spawn_points
            ) if spawn_points else carla.Transform()
        map = world.get_map()
        waypoint01 = map.get_waypoint(player.get_location(),
            project_to_road=True, lane_type=carla.LaneType.Driving | carla.
            LaneType.Sidewalk)
        player.set_simulate_physics(False)
        distance = 5.0
        waypoints = map.generate_waypoints(distance)
        clock = pygame.time.Clock()
        count = 0
        vehicle = player
        while True:
            timestamp = world.wait_for_tick(20)
            if count % 10 == 0:
                nexts = list(waypoint01.next(1.0))
                print('Next(1.0) --> %d waypoints' % len(nexts))
                if not nexts:
                    raise RuntimeError('No more waypoints!')
                waypoint01 = random.choice(nexts)
                text = 'road id = %d, lane id = %d, transform = %s'
                print(text % (waypoint01.road_id, waypoint01.lane_id,
                    waypoint01.transform))
                if count % 40 == 0:
                    draw_waypoints(world, waypoint01)
                    count = 0
                t = waypoint01.transform
                vehicle.set_transform(t)
                spectator.set_transform(camera.get_transform())
            count += 1
    finally:
        print('done.')


if __name__ == '__main__':
    main()

#!/usr/bin/env python

# 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 glob
import os
import sys
import random
import pygame
import random
import time
import math


try:
    sys.path.append(glob.glob('../Downloads/CARLA/PythonAPI/carla/dist//carla-*%d.%d-%s.egg' % (
        sys.version_info.major,
        sys.version_info.minor,
        'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass

import carla


def draw_waypoints(world, waypoint, depth=6):
    if depth < 0:
        return
    for w in waypoint.next(4.0):
        t = w.transform
        begin = t.location + carla.Location(z=0.5)
        angle = math.radians(t.rotation.yaw)
        end = begin + carla.Location(x=math.cos(angle), y=math.sin(angle))
        world.debug.draw_arrow(begin, end, arrow_size=0.3, life_time=1.0)
        draw_waypoints(world, w, depth - 1)


def main():
    actor_list = []

    # In this tutorial script, we are going to add a vehicle to the simulation
    # and let it drive in autopilot. We will also create a camera attached to
    # that vehicle, and save all the images generated by the camera to disk.

    try:
        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)

        # Once we have a client we can retrieve the world that is currently
        # running.
        world = client.get_world()


        # The world contains the list blueprints that we can use for adding new
        # actors into the simulation.
        blueprint_library = world.get_blueprint_library()
        blueprints = [bp for bp in world.get_blueprint_library().filter('*')]
        vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*.*')
        blueprint = random.choice(vehicle_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)
        if blueprint.has_attribute('is_invincible'):
            blueprint.set_attribute('is_invincible', 'true')
        # set the max speed
        if blueprint.has_attribute('speed'):
            self.player_max_speed = float(blueprint.get_attribute('speed').recommended_values[1])
            self.player_max_speed_fast = float(blueprint.get_attribute('speed').recommended_values[2])
        else:
            print("No recommended values for 'speed' attribute")
            
        # Spawn a vehicle
        spawn_points = world.get_map().get_spawn_points()
        print(len(spawn_points))
        spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()
        player = world.try_spawn_actor(blueprint, spawn_point)
        print(player)
                
        #Spectator view
        spectator = world.get_spectator()
        print(spectator)
        
        #Spawn a sensor to align spectator view
        camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        camera_transform = carla.Transform(carla.Location(x=-8.0, z=6.0), carla.Rotation(pitch=6.0))
        camera = world.spawn_actor(camera_bp, camera_transform, player, carla.AttachmentType.SpringArm)
        
        # Lets drive to another destination
        destination_point = random.choice(spawn_points) if spawn_points else carla.Transform()
        map = world.get_map()
        waypoint01 = map.get_waypoint(player.get_location(),project_to_road=True, lane_type=(carla.LaneType.Driving | carla.LaneType.Sidewalk))
#        waypoints_list = waypoint01.next_until_lane_end(2)
        player.set_simulate_physics(False)
        
        
        distance = 5.0
        ## Code to see all the waypoints
        waypoints = map.generate_waypoints(distance)
#        for w in waypoints:
#            world.debug.draw_string(w.transform.location, 'O', draw_shadow=False,
#                                               color=carla.Color(r=255, g=0, b=0), life_time=120.0,
#                                               persistent_lines=True)
        
        clock = pygame.time.Clock()
        count = 0
        vehicle = player
        while True:
#                timestamp = world.wait_for_tick()
#                spectator.set_transform(camera.get_transform())
#                vehicle.set_transform(waypoint_list[count].transform)
#                count= count+1
#                time.sleep(2)
                
                #clock.tick_busy_loop(60)
                timestamp = world.wait_for_tick(20)
                #world.render(display)
                #pygame.display.flip()
                if count % 10 == 0:
                        nexts = list(waypoint01.next(1.0))
                        print('Next(1.0) --> %d waypoints' % len(nexts))
                        if not nexts:
                            raise RuntimeError("No more waypoints!")
                        waypoint01 = random.choice(nexts)
                        text = "road id = %d, lane id = %d, transform = %s"
                        print(text % (waypoint01.road_id, waypoint01.lane_id, waypoint01.transform))
                        if count % 40 == 0:
                            draw_waypoints(world, waypoint01)
                            count = 0
                        t = waypoint01.transform
                        vehicle.set_transform(t)
                        spectator.set_transform(camera.get_transform())
                count += 1
        
        
        

#        for vehicle in vehicles:
#                print(vehicle.id)
#                
#        actor_list = world.get_actors()
#        for actor in actor_list:
#                print(actor)
##        for blueprint in blueprints:
#           print(blueprint.id)
##           for attr in blueprint:
##               print('  - {}'.format(attr))
#        spawn_points = world.get_map().get_spawn_points()
#        #print(spawn_points)
	


        # Now let's filter all the blueprints of type 'vehicle' and choose one
        # at random.
        # bp = random.choice(blueprint_library.filter('vehicle'))

        # A blueprint contains the list of attributes that define a vehicle's
        # instance, we can read them and modify some of them. For instance,
        # let's randomize its color.
#        if bp.has_attribute('color'):
#            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. 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)

#        # It is important to note that the actors we create won't be destroyed
#        # unless we call their "destroy" function. If we fail to call "destroy"
#        # they will stay in the simulation even after we quit the Python script.
#        # For that reason, we are storing all the actors we create so we can
#        # destroy them afterwards.
#        actor_list.append(vehicle)
#        print('created %s' % vehicle.type_id)

#        # Let's put the vehicle to drive around.
#        vehicle.set_autopilot(True)

#        # Let's add now a "depth" camera attached to the vehicle. Note that the
#        # transform we give here is now relative to the vehicle.
#        camera_bp = blueprint_library.find('sensor.camera.depth')
#        camera_transform = carla.Transform(carla.Location(x=1.5, z=2.4))
#        camera = world.spawn_actor(camera_bp, camera_transform, attach_to=vehicle)
#        actor_list.append(camera)
#        print('created %s' % camera.type_id)

#        # Now we register the function that will be called each time the sensor
#        # receives an image. In this example we are saving the image to disk
#        # converting the pixels to gray-scale.
#        cc = carla.ColorConverter.LogarithmicDepth
#        camera.listen(lambda image: image.save_to_disk('_out/%06d.png' % image.frame, cc))

#        # Oh wait, I don't like the location we gave to the vehicle, I'm going
#        # to move it a bit forward.
#        location = vehicle.get_location()
#        location.x += 40
#        vehicle.set_location(location)
#        print('moved vehicle to %s' % location)

#        # But the city now is probably quite empty, let's add a few more
#        # vehicles.
#        transform.location += carla.Location(x=40, y=-3.2)
#        transform.rotation.yaw = -180.0
#        for _ in range(0, 10):
#            transform.location.x += 8.0

#            bp = random.choice(blueprint_library.filter('vehicle'))

#            # This time we are using try_spawn_actor. If the spot is already
#            # occupied by another object, the function will return None.
#            npc = world.try_spawn_actor(bp, transform)
#            if npc is not None:
#                actor_list.append(npc)
#                npc.set_autopilot()
#                print('created %s' % npc.type_id)



    finally:

#        print('destroying actors')
#        for actor in actor_list:
#            actor.destroy()
        print('done.')


if __name__ == '__main__':

    main()
