Exemple #1
0
def main():
    """
    main function
    """
    description = (
        "CARLA Scenario Runner: Setup, Run and Evaluate scenarios using CARLA\n"
        "Current version: " + str(VERSION))

    parser = argparse.ArgumentParser(description=description,
                                     formatter_class=RawTextHelpFormatter)
    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('--debug',
                        action="store_true",
                        help='Run with debug output')
    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(
        '--outputDir',
        default='',
        help='Directory for output files (default: this directory)')
    parser.add_argument('--waitForEgo',
                        action="store_true",
                        help='Connect the scenario to an existing ego vehicle')
    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(
        '--reloadWorld',
        action="store_true",
        help='Reload the CARLA world before starting a scenario (default=True)'
    )
    # pylint: disable=line-too-long
    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('--randomize',
                        action="store_true",
                        help='Scenario parameters are randomized')
    parser.add_argument('--repetitions',
                        default=1,
                        help='Number of scenario executions')
    parser.add_argument('--list',
                        action="store_true",
                        help='List all supported scenarios and exit')
    parser.add_argument(
        '--agent',
        help=
        "Agent used to execute the scenario (optional). Currently only compatible with route-based scenarios."
    )
    parser.add_argument('--agentConfig',
                        type=str,
                        help="Path to Agent's configuration file",
                        default="")
    parser.add_argument('--openscenario',
                        help='Provide an OpenSCENARIO definition')
    parser.add_argument(
        '--route',
        help=
        'Run a route as a scenario, similar to the CARLA AD challenge (input: (route_file,scenario_file,[number of route]))',
        nargs='+',
        type=str)
    parser.add_argument('--challenge',
                        action="store_true",
                        help='Run in challenge mode')
    parser.add_argument(
        '--record',
        action="store_true",
        help='Use CARLA recording feature to create a recording of the scenario'
    )
    parser.add_argument('--timeout',
                        default="10.0",
                        help='Set the CARLA client timeout value in seconds')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='%(prog)s ' + str(VERSION))
    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.route
                                            and 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.challenge and (arguments.openscenario or arguments.scenario):
        print(
            "The challenge mode can only be used with route-based scenarios'\n\n"
        )
        parser.print_help(sys.stdout)
        return 1

    if arguments.route:
        arguments.reloadWorld = True

    scenario_runner = None
    result = True
    try:
        scenario_runner = ScenarioRunner(arguments)
        result = scenario_runner.run()

    finally:
        if arguments.challenge:
            ChallengeStatisticsManager.report_challenge_statistics(
                'results.json', arguments.debug)
        if scenario_runner is not None:
            scenario_runner.destroy()
            del scenario_runner
    return not result
Exemple #2
0
            "The route mode cannot be used together with a scenario (incl. OpenSCENARIO)'\n\n"
        )
        PARSER.print_help(sys.stdout)
        sys.exit(0)

    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)
        sys.exit(0)

    if ARGUMENTS.challenge and (ARGUMENTS.openscenario or ARGUMENTS.scenario):
        print(
            "The challenge mode can only be used with route-based scenarios'\n\n"
        )
        PARSER.print_help(sys.stdout)
        sys.exit(0)

    if ARGUMENTS.route:
        ARGUMENTS.reloadWorld = True

    SCENARIORUNNER = None
    try:
        SCENARIORUNNER = ScenarioRunner(ARGUMENTS)
        SCENARIORUNNER.run(ARGUMENTS)
    finally:
        if ARGUMENTS.challenge:
            ChallengeStatisticsManager.report_challenge_statistics(
                'results.json', ARGUMENTS.debug)
        if SCENARIORUNNER is not None:
            del SCENARIORUNNER