def __init__(self, args): """ Setup CARLA client and world Setup ScenarioManager """ # First of all, we need to create the client that will send the requests # to the simulator. Here we'll assume the simulator is accepting # requests in the localhost at port 2000. self.client = carla.Client(args.host, int(args.port)) self.client.set_timeout(self.client_timeout) dist = pkg_resources.get_distribution("carla") if LooseVersion(dist.version) < LooseVersion('0.9.6'): raise ImportError("CARLA version 0.9.6 or newer required. CARLA version found: {}".format(dist)) # Load additional scenario definitions, if there are any # If something goes wrong an exception will be thrown by importlib (ok here) if args.additionalScenario != '': module_name = os.path.basename(args.additionalScenario).split('.')[0] sys.path.insert(0, os.path.dirname(args.additionalScenario)) self.additional_scenario_module = importlib.import_module(module_name) # Load agent if requested via command line args # If something goes wrong an exception will be thrown by importlib (ok here) if args.agent is not None: module_name = os.path.basename(args.agent).split('.')[0] sys.path.insert(0, os.path.dirname(args.agent)) self.module_agent = importlib.import_module(module_name) # Create the ScenarioManager self.manager = ScenarioManager(args.debug, args.challenge) self._start_wall_time = datetime.now()
def run(self, args): """ Run all scenarios according to provided commandline args """ if args.openscenario: self.run_openscenario(args) return # 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 = find_scenario_config(args.scenario, args.configFile) if scenario_config_file is None: print("Configuration for scenario {} cannot be found!".format(args.scenario)) continue print("scenario_config_file is ", scenario_config_file) # srunner/configs/*.xml scenario_configurations = parse_scenario_configuration(scenario_config_file, args.scenario) # Execute each configuration config_counter = 0 for config in scenario_configurations: if not self.load_world(args, config.town): self.cleanup() continue # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Prepare scenario print("Preparing scenario: " + config.name) scenario_class = self.get_scenario_class_or_fail(config.type) try: CarlaActorPool.set_world(self.world) self.prepare_ego_vehicles(config) 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() config_counter += 1 continue self.load_and_run_scenario(args, config, scenario) config_counter += 1 self.cleanup(ego=(not args.waitForEgo)) print("No more scenarios .... Exiting")
def simulate(self, config, args, rss_params): file = open(self.filename_traj, 'w') file.close() result = False scenario_class = self.get_scenario_class_or_fail(config.type) while not result: try: self.load_world(args, config.town) self.manager = ScenarioManager(self.world, args.debug) CarlaActorPool.set_world(self.world) self.prepare_ego_vehicles(config) self.prepare_camera(config) scenario = scenario_class(self.world, rss_params, self.filename_traj, self.ego_vehicles, config, args.randomize, args.debug) result = True except Exception as exception: print("The scenario cannot be loaded") traceback.print_exc() print(exception) self.cleanup() pass self.load_and_run_scenario(args, config, scenario) rob = robustness.getRobustness(self.filename_traj) return rob
def __init__(self, args): """ Setup CARLA client and world Setup ScenarioManager """ self._args = args if args.timeout: self.client_timeout = float(args.timeout) # First of all, we need to create the client that will send the requests # to the simulator. Here we'll assume the simulator is accepting # requests in the localhost at port 2000. self.client = carla.Client(args.host, int(args.port)) self.client.set_timeout(self.client_timeout) # debug the traffic manager port number # print('tf port: ', int(self._args.trafficManagerPort)) self.traffic_manager = self.client.get_trafficmanager( int(self._args.trafficManagerPort)) # todo version check is skipped # dist = pkg_resources.get_distribution("carla") # if LooseVersion(dist.version) < LooseVersion('0.9.10'): # raise ImportError("CARLA version 0.9.10 or newer required. CARLA version found: {}".format(dist)) # Load agent if requested via command line args # If something goes wrong an exception will be thrown by importlib (ok here) if self._args.agent is not None: module_name = os.path.basename(args.agent).split('.')[0] sys.path.insert(0, os.path.dirname(args.agent)) self.module_agent = importlib.import_module(module_name) # Create the ScenarioManager self.manager = ScenarioManager(self._args.debug, self._args.sync, self._args.timeout) # Create signal handler for SIGINT self._shutdown_requested = False if sys.platform != 'win32': signal.signal(signal.SIGHUP, self._signal_handler) signal.signal(signal.SIGINT, self._signal_handler) signal.signal(signal.SIGTERM, self._signal_handler) self._start_wall_time = datetime.now()
def run_openscenario(self, args): """ Run openscenario """ # Load the scenario configurations provided in the config file if not os.path.isfile(args.openscenario): print("File does not exist") self.cleanup() return config = OpenScenarioConfiguration(args.openscenario) if not self.load_world(args, config.town): self.cleanup() return # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Prepare scenario print("Preparing scenario: " + config.name) try: CarlaActorPool.set_world(self.world) self.prepare_ego_vehicles(config, args.waitForEgo) scenario = OpenScenario(world=self.world, ego_vehicles=self.ego_vehicles, config=config, config_file=args.openscenario, timeout=100000) except Exception as exception: print("The scenario cannot be loaded") if args.debug: traceback.print_exc() print(exception) self.cleanup() return self.load_and_run_scenario(args, config, scenario) self.cleanup(ego=(not args.waitForEgo)) print("No more scenarios .... Exiting")
def __init__(self, args): """ Setup CARLA client and world Setup ScenarioManager """ # First of all, we need to create the client that will send the requests # to the simulator. Here we'll assume the simulator is accepting # requests in the localhost at port 2000. client = carla.Client(args.host, int(args.port)) client.set_timeout(self.client_timeout) # Once we have a client we can retrieve the world that is currently # running. self.world = client.get_world() # Wait for the world to be ready self.world.wait_for_tick(self.wait_for_world) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug)
def run(self, args): """ Run all scenarios according to provided commandline args """ # 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 if args.scenario.startswith("group:"): scenario_configurations = parse_scenario_configuration( args.scenario, args.scenario) else: scenario_config_file = find_scenario_config(args.scenario) if scenario_config_file is None: print("Configuration for scenario {} cannot be found!". format(args.scenario)) continue scenario_configurations = parse_scenario_configuration( scenario_config_file, args.scenario) # Execute each configuration for config in scenario_configurations: #self.world = self.client.load_world(config.town) CarlaActorPool.set_client(self.client) CarlaDataProvider.set_world(self.world) # Wait for the world to be ready self.world.wait_for_tick(self.wait_for_world) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Prepare scenario print("Preparing scenario: " + config.name) scenario_class = ScenarioRunner.get_scenario_class_or_fail( config.type) try: CarlaActorPool.set_world(self.world) self.prepare_ego_vehicle(config) scenario = scenario_class(self.world, self.ego_vehicle, 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() continue # Load scenario and run it self.manager.load_scenario(scenario) self.manager.run_scenario() # Provide outputs if required self.analyze_scenario(args, config) # Stop scenario and cleanup self.manager.stop_scenario() scenario.remove_all_actors() self.cleanup() print("No more scenarios .... Exiting")
def load_scenario(self): self.manager = ScenarioManager(self.world, False) self.manager.load_scenario(self.scenario)
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 # 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) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Load scenario and run it self.manager.load_scenario(scenario) self.manager.run_scenario() # Provide outputs if required self._analyze_scenario(args, config) # Stop scenario and _cleanup self.manager.stop_scenario() scenario.remove_all_actors() self._cleanup()
def run(self, args): """ Run all scenarios according to provided commandline args """ # Prepare CARLA server self._carla_server.reset(args.host, args.port) self._carla_server.wait_until_ready() # 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 if args.scenario.startswith("group:"): scenario_configurations = parse_scenario_configuration( args.scenario, args.scenario) else: scenario_config_file = find_scenario_config(args.scenario) if scenario_config_file is None: print("Configuration for scenario {} cannot be found!". format(args.scenario)) continue scenario_configurations = parse_scenario_configuration( scenario_config_file, args.scenario) # Execute each configuration for config in scenario_configurations: # create agent instance self.agent_instance = getattr( self.module_agent, self.module_agent.__name__)(args.config) # Prepare scenario print("Preparing scenario: " + config.name) scenario_class = ChallengeEvaluator.get_scenario_class_or_fail( config.type) client = carla.Client(args.host, int(args.port)) client.set_timeout(self.client_timeout) # Once we have a client we can retrieve the world that is currently # running. self.world = client.load_world(config.town) # Wait for the world to be ready self.world.wait_for_tick(self.wait_for_world) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) try: self.prepare_actors(config) lat_ref, lon_ref = self._get_latlon_ref() compact_route = self.compress_route( config.route.data, config.ego_vehicle.transform.location, config.target.transform.location) gps_route = self.location_route_to_gps( compact_route, lat_ref, lon_ref) self.agent_instance.set_global_plan(gps_route) scenario = scenario_class(self.world, self.ego_vehicle, self.actors, config.town, args.randomize, args.debug, config) except Exception as exception: print("The scenario cannot be loaded") print(exception) self.cleanup(ego=True) continue # Load scenario and run it self.manager.load_scenario(scenario) # debug if args.route_visible: locations_route, _ = zip(*config.route.data) self.draw_waypoints(locations_route, vertical_shift=1.0, persistency=scenario.timeout) self.manager.run_scenario(self.agent_instance) # Provide outputs if required self.analyze_scenario(args, config) # Stop scenario and cleanup self.manager.stop_scenario() del scenario self.cleanup(ego=True) self.agent_instance.destroy() self.final_summary(args) # stop CARLA server self._carla_server.stop()
def run_openscenario(self, args): """ Run openscenario """ # Load the scenario configurations provided in the config file if not os.path.isfile(args.openscenario): print("File does not exist") self.cleanup() return CarlaActorPool.set_client(self.client) CarlaDataProvider.set_world(self.world) config = OpenScenarioConfiguration(args.openscenario) if args.reloadWorld: self.world = self.client.load_world(config.town) else: if CarlaDataProvider.get_map().name != config.town: print("The CARLA server uses the wrong map!") print("This scenario requires to use map {}".format( config.town)) self.cleanup() return # Wait for the world to be ready self.world.wait_for_tick(self.wait_for_world) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Prepare scenario print("Preparing scenario: " + config.name) try: CarlaActorPool.set_world(self.world) self.prepare_ego_vehicles(config, args.waitForEgo) scenario = OpenScenario(world=self.world, ego_vehicles=self.ego_vehicles, config=config, config_file=args.openscenario, timeout=100000) except Exception as exception: print("The scenario cannot be loaded") if args.debug: traceback.print_exc() print(exception) self.cleanup() return # Load scenario and run it self.manager.load_scenario(scenario) self.manager.run_scenario() # Provide outputs if required self.analyze_scenario(args, config) # Stop scenario and cleanup self.manager.stop_scenario() scenario.remove_all_actors() self.cleanup(ego=(not args.waitForEgo)) print("No more scenarios .... Exiting")
def run(self, args): """ Run all scenarios according to provided commandline args """ if args.openscenario: self.run_openscenario(args) return # 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 = 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 = parse_scenario_configuration( scenario_config_file, args.scenario) # Execute each configuration config_counter = 0 for config in scenario_configurations: if args.reloadWorld: self.world = self.client.load_world(config.town) else: if CarlaDataProvider.get_map().name != config.town: print("The CARLA server uses the wrong map!") print("This scenario requires to use map {}".format( config.town)) self.cleanup() continue CarlaActorPool.set_client(self.client) CarlaDataProvider.set_world(self.world) # Wait for the world to be ready self.world.wait_for_tick(self.wait_for_world) # Create scenario manager self.manager = ScenarioManager(self.world, args.debug) # Prepare scenario print("Preparing scenario: " + config.name) scenario_class = self.get_scenario_class_or_fail(config.type) try: CarlaActorPool.set_world(self.world) self.prepare_ego_vehicles( config, args.waitForEgo or (config_counter > 0)) 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() config_counter += 1 continue # Load scenario and run it self.manager.load_scenario(scenario) self.manager.run_scenario() # Provide outputs if required self.analyze_scenario(args, config) # Stop scenario and cleanup self.manager.stop_scenario() scenario.remove_all_actors() self.cleanup() config_counter += 1 self.cleanup(ego=(not args.waitForEgo)) print("No more scenarios .... Exiting")