def _run_scenarios(self): """ Run conventional scenarios (e.g. implemented using the Python API of ScenarioRunner) """ result = False # Load the scenario configurations provided in the config file scenario_configurations = ScenarioConfigurationParser.parse_scenario_configuration( self._args.scenario, self._args.configFile) if not scenario_configurations: print("Configuration for scenario {} cannot be found!".format( self._args.scenario)) return result # # ===== original lines ===== # # Execute each configuration # for config in scenario_configurations: # for _ in range(self._args.repetitions): # result = self._load_and_run_scenario(config) # # self._cleanup() # # ============================ # Execute each configuration result = self.run_group_scenarios(scenario_configurations) return result
def _run_scenarios(self): """ Run conventional scenarios (e.g. implemented using the Python API of ScenarioRunner) """ result = False # Load the scenario configurations provided in the config file scenario_config_file = ScenarioConfigurationParser.find_scenario_config( self._args.scenario, self._args.configFile) if scenario_config_file is None: print("Configuration for scenario {} cannot be found!".format( self._args.scenario)) return result scenario_configurations = ScenarioConfigurationParser.parse_scenario_configuration( scenario_config_file, self._args.scenario) # Execute each configuration for config in scenario_configurations: for _ in range(self._args.repetitions): result = self._load_and_run_scenario(config) self._cleanup() return result
def main(): """ main function """ description = ("CARLA Scenario Runner: Setup, Run and Evaluate scenarios using CARLA\n" "Current version: " + VERSION) # pylint: disable=line-too-long parser = argparse.ArgumentParser(description=description, formatter_class=RawTextHelpFormatter) parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + VERSION) parser.add_argument('--host', default='127.0.0.1', help='IP of the host server (default: localhost)') parser.add_argument('--port', default='2000', help='TCP port to listen to (default: 2000)') parser.add_argument('--timeout', default="10.0", help='Set the CARLA client timeout value in seconds') parser.add_argument('--trafficManagerPort', default='8000', help='Port to use for the TrafficManager (default: 8000)') parser.add_argument('--trafficManagerSeed', default='0', help='Seed used by the TrafficManager (default: 0)') parser.add_argument('--sync', action='store_true', help='Forces the simulation to run synchronously') parser.add_argument('--list', action="store_true", help='List all supported scenarios and exit') parser.add_argument( '--scenario', help='Name of the scenario to be executed. Use the preposition \'group:\' to run all scenarios of one class, e.g. ControlLoss or FollowLeadingVehicle') parser.add_argument('--openscenario', help='Provide an OpenSCENARIO definition') parser.add_argument( '--route', help='Run a route as a scenario (input: (route_file,scenario_file,[route id]))', nargs='+', type=str) parser.add_argument( '--agent', help="Agent used to execute the scenario. Currently only compatible with route-based scenarios.") parser.add_argument('--agentConfig', type=str, help="Path to Agent's configuration file", default="") parser.add_argument('--output', action="store_true", help='Provide results on stdout') parser.add_argument('--file', action="store_true", help='Write results into a txt file') parser.add_argument('--junit', action="store_true", help='Write results into a junit file') parser.add_argument('--json', action="store_true", help='Write results into a JSON file') parser.add_argument('--outputDir', default='', help='Directory for output files (default: this directory)') parser.add_argument('--configFile', default='', help='Provide an additional scenario configuration file (*.xml)') parser.add_argument('--additionalScenario', default='', help='Provide additional scenario implementations (*.py)') parser.add_argument('--debug', action="store_true", help='Run with debug output') parser.add_argument('--reloadWorld', action="store_true", help='Reload the CARLA world before starting a scenario (default=True)') parser.add_argument('--record', type=str, default='', help='Path were the files will be saved, relative to SCENARIO_RUNNER_ROOT.\nActivates the CARLA recording feature and saves to file all the criteria information.') parser.add_argument('--randomize', action="store_true", help='Scenario parameters are randomized') parser.add_argument('--repetitions', default=1, type=int, help='Number of scenario executions') parser.add_argument('--waitForEgo', action="store_true", help='Connect the scenario to an existing ego vehicle') arguments = parser.parse_args() # pylint: enable=line-too-long if arguments.list: print("Currently the following scenarios are supported:") print(*ScenarioConfigurationParser.get_list_of_scenarios(arguments.configFile), sep='\n') return 1 if not arguments.scenario and not arguments.openscenario and not arguments.route: print("Please specify either a scenario or use the route mode\n\n") parser.print_help(sys.stdout) return 1 if arguments.route and (arguments.openscenario or arguments.scenario): print("The route mode cannot be used together with a scenario (incl. OpenSCENARIO)'\n\n") parser.print_help(sys.stdout) return 1 if arguments.agent and (arguments.openscenario or arguments.scenario): print("Agents are currently only compatible with route scenarios'\n\n") parser.print_help(sys.stdout) return 1 if arguments.route: arguments.reloadWorld = True if arguments.agent: arguments.sync = True scenario_runner = None result = True try: scenario_runner = ScenarioRunner(arguments) result = scenario_runner.run() finally: if scenario_runner is not None: scenario_runner.destroy() del scenario_runner return not result