def build_master_scenario(self, route, town_name, timeout=300): # We have to find the target. # we also have to convert the route to the expected format master_scenario_configuration = ScenarioConfiguration() master_scenario_configuration.target = route[-1][ 0] # Take the last point and add as target. master_scenario_configuration.route = convert_transform_to_location( route) master_scenario_configuration.town = town_name # TODO THIS NAME IS BIT WEIRD SINCE THE EGO VEHICLE IS ALREADY THERE, IT IS MORE ABOUT THE TRANSFORM master_scenario_configuration.ego_vehicle = ActorConfigurationData( 'vehicle.lincoln.mkz2017', self.ego_vehicle.get_transform()) master_scenario_configuration.trigger_point = self.ego_vehicle.get_transform( ) CarlaDataProvider.register_actor(self.ego_vehicle) # Provide an initial blackboard entry to ensure all scenarios are running correctly blackboard = py_trees.blackboard.Blackboard() blackboard.set('master_scenario_command', 'scenarios_running') return MasterScenario(self.world, self.ego_vehicle, master_scenario_configuration, timeout=timeout, debug_mode=self.debug > 1)
def load_scenario(self, scenario): """ Load a new scenario """ self.restart() self.scenario = scenario.scenario self.scenario_tree = self.scenario.scenario_tree self.ego_vehicle = scenario.ego_vehicle self.other_actors = scenario.other_actors CarlaDataProvider.register_actor(self.ego_vehicle) CarlaDataProvider.register_actors(self.other_actors)
def build_master_scenario(self, route, town_name, timeout, terminate_on_collision): # We have to find the target. # we also have to convert the route to the expected format master_scenario_configuration = ScenarioConfiguration() master_scenario_configuration.target = route[-1][0] # Take the last point and add as target. master_scenario_configuration.route = convert_transform_to_location(route) master_scenario_configuration.town = town_name master_scenario_configuration.ego_vehicle = ActorConfigurationData('vehicle.lincoln.mkz2017', self._ego_actor.get_transform()) master_scenario_configuration.trigger_point = self._ego_actor.get_transform() CarlaDataProvider.register_actor(self._ego_actor) return MasterScenario(self.world, [self._ego_actor], master_scenario_configuration, timeout=timeout, terminate_on_collision=terminate_on_collision)
def _prepare_ego_vehicles(self, ego_vehicles): """ Spawn or update the ego vehicles """ if not self._args.waitForEgo: for vehicle in ego_vehicles: self.ego_vehicles.append( CarlaDataProvider.request_new_actor( vehicle.model, vehicle.transform, vehicle.rolename, color=vehicle.color, actor_category=vehicle.category)) else: ego_vehicle_missing = True while ego_vehicle_missing: self.ego_vehicles = [] ego_vehicle_missing = False for ego_vehicle in ego_vehicles: ego_vehicle_found = False carla_vehicles = CarlaDataProvider.get_world().get_actors( ).filter('vehicle.*') for carla_vehicle in carla_vehicles: if carla_vehicle.attributes[ 'role_name'] == ego_vehicle.rolename: ego_vehicle_found = True self.ego_vehicles.append(carla_vehicle) break if not ego_vehicle_found: ego_vehicle_missing = True break for i, _ in enumerate(self.ego_vehicles): self.ego_vehicles[i].set_transform(ego_vehicles[i].transform) CarlaDataProvider.register_actor(self.ego_vehicles[i]) # self.traffic_manager.vehicle_percentage_speed_difference(-70) # sync state if CarlaDataProvider.is_sync_mode(): self.world.tick() else: self.world.wait_for_tick()
def test_routes(args): """ Run all routes according to provided commandline args """ # instance a challenge challenge = ChallengeEvaluator(args) # retrieve worlds annotations world_annotations = parser.parse_annotations_file(args.scenarios) # retrieve routes routes = [] route_descriptions_list = parser.parse_routes_file(args.routes) for route_description in route_descriptions_list: if route_description['town_name'] == args.debug_town: routes.append(route_description) # find and filter potential scenarios for each of the evaluated routes # For each of the routes and corresponding possible scenarios to be evaluated. list_scenarios_town = [] if args.debug_town in world_annotations.keys(): list_scenarios_town = world_annotations[args.debug_town] scenarios_current_type = [] for scenario in list_scenarios_town: if args.debug_scenario == scenario['scenario_type']: scenarios_current_type = scenario break for scenario_configuration in scenarios_current_type[ 'available_event_configurations']: scenario_conf = create_configuration_scenario(scenario_configuration, args.debug_scenario) client = carla.Client(args.host, int(args.port)) client.set_timeout(challenge.client_timeout) # load the challenge.world variable to be used during the route challenge.load_world(client, args.debug_town) # Set the actor pool so the scenarios can prepare themselves when needed CarlaActorPool.set_world(challenge.world) # Also se the Data provider pool. CarlaDataProvider.set_world(challenge.world) # tick world so we can start. challenge.world.tick() # create agent challenge.agent_instance = getattr(challenge.module_agent, challenge.module_agent.__name__)( args.config) correct_sensors, error_message = challenge.valid_sensors_configuration( challenge.agent_instance, challenge.track) if not correct_sensors: # the sensor configuration is illegal challenge.report_fatal_error(args.filename, args.show_to_participant, error_message) return waypoint = routes[0]['trajectory'][0] location = carla.Location(x=float(waypoint.attrib['x']), y=float(waypoint.attrib['y']), z=float(waypoint.attrib['z'])) rotation = carla.Rotation(pitch=float(waypoint.attrib['pitch']), yaw=float(waypoint.attrib['yaw'])) challenge.prepare_ego_car(carla.Transform(location, rotation)) CarlaDataProvider.register_actor(challenge.ego_vehicle) list_scenarios = [] list_scenarios += challenge.build_scenario_instances([scenario_conf], args.debug_town) # Tick once to start the scenarios. print(" Running these scenarios --- ", list_scenarios) for scenario in list_scenarios: scenario.scenario.scenario_tree.tick_once() challenge.run_route(list_scenarios, None, True) # clean up for scenario in list_scenarios: del scenario challenge.cleanup(ego=True) challenge.agent_instance.destroy() break # final measurements from the challenge challenge.report_challenge_statistics(args.filename, args.show_to_participant) del challenge
def _initialize_actors(self, config): # initialize background vehicles super(TrainScenario, self)._initialize_actors(config) # initialize background pedestrians town_amount = { 'Town01': 150, 'Town02': 120, 'Town03': 150, 'Town04': 200, 'Town05': 150, 'Town06': 200, 'Town07': 120, 'Town08': 200, 'Town09': 320, 'Town10HD': 150, } amount = town_amount[config.town] if config.town in town_amount else 0 blueprints = CarlaDataProvider._blueprint_library.filter( 'walker.pedestrian.*') spawn_points = [] while len(spawn_points) < amount: spawn_point = carla.Transform() loc = CarlaDataProvider.get_world( ).get_random_location_from_navigation() if (loc != None): spawn_point.location = loc spawn_points.append(spawn_point) batch = [] for spawn_point in spawn_points: walker_bp = random.choice(blueprints) if walker_bp.has_attribute('is_invincible'): walker_bp.set_attribute('is_invincible', 'false') batch.append(carla.command.SpawnActor(walker_bp, spawn_point)) pedestrians = CarlaDataProvider.handle_actor_batch(batch) batch = [] walker_controller_bp = CarlaDataProvider._blueprint_library.find( 'controller.ai.walker') for pedestrian in pedestrians: batch.append( carla.command.SpawnActor(walker_controller_bp, carla.Transform(), pedestrian)) pedestrian_controllers = CarlaDataProvider.handle_actor_batch(batch) CarlaDataProvider.get_world().set_pedestrians_cross_factor(1.0) for controller in pedestrian_controllers: controller.start() controller.go_to_location(CarlaDataProvider.get_world(). get_random_location_from_navigation()) controller.set_max_speed(1.2 + random.random()) for actor in itertools.chain(pedestrians, pedestrian_controllers): if actor is None: continue CarlaDataProvider._carla_actor_pool[actor.id] = actor CarlaDataProvider.register_actor(actor) self.other_actors.append(actor) for scenario in self.list_scenarios: self.other_actors.extend(scenario.other_actors)
def _initialize_actors(self, config): """ Set other_actors to the superset of all scenario actors """ # Create the background activity of the route car_amounts = { 'Town01': [0, 20, 100], 'Town02': [0, 15, 70], } ped_amounts = { 'Town01': [0, 50, 200], 'Town02': [0, 50, 150], } car_amount = car_amounts[self.town_name][self.traffic_idx] ped_amount = ped_amounts[self.town_name][self.traffic_idx] new_actors = CarlaDataProvider.request_new_batch_actors( 'vehicle.*', car_amount, carla.Transform(), autopilot=True, random_location=True, rolename='background') if new_actors is None: raise Exception( "Error: Unable to add the background activity, all spawn points were occupied" ) blueprints = CarlaDataProvider._blueprint_library.filter( 'walker.pedestrian.*') spawn_points = [] while len(spawn_points) < ped_amount: spawn_point = carla.Transform() loc = CarlaDataProvider.get_world( ).get_random_location_from_navigation() if (loc != None): spawn_point.location = loc spawn_points.append(spawn_point) batch = [] for spawn_point in spawn_points: walker_bp = random.choice(blueprints) if walker_bp.has_attribute('is_invincible'): walker_bp.set_attribute('is_invincible', 'false') batch.append(carla.command.SpawnActor(walker_bp, spawn_point)) pedestrians = CarlaDataProvider.handle_actor_batch(batch) batch = [] walker_controller_bp = CarlaDataProvider._blueprint_library.find( 'controller.ai.walker') for pedestrian in pedestrians: batch.append( carla.command.SpawnActor(walker_controller_bp, carla.Transform(), pedestrian)) pedestrian_controllers = CarlaDataProvider.handle_actor_batch(batch) CarlaDataProvider.get_world().set_pedestrians_cross_factor(1.0) for controller in pedestrian_controllers: controller.start() controller.go_to_location(CarlaDataProvider.get_world(). get_random_location_from_navigation()) controller.set_max_speed(1.2 + random.random()) for actor in itertools.chain(pedestrians, pedestrian_controllers): if actor is None: continue CarlaDataProvider._carla_actor_pool[actor.id] = actor CarlaDataProvider.register_actor(actor) self.other_actors.append(actor)