def _create_behavior(self):
        """
        After invoking this scenario, cyclist will wait for the user
        controlled vehicle to enter the in the trigger distance region,
        the cyclist starts crossing the road once the condition meets,
        ego vehicle has to avoid the crash after a left turn, but
        continue driving after the road is clear.If this does not happen
        within 90 seconds, a timeout stops the scenario.
        """
        # leaf nodes
        trigger_distance = InTriggerDistanceToVehicle(
            self.other_vehicles[0], self.ego_vehicle,
            self._trigger_distance_from_ego)
        stop_other_vehicle = StopVehicle(self.other_vehicles[0],
                                         self._other_vehicle_max_brake)
        timeout_other_vehicle = TimeOut(5)
        start_other = KeepVelocity(self.other_vehicles[0],
                                   self._other_vehicle_target_velocity)
        trigger_other = InTriggerRegion(self.other_vehicles[0], 95, 96, 78, 79)
        stop_other = StopVehicle(self.other_vehicles[0],
                                 self._other_vehicle_max_brake)
        timeout_other = TimeOut(3)

        sync_arrival = SyncArrival(self.other_vehicles[0], self.ego_vehicle,
                                   self._location_of_collision)
        sync_arrival_stop = InTriggerDistanceToVehicle(self.other_vehicles[0],
                                                       self.ego_vehicle, 6)

        # non leaf nodes
        root = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        scenario_sequence = py_trees.composites.Sequence()
        keep_velocity_other = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        sync_arrival_parallel = py_trees.composites.Parallel(
            "Synchronize arrival times",
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        # building the tress
        root.add_child(scenario_sequence)
        scenario_sequence.add_child(trigger_distance)
        scenario_sequence.add_child(sync_arrival_parallel)
        scenario_sequence.add_child(stop_other_vehicle)
        scenario_sequence.add_child(timeout_other_vehicle)
        scenario_sequence.add_child(keep_velocity_other)
        scenario_sequence.add_child(stop_other)
        scenario_sequence.add_child(timeout_other)
        sync_arrival_parallel.add_child(sync_arrival)
        sync_arrival_parallel.add_child(sync_arrival_stop)
        keep_velocity_other.add_child(start_other)
        keep_velocity_other.add_child(trigger_other)

        return root
예제 #2
0
    def _create_behavior(self):
        """
        After invoking this scenario, cyclist will wait for the user
        controlled vehicle to enter the in the trigger distance region,
        the cyclist starts crossing the road once the condition meets,
        ego vehicle has to avoid the crash after a right turn, but
        continue driving after the road is clear.If this does not happen
        within 90 seconds, a timeout stops the scenario.
        """
        # leaf nodes
        trigger_distance = InTriggerDistanceToVehicle(
            self.other_vehicles[0], self.ego_vehicle,
            self._trigger_distance_from_ego)
        start_other_vehicle = KeepVelocity(self.other_vehicles[0],
                                           self._other_vehicle_target_velocity)
        trigger_other_vehicle = InTriggerRegion(self.other_vehicles[0], 91, 93,
                                                41, 43)
        stop_other_vehicle = StopVehicle(self.other_vehicles[0],
                                         self._other_vehicle_max_brake)
        timeout_other_vehicle = TimeOut(5)
        start_other = KeepVelocity(self.other_vehicles[0],
                                   self._other_vehicle_target_velocity)
        trigger_other = InTriggerRegion(self.other_vehicles[0], 85.5, 86.5, 41,
                                        43)
        stop_other = StopVehicle(self.other_vehicles[0],
                                 self._other_vehicle_max_brake)
        timeout_other = TimeOut(20)
        root_timeout = TimeOut(self.timeout)

        # non leaf nodes
        root = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        scenario_sequence = py_trees.composites.Sequence()
        keep_velocity_other_vehicle = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        keep_velocity_other = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        # building the tress
        root.add_child(scenario_sequence)
        root.add_child(root_timeout)
        scenario_sequence.add_child(trigger_distance)
        scenario_sequence.add_child(keep_velocity_other_vehicle)
        scenario_sequence.add_child(stop_other_vehicle)
        scenario_sequence.add_child(timeout_other_vehicle)
        scenario_sequence.add_child(keep_velocity_other)
        scenario_sequence.add_child(stop_other)
        scenario_sequence.add_child(timeout_other)
        keep_velocity_other_vehicle.add_child(start_other_vehicle)
        keep_velocity_other_vehicle.add_child(trigger_other_vehicle)
        keep_velocity_other.add_child(start_other)
        keep_velocity_other.add_child(trigger_other)

        return root
    def _create_behavior(self):
        """
        After invoking this scenario, cyclist will wait for the user
        controlled vehicle to enter the in the trigger distance region,
        the cyclist starts crossing the road once the condition meets,
        then after 60 seconds, a timeout stops the scenario
        """
        # leaf nodes
        trigger_dist = InTriggerDistanceToVehicle(
            self.other_vehicles[0], self.ego_vehicle,
            self._trigger_distance_from_ego)
        start_other_vehicle = KeepVelocity(self.other_vehicles[0],
                                           self._other_vehicle_target_velocity)
        trigger_other = InTriggerRegion(self.other_vehicles[0], 46, 50, 128,
                                        129.5)
        stop_other_vehicle = StopVehicle(self.other_vehicles[0],
                                         self._other_vehicle_max_brake)
        timeout_other = TimeOut(10)
        start_vehicle = KeepVelocity(self.other_vehicles[0],
                                     self._other_vehicle_target_velocity)
        trigger_other_vehicle = InTriggerRegion(self.other_vehicles[0], 46, 50,
                                                137, 139)
        stop_vehicle = StopVehicle(self.other_vehicles[0],
                                   self._other_vehicle_max_brake)
        timeout_other_vehicle = TimeOut(3)

        # non leaf nodes
        root = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        scenario_sequence = py_trees.composites.Sequence()
        keep_velocity_other_parallel = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        keep_velocity_other = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        # building tree
        root.add_child(scenario_sequence)
        scenario_sequence.add_child(trigger_dist)
        scenario_sequence.add_child(keep_velocity_other_parallel)
        scenario_sequence.add_child(stop_other_vehicle)
        scenario_sequence.add_child(timeout_other)
        scenario_sequence.add_child(keep_velocity_other)
        scenario_sequence.add_child(stop_vehicle)
        scenario_sequence.add_child(timeout_other_vehicle)
        keep_velocity_other_parallel.add_child(start_other_vehicle)
        keep_velocity_other_parallel.add_child(trigger_other)
        keep_velocity_other.add_child(start_vehicle)
        keep_velocity_other.add_child(trigger_other_vehicle)

        return root
예제 #4
0
    def __init__(self,
                 behavior,
                 criteria,
                 name,
                 timeout=60,
                 terminate_on_failure=False):
        self.behavior = behavior
        self.test_criteria = criteria
        self.timeout = timeout

        for criterion in self.test_criteria:
            criterion.terminate_on_failure = terminate_on_failure

        # Create py_tree for test criteria
        self.criteria_tree = py_trees.composites.Parallel(name="Test Criteria")
        self.criteria_tree.add_children(self.test_criteria)
        self.criteria_tree.setup(timeout=1)

        # Create node for timeout
        self.timeout_node = TimeOut(self.timeout, name="TimeOut")

        # Create overall py_tree
        self.scenario_tree = py_trees.composites.Parallel(
            name, policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        self.scenario_tree.add_child(self.behavior)
        self.scenario_tree.add_child(self.timeout_node)
        self.scenario_tree.add_child(self.criteria_tree)
        self.scenario_tree.setup(timeout=1)
예제 #5
0
    def _create_behavior(self):
        """
        After invoking this scenario, it will wait for the user
        controlled vehicle to enter the start region,
        then make a traffic participant to accelerate
        until it is going fast enough to reach an intersection point.
        at the same time as the user controlled vehicle at the junction.
        Once the user controlled vehicle comes close to the junction,
        the traffic participant accelerates and passes through the junction.
        After 60 seconds, a timeout stops the scenario.
        """

        # Creating leaf nodes
        start_other_trigger = InTriggerRegion(self.ego_vehicle, -80, -70, -75,
                                              -60)

        sync_arrival = SyncArrival(self.other_vehicles[0], self.ego_vehicle,
                                   carla.Location(x=-74.63, y=-136.34))

        pass_through_trigger = InTriggerRegion(self.ego_vehicle, -90, -70,
                                               -124, -119)

        keep_velocity_other = KeepVelocity(self.other_vehicles[0],
                                           self._other_vehicle_target_velocity)

        stop_other_trigger = InTriggerRegion(self.other_vehicles[0], -45, -35,
                                             -140, -130)

        stop_other = StopVehicle(self.other_vehicles[0],
                                 self._other_vehicle_max_brake)

        end_condition = InTriggerRegion(self.ego_vehicle, -90, -70, -170, -156)

        root_timeout = TimeOut(self.timeout)

        # Creating non-leaf nodes
        root = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        scenario_sequence = py_trees.composites.Sequence()
        sync_arrival_parallel = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
        keep_velocity_other_parallel = py_trees.composites.Parallel(
            policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        # Building tree
        root.add_child(scenario_sequence)
        root.add_child(root_timeout)
        scenario_sequence.add_child(start_other_trigger)
        scenario_sequence.add_child(sync_arrival_parallel)
        scenario_sequence.add_child(keep_velocity_other_parallel)
        scenario_sequence.add_child(stop_other)
        scenario_sequence.add_child(end_condition)
        sync_arrival_parallel.add_child(sync_arrival)
        sync_arrival_parallel.add_child(pass_through_trigger)
        keep_velocity_other_parallel.add_child(keep_velocity_other)
        keep_velocity_other_parallel.add_child(stop_other_trigger)

        return root
예제 #6
0
    def _create_behavior(self):
        """
        The scenario defined after is a "control loss vehicle" scenario. After
        invoking this scenario, it will wait for the user controlled vehicle to
        enter the start region, then it performs a jitter action. Finally,
        the user-controlled vehicle has to reach a target region.
        If this does not happen within 60 seconds, a timeout stops the scenario
        """

        # start condition
        start_condition = InTriggerRegion(self.ego_vehicle, 43, 49, 190, 210)

        # jitter sequence
        jitter_sequence = py_trees.composites.Sequence(
            "Jitter Sequence Behavior")
        jitter_timeout = TimeOut(timeout=0.2, name="Timeout for next jitter")

        for i in range(self._no_of_jitter_actions):
            ego_vehicle_max_steer = random.gauss(self._noise_mean,
                                                 self._noise_std)
            if ego_vehicle_max_steer > 0:
                ego_vehicle_max_steer += self._dynamic_mean
            elif ego_vehicle_max_steer < 0:
                ego_vehicle_max_steer -= self._dynamic_mean

            # turn vehicle
            turn = SteerVehicle(self.ego_vehicle,
                                ego_vehicle_max_steer,
                                name='Steering ' + str(i))

            jitter_action = py_trees.composites.Parallel(
                "Jitter Actions with Timeouts",
                policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ALL)
            jitter_action.add_child(turn)
            jitter_action.add_child(jitter_timeout)
            jitter_sequence.add_child(jitter_action)

        # endcondition
        end_condition = InTriggerRegion(self.ego_vehicle, 145, 150, 190, 210)

        # Build behavior tree
        sequence = py_trees.composites.Sequence("Sequence Behavior")
        sequence.add_child(start_condition)
        sequence.add_child(jitter_sequence)
        sequence.add_child(end_condition)
        return sequence
 def _create_behavior(self):
     """
     Only behavior here is to wait
     """
     redundant = TimeOut(self.timeout - 5)
     return redundant