def _create_behavior(self): """ The behavior tree returned by this method is as follows: The ego vehicle is trying to pass a leading vehicle in the same lane by moving onto the oncoming lane while another vehicle is moving in the opposite direction in the oncoming lane. """ # Leaf nodes actor_source = ActorSource( [ "vehicle.audi.tt", "vehicle.tesla.model3", "vehicle.nissan.micra" ], self._source_transform, self._source_gap, self._blackboard_queue_name, ) actor_sink = ActorSink(self._sink_location, 10) ego_drive_distance = DriveDistance(self.ego_vehicles[0], self._ego_vehicle_drive_distance) waypoint_follower = WaypointFollower( self.other_actors[1], self._opposite_speed, blackboard_queue_name=self._blackboard_queue_name, avoid_collision=True, ) pedestrian_walking = KeepVelocity(self.other_actors[2], 1, distance=300) # Non-leaf nodes parallel_root = py_trees.composites.Parallel( policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) # Building tree parallel_root.add_child(ego_drive_distance) parallel_root.add_child(actor_source) parallel_root.add_child(actor_sink) parallel_root.add_child(waypoint_follower) parallel_root.add_child(pedestrian_walking) scenario_sequence = py_trees.composites.Sequence() scenario_sequence.add_child( ActorTransformSetter(self.other_actors[0], self._first_actor_transform)) scenario_sequence.add_child( ActorTransformSetter(self.other_actors[1], self._second_actor_transform)) # scenario_sequence.add_child( # ActorTransformSetter(self.other_actors[2], # self._third_actor_transform)) scenario_sequence.add_child(parallel_root) scenario_sequence.add_child(ActorDestroy(self.other_actors[0])) scenario_sequence.add_child(ActorDestroy(self.other_actors[1])) scenario_sequence.add_child(ActorDestroy(self.other_actors[2])) return scenario_sequence
def _create_behavior(self): """ Hero vehicle is turning left in an urban area, at a signalized intersection, while other actor coming straight .The hero actor may turn left either before other actor passes intersection or later, without any collision. After 80 seconds, a timeout stops the scenario. """ sequence = py_trees.composites.Sequence("Sequence Behavior") # Selecting straight path at intersection target_waypoint = generate_target_waypoint( CarlaDataProvider.get_map().get_waypoint( self.other_actors[0].get_location()), 0) # Generating waypoint list till next intersection plan = [] wp_choice = target_waypoint.next(1.0) while not wp_choice[0].is_intersection: target_waypoint = wp_choice[0] plan.append((target_waypoint, RoadOption.LANEFOLLOW)) wp_choice = target_waypoint.next(1.0) # adding flow of actors actor_source = ActorSource(['vehicle.tesla.model3', 'vehicle.audi.tt'], self._other_actor_transform, 15, self._blackboard_queue_name) # destroying flow of actors actor_sink = ActorSink(plan[-1][0].transform.location, 10) # follow waypoints untill next intersection move_actor = WaypointFollower( self.other_actors[0], self._target_vel, plan=plan, blackboard_queue_name=self._blackboard_queue_name, avoid_collision=True) # wait wait = DriveDistance(self.ego_vehicles[0], self._ego_distance) # Behavior tree root = py_trees.composites.Parallel( policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) root.add_child(wait) root.add_child(actor_source) root.add_child(actor_sink) root.add_child(move_actor) sequence.add_child( ActorTransformSetter(self.other_actors[0], self._other_actor_transform)) sequence.add_child(root) sequence.add_child(ActorDestroy(self.other_actors[0])) return sequence