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.

Views: 2403

Comment by ionut on September 19, 2011 at 1:18pm

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.

Comment by Michael Pursifull on September 19, 2011 at 3:35pm

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

Comment by robert bouwens on September 19, 2011 at 10:22pm


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.


Comment by emile on September 20, 2011 at 2:01am

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 :)



Comment by robert bouwens on September 20, 2011 at 3:10am

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 ... ;-)



Comment by robert bouwens on September 22, 2011 at 9:09am


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


Comment by Seb Madgwick on October 4, 2011 at 11:48am

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:


You need to be a member of DIY Drones to add comments!

Join DIY Drones


Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service