Quadcopter Software Design

Before I begin discussing the quadcopter design, here is a diagram that shows the high-level software structure for my design:

All future software design posts will reference to this diagram.  Here is a short explanation of the necessity and function of each block:

PWM Decoder Driver:
In order to interpret flight commands from a standard RC Transmitter/Receiver, any multi-rotor design must have some sort of PWM decoder.  My decoder will be expecting a single signal containing all PWM channels (details here).  The decoder driver will translate the several channels of pulse widths into values to be interpreted by the command translator.

Command Translator:
Depending on the flight mode, the PWM values given by the transmitter are interpreted differently.  The command translator determines which mode the user is flying in and translates the commands accordingly.

I2C Master:
The inertial sensors I’ve chosen to use all run on the I2C protocol.  This high-speed protocol will be a great interface to use because of its addressing scheme and its interrupt time efficiency.  The I2C protocol is more complicated that most serial protocols but the LPC1768 has built-in hardware to handle the physical layer.  The I2C interrupt scheme for this hardware is very efficient with each interrupt needing only a few lines of code.

Sensor Fusion:
As mentioned in an earlier post, I will be implementing several sensor fusion algorithms to find out which has the best performance.  The first one I will implement is the Extended Kalman Filter (EKF).  The EKF algorithm is widely known to be one of the best methods for state (in my case aircraft attitude) estimation.  This filter will take the sensor readings from the various sensors and output an estimation of the current aircraft attitude.  For my initial design it will be important to measure:

  • Roll – Side to side angle relative to the horizon
  • Pitch – Front to back angle relative to the horizon
  • Roll Rate – Side to side rotational rate relative to the horizon
  • Pitch Rate – Front to back rotational rate relative to the horizon
  • Yaw Rate – Horizontal rotational rate relative to magnetic heading
  • Magnetic Heading – Direction relative to magnetic north

Proportional-Integral-Derivative (PID) Stabilization:
Once the desired aircraft attitude is determined from the transmitter commands and the actual aircraft attitude is determined from the sensor fusion algorithm, PID controllers are used to determine the fastest way to make the desired attitude become the actual attitude.  PID controllers are very efficient for control of a system in which an accurate physical model is unknown.  Using calculus to determine error slopes and areas, PID controllers compensate for environmental noise and disturbances while overcoming steady state error and oscillations.  PID controllers are VERY simple to design and code but are VERY hard to tune and calibrate.  (see this post)

Multi-Rotor Throttle Mixing (MRTM):
Standard helicopters use Cyclic Collective Pitch Mixing (CCPM) to adjust the aircraft attitude.  It works by adjusting the pitch of the blades depending on their current angular position.  I came up with term MRTM, as I haven’t found a term defined for multi-rotor helicopters.  MRTM works by adjusting the speed of several propellers in such a way that results in the same aircraft control and a typical helicopter (a post will soon follow that explains this in detail).  MRTM can be used to control the attitude of many styles of multi-rotor helicopters.

PWM Encoder Driver:
Once everything has been computed, the PWM Encoder takes the control values and generates a pulse width modulated (PWM) output for each motor.  This is the exact opposite process of the PWM Decoder.  The LPC1768 has good support for PWM output.  I’ll be able to output all channels of PWM without using any interrupts or processing time.  Can’t beat that!

  1. Looking good Nic!

    • Ahmed Samy
    • February 10th, 2012

    please Can you help me to diagram the FCB () and ESC chips for T580 Quadcopter……
    like your design ……… please
    E-mail :ahsamy_90@yahoo.com

      • nic
      • February 10th, 2012

      I’m not quite sure what you are asking for. Do you want a software flow diagram of the T850? I’m not familiar with that quadcopter.

        • Ahmed Samy
        • February 11th, 2012

        Thank you for your response …….
        Yes , i want a software flow diagram or schematic diagram of the T580 Quadcopter
        i hope you can help !!!!

      • nic
      • February 11th, 2012

      Sorry, I don’t know anything about the T850. Any diagram I make for it would be B.S.

  2. Did you succeed in making and testing the different Sensor fusion algorithms?
    I just started planning my own QuadCopter and would like to know whether you can share this code?

      • nic
      • February 23rd, 2012

      I have not yet implemented the sensor fusion algorithms. Unfortunately my quadcopter design has been put on hold. Hopefully I’ll be able to finish it up this summer.

    • David Winchell
    • October 31st, 2012

    Great start and GREAT basic explanation

    • su
    • November 29th, 2012

    hey !! we need your help…we are trying to make a quadcopter using stellaris lm4f232 microcontroller .we are stuck up with the programming .the code how to go about with it .can you help us out please

    • Hi! So what do you have done so far? The first thing you need to do is start making a “board support package”. If you aren’t running under an operating system, then you just need to write some drivers to interface with all the hardware components you are using on your quadcopter. Once you have tested all the drivers and can communicate with all the components, you should just start building the quadcopter from bottom up. I started with a basic interface to my RC receiver. I made sure I could interpret commands from the RC transmitter. I then worked to convert those commands into quadcopter attitude commands. Those commands are fed into PID controllers which then control the motors directly.

        • su
        • December 2nd, 2012

        do you know anything about sourcery code bench which is an IDE by Texas instruments ?

      • I’ve never used it, but a quick Google search shows that Mentor Graphics made it and that it is based from the Eclipse IDE, which I use for my development. It is pretty standard for companies to supply an Eclipse based IDE for embedded systems development. They are easy to use. If you are having trouble using it, I’m sure TI (or Mentor Graphics) has small tutorials you can follow.

    • Samuel Sandesh
    • February 3rd, 2013

    can you please guide me through the balancing of my quadcopter
    am using ATMEL MEGA 16BPAAU1133 controller.

    Please help with this.


    • Hasan
    • February 11th, 2013

    Excellent post nic
    i am weak in programming can u plz mail me your whole quadcopter code i shall be very thankful to you for this act
    my email is hasanamjad1272@yahoo.com

      • nic
      • February 12th, 2013

      I created this blog so that those who are “weak in programming” can become strong!

    • Luc VandenBorre
    • September 3rd, 2013

    Hello Nic,

    I’m looking to build my first quadcopter. My target goal is to build it from scratch. However before i can actual start i’m looking for some study material on different platforms. My target platform is an advanced C8051F120. It runs at 100Mhz and has a lot of features on board.
    The reason for this is that i have two development kits in my possesion that i used earlier to build a robot.
    My only concern is the limited ammount of memory.
    I’m not sure if i will be able to put everything into it.
    If this kit is not sufficient i will aim for an ARM controller.
    Unfortunatly I have to learn the arm architucture from scratch.

    Could your share your C-code and schematics e with me so that i can learn how things are implemented ? You can send it to

    I already read your notes about PID and it seems easy to do in theory but translating into a working solutions looks like a daunting tast to me.

    At the end i would like to have a quadcopter that can be controlled with commands send from a PC instead of an RC.

    Thanks advance for replying


      • nic
      • September 18th, 2013

      Sounds like a fun project. The C8051 might do OK, but you might want a better processor. 8-bit processors are fairly slow. However, if the hardware peripherals are good, it may not matter.

      All of my code that is releasable at the moment is on this blog. Sorry, I don’t have a full release yet. If you ask specific questions, I might be able to help you.


    • sai malik
    • October 15th, 2013

    can u send me the algorithm or whole coding of a quad copter I want to make my own please help me

    • There are many components of quadcopter design. I’ve covered many of them here, but not all of them. Code samples are given on each post. I don’t give away full code, because it isn’t ready for release.

    • Zeeko
    • July 27th, 2014

    awesome Nic ! great job !

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: