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 build_master_scenario(self, route, town_name, timeout, terminate_on_collision): # We have to find the target. # we also have to convert the route to the expected format master_scenario_configuration = ScenarioConfiguration() master_scenario_configuration.target = route[-1][0] # Take the last point and add as target. master_scenario_configuration.route = convert_transform_to_location(route) master_scenario_configuration.town = town_name master_scenario_configuration.ego_vehicle = ActorConfigurationData('vehicle.lincoln.mkz2017', self._ego_actor.get_transform()) master_scenario_configuration.trigger_point = self._ego_actor.get_transform() CarlaDataProvider.register_actor(self._ego_actor) return MasterScenario(self.world, [self._ego_actor], master_scenario_configuration, timeout=timeout, terminate_on_collision=terminate_on_collision)