コード例 #1
0
def log_stop_signs(world):
    world_map = world.get_map()
    (_, traffic_lights, traffic_stops, speed_signs) = get_actors(world)
    transforms_of_interest = []
    # Add transforms that are close to stop signs.
    for stop_sign in traffic_stops:
        for offset in range(10, 25, 5):
            offset_loc = pylot.simulation.utils.Location(x=-offset, y=0, z=0)
            offset_rot = pylot.simulation.utils.Rotation(
                pitch=0, yaw=0, roll=0)
            offset_trans = pylot.simulation.utils.Transform(
                offset_loc, offset_rot)
            transform = stop_sign.transform * offset_trans
            location = to_carla_location(transform.location)
            w = world_map.get_waypoint(
                location,
                project_to_road=True,
                lane_type=carla.LaneType.Driving)
            camera_transform = to_pylot_transform(w.transform)
            camera_transform.location.z += 2.0
            transform = to_carla_transform(camera_transform)
            transforms_of_interest.append(transform)
    # Ensure all traffic lights are red.
    change_traffic_light_colors(world, carla.TrafficLightState.Red)
    world.tick()
    time.sleep(3)
    (_, traffic_lights, traffic_stops, speed_signs) = get_actors(world)
    log_obstacles(world,
                  transforms_of_interest,
                  traffic_lights,
                  carla.TrafficLightState.Red,
                  speed_signs,
                  traffic_stops)
コード例 #2
0
ファイル: sign_data_gatherer.py プロジェクト: Rmao99/pylot
def log_speed_limits(world):
    world_map = world.get_map()
    (_, traffic_lights, traffic_stops, speed_signs) = get_actors(world)
    transforms_of_interest = []
    # Add transforms that are close to speed limit signs.
    for speed_sign in speed_signs:
        for offset in range(10, 25, 5):
            # Speed signs have different coordinate systems, hence
            # we need to offset y, instead of x.
            offset_loc = pylot.simulation.utils.Location(x=0, y=offset, z=0)
            offset_rot = pylot.simulation.utils.Rotation(pitch=0,
                                                         yaw=0,
                                                         roll=0)
            offset_trans = pylot.simulation.utils.Transform(
                offset_loc, offset_rot)
            transform = speed_sign.transform * offset_trans
            location = to_carla_location(transform.location)
            w = world_map.get_waypoint(location,
                                       project_to_road=True,
                                       lane_type=carla.LaneType.Driving)
            camera_transform = to_pylot_transform(w.transform)
            camera_transform.location.z += 2.0
            transform = to_carla_transform(camera_transform)
            transforms_of_interest.append(transform)
    # Ensure all traffic lights are red.
    change_traffic_light_colors(world, carla.TrafficLightState.Red)
    world.tick()
    time.sleep(1)
    (_, traffic_lights, traffic_stops, speed_signs) = get_actors(world)
    for weather in find_weather_presets():
        change_weather(world, weather)
        log_obstacles(world, transforms_of_interest, traffic_lights,
                      carla.TrafficLightState.Red, speed_signs, traffic_stops,
                      weather, world_map.name)
コード例 #3
0
    def on_vehicle_id(self, msg):
        """ This function receives the identifier for the vehicle, retrieves
        the handler for the vehicle from the simulation and attaches the
        camera to it.

        Args:
            msg: The identifier for the vehicle to attach the camera to.
        """
        vehicle_id = msg.data
        self._logger.info(
            "The CameraDriverOperator received the vehicle id: {}".format(
                vehicle_id))

        # Connect to the world. We connect here instead of in the constructor
        # to ensure we're connected to the latest world.
        _, world = get_world(self._flags.carla_host, self._flags.carla_port,
                             self._flags.carla_timeout)
        if world is None:
            raise ValueError("There was an issue connecting to the simulator.")
        if self._flags.carla_synchronous_mode:
            set_synchronous_mode(world, self._flags.carla_fps)

        num_tries = 0
        while self._vehicle is None and num_tries < 30:
            self._vehicle = world.get_actors().find(vehicle_id)
            self._logger.info(
                "Could not find vehicle. Try {}".format(num_tries))
            time.sleep(1)
            num_tries += 1
        if self._vehicle is None:
            raise ValueError("There was an issue finding the vehicle.")

        # Install the camera.
        camera_blueprint = world.get_blueprint_library().find(
            self._camera_setup.camera_type)

        camera_blueprint.set_attribute('image_size_x',
                                       str(self._camera_setup.width))
        camera_blueprint.set_attribute('image_size_y',
                                       str(self._camera_setup.height))
        camera_blueprint.set_attribute('fov', str(self._camera_setup.fov))

        transform = to_carla_transform(self._camera_setup.get_transform())

        self._logger.info("Spawning a camera: {}".format(self._camera_setup))

        self._camera = world.spawn_actor(camera_blueprint,
                                         transform,
                                         attach_to=self._vehicle)

        # Register the callback on the camera.
        self._camera.listen(self.process_images)
コード例 #4
0
    def on_vehicle_id(self, msg):
        """ This function receives the identifier for the vehicle, retrieves
        the handler for the vehicle from the simulation and attaches the
        camera to it.

        Args:
            msg: The identifier for the vehicle to attach the camera to.
        """
        vehicle_id = msg.data
        self._logger.info(
            "The LidarDriverOperator received the vehicle id: {}".format(
                vehicle_id))

        self._vehicle = self._world.get_actors().find(vehicle_id)
        if self._vehicle is None:
            raise ValueError("There was an issue finding the vehicle.")

        # Install the Lidar.
        lidar_blueprint = self._world.get_blueprint_library().find(
            self._lidar_setup.lidar_type)

        lidar_blueprint.set_attribute('channels',
                                      str(self._lidar_setup.channels))
        lidar_blueprint.set_attribute('range', str(self._lidar_setup.range))
        lidar_blueprint.set_attribute('points_per_second',
                                      str(self._lidar_setup.points_per_second))
        lidar_blueprint.set_attribute(
            'rotation_frequency', str(self._lidar_setup.rotation_frequency))
        lidar_blueprint.set_attribute('upper_fov',
                                      str(self._lidar_setup.upper_fov))
        lidar_blueprint.set_attribute('lower_fov',
                                      str(self._lidar_setup.lower_fov))
        # XXX(ionel): Set sensor tick.
        # lidar_blueprint.set_attribute('sensor_tick')

        transform = to_carla_transform(self._lidar_setup.get_transform())

        self._logger.info("Spawning a lidar: {}".format(self._lidar_setup))

        self._lidar = self._world.spawn_actor(lidar_blueprint,
                                              transform,
                                              attach_to=self._vehicle)
        # Register the callback on the Lidar.
        self._lidar.listen(self.process_point_clouds)
コード例 #5
0
    def on_vehicle_id(self, msg):
        """ This function receives the identifier for the vehicle, retrieves
        the handler for the vehicle from the simulation and attaches the
        camera to it.

        Args:
            msg: The identifier for the vehicle to attach the camera to.
        """
        vehicle_id = msg.data
        self._logger.info(
            "The CameraDriverOperator received the vehicle id: {}".format(
                vehicle_id))

        self._vehicle = self._world.get_actors().find(vehicle_id)
        if self._vehicle is None:
            raise ValueError("There was an issue finding the vehicle.")

        # Install the camera.
        camera_blueprint = self._world.get_blueprint_library().find(
            self._camera_setup.camera_type)

        camera_blueprint.set_attribute('image_size_x',
                                       str(self._camera_setup.width))
        camera_blueprint.set_attribute('image_size_y',
                                       str(self._camera_setup.height))

        transform = to_carla_transform(self._camera_setup.get_transform())

        self._logger.info("Spawning a camera: {}".format(self._camera_setup))

        self._camera = self._world.spawn_actor(camera_blueprint,
                                               transform,
                                               attach_to=self._vehicle)

        # Register the callback on the camera.
        self._camera.listen(self.process_images)
コード例 #6
0
def log_traffic_lights(world):
    world_map = world.get_map()
    (traffic_lights, _, traffic_stops, speed_signs) = get_actors(world)
    tl_colors = [
        carla.TrafficLightState.Yellow, carla.TrafficLightState.Green,
        carla.TrafficLightState.Red
    ]
    for light in traffic_lights:
        print("Working for traffic light {}".format(light.id))
        # For every traffic light, get the neighbouring lights except the one
        # directly opposite.
        group_lights = []
        for n_light in light.get_group_traffic_lights():
            if not check_lights_opposite(light, n_light):
                group_lights.append(convert_to_pylot_traffic_light(n_light))

        transforms_of_interest = []
        for offset in range(10, 40, 5):
            # Traffic lights have different coordinate systems, hence
            # we need to offset y, instead of x and add that to the trigger
            # volume location.
            offset_loc = pylot.simulation.utils.Location(
                x=light.trigger_volume.location.x,
                y=light.trigger_volume.location.y + offset,
                z=light.trigger_volume.location.z)
            offset_rot = pylot.simulation.utils.Rotation(pitch=0,
                                                         yaw=0,
                                                         roll=0)
            offset_trans = pylot.simulation.utils.Transform(
                offset_loc, offset_rot)

            # Transform the offset relative to the traffic light.
            transform = to_pylot_transform(
                light.get_transform()) * offset_trans
            location = to_carla_location(transform.location)

            # Get the waypoint nearest to the transform.
            w = world_map.get_waypoint(location,
                                       project_to_road=True,
                                       lane_type=carla.LaneType.Driving)
            w_rotation = w.transform.rotation
            camera_transform = to_pylot_transform(w.transform)
            camera_transform.location.z += 2.0
            transform = to_carla_transform(camera_transform)
            transforms_of_interest.append(transform)

            # Get the right lanes.
            wp_right = w.get_right_lane()
            while wp_right and wp_right.lane_type == carla.LaneType.Driving \
                    and w_rotation == wp_right.transform.rotation:
                camera_transform = to_pylot_transform(wp_right.transform)
                camera_transform.location.z += 2.0
                transform = to_carla_transform(camera_transform)
                transforms_of_interest.append(transform)
                wp_right = wp_right.get_right_lane()

            # Get the left lanes.
            wp_left = w.get_left_lane()
            while wp_left and wp_left.lane_type == carla.LaneType.Driving and \
                    w_rotation == wp_left.transform.rotation:
                camera_transform = to_pylot_transform(wp_left.transform)
                camera_transform.location.z += 2.0
                transform = to_carla_transform(camera_transform)
                transforms_of_interest.append(transform)
                wp_left = wp_left.get_left_lane()

        print("The total number of transforms were: {}".format(
            len(transforms_of_interest)))
        for tl_color in tl_colors:
            change_traffic_light_colors(world, tl_color)
            world.tick()
            time.sleep(3)
            log_obstacles(world, transforms_of_interest, group_lights,
                          tl_color, speed_signs, traffic_stops)
コード例 #7
0
    def on_vehicle_id(self, msg):
        """ This function receives the identifier for the vehicle, retrieves
        the handler for the vehicle from the simulation and attaches the
        camera to it.

        Args:
            msg: The identifier for the vehicle to attach the camera to.
        """
        vehicle_id = msg.data
        self._logger.info(
            "The LidarDriverOperator received the vehicle id: {}".format(
                vehicle_id))

        # Connect to the world. We connect here instead of in the constructor
        # to ensure we're connected to the latest world.
        _, world = get_world(self._flags.carla_host,
                             self._flags.carla_port,
                             self._flags.carla_timeout)
        if world is None:
            raise ValueError("There was an issue connecting to the simulator.")
        if self._flags.carla_synchronous_mode:
            set_synchronous_mode(world, self._flags.carla_fps)

        num_tries = 0
        while self._vehicle is None and num_tries < 30:
            self._vehicle = world.get_actors().find(vehicle_id)
            self._logger.info("Could not find vehicle. Try {}".format(num_tries))
            time.sleep(1)
            num_tries += 1
        if self._vehicle is None:
            raise ValueError("There was an issue finding the vehicle.")

        # Install the Lidar.
        lidar_blueprint = world.get_blueprint_library().find(
            self._lidar_setup.lidar_type)

        lidar_blueprint.set_attribute('channels',
                                      str(self._lidar_setup.channels))
        lidar_blueprint.set_attribute('range',
                                      str(self._lidar_setup.range))
        lidar_blueprint.set_attribute('points_per_second',
                                      str(self._lidar_setup.points_per_second))
        lidar_blueprint.set_attribute(
            'rotation_frequency',
            str(self._lidar_setup.rotation_frequency))
        lidar_blueprint.set_attribute('upper_fov',
                                      str(self._lidar_setup.upper_fov))
        lidar_blueprint.set_attribute('lower_fov',
                                      str(self._lidar_setup.lower_fov))
        # XXX(ionel): Set sensor tick.
        # lidar_blueprint.set_attribute('sensor_tick')

        transform = to_carla_transform(self._lidar_setup.get_transform())

        self._logger.info("Spawning a lidar: {}".format(self._lidar_setup))

        self._lidar = world.spawn_actor(lidar_blueprint,
                                        transform,
                                        attach_to=self._vehicle)
        # Register the callback on the Lidar.
        self._lidar.listen(self.process_point_clouds)