def build_scenario_instances(self, scenario_definition_vec, timeout): """ Based on the parsed route and possible scenarios, build all the scenario classes. :param scenario_definition_vec: the dictionary defining the scenarios :param town: the town where scenarios are going to be :return: """ list_instanced_scenarios = [] if scenario_definition_vec is None: return list_instanced_scenarios for scenario_name in scenario_definition_vec: # The BG activity encapsulates several scenarios that contain vehicles going arround if scenario_name == 'background_activity': # BACKGROUND ACTIVITY SPECIAL CASE background_definition = scenario_definition_vec[scenario_name] background = self._build_background(background_definition, timeout) list_instanced_scenarios.append(background) else: # Sample the scenarios to be used for this route instance. # tehre can be many instances of the same scenario scenario_definition_instances = scenario_definition_vec[scenario_name] if scenario_definition_instances is None: raise ValueError(" Not Implemented ") for scenario_definition in scenario_definition_instances: # TODO scenario 4 is out #ScenarioClass = number_class_translation[scenario_name][0] egoactor_trigger_position = convert_json_to_transform( scenario_definition) scenario_configuration = ScenarioConfiguration() scenario_configuration.other_actors = None # TODO the other actors are maybe needed scenario_configuration.town = self._town_name scenario_configuration.trigger_point = egoactor_trigger_position scenario_configuration.ego_vehicle = ActorConfigurationData( 'vehicle.lincoln.mkz2017', self._ego_actor.get_transform()) try: scenario_instance = ScenarioClass(self.world, self._ego_actor, scenario_configuration, criteria_enable=False, timeout=timeout) except Exception as e: print("Skipping scenario '{}' due to setup error: {}".format( 'Scenario3', e)) continue # registering the used actors on the data provider so they can be updated. CarlaDataProvider.register_actors(scenario_instance.other_actors) list_instanced_scenarios.append(scenario_instance) return list_instanced_scenarios
def load_scenario(self, scenario): """ Load a new scenario """ self.restart() self.scenario = scenario.scenario self.scenario_tree = self.scenario.scenario_tree self.ego_vehicle = scenario.ego_vehicle self.other_actors = scenario.other_actors CarlaDataProvider.register_actor(self.ego_vehicle) CarlaDataProvider.register_actors(self.other_actors)
def load_scenario(self, scenario, agent=None): """ Load a new scenario """ self._reset() self._agent = AgentWrapper(agent, self._challenge_mode) if agent else None self.scenario_class = scenario self.scenario = scenario.scenario self.scenario_tree = self.scenario.scenario_tree self.ego_vehicles = scenario.ego_vehicles self.other_actors = scenario.other_actors #print(self.other_actors) CarlaDataProvider.register_actors(self.ego_vehicles) CarlaDataProvider.register_actors(self.other_actors) # To print the scenario tree uncomment the next line # py_trees.display.render_dot_tree(self.scenario_tree) if self._agent is not None: self._agent.setup_sensors(self.ego_vehicles[0], self._debug_mode, self._track)