-
Notifications
You must be signed in to change notification settings - Fork 27
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
C# implementation in cross platform Xamarin app #1
Comments
I decided to translate the code into C#: https://github.com/Lelelo1/AHRS-CSharp |
Hello! I was not comfortable with Matlab when I started to work on AHRS algorithms too, but today, I can confirm this language is designed for these kinds of algorithms thanks to good readability. I translated some parts of this code in Java/Android, and it took me hundreds of lines compared to 30 for Matlab. About your thoughts on:
If I can recommend something to enhance the built-in AHRS filters of iOS and Android devices, it is to control the calibration phase. I have noticed their calibration algorithm seems to be good, but as they do it "on-the-fly" (at least for Android), sometimes, data received by sensors are not well suited for their About the comprehension of
|
What about the sensor input to the algorithms, Currently I noticed my |
Can you provide a code snippet to understand the problem better? |
I see. |
Can you give me the value of About the Gravity vector, you can safely use [0, 0, -9.81]. The real value of the local gravity vector is not necessary for this kind of application |
geoMagRes: (The date there is old because that particular package hasen't been updated with latest world magnetic model data) QMagneticTue:
Great one less needed external package! |
I have tried to pass that check with matlab trial test project that I have - It still says:
It is the vector MagRef that ends up being constructed wrong, as I temporarily removed the |
About that check my MagRef still don't pass it. It assumes the value of 3, when it should be 2. I have traced it to the declination. The declination of the matlab source code end up being
My declination is However I also noticed MagRef is not created with i'ts x-component sufficiently near 0 in my translation - even when using the matlab values as input for the method. |
Regarding your data, it seems your WMM library is reporting values in NED coordinates, so you have to convert them to ENU (at least the vector and the declination) if you want to keep coherence through the project. To summarize:
Then, in
|
So it seems the setup prior to using the algorithm is not the problem. I found I could use the most recent wmm from the api as well.
So I end up with this
Notice |
Do not worry, |
Ok! |
When it comes to the sensordata I assume these should be given as they are.
But I was not aware of the (2) most common coordinate system you describe. I think that operation in this circumstance resulted in a quaternion in the style of the standard os attitude - which to my understanding must be It says in visualiseAttitudeOnSpecificDataset.m that the data set is in Looking at how the native sensor data is extracted in Xamarin.Essentials - it is there for some reason made differently in case of the accelerometer depending on the platform: Accelorometer
Difference between Running one first row of sensor data as update, and second row into update I get
with the translated
My progress so far I made sure the projection in my app which uses a game coordinateesystem receives it's attitude in Current observed differences between There is instability using |
Its much more stable on my iPhone11, however both the translated |
True
NED is mostly used for aerial vehicles (UAVs, aircrafts, satellite...) whereas ENU is mostly used for ground vehicles/objects (robots, cars, smartphones). The reason is developers prefer to have a positive value on z-axis. Fortunately, smartphone manufacturers use the same coordinates system: ENU.
Yeah that is funny too, iOS considers acceleration on the z-axis as its opposite.
That is not an easy part but all algorithms can be tuned with parameters to get the best of each. The "25-sec convergence" can be reduced if you trust less the gyroscope in the Kalman algorithm. |
Because Android does not provide an "accelerometer-calibrated" value. That is why I created a specific dataset each day for the "accelerometer calibration". But, as you can see in this table, accelerometer calibration does not have a huge impact on the output quaternion. |
To have an idea of the rendering of MichelObs and a native filter, have a look here: |
First of all, sorry for being late with this response. My free trial of matlab has ended. But I am considering getting a license - so that I can continue translating and control existing translated algorithms. Then, to be totally sure - I would have to generate multiple quaternions in matlab and save it as a text file. Then run C# version and see if the quaternions are the same. About android there is in fact calibrated/uncalibrated accelerometer present . When it comes to parrying magnetic distortion, I am slightly worried with this procedure: https://github.com/tyrex-team/benchmarks-attitude-smartphones/blob/master/src/Filters/Implementations/QMichelObsExtmagWtRep.m#L44 |
I just had a look on it and you are right, they "recently" added an "AccelerometerUncalibrated" field
Not exactly, in fact, during this period (when the value is upper than the threshold), the new quaternion is generated only using the gyroscope and the accelerometer. The trick is here, magUpdate is set to 0, so the magnetometer weight in the prediction is 0 too. |
I've tried turning off the magnetometer. In that situation there is no absolute reference - so the items in my app is shown differently depending on the initial device frame. Also, I have looked more closely on magnetometer calibration - and I wonder, can't the sphere be constructed with WMM vector? That might lead to a completely pure magnetic measurement: hightower70/MagCal#1 ? |
That is the normal behavior ;)
The WMM for the magnetometer calibration, as far as I know, can only be used to grow or shrink the sphere. (see src/Calibration/Magnetometer/retrieveParametersFromMagnetometerCalibration.m#L21) |
It is just in my case, there is slight risk that the user will be showed invalid visual UI elements during time using that time:/ (It relies on magnetometer to position them.)
Should it not be someway that:
and then It says: https://github.com/kritiksoman/Magnetometer-Calibration
So constructing a sphere with magRef, and subtracting all magnetometer measurements - could possibly create valid magnetometer values at all time? |
True. Maybe you can provide a feedback to the user until it is not in an area without magnetic distortions.
I am not sure to understand what you are talking about. Vectors? Vectors' norm? Distortions?
You do not construct a sphere with magRef (magRef is fixed by WMM given a {lat, lng, alt, time}) but with the magnetometer measurements.
|
It's just that the wmm vector is always present in the measurement. So therefore it should be possible to know where all the distortion is coming from? If I have understood basic physics vector teachings in school, the measurement is a total of all magnetic forces involved:
Also, the wmm vector is always present. And it is a sphere. So I I don't really understand why calibration can't be done against the sphere of Thank you for the details, the calibration concepts is more understandable now. |
Ok, so you cannot do that with vectors directly. Vectors are not coming from the same coordinate system (Local Tangent Plane frame [sometimes called "World frame"] for MagRef vs Device frame for Magnetometer measurements). However, you can use this formula with vectors norms |
(that was with device os's calibration) Still, if you have an environment cleared of magnetic disturbance like how the experiments where made - won't the MagRef vector be present somewhere in the raw magnetometer sensor data? |
Here is an implementation I found with magnetometer calibration and wmm: https://github.com/PX4/Firmware/blob/master/src/modules/commander/mag_calibration.cpp#L904
...and
In the It uses wmm in more in
Which I believe would same the as the shrinking of the sphere you mentioned. The short calibration method implementation was not very applicable for me though as it requires a prequest (accuarte) heading. I think it is more meant as an on the go calibration - but it still contain some interesting wmm code.
|
About the hard iron distortions => no because you only remove the values which are in the same frame of the sensor If you want further information, I recommend this paper: https://www.hindawi.com/journals/js/2010/967245/
It seems.
Do not forget; the WMM is still mandatory to transform your attitude from the Magnetic North Frame to the True North Frame. |
Is it any chance any of them are similar to the one mentioned article and could be useful? |
I am not sure we are talking about the same thing, but, if you are looking for an algorithm to retrieve the ellipsoid you have to find a code to fit an ellipsoid, e.g. https://skotagiri.wordpress.com/2010/06/19/c-implementation-for-fitting-an-ellipse-for-a-set-of-points (I did not test). |
Thanks I can probably try that out. |
I have decided that I will move on with my app project without using the most ideal magnetometer and ahrs setup. I lack too much of the scientific expertise and mathematical knowledge to implement special calibrations and some filters. Many android devices don't have a magnetometer, those that do seem be worse than those on iPhone. So I will instead mainly target iPhones instead. |
Hello again. Either way I am looking for a better alternative in case the magnetic disturbances causes to much inaccuracy. To my question: |
Hello, and sorry for the late answer As you noticed, the filter alone is far to be perfect. The magnetometer calibration in a good context is really important if you have a look at the document here: http://tyrex.inria.fr/mobile/benchmarks-attitude/ (Table 4) I do not know in which context you need an AHRS, but in a real app, you often fuse it with other sensors to improve the accuracy. (ie. at Wemap, we need attitude estimation for AR/Map navigation: https://blog.getwemap.com/geo-ar-the-challenges-of-navigation-from-the-web-browser-79eaaf6eab3f) About ML, I have no idea. |
I spoke to the a ceo of ESPrtk, as I found this video: https://www.youtube.com/watch?v=Udo9jRyJD1A&t=81s Yea I am suing the ahrs in my app, I forgot to provide a link: https://apps.apple.com/se/app/seeknav/id1537320921. (There is video when opening on an phone, and i'ts only iOS for now) |
I just want to clarify a point about the calibration process. From my point of view, using IA or a mathematical approach to calibrate the magnetometer will not solve the whole approach of the AR/Navigation because of :
You are right, our correction is made if the user does some steps. |
Hello!
I am looking to use these set of filters and algorithms to improve the overall accuracy of my navigation app - after having read Attitude Estimation for Indoor Navigation and Augmented Reality with Smartphones. The app currently takes os calibrated acc, gyro and mag readings into madgwick and uses the attitude quaternion that is returned.
Here is a screen recording of the app in i'ts current state.
There is some inaccuracies when indoors, certain areas outside and near house walls - which I believe is caused by magnet perturbations. I have measured the µT and found these to rise or fall in this places. However given from the small discussion at xioTechnologies/Fusion#8 - I learned that all perturbations are not reflected in the µT.
I was hoping I could try the magnetometer calibration with Barz and one of the MichelObs sensor fusion algorithms
My problem right now is I have no knowledge of matlab and also have very little math knowledge - so it is very hard to translate. It also seems difficult to use Matlab code in another languages (C# in this case) - It requires MATLAB Coder
The text was updated successfully, but these errors were encountered: