Understanding PX 4 Flight stack algorithm

Hi , I just got introduced to PX4 and I need some help. We are working on integrating Modelica with PX4, for which I am trying to understand the algorithm of the PX4 flight stack. I couldn’t find documents explaining this. Could someone guide me in the right direction ?

I went through the PX 4 udlser guide and development guide. I am going dig into the Firmware Git repo code files next to understand what the Flight stack really does. Is there a better source to do this , understanding what PX 4 flight stack does ?

The PX4 ecosystem can be a bit daunting to dig into. This page from the Developer Guide does, however, provide a reasonably good overview of how the firmware works: https://dev.px4.io/en/concept/architecture.html.

The developer guide (https://dev.px4.io) is probably a better place to start if you want to understand how the code works.

I actually have been reading through the Developer Guide for the past few days. But I find that too brief.

It says that there are modules like the “Navigator” , “Position Controller” etc… so what do these modules exactly do ?

How do I understand how the copter takes off ? what is the algorithm ?

While digging through the MAV Guide (https://mavlink.io/en/messages/common.html) I found that there are 36! flight modes! at least thats the number of CMD ID options in the FLIGHT_MODE_ parameter.
Counting everything from Manual, ALTCTL, POSCTL, Stabilized… TakeOff, Land, Descend…Steering…and so on. What do these really mean ?

Say I wanted to work on a new way to take off or follow mission points. How would I go about understanding the current implementation logic, algorithm ?

It depends on what you are actually looking for, but, from the firmware point of view, there are two different classes of “flight modes”: commander and the navigator states. You can find them into msg/commander_state.msg and msg/vehicle_status.msg, respectively.

PX4 modules are standalone tasks/works, so you can somewhat analyze them one by one. For instance, commander handles RC commands, calibration and arm routines, etc, while navigator handles mission items, mission modes and generate position references, which are later interpreted by the MPC (multicopter position control) module (if you are using a MC airframe) and so on.

If you are trying to implement a new take off strategy, you can both change how references and logic is set or how the position controller handles this information. For now, it is hard to say which one is the best solution.

Hey @alexh , Thank you.

These two classes of flight modes you mentioned, are these explained anywhere ? That’s the problem I am facing, finding how the FC really works instead of reading through .cpp files and msg details.

I have started going through them one by one, but are these summarized anywhere ? In total ? I founds short summaries of a few modules here and there on various pages but not all are covered.

To understand the best way to implement new features/update existing ones, the best way is to read to all of the relevant .cpp files? Isn’t there any document explaining using a Flow chart or algorithm ?

1 Like

As, @ksschwabe mentioned, I’m afraid that you will hardly find a specific documentation about the modules that is better written than the DevGuide itself.

Out of curiosity, what are you trying to do with Modelica?

@alexh I was afraid of that being the case. I was hoping someone in the community compiled a flowchart of the whole thing, or something similar.

@keenanjohnson we are building a dynamic model of an MC, which can later be used to develop and test features and functions of the PX4