Main loop and master schedule

I’m very much a novice, so apologies for the simplicity of the question. When I was looking through the source code, I had expected some kind of obvious main flight loop, that contains a lists of functions/tasks that are performed sequentially and continuously looped through in normal flight, however I couldn’t find anything to that effect. I’m guessing I fundamentally don’t understand the architecture of the firmware, but can anyone explain why there is no obvious main flight loop (or tell me where it is)?

@User_N here’s a diagram with the basic PX4 architecture

I hope it helps.

I’d like to reopen this. I’m a former Piccolo dev and am now getting spun up on PX4. As @User_N wrote, I was expecting main() to kick off a flowdown of major functions. Instead main() initializes a server/client setup that I’m not clear on. The architecture chart provided above is helpful in seeing how different components and modules interact but it doesn’t describe the program flow in a way that allows someone to understand how we move into and out of a state or mode.

For example, how would I determine which flight mode I am in for a given vehicle time and position?

Thanks all!

@Charles_Armer @User_N I think what you expected was something similar to the Arduino void loop()-function, right? I’m afraid you aren’t gonna find anything similar in PX4. The looping of specific functions is handled by the scheduler of the operating system that PX4 is running on (NuttX). In the code you need to watch out for calls to px4_task_spawn_cmd(). This function adds a task to the scheduler. From what I understood about this architecture so far is that it is much more dynamic than having a static loop function, that calls one task after each other. The schceduler can prioritize and deprioritize tasks and thus it can ensure real time performance for the most important tasks.