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_vehicles[0], -80, -70, -75, -60) sync_arrival = SyncArrival(self.other_actors[0], self.ego_vehicles[0], carla.Location(x=-74.63, y=-136.34)) pass_through_trigger = InTriggerRegion(self.ego_vehicles[0], -90, -70, -124, -119) keep_velocity_other = KeepVelocity(self.other_actors[0], self._other_actor_target_velocity) stop_other_trigger = InTriggerRegion(self.other_actors[0], -45, -35, -140, -130) stop_other = StopVehicle(self.other_actors[0], self._other_actor_max_brake) end_condition = InTriggerRegion(self.ego_vehicles[0], -90, -70, -170, -156) # Creating non-leaf nodes root = py_trees.composites.Sequence() 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) scenario_sequence.add_child( ActorTransformSetter(self.other_actors[0], self._other_actor_transform)) 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) scenario_sequence.add_child(ActorDestroy(self.other_actors[0])) 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
def _create_behavior(self): """ Scenario behavior: The other vehicle waits until the ego vehicle is close enough to the intersection and that its own traffic light is red. Then, it will start driving and 'illegally' cross the intersection. After a short distance it should stop again, outside of the intersection. The ego vehicle has to avoid the crash, but continue driving after the intersection is clear. If this does not happen within 120 seconds, a timeout stops the scenario """ crossing_point_dynamic = get_crossing_point(self.ego_vehicles[0]) # start condition startcondition = InTriggerDistanceToLocation( self.ego_vehicles[0], crossing_point_dynamic, self._ego_distance_to_traffic_light, name="Waiting for start position") sync_arrival_parallel = py_trees.composites.Parallel( "Synchronize arrival times", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) location_of_collision_dynamic = get_geometric_linear_intersection( self.ego_vehicles[0], self.other_actors[0]) sync_arrival = SyncArrival(self.other_actors[0], self.ego_vehicles[0], location_of_collision_dynamic) sync_arrival_stop = InTriggerDistanceToNextIntersection( self.other_actors[0], 5) sync_arrival_parallel.add_child(sync_arrival) sync_arrival_parallel.add_child(sync_arrival_stop) # Generate plan for WaypointFollower turn = 0 # drive straight ahead plan = [] # generating waypoints until intersection (target_waypoint) plan, target_waypoint = generate_target_waypoint_list( CarlaDataProvider.get_map().get_waypoint( self.other_actors[0].get_location()), turn) # Generating waypoint list till next intersection wp_choice = target_waypoint.next(5.0) while len(wp_choice) == 1: target_waypoint = wp_choice[0] plan.append((target_waypoint, RoadOption.LANEFOLLOW)) wp_choice = target_waypoint.next(5.0) continue_driving = py_trees.composites.Parallel( "ContinueDriving", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) continue_driving_waypoints = WaypointFollower( self.other_actors[0], self._other_actor_target_velocity, plan=plan, avoid_collision=False) continue_driving_distance = DriveDistance(self.other_actors[0], self._other_actor_distance, name="Distance") continue_driving_timeout = TimeOut(10) continue_driving.add_child(continue_driving_waypoints) continue_driving.add_child(continue_driving_distance) continue_driving.add_child(continue_driving_timeout) # finally wait that ego vehicle drove a specific distance wait = DriveDistance(self.ego_vehicles[0], self._ego_distance_to_drive, name="DriveDistance") # Build behavior tree sequence = py_trees.composites.Sequence("Sequence Behavior") sequence.add_child( ActorTransformSetter(self.other_actors[0], self._other_actor_transform)) sequence.add_child(startcondition) sequence.add_child(sync_arrival_parallel) sequence.add_child(continue_driving) sequence.add_child(wait) sequence.add_child(ActorDestroy(self.other_actors[0])) return sequence
def _create_behavior(self): """ Hero vehicle is turning right in an urban area, at a signalized intersection, while other actor coming straight from left.The hero actor may turn right either before other actor passes intersection or later, without any collision. After 80 seconds, a timeout stops the scenario. """ location_of_collision_dynamic = get_geometric_linear_intersection( self.ego_vehicles[0], self.other_actors[0]) crossing_point_dynamic = get_crossing_point(self.other_actors[0]) sync_arrival = SyncArrival(self.other_actors[0], self.ego_vehicles[0], location_of_collision_dynamic) sync_arrival_stop = InTriggerDistanceToLocation( self.other_actors[0], crossing_point_dynamic, 5) sync_arrival_parallel = py_trees.composites.Parallel( "Synchronize arrival times", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) sync_arrival_parallel.add_child(sync_arrival) sync_arrival_parallel.add_child(sync_arrival_stop) # 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) move_actor = WaypointFollower(self.other_actors[0], self._target_vel, plan=plan) waypoint_follower_end = InTriggerDistanceToLocation( self.other_actors[0], plan[-1][0].transform.location, 10) move_actor_parallel = py_trees.composites.Parallel( policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) move_actor_parallel.add_child(move_actor) move_actor_parallel.add_child(waypoint_follower_end) #manipulate traffic light manipulate_traffic_light = TrafficLightManipulator( self.ego_vehicles[0], "S7right") move_actor_parallel.add_child(manipulate_traffic_light) # stop other actor stop = StopVehicle(self.other_actors[0], self._brake_value) # end condition end_condition = DriveDistance(self.ego_vehicles[0], self._ego_distance) # Behavior tree sequence = py_trees.composites.Sequence() sequence.add_child( ActorTransformSetter(self.other_actors[0], self._other_actor_transform)) sequence.add_child(sync_arrival_parallel) sequence.add_child(move_actor_parallel) sequence.add_child(stop) sequence.add_child(end_condition) sequence.add_child(ActorDestroy(self.other_actors[0])) return sequence