Beispiel #1
0
def draw_routes(world, routes_file, output_folder):

    if not os.path.exists(output_folder):
        os.mkdir(output_folder)

    routes_descriptions = parse_routes_file('database/' + routes_file)

    for route in routes_descriptions:
        fig = plt.figure()
        plt.xlim(-200, 5500)
        plt.ylim(-200, 5500)

        draw_map(world)

        _, route_interpolated = interpolate_trajectory(world, route['trajectory'])
        draw_route(route_interpolated)

        fig.savefig(os.path.join(output_folder,
                                 'route_' + str(route['id']) + '_.png'),
                    orientation='landscape', bbox_inches='tight', dpi=1200)
Beispiel #2
0
def get_scenario_list(world, scenarios_json_path, routes_path, routes_id):

    world_annotations = parse_annotations_file(scenarios_json_path)

    route_descriptions_list = parse_routes_file(routes_path)

    per_route_possible_scenarios = []
    for id in routes_id:
        route = route_descriptions_list[id]

        _, route_interpolated = interpolate_trajectory(world,
                                                       route['trajectory'])

        position_less_10_percent = int(0.1 * len(route_interpolated))
        possible_scenarios, existent_triggers = scan_route_for_scenarios(
            route_interpolated[:-position_less_10_percent], world_annotations,
            world.get_map().name)
        #if not possible_scenarios:
        #    continue
        per_route_possible_scenarios.append(possible_scenarios)

    return route_descriptions_list, per_route_possible_scenarios
Beispiel #3
0
def scenario_route_generator(routes_file, scenarios_tag, scenario_name,
                             number_of_routes):
    """
    returns exp dictionaries containing a single scenario happening on that route.
    :param routes_file:
    :param scenarios_tag:
    :param scenario_number: The name of the scenario that is going to be used.
    :param number_of_routes:
    :return:
    """

    # TODO I need to know the route points related to the scenario ...
    # retrieve worlds annotations
    world_annotations = parser.parse_annotations_file(scenarios_tag)
    # retrieve routes
    route_descriptions_list = parser.parse_routes_file(routes_file)

    # Connect to some carla here.
    env_vec = []
    count = 0
    client = carla.Client('localhost', 2000)

    client.set_timeout(32)

    for _route_description in route_descriptions_list:

        original_trajectory = _route_description['trajectory']

        world = client.load_world(_route_description['town_name'])
        _, _route_description['trajectory'] = interpolate_trajectory(
            world, _route_description['trajectory'])

        potential_scenarios_definitions, _ = parser.scan_route_for_scenarios(
            _route_description, world_annotations)
        # remove the trigger positon clustering  since we are only doing one scenario per time.
        # TODO add multi scenario route posibilities
        scenario_definitions = []
        for trigger in potential_scenarios_definitions:
            scenario_definitions += potential_scenarios_definitions[trigger]

        # filter only the scenario that you want to generate the routes.
        # (Doing more than one would be quicker but i preffer this organization for now)
        filtered_scenario_definitions = []
        for pot_scenario in scenario_definitions:
            if pot_scenario['name'] == scenario_name:
                filtered_scenario_definitions.append(pot_scenario)

        print(" The representations")
        print(original_trajectory, filtered_scenario_definitions)

        # Now we get the correspondent route points for the trigger
        for sce_def in filtered_scenario_definitions:

            route = find_closest_route_trip(sce_def['trigger_position'],
                                            original_trajectory)
            env_vec.append({
                scenario_name + '_' + 'route_' + str(count): {
                    'route': route,
                    'scenarios': {
                        scenario_name: sce_def['trigger_position']
                    },
                    'town_name': _route_description['town_name'],
                    'vehicle_model': "vehicle.lincoln.mkz2017"
                }
            })
            count += 1

    return env_vec[0:number_of_routes]
Beispiel #4
0
def generate_json_with_scenarios(world, routes_path, number_per_route,
                                 output_json_name, routes_id,
                                 number_of_vehicles):
    """

    :param world:
    :param scenarios_json_path:
    :param routes_path:
    :param wanted_scenarios:
    :param output_json_name:
    :param number_of_routes: the number of routes used on the generation
    :return:
    """

    route_descriptions_list = parse_routes_file('database/' + routes_path)

    print("###################")

    weather_sets = {
        'training': ["ClearNoon", "WetNoon", "HardRainNoon", "ClearSunset"]
    }
    new_json = {
        "envs": {},
        "package_name": output_json_name.split('/')[-1].split('.')[0],
    }

    for w_set_name in weather_sets.keys():
        # get the actual set  from th name
        w_set = weather_sets[w_set_name]

        for weather in w_set:

            for id in range(len(routes_id)):  # TODO change this to routes id
                # get the possible scenario for a given ID
                specific_scenarios_for_route = get_scenario_3(
                    world, route_descriptions_list[routes_id[id]],
                    number_per_route)

                scenarios_all = {
                    'background_activity': {
                        "vehicle.*": number_of_vehicles,
                        "walker.*": 0
                    },
                }

                scenarios_all.update(
                    {'Scenario3': specific_scenarios_for_route})

                env_dict = {
                    "route": {
                        "file": routes_path,
                        "id": routes_id[id]
                    },
                    "scenarios": scenarios_all,
                    "town_name": "Town01",
                    "vehicle_model": "vehicle.lincoln.mkz2017",
                    "weather_profile": weather
                }

                new_json["envs"].update(
                    {weather + '_route' + str(id).zfill(5): env_dict})

    filename = output_json_name

    print(new_json)
    with open(filename, 'w') as fo:
        fo.write(json.dumps(new_json, sort_keys=True, indent=4))