srunner/tools/scenario_helper.py
def detect_lane_obstacle(actor, extension_factor=3, margin=1.02):
    """
    This function identifies if an obstacle is present in front of the reference actor
    """
    world = CarlaDataProvider.get_world()
    world_actors = world.get_actors().filter('vehicle.*')
    actor_bbox = actor.bounding_box
    actor_transform = actor.get_transform()
    actor_location = actor_transform.location
    actor_vector = actor_transform.rotation.get_forward_vector()
    actor_vector = np.array([actor_vector.x, actor_vector.y])
    actor_vector = actor_vector / np.linalg.norm(actor_vector)
    actor_vector = actor_vector * (extension_factor - 1) * actor_bbox.extent.x
    actor_location = actor_location + carla.Location(actor_vector[0], actor_vector[1])
    actor_yaw = actor_transform.rotation.yaw

    is_hazard = False
    for adversary in world_actors:
        if adversary.id != actor.id and \
                actor_transform.location.distance(adversary.get_location()) < 50:
            adversary_bbox = adversary.bounding_box
            adversary_transform = adversary.get_transform()
            adversary_loc = adversary_transform.location
            adversary_yaw = adversary_transform.rotation.yaw
            overlap_adversary = RotatedRectangle(
                adversary_loc.x, adversary_loc.y,
                2 * margin * adversary_bbox.extent.x, 2 * margin * adversary_bbox.extent.y, adversary_yaw)
            overlap_actor = RotatedRectangle(
                actor_location.x, actor_location.y,
                2 * margin * actor_bbox.extent.x * extension_factor, 2 * margin * actor_bbox.extent.y, actor_yaw)
            overlap_area = overlap_adversary.intersection(overlap_actor).area
            if overlap_area > 0:
                is_hazard = True
                break

    return is_hazard

    This function identifies if an obstacle is present in front of the reference actor
    
This function identifies if an obstacle is present in front of the reference actor
This function identifies if an obstacle is present in front of the reference actor
def detect_lane_obstacle(actor, extension_factor=3, margin=1.02):
    world = CarlaDataProvider.get_world()
    world_actors = world.get_actors().filter('vehicle.*')
    actor_bbox = actor.bounding_box
    actor_transform = actor.get_transform()
    actor_location = actor_transform.location
    actor_vector = actor_transform.rotation.get_forward_vector()
    actor_vector = np.array([actor_vector.x, actor_vector.y])
    actor_vector = actor_vector / np.linalg.norm(actor_vector)
    actor_vector = actor_vector * (extension_factor - 1) * actor_bbox.extent.x
    actor_location = actor_location + carla.Location(actor_vector[0], actor_vector[1])
    actor_yaw = actor_transform.rotation.yaw
    is_hazard = False
    for adversary in world_actors:
        if adversary.id != actor.id and \
                actor_transform.location.distance(adversary.get_location()) < 50:
            adversary_bbox = adversary.bounding_box
            adversary_transform = adversary.get_transform()
            adversary_loc = adversary_transform.location
            adversary_yaw = adversary_transform.rotation.yaw
            overlap_adversary = RotatedRectangle(
                adversary_loc.x, adversary_loc.y,
                2 * margin * adversary_bbox.extent.x, 2 * margin * adversary_bbox.extent.y, adversary_yaw)
            overlap_actor = RotatedRectangle(
                actor_location.x, actor_location.y,
                2 * margin * actor_bbox.extent.x * extension_factor, 2 * margin * actor_bbox.extent.y, actor_yaw)
            overlap_area = overlap_adversary.intersection(overlap_actor).area
            if overlap_area > 0:
                is_hazard = True
                break
    return is_hazard
def detect_lane_obstacle ( actor , extension_factor = 3 , margin = 1.02 ) : world = CarlaDataProvider . get_world ( ) world_actors = world . get_actors ( ) . filter ( 'vehicle.*' ) actor_bbox = actor . bounding_box actor_transform = actor . get_transform ( ) actor_location = actor_transform . location actor_vector = actor_transform . rotation . get_forward_vector ( ) actor_vector = np . array ( [ actor_vector . x , actor_vector . y ] ) actor_vector = actor_vector / np . linalg . norm ( actor_vector ) actor_vector = actor_vector * ( extension_factor - 1 ) * actor_bbox . extent . x actor_location = actor_location + carla . Location ( actor_vector [ 0 ] , actor_vector [ 1 ] ) actor_yaw = actor_transform . rotation . yaw is_hazard = False for adversary in world_actors : if adversary . id != actor . id and actor_transform . location . distance ( adversary . get_location ( ) ) < 50 : adversary_bbox = adversary . bounding_box adversary_transform = adversary . get_transform ( ) adversary_loc = adversary_transform . location adversary_yaw = adversary_transform . rotation . yaw overlap_adversary = RotatedRectangle ( adversary_loc . x , adversary_loc . y , 2 * margin * adversary_bbox . extent . x , 2 * margin * adversary_bbox . extent . y , adversary_yaw ) overlap_actor = RotatedRectangle ( actor_location . x , actor_location . y , 2 * margin * actor_bbox . extent . x * extension_factor , 2 * margin * actor_bbox . extent . y , actor_yaw ) overlap_area = overlap_adversary . intersection ( overlap_actor ) . area if overlap_area > 0 : is_hazard = True break return is_hazard
This function identifies if an obstacle is present in front of the reference actor
This function identifies if an obstacle is present in front of the reference actor
"""
    This function identifies if an obstacle is present in front of the reference actor
    """
actor
extension_factor
margin