def make_carla_settings():
    """Make a CarlaSettings object with the settings we need."""



    settings = CarlaSettings()
    settings.set(
        SendNonPlayerAgentsInfo=True,
        SynchronousMode=True,
        NumberOfVehicles=30,
        NumberOfPedestrians=50,
        WeatherId=1)

    settings.set(DisableTwoWheeledVehicles=True)

    settings.randomize_seeds() # IMPORTANT TO RANDOMIZE THE SEEDS EVERY TIME
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=100)
    camera0.set_image_size(800, 600)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0, 0)

    settings.add_sensor(camera0)

    return settings




# 65, 18 to 65, 16

# 18, 145 to 16, 145

# 79, 45 to 79 47
def make_carla_settings():
    """Make a CarlaSettings object with the settings we need."""

    settings = CarlaSettings()
    settings.set(SendNonPlayerAgentsInfo=True,
                 SynchronousMode=True,
                 NumberOfVehicles=30,
                 NumberOfPedestrians=50,
                 WeatherId=1)

    settings.set(DisableTwoWheeledVehicles=True)

    settings.randomize_seeds()  # IMPORTANT TO RANDOMIZE THE SEEDS EVERY TIME
    camera0 = sensor.Camera('CentralSemanticSeg',
                            PostProcessing='SemanticSegmentation')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0, 0)

    settings.add_sensor(camera0)
    camera0 = sensor.Camera('CentralRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0, 0)

    settings.add_sensor(camera0)

    camera0 = sensor.Camera('LeftSemanticSeg',
                            PostProcessing='SemanticSegmentation')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, -30.0, 0)

    settings.add_sensor(camera0)
    camera0 = sensor.Camera('LeftRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, -30.0, 0)

    settings.add_sensor(camera0)

    camera0 = sensor.Camera('RightSemanticSeg',
                            PostProcessing='SemanticSegmentation')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 30.0, 0)

    settings.add_sensor(camera0)
    camera0 = sensor.Camera('RightRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 30.0, 0)

    return settings
Exemplo n.º 3
0
    def start_new_episode(self, player_index):
        settings = CarlaSettings()
        settings.set(SynchronousMode=True,
                     SendNonPlayerAgentsInfo=True,
                     NumberOfVehicles=20,
                     NumberOfPedestrians=40,
                     WeatherId=random.choice([1, 3, 7, 8, 14]))
        settings.randomize_seeds()

        camera0 = Camera('CameraRGB')
        camera0.set(CameraFOV=100)
        camera0.set_image_size(800, 400)
        camera0.set_position(120, 0, 130)
        settings.add_sensor(camera0)

        camera2 = Camera('CameraSeg', PostProcessing='SemanticSegmentation')
        camera2.set(CameraFOV=100)
        camera2.set_image_size(800, 400)
        camera2.set_position(120, 0, 130)
        settings.add_sensor(camera2)

        self.client.load_settings(settings)
        self.episode_index += 1
        self.frame = 0
        print('\nStarting episode {0}.'.format(self.episode_index))
        self.client.start_episode(player_index)
Exemplo n.º 4
0
    def _setup_carla_client(self):
        carla_client = CarlaClient(self._params['host'], self._params['port'], timeout=None)
        carla_client.connect()

        ### create initial settings
        carla_settings = CarlaSettings()
        carla_settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=False,
            NumberOfVehicles=self._params['number_of_vehicles'],
            NumberOfPedestrians=self._params['number_of_pedestrians'],
            WeatherId=self._params['weather'])
        carla_settings.randomize_seeds()

        ### add cameras
        for camera_name in self._params['cameras']:
            camera_params = self._params[camera_name]
            camera_postprocessing = camera_params['postprocessing']
            camera = Camera(camera_name, PostProcessing=camera_postprocessing)
            camera.set_image_size(CarlaCollSpeedEnv.CAMERA_HEIGHT * CarlaCollSpeedEnv.WIDTH_TO_HEIGHT_RATIO, CarlaCollSpeedEnv.CAMERA_HEIGHT)
            camera.set_position(*camera_params['position'])
            camera.set(**{'FOV': camera_params['fov']})

            carla_settings.add_sensor(camera)

        ### load settings
        carla_scene = carla_client.load_settings(carla_settings)

        self._carla_client = carla_client
        self._carla_settings = carla_settings
        self._carla_scene = carla_scene
Exemplo n.º 5
0
    def _reset(self):
        self.num_steps = 0
        self.total_reward = 0
        self.prev_measurement = None
        self.prev_image = None
        self.episode_id = datetime.today().strftime("%Y-%m-%d_%H-%M-%S_%f")
        self.measurements_file = None

        # Create a CarlaSettings object. This object is a wrapper around
        # the CarlaSettings.ini file. Here we set the configuration we
        # want for the new episode.
        settings = CarlaSettings()
        self.scenario = random.choice(self.config["scenarios"])
        assert self.scenario["city"] == self.city, (self.scenario, self.city)
        self.weather = random.choice(self.scenario["weather_distribution"])
        settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=True,
            NumberOfVehicles=self.scenario["num_vehicles"],
            NumberOfPedestrians=self.scenario["num_pedestrians"],
            WeatherId=self.weather)
        settings.randomize_seeds()

        if self.config["use_depth_camera"]:
            camera1 = Camera("CameraDepth", PostProcessing="Depth")
            camera1.set_image_size(self.config["render_x_res"],
                                   self.config["render_y_res"])
            camera1.set_position(30, 0, 130)
            settings.add_sensor(camera1)

        camera2 = Camera("CameraRGB")
        camera2.set_image_size(self.config["render_x_res"],
                               self.config["render_y_res"])
        camera2.set_position(30, 0, 130)
        settings.add_sensor(camera2)

        # Setup start and end positions
        scene = self.client.load_settings(settings)
        positions = scene.player_start_spots
        self.start_pos = positions[self.scenario["start_pos_id"]]
        self.end_pos = positions[self.scenario["end_pos_id"]]
        self.start_coord = [
            self.start_pos.location.x // 100, self.start_pos.location.y // 100
        ]
        self.end_coord = [
            self.end_pos.location.x // 100, self.end_pos.location.y // 100
        ]
        print("Start pos {} ({}), end {} ({})".format(
            self.scenario["start_pos_id"], self.start_coord,
            self.scenario["end_pos_id"], self.end_coord))

        # Notify the server that we want to start the episode at the
        # player_start index. This function blocks until the server is ready
        # to start the episode.
        print("Starting new episode...")
        self.client.start_episode(self.scenario["start_pos_id"])

        image, py_measurements = self._read_observation()
        self.prev_measurement = py_measurements
        return self.encode_obs(self.preprocess_image(image), py_measurements)
Exemplo n.º 6
0
def make_carla_settings():
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=15,
                 NumberOfPedestrians=30,
                 WeatherId=random.choice([1, 3, 7, 8, 14]))
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(200, 0, 140)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera1.set_position(200, 0, 140)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    if mixed_reality:
        camera2.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    else:
        camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_position(200, 0, 140)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)
    return settings
Exemplo n.º 7
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need.
    """
    settings = CarlaSettings()
    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=False,
                 NumberOfVehicles=20,
                 NumberOfPedestrians=40,
                 WeatherId=1)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera1.set_position(2.0, 0.0, 1.4)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_position(2.0, 0.0, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)

    return settings
Exemplo n.º 8
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need.
    """
    settings = CarlaSettings()
    settings = CarlaSettings()
    settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=False,
            NumberOfVehicles=20,
            NumberOfPedestrians=40,
            WeatherId=1)
    settings.randomize_seeds()
    camera1 = Camera('CameraDepth', PostProcessing='Depth', FOV=fov)
    camera1.set_image_size(*image_size)
    camera1.set_position(*camera_local_pos)
    camera1.set_rotation(*camera_local_rotation)
    settings.add_sensor(camera1)

    camera2 = Camera('CameraRGB', PostProcessing='SceneFinal', FOV=fov)
    camera2.set_image_size(*image_size)
    camera2.set_position(*camera_local_pos)
    camera2.set_rotation(*camera_local_rotation)
    settings.add_sensor(camera2)
    
    return settings,camera2
Exemplo n.º 9
0
    def carla_settings(self):
        settings = CarlaSettings()
        settings.set(SynchronousMode=False,
                     SendNonPlayerAgentsInfo=False,
                     NumberOfVehicles=0,
                     NumberOfPedestrians=0,
                     WeatherId=0)
        settings.randomize_seeds()

        camera0 = sensor.Camera('CameraCenter')
        camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
        camera0.set_position(200, 0, 140)
        camera0.set_rotation(0.0, 0.0, 0.0)
        settings.add_sensor(camera0)

        camera1 = sensor.Camera('CameraLeft')
        camera1.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
        camera1.set_position(200, 0, 140)
        camera1.set_rotation(0.0, 0.0, -30.0)
        settings.add_sensor(camera1)

        camera2 = sensor.Camera('CameraRight')
        camera2.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
        camera2.set_position(200, 0, 140)
        camera2.set_rotation(0.0, 0.0, 30.0)
        settings.add_sensor(camera2)

        if self.map_view is not None:
            camera3 = sensor.Camera('TPPCamera')
            camera3.set_image_size(self.map_view.shape[1], WINDOW_HEIGHT // 2)
            camera3.set_position(-450, 0, 400)
            camera3.set_rotation(-30.0, 0.0, 0.0)
            settings.add_sensor(camera3)

        self.settings = settings
Exemplo n.º 10
0
    def make_carla_settings(self):

        if self.settings_filepath is None:
            """Make a CarlaSettings object with the settings we need."""
            settings = CarlaSettings()
            settings.set(SynchronousMode=True,
                         SendNonPlayerAgentsInfo=True,
                         NumberOfVehicles=5,
                         NumberOfPedestrians=60,
                         WeatherId=random.choice(
                             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]))
            settings.randomize_seeds()
            camera0 = sensor.Camera('CameraRGB')
            camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
            camera0.set_position(200, 0, 140)
            camera0.set_rotation(0.0, 0.0, 0.0)
            settings.add_sensor(camera0)
            camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
            camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
            camera1.set_position(200, 0, 140)
            camera1.set_rotation(0.0, 0.0, 0.0)
            settings.add_sensor(camera1)
            camera2 = sensor.Camera('CameraSemSeg',
                                    PostProcessing='SemanticSegmentation')
            camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
            camera2.set_position(200, 0, 140)
            camera2.set_rotation(0.0, 0.0, 0.0)
            settings.add_sensor(camera2)
        else:
            # Alternatively, we can load these settings from a file.
            with open(self.settings_filepath, 'r') as fp:
                settings = fp.read()

        return settings
Exemplo n.º 11
0
    def _reset(self):
        self.num_steps = 0
        self.total_reward = 0
        self.prev_measurement = None
        self.prev_image = None
        self.episode_id = datetime.today().strftime("%Y-%m-%d_%H-%M-%S_%f")
        self.measurements_file = None

        # Create a CarlaSettings object. This object is a wrapper around
        # the CarlaSettings.ini file. Here we set the configuration we
        # want for the new episode.
        settings = CarlaSettings()
        self.scenario = random.choice(self.config["scenarios"])
        assert self.scenario["city"] == self.city, (self.scenario, self.city)
        self.weather = random.choice(self.scenario["weather_distribution"])
        settings.set(SynchronousMode=True,
                     SendNonPlayerAgentsInfo=True,
                     NumberOfVehicles=self.scenario["num_vehicles"],
                     NumberOfPedestrians=self.scenario["num_pedestrians"],
                     WeatherId=self.weather)
        settings.randomize_seeds()

        if self.config["use_depth_camera"]:
            camera1 = Camera("CameraDepth", PostProcessing="Depth")
            camera1.set_image_size(self.config["render_x_res"],
                                   self.config["render_y_res"])
            camera1.set_position(0.1, 0, 1.7)
            settings.add_sensor(camera1)

        camera2 = Camera("CameraRGB")
        camera2.set_image_size(self.config["render_x_res"],
                               self.config["render_y_res"])
        camera2.set_position(0.1, 0, 1.7)
        settings.add_sensor(camera2)

        # Setup start and end positions
        scene = self.client.load_settings(settings)
        positions = scene.player_start_spots
        self.start_pos = positions[self.scenario["start_pos_id"]]
        self.end_pos = positions[self.scenario["end_pos_id"]]
        self.start_coord = [
            self.start_pos.location.x // 100, self.start_pos.location.y // 100
        ]
        self.end_coord = [
            self.end_pos.location.x // 100, self.end_pos.location.y // 100
        ]
        print("Start pos {} ({}), end {} ({})".format(
            self.scenario["start_pos_id"], self.start_coord,
            self.scenario["end_pos_id"], self.end_coord))

        # Notify the server that we want to start the episode at the
        # player_start index. This function blocks until the server is ready
        # to start the episode.
        print("Starting new episode...")
        self.client.start_episode(self.scenario["start_pos_id"])

        image, py_measurements = self._read_observation()
        self.prev_measurement = py_measurements
        return self.encode_obs(self.preprocess_image(image), py_measurements)
Exemplo n.º 12
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)
Exemplo n.º 13
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=False,
                 NumberOfVehicles=0,
                 NumberOfPedestrians=0,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    return settings
Exemplo n.º 14
0
def generate_settings(args, sync_mode=True):
    settings = CarlaSettings()
    settings.set(SynchronousMode=sync_mode,
                 SendNonPlayerAgentsInfo=False,
                 NumberOfVehicles=0,
                 NumberOfPedestrians=0,
                 WeatherId=args.weather,
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()

    return settings
Exemplo n.º 15
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=0,
                 NumberOfPedestrians=0,
                 SeedVehicles='00000',
                 WeatherId=1,
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    return settings
Exemplo n.º 16
0
    def __init__(self,
                 client,
                 frame_skip=1,
                 cam_width=800,
                 cam_height=600,
                 town_string='Town01'):
        super(StraightDriveEnv, self).__init__()
        self.frame_skip = frame_skip
        self.client = client
        self._planner = Planner(town_string)

        camera0 = Camera('CameraRGB')
        camera0.set(CameraFOV=100)
        camera0.set_image_size(cam_height, cam_width)
        camera0.set_position(200, 0, 140)
        camera0.set_rotation(-15.0, 0, 0)

        self.start_goal_pairs = [[36, 40], [39, 35], [110, 114], [7,
                                                                  3], [0, 4],
                                 [68, 50], [61, 59], [47, 64], [147, 90],
                                 [33, 87], [26, 19], [80, 76], [45, 49],
                                 [55, 44], [29, 107], [95, 104], [84, 34],
                                 [53, 67], [22, 17], [91, 148], [20, 107],
                                 [78, 70], [95, 102], [68, 44], [45, 69]]

        vehicles = 0
        pedestrians = 0
        weather = 1

        settings = CarlaSettings()
        settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=True,
            NumberOfVehicles=vehicles,
            NumberOfPedestrians=pedestrians,
            WeatherId=weather,
        )

        settings.randomize_seeds()
        settings.add_sensor(camera0)

        self.scene = self.client.load_settings(settings)

        img_shape = (cam_width, cam_height, 3)
        self.observation_space = spaces.Tuple(
            (spaces.Box(-np.inf, np.inf, (3, )), spaces.Box(0, 255,
                                                            img_shape)))
        self.action_space = spaces.Box(-np.inf, np.inf, shape=(3, ))

        self.prev_state = np.array([0., 0., 0.])
        self.prev_collisions = np.array([0., 0., 0.])
        self.prev_intersections = np.array([0., 0.])
Exemplo n.º 17
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(
        SynchronousMode=False,
        SendNonPlayerAgentsInfo=True,
        NumberOfVehicles=NUM_VEHICLES,
        NumberOfPedestrians=NUM_PEDESTRIANS,
        DisableTwoWheeledVehicles=NO_BIKE,
        # WeatherId=random.choice([1, 3, 7, 8, 14]),
        WeatherId=1,
        QualityLevel=args.quality_level)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(0, 0.0, CAMERA_HEIGHT_POS)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)

    lidar = sensor.Lidar('Lidar32')
    lidar.set_position(0, 0.0, LIDAR_HEIGHT_POS)
    lidar.set_rotation(0, 0, 0)
    lidar.set(Channels=40,
              Range=MAX_RENDER_DEPTH_IN_METERS,
              PointsPerSecond=720000,
              RotationFrequency=10,
              UpperFovLimit=7,
              LowerFovLimit=-16)
    settings.add_sensor(lidar)
    """ Depth camera for filtering out occluded vehicles """
    depth_camera = sensor.Camera('DepthCamera', PostProcessing='Depth')
    depth_camera.set(FOV=90.0)
    depth_camera.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    depth_camera.set_position(0, 0, CAMERA_HEIGHT_POS)
    depth_camera.set_rotation(0, 0, 0)
    settings.add_sensor(depth_camera)
    # (Intrinsic) K Matrix
    # | f 0 Cu
    # | 0 f Cv
    # | 0 0 1
    # (Cu, Cv) is center of image
    k = np.identity(3)
    k[0, 2] = WINDOW_WIDTH_HALF
    k[1, 2] = WINDOW_HEIGHT_HALF
    f = WINDOW_WIDTH / \
        (2.0 * math.tan(90.0 * math.pi / 360.0))
    k[0, 0] = k[1, 1] = f
    camera_to_car_transform = camera0.get_unreal_transform()
    lidar_to_car_transform = lidar.get_transform() * Transform(
        Rotation(yaw=90), Scale(z=-1))
    return settings, k, camera_to_car_transform, lidar_to_car_transform
Exemplo n.º 18
0
    def _reset(self):
        self.num_steps = 0
        self.prev_measurement = None
        self.episode_id = datetime.today().strftime("%Y-%m-%d_%H-%M-%S_%f")
        self.measurements_file = None

        # Create a CarlaSettings object. This object is a wrapper around
        # the CarlaSettings.ini file. Here we set the configuration we
        # want for the new episode.
        settings = CarlaSettings()
        self.weather = random.choice(self.config["weather"])
        settings.set(SynchronousMode=True,
                     SendNonPlayerAgentsInfo=True,
                     NumberOfVehicles=self.config["num_vehicles"],
                     NumberOfPedestrians=self.config["num_pedestrians"],
                     WeatherId=self.weather)
        settings.randomize_seeds()

        camera1 = Camera("CameraDepth", PostProcessing="Depth")
        camera1.set_image_size(self.config["render_x_res"],
                               self.config["render_y_res"])
        camera1.set_position(30, 0, 130)
        settings.add_sensor(camera1)

        camera2 = Camera("CameraRGB")
        camera2.set_image_size(self.config["render_x_res"],
                               self.config["render_y_res"])
        camera2.set_position(30, 0, 130)
        settings.add_sensor(camera2)

        scene = self.client.load_settings(settings)

        # Choose one player start at random.
        number_of_player_starts = len(scene.player_start_spots)
        if self.config["random_starting_location"]:
            self.player_start = random.randint(
                0, max(0, number_of_player_starts - 1))
        else:
            self.player_start = 0

        # Notify the server that we want to start the episode at the
        # player_start index. This function blocks until the server is ready
        # to start the episode.
        print("Starting new episode...")
        self.client.start_episode(self.player_start)

        image, py_measurements = self._read_observation()
        self.prev_measurement = py_measurements
        return self.preprocess_image(image)
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(
        SynchronousMode=True,
        SendNonPlayerAgentsInfo=True,
        NumberOfVehicles=10,
        NumberOfPedestrians=100,
        WeatherId=random.choice([1, 3, 7, 8, 14]),
        QualityLevel=args.quality_level)
    settings.randomize_seeds()
    # camera0 = sensor.Camera('CameraRGB_main')
    # camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    # camera0.set_position(2.0, 0.0, 1.4)
    # camera0.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera0)
    # camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    # camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    # camera1.set_position(2.0, 0.0, 1.4)
    # camera1.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera1)
    # camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation')
    # camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    # camera2.set_position(2.0, 0.0, 1.4)
    # camera2.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera2)
    cameraNN = sensor.Camera('CameraRGB')
    cameraNN.set_image_size(H5_WINDOW_WIDTH, H5_WINDOW_HEIGHT)
    cameraNN.set_position(2.0, 0.0, 1.4)
    cameraNN.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(cameraNN)
    camera3 = sensor.Camera('CameraRGB_h5')
    camera3.set_image_size(H5_WINDOW_WIDTH, H5_WINDOW_HEIGHT)
    camera3.set_position(2.0, 0.0, 1.4)
    camera3.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera3)
    if args.lidar:
        lidar = sensor.Lidar('Lidar32')
        lidar.set_position(0, 0, 2.5)
        lidar.set_rotation(0, 0, 0)
        lidar.set(
            Channels=32,
            Range=50,
            PointsPerSecond=100000,
            RotationFrequency=10,
            UpperFovLimit=10,
            LowerFovLimit=-30)
        settings.add_sensor(lidar)
    return settings
Exemplo n.º 20
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""

    ########################################################################################################
    # TODO
    # Change this to add more cameras
    # Remove segmentation, depth if we use our own
    # Change the no of vehicles, pedestrians, weather
    ########################################################################################################

    ###################################### Default from carla ######################################

    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=15,
                 NumberOfPedestrians=30,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera1.set_position(2.0, 0.0, 1.4)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_position(2.0, 0.0, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)
    if args.lidar:
        lidar = sensor.Lidar('Lidar32')
        lidar.set_position(0, 0, 2.5)
        lidar.set_rotation(0, 0, 0)
        lidar.set(Channels=32,
                  Range=50,
                  PointsPerSecond=100000,
                  RotationFrequency=10,
                  UpperFovLimit=10,
                  LowerFovLimit=-30)
        settings.add_sensor(lidar)
    return settings
Exemplo n.º 21
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=10,
                 NumberOfPedestrians=5,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(0.30, 0, 1.30)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    return settings
Exemplo n.º 22
0
def make_carla_settings():
    """Make a CarlaSettings object with the settings we need."""

    settings = CarlaSettings()
    settings.set(SendNonPlayerAgentsInfo=True, SynchronousMode=True)
    settings.set(DisableTwoWheeledVehicles=True)

    settings.randomize_seeds()
    # Add a carla camera.
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=FOV)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0, 0)
    settings.add_sensor(camera0)

    return settings
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""

    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=0,
                 NumberOfPedestrians=0,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()

    #Camera type and placement is chosen
    #comment out a camera block if not wanted
    camera0 = sensor.Camera('CameraCenter')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)

    camera1 = sensor.Camera('CameraRight')
    camera1.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera1.set_position(2.0, 1.5, 1.4)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)

    camera2 = sensor.Camera('CameraLeft')
    camera2.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera2.set_position(2.0, -1.5, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)

    #if lidar is chosen, placement of it
    if args.lidar:
        lidar = sensor.Lidar('Lidar32')
        lidar.set_position(0, 0, 2.5)
        lidar.set_rotation(0, 0, 0)
        lidar.set(Channels=32,
                  Range=50,
                  PointsPerSecond=100000,
                  RotationFrequency=10,
                  UpperFovLimit=10,
                  LowerFovLimit=-30)
        settings.add_sensor(lidar)
    return settings
Exemplo n.º 24
0
def gen_settings(args):
	settings = CarlaSettings()
	settings.set(
		SynchronousMode=True,
		SendNonPlayerAgentsInfo=False,
		NumberOfVehicles=0,
		NumberOfPedestrians=0,
		WeatherId=args.weather,
		QualityLevel=args.quality_level)
	settings.randomize_seeds()
	camera_pos_x = 2
	camera_pos_y = 0
	camera_pos_z = 1

	camera = Camera("MainCamera")
	camera.set_image_size(800, 600)
	camera.set_position(camera_pos_x, camera_pos_y, camera_pos_z)
	settings.add_sensor(camera)
	return settings
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    model = lm('./model_semseg.hdf5')
    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=5,
                 NumberOfPedestrians=30,
                 WeatherId=random.choice(list(range(15))),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    # camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    # # camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    # camera1.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    # camera1.set_position(2.0, 0.0, 1.4)
    # camera1.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    # camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera2.set_position(2.0, 0.0, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)
    # if args.lidar:
    #     lidar = sensor.Lidar('Lidar32')
    #     lidar.set_position(0, 0, 2.5)
    #     lidar.set_rotation(0, 0, 0)
    #     lidar.set(
    #         Channels=32,
    #         Range=50,
    #         PointsPerSecond=100000,
    #         RotationFrequency=10,
    #         UpperFovLimit=10,
    #         LowerFovLimit=-30)
    #     settings.add_sensor(lidar)
    return settings
Exemplo n.º 26
0
def make_carla_settings(args):
    '''
    Creates a CarlaSettings object.
    It configures the sensors, pedestrians, vehicles, weather, etc.
    '''
    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=args.vehicles,
                 NumberOfPedestrians=args.pedestrians,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    # 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 meters.
    camera0.set_position(0.30, 0, 1.30)
    settings.add_sensor(camera0)
    return settings
Exemplo n.º 27
0
def get_carla_settings(settings_file=None):

    if settings_file is None:

        # Create a CarlaSettings object. This object is a wrapper around
        # the CarlaSettings.ini file. Here we set the configuration we
        # want for the new episode.
        settings = CarlaSettings()
        settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=False,
            NumberOfVehicles=0,
            NumberOfPedestrians=0,
            # 8-14 are sunset; we want easy first
            WeatherId=random.choice(range(0, 11)),
            QualityLevel='Epic'
        )
        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(carla_config.render_width,
                               carla_config.render_height)
        # Set its position relative to the car in meters.
        camera0.set_position(0.30, 0, 1.30)
        settings.add_sensor(camera0)

    else:

        # Alternatively, we can load these settings from a file.
        with open(settings_file, 'r') as fp:
            settings = fp.read()

    return settings
Exemplo n.º 28
0
def make_carla_settings():
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(
        SynchronousMode=False,
        SendNonPlayerAgentsInfo=True,
        NumberOfVehicles=15,
        NumberOfPedestrians=30,
        WeatherId=random.choice([1, 3, 7, 8, 14]))
    settings.randomize_seeds()
    # camera0 = sensor.Camera('CameraRGB')
    # camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    # camera0.set_position(200, 0, 140)
    # camera0.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera0)
    # camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    # camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    # camera1.set_position(200, 0, 140)
    # camera1.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera1)
    # camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation')
    # camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    # camera2.set_position(200, 0, 140)
    # camera2.set_rotation(0.0, 0.0, 0.0)
    # settings.add_sensor(camera2)
    lidar0 = sensor.Lidar('Lidar32')
    lidar0.set_position(0, 0, 250)
    lidar0.set_rotation(0, 0, 0)
    lidar0.set(
        Channels = 32,
        Range = 5000,
        PointsPerSecond = 640000,
        RotationFrequency = 10,
        UpperFovLimit = 10,
        LowerFovLimit = -30,
        ShowDebugPoints = False)
    settings.add_sensor(lidar0)

    return settings
Exemplo n.º 29
0
def make_carla_settings(args, vehicle_tot):
    # Create a CarlaSettings object. This object is a wrapper around
    # the CarlaSettings.ini file. Here we set the configuration we
    # want for the new episode.
    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=vehicle_tot,
                 NumberOfPedestrians=0,
                 WeatherId=1,
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()

    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)

    px, py, pz = 2.0, 0.0, 1.4  # Default (Front)
    rx, ry, rz = 0.0, 0.0, 0.0

    if args.camera == "Driver":
        px = -0.3
        py = -0.5
        pz = 1.1
    elif args.camera == "Hood":
        px = 1.0
        py = 0.0
        pz = 1.4
    elif args.camera == "Top":
        px = -5.5
        py = 0.0
        pz = 3.0
        rx = -10.0

    camera0.set_position(px, py, pz)
    camera0.set_rotation(rx, ry, rz)
    settings.add_sensor(camera0)

    return settings
Exemplo n.º 30
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(
        SynchronousMode=True,
        SendNonPlayerAgentsInfo=False,
        NumberOfVehicles=30,
        NumberOfPedestrians=0,
        WeatherId=1,
        QualityLevel='Epic')
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(CAM_WINDOW_WIDTH, CAM_WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera1.set_position(2.0, 0.0, 1.4)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation')
    camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_position(2.0, 0.0, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)
    lidar = sensor.Lidar('Lidar32')
    lidar.set_position(0, 0, 2.5)
    lidar.set_rotation(0, 0, 0)
    lidar.set(
        Channels=0,
        Range=50,
        PointsPerSecond=100000,
        RotationFrequency=10,
        UpperFovLimit=0,
        LowerFovLimit=0)
    settings.add_sensor(lidar)
    return settings
Exemplo n.º 31
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=False,
                 SendNonPlayerAgentsInfo=True,
                 NumberOfVehicles=15,
                 NumberOfPedestrians=30,
                 WeatherId=random.choice([1, 3, 7, 8, 14]),
                 QualityLevel=args.quality_level)
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera0)

    #camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation')
    #camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    #camera2.set_position(2.0, 0.0, 1.4)
    #camera2.set_rotation(0.0, 0.0, 0.0)
    #settings.add_sensor(camera2)
    return settings
Exemplo n.º 32
0
def start_game(args):
    pygame.init()
    with make_carla_client(args.host, args.port) as client:
        settings = CarlaSettings()
        settings.set(
            SynchronousMode=False,
            SendNonPlayerAgentsInfo=True,
            NumberOfVehicles=3,
            NumberOfPedestrians=40,
            WeatherId=1,
            QualityLevel="Low")
        settings.randomize_seeds()

        scene = client.load_settings(settings)
        screen, img, dim, scale = setup_game_window(scene)
        town_map = CarlaMap(scene.map_name, 0.1653, 50)
        client.start_episode(7)

        while running:
            manage_events(pygame.event.get())
            screen.blit(img, (0, 0))
            play_frame(client, town_map, screen, dim, scale)
            pygame.display.flip()
Exemplo n.º 33
0
def make_carla_settings(args):
    """Make a CarlaSettings object with the settings we need."""
    settings = CarlaSettings()
    settings.set(SynchronousMode=True,
                 SendNonPlayerAgentsInfo=False,
                 NumberOfVehicles=30,
                 NumberOfPedestrians=0,
                 WeatherId=1,
                 QualityLevel='Epic')
    settings.randomize_seeds()
    camera0 = sensor.Camera('CameraRGB')
    camera0.set_image_size(CAM_WINDOW_WIDTH, CAM_WINDOW_HEIGHT)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0.0, 0.0)
    settings.add_sensor(camera0)
    camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth')
    camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera1.set_position(2.0, 0.0, 1.4)
    camera1.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera1)
    camera2 = sensor.Camera('CameraSemSeg',
                            PostProcessing='SemanticSegmentation')
    camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT)
    camera2.set_position(2.0, 0.0, 1.4)
    camera2.set_rotation(0.0, 0.0, 0.0)
    settings.add_sensor(camera2)
    lidar = sensor.Lidar('Lidar32')
    lidar.set_position(0, 0, 2.5)
    lidar.set_rotation(0, 0, 0)
    lidar.set(Channels=0,
              Range=50,
              PointsPerSecond=100000,
              RotationFrequency=10,
              UpperFovLimit=0,
              LowerFovLimit=0)
    settings.add_sensor(lidar)
    return settings
Exemplo n.º 34
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
Exemplo n.º 35
0
def run_carla_client(args):
    # 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(args.host, args.port) as client:
        print('CarlaClient connected')

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

            if args.settings_filepath is None:

                # Create a CarlaSettings object. This object is a wrapper around
                # the CarlaSettings.ini file. Here we set the configuration we
                # want for the new episode.
                settings = CarlaSettings()
                settings.set(
                    SynchronousMode=True,
                    SendNonPlayerAgentsInfo=True,
                    NumberOfVehicles=20,
                    NumberOfPedestrians=40,
                    WeatherId=random.choice([1, 3, 7, 8, 14]),
                    QualityLevel=args.quality_level)
                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 meters.
                camera0.set_position(0.30, 0, 1.30)
                settings.add_sensor(camera0)

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

                if args.lidar:
                    lidar = Lidar('Lidar32')
                    lidar.set_position(0, 0, 2.50)
                    lidar.set_rotation(0, 0, 0)
                    lidar.set(
                        Channels=32,
                        Range=50,
                        PointsPerSecond=100000,
                        RotationFrequency=10,
                        UpperFovLimit=10,
                        LowerFovLimit=-30)
                    settings.add_sensor(lidar)

            else:

                # Alternatively, we can load these settings from a file.
                with open(args.settings_filepath, 'r') as fp:
                    settings = fp.read()

            # Now we load these settings into the server. The server replies
            # with a scene description containing the available start spots for
            # the player. Here we can provide a CarlaSettings object or a
            # CarlaSettings.ini file as string.
            scene = client.load_settings(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 the
            # player_start index. This function blocks until the server is ready
            # to start the episode.
            print('Starting new episode at %r...' % scene.map_name)
            client.start_episode(player_start)

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

                # Read the data produced by the server this frame.
                measurements, sensor_data = client.read_data()

                # Print some of the measurements.
                print_measurements(measurements)

                # Save the images to disk if requested.
                if args.save_images_to_disk:
                    for name, measurement in sensor_data.items():
                        filename = args.out_filename_format.format(episode, name, frame)
                        measurement.save_to_disk(filename)

                # We can access the encoded data of a given image as numpy
                # array using its "data" property. For instance, to get the
                # depth value (normalized) at pixel X, Y
                #
                #     depth_array = sensor_data['CameraDepth'].data
                #     value_at_pixel = depth_array[Y, X]
                #

                # 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 args.autopilot:

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

                else:

                    # Together with the measurements, the server has sent the
                    # control that the in-game autopilot would do this frame. We
                    # can enable autopilot by sending back this control to the
                    # server. We can modify it if wanted, here for instance we
                    # will add some noise to the steer.

                    control = measurements.player_measurements.autopilot_control
                    control.steer += random.uniform(-0.1, 0.1)
                    client.send_control(control)
Exemplo n.º 36
0
def run_carla_client(host, port, far):
    # Here we will run a single episode with 300 frames.
    number_of_frames = 3000
    frame_step = 100  # Save one image every 100 frames
    output_folder = '_out'
    image_size = [800, 600]
    camera_local_pos = [0.3, 0.0, 1.3] # [X, Y, Z]
    camera_local_rotation = [0, 0, 0]  # [pitch(Y), yaw(Z), roll(X)]
    fov = 70

    # Connect with the server
    with make_carla_client(host, port) as client:
        print('CarlaClient connected')

        # Here we load the settings.
        settings = CarlaSettings()
        settings.set(
            SynchronousMode=True,
            SendNonPlayerAgentsInfo=False,
            NumberOfVehicles=20,
            NumberOfPedestrians=40,
            WeatherId=random.choice([1, 3, 7, 8, 14]))
        settings.randomize_seeds()

        camera1 = Camera('CameraDepth', PostProcessing='Depth', FOV=fov)
        camera1.set_image_size(*image_size)
        camera1.set_position(*camera_local_pos)
        camera1.set_rotation(*camera_local_rotation)
        settings.add_sensor(camera1)

        camera2 = Camera('CameraRGB', PostProcessing='SceneFinal', FOV=fov)
        camera2.set_image_size(*image_size)
        camera2.set_position(*camera_local_pos)
        camera2.set_rotation(*camera_local_rotation)
        settings.add_sensor(camera2)

        client.load_settings(settings)

        # Start at location index id '0'
        client.start_episode(0)

        # Compute the camera transform matrix
        camera_to_car_transform = camera2.get_unreal_transform()

        # Iterate every frame in the episode except for the first one.
        for frame in range(1, number_of_frames):
            # Read the data produced by the server this frame.
            measurements, sensor_data = client.read_data()

            # Save one image every 'frame_step' frames
            if not frame % frame_step:
                # Start transformations time mesure.
                timer = StopWatch()

                # RGB image [[[r,g,b],..[r,g,b]],..[[r,g,b],..[r,g,b]]]
                image_RGB = to_rgb_array(sensor_data['CameraRGB'])

                # 2d to (camera) local 3d
                # We use the image_RGB to colorize each 3D point, this is optional.
                # "max_depth" is used to keep only the points that are near to the
                # camera, meaning 1.0 the farest points (sky)
                point_cloud = depth_to_local_point_cloud(
                    sensor_data['CameraDepth'],
                    image_RGB,
                    max_depth=far
                )

                # (Camera) local 3d to world 3d.
                # Get the transform from the player protobuf transformation.
                world_transform = Transform(
                    measurements.player_measurements.transform
                )

                # Compute the final transformation matrix.
                car_to_world_transform = world_transform * camera_to_car_transform

                # Car to World transformation given the 3D points and the
                # transformation matrix.
                point_cloud.apply_transform(car_to_world_transform)

                # End transformations time mesure.
                timer.stop()

                # Save PLY to disk
                # This generates the PLY string with the 3D points and the RGB colors
                # for each row of the file.
                point_cloud.save_to_disk(os.path.join(
                    output_folder, '{:0>5}.ply'.format(frame))
                )

                print_message(timer.milliseconds(), len(point_cloud), frame)

            client.send_control(
                measurements.player_measurements.autopilot_control
            )
Exemplo n.º 37
0
def run_carla_client(args):
    # Here we will run 3 episodes with 300 frames each.
    number_of_episodes = 5
    cut_per_episode = 40
    frames_per_cut = 200


    # 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(args.host, args.port) as client:
        print('CarlaClient connected')
        for episode in range(0, number_of_episodes):
            print("input any key to continue...")
            start = input()
            # each episode dir store a set of traindata.  if dir not existed, then make it
            pathdir = '/home/kadn/dataTrain/episode_{:0>3}'.format(episode)
            mkdir(pathdir)

            # Create a CarlaSettings object. This object is a wrapper around
            # the CarlaSettings.ini file. Here we set the configuration we
            # want for the new episode.
            settings = CarlaSettings()
            settings.set(
                SynchronousMode=True,
                SendNonPlayerAgentsInfo=True,
                NumberOfVehicles=20,
                NumberOfPedestrians=40,
                # WeatherId=random.choice([1, 3, 7, 8, 14]),
                WeatherId = 1,
                QualityLevel=args.quality_level)
            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(88, 200)
            # Set its position relative to the car in meters.
            camera0.set_position(0.30, 0, 1.30)
            settings.add_sensor(camera0)

            # Let's add another camera producing ground-truth depth.
            camera1 = Camera('CameraDepth', PostProcessing='Depth')
            camera1.set_image_size(200, 88)
            camera1.set_position(0.30, 0, 1.30)
            settings.add_sensor(camera1)

            camera2 = Camera('CameraSemSeg', PostProcessing='SemanticSegmentation')
            camera2.set_image_size(88, 200)
            camera2.set_position(2.0, 0.0, 1.4)
            camera2.set_rotation(0.0, 0.0, 0.0)
            settings.add_sensor(camera2)
            # if args.lidar:
            lidar = Lidar('Lidar32')
            lidar.set_position(0, 0, 2.50)
            lidar.set_rotation(0, 0, 0)
            lidar.set(
                Channels=0,
                Range=30,
                PointsPerSecond=200000,
                RotationFrequency=10,
                UpperFovLimit=0,
                LowerFovLimit=0)
            settings.add_sensor(lidar)

            # else:
            #
            #     # Alternatively, we can load these settings from a file.
            #     with open(args.settings_filepath, 'r') as fp:
            #         settings = fp.read()

            # Now we load these settings into the server. The server replies
            # with a scene description containing the available start spots for
            # the player. Here we can provide a CarlaSettings object or a
            # CarlaSettings.ini file as string.
            scene = client.load_settings(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))
            player_start = 1

            # Notify the server that we want to start the episode at the
            # player_start index. This function blocks until the server is ready
            # to start the episode.
            print('Starting new episode at %r...' % scene.map_name)
            # Start a new episode.
            client.start_episode(player_start)

            for cut_per_episode in range(0,cut_per_episode):
                num = fileCounter(pathdir)
                filename = "data_{:0>6}.h5".format(num)
                filepath = pathdir + '/' + filename
                f = h5py.File(filepath, "w")
                rgb_file = f.create_dataset("rgb", (200, 88, 200), np.uint8)
                seg_file = f.create_dataset("seg", (200, 88, 200), np.uint8)
                lidar_file = f.create_dataset('lidar',(200,200,200),np.uint8)
                startendpoint = f.create_dataset('startend',(1,2),np.float32)
                targets_file = f.create_dataset("targets", (200, 28), np.float32)
                index_file = 0

                # Iterate every frame in the episode.
                for frame in range(0, frames_per_cut):
                    # Read the data produced by the server this frame.
                    measurements, sensor_data = client.read_data()

                    # get data and store
                    sensors, targets_data = record_train_data(measurements,sensor_data)
                    rgb_file[:,:,index_file] = sensors['rgb']
                    seg_file[:,:,index_file] = sensors['seg']
                    lidar_file[:,:,index_file] = sensors['lidar']
                    targets_file[index_file,:] = targets_data
                    index_file += 1

                    # We can access the encoded data of a given image as numpy
                    # array using its "data" property. For instance, to get the
                    # depth value (normalized) at pixel X, Y
                    #
                    #     depth_array = sensor_data['CameraDepth'].data
                    #     value_at_pixel = depth_array[Y, X]
                    #

                    # 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  args.autopilot:

                        client.send_control(
                            steer=0,
                            throttle=0.8,
                            brake=0.0,
                            hand_brake=False,
                            reverse=False)

                    else:

                        # Together with the measurements, the server has sent the
                        # control that the in-game autopilot would do this frame. We
                        # can enable autopilot by sending back this control to the
                        # server. We can modify it if wanted, here for instance we
                        # will add some noise to the steer.

                        control = measurements.player_measurements.autopilot_control
                        control.steer += random.uniform(-0.05, 0.05)
                        client.send_control(control)
Exemplo n.º 38
0
def run_carla_clients(args):
    filename = '_images_repeatability/server{:d}/{:0>6d}.png'
    with make_carla_client(args.host1, args.port1) as client1:
        logging.info('1st client connected')
        with make_carla_client(args.host2, args.port2) as client2:
            logging.info('2nd client connected')

            settings = CarlaSettings()
            settings.set(
                SynchronousMode=True,
                SendNonPlayerAgentsInfo=True,
                NumberOfVehicles=50,
                NumberOfPedestrians=50,
                WeatherId=random.choice([1, 3, 7, 8, 14]))
            settings.randomize_seeds()

            if args.images_to_disk:
                camera = Camera('DefaultCamera')
                camera.set_image_size(800, 600)
                settings.add_sensor(camera)

            scene1 = client1.load_settings(settings)
            scene2 = client2.load_settings(settings)

            number_of_player_starts = len(scene1.player_start_spots)
            assert number_of_player_starts == len(scene2.player_start_spots)
            player_start = random.randint(0, max(0, number_of_player_starts - 1))
            logging.info(
                'start episode at %d/%d player start (run forever, press ctrl+c to cancel)',
                player_start,
                number_of_player_starts)

            client1.start_episode(player_start)
            client2.start_episode(player_start)

            frame = 0
            while True:
                frame += 1

                meas1, sensor_data1 = client1.read_data()
                meas2, sensor_data2 = client2.read_data()

                player1 = meas1.player_measurements
                player2 = meas2.player_measurements

                images1 = [x for x in sensor_data1.values() if isinstance(x, Image)]
                images2 = [x for x in sensor_data2.values() if isinstance(x, Image)]

                control1 = player1.autopilot_control
                control2 = player2.autopilot_control

                try:
                    assert len(images1) == len(images2)
                    assert len(meas1.non_player_agents) == len(meas2.non_player_agents)
                    assert player1.transform.location.x == player2.transform.location.x
                    assert player1.transform.location.y == player2.transform.location.y
                    assert player1.transform.location.z == player2.transform.location.z
                    assert control1.steer == control2.steer
                    assert control1.throttle == control2.throttle
                    assert control1.brake == control2.brake
                    assert control1.hand_brake == control2.hand_brake
                    assert control1.reverse == control2.reverse
                except AssertionError:
                    logging.exception('assertion failed')

                if args.images_to_disk:
                    assert len(images1) == 1
                    images1[0].save_to_disk(filename.format(1, frame))
                    images2[0].save_to_disk(filename.format(2, frame))

                client1.send_control(control1)
                client2.send_control(control2)