Sebastian O.H. Madgwick's Filter in action

i have been struggling with gyro drift and up to now no real solution exists.

it effects the pirates and the newer arducopter2 code base because both build upon the same dcm implementation.


i played around with the pirate code base and could improve the situation a little bit.

and after a few trials i decided to replace the current dcm implementation by the quaternion solution from sebastian madgwick.


what i need is some more tuning and a better pilot :)

there was quite a bit of wind today. and gusty wind between the rain showers.

Views: 3110

Comment by ThomasB on July 10, 2011 at 12:18pm

Hi Robert,

Congratulations to your implementation. I hope we will see some longer video in the next time.

Is it possible to see the code of your solution?

By the way, it seems that your test area has exactly the same immense dimensions like mine ;)

Comment by robert bouwens on July 10, 2011 at 1:17pm
yes, i will publish the code.
i need more time to tune the parameters.
takes more time as expected.

Comment by Ryan Beall on July 10, 2011 at 4:30pm
quaternions are a much better approach.  A lot less overhead!
Comment by Andrew Rabbitt on July 10, 2011 at 5:18pm
Congratulations!  I have been working through the quaternion math in an effort to replace APM_DCM with a Quaternion equivalent.  Well done that you made it happen!
Comment by ken on July 10, 2011 at 8:49pm

Forgive my ignorance, but I have a few questions (which I hope are neither too dumb nor too forward). How much drift are you talking about, a few degrees per second? Shouldn't that be fixed with a magnetometer? Isn't the quaternion version the same algorithm just applied with quats instead of matricies? If it is the same algorithm, why would there be a difference in performance? Are you suggesting that this DCM implementation has a bug?

Thanks, again sorry if they are stupid questions. Either way, I am partial to quaternions.

Comment by Andrew Rabbitt on July 11, 2011 at 2:02am
I rather like quaternions too, but I don't think they're magic enough to fix gyro drift...
Comment by robert bouwens on July 11, 2011 at 9:51am


pls. read jason's comment on gyrodrift

the quaternions might be a tad to non magic ;-)

sebastion claims it is not subject to accumulate errors: demonstration

comparison of methods

to me the integrator as is has a few flaws. the most important one is it introduces a delay and delays create an instable system. those delays are visible as low frequent whobbles in the air.

at the moment i need to increase the convergence of the gyroscope bias.

Comment by Roy Brewer on July 12, 2011 at 10:08am

Sebastian is on DiyDrones


His own conclusion:
"Conclusion:Mayhony’s algorithm is computationally less expensive and more ‘elegant’. In my own work, I now use Mayhony’s for these reason but I combine it with my ‘magnetic distortion compensation’ algorithm for the reasons given above."

Note that in the video you linked, the poster claims he may not have implmented te Mahony DCM correctly.

Note also that quaternions require less computational effort in the sense that they only require 1 constraint to be enforced, since they have only one "redundant" parameter, whereas orientation matrix (DCM) has 6 extra parameters and associated constraints. But, rotating a vector is much cheaper for DCM than for quaternions. Which is the better chpoice depends on which tasks you need to perform.

- Roy
Comment by robert bouwens on July 12, 2011 at 11:14am

hi roy,

your arguments are abs. correct.

to me it was amazing - i did not spend too much time on putting everything together. the video itself is made on the first day without crashes. my main problem area was the error feedback for the pid pwm calculation (actually only pi). here i prob. make an other change to simplify things.

computationally it is amazing - i upped the mainloop frequency up to 333 hz and my newer copter flew nicely. the older one is dead now ;-)




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