Ejemplo n.º 1
0
    def _run_scenarios(self):
        """
        Run conventional scenarios (e.g. implemented using the Python API of ScenarioRunner)
        """
        result = False
        # Setup and run the scenarios for repetition times
        for _ in range(int(self._args.repetitions)):

            # Load the scenario configurations provided in the config file
            scenario_configurations = None
            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))
                continue

            scenario_configurations = ScenarioConfigurationParser.parse_scenario_configuration(
                scenario_config_file, self._args.scenario)

            # Execute each configuration
            for config in scenario_configurations:
                result = self._load_and_run_scenario(config)

            self._cleanup()
        return result
Ejemplo n.º 2
0
    def _run_scenarios(self, args):
        """
        Run conventional scenarios (e.g. implemented using the Python API of ScenarioRunner)
        """

        # Setup and run the scenarios for repetition times
        for _ in range(int(args.repetitions)):

            # Load the scenario configurations provided in the config file
            scenario_configurations = None
            scenario_config_file = ScenarioConfigurationParser.find_scenario_config(
                args.scenario, args.configFile)
            if scenario_config_file is None:
                print("Configuration for scenario {} cannot be found!".format(
                    args.scenario))
                continue

            scenario_configurations = ScenarioConfigurationParser.parse_scenario_configuration(
                scenario_config_file, args.scenario)

            # Execute each configuration
            for config in scenario_configurations:
                self._load_and_run_scenario(args, config)

            self._cleanup(ego=(not args.waitForEgo))

            print("No more scenarios .... Exiting")
Ejemplo n.º 3
0
    def run(self, args):
        scenario_config_file = ScenarioConfigurationParser.find_scenario_config(args.scenario, args.configFile) # xml file

        ####################################
        print(args.configFile)
        print(scenario_config_file)
        print(args.scenario)
        scenario_configurations = parse_rss_scenario_configuration(scenario_config_file, args.scenario)
        config = scenario_configurations[0] # since we work only with one scenario!

	# Defaults except for ones we set
        # Lon accel max: 3.500
        # Lon brake max: 8.000
        # Lon brake min: 4.000
        # Lon brake min correct: 0.100
        # Lat accel max: 0.200
        # Lat brake min: 0.800
        # Lat fluct mar: 0.000
        # Response time: 0.200

        g = 9.8
        rss_params = {}
        rss_params['alpha_lon_accel_max'] = 0.5*g
        rss_params['alpha_lon_brake_max'] = 0.7*g
        rss_params['response_time'] = 0.2
        rss_params['alpha_lon_brake_min'] = 0.5*g
        print('RSS params: %s' % rss_params)

        # Load the world once
        self.load_world(config.town)

        settings = self.world.get_settings()
        settings.fixed_delta_seconds = 0.015
        self.world.apply_settings(settings)

        # Set the sun to be directly overhead
        weather = carla.WeatherParameters(sun_altitude_angle=90)
        self.world.set_weather(weather)

        return self.simulate(config, args, rss_params)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    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('-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')
        sys.exit(0)

    if ARGUMENTS.listClass:
        print("Currently the following scenario classes are supported:")
        print(*SCENARIOS.keys(), sep='\n')
        sys.exit(0)

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

    if (ARGUMENTS.route
            and ARGUMENTS.openscenario) or (ARGUMENTS.route
Ejemplo n.º 6
0
    def run(self, args):
        scenario_config_file = ScenarioConfigurationParser.find_scenario_config(
            args.scenario, args.configFile)  # xml file

        num_simult_runs = 1
        nruns = 20
        ####################################

        search_names = [
            'alpha_lon_accel_max', 'alpha_lon_brake_max',
            'alpha_lon_brake_min', 'response_time', 'alpha_lat_accel_max',
            'alpha_lat_brake_min', 'lateral_fluctuation_margin'
        ]  #, 'alpha_lon_brake_min_correct']

        # extra params for lateral and opposite directions :
        # 'alpha_lat_brake_min', 'lateral_fluctuation_margin', 'alpha_lon_brake_min_correct', 'alpha_lat_accel_max'

        ## initial values ?
        alpha_lon_accel_max = 3.5
        response_time = 1.0
        alpha_lon_brake_max = 6.0
        alpha_lon_brake_min = 3.5
        alpha_lat_accel_max = 0.1
        alpha_lat_brake_min = 0.1
        lateral_fluctuation_margin = 0.1
        alpha_lon_brake_min_correct = 1.0

        # alpha_lon_accel_max = 4.01
        # response_time       = 0.53
        # alpha_lon_brake_max = 8.03
        # alpha_lon_brake_min = 4.64
        # alpha_lat_accel_max = 0.43
        # alpha_lat_brake_min = 0.96
        # lateral_fluctuation_margin = 0.07
        # alpha_lon_brake_min_correct = 1.76

        ####################################
        x0, searchSpace = RssParamsInit().getInit(
            search_names,
            alpha_lon_accel_max=alpha_lon_accel_max,
            response_time=response_time,
            alpha_lon_brake_max=alpha_lon_brake_max,
            alpha_lon_brake_min=alpha_lon_brake_min,
            alpha_lat_accel_max=alpha_lat_accel_max,
            alpha_lat_brake_min=alpha_lat_brake_min,
            lateral_fluctuation_margin=lateral_fluctuation_margin)
        # ,                                            alpha_lon_brake_min_correct = alpha_lon_brake_min_correct)

        # search_names = ['alpha_lon_accel_max', 'response_time']
        # alpha_lon_accel_max = 3.5
        # response_time = 1.0
        # ####################################
        # x0, searchSpace = RssParamsInit().getInit(search_names,
        #                                            alpha_lon_accel_max = alpha_lon_accel_max,
        #                                            response_time = response_time)
        print('X0 = %s' % x0)
        print('SearchSpace = %s\n' % searchSpace)
        #-------------------------------
        X0 = []
        for _ in range(num_simult_runs):
            X0.append(x0)
        ####################################

        ####################################
        def ff(x):
            scenario_configurations = parse_rss_scenario_configuration(
                scenario_config_file, args.scenario)
            config = scenario_configurations[
                0]  # since we work only with one scenario!

            rss_params = defineRssParams(x, search_names)
            rss_params['alpha_lon_brake_min_correct'] = 0.1
            print('RSS params: %s' % rss_params)

            return self.simulate(config, args, rss_params)

        # reproduce trajs
        '''
        for i in range(10):
            self.filename_traj = os.path.join(RES_FOLDER, ('trajectory'+str(i)+'.csv'))
            ff(x0)
        '''
        best_x_history, best_f_history, x_history, f_history, accept_x_history, accept_flags = annealing.runFunc(
            ff, X0, searchSpace, nruns, num_simult_runs, RES_FOLDER)