class_docstr: BehaviorAgent implements an agent that navigates scenes to reach a given
  target destination, by computing the shortest possible path to it.
  This agent can correctly follow traffic signs, speed limitations,
  traffic lights, while also taking into account nearby vehicles. Lane changing
  decisions can be taken by analyzing the surrounding environment such as tailgating avoidance.
  Adding to these are possible behaviors, the agent can also keep safety distance
  from a car in front of it by tracking the instantaneous time to collision
  and keeping it in a certain range. Finally, different sets of behaviors
  are encoded in the agent, from cautious to a more aggressive ones.
class_docstr_tok: ["BehaviorAgent","implements","an","agent","that","navigates","scenes","to","reach","a","given","target","destination",",","by","computing","the","shortest","possible","path","to","it",".","This","agent","can","correctly","follow","traffic","signs",",","speed","limitations",",","traffic","lights",",","while","also","taking","into","account","nearby","vehicles",".","Lane","changing","decisions","can","be","taken","by","analyzing","the","surrounding","environment","such","as","tailgating","avoidance",".","Adding","to","these","are","possible","behaviors",",","the","agent","can","also","keep","safety","distance","from","a","car","in","front","of","it","by","tracking","the","instantaneous","time","to","collision","and","keeping","it","in","a","certain","range",".","Finally",",","different","sets","of","behaviors","are","encoded","in","the","agent",",","from","cautious","to","a","more","aggressive","ones","."]
docstr: This method is in charge of tailgating behaviors.
  
      :param location: current location of the agent
      :param waypoint: current waypoint of the agent
      :param vehicle_list: list of all the nearby vehicles
docstr_tok: ["This","method","is","in","charge","of","tailgating","behaviors",".",":","param","location",":","current","location","of","the","agent",":","param","waypoint",":","current","waypoint","of","the","agent",":","param","vehicle_list",":","list","of","all","the","nearby","vehicles"]
code: def _tailgating(self, waypoint, vehicle_list):
      """
      This method is in charge of tailgating behaviors.
  
          :param location: current location of the agent
          :param waypoint: current waypoint of the agent
          :param vehicle_list: list of all the nearby vehicles
      """
  
      left_turn = waypoint.left_lane_marking.lane_change
      right_turn = waypoint.right_lane_marking.lane_change
  
      left_wpt = waypoint.get_left_lane()
      right_wpt = waypoint.get_right_lane()
  
      (
          behind_vehicle_state,
          behind_vehicle,
          _,
      ) = self._vehicle_obstacle_detected(
          vehicle_list,
          max(
              self._behavior.min_proximity_threshold,
              self._speed_limit / 2,
          ),
          up_angle_th=180,
          low_angle_th=160,
      )
      if behind_vehicle_state and self._speed < get_speed(
          behind_vehicle
      ):
          if (
              (
                  right_turn == carla.LaneChange.Right
                  or right_turn == carla.LaneChange.Both
              )
              and waypoint.lane_id * right_wpt.lane_id > 0
              and right_wpt.lane_type == carla.LaneType.Driving
          ):
              new_vehicle_state, _, _ = self._vehicle_obstacle_detected(
                  vehicle_list,
                  max(
                      self._behavior.min_proximity_threshold,
                      self._speed_limit / 2,
                  ),
                  up_angle_th=180,
                  lane_offset=1,
              )
              if not new_vehicle_state:
                  print("Tailgating, moving to the right!")
                  end_waypoint = self._local_planner.target_waypoint
                  self._behavior.tailgate_counter = 200
                  self.set_destination(
                      end_waypoint.transform.location,
                      right_wpt.transform.location,
                  )
          elif (
              left_turn == carla.LaneChange.Left
              and waypoint.lane_id * left_wpt.lane_id > 0
              and left_wpt.lane_type == carla.LaneType.Driving
          ):
              new_vehicle_state, _, _ = self._vehicle_obstacle_detected(
                  vehicle_list,
                  max(
                      self._behavior.min_proximity_threshold,
                      self._speed_limit / 2,
                  ),
                  up_angle_th=180,
                  lane_offset=-1,
              )
              if not new_vehicle_state:
                  print("Tailgating, moving to the left!")
                  end_waypoint = self._local_planner.target_waypoint
                  self._behavior.tailgate_counter = 200
                  self.set_destination(
                      end_waypoint.transform.location,
                      left_wpt.transform.location,
                  )
  
file_path: carla/PythonAPI/carla/agents/navigation/behavior_agent.py
imports: import random
  import numpy
  import carla
  from agents.navigation.basic_agent import BasicAgent
  from agents.navigation.local_planner import RoadOption
  from agents.navigation.behavior_types import Cautious, Aggressive, Normal
  from agents.tools.misc import get_speed, positive, is_within_distance, compute_distance
label_desc: Use image node_id 4 for calling the BehaviorAgent obj's underlying member method code with example usage: obj._tailgating(waypoint, vehicle_list) without return types