Пример #1
0
    def _initialize_actors(self, config):
        """
        Set other_actors to the superset of all scenario actors
        """

        if config.background_actors_count < 0:

            # Create the background activity of the route
            town_amount = {
                'Town01': 120,
                'Town02': 100,
                'Town03': 120,
                'Town04': 200,
                'Town05': 120,
                'Town06': 150,
                'Town07': 110,
                'Town08': 180,
                'Town09': 300,
                'Town10': 120,
            }

            amount = town_amount[
                config.town] if config.town in town_amount else 0

        else:

            amount = config.background_actors_count

        new_actors = CarlaDataProvider.request_new_batch_actors(
            'vehicle.*',
            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"
            )

        for _actor in new_actors:
            self.other_actors.append(_actor)

        # Add all the actors of the specific scenarios to self.other_actors
        for scenario in self.list_scenarios:
            self.other_actors.extend(scenario.other_actors)
Пример #2
0
    def _initialize_actors(self, config):
        town_name = config.town
        if town_name in self.town_amount:
            amount = self.town_amount[town_name]
        else:
            amount = 0
        for actor in config.other_actors:
            new_actors = CarlaDataProvider.request_new_batch_actors(
                'vehicle.*',
                amount,
                carla.Transform(),
                autopilot=True,
                rolename='background')
            if new_actors is None:
                raise Exception(
                    "Error: Unable to add the background activity, all spawn points were occupied"
                )

            for _actor in new_actors:
                self.other_actors.append(_actor)
Пример #3
0
    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)