Coder Social home page Coder Social logo

open-source-ahrs-with-x-imu's Introduction

Open-Source-AHRS-With-x-IMU

Warning

This repository is no longer maintained and has been superseded by Fusion.

More information available on website.

open-source-ahrs-with-x-imu's People

Contributors

xiotechnologies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

open-source-ahrs-with-x-imu's Issues

coefficient 2 missing

Hello, I'm checking the formulas used in the code. I can understand all formulas apart from one, which I think might be wrong in your code.

In file MadgwickAHRS.cs lines 150-151 you have:

            _2bx = (float)Math.Sqrt(hx * hx + hy * hy);
            _2bz = -_2q1mx * q3 + _2q1my * q2 + mz * q1q1 + _2q2mx * q4 - mz * q2q2 + _2q3 * my * q4 - mz * q3q3 + mz * q4q4;

but I think you should have a multiplicative 2 coefficient:

            _2bx = 2.0f * (float)Math.Sqrt(hx * hx + hy * hy);
            _2bz = 2.0f * (-_2q1mx * q3 + _2q1my * q2 + mz * q1q1 + _2q2mx * q4 - mz * q2q2 + _2q3 * my * q4 - mz * q3q3 + mz * q4q4);

The vector [mx, my, mz] is the magnetometer output. Such vector is renormalized. Then the vector [hx, hy, hz] is computed using quaternion rotation:

            hx = mx * q1q1 - _2q1my * q4 + _2q1mz * q3 + mx * q2q2 + _2q2 * my * q3 + _2q2 * mz * q4 - mx * q3q3 - mx * q4q4;
            hy = _2q1mx * q4 + my * q1q1 - _2q1mz * q2 + _2q2mx * q3 - my * q2q2 + my * q3q3 + _2q3 * mz * q4 - my * q4q4;
            hz = -_2q1mx * q3 + _2q1my * q2 + mz * q1q1 + _2q2mx * q4 - mz * q2q2 + _2q3 * my * q4 - mz * q3q3 + mz * q4q4

(hz is equal to _2bz in the code). One can check that the above formulas are correct and correspond to the rotation given by the quaternion [q1, q2, q3, q4] which is normalized. Hence the resulting vector [hx, hy, hz] is a unit vector. If you let bx = _2bx/2 and bz = _2bz/2 we expect that the vector [bx 0 bz] should be a unit vector too. This is suggested by the name, but is also confirmed in the code which follows. In the computation of [s1, s2, s3, s4] (at lines 156-159) the coefficents _2bx and _2bz are used. The vector [s1, s2, s3, s4] is the gradient of the function f described in Madgwick article. The objective function f_b evaluates the difference between the earth magnetic field and the field obtained rotating [mx, my, mz] in earth coordinates. Actually [hx, hy, hz] are the coordinates of [mx, my, mz] in the earth frame and [bx, 0, bz] should be the vector with same inclination of [hx, hy, hz] unit norm and north direction. The objective function should evaluate the difference between [bx, 0, bz] and [hx, hy, hz]. I checked the the gradient [s1, s2, s3, s4] of the objective function is correct if we assume that _2bx and _2bz represent 2*bx and 2*bz as the name suggest.

You can check the code by printing hx*hx+hy*hy+hz*hz and _2bx*_2bx + _2bz*_2bz and see that both are close to 1.0 while the second one should be close to 4.0 since [_2bx/2, 0, _2bz/2] should have length 1.

License?

Please select an open source license when releasing software to the public so people know if they can use it or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.