foshlabs / OrientationFilter

The following code is an implementation of the orientation filter for a MARG sensor array including magnetic distortion and gyroscope drift compensation, in Swift.
MIT License
4 stars 0 forks source link

Failed usage #1

Closed Lelelo1 closed 4 years ago

Lelelo1 commented 4 years ago

Hello

I translated the swift code to C# so I could test it in my app. First of all I believe there is a typo mistake.

Secondly I wonder why the reference frame is taken depending on where the device is orientation in the start? I expected quaternion = []{1, 0, 0, 0} to always point north?

Thirdly I don't understand the 9 mutable variable declarations at the start, that are being normalized on occasions (divided by norm). Is there some sort of swift syntax in the update function that I don't understand - because I can't see those used anywhere?

adam-leitgeb commented 4 years ago

Hi Lelelo1,

Thank you for reporting the typo. I will fix it.

Regarding the quaternion - I'm sorry, but I don't remember. It has been a long time since I did this. However, here is a document where is explained everything regarding this filter and it's implementation.

About the mutable keyword. Swift has 2 kinds of property: constant (let, immutable) and variable (var, mutable). I put “mutable” keyword in property’s name because I thought most people reading the code won’t be Swift developers, so it’ll make it easier to understand. About the properties not being used, you're right as well. There is not hidden magic, but I really don't recall. I will revisit the code soon and fix anything wrong with it.

Please visit the link above, it'll give you answers to all your questions without needing this code.

Thanks for heads up!

Lelelo1 commented 4 years ago

Thank you for your response. There is few more things:

I believe the coordinate system is in ENU (East-North-Up) - since the AR objects in my mobile app almost appear correctly - but I am not sure. The axises of the sensor mobile devices is in ENU. (Although I have been told Madgwick is in NED (North-East-Down) - but the latest version from xio-technologies states itself being NWU (North-West-Up)

... the order of letter being directions of XYZ (as far as I have understood it)

I must have corrected something on my side as the ar objects (set to north at 0 deg) of the app appear to usually appear in the correct direction. Actually the problem is still there, I just get fooled because I usually sit in northern direction with the device..

Then I am intrigued about how you manage to set up the algorithm to fend off the magnetic perturbation. I can hold a metal fork around sensor to disturb - but it has no effect on the ar objects! Magnetometer measurements are being used - as I don't see the initial behaviour I described first (with the ar object always in the start direction of the device).

To use the algorithm I need correct that yaw drift (or whatever it is) - but first I should probably be 100% sure I give the sensor data in the correctly as well. So it is ENU - the same system the device sensor data is given in?

Lelelo1 commented 4 years ago

Do you remember if it should take raw or calibrated sensor inputs?

Lelelo1 commented 4 years ago

Okey, I found the reason. The magnetometer values needs normalisation before being passed to filterUpdate. This is needed - despite /= norm being done inside the method