Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status / Usage Example with Board? #1

Open
ssokol opened this issue Jun 10, 2022 · 8 comments
Open

Status / Usage Example with Board? #1

ssokol opened this issue Jun 10, 2022 · 8 comments

Comments

@ssokol
Copy link

ssokol commented Jun 10, 2022

I'm working on adding a magnetic heading sensor to an aviation application using an LSM303AGR sensor driven by an SAMD21. The sensor + micro provide raw readings to a daemon on a Linux system for processing into a valid heading. I am hoping I can use this project to build an automatic calibration function into the system. A few questions regarding implementation:

  1. Is there any scaling or other pre-processing required to use the magcal algo, or do I simply push the raw magnetometer readings to the apply() function?

  2. Do you happen to have an implementation example that shows how to extract the resulting offsets for application to the live data stream and for storage / re-use?

@ysoldak
Copy link
Owner

ysoldak commented Jun 10, 2022

Hi @ssokol and thanks for interest to my little hobby proof-of-concept project.

This is a library for my HeadTracker project that I never actually integrated into, since Gyro+Acc combo is more than enough for reliable hobby head tracking.

But the code that integrates this lib into the main project is still there, in git history. For usage example please check this commit that drops magnetometer support: ysoldak/HeadTracker@206a967

As for scaling, the algorithm tries to find coefficients for raw readings to end up on a sphere with radius magcal.Configuration.Target after calibration was applied to them. The default target is 1.0 so you have to divide raw readings roughly by 50000 (magnetic field intensity) if you like me live in Sweden (see code above). Theoretically, target is not important, since all we want is orientation w/o distortion, i.e. perfect sphere no matter what radius. And algorithm could guess any radius and work with it. In practice though, we want to avoid weird cases and have to keep and eye on coefficients so they still make sense. So just to make my life simpler I was scaling down raw readings to around 1.0 and testing the lib with that data. No guarantees it will work properly for any random target :/ A good feature/improvement, perhaps?

As said, this is still PoC since I don't really use it in my HeadTracker yet, so there may be some bugs and room for improvement. I believe in idea though and encourage you to give it a try and don't hesitate to ask or file PRs!

@ysoldak
Copy link
Owner

ysoldak commented Jun 10, 2022

One if improvements, I've just realised, this lib shall use runtime.Gosched instead of time.Sleep, see #2

@RafigRzayev
Copy link

RafigRzayev commented Aug 16, 2022

Hi,

You (@ysoldak ) wrote:

since Gyro+Acc combo is more than enough for reliable hobby head tracking.

I am using Gyro+Accelerometer in my project, and also using a fusion library. When there is no magnetometer, the drift in yaw angles is too much. One of my sensors has 1degree/sec drift in yaw angle.

Aren't you getting such values? If not, what are you doing so that your drift is such negligible?

I would appreciate your feedback :)

@ysoldak
Copy link
Owner

ysoldak commented Aug 16, 2022

@RafigRzayev some gyro calibration needed indeed. Thankfully, it can happen continuously and with low effort.
You can see how I solved it here https://github.com/ysoldak/HeadTracker/blob/master/src/orientation/gyrcal.go

@RafigRzayev
Copy link

Thank you very much!

I always ignored gyro calibration until now. That's why I am struggling with magnetometer calibration. Since my application is for dynamic/indoor use, the yaw angles are not stable because of magnetometer output. I was looking for a continuous magnetometer calibration method with hope to improve the readings, but I will try just accel+gyro method too. Hopefully it can get me rid of magnetometers :D

If not, I will try to adapt your code to C to see the results.

@ysoldak
Copy link
Owner

ysoldak commented Aug 16, 2022

Indoors, you may have real big problems with magnetometer. Not sure if that's possible.

@RafigRzayev
Copy link

Thanks for your feedback.

I heard similar opinion from one person before( who wrote a fusion library), but I kept trying because of following reasons:

  1. It seems to me that phones are using magnetometers in their compass applications pretty good. If I am not mistaken, newer model phones don't even need calibration inside the app.
  2. Also people use magnetometers for robotics, they should be getting noise too.
  3. I need long term stability in yaw angles.

That's why I kept trying with the magnetometer approach.

I do really hope that gyro+accel will be sufficient to get stable yaw angles.

Can you please tell me how long does it take for your yaw angles to drift 1-2 degrees? Can it last for several hours without changing?

@ysoldak
Copy link
Owner

ysoldak commented Aug 16, 2022

Well, try and walk with your smartphone and compass app in apartment and see how much it deviates due to hard and soft iron effects. Plus, I believe they do use gyro to assist compass (specifically important when indoors).

I did not conduct any several hours test. I did however left the device stationary for up to an hour max perhaps to observe no significant drift in the end, if at all. But again, stationary -- is the best condition for a self-calibrating algorithm.
Try it yourself, and see if it helps in your setup.

To have a reference, you may want to buy XIAO BLE board and SSD1306 128x32 display and flash my HeadTracker on it and experiment. So you can compare with your C implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants