def cleanup(self, ego=True): """ Remove and destroy all actors """ for scenario in self._list_scenarios: # Reset scenario status for proper cleanup scenario.scenario.terminate() # Do not call del here! Directly enforce the actor removal scenario.remove_all_actors() scenario = None self._client.stop_recorder() # We need enumerate here, otherwise the actors are not properly removed for i, _ in enumerate(self._instanced_sensors): if self._instanced_sensors[i] is not None: self._instanced_sensors[i].stop() self._instanced_sensors[i].destroy() self._instanced_sensors[i] = None self._instanced_sensors = [] self._sensor_interface.destroy() # We stop the sensors first to avoid problems CarlaActorPool.cleanup() CarlaDataProvider.cleanup() if ego and self._ego_actor is not None: self._ego_actor.destroy() self._ego_actor = None logging.debug("Removed Ego Vehicle") if self.world is not None: self.world = None
def _initialize_actors(self, config): """ Custom initialization """ first_vehicle_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._first_vehicle_location) second_vehicle_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._second_vehicle_location) second_vehicle_waypoint = second_vehicle_waypoint.get_left_lane() first_vehicle_transform = carla.Transform( first_vehicle_waypoint.transform.location, first_vehicle_waypoint.transform.rotation) second_vehicle_transform = carla.Transform( second_vehicle_waypoint.transform.location, second_vehicle_waypoint.transform.rotation) first_vehicle = CarlaActorPool.request_new_actor( 'vehicle.nissan.patrol', first_vehicle_transform) second_vehicle = CarlaActorPool.request_new_actor( 'vehicle.audi.tt', second_vehicle_transform) self.other_actors.append(first_vehicle) self.other_actors.append(second_vehicle) self._first_actor_transform = first_vehicle_transform self._second_actor_transform = second_vehicle_transform
def __init__(self, debug=False, name="TrafficJamChecker"): super(TrafficJamChecker, self).__init__(name) self.debug = debug self.blackboard = Blackboard() self.world = CarlaDataProvider.get_world() self.map = CarlaDataProvider.get_map() self.list_intersection_waypoints = [] # remove initial collisions during setup list_actors = list(CarlaActorPool.get_actors()) for _, actor in list_actors: if actor.attributes['role_name'] == 'autopilot': if detect_lane_obstacle(actor, margin=0.2): CarlaActorPool.remove_actor_by_id(actor.id) # prepare a table to check for stalled vehicles during the execution of the scenario self.table_blocked_actors = {} current_game_time = GameTime.get_time() for actor_id, actor in CarlaActorPool.get_actors(): if actor.attributes['role_name'] == 'autopilot': actor.set_autopilot(True) self.table_blocked_actors[actor_id] = { 'location': actor.get_location(), 'time': current_game_time } self.logger.debug("%s.__init__()" % (self.__class__.__name__))
def cleanup(self, ego=False): """ Remove and destroy all actors """ # We need enumerate here, otherwise the actors are not properly removed if hasattr(self, '_sensors_list'): for i, _ in enumerate(self._sensors_list): if self._sensors_list[i] is not None: self._sensors_list[i].stop() self._sensors_list[i].destroy() self._sensors_list[i] = None self._sensors_list = [] for i, _ in enumerate(self.actors): if self.actors[i] is not None: self.actors[i].destroy() self.actors[i] = None self.actors = [] CarlaActorPool.cleanup() CarlaDataProvider.cleanup() if ego and self.ego_vehicle is not None: self.ego_vehicle.destroy() self.ego_vehicle = None
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 _cleanup(self): """ Remove and destroy all actors """ if self.world is not None and self.manager is not None \ and self._args.agent and self.manager.get_running_status(): # Reset to asynchronous mode settings = self.world.get_settings() settings.synchronous_mode = False settings.fixed_delta_seconds = None self.world.apply_settings(settings) self.client.stop_recorder() self.manager.cleanup() CarlaDataProvider.cleanup() CarlaActorPool.cleanup() for i, _ in enumerate(self.ego_vehicles): if self.ego_vehicles[i]: if not self._args.waitForEgo: print("Destroying ego vehicle {}".format( self.ego_vehicles[i].id)) self.ego_vehicles[i].destroy() self.ego_vehicles[i] = None self.ego_vehicles = [] if self.agent_instance: self.agent_instance.destroy() self.agent_instance = None
def update(self): new_status = py_trees.common.Status.RUNNING if self._actor: CarlaActorPool.remove_actor_by_id(self._actor.id) self._actor = None new_status = py_trees.common.Status.SUCCESS return new_status
def remove_all_actors(self): """ Remove all actors """ for i, _ in enumerate(self.other_actors): if self.other_actors[i] is not None: if CarlaActorPool.actor_id_exists(self.other_actors[i].id): CarlaActorPool.remove_actor_by_id(self.other_actors[i].id) self.other_actors[i] = None self.other_actors = []
def _initialize_actors(self, config): """ Custom initialization """ self._other_actor_transform = config.other_actors[0].transform first_vehicle_transform = carla.Transform( carla.Location( config.other_actors[0].transform.location.x, config.other_actors[0].transform.location.y, config.other_actors[0].transform.location.z - 500, ), config.other_actors[0].transform.rotation, ) try: first_vehicle = CarlaActorPool.request_new_actor( config.other_actors[0].model, self._other_actor_transform) except RuntimeError as r_error: raise r_error first_vehicle.set_transform(first_vehicle_transform) self.other_actors.append(first_vehicle) self._other_actor_transform2 = config.other_actors[1].transform first_vehicle_transform2 = carla.Transform( carla.Location( config.other_actors[1].transform.location.x, config.other_actors[1].transform.location.y, config.other_actors[1].transform.location.z, ), config.other_actors[1].transform.rotation, ) try: first_vehicle2 = CarlaActorPool.request_new_actor( config.other_actors[1].model, self._other_actor_transform2) except RuntimeError as r_error: raise r_error first_vehicle2.set_transform(first_vehicle_transform2) self.other_actors.append(first_vehicle2) self._other_actor_transform3 = config.other_actors[2].transform first_vehicle_transform3 = carla.Transform( carla.Location( config.other_actors[2].transform.location.x, config.other_actors[2].transform.location.y, config.other_actors[2].transform.location.z, ), config.other_actors[2].transform.rotation, ) try: first_vehicle3 = CarlaActorPool.request_new_actor( config.other_actors[2].model, self._other_actor_transform3) except RuntimeError as r_error: raise r_error first_vehicle3.set_transform(first_vehicle_transform3) self.other_actors.append(first_vehicle3) print("Init done.")
def _load_and_wait_for_world(self, town, ego_vehicles=None): """ Load a new CARLA world and provide data to CarlaActorPool and CarlaDataProvider """ if self._args.reloadWorld: self.world = self.client.load_world(town) else: # if the world should not be reloaded, wait at least until all ego vehicles are ready ego_vehicle_found = False if self._args.waitForEgo: while not ego_vehicle_found and not self._shutdown_requested: vehicles = self.client.get_world().get_actors().filter( 'vehicle.*') for ego_vehicle in ego_vehicles: ego_vehicle_found = False for vehicle in vehicles: if vehicle.attributes[ 'role_name'] == ego_vehicle.rolename: ego_vehicle_found = True break if not ego_vehicle_found: print("Not all ego vehicles ready. Waiting ... ") time.sleep(1) break self.world = self.client.get_world() CarlaActorPool.set_client(self.client) CarlaActorPool.set_world(self.world) CarlaDataProvider.set_world(self.world) settings = self.world.get_settings() settings.fixed_delta_seconds = 1.0 / self.frame_rate self.world.apply_settings(settings) if self._args.agent: settings = self.world.get_settings() settings.synchronous_mode = True self.world.apply_settings(settings) # Wait for the world to be ready if self.world.get_settings().synchronous_mode: CarlaDataProvider.perform_carla_tick() else: self.world.wait_for_tick() if CarlaDataProvider.get_map( ).name != town and CarlaDataProvider.get_map().name != "OpenDriveMap": print("The CARLA server uses the wrong map: {}".format( CarlaDataProvider.get_map().name)) print("This scenario requires to use map: {}".format(town)) return False return True
def _initialize_actors(self, config): """ Custom initialization """ self._distance = random.sample(range(10, 80), 3) self._distance = sorted(self._distance) first_loc, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._distance[0]) second_loc, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._distance[1]) third_loc, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._distance[2]) self.loc_list.extend([first_loc, second_loc, third_loc]) self._dist_prop = [x - 2 for x in self._distance] self.first_loc_prev, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._dist_prop[0]) self.sec_loc_prev, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._dist_prop[1]) self.third_loc_prev, _ = get_location_in_distance_from_wp( self._reference_waypoint, self._dist_prop[2]) self.first_transform = carla.Transform(self.first_loc_prev) self.sec_transform = carla.Transform(self.sec_loc_prev) self.third_transform = carla.Transform(self.third_loc_prev) self.first_transform = carla.Transform( carla.Location(self.first_loc_prev.x, self.first_loc_prev.y, self.first_loc_prev.z)) self.sec_transform = carla.Transform( carla.Location(self.sec_loc_prev.x, self.sec_loc_prev.y, self.sec_loc_prev.z)) self.third_transform = carla.Transform( carla.Location(self.third_loc_prev.x, self.third_loc_prev.y, self.third_loc_prev.z)) first_debris = CarlaActorPool.request_new_actor( 'static.prop.dirtdebris01', self.first_transform) second_debris = CarlaActorPool.request_new_actor( 'static.prop.dirtdebris01', self.sec_transform) third_debris = CarlaActorPool.request_new_actor( 'static.prop.dirtdebris01', self.third_transform) first_debris.set_transform(self.first_transform) second_debris.set_transform(self.sec_transform) third_debris.set_transform(self.third_transform) self.obj.extend([first_debris, second_debris, third_debris]) for debris in self.obj: debris.set_simulate_physics(False) self.other_actors.append(first_debris) self.other_actors.append(second_debris) self.other_actors.append(third_debris)
def remove_all_actors(self): """ Remove all actors """ for i, _ in enumerate(self.other_actors): if self.other_actors[i] is not None: # print("removed other actor position: {}, {}, {}".format(self.other_actors[i].get_location().x, # self.other_actors[i].get_location().y, # self.other_actors[i].get_location().z)) if CarlaActorPool.actor_id_exists(self.other_actors[i].id): CarlaActorPool.remove_actor_by_id(self.other_actors[i].id) self.other_actors[i] = None self.other_actors = []
def _initialize_actors(self, config): """ Custom initialization """ first_actor_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._first_vehicle_location) second_actor_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._second_vehicle_location) second_actor_waypoint = second_actor_waypoint.get_left_lane() first_actor_transform = carla.Transform( first_actor_waypoint.transform.location, first_actor_waypoint.transform.rotation) if self._obstacle_type == 'vehicle': first_actor_model = 'vehicle.nissan.micra' else: first_actor_transform.rotation.yaw += 90 first_actor_model = 'static.prop.streetbarrier' second_prop_waypoint = first_actor_waypoint.next(2.0)[0] position_yaw = second_prop_waypoint.transform.rotation.yaw + 90 offset_location = carla.Location( 0.50 * second_prop_waypoint.lane_width * math.cos(math.radians(position_yaw)), 0.50 * second_prop_waypoint.lane_width * math.sin(math.radians(position_yaw))) second_prop_transform = carla.Transform( second_prop_waypoint.transform.location + offset_location, first_actor_transform.rotation) second_prop_actor = CarlaActorPool.request_new_actor( first_actor_model, second_prop_transform) second_prop_actor.set_simulate_physics(True) first_actor = CarlaActorPool.request_new_actor(first_actor_model, first_actor_transform) first_actor.set_simulate_physics(True) second_actor = CarlaActorPool.request_new_actor( 'vehicle.audi.tt', second_actor_waypoint.transform) self.other_actors.append(first_actor) self.other_actors.append(second_actor) if self._obstacle_type != 'vehicle': self.other_actors.append(second_prop_actor) self._source_transform = second_actor_waypoint.transform sink_waypoint = second_actor_waypoint.next(1)[0] while not sink_waypoint.is_intersection: sink_waypoint = sink_waypoint.next(1)[0] self._sink_location = sink_waypoint.transform.location self._first_actor_transform = first_actor_transform self._second_actor_transform = second_actor_waypoint.transform self._third_actor_transform = second_prop_transform
def load_world(self, town): """ Load a new CARLA world and provide data to CarlaActorPool and CarlaDataProvider """ self.world = self.client.load_world(town) # Wait for the world to be ready self.world.tick() CarlaActorPool.set_client(self.client) CarlaActorPool.set_world(self.world) CarlaDataProvider.set_world(self.world) return True
def retrieve_wold(client): world = client.get_world() world_id = world.id settings = world.get_settings() # settings.synchronous_mode = True world.apply_settings(settings) CarlaActorPool.set_client(client) CarlaActorPool.set_world(world) CarlaDataProvider.set_world(world) return world
def stop_scenario(self): """ This function triggers a proper termination of a scenario """ if self.scenario is not None: self.scenario.terminate() if self._agent is not None: self._agent.cleanup() self._agent = None CarlaDataProvider.cleanup() CarlaActorPool.cleanup()
def test_route_parser(self): args = Arguments() client = carla.Client(args.host, int(args.port)) client.set_timeout(25.0) challenge = ChallengeEvaluator(args) filename = os.path.join(self.root_route_file_position, 'all_towns_traffic_scenarios.json') world_annotations = parser.parse_annotations_file(filename) # retrieve routes # Which type of file is expected ???? filename = os.path.join(self.root_route_file_position, 'routes_training.xml') list_route_descriptions = parser.parse_routes_file(filename) # For each of the routes to be evaluated. for route_description in list_route_descriptions: if route_description['town_name'] == 'Town03' or route_description[ 'town_name'] == 'Town01': continue print(" TOWN: ", route_description['town_name']) challenge.world = client.load_world(route_description['town_name']) # Set the actor pool so the scenarios can prepare themselves when needed CarlaActorPool.set_world(challenge.world) CarlaDataProvider.set_world(challenge.world) # find and filter potential scenarios # Returns the interpolation in a different format challenge.world.wait_for_tick() gps_route, route_description[ 'trajectory'] = interpolate_trajectory( challenge.world, route_description['trajectory']) potential_scenarios_definitions, existent_triggers = parser.scan_route_for_scenarios( route_description, world_annotations) for trigger_id, possible_scenarios in potential_scenarios_definitions.items( ): print(" For trigger ", trigger_id, " -- ", possible_scenarios[0]['trigger_position']) for scenario in possible_scenarios: print(" ", scenario['name']) challenge.cleanup(ego=True)
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(CarlaActorPool.setup_actor(vehicle.model, vehicle.transform, vehicle.rolename, True, 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) # sync state CarlaDataProvider.get_world().tick()
def _initialize_dynamic_obstacles_ahead(self, actor_dict): actor_dict.speed = 3 + (0.4 * actor_dict.num_lane_changes) while True: try: actor_dict.start_transform, orientation = actor_dict._calculate_transform( ) walker = CarlaActorPool.request_new_actor( 'walker.*', actor_dict.start_transform) walker.set_transform(actor_dict.start_transform) walker.set_simulate_physics(enabled=False) # print("walker spawned at" + str(actor_dict.start_transform)) break except RuntimeError as r: # actor_dict._update_transform() actor_dict.start_dist += 0.4 # print("self.start_dist after update: " + str(self.start_dist)) actor_dict.spawn_attempted += 1 if actor_dict.spawn_attempted >= actor_dict._number_of_attempts: raise r default = actor_dict._calculate_default(actor_dict.start_transform) walker.set_transform(default) index = len(self.other_actors) actor_dict.index = index # print("index of dynamic crossing actor: " + str(index)) self.other_actors.append(walker)
def update(self): new_status = py_trees.common.Status.RUNNING if self._actor_limit > 0: world_actors = self._world.get_actors() spawn_point_blocked = False if (self._last_blocking_actor and self._spawn_point.location.distance( self._last_blocking_actor.get_location()) < self._threshold): spawn_point_blocked = True if not spawn_point_blocked: for actor in world_actors: if self._spawn_point.location.distance( actor.get_location()) < self._threshold: spawn_point_blocked = True self._last_blocking_actor = actor break if not spawn_point_blocked: try: new_actor = CarlaActorPool.request_new_actor( np.random.choice(self._actor_types), self._spawn_point) self._actor_limit -= 1 self._queue.put(new_actor) except: print("ActorSource unable to spawn actor") return new_status
def prepare_ego_vehicles(self, config, wait_for_ego_vehicles=False): """ Spawn or update the ego vehicle according to its parameters provided in config As the world is re-loaded for every scenario, no ego exists so far """ if not wait_for_ego_vehicles: for vehicle in config.ego_vehicles: self.ego_vehicles.append(CarlaActorPool.setup_actor(vehicle.model, vehicle.transform, vehicle.rolename, True)) else: ego_vehicle_missing = True while ego_vehicle_missing: self.ego_vehicles = [] ego_vehicle_missing = False for ego_vehicle in config.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(config.ego_vehicles[i].transform) self._start_time = CarlaDataProvider.get_world().tick()
def _spawn_blocker(self, transform): """ Spawn the blocker prop that blocks the vision from the egovehicle of the jaywalker :return: """ # static object transform shift = 0.9 x_ego = self._reference_waypoint.transform.location.x y_ego = self._reference_waypoint.transform.location.y x_cycle = transform.location.x y_cycle = transform.location.y x_static = x_ego + shift * (x_cycle - x_ego) y_static = y_ego + shift * (y_cycle - y_ego) spawn_point_wp = self.ego_vehicles[0].get_world().get_map( ).get_waypoint(transform.location) self.transform2 = carla.Transform( carla.Location(x_static, y_static, spawn_point_wp.transform.location.z + 0.3)) static = CarlaActorPool.request_new_actor('static.prop.vendingmachine', self.transform2) static.set_simulate_physics(enabled=False) return static
def _initialize_actors(self, config): # add actors from xml file for actor in config.other_actors: vehicle = CarlaActorPool.request_new_actor(actor.model, actor.transform) self.other_actors.append(vehicle) vehicle.set_simulate_physics(enabled=False) # fast vehicle, tesla # transform visible fast_car_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._fast_vehicle_distance) self.fast_car_visible = carla.Transform( carla.Location(fast_car_waypoint.transform.location.x, fast_car_waypoint.transform.location.y, fast_car_waypoint.transform.location.z + 1), fast_car_waypoint.transform.rotation) # slow vehicle, vw # transform visible slow_car_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._slow_vehicle_distance) self.slow_car_visible = carla.Transform( carla.Location(slow_car_waypoint.transform.location.x, slow_car_waypoint.transform.location.y, slow_car_waypoint.transform.location.z), slow_car_waypoint.transform.rotation)
def _initialize_stationary_obstacles_ahead(self, actor_dict): static = CarlaActorPool.request_new_actor('vehicle.nissan.patrol', actor_dict.start_transform) static.set_simulate_physics(True) index = len(self.other_actors) actor_dict.index = index # print("index of Stationary obstacle actor: " + str(index)) self.other_actors.append(static)
def cleanup(self, ego=False): """ Remove and destroy all actors """ settings = self.world.get_settings() settings.synchronous_mode = False self.world.apply_settings(settings) CarlaDataProvider.cleanup() CarlaActorPool.cleanup() for i, _ in enumerate(self.ego_vehicles): if self.ego_vehicles[i]: if ego: self.ego_vehicles[i].destroy() self.ego_vehicles[i] = None self.ego_vehicles = []
def _initialize_cut_in(self, actor_dict): vehicle = CarlaActorPool.request_new_actor( 'vehicle.nissan.patrol', actor_dict.start_transform) #default_transform) vehicle.set_simulate_physics(enabled=False) index = len(self.other_actors) actor_dict.index = index # print("index of Cut In actor: " + str(index)) self.other_actors.append(vehicle)
def _spawn_adversary(self, transform, orientation_yaw): self._time_to_reach *= self._num_lane_changes if self._adversary_type is False: self._walker_yaw = orientation_yaw self._other_actor_target_velocity = 3 + (0.4 * self._num_lane_changes) walker = CarlaActorPool.request_new_actor('walker.*', transform) adversary = walker else: self._other_actor_target_velocity = self._other_actor_target_velocity * self._num_lane_changes first_vehicle = CarlaActorPool.request_new_actor( 'vehicle.diamondback.century', transform) first_vehicle.set_simulate_physics(enabled=False) adversary = first_vehicle return adversary
def _initialize_actors(self, config): """ Custom initialization """ num_actors = 0 actor_locations = [] while num_actors < self._num_actors: actor_dict = dict() actor_dict["speed"] = random.randint(10, 20) actor_dict["location"] = self.generate_valid_location( actor_locations) actor_locations.append(actor_dict["location"]) print("actor " + str(num_actors) + " location: " + str(actor_dict["location"])) self.actor_list[num_actors] = actor_dict num_actors += 1 num_actors = self._num_actors - 1 while num_actors >= 0: vehicle_location = self.actor_list[num_actors]["location"] # first_vehicle_waypoint, _ = get_waypoint_in_distance(self._reference_waypoint, vehicle_location) first_vehicle_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, vehicle_location) lane = random.randint(0, 2) if lane == 0: pass elif lane == 1: left_lane = first_vehicle_waypoint.get_left_lane() if left_lane: first_vehicle_waypoint = left_lane elif lane == 2: right_lane = first_vehicle_waypoint.get_right_lane() if right_lane: first_vehicle_waypoint = right_lane # self.actor_list[num_actors]["transform"] = carla.Transform( # carla.Location(first_vehicle_waypoint.transform.location.x, # first_vehicle_waypoint.transform.location.y, # first_vehicle_waypoint.transform.location.z + 1), # first_vehicle_waypoint.transform.rotation) other_actor_transform = carla.Transform( carla.Location(first_vehicle_waypoint.transform.location.x, first_vehicle_waypoint.transform.location.y, first_vehicle_waypoint.transform.location.z + 1), first_vehicle_waypoint.transform.rotation) self.actor_list[num_actors]["transform"] = other_actor_transform first_vehicle_transform = carla.Transform( carla.Location(other_actor_transform.location.x, other_actor_transform.location.y, other_actor_transform.location.z - 500), other_actor_transform.rotation) first_vehicle = CarlaActorPool.request_new_actor( 'vehicle.nissan.patrol', first_vehicle_transform) first_vehicle.set_simulate_physics(enabled=False) self.other_actors.append(first_vehicle) num_actors -= 1
def _initialize_actors(self, config): """ Custom initialization """ first_actor_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._first_actor_location) second_actor_waypoint, _ = get_waypoint_in_distance( self._reference_waypoint, self._second_actor_location) first_actor_transform = carla.Transform( carla.Location(first_actor_waypoint.transform.location.x, first_actor_waypoint.transform.location.y, first_actor_waypoint.transform.location.z - 500), first_actor_waypoint.transform.rotation) self._first_actor_transform = carla.Transform( carla.Location(first_actor_waypoint.transform.location.x, first_actor_waypoint.transform.location.y, first_actor_waypoint.transform.location.z + 1), first_actor_waypoint.transform.rotation) yaw_1 = second_actor_waypoint.transform.rotation.yaw + 90 second_actor_transform = carla.Transform( carla.Location(second_actor_waypoint.transform.location.x, second_actor_waypoint.transform.location.y, second_actor_waypoint.transform.location.z - 500), carla.Rotation(second_actor_waypoint.transform.rotation.pitch, yaw_1, second_actor_waypoint.transform.rotation.roll)) self._second_actor_transform = carla.Transform( carla.Location(second_actor_waypoint.transform.location.x, second_actor_waypoint.transform.location.y, second_actor_waypoint.transform.location.z + 1), carla.Rotation(second_actor_waypoint.transform.rotation.pitch, yaw_1, second_actor_waypoint.transform.rotation.roll)) first_actor = CarlaActorPool.request_new_actor('vehicle.nissan.patrol', first_actor_transform) second_actor = CarlaActorPool.request_new_actor( 'vehicle.diamondback.century', second_actor_transform) first_actor.set_simulate_physics(enabled=False) second_actor.set_simulate_physics(enabled=False) self.other_actors.append(first_actor) self.other_actors.append(second_actor)
def _init(self): super()._init() self._vehicle = CarlaActorPool.get_hero_actor() self._world = self._vehicle.get_world() self._waypoint_planner = RoutePlanner(4.0, 50) self._waypoint_planner.set_route(self._plan_gps_HACK, True) self._traffic_lights = list()