leaderboard/leaderboard/scenarios/train_scenario.py
def _build_scenario_instances(self, world, ego_vehicle, scenario_definitions,
                                  scenarios_per_tick=5, timeout=300, debug_mode=False):
        """
        Based on the parsed route and possible scenarios, build all the scenario classes.
        """
        scenario_instance_vec = []

        if debug_mode:
            for scenario in scenario_definitions:
                loc = carla.Location(scenario['trigger_position']['x'],
                                     scenario['trigger_position']['y'],
                                     scenario['trigger_position']['z']) + carla.Location(z=2.0)
                world.debug.draw_point(loc, size=0.3, color=carla.Color(255, 0, 0), life_time=100000)
                world.debug.draw_string(loc, str(scenario['name']), draw_shadow=False,
                                        color=carla.Color(0, 0, 255), life_time=100000, persistent_lines=True)

        for scenario_number, definition in enumerate(scenario_definitions):
            # Get the class possibilities for this scenario number
            if definition['name'] not in NUMBER_CLASS_TRANSLATION:
                continue
            
            print (definition['name'])
            
            scenario_class = NUMBER_CLASS_TRANSLATION[definition['name']]

            # Create the other actors that are going to appear
            if definition['other_actors'] is not None:
                list_of_actor_conf_instances = self._get_actors_instances(definition['other_actors'])
            else:
                list_of_actor_conf_instances = []
            # Create an actor configuration for the ego-vehicle trigger position
            
            egoactor_trigger_position = convert_json_to_transform(definition['trigger_position'])
            scenario_configuration = ScenarioConfiguration()
            scenario_configuration.other_actors = list_of_actor_conf_instances
            scenario_configuration.trigger_points = [egoactor_trigger_position]
            scenario_configuration.subtype = definition['scenario_type']
            scenario_configuration.ego_vehicles = [ActorConfigurationData('vehicle.lincoln.mkz2017',
                                                                          ego_vehicle.get_transform(),
                                                                          'hero')]
            route_var_name = "ScenarioRouteNumber{}".format(scenario_number)
            scenario_configuration.route_var_name = route_var_name
            try:
                scenario_instance = scenario_class(world, [ego_vehicle], scenario_configuration,
                                                   criteria_enable=False, timeout=timeout)
                # Do a tick every once in a while to avoid spawning everything at the same time
                if scenario_number % scenarios_per_tick == 0:
                    if CarlaDataProvider.is_sync_mode():
                        world.tick()
                    else:
                        world.wait_for_tick()

            except Exception as e:
                print("Skipping scenario '{}' due to setup error: {}".format(definition['name'], e))
                # import pdb; pdb.set_trace()
                continue

            scenario_instance_vec.append(scenario_instance)

        return scenario_instance_vec

        Based on the parsed route and possible scenarios, build all the scenario classes.
        
Based on the parsed route and possible scenarios, build all the scenario classes.
Based on the parsed route and possible scenarios build all the scenario classes .
def _build_scenario_instances(self, world, ego_vehicle, scenario_definitions,
                                  scenarios_per_tick=5, timeout=300, debug_mode=False):
        scenario_instance_vec = []
        if debug_mode:
            for scenario in scenario_definitions:
                loc = carla.Location(scenario['trigger_position']['x'],
                                     scenario['trigger_position']['y'],
                                     scenario['trigger_position']['z']) + carla.Location(z=2.0)
                world.debug.draw_point(loc, size=0.3, color=carla.Color(255, 0, 0), life_time=100000)
                world.debug.draw_string(loc, str(scenario['name']), draw_shadow=False,
                                        color=carla.Color(0, 0, 255), life_time=100000, persistent_lines=True)
        for scenario_number, definition in enumerate(scenario_definitions):
            if definition['name'] not in NUMBER_CLASS_TRANSLATION:
                continue
            print (definition['name'])
            scenario_class = NUMBER_CLASS_TRANSLATION[definition['name']]
            if definition['other_actors'] is not None:
                list_of_actor_conf_instances = self._get_actors_instances(definition['other_actors'])
            else:
                list_of_actor_conf_instances = []
            egoactor_trigger_position = convert_json_to_transform(definition['trigger_position'])
            scenario_configuration = ScenarioConfiguration()
            scenario_configuration.other_actors = list_of_actor_conf_instances
            scenario_configuration.trigger_points = [egoactor_trigger_position]
            scenario_configuration.subtype = definition['scenario_type']
            scenario_configuration.ego_vehicles = [ActorConfigurationData('vehicle.lincoln.mkz2017',
                                                                          ego_vehicle.get_transform(),
                                                                          'hero')]
            route_var_name = "ScenarioRouteNumber{}".format(scenario_number)
            scenario_configuration.route_var_name = route_var_name
            try:
                scenario_instance = scenario_class(world, [ego_vehicle], scenario_configuration,
                                                   criteria_enable=False, timeout=timeout)
                if scenario_number % scenarios_per_tick == 0:
                    if CarlaDataProvider.is_sync_mode():
                        world.tick()
                    else:
                        world.wait_for_tick()
            except Exception as e:
                print("Skipping scenario '{}' due to setup error: {}".format(definition['name'], e))
                continue
            scenario_instance_vec.append(scenario_instance)
        return scenario_instance_vec
def _build_scenario_instances ( self , world , ego_vehicle , scenario_definitions , scenarios_per_tick = 5 , timeout = 300 , debug_mode = False ) : scenario_instance_vec = [ ] if debug_mode : for scenario in scenario_definitions : loc = carla . Location ( scenario [ 'trigger_position' ] [ 'x' ] , scenario [ 'trigger_position' ] [ 'y' ] , scenario [ 'trigger_position' ] [ 'z' ] ) + carla . Location ( z = 2.0 ) world . debug . draw_point ( loc , size = 0.3 , color = carla . Color ( 255 , 0 , 0 ) , life_time = 100000 ) world . debug . draw_string ( loc , str ( scenario [ 'name' ] ) , draw_shadow = False , color = carla . Color ( 0 , 0 , 255 ) , life_time = 100000 , persistent_lines = True ) for scenario_number , definition in enumerate ( scenario_definitions ) : if definition [ 'name' ] not in NUMBER_CLASS_TRANSLATION : continue print ( definition [ 'name' ] ) scenario_class = NUMBER_CLASS_TRANSLATION [ definition [ 'name' ] ] if definition [ 'other_actors' ] is not None : list_of_actor_conf_instances = self . _get_actors_instances ( definition [ 'other_actors' ] ) else : list_of_actor_conf_instances = [ ] egoactor_trigger_position = convert_json_to_transform ( definition [ 'trigger_position' ] ) scenario_configuration = ScenarioConfiguration ( ) scenario_configuration . other_actors = list_of_actor_conf_instances scenario_configuration . trigger_points = [ egoactor_trigger_position ] scenario_configuration . subtype = definition [ 'scenario_type' ] scenario_configuration . ego_vehicles = [ ActorConfigurationData ( 'vehicle.lincoln.mkz2017' , ego_vehicle . get_transform ( ) , 'hero' ) ] route_var_name = "ScenarioRouteNumber{}" . format ( scenario_number ) scenario_configuration . route_var_name = route_var_name try : scenario_instance = scenario_class ( world , [ ego_vehicle ] , scenario_configuration , criteria_enable = False , timeout = timeout ) if scenario_number % scenarios_per_tick == 0 : if CarlaDataProvider . is_sync_mode ( ) : world . tick ( ) else : world . wait_for_tick ( ) except Exception as e : print ( "Skipping scenario '{}' due to setup error: {}" . format ( definition [ 'name' ] , e ) ) continue scenario_instance_vec . append ( scenario_instance ) return scenario_instance_vec
Based on the parsed route and possible scenarios, build all the scenario classes.
Based on the parsed route and possible scenarios build all the scenario classes .
"""
        Based on the parsed route and possible scenarios, build all the scenario classes.
        """ # Get the class possibilities for this scenario number # Create the other actors that are going to appear # Create an actor configuration for the ego-vehicle trigger position # Do a tick every once in a while to avoid spawning everything at the same time # import pdb; pdb.set_trace()
self
world
ego_vehicle
scenario_definitions
scenarios_per_tick
timeout
debug_mode