Where can I find/How does air traffic detect and avoid work?

Hey all,

Problem/Question: I’m trying to understand the algorithm that governs detect and avoid (DAA) for copters and planes, and I’m getting lost.

  • Problem 1: which file/files actually run this operation? From what I’ve seen, it’s broken up between:
    -The AC_Avoidance and all of it’s sub functions
    -AP_ADSB
    -AP_Math
    Do these functions/scripts/files encompass the entirety of the DAA algorithms?
    Also, in both the code and commit comments on github, there’s mention of the rover, copter, and plane all in the same set of codes. Is the ArduPilot code the same for all vehicle types?
    Finally, in the AP_ADSB.cpp file, lines 140-146 set an altitude filter. The comment ( “Vehicles detected above this altitude will be completely ignored. They will not show up in the SRx_ADSB stream to the GCS and will not be considered in any avoidance calculations. A value of 0 will disable this filter.”) makes it seem as though this filter is only useful for a rover, because wouldn’t a plane or drone want a lower and upper altitude limit?

*Problem 2: How do these files work together? I’m not looking for an in depth, hand-hold, step by step (I don’t want to waste others time, and I think we learn more when we figure things out by ourselves, I’m just really stuck), but just a general overview/high level look at the sequence of events and/or where in the code (for DAA) each function calls each other function.
-Also, there’s a few articles in the documentation that goes over object avoidance (linked below), is incoming traffic from other drones/planes/moving objects treated the same way as a stationary object? How are the trajectories of traffic calculated?
-https://ardupilot.org/copter/docs/common-simple-object-avoidance.html
-https://ardupilot.org/dev/docs/code-overview-object-avoidance.html
-https://ardupilot.org/copter/docs/common-oa-bendyruler.html

I guess in summary; where is a good place to start diving into the nitty-gritty of the DAA logic? My main focus is understanding how ArduPilot negotiates incoming aerial traffic. I’ve been looking at this for a while, and from the base of the learning curve, it looks like a messy climb.

Background: I’m a college student trying to replicate this code in Python to simulate how this software reacts to traffic. I am fresh-off-the-presses new at Python and all things drones, and I’ve never seen C++ code until now. I’m sorry if this is not the right place to post this question (maybe the discord is better?), or if I’m asking too much, or if this is way too trivial/explained fully in a place I haven’t seen yet. Let me know if I need to be more specific or clarify anything! I’d very much appreciate all the help I can get!

Thank you

-The AC_Avoidance and all of it¢s sub functions

You’re after AP_Avoidance, not AC_Avoidance

Background: I¢m a college student trying to replicate this code in Python to simulate how this software reacts to traffic. I am fresh-off-the-presses new

Might I suggest you run the current code in ArduPilot’s simulation?

You will need a SITL (Software In The Loop) environment (lots of docs
@ardupilot.org on how to get one of those).

Past that you can simulate an ADSB-based-avoidance incident with:

./Tools/autotest/autotest.py build.Plane test.Plane.ADSB --map

at Python and all things drones, and I¢ve never seen C++ code until now. I¢m sorry if this is not the right place to post this question (maybe the discord
is better?), or if I¢m asking too much, or if this is way too trivial/explained fully in a place I haven¢t seen yet. Let me know if I need to be more
specific or clarify anything! I¢d very much appreciate all the help I can get!

You may be able to do all the simulation work you need to do by modifying
the existing autotest. Note that you can run autotest with “–gdb” and
“–debug” to step through the code and understand its structure. Yes,
this is a rather large amount of stuff to learn! OTOH, it might be time
better spent than re-implementing the code in Python when ArduPilot’s own
simulation is so good.

Peter

1 Like

Thank you so much Peter!

I was looking at SITL, and I might try it out, but for the project I’m working on, I have to chuck this code translated into python into a sim that will run hundreds of random instances. But I do hear what you’re saying about time better spent!

Right now, I’m working on understanding how ADSB then communicates to AP_Avoidance. It looks like adsb creates a struct filled with data about the oncoming vehicle which is then sent off via mavlink protocol. I can’t tell exactly what picks it up after it is sent. After that, I’ve just been looking through the AP_Math (I think Vector2 and Vector3) do a lot, and trying to understand the BendyRuler and Dijkstra calls to the specific math functions. I think it is just a series of instructions that directs what and how to complete the algorithms. I view it as an instruction book, or project manager, that tells/gives each code (like an engineer in this analogy) what to use to complete a specific task that all comes together to form the algorithm. Hopefully that made sense.

Thank you again for your response, it was extremely appreciated!

Best,
Jimmy