About learning px4 source code

Hi guys,
I’ve been dealing with px4 for half a year now and yet cannot understand the structure of the source code. This has been disturbing me for the whole summer. I wonder how you folks learnt px4 code on your own? I mean, when the whole project is cloned from github.com, how do I learn the role and function of each file (and how these files work together to perform on pixhawk boards) and so on. Though I’ve gone through dev.px4.io, I failed to find related info. What I really hope to do is understand the source code and be able to develop my own project (one without )
Hope that I can get some suggestions from you.
Much appreciated!

2 Likes

One way to do it is just understand how the system works on the top level. It is actually one UNIX ( Linux, Possix) operating system called NuttX. It runs on top of the Pixhawk Flight Controller Board, it starts programs with scripts that run in real time during flight or drive and control the craft or vehicle. The NuttX that we are using is not the regular open source version. But it is customized to the needs of PX4.

So if you open the boot up scripts in the github source tree, you will see which applications are started for which scenario, and then follow the source code of this applications. These applications run simultaneously in real time as i said.

All the sensors and hardware connected to the Pixhawk FC have a corresponding drivers in the NuttX in order to be available for the applications.

Imagine it as a tiny computer system with its own operating system and number of applications that interact. There is not one source code structured as you imagine. There are many source trees and many modules apps and drivers source code.

Hope it helps.

In the diagram above the Flight code for PX4 is “PX4 Flight Stack”.I want to Know where can I find the code base of PX4 is it in the link given below.
https://github.com/PX4/Firmware
Since I am new to learniing Px4 thank you Tubeme for sharing usefull information .

The flight code is here:

2 Likes

Well actually I already know that, what I hope to do is fully comprehend the source code, namely the software part. But anyway I’m heading for my goal with further knowledge of cmake now. Thank you all the same and surely your reply will hopefully help other starters as well!

Thank you all for replying and now I’m starting to understand the code with further knowledge of cmake. Here is my suggestion if anyone else faces similar problems: learn the use of CMake first and we will be able to understand the basic structure of the source code :slight_smile: the difficult part used to be the too many files on the screen haha:))

1 Like

Hi! Thank you for sharing your experience in learning the px4 source code. I am also new to it, which has troubled me for two months. I learned from some web blog such as http://uav-lab.org/tutorials/software/px4-2/ . But I cannt comprehend the source code as well. Can you give me some further advices ? Thank you very much

yun

1 Like

Where I can find the code in the link(https://github.com/PX4/Firmware) if I want to know how the pixhawk firmware connect to the pixhawk hardware? What I need to read is code related to uavcan module, drivers or Nuttx? I’m really confused. Thanks very much.

@ArayCHN Hello! Based on your experience, is Cmake enough to implement a own flight mode?