Author Topic: compass heading using MPU9250  (Read 5248 times)

0 Members and 1 Guest are viewing this topic.

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
compass heading using MPU9250
« on: August 11, 2018, 07:09:46 am »
Hi all,
I have MPU9250 and I want to use it as heading for my project which requires a heading to be entered via serial
anyway, how do I convert the magnetometer values to heading values ?
I tried atan2(y,x) and it didn't work at all
 

Offline jeroen79

  • Frequent Contributor
  • **
  • Posts: 529
Re: compass heading using MPU9250
« Reply #1 on: August 11, 2018, 08:10:35 am »
What values does the chip return for the magnetometer's X, Y and Z?
Do they as expected when you rotate the chip and align each axis to the local magnetic field?

How exactly does atan2 (x,y) "not work at all"?
How are you testing it and what results are you getting?

Atan2 (x,y) will only give valid results if you keep the Z axis vertical.
If that is not the case then you need to involve the other sensors and some more math.

Mind that the earth's magnetic field is not north aligned and that all sorts of global and local things influence it.
You should first establish how the local magnetic field is oriented or provide a known field with some magnets.
« Last Edit: August 11, 2018, 08:14:27 am by jeroen79 »
 

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
Re: compass heading using MPU9250
« Reply #2 on: August 11, 2018, 08:14:31 am »
What values does the chip return for the magnetometer's X, Y and Z?
uT for each axis
Do they as expected when you rotate the chip and align each axis to the local magnetic field?
could you please explain
How exactly does atan2 (x,y) "not work at all"?
when I rotate, the angle goes from 0 to 180 only
How are you testing it and what results are you getting?
I am comparing it with my iPhone
Mind that the earth's magnetic field is not north aligned and that all sorts of global and local things influence it.
You should first establish how the local magnetic field is oriented or provide a known field with some magnets.

see the red comment
 

Offline jeroen79

  • Frequent Contributor
  • **
  • Posts: 529
Re: compass heading using MPU9250
« Reply #3 on: August 11, 2018, 09:27:53 am »
Quote
What values does the chip return for the magnetometer's X, Y and Z?
uT for each axis
Do they as expected when you rotate the chip and align each axis to the local magnetic field?
could you please explain
When you align one axis parallel to the magnetic field it should give the maximum reading and the others should give 0.

Hold one axis perpendicular to the magnetic field and rotate the chip around that same axis.
Do the other axes follow a sine and cosine relative to the rotation?
Quote
How exactly does atan2 (x,y) "not work at all"?
when I rotate, the angle goes from 0 to 180 only
Does it perhaps go from -180 to 180?
If not, please be more precise.
Could you post a table of the raw x, y, z values for each 30 degrees of rotation?
Quote
How are you testing it and what results are you getting?
I am comparing it with my iPhone
I would find a pair of magnets to create a more controlled magnetic field.
« Last Edit: August 11, 2018, 09:32:18 am by jeroen79 »
 

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
Re: compass heading using MPU9250
« Reply #4 on: August 11, 2018, 10:10:15 am »
I got these data
x-axis                   y-axis               z-axis
43.335868   -74.113182   16.532526   
47.050373   -74.997589   16.702964   
46.696613   -73.228775   17.043840   
44.750919   -73.759422   16.532526   
45.635326   -74.643829   17.043840   
45.635326   -74.643829   17.043840   
46.696613   -74.290061   17.043840   
45.458442   -73.759422   16.532526   
44.927799   -73.936302   16.021209   
44.927799   -72.875015   17.043840   
44.927799   -74.643829   14.316826   
44.927799   -74.643829   14.316826   
45.281562   -72.167488   16.362087   
46.696613   -74.290061   15.680335   
46.342849   -74.997589   15.680335   
47.404136   -74.290061   17.043840   
47.404136   -74.290061   17.043840   

and I am trying the magnet thing
 

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
Re: compass heading using MPU9250
« Reply #5 on: August 11, 2018, 10:15:58 am »
when I use the magnet, I get the maximum value of 5584.244140    and when I rotate the chip around the same axis, the sensor have same value and doesn't change at all
 

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
Re: compass heading using MPU9250
« Reply #6 on: August 11, 2018, 11:04:54 am »
Hi all
I fixed the issue and I managed to get the heading correctly and the issue was the printed axis on the PCB was in correct and it was not helping me out
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11714
  • Country: my
  • reassessing directives...
Re: compass heading using MPU9250
« Reply #7 on: August 11, 2018, 11:39:09 am »
I got these data
we got lego hi technic compass sensor here. and it has calibrate method and describes how to do it... during calibrate command, rotate the sensor a little bit more than 360 degree in 2 minutes times (i'm guessing the slowness is to avoid excess vibration that will make invalid reading during data collection). i'm guessing the sensor will collect data during the process and interpolate/compensate appropriate heading angle after that. you should do the same and provide again the data while its being rotated in full rotation.

I would find a pair of magnets to create a more controlled magnetic field.
if heading relative to earth is required, any man made / artificial magnetic field should be avoided. the calibration to earth pole should be conducted in any free artificial magnetic field influence. this given you are not located near north or south pole that doing calibration will give difficult result.

from the data we should be able to see the maximum (or minimum) magnitude reading when sensor in parallel to the magnetic field. ymmv.

I got these data
edit: and can you provide data with comma separated so anybody can help you analysis in excel easily by copy pasting? 2cnts.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline hussamaldeanTopic starter

  • Supporter
  • ****
  • Posts: 271
  • Country: iq
Re: compass heading using MPU9250
« Reply #8 on: August 11, 2018, 11:41:09 am »
I got these data
we got lego hi technic compass sensor here. and it has calibrate method and describes how to do it... during calibrate command, rotate the sensor a little bit more than 360 degree in 2 minutes times (i'm guessing the slowness is to avoid excess vibration that will make invalid reading during data collection). i'm guessing the sensor will collect data during the process and interpolate/compensate appropriate heading angle after that. you should do the same and provide again the data while its being rotated in full rotation.

I would find a pair of magnets to create a more controlled magnetic field.
if heading relative to earth is required, any man made / artificial magnetic field should be avoided. the calibration to earth pole should be conducted in any free artificial magnetic field influence. this given you are not located near north or south pole that doing calibration will give difficult result.

from the data we should be able to see the maximum (or minimum) magnitude reading when sensor in parallel to the magnetic field. ymmv.

I got these data
edit: and can you provide data with comma separated so anybody can help you analysis in excel easily by copy pasting? 2cnts.
no need
I figured out everything
thx for your help
 

Offline jeroen79

  • Frequent Contributor
  • **
  • Posts: 529
Re: compass heading using MPU9250
« Reply #9 on: August 11, 2018, 01:28:26 pm »
I would find a pair of magnets to create a more controlled magnetic field.
if heading relative to earth is required, any man made / artificial magnetic field should be avoided. the calibration to earth pole should be conducted in any free artificial magnetic field influence. this given you are not located near north or south pole that doing calibration will give difficult result.
I meant it for use on the bench when testing the sensor.
When using it in the application any magnrtic disturbances must indeed be minimised.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf