| Electronics > Beginners |
| compass heading using MPU9250 |
| (1/2) > >> |
| hussamaldean:
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 |
| jeroen79:
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. |
| hussamaldean:
--- Quote from: jeroen79 on August 11, 2018, 08:10:35 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. --- End quote --- see the red comment |
| jeroen79:
--- 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 --- End quote --- 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 --- End quote --- 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 --- End quote --- I would find a pair of magnets to create a more controlled magnetic field. |
| hussamaldean:
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 |
| Navigation |
| Message Index |
| Next page |