def test_route_parser(self):

        args = Arguments()
        client = carla.Client(args.host, int(args.port))
        client.set_timeout(25.0)
        challenge = ChallengeEvaluator(args)

        filename = os.path.join(self.root_route_file_position,
                                'all_towns_traffic_scenarios.json')
        world_annotations = parser.parse_annotations_file(filename)
        # retrieve routes
        # Which type of file is expected ????

        filename = os.path.join(self.root_route_file_position,
                                'routes_training.xml')
        list_route_descriptions = parser.parse_routes_file(filename)

        # For each of the routes to be evaluated.
        for route_description in list_route_descriptions:
            if route_description['town_name'] == 'Town03' or route_description[
                    'town_name'] == 'Town01':
                continue
            print(" TOWN: ", route_description['town_name'])
            challenge.world = client.load_world(route_description['town_name'])
            # Set the actor pool so the scenarios can prepare themselves when needed
            CarlaActorPool.set_world(challenge.world)

            CarlaDataProvider.set_world(challenge.world)
            # find and filter potential scenarios
            # Returns the interpolation in a different format

            challenge.world.wait_for_tick()

            gps_route, route_description[
                'trajectory'] = interpolate_trajectory(
                    challenge.world, route_description['trajectory'])

            potential_scenarios_definitions, existent_triggers = parser.scan_route_for_scenarios(
                route_description, world_annotations)

            for trigger_id, possible_scenarios in potential_scenarios_definitions.items(
            ):

                print("  For trigger ", trigger_id, " --  ",
                      possible_scenarios[0]['trigger_position'])
                for scenario in possible_scenarios:
                    print("      ", scenario['name'])

            challenge.cleanup(ego=True)
    def test_possible_spawns(self):

        args = Arguments()
        client = carla.Client(args.host, int(args.port))
        client.set_timeout(25.0)
        challenge = ChallengeEvaluator(args)

        filename = os.path.join(self.root_route_file_position,
                                'routes_training.xml')
        list_route_descriptions = parser.parse_routes_file(filename)

        # Which type of file is expected ????

        # For each of the routes to be evaluated.
        for route_description in list_route_descriptions:
            challenge.world = client.load_world(route_description['town_name'])

            # Set the actor pool so the scenarios can prepare themselves when needed
            CarlaActorPool.set_world(challenge.world)

            CarlaDataProvider.set_world(challenge.world)
            # find and filter potential scenarios
            # Returns the iterpolation in a different format

            challenge.world.wait_for_tick()

            gps_route, route_description[
                'trajectory'] = interpolate_trajectory(
                    challenge.world, route_description['trajectory'])

            #print (gps_route)
            #print (route_description['trajectory'])

            elevate_transform = route_description['trajectory'][0][0].transform
            elevate_transform.location.z += 0.5
            #print (elevate_transform)
            challenge.prepare_ego_car(elevate_transform)

            challenge.cleanup(ego=True)
def test_routes(args):
    """
    Run all routes according to provided commandline args
    """
    # instance a challenge
    challenge = ChallengeEvaluator(args)

    # retrieve worlds annotations
    world_annotations = parser.parse_annotations_file(args.scenarios)
    # retrieve routes

    routes = []
    route_descriptions_list = parser.parse_routes_file(args.routes)
    for route_description in route_descriptions_list:
        if route_description['town_name'] == args.debug_town:
            routes.append(route_description)
    # find and filter potential scenarios for each of the evaluated routes
    # For each of the routes and corresponding possible scenarios to be evaluated.
    list_scenarios_town = []
    if args.debug_town in world_annotations.keys():
        list_scenarios_town = world_annotations[args.debug_town]

    scenarios_current_type = []
    for scenario in list_scenarios_town:
        if args.debug_scenario == scenario['scenario_type']:
            scenarios_current_type = scenario
            break

    for scenario_configuration in scenarios_current_type[
            'available_event_configurations']:
        scenario_conf = create_configuration_scenario(scenario_configuration,
                                                      args.debug_scenario)

        client = carla.Client(args.host, int(args.port))
        client.set_timeout(challenge.client_timeout)

        # load the challenge.world variable to be used during the route
        challenge.load_world(client, args.debug_town)
        # Set the actor pool so the scenarios can prepare themselves when needed
        CarlaActorPool.set_world(challenge.world)
        # Also se the Data provider pool.
        CarlaDataProvider.set_world(challenge.world)
        # tick world so we can start.

        challenge.world.tick()
        # create agent
        challenge.agent_instance = getattr(challenge.module_agent,
                                           challenge.module_agent.__name__)(
                                               args.config)
        correct_sensors, error_message = challenge.valid_sensors_configuration(
            challenge.agent_instance, challenge.track)
        if not correct_sensors:
            # the sensor configuration is illegal
            challenge.report_fatal_error(args.filename,
                                         args.show_to_participant,
                                         error_message)
            return

        waypoint = routes[0]['trajectory'][0]

        location = carla.Location(x=float(waypoint.attrib['x']),
                                  y=float(waypoint.attrib['y']),
                                  z=float(waypoint.attrib['z']))

        rotation = carla.Rotation(pitch=float(waypoint.attrib['pitch']),
                                  yaw=float(waypoint.attrib['yaw']))

        challenge.prepare_ego_car(carla.Transform(location, rotation))
        CarlaDataProvider.register_actor(challenge.ego_vehicle)

        list_scenarios = []
        list_scenarios += challenge.build_scenario_instances([scenario_conf],
                                                             args.debug_town)

        # Tick once to start the scenarios.
        print(" Running these scenarios  --- ", list_scenarios)
        for scenario in list_scenarios:
            scenario.scenario.scenario_tree.tick_once()

        challenge.run_route(list_scenarios, None, True)

        # clean up
        for scenario in list_scenarios:
            del scenario
        challenge.cleanup(ego=True)
        challenge.agent_instance.destroy()
        break

    # final measurements from the challenge
    challenge.report_challenge_statistics(args.filename,
                                          args.show_to_participant)
    del challenge
def test_routes(args):
    """
    Run all routes according to provided commandline args
    """

    # Routes are always visible
    args.route_visible = True
    challenge = ChallengeEvaluator(args)
    # retrieve worlds annotations
    world_annotations = parser.parse_annotations_file(args.scenarios)
    # retrieve routes
    route_descriptions_list = parser.parse_routes_file(args.routes)
    # find and filter potential scenarios for each of the evaluated routes
    # For each of the routes and corresponding possible scenarios to be evaluated.

    route_description = route_descriptions_list[args.route_id]
    # setup world and client assuming that the CARLA server is up and running
    client = carla.Client(args.host, int(args.port))
    client.set_timeout(challenge.client_timeout)

    # load the challenge.world variable to be used during the route
    challenge.load_world(client, route_description['town_name'])
    # Set the actor pool so the scenarios can prepare themselves when needed
    CarlaActorPool.set_client(client)
    CarlaActorPool.set_world(challenge.world)
    # Also se the Data provider pool.
    CarlaDataProvider.set_world(challenge.world)
    # tick world so we can start.
    challenge.world.tick()
    # prepare route's trajectory
    gps_route, route_description['trajectory'] = interpolate_trajectory(
        challenge.world, route_description['trajectory'])

    CarlaDataProvider.set_ego_vehicle_route(
        convert_transform_to_location(route_description['trajectory']))

    potential_scenarios_definitions, existent_triggers = parser.scan_route_for_scenarios(
        route_description, world_annotations)
    potential_scenarios_definitions = challenge.filter_scenarios(
        potential_scenarios_definitions, args.removed_scenarios)
    print("WE HAVE This number of posibilities : ",
          len(potential_scenarios_definitions))

    # Sample the scenarios to be used for this route instance.
    sampled_scenarios_definitions = challenge.scenario_sampling(
        potential_scenarios_definitions)
    # create agent
    challenge.agent_instance = getattr(
        challenge.module_agent, challenge.module_agent.__name__)(args.config)
    correct_sensors, error_message = challenge.valid_sensors_configuration(
        challenge.agent_instance, challenge.track)
    if not correct_sensors:
        # the sensor configuration is illegal
        challenge.report_fatal_error(args.filename, args.show_to_participant,
                                     error_message)
        return

    challenge.agent_instance.set_global_plan(gps_route,
                                             route_description['trajectory'])

    # prepare the ego car to run the route.
    # It starts on the first wp of the route

    elevate_transform = route_description['trajectory'][0][0]
    elevate_transform.location.z += 0.5

    challenge.prepare_ego_car(elevate_transform)

    # build the master scenario based on the route and the target.
    challenge.master_scenario = challenge.build_master_scenario(
        route_description['trajectory'], route_description['town_name'])
    list_scenarios = [challenge.master_scenario]

    if args.background:
        background_scenario = challenge.build_background_scenario(
            route_description['town_name'])
        list_scenarios.append(background_scenario)
    # build the instance based on the parsed definitions.
    print("Definition of the scenarios present on the route ")
    pprint(sampled_scenarios_definitions)
    list_scenarios += challenge.build_scenario_instances(
        sampled_scenarios_definitions, route_description['town_name'])
    if args.debug > 0:
        for scenario in sampled_scenarios_definitions:
            loc = carla.Location(
                scenario['trigger_position']['x'],
                scenario['trigger_position']['y'],
                scenario['trigger_position']['z']) + carla.Location(z=2.0)
            challenge.world.debug.draw_point(loc,
                                             size=1.0,
                                             color=carla.Color(255, 0, 0),
                                             life_time=100000)
            challenge.world.debug.draw_string(loc,
                                              scenario['name'],
                                              draw_shadow=False,
                                              color=carla.Color(0, 0, 255),
                                              life_time=100000,
                                              persistent_lines=True)

    # Tick once to start the scenarios.
    print(" Running these scenarios  --- ", list_scenarios)
    for scenario in list_scenarios:
        scenario.scenario.scenario_tree.tick_once()

    challenge.run_route(list_scenarios, route_description['trajectory'])

    # statistics recording
    challenge.record_route_statistics(route_description['id'])

    # clean up
    for scenario in list_scenarios:
        scenario.remove_all_actors()
    challenge.cleanup(ego=True)
    challenge.agent_instance.destroy()
Exemple #5
0
    def test_build_scenarios(self):

        args = Arguments()
        client = carla.Client(args.host, int(args.port))
        client.set_timeout(25.0)
        challenge = ChallengeEvaluator(args)

        filename = os.path.join(self.root_route_file_position,
                                'all_towns_traffic_scenarios1_3_4.json')
        world_annotations = parser.parse_annotations_file(filename)
        # retrieve routes
        # Which type of file is expected ????

        filename_train = os.path.join(self.root_route_file_position,
                                      'routes_training.xml')
        filename_val = os.path.join(self.root_route_file_position,
                                    'routes_devtest.xml')
        list_route_descriptions = parser.parse_routes_file(
            filename_train) + parser.parse_routes_file(filename_val)
        # For each of the routes to be evaluated.
        for route_description in list_route_descriptions:

            if route_description['town_name'] == 'Town03'\
                    or route_description['town_name'] == 'Town04':
                continue
            #         or route_description['town_name'] == 'Town02':
            #    continue
            print(" TOWN  ", route_description['town_name'])
            challenge.world = client.load_world(route_description['town_name'])
            CarlaActorPool.set_client(client)
            # Set the actor pool so the scenarios can prepare themselves when needed
            CarlaActorPool.set_world(challenge.world)
            CarlaDataProvider.set_world(challenge.world)
            # find and filter potential scenarios
            # Returns the iterpolation in a different format

            challenge.world.wait_for_tick()
            gps_route, route_description[
                'trajectory'] = interpolate_trajectory(
                    challenge.world, route_description['trajectory'])

            potential_scenarios_definitions, existent_triggers = parser.scan_route_for_scenarios(
                route_description, world_annotations)
            # Sample the scenarios
            sampled_scenarios = challenge.scenario_sampling(
                potential_scenarios_definitions)

            # prepare route's trajectory
            elevate_transform = route_description['trajectory'][0][0]
            elevate_transform.location.z += 0.5
            challenge.prepare_ego_car(elevate_transform)

            # build the master scenario based on the route and the target.
            print("loading master")
            master_scenario = challenge.build_master_scenario(
                route_description['trajectory'],
                route_description['town_name'])
            list_scenarios = [master_scenario]
            if args.background:
                background_scenario = challenge.build_background_scenario(
                    route_description['town_name'])
                list_scenarios.append(background_scenario)
            print(" Built the master scenario ")
            # build the instance based on the parsed definitions.
            print(sampled_scenarios)
            # remove scenario 8 and 9
            scenario_removed = []
            for possible_scenario in sampled_scenarios:
                if possible_scenario['name'] == 'Scenario8' or possible_scenario['name'] == 'Scenario7' or \
                        possible_scenario['name'] == 'Scenario9' or possible_scenario['name'] == 'Scenario5':
                    continue
                else:
                    scenario_removed.append(possible_scenario)

            list_scenarios += challenge.build_scenario_instances(
                scenario_removed, route_description['town_name'])
            print(" Scenarios present ", list_scenarios)

            challenge.cleanup(ego=True)