Пример #1
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
Пример #2
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