Sebastian Madgwick's Quaternion solution - Episode II

I made nice progress - but not after having some bad experience.

As you may know I decided recently to replace DCM with the solution from Seb.

During my holidays in holland i got a terrible cold but i could work a little bit.

Not in terms of a total new framework but experience what to do and not.

I started to change the pid control loop using this guide: The balance filter

The biggest surprise was the amount of propellors used.

One hand is enough for counting :-)


Above a simple hovering in the garage.

and the same outside.

To me the result is ok.

I am happy to have something flyable in a short time frame.

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • If the code you are using is from Google Code then its rather old.  The latest versions of the code are available (and maintained) here:

  • @ionut

    i forgot to mention this link.

    you see some comments about filtertuning. and that is exactly where the difference is.

    the result is about the same but not absolutely.

    the other things - the code is much more compact:

    Binary sketch size: 112720 bytes


  • hi emile,

    during my initial test i found out that my copter flies upside down ... in the simulation ;-)

    the issue was the sensor sign vector.

    this vector is different between acm and the ardupiratesng sw.

    jason uses the dcm matrix directly and i assume that there will be occurencies where the different sign will cause a crash or some other misbehaviour. before i release the sw i need to verify this.

    else you blame me for a bad implementation ... ;-)



  • Nice work!

    Would it be possible to sneak your code? I would like to test it on the MP32 with a 1KHz loop and see the difference :)



  • @ionut,

    there are two implementations from seb. one covers dcm with his magnetic distortion compensation plus the marg implementtaion. i have chosen the later one becaise it has no explizit error integrator. which i think makes it very difficult to manage the copter requirements.

    the big plus is the 'no' gyrodryft behaviour.


    yes, i agree. rising the throttle a bit to much and you will see a clash where you didn't expect it.

    for testing i prefer knee.high grass and hovering about one meter above the gras.

    a flip will end gracefull ;-)

    but i like to give full throttle.


  • Moderator

    I have to say, that garage looks like a very unforgiving place to test. Concrete in all directions ;) You are braver than I.

  • How are you going to compare the quaternions with DCM.From my small experience quaternions are easier to implement to compute a resultant rotation compared to rotation matrix computations.Also they may be a little faster.But the results are the same.

This reply was deleted.