Пример #1
0
    def _scenario_sampling(self, potential_scenarios_definitions):
        """
        The function used to sample the scenarios that are going to happen for this route.
        """

        # fix the random seed for reproducibility
        rng = CarlaDataProvider.get_random_seed()

        def position_sampled(scenario_choice, sampled_scenarios):
            """
            Check if a position was already sampled, i.e. used for another scenario
            """
            for existent_scenario in sampled_scenarios:
                # If the scenarios have equal positions then it is true.
                if compare_scenarios(scenario_choice, existent_scenario):
                    return True

            return False

        # The idea is to randomly sample a scenario per trigger position.
        sampled_scenarios = []
        for trigger in potential_scenarios_definitions.keys():
            possible_scenarios = potential_scenarios_definitions[trigger]

            scenario_choice = rng.choice(possible_scenarios)
            del possible_scenarios[possible_scenarios.index(scenario_choice)]
            # We keep sampling and testing if this position is present on any of the scenarios.
            while position_sampled(scenario_choice, sampled_scenarios):
                if possible_scenarios is None or not possible_scenarios:
                    scenario_choice = None
                    break
                scenario_choice = rng.choice(possible_scenarios)
                del possible_scenarios[possible_scenarios.index(scenario_choice)]

            if scenario_choice is not None:
                sampled_scenarios.append(scenario_choice)

        return sampled_scenarios
Пример #2
0
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 criteria_enable=True,
                 timeout=180):
        """
        Setup all relevant parameters and create scenario
        and instantiate scenario manager
        """
        self._world = world
        self._map = CarlaDataProvider.get_map()
        self._source_dist = 30
        self._sink_dist = 20
        self._direction = None
        self._opposite_bp_wildcards = [
            '*firetruck*', '*ambulance*', '*police*'
        ]  # Wildcard patterns of the blueprints
        self.timeout = timeout

        self._adversary_speed = 70 / 3.6  # Speed of the adversary [m/s]
        self._sync_time = 2.2  # Time the agent has to react to avoid the collision [s]
        self._min_trigger_dist = 9.0  # Min distance to the collision location that triggers the adversary [m]
        self._speed_duration_ratio = 2.0
        self._speed_distance_ratio = 1.5

        # Get the CDP seed or at routes, all copies of the scenario will have the same configuration
        self._rng = CarlaDataProvider.get_random_seed()

        super(OppositeVehicleRunningRedLight,
              self).__init__("OppositeVehicleRunningRedLight",
                             ego_vehicles,
                             config,
                             world,
                             debug_mode,
                             criteria_enable=criteria_enable)