CurryChen77 / FREA

[CoRL 2024 Oral] FREA: Feasibility-Guided Generation of Safety-Critical Scenarios with Reasonable Adversariality
https://currychen77.github.io/FREA/
MIT License
24 stars 2 forks source link

ERROR: math.degrees(current_vector.get_vector_angle(relative_direction)) #1

Open jingzhengli opened 1 week ago

jingzhengli commented 1 week ago

AttributeError: 'Vector3D' object has no attribute 'get_vector_angle'

I have met an error in the following code, can you help me? relative_delta_angle = math.degrees(ego_forward_vector.get_vector_angle(relative_direction)) direction_angle = math.degrees(ego_forward_vector.get_vector_angle(CBV_forward_vector)) delta_angle = math.degrees(current_vector.get_vector_angle(relative_direction))

I try to use the following code, but I don't know the correctness


    dot_product = ego_forward_vector.x * relative_direction.x + ego_forward_vector.y * relative_direction.y + ego_forward_vector.z * relative_direction.z
    magnitude_ego = math.sqrt(ego_forward_vector.x ** 2 + ego_forward_vector.y ** 2 + ego_forward_vector.z ** 2)
    magnitude_relative = math.sqrt(relative_direction.x ** 2 + relative_direction.y ** 2 + relative_direction.z ** 2)
    if magnitude_ego == 0 or magnitude_relative == 0:
        raise ValueError("One of the vectors has zero magnitude, cannot compute angle.")

    cos_angle = dot_product / (magnitude_ego * magnitude_relative)
    cos_angle = max(-1.0, min(1.0, cos_angle))
    angle_rad = math.acos(cos_angle)
    relative_delta_angle  = math.degrees(angle_rad)
CurryChen77 commented 1 week ago

According to the Carla CHANGELOG, 'get_vector_angle' was added to Vector3D in version 0.9.13. We tested this project under version 0.9.13, so we recommend updating Carla to version 0.9.13 (or higher). Otherwise, you'll need to write your own code to calculate the angle between two 3D vectors in radians.

jingzhengli commented 2 days ago

According to the Carla CHANGELOG, 'get_vector_angle' was added to Vector3D in version 0.9.13. We tested this project under version 0.9.13, so we recommend updating Carla to version 0.9.13 (or higher). Otherwise, you'll need to write your own code to calculate the angle between two 3D vectors in radians.

Thanks, you solve my issue. BTW. I also proved the code I wrote to replace it correct.

In addition, I want to know how to incorporate the KING code and Advtraj (adversarial trajectory) into the FREA framework. Could you give me some guide or idea? To my knowledge, FREA framework is complete as opposed to Safebench in generating scenarios.

CurryChen77 commented 5 hours ago

Thank you for your interest in FREA. The KING experiments in the paper are based on results from its official repository, analyzed using evaluation code. Unlike KING, our framework generates continuous traffic flow and selects CBVs for adversarial interactions. To incorporate KING (or any other adversarial method), you could apply it after CBV selection to generate adversarial trajectories for interaction with the ego vehicle and release the CBV as a regular vehicle when the attacking is done. This would require integrating KING into our framework and aligning its observation part.