def _load_and_run_scenario(self, config): """ Load and run the scenario given by config """ result = False if not self._load_and_wait_for_world(config.town, config.ego_vehicles): self._cleanup() return False if self._args.agent: agent_class_name = self.module_agent.__name__.title().replace( '_', '') try: self.agent_instance = getattr(self.module_agent, agent_class_name)( self._args.agentConfig) config.agent = self.agent_instance except Exception as e: # pylint: disable=broad-except traceback.print_exc() print("Could not setup required agent due to {}".format(e)) self._cleanup() return False # Prepare scenario print("Preparing scenario: " + config.name) try: self._prepare_ego_vehicles(config.ego_vehicles) if self._args.openscenario: scenario = OpenScenario(world=self.world, ego_vehicles=self.ego_vehicles, config=config, config_file=self._args.openscenario, timeout=100000) elif self._args.route: scenario = RouteScenario(world=self.world, config=config, debug_mode=self._args.debug) else: scenario_class = self._get_scenario_class_or_fail(config.type) scenario = scenario_class(self.world, self.ego_vehicles, config, self._args.randomize, self._args.debug) except Exception as exception: # pylint: disable=broad-except print("The scenario cannot be loaded") traceback.print_exc() print(exception) self._cleanup() return False # Set the appropriate weather conditions self.world.set_weather(config.weather) # Set the appropriate road friction if config.friction is not None: friction_bp = self.world.get_blueprint_library().find( 'static.trigger.friction') extent = carla.Location(1000000.0, 1000000.0, 1000000.0) friction_bp.set_attribute('friction', str(config.friction)) friction_bp.set_attribute('extent_x', str(extent.x)) friction_bp.set_attribute('extent_y', str(extent.y)) friction_bp.set_attribute('extent_z', str(extent.z)) # Spawn Trigger Friction transform = carla.Transform() transform.location = carla.Location(-10000.0, -10000.0, 0.0) self.world.spawn_actor(friction_bp, transform) try: # Load scenario and run it if self._args.record: self.client.start_recorder("{}/{}.log".format( os.getenv('ROOT_SCENARIO_RUNNER', "./"), config.name)) self.manager.load_scenario(scenario, self.agent_instance) self.manager.run_scenario() # Provide outputs if required self._analyze_scenario(config) # Remove all actors scenario.remove_all_actors() result = True except SensorConfigurationInvalid as e: self._cleanup() ChallengeStatisticsManager.record_fatal_error(e) sys.exit(-1) except Exception as e: # pylint: disable=broad-except traceback.print_exc() if self._args.challenge: ChallengeStatisticsManager.set_error_message( traceback.format_exc()) print(e) result = False self._cleanup() return result
def _run_challenge(self): """ Run the challenge mode """ result = False phase_codename = os.getenv('CHALLENGE_PHASE_CODENAME', 'dev_track_3') phase = phase_codename.split("_")[0] repetitions = self._args.repetitions if self._args.challenge: weather_profiles = CarlaDataProvider.find_weather_presets() scenario_runner_root = os.getenv('ROOT_SCENARIO_RUNNER', "./") if phase == 'dev': routes = '{}/srunner/challenge/routes_devtest.xml'.format( scenario_runner_root) repetitions = 1 elif phase == 'validation': routes = '{}/srunner/challenge/routes_testprep.xml'.format( scenario_runner_root) repetitions = 3 elif phase == 'test': routes = '{}/srunner/challenge/routes_testchallenge.xml'.format( scenario_runner_root) repetitions = 3 else: # debug mode routes = '{}/srunner/challenge/routes_debug.xml'.format( scenario_runner_root) repetitions = 1 if self._args.route: routes = self._args.route[0] scenario_file = self._args.route[1] single_route = None if len(self._args.route) > 2: single_route = self._args.route[2] # retrieve routes route_descriptions_list = RouteParser.parse_routes_file( routes, single_route) # find and filter potential scenarios for each of the evaluated routes # For each of the routes and corresponding possible scenarios to be evaluated. if self._args.challenge: n_routes = len(route_descriptions_list) * repetitions ChallengeStatisticsManager.set_number_of_scenarios(n_routes) for _, route_description in enumerate(route_descriptions_list): for repetition in range(repetitions): if self._args.challenge and not self._within_available_time(): error_message = 'Not enough simulation time available to continue' print(error_message) ChallengeStatisticsManager.record_fatal_error( error_message) self._cleanup() return False config = RouteScenarioConfiguration(route_description, scenario_file) if self._args.challenge: profile = weather_profiles[repetition % len(weather_profiles)] config.weather = profile[0] config.weather.sun_azimuth_angle = -1 config.weather.sun_altitude_angle = -1 result = self._load_and_run_scenario(config) self._cleanup() return result
def _load_and_run_scenario(self, args, config): """ Load and run the scenario given by config """ if not self._load_and_wait_for_world(args, config.town, config.ego_vehicles): self._cleanup() return if args.agent: agent_class_name = self.module_agent.__name__.title().replace( '_', '') try: self.agent_instance = getattr( self.module_agent, agent_class_name)(args.agentConfig) config.agent = self.agent_instance except Exception as e: print("Could not setup required agent due to {}".format(e)) self._cleanup() return # Prepare scenario print("Preparing scenario: " + config.name) try: self._prepare_ego_vehicles(config.ego_vehicles, args.waitForEgo) if args.openscenario: scenario = OpenScenario(world=self.world, ego_vehicles=self.ego_vehicles, config=config, config_file=args.openscenario, timeout=100000) elif args.route: scenario = RouteScenario(world=self.world, config=config, debug_mode=args.debug) else: scenario_class = self._get_scenario_class_or_fail(config.type) scenario = scenario_class(self.world, self.ego_vehicles, config, args.randomize, args.debug) except Exception as exception: print("The scenario cannot be loaded") if args.debug: traceback.print_exc() print(exception) self._cleanup() return # Set the appropriate weather conditions weather = carla.WeatherParameters( cloudyness=config.weather.cloudyness, precipitation=config.weather.precipitation, precipitation_deposits=config.weather.precipitation_deposits, wind_intensity=config.weather.wind_intensity, sun_azimuth_angle=config.weather.sun_azimuth, sun_altitude_angle=config.weather.sun_altitude) self.world.set_weather(weather) try: # Load scenario and run it if args.record: self.client.start_recorder("{}/{}.log".format( os.getenv('ROOT_SCENARIO_RUNNER', "./"), config.name)) self.manager.load_scenario(scenario, self.agent_instance) self.manager.run_scenario() # Stop scenario self.manager.stop_scenario() # Provide outputs if required self._analyze_scenario(args, config) # Remove all actors scenario.remove_all_actors() except SensorConfigurationInvalid as e: self._cleanup(True) ChallengeStatisticsManager.record_fatal_error(e) sys.exit(-1) except Exception as e: if args.debug: traceback.print_exc() if args.challenge: ChallengeStatisticsManager.set_error_message( traceback.format_exc()) print(e) self._cleanup()