def _build_background_scenario(self, world, ego_vehicle, town_name, timeout=300, debug_mode=False):
        """
        Create the BackgroundActivity scenario
        """
        scenario_configuration = ScenarioConfiguration()
        scenario_configuration.route = None
        scenario_configuration.town = town_name

        model = 'vehicle.*'
        transform = carla.Transform()

        if town_name == 'Town01' or town_name == 'Town02':
            amount = 120
        elif town_name == 'Town03' or town_name == 'Town05':
            amount = 120
        elif town_name == 'Town04':
            amount = 200
        elif town_name == 'Town06' or town_name == 'Town07':
            amount = 150
        elif town_name == 'Town08':
            amount = 180
        elif town_name == 'Town09':
            amount = 350
        else:
            amount = 0

        actor_configuration_instance = ActorConfigurationData(
            model, transform, rolename='background', autopilot=True, random=True, amount=amount)
        scenario_configuration.other_actors = [actor_configuration_instance]

        return BackgroundActivity(world, [ego_vehicle], scenario_configuration,
                                  timeout=timeout, debug_mode=debug_mode)
Beispiel #2
0
    def _build_background(self, background_definition, timeout):
        """
        Build background scenario. Adding pedestrians and vehicles wandering
        around.
        :param background_definition:
        :param timeout:
        :return:
        """

        scenario_configuration = ScenarioConfiguration()
        scenario_configuration.route = None
        scenario_configuration.town = self._town_name
        # TODO The random seed should be set.
        # Also the crossing factor should be specified on the benchmark itself.
        configuration_instances_vehicles = []
        configuration_instances_walkers = []
        # If there are walkers there should be cross factors otherwise it is 0
        cross_factor = 0.0

        if 'walker.*'  in background_definition:

            model = 'walker'
            transform = carla.Transform()
            autopilot = True
            random_location = True
            actor_configuration_instance = ActorConfigurationData(model, transform,
                                                                  autopilot=autopilot,
                                                                  random=random_location,
                                                                  amount=int(
                                                                      background_definition[
                                                                          'walker.*']),
                                                                  category='walker')
            configuration_instances_walkers.append(actor_configuration_instance)

            if "cross_factor" not in background_definition:
                raise ValueError(" If there are walkers on the json file "
                                 "background scenario there must also be a cross factor")

            cross_factor = background_definition["cross_factor"]

        if 'vehicle.*' in background_definition:
            model = 'vehicle'
            transform = carla.Transform()
            autopilot = True
            random_location = True
            actor_configuration_instance = ActorConfigurationData(model, transform,
                                                                  autopilot=autopilot,
                                                                  random=random_location,
                                                                  amount=int(background_definition[
                                                                      "vehicle.*"]),
                                                                  category='vehicle')
            configuration_instances_vehicles.append(actor_configuration_instance)

        scenario_configuration.other_actors = configuration_instances_vehicles + \
                                              configuration_instances_walkers


        return BackgroundActivity(self.world, self._ego_actor, scenario_configuration,
                                  cross_factor=cross_factor,
                                  timeout=timeout, debug_mode=False)
    def __init__(self, world, config, debug_mode=False, criteria_enable=True, timeout=300):
        """
        Setup all relevant parameters and create scenarios along route
        """

        self.config = config
        self.route = None
        self.sampled_scenarios_definitions = None

        self._update_route(world, config, debug_mode)

        ego_vehicle = self._update_ego_vehicle()

        self.list_scenarios = self._build_scenario_instances(world,
                                                             ego_vehicle,
                                                             self.sampled_scenarios_definitions,
                                                             scenarios_per_tick=5,
                                                             timeout=self.timeout,
                                                             debug_mode=debug_mode)

        self.list_scenarios.append(BackgroundActivity(
            world, ego_vehicle, self.config, self.route, timeout=self.timeout))

        super(RouteScenario, self).__init__(name=config.name,
                                            ego_vehicles=[ego_vehicle],
                                            config=config,
                                            world=world,
                                            debug_mode=False,
                                            terminate_on_failure=False,
                                            criteria_enable=criteria_enable)
    def _build_background_scenario(self,
                                   world,
                                   ego_vehicle,
                                   town_name,
                                   timeout=300,
                                   debug_mode=False):
        """
        Create the BackgroundActivity scenario
        """
        scenario_configuration = ScenarioConfiguration()
        scenario_configuration.route = None
        scenario_configuration.town = town_name

        return BackgroundActivity(world, [ego_vehicle],
                                  scenario_configuration,
                                  timeout=timeout,
                                  debug_mode=debug_mode)
Beispiel #5
0
    def _build_background(self, background_definition, timeout):
        scenario_configuration_vehicle = ScenarioConfiguration()
        scenario_configuration_vehicle.route = None
        scenario_configuration_vehicle.town = self._town_name
        scenario_configuration_walker = ScenarioConfiguration()
        scenario_configuration_walker.route = None
        scenario_configuration_walker.town = self._town_name
        # TODO The random seed should be set
        configuration_instances_vehicles = []
        configuration_instances_walkers = []
        for key, numbers in background_definition.items():
            if 'walker' not in key:
                model = key
                transform = carla.Transform()
                autopilot = True
                random = True
                actor_configuration_instance = ActorConfigurationData(
                    model,
                    transform,
                    autopilot,
                    random,
                    amount=background_definition[key])
                configuration_instances_vehicles.append(
                    actor_configuration_instance)
            else:
                model = 'controller.ai.walker'
                transform = carla.Transform()
                autopilot = True
                random = True
                actor_configuration_instance = ActorConfigurationData(
                    model,
                    transform,
                    autopilot,
                    random,
                    amount=background_definition[key])
                configuration_instances_walkers.append(
                    actor_configuration_instance)

        scenario_configuration_vehicle.other_actors = configuration_instances_vehicles
        scenario_configuration_walker.other_actors = configuration_instances_walkers
        return BackgroundActivity(self.world, self._ego_actor, scenario_configuration_vehicle,
                                  timeout=timeout, debug_mode=False), \
            BackgroundActivityWalkers(self.world, self._ego_actor, scenario_configuration_vehicle,
                       timeout=timeout, debug_mode=False)