I'm interested in quadcopters/multi-rotors and want to eventually code my own flight controller ala an APM and/or Pixhawk. I've got a little experience in programming (i.e i know about if/else/else if conditionals), and have done a little programming with PHP, though it was procedural code.

I currently have a quadcopter that i built/assembled myself that is running on a f450 frame, using a APM 2.6 flight controller,so i have a reasonable grasp of how a quad works, and i would like to take it a step further and make my own adjustments to the code base, with the eventual aim of coding my own flight controller.

I've had a look at the code base, but am still unable to get a grasp of what the code is actually doing....yet. How would i go about learning how to code a flight controller?

I'm thinking that i would have to learn C++ & OOP first, but how familiar/proficient would i have to be with C++ before i can reasonably attempt to edit the code base?Also, what else would i need to learn apart from C++ & OOP?I am looking at setting a 6 month timeframe/deadline for me to do this, would it be possible?

  • $\begingroup$ In my opinion, start doing simulation with OpenGL ( stick with C/C++). Get acquainted with the quadrotor models linear and nonlinear. The system is so complicated. master and Phd thesis's have been published regarding this matter. For simulation, the problem is getting harder because you need to have a good programming skills. The bottom line is that you might not get an answer for this question. $\endgroup$
    – CroCo
    Commented May 27, 2015 at 16:39
  • $\begingroup$ U just need to learn programing AVR microcontroller in c language, u can find tutorials on youtube , or u can find books on avr programing , ofcourse youtube is an easy choice . $\endgroup$
    – M0xff
    Commented Dec 10, 2015 at 17:56

4 Answers 4


Seeking proficiency in C++ or in OOP in general would either have to be a result of obtaining the necessary knowledge in order to browse through the code-base of the flight controllers that you mentioned, or with the eventual goal that this is what you would use when implementing your own flight controller.

The first thing is familiarizing yourself with the syntax and semantics of the language(s) used in the implementation of the flight controllers that you're interested in adjusting. The tricky part is actually determining what the code is doing. It helps if the code base is well documented and that the code is developed in a concise manner. For example, the functions and variables are named appropriately so that their purpose is clearly understood. Otherwise be prepared to follow through the logic of the code.

Once you have that down, one of the efficient ways when trying to decipher what the code is doing is to start from the beginning. Look for where the program starts when the flight controller is first turned on or is commanded to start executing whatever it needs to execute. Also what sort of initialization is it doing. Another thing is what sort of communication protocols that might be in play if the flight controller were to communicate with others. And then just work from there.

Ignoring the details for now, the sole purpose of a flight controller is really to monitor and control the whole system and possibly relay any information to others perhaps a ground station of something. This means having the knowledge of the sort of hardware/sensors/etc. that you need and need to be physically present in order to obtain the required data and make sense of it. Based on the data this will determine how the quadcopter should behave/maneuver.

As for wanting to implement your own flight controller it depends on what you are seeking. Are you looking to take the existing flight controllers and replace the program installed in its entirety or are you looking to design and build your own flight controller platform and then create your own flight controller code.

  • For the first case, look at the related documentation/datasheets of the flight controller at interest. In particular see if it's possible to make your own adjustments to the flight controller code.
  • For the second case, you might want to look into embedded systems development.

Controlling a flying robot (or anything else) is a very complex subject (well, people are doing PhD on it..). I can recommend this free online course on the subject (I have taken it myself). It will give you a little taste of what it is.

  • $\begingroup$ The link is broken. $\endgroup$
    – CroCo
    Commented May 27, 2015 at 16:26
  • 1
    $\begingroup$ @CroCo Well, this is the nature of outside links.. Updated to a new iteration of the course. $\endgroup$
    – Eugene Sh.
    Commented May 27, 2015 at 16:28
  • 1
    $\begingroup$ @CroCo Probably, but the learning experience is different. The course has programming exercises on a nice simulation platform and discussion forums. $\endgroup$
    – Eugene Sh.
    Commented May 27, 2015 at 16:32
  • 1
    $\begingroup$ @CroCo It's python $\endgroup$
    – Eugene Sh.
    Commented May 27, 2015 at 16:42
  • 1
    $\begingroup$ @ott Controlling using joysticks or in the best case some pre-made controller? Yes, sure. But the question here is about the underlying theory. $\endgroup$
    – Eugene Sh.
    Commented May 28, 2015 at 21:21

The course suggested by @Eugene Sh is a good one to understand in depth the relevant details. If you have general idea about how an aircraft (fixed wing) operates it will be actually helpful to you. Refer Small Unmanned Aircraft:Theory and Practice by Randal Beard, one of the pioneers in aerial vehicle research and T.Mclain. This is about fixed wing aircraft, but the navigation and guidance principles are same for both fixed wind and quad/tri-copters. This book is written in a very simple language with minimal equations. Will be very good for testing out some of your guidance strategies


Steps one should take to eventually write a flight controller software:

Step 1

Learn the mathematics and physics laws behind the airplanes, helicopters, multi-rotors, etc.

Step 2

Learn electronics.

Electronics is a huge field and learning the robotics related stuff would be enough.

Step 3

Learn how computers work.

The electronics behind a computer. How does a computer stores information, how does a CPU or micro-controller processes those information, how would you send those information to another system through the wire or air, etc. The concepts are same from an Arduino Uno to a bad-ass gaming PC.

Step 4

Learn a programming language.

Choosing a language depends on the platform you want to target. Are you targeting a specific micro-controller? then you need to learn that micro-controller's specific language (which is an assembly language or maybe a C like language). Are you targeting an Operating System? For example your goal may be that I want to write a flight controller for the Linux OS which requires the real-time patch and would work on any Linux enabled SBC with some specified MPU sensors that I support. In that case you need to learn C (because Linux's native APIs are in C) and you also need to master the Linux kernel. There are wrappers around native APIs in many languages but none of them cover all of the APIs and may give you less control over how you can call them.

Step 5

Put it all together!

At this point you can start writing a flight controller.

Depending on how much time and energy you have, this may take from a few years to a few decades! :D

This is why these things are usually created in a team work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.