Ejemplo n.º 1
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     camera2 = Camera('Camera2')
     camera2.set(PostProcessing='Depth', CameraFOV=120)
     camera2.set_image_size(1924, 1028)
     settings.add_camera(camera2)
     self.run_carla_client(settings, 3, 100)
Ejemplo n.º 2
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     camera2 = Camera('Camera2')
     camera2.set(PostProcessing='Depth', CameraFOV=120)
     camera2.set_image_size(1924, 1028)
     settings.add_camera(camera2)
     self.run_carla_client(settings, 3, 100)
Ejemplo n.º 3
0
 def run(self):
     settings = CarlaSettings()
     settings.set(SynchronousMode=True,
                  SendNonPlayerAgentsInfo=True,
                  NumberOfVehicles=60,
                  NumberOfPedestrians=90)
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 3, 100)
Ejemplo n.º 4
0
 def run(self):
     settings = CarlaSettings()
     settings.set(
         SynchronousMode=True,
         SendNonPlayerAgentsInfo=True,
         NumberOfVehicles=60,
         NumberOfPedestrians=90)
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 3, 100)
Ejemplo n.º 5
0
def run_carla_client(args):
    with make_connection(CarlaClient, args.host, args.port, timeout=15) as client:
        logging.info('CarlaClient connected')
        filename = '_images/episode_{:0>3d}/image_{:0>5d}.png'
        frames_per_episode = 300
        episode = 0
        while True:
            episode += 1
            settings = CarlaSettings()
            settings.set(SendNonPlayerAgentsInfo=True,SynchronousMode=args.synchronous)
            settings.randomize_seeds()
            camera = Camera('DefaultCamera')
            camera.set_image_size(300, 200) # Do not change this, hard-coded in test.
            settings.add_camera(camera)

            logging.debug('sending CarlaSettings:\n%s', settings)
            logging.info('new episode requested')

            scene = client.request_new_episode(settings)

            number_of_player_starts = len(scene.player_start_spots)
            player_start = random.randint(0, max(0, number_of_player_starts - 1))
            logging.info(
                'start episode at %d/%d player start (%d frames)',
                player_start,
                number_of_player_starts,
                frames_per_episode)

            client.start_episode(player_start)

            use_ai_control = (random.random() < 0.5)
            reverse = (random.random() < 0.2)

            for frame in range(0, frames_per_episode):
                logging.debug('reading measurements...')
                measurements, images = client.read_measurements()

                logging.debug('received data of %d agents', len(measurements.non_player_agents))
                assert len(images) == 1
                assert (images[0].width, images[0].height) == (camera.ImageSizeX, camera.ImageSizeY)

                if args.images_to_disk:
                    images[0].save_to_disk(filename.format(episode, frame))

                logging.debug('sending control...')
                control = measurements.player_measurements.ai_control
                if not use_ai_control:
                    control.steer = random.uniform(-1.0, 1.0)
                    control.throttle = 0.3
                    control.hand_brake = False
                    control.reverse = reverse
                client.send_control(
                    steer=control.steer,
                    throttle=control.throttle,
                    brake=control.brake,
                    hand_brake=control.hand_brake,
                    reverse=control.reverse)
Ejemplo n.º 6
0
def run_carla_client(args):
    with make_connection(CarlaClient, args.host, args.port,
                         timeout=15) as client:
        logging.info('CarlaClient connected')
        filename = '_images/episode_{:0>3d}/image_{:0>5d}.png'
        frames_per_episode = 300
        episode = 0
        while True:
            episode += 1
            settings = CarlaSettings()
            settings.set(SendNonPlayerAgentsInfo=True,
                         SynchronousMode=args.synchronous)
            settings.randomize_seeds()
            camera = Camera('DefaultCamera')
            camera.set_image_size(
                300, 200)  # Do not change this, hard-coded in test.
            settings.add_camera(camera)

            logging.debug('sending CarlaSettings:\n%s', settings)
            logging.info('new episode requested')

            scene = client.request_new_episode(settings)

            number_of_player_starts = len(scene.player_start_spots)
            player_start = random.randint(0, max(0,
                                                 number_of_player_starts - 1))
            logging.info('start episode at %d/%d player start (%d frames)',
                         player_start, number_of_player_starts,
                         frames_per_episode)

            client.start_episode(player_start)

            use_ai_control = (random.random() < 0.5)
            reverse = (random.random() < 0.2)

            for frame in range(0, frames_per_episode):
                logging.debug('reading measurements...')
                measurements, images = client.read_measurements()

                logging.debug('received data of %d agents',
                              len(measurements.non_player_agents))
                assert len(images) == 1
                assert (images[0].width,
                        images[0].height) == (camera.ImageSizeX,
                                              camera.ImageSizeY)

                if args.images_to_disk:
                    images[0].save_to_disk(filename.format(episode, frame))

                logging.debug('sending control...')
                control = measurements.player_measurements.ai_control
                if not use_ai_control:
                    control.steer = random.uniform(-1.0, 1.0)
                    control.throttle = 0.3
                    control.hand_brake = False
                    control.reverse = reverse
                client.send_control(steer=control.steer,
                                    throttle=control.throttle,
                                    brake=control.brake,
                                    hand_brake=control.hand_brake,
                                    reverse=control.reverse)
Ejemplo n.º 7
0
def run_carla_client(host, port, autopilot_on, save_images_to_disk, image_filename_format):
    # Here we will run 3 episodes with 300 frames each.
    number_of_episodes = 3
    frames_per_episode = 300

    # We assume the CARLA server is already waiting for a client to connect at
    # host:port. To create a connection we can use the `make_carla_client`
    # context manager, it creates a CARLA client object and starts the
    # connection. It will throw an exception if something goes wrong. The
    # context manager makes sure the connection is always cleaned up on exit.
    with make_carla_client(host, port) as client:
        print('CarlaClient connected')

        for episode in range(0, number_of_episodes):
            # Start a new episode.

            # Create a CarlaSettings object. This object is a handy wrapper
            # around the CarlaSettings.ini file. Here we set the configuration
            # we want for the new episode.
            settings = CarlaSettings()
            settings.set(
                SynchronousMode=True,
                NumberOfVehicles=30,
                NumberOfPedestrians=50,
                WeatherId=random.choice([1, 3, 7, 8, 14]))
            settings.randomize_seeds()

            # Now we want to add a couple of cameras to the player vehicle. We
            # will collect the images produced by these cameras every frame.

            # The default camera captures RGB images of the scene.
            camera0 = Camera('CameraRGB')
            # Set image resolution in pixels.
            camera0.set_image_size(800, 600)
            # Set its position relative to the car in centimeters.
            camera0.set_position(30, 0, 130)
            settings.add_camera(camera0)

            # Let's add another camera producing ground-truth depth.
            camera1 = Camera('CameraDepth', PostProcessing='Depth')
            camera1.set_image_size(800, 600)
            camera1.set_position(30, 0, 130)
            settings.add_camera(camera1)

            print('Requesting new episode...')

            # Now we request a new episode with these settings. The server
            # replies with a scene description containing the available start
            # spots for the player. Here instead of a CarlaSettings object we
            # could also provide a CarlaSettings.ini file as string.
            scene = client.request_new_episode(settings)

            # Choose one player start at random.
            number_of_player_starts = len(scene.player_start_spots)
            player_start = random.randint(0, max(0, number_of_player_starts - 1))

            # Notify the server that we want to start the episode at
            # `player_start`. This function blocks until the server is ready to
            # start the episode.
            client.start_episode(player_start)

            # Iterate every frame in the episode.
            for frame in range(0, frames_per_episode):

                # Read the measurements and images produced by the server this
                # frame.
                measurements, images = client.read_measurements()

                # Print some of the measurements we received.
                print_player_measurements(measurements.player_measurements)

                # Save the images to disk if requested.
                if save_images_to_disk:
                    for n, image in enumerate(images):
                        image.save_to_disk(image_filename_format.format(episode, n, frame))

                # Now we have to send the instructions to control the vehicle.
                # If we are in synchronous mode the server will pause the
                # simulation until we send this control.

                if not autopilot_on:

                    client.send_control(
                        steer=random.uniform(-1.0, 1.0),
                        throttle=0.3,
                        brake=False,
                        hand_brake=False,
                        reverse=False)

                else:

                    # Together with the measurements, the server has sent the
                    # control that the in-game AI would do this frame. We can
                    # enable autopilot by sending back this control to the
                    # server. Here we will also add some noise to the steer.

                    control = measurements.player_measurements.ai_control
                    control.steer += random.uniform(-0.1, 0.1)
                    client.send_control(control)

    print('Done.')
    return True
Ejemplo n.º 8
0
 def run(self):
     settings = CarlaSettings(SynchronousMode=True)
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 3, 200)
Ejemplo n.º 9
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 5, 200)
Ejemplo n.º 10
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 1, 2000, use_ai_control=True)
Ejemplo n.º 11
0
def run_carla_client(host, port, autopilot_on, save_images_to_disk,
                     image_filename_format):
    # Here we will run 3 episodes with 300 frames each.
    number_of_episodes = 3
    frames_per_episode = 300

    # We assume the CARLA server is already waiting for a client to connect at
    # host:port. To create a connection we can use the `make_carla_client`
    # context manager, it creates a CARLA client object and starts the
    # connection. It will throw an exception if something goes wrong. The
    # context manager makes sure the connection is always cleaned up on exit.
    with make_carla_client(host, port) as client:
        print('CarlaClient connected')

        for episode in range(0, number_of_episodes):
            # Start a new episode.

            # Create a CarlaSettings object. This object is a handy wrapper
            # around the CarlaSettings.ini file. Here we set the configuration
            # we want for the new episode.
            settings = CarlaSettings()
            settings.set(SynchronousMode=True,
                         NumberOfVehicles=30,
                         NumberOfPedestrians=50,
                         WeatherId=random.choice([1, 3, 7, 8, 14]))
            settings.randomize_seeds()

            # Now we want to add a couple of cameras to the player vehicle. We
            # will collect the images produced by these cameras every frame.

            # The default camera captures RGB images of the scene.
            camera0 = Camera('CameraRGB')
            # Set image resolution in pixels.
            camera0.set_image_size(800, 600)
            # Set its position relative to the car in centimeters.
            camera0.set_position(30, 0, 130)
            settings.add_camera(camera0)

            # Let's add another camera producing ground-truth depth.
            camera1 = Camera('CameraDepth', PostProcessing='Depth')
            camera1.set_image_size(800, 600)
            camera1.set_position(30, 0, 130)
            settings.add_camera(camera1)

            print('Requesting new episode...')

            # Now we request a new episode with these settings. The server
            # replies with a scene description containing the available start
            # spots for the player. Here instead of a CarlaSettings object we
            # could also provide a CarlaSettings.ini file as string.
            scene = client.request_new_episode(settings)

            # Choose one player start at random.
            number_of_player_starts = len(scene.player_start_spots)
            player_start = random.randint(0, max(0,
                                                 number_of_player_starts - 1))

            # Notify the server that we want to start the episode at
            # `player_start`. This function blocks until the server is ready to
            # start the episode.
            client.start_episode(player_start)

            # Iterate every frame in the episode.
            for frame in range(0, frames_per_episode):

                # Read the measurements and images produced by the server this
                # frame.
                measurements, images = client.read_measurements()

                # Print some of the measurements we received.
                print_player_measurements(measurements.player_measurements)

                # Save the images to disk if requested.
                if save_images_to_disk:
                    for n, image in enumerate(images):
                        image.save_to_disk(
                            image_filename_format.format(episode, n, frame))

                # Now we have to send the instructions to control the vehicle.
                # If we are in synchronous mode the server will pause the
                # simulation until we send this control.

                if not autopilot_on:

                    client.send_control(steer=random.uniform(-1.0, 1.0),
                                        throttle=0.3,
                                        brake=False,
                                        hand_brake=False,
                                        reverse=False)

                else:

                    # Together with the measurements, the server has sent the
                    # control that the in-game AI would do this frame. We can
                    # enable autopilot by sending back this control to the
                    # server. Here we will also add some noise to the steer.

                    control = measurements.player_measurements.ai_control
                    control.steer += random.uniform(-0.1, 0.1)
                    client.send_control(control)

    print('Done.')
    return True
Ejemplo n.º 12
0
 def run(self):
     settings = CarlaSettings(SynchronousMode=True)
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 3, 200)
Ejemplo n.º 13
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 5, 200)
Ejemplo n.º 14
0
 def run(self):
     settings = CarlaSettings()
     settings.add_camera(Camera('DefaultCamera'))
     self.run_carla_client(settings, 1, 2000, use_ai_control=True)