def _create_behavior(self): """ The scenario defined after is a "follow leading vehicle" scenario. After invoking this scenario, it will wait for the user controlled vehicle to enter the start region, then make the other actor to drive towards obstacle. Once obstacle clears the road, make the other actor to drive towards the next intersection. Finally, the user-controlled vehicle has to be close enough to the other actor to end the scenario. If this does not happen within 60 seconds, a timeout stops the scenario """ # let the other actor drive until next intersection driving_to_next_intersection = py_trees.composites.Parallel( "Driving towards Intersection", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) obstacle_clear_road = py_trees.composites.Parallel("Obstalce clearing road", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) obstacle_clear_road.add_child(DriveDistance(self.other_actors[1], 4)) obstacle_clear_road.add_child(KeepVelocity(self.other_actors[1], self._second_actor_speed)) stop_near_intersection = py_trees.composites.Parallel( "Waiting for end position near Intersection", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) stop_near_intersection.add_child(WaypointFollower(self.other_actors[0], 10)) stop_near_intersection.add_child(InTriggerDistanceToNextIntersection(self.other_actors[0], 20)) driving_to_next_intersection.add_child(WaypointFollower(self.other_actors[0], self._first_actor_speed)) driving_to_next_intersection.add_child(InTriggerDistanceToVehicle(self.other_actors[1], self.other_actors[0], 15)) # end condition endcondition = py_trees.composites.Parallel("Waiting for end position", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ALL) endcondition_part1 = InTriggerDistanceToVehicle(self.other_actors[0], self.ego_vehicles[0], distance=20, name="FinalDistance") endcondition_part2 = StandStill(self.ego_vehicles[0], name="FinalSpeed") endcondition.add_child(endcondition_part1) endcondition.add_child(endcondition_part2) # Build behavior tree sequence = py_trees.composites.Sequence("Sequence Behavior") sequence.add_child(ActorTransformSetter(self.other_actors[0], self._first_actor_transform)) sequence.add_child(ActorTransformSetter(self.other_actors[1], self._second_actor_transform)) sequence.add_child(driving_to_next_intersection) sequence.add_child(StopVehicle(self.other_actors[0], self._other_actor_max_brake)) sequence.add_child(TimeOut(3)) sequence.add_child(obstacle_clear_road) sequence.add_child(stop_near_intersection) sequence.add_child(StopVehicle(self.other_actors[0], self._other_actor_max_brake)) sequence.add_child(endcondition) sequence.add_child(ActorDestroy(self.other_actors[0])) sequence.add_child(ActorDestroy(self.other_actors[1])) return sequence
def _create_behavior(self): """ The scenario defined after is a "follow leading vehicle" scenario. After invoking this scenario, it will wait for the user controlled vehicle to enter the start region, then make the other actor to drive until reaching the next intersection. Finally, the user-controlled vehicle has to be close enough to the other actor to end the scenario. If this does not happen within 60 seconds, a timeout stops the scenario """ # to avoid the other actor blocking traffic, it was spawed elsewhere # reset its pose to the required one start_transform = ActorTransformSetter(self.other_actors[0], self._other_actor_transform) # let the other actor drive until next intersection # @todo: We should add some feedback mechanism to respond to ego_vehicle behavior driving_to_next_intersection = py_trees.composites.Parallel( "DrivingTowardsIntersection", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) driving_to_next_intersection.add_child( WaypointFollower(self.other_actors[0], self._first_vehicle_speed)) driving_to_next_intersection.add_child( InTriggerDistanceToNextIntersection( self.other_actors[0], self._other_actor_stop_in_front_intersection)) # stop vehicle stop = StopVehicle(self.other_actors[0], self._other_actor_max_brake) # end condition endcondition = py_trees.composites.Parallel( "Waiting for end position", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ALL) endcondition_part1 = InTriggerDistanceToVehicle(self.other_actors[0], self.ego_vehicles[0], distance=20, name="FinalDistance") endcondition_part2 = StandStill(self.ego_vehicles[0], name="StandStill", duration=1) endcondition.add_child(endcondition_part1) endcondition.add_child(endcondition_part2) # Build behavior tree sequence = py_trees.composites.Sequence("Sequence Behavior") sequence.add_child(start_transform) sequence.add_child(driving_to_next_intersection) sequence.add_child(stop) sequence.add_child(endcondition) sequence.add_child(ActorDestroy(self.other_actors[0])) return sequence
def _create_behavior(self): """ The scenario defined after is a "control loss vehicle" scenario. After invoking this scenario, it will wait until the vehicle drove a few meters (_start_distance), and then perform a jitter action. Finally, the vehicle has to reach a target point (_end_distance). If this does not happen within 60 seconds, a timeout stops the scenario """ # start condition start_end_parallel = py_trees.composites.Parallel("Jitter", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) start_condition = InTriggerDistanceToLocation(self.ego_vehicles[0], self.first_loc_prev, self._trigger_dist) for _ in range(self._no_of_jitter): # change the current noise to be applied turn = ChangeNoiseParameters(self._current_steer_noise, self._current_throttle_noise, self._noise_mean, self._noise_std, self._dynamic_mean_for_steer, self._dynamic_mean_for_throttle) # Mean value of steering noise # Noise end! put again the added noise to zero. noise_end = ChangeNoiseParameters(self._current_steer_noise, self._current_throttle_noise, 0, 0, 0, 0) jitter_action = py_trees.composites.Parallel("Jitter", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) # Abort jitter_sequence, if the vehicle is approaching an intersection jitter_abort = InTriggerDistanceToNextIntersection(self.ego_vehicles[0], self._abort_distance_to_intersection) # endcondition: Check if vehicle reached waypoint _end_distance from here: end_condition = DriveDistance(self.ego_vehicles[0], self._end_distance) start_end_parallel.add_child(start_condition) start_end_parallel.add_child(end_condition) # Build behavior tree sequence = py_trees.composites.Sequence("ControlLoss") sequence.add_child(ActorTransformSetter(self.other_actors[0], self.first_transform, physics=False)) sequence.add_child(ActorTransformSetter(self.other_actors[1], self.sec_transform, physics=False)) sequence.add_child(ActorTransformSetter(self.other_actors[2], self.third_transform, physics=False)) jitter = py_trees.composites.Sequence("Jitter Behavior") jitter.add_child(turn) jitter.add_child(InTriggerDistanceToLocation(self.ego_vehicles[0], self.sec_loc_prev, self._trigger_dist)) jitter.add_child(turn) jitter.add_child(InTriggerDistanceToLocation(self.ego_vehicles[0], self.third_loc_prev, self._trigger_dist)) jitter.add_child(turn) jitter_action.add_child(jitter) jitter_action.add_child(jitter_abort) sequence.add_child(start_end_parallel) sequence.add_child(jitter_action) sequence.add_child(end_condition) sequence.add_child(noise_end) return sequence
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