Esempio n. 1
0
    def _setup_scenario_trigger(self, config):
        start_location = None
        if config.trigger_points and config.trigger_points[0]:
            start_waypoint, _ = get_waypoint_in_distance(
                config.trigger_points[0], 10)
            start_location = start_waypoint.location
            #config.trigger_points[0].location     # start location of the scenario

        ego_vehicle_route = CarlaDataProvider.get_ego_vehicle_route()

        if start_location:
            if ego_vehicle_route:
                if config.route_var_name is None:  # pylint: disable=no-else-return
                    return conditions.InTriggerDistanceToLocationAlongRoute(
                        self.ego_vehicles[0], ego_vehicle_route,
                        start_location, 5)
                else:
                    check_name = "WaitForBlackboardVariable: {}".format(
                        config.route_var_name)
                    return conditions.WaitForBlackboardVariable(
                        name=check_name,
                        variable_name=config.route_var_name,
                        variable_value=True,
                        var_init_value=False)

            return conditions.InTimeToArrivalToLocation(
                self.ego_vehicles[0], 2.0, start_location)

        return None
Esempio n. 2
0
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 criteria_enable=True,
                 timeout=60):
        """
        Setup all relevant parameters and create scenario
        """
        # other vehicle parameters
        self._other_actor_target_velocity = 10
        self._wmap = CarlaDataProvider.get_map()
        self._reference_waypoint = self._wmap.get_waypoint(
            config.trigger_points[0].location)
        self._trigger_location = config.trigger_points[0].location
        self._other_actor_transform = None
        self._num_lane_changes = 0
        # Timeout of scenario in seconds
        self.timeout = timeout
        # Total Number of attempts to relocate a vehicle before spawning
        self._number_of_attempts = 6
        # Number of attempts made so far
        self._spawn_attempted = 0

        self._ego_route = CarlaDataProvider.get_ego_vehicle_route()

        super(VehicleTurningRight,
              self).__init__("VehicleTurningRight",
                             ego_vehicles,
                             config,
                             world,
                             debug_mode,
                             criteria_enable=criteria_enable)
    def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True,
                 timeout=60, name="BaseVehicleTurning"):
        """
        Setup all relevant parameters and create scenario
        """

        self._wmap = CarlaDataProvider.get_map()
        self._trigger_location = config.trigger_points[0].location
        self._reference_waypoint = self._wmap.get_waypoint(self._trigger_location)
        self._ego_route = CarlaDataProvider.get_ego_vehicle_route()

        self._start_distance = 10
        self._spawn_dist = self._start_distance
        self._number_of_attempts = 6
        self._retry_dist = 0.4

        self._adversary_transform = None

        self._collision_wp = None
        self._adversary_speed = 4.0  # Speed of the adversary [m/s]
        self._reaction_time = 0.5  # Time the agent has to react to avoid the collision [s]
        self._min_trigger_dist = 6.0  # Min distance to the collision location that triggers the adversary [m]
        self._ego_end_distance = 40

        self.timeout = timeout
        super(BaseVehicleTurning, self).__init__(
            name, ego_vehicles, config, world, debug_mode, criteria_enable=criteria_enable)
Esempio n. 4
0
    def _setup_scenario_trigger(self, config):
        """
        This function creates a trigger maneuver, that has to be finished before the real scenario starts.
        This implementation focuses on the first available ego vehicle.

        The function can be overloaded by a user implementation inside the user-defined scenario class.
        """
        start_location = None
        if config.trigger_points and config.trigger_points[0]:
            start_location = config.trigger_points[
                0].location  # start location of the scenario

        ego_vehicle_route = CarlaDataProvider.get_ego_vehicle_route()

        if start_location:
            if ego_vehicle_route:
                if config.route_var_name is None:  # pylint: disable=no-else-return
                    return conditions.InTriggerDistanceToLocationAlongRoute(
                        self.ego_vehicles[0], ego_vehicle_route,
                        start_location, 5)
                else:
                    check_name = "WaitForBlackboardVariable: {}".format(
                        config.route_var_name)
                    return conditions.WaitForBlackboardVariable(
                        name=check_name,
                        variable_name=config.route_var_name,
                        variable_value=True,
                        var_init_value=False)

            return conditions.InTimeToArrivalToLocation(
                self.ego_vehicles[0], 2.0, start_location)

        return None
    def _create_behavior(self):
        """
        Hero vehicle is turning left in an urban area at a signalized intersection,
        where, a flow of actors coming straight is present.
        """

        root = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        root.add_child(WaitEndIntersection(self.ego_vehicles[0]))
        root.add_child(
            ActorFlow(self._source_wp, self._sink_wp,
                      self._source_dist_interval, 2, self._opposite_speed))

        tl_freezer_sequence = py_trees.composites.Sequence(
            "Traffic Light Behavior")
        tl_freezer_sequence.add_child(
            TrafficLightFreezer(self._init_tl_dict,
                                duration=self._green_light_delay))
        tl_freezer_sequence.add_child(TrafficLightFreezer(self._flow_tl_dict))
        root.add_child(tl_freezer_sequence)

        sequence = py_trees.composites.Sequence("Sequence Behavior")
        if CarlaDataProvider.get_ego_vehicle_route():
            sequence.add_child(Scenario8Manager(self._direction))
        sequence.add_child(root)

        return sequence
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 criteria_enable=True,
                 adversary_type=False,
                 timeout=60):
        """
        Setup all relevant parameters and create scenario
        """
        self._wmap = CarlaDataProvider.get_map()

        self._reference_waypoint = self._wmap.get_waypoint(
            config.trigger_points[0].location)
        # ego vehicle parameters
        self._ego_vehicle_distance_driven = 40
        # other vehicle parameters
        self._other_actor_target_velocity = 5
        self._other_actor_max_brake = 1.0
        self._time_to_reach = 10

        # if random.randint(1, 2) == 1:
        #     self._adversary_type = False  # flag to select either pedestrian (False) or cyclist (True)
        # else:
        #
        self._adversary_type = adversary_type

        self._walker_yaw = 0
        self._num_lane_changes = 1
        self.transform = None
        self.transform2 = None
        self.timeout = timeout
        self._trigger_location = config.trigger_points[0].location
        # Total Number of attempts to relocate a vehicle before spawning
        self._number_of_attempts = 20
        # Number of attempts made so far
        self._spawn_attempted = 0

        self._num_actors = random.randint(1, 3)
        print("number of actors: {}".format(self._num_actors))

        self._ego_route = CarlaDataProvider.get_ego_vehicle_route()
        self.actor_list = {}

        super(DynamicObstaclesAhead,
              self).__init__("DynamicObstaclesAhead",
                             ego_vehicles,
                             config,
                             world,
                             debug_mode,
                             criteria_enable=criteria_enable)
    def _setup_scenario_end(self, config):
        """
        This function adds and additional behavior to the scenario, which is triggered
        after it has ended.

        The function can be overloaded by a user implementation inside the user-defined scenario class.
        """
        ego_vehicle_route = CarlaDataProvider.get_ego_vehicle_route()

        if ego_vehicle_route:
            if config.route_var_name is not None:
                set_name = "Reset Blackboard Variable: {} ".format(config.route_var_name)
                return py_trees.blackboard.SetBlackboardVariable(name=set_name,
                                                                 variable_name=config.route_var_name,
                                                                 variable_value=False)
        return None
Esempio n. 8
0
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 criteria_enable=True,
                 timeout=60,
                 customized_data=None):
        """
        Setup all relevant parameters and create scenario
        """
        self.world = world
        self.customized_data = customized_data

        self._wmap = CarlaDataProvider.get_map()
        self._trigger_location = config.trigger_points[0].location
        self._num_lane_changes = 0

        # Timeout of scenario in seconds
        self.timeout = timeout
        # Total Number of attempts to relocate a vehicle before spawning
        if 'number_of_attempts_to_request_actor' in customized_data:
            self._number_of_attempts = customized_data[
                'number_of_attempts_to_request_actor']
        else:
            self._number_of_attempts = 10

        self._ego_route = CarlaDataProvider.get_ego_vehicle_route()

        self.static_list = []
        self.pedestrian_list = []
        self.vehicle_list = []
        if 'tmp_travel_dist_file' in self.customized_data and os.path.exists(
                self.customized_data['tmp_travel_dist_file']):
            os.remove(self.customized_data['tmp_travel_dist_file'])
            print('remove tmp_travel_dist_file')

        super(Intersection, self).__init__("Intersection",
                                           ego_vehicles,
                                           config,
                                           world,
                                           debug_mode,
                                           criteria_enable=criteria_enable)
Esempio n. 9
0
    def _create_behavior(self):
        """
        Hero vehicle is entering a junction in an urban area, at a signalized intersection,
        while another actor runs a red lift, forcing the ego to break.
        """
        sequence = py_trees.composites.Sequence()

        # Wait until ego is close to the adversary
        trigger_adversary = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE,
            name="TriggerAdversaryStart")
        trigger_adversary.add_child(
            InTimeToArrivalToLocation(self.ego_vehicles[0], self._sync_time,
                                      self._collision_location))
        trigger_adversary.add_child(
            InTriggerDistanceToLocation(self.ego_vehicles[0],
                                        self._collision_location,
                                        self._min_trigger_dist))

        sequence.add_child(trigger_adversary)
        sequence.add_child(
            BasicAgentBehavior(
                self.other_actors[0],
                target_location=self._sink_wp.transform.location,
                target_speed=self._adversary_speed,
                opt_dict={'ignore_vehicles': True},
                name="AdversaryCrossing"))

        main_behavior = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        main_behavior.add_child(TrafficLightFreezer(self._tl_dict))
        main_behavior.add_child(sequence)

        root = py_trees.composites.Sequence()
        if CarlaDataProvider.get_ego_vehicle_route():
            root.add_child(Scenario7Manager(self._direction))
        root.add_child(
            ActorTransformSetter(self.other_actors[0], self._spawn_location))
        root.add_child(main_behavior)
        root.add_child(ActorDestroy(self.other_actors[0]))
        root.add_child(WaitEndIntersection(self.ego_vehicles[0]))

        return root
Esempio n. 10
0
    def _setup_scenario_trigger(self, config):
        """
        This function creates a trigger maneuver, that has to be finished before the real scenario starts.
        This implementation focuses on the first available ego vehicle.

        The function can be overloaded by a user implementation inside the user-defined scenario class.
        """
        start_location = None
        if config.trigger_points and config.trigger_points[0]:
            start_location = config.trigger_points[
                0].location  # start location of the scenario

        ego_vehicle_route = CarlaDataProvider.get_ego_vehicle_route()

        if start_location:
            if ego_vehicle_route:
                return InTriggerDistanceToLocationAlongRoute(
                    self.ego_vehicles[0], ego_vehicle_route, start_location, 5)
            return InTimeToArrivalToLocation(self.ego_vehicles[0], 2.0,
                                             start_location)

        return None
Esempio n. 11
0
    def __init__(self,
                 name,
                 ego_vehicle,
                 config,
                 world,
                 debug_mode=False,
                 terminate_on_failure=False,
                 criteria_enable=False):
        """
        Setup all relevant parameters and create scenario
        and instantiate scenario manager
        """
        self.other_actors = []
        if not self.timeout:  # pylint: disable=access-member-before-definition
            self.timeout = 60  # If no timeout was provided, set it to 60 seconds

        self.category = None  # Scenario category, e.g. control_loss, follow_leading_vehicle, ...
        self.criteria_list = []  # List of evaluation criteria
        self.scenario = None
        # Check if the CARLA server uses the correct map
        self._town = config.town
        self._check_town(world)

        self.ego_vehicle = ego_vehicle
        self.name = name
        self.terminate_on_failure = terminate_on_failure

        # Initializing adversarial actors
        self._initialize_actors(config)
        if not CarlaDataProvider.is_sync_mode():
            world.wait_for_tick()
        else:
            world.tick()

        # Setup scenario
        if debug_mode:
            py_trees.logging.level = py_trees.logging.Level.DEBUG

        behavior = self._create_behavior()

        criteria = None
        if criteria_enable:
            criteria = self._create_test_criteria()

        # Add a trigger condition for the behavior to ensure the behavior is only activated, when it is relevant

        start_location = None
        if config.trigger_point:
            start_location = config.trigger_point.location  # start location of the scenario

        ego_vehicle_route = CarlaDataProvider.get_ego_vehicle_route()

        behavior_seq = py_trees.composites.Sequence()
        if start_location:
            if ego_vehicle_route:
                behavior_seq.add_child(
                    InTriggerDistanceToLocationAlongRoute(
                        self.ego_vehicle, ego_vehicle_route, start_location,
                        5))
            else:
                behavior_seq.add_child(
                    InTimeToArrivalToLocation(self.ego_vehicle, 2.0,
                                              start_location))

        behavior_seq.add_child(behavior)

        self.scenario = Scenario(behavior_seq, criteria, self.name,
                                 self.timeout, self.terminate_on_failure)