Ejemplo n.º 1
0
    def __init__(self, routes_file, scenarios_file, repetitions):
        self._routes_file = routes_file
        self._scenarios_file = scenarios_file
        self._repetitions = repetitions
        self._configs_dict = OrderedDict()
        self._configs_list = None
        self.routes_length = []
        self._index = 0

        # retrieve routes
        route_descriptions_list = RouteParser.parse_routes_file(
            self._routes_file, False)

        self.n_routes = len(route_descriptions_list)
        self.total = self.n_routes * self._repetitions

        for i, route_description in enumerate(route_descriptions_list):
            for repetition in range(repetitions):
                config = RouteScenarioConfiguration(route_description,
                                                    self._scenarios_file)
                config.index = i * self._repetitions + repetition
                self._configs_dict['{}.{}'.format(config.name,
                                                  repetition)] = config

        self._configs_list = list(self._configs_dict.items())
Ejemplo n.º 2
0
    def _run_challenge(self, args):
        """
        Run the challenge mode
        """

        routes = args.route[0]
        scenario_file = args.route[1]
        single_route = None
        if args.route[2]:
            single_route = args.route[2]

        repetitions = 1

        # retrieve routes
        route_descriptions_list = RouteParser.parse_routes_file(
            routes, single_route)
        # find and filter potential scenarios for each of the evaluated routes
        # For each of the routes and corresponding possible scenarios to be evaluated.
        # n_routes = len(route_descriptions_list) * repetitions

        for _, route_description in enumerate(route_descriptions_list):
            for _ in range(repetitions):

                config = RouteScenarioConfiguration(route_description,
                                                    scenario_file)

                self._load_and_run_scenario(args, config)
                self._cleanup(ego=(not args.waitForEgo))
Ejemplo n.º 3
0
    def _run_route(self):
        """
        Run the route scenario
        """
        result = False
        repetitions = self._args.repetitions

        if self._args.route:
            routes = self._args.route[0]
            scenario_file = self._args.route[1]
            single_route = None
            if len(self._args.route) > 2:
                single_route = self._args.route[2]

        # retrieve routes
        route_descriptions_list = RouteParser.parse_routes_file(
            routes, single_route)
        # find and filter potential scenarios for each of the evaluated routes
        # For each of the routes and corresponding possible scenarios to be evaluated.

        for _, route_description in enumerate(route_descriptions_list):
            for _ in range(repetitions):

                config = RouteScenarioConfiguration(route_description,
                                                    scenario_file)
                result = self._load_and_run_scenario(config, -1, -1)

                self._cleanup()
        return result
Ejemplo n.º 4
0
    def parse_routes_file(route_filename, scenario_file, single_route=None):
        """
        Returns a list of route elements.
        :param route_filename: the path to a set of routes.
        :param single_route: If set, only this route shall be returned
        :return: List of dicts containing the waypoints, id and town of the routes
        """

        list_route_descriptions = []
        tree = ET.parse(route_filename)
        for route in tree.iter("route"):

            route_id = route.attrib['id']
            if single_route and route_id != single_route:
                continue

            new_config = RouteScenarioConfiguration()
            new_config.town = route.attrib['town']
            new_config.name = "RouteScenario_{}".format(route_id)
            new_config.weather = RouteParser.parse_weather(route)
            new_config.scenario_file = scenario_file

            waypoint_list = []  # the list of waypoints that can be found on this route
            for waypoint in route.iter('waypoint'):
                waypoint_list.append(carla.Location(x=float(waypoint.attrib['x']),
                                                    y=float(waypoint.attrib['y']),
                                                    z=float(waypoint.attrib['z'])))

            new_config.trajectory = waypoint_list

            list_route_descriptions.append(new_config)

        return list_route_descriptions
Ejemplo n.º 5
0
    def createScenarioConfig(self, result=None):
        self.scenario = self.scenarioGenerator.generateScenario(result)

        if not self.scenario or self.wp_idx + 7 >= len(self.waypoint_list):
            return None
        location = carla.Location(self.waypoint_list[self.wp_idx + 2][0],
                                  self.waypoint_list[self.wp_idx + 2][1],
                                  self.waypoint_list[self.wp_idx + 2][2])
        trigger_points = []
        for i in range(len(self.scenario)):
            if i != 0:
                trigger_point = self.map.get_waypoint(
                    location,
                    project_to_road=True,
                    lane_type=carla.LaneType.Driving).next(10 * i)[0].transform
            else:
                trigger_point = self.map.get_waypoint(
                    location,
                    project_to_road=True,
                    lane_type=carla.LaneType.Driving).transform
            trigger_points.append(trigger_point)

        scenarioConfig = ScenarioConfig(self.track)
        scenario_config = scenarioConfig.getScenario(self.scenario,
                                                     trigger_points)
        print("Config: ", scenario_config)
        route_config_list = []
        route_config = RouteScenarioConfiguration()
        route_config.town = self.track
        route_config.name = 'RouteScenario_0'
        route_config.weather = carla.WeatherParameters(sun_altitude_angle=70)
        route_config.scenario_config = scenario_config
        wp = []
        wp.append(
            carla.Location(x=self.waypoint_list[self.wp_idx][0],
                           y=self.waypoint_list[self.wp_idx][1],
                           z=self.waypoint_list[self.wp_idx][2]))

        wp.append(
            carla.Location(x=self.waypoint_list[self.wp_idx + 6][0],
                           y=self.waypoint_list[self.wp_idx + 6][1],
                           z=self.waypoint_list[self.wp_idx + 6][2]))

        route_config.trajectory = wp

        route_config_list.append(route_config)

        args = ScenarioArguments(route_config_list,
                                 scenario_config,
                                 port=self.port)
        self.wp_idx += 7

        return args
Ejemplo n.º 6
0
    def _run_challenge(self):
        """
        Run the challenge mode
        """
        result = False
        phase_codename = os.getenv('CHALLENGE_PHASE_CODENAME', 'dev_track_3')
        phase = phase_codename.split("_")[0]

        repetitions = self._args.repetitions

        if self._args.challenge:
            weather_profiles = CarlaDataProvider.find_weather_presets()
            scenario_runner_root = os.getenv('ROOT_SCENARIO_RUNNER', "./")

            if phase == 'dev':
                routes = '{}/srunner/challenge/routes_devtest.xml'.format(
                    scenario_runner_root)
                repetitions = 1
            elif phase == 'validation':
                routes = '{}/srunner/challenge/routes_testprep.xml'.format(
                    scenario_runner_root)
                repetitions = 3
            elif phase == 'test':
                routes = '{}/srunner/challenge/routes_testchallenge.xml'.format(
                    scenario_runner_root)
                repetitions = 3
            else:
                # debug mode
                routes = '{}/srunner/challenge/routes_debug.xml'.format(
                    scenario_runner_root)
                repetitions = 1

        if self._args.route:
            routes = self._args.route[0]
            scenario_file = self._args.route[1]
            single_route = None
            if len(self._args.route) > 2:
                single_route = self._args.route[2]

        # retrieve routes
        route_descriptions_list = RouteParser.parse_routes_file(
            routes, single_route)
        # find and filter potential scenarios for each of the evaluated routes
        # For each of the routes and corresponding possible scenarios to be evaluated.
        if self._args.challenge:
            n_routes = len(route_descriptions_list) * repetitions
            ChallengeStatisticsManager.set_number_of_scenarios(n_routes)

        for _, route_description in enumerate(route_descriptions_list):
            for repetition in range(repetitions):

                if self._args.challenge and not self._within_available_time():
                    error_message = 'Not enough simulation time available to continue'
                    print(error_message)
                    ChallengeStatisticsManager.record_fatal_error(
                        error_message)
                    self._cleanup()
                    return False

                config = RouteScenarioConfiguration(route_description,
                                                    scenario_file)

                if self._args.challenge:
                    profile = weather_profiles[repetition %
                                               len(weather_profiles)]
                    config.weather = profile[0]
                    config.weather.sun_azimuth_angle = -1
                    config.weather.sun_altitude_angle = -1

                result = self._load_and_run_scenario(config)
                self._cleanup()
        return result