Exemplo n.º 1
0
def get_actors(world):
    actor_list = world.get_actors()
    tl_actors = actor_list.filter('traffic.traffic_light*')
    traffic_lights = [
        TrafficLight.from_carla_actor(tl_actor) for tl_actor in tl_actors
    ]
    traffic_stop_actors = actor_list.filter('traffic.stop')
    traffic_stops = [
        StopSign.from_carla_actor(ts_actor) for ts_actor in traffic_stop_actors
    ]
    speed_limit_actors = actor_list.filter('traffic.speed_limit*')
    speed_signs = [
        SpeedLimitSign.from_carla_actor(ts_actor)
        for ts_actor in speed_limit_actors
    ]
    return (tl_actors, traffic_lights, traffic_stops, speed_signs)
Exemplo n.º 2
0
def extract_data_in_pylot_format(actor_list):
    """Extracts actor information in pylot format from an actor list.

    Args:
        actor_list (carla.ActorList): An actor list object with all the
            simulation actors.

    Returns:
        A tuple that contains objects for all different types of actors.
    """
    # Note: the output will include the ego vehicle as well.
    vec_actors = actor_list.filter('vehicle.*')
    vehicles = [
        Obstacle.from_carla_actor(vec_actor) for vec_actor in vec_actors
    ]

    person_actors = actor_list.filter('walker.pedestrian.*')
    people = [
        Obstacle.from_carla_actor(ped_actor) for ped_actor in person_actors
    ]

    tl_actors = actor_list.filter('traffic.traffic_light*')
    traffic_lights = [
        TrafficLight.from_carla_actor(tl_actor) for tl_actor in tl_actors
    ]

    speed_limit_actors = actor_list.filter('traffic.speed_limit*')
    speed_limits = [
        SpeedLimitSign.from_carla_actor(ts_actor)
        for ts_actor in speed_limit_actors
    ]

    traffic_stop_actors = actor_list.filter('traffic.stop')
    traffic_stops = [
        StopSign.from_carla_actor(ts_actor) for ts_actor in traffic_stop_actors
    ]

    return (vehicles, people, traffic_lights, speed_limits, traffic_stops)
Exemplo n.º 3
0
def log_traffic_lights(world):
    world_map = world.get_map()
    (traffic_lights, _, _, _) = get_actors(world)
    tl_colors = [
        carla.TrafficLightState.Yellow, carla.TrafficLightState.Green,
        carla.TrafficLightState.Red
    ]
    transforms_of_interest = []
    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.
        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.utils.Location(
                x=light.trigger_volume.location.x,
                y=light.trigger_volume.location.y + offset,
                z=light.trigger_volume.location.z)
            offset_trans = pylot.utils.Transform(offset_loc,
                                                 pylot.utils.Rotation())

            # Transform the offset relative to the traffic light.
            transform = pylot.utils.Transform.from_carla_transform(
                light.get_transform()) * offset_trans
            location = transform.location.as_carla_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 = pylot.utils.Transform.from_carla_transform(
                w.transform)
            camera_transform.location.z += 2.0
            transform = camera_transform.as_carla_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 = pylot.utils.Transform.from_carla_transform(
                    wp_right.transform)
                camera_transform.location.z += 2.0
                transform = camera_transform.as_carla_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 = pylot.utils.Transform.from_carla_transform(
                    wp_left.transform)
                camera_transform.location.z += 2.0
                transform = camera_transform.as_carla_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)))

    traffic_lights = [
        TrafficLight.from_carla_actor(light) for light in traffic_lights
    ]
    for weather in find_weather_presets():
        change_weather(world, weather)
        time.sleep(1)
        for tl_color in tl_colors:
            change_traffic_light_colors(world, tl_color)
            world.tick()
            time.sleep(1)
            log_obstacles(world, transforms_of_interest, traffic_lights,
                          tl_color, None, None, weather, world_map.name)