Structure of the code


I am new to all of this, and am trying to make sense of the code.

What I can’t understand is, what is the main code that runs? All the cpp files have function declarations only. There must be a main function that calls all the functions right? If yes, where is that? If no, can someone give me an overview of how the codes are linked to each other? As in when I go from GUIDED mode to say RTL, how does the transition in code take place?

Any help would be appreciated!

Maybe you could start here:


1 Like

I did read that, but didn’t understand every bit of it.
I can understand when we run an example sketch.

How is the code accessed when I go from GUIDED to RTL mode in missionplanner, say?

ArduCopter is a multithread code, in ArduCopter.cpp you have the setup and the declaration of the Scheduler, and there you can see all the threads available, their frecuency, and their máximum time.
To answer your question, when you change the flight mode from GUIDED to RTL, the “flight_update” thread is the one in charge of doing all of that. (You can see what it does in “flight_mode.cpp”

Is it real multithread? how it handles locks ? can u explain more ?

Depends on the underlying hardware, but in (very) short and oversimplifying: interrupt handlers on Arduino based hardware, and semaphores and equivalents on hardware with OS. See this: