Hi, new to the forums and it looks like a very active community!
I have been trying to get heading out of my LSM303DLHC magnetometer chip, playing around with output data and different tilt-compensated methods etc. etc. I continuously got heading data which would be semi-accurate (accurate to changes in heading, not absolute) for some portion of the 360 degree revolution then go completely nuts.
I started plotting the raw data to make sense of what why this was happening which I'll show in an image. First though: magnetic field information. Where I am from the declination is 8° (not really important at this stage) and inclination is 67° (this seems oddly high to me? Maybe this is why getting heading is so difficult where I am?). Anyway, here are the plots:
[*] The first plot shows the RAW DATA output from the magnetometer in the x and y directions.
[*] The second plot shows each channel of the raw data centred around its average point (simply shifted up or down). Eg. x max = 20000, x min = 10000, avg = 15000, so shift down 15000.
[*] Third plot shows heading from the shifted channels.
So you can see that my heading from these isnt too bad, calculated simply using the ATAN2 function. The problem arises when I apply the 'shift' value (15000 in the example) in the code. The shift value seems to be very very sensetive each time I run the arduino. Even in the example above you can see that some of the values are out (Eg. at approx 65 seconds in, we see a heading change of approx 200° when in reality it was only a 90° turn.
This led me to plot the raw data on a 3d scatter plot which is shown below (this is the calibrated data now). You can clearly see that it is well calibrated, a nice sphere centred on the origin. The data points in the bottom right shows the progression of points when I sit the chip flat on the table and rotate it. (Black lines hand drawn to show rough path). Things to note are that it is not centred around the z axis, hence why the shift I did in the earlier graphs worked so well! I also noted that it is an awfully small circle (due to the inclination angle of hte magnetic field? but even that is 70 degrees which should result in a larger circle than the one shown...
One thing this magnetometer does damn well though is NOT drift. you hold it steady and that red dot is not creeping anywhere!
Any ideas on what issues with the sensor or my working through trying to find the heading?
Heading from magnetometer, bogus(?) data (with 3d plot)
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- hvince95
- Posts: 1
- Joined: Thu Mar 08, 2018 7:43 pm
Please be positive and constructive with your questions and comments.