0

I have a digital magnetometer (compass) which outputs the following:

  • Magnetic flux density ranging $\pm1229\mu\text{T}$ on the X axis
  • Magnetic flux density ranging $\pm1229\mu\text{T}$ on the Y axis
  • Magnetic flux density ranging $\pm1229\mu\text{T}$ on the Z axis

I would like to convert these values into degrees (relative to the north).

Searching on the web, I found that $\arctan\left(\frac{y}{x}\right)$ should give the answer in Radians.

However, rotating the device on the XY plane, I only get values from $10$ to $60$ degrees.

I believe that I am correctly converting the raw (measured) data into magnetic flux density.

Any idea would be highly appreciated.

Relevant documents can be found at:


Empiric Measurements:

   | North | East  | South | West
---|-------|-------|-------|-------
 X | -75uT | -50uT | -25uT | -50uT
---|-------|-------|-------|-------
 Y | -35uT | -10uT | -35uT | -60uT
---|-------|-------|-------|-------
 Z | 140uT | 140uT | 140uT | 140uT

UPDATE:

I've found the following neat description, which might explain why I keep getting values within only a single quarter of the circle:

$ h(x,y)= \begin{cases} 90 & x = 0 , y\neq0\\ 0 & x\neq0 , y = 0\\ \arctan\left(\frac{y}{x}\right) & x > 0 , y > 0\\ \arctan\left(\frac{y}{x}\right) + 360 & x > 0 , y < 0\\ \arctan\left(\frac{y}{x}\right) + 180 & x < 0 , y\neq0\\ &\\ \end{cases} $

The article also claims that we need to use the accelerometer values in order apply correction on the magnetometers values, before we use them in order to calculate the compass heading, but that is besides my main concern for now:

enter image description here

barak manos
  • 43,109
  • Please post flux data for two measurements in orthogonal directions. – Justpassingby Dec 25 '15 at 12:05
  • @Justpassingby: Done, thanks. – barak manos Dec 25 '15 at 12:17
  • How come the x components are not each other's opposites then? There must be a problem with the measurements, check for interference from other sources of magnetism. – Justpassingby Dec 25 '15 at 12:19
  • @Justpassingby: Though, by "orthogonal", did you mean $90$ degrees offset between them? (since north and south are at an offset of $180$ degrees). – barak manos Dec 25 '15 at 12:19
  • I did but then the x and y components should have been exchanged or opposite. Same comment as before, – Justpassingby Dec 25 '15 at 12:20
  • @Justpassingby: Pointing east, Y goes to $-10$. Pointing west, Y goes to $-60$. Pointing north and south, it stays around somewhere in between ($-40$ according to my measurements, but I'd take $\pm5$ on all of them). What does this tell us about the Y component? – barak manos Dec 25 '15 at 12:28
  • Perhaps you need to calibrate the device? – Justpassingby Dec 25 '15 at 12:37
  • @Justpassingby: Yes, that has just occurred to me, though, as far as I understand the documents, I have already done that (well, not exactly calibrate, but read hard-coded adjustment values from the device ROM (programmed per device upon production), and use them in order to adjust the measured data). – barak manos Dec 25 '15 at 12:49
  • @Justpassingby: Can you please take a look at the updated measurement values, perhaps it would give you a hint on how I should perform the conversion from uT into degrees? (assuming that everything else is correct of course). Thanks. – barak manos Dec 25 '15 at 12:51
  • The problem is not in the formulas. It is plainly impossible that the north and south orientations give identical y fluxes, so you need to concentrate on the measurements first. Try varying the physical setup, like the orientation of cables etc – Justpassingby Dec 25 '15 at 13:30

1 Answers1

1

Your magnetometer is giving three cartesian components of the magnetic flux density $\vec{B}$. If you are interested only in the 'degrees with respect to the north', then assuming that your $z$ axis points to the north, you can get it as, \begin{equation} \theta = \cos^{-1}\left(\frac{B_z}{\sqrt{B_x^2 + B_y^2 + B_z^2}}\right) \end{equation} In three dimensions, you may be interested not only in the polar angle (latitude) but also the azimuthal angle (longitude). You can get it as, \begin{equation} \theta = \tan^{-1}\left(\frac{B_y}{B_x}\right) \end{equation}

Amey Joshi
  • 1,084
  • The second formula is the one that I've mentioned in my question (which, as I've mentioned, gives me only values in the range $10-60$). The first formula gives me only values in the range $10-30$. I'd expect to get values in the range $\pm180$ (or in the range $0-360$). Are you sure about this formula? Does it work with respect to the measurement values that I have provided? In any case, I'm beginning to think that I am not using the device properly (i.e., it is more likely than your formulas being wrong, but I just want to make sure that they're not). Thanks. – barak manos Dec 25 '15 at 13:02
  • Your formula is correct in two dimensions. It follows from conversion of 2d Cartesian to plane polar coordinates. In three dimensions, you will need one more angle. I gave you the conversion of 3d Cartesian to spherical polar coordinated. Let me add another comment offering an explanation for the values you are getting. – Amey Joshi Dec 25 '15 at 13:12
  • Please note that your XY plane is not the same as the XY plane I am using in my formulas. The latter has origin at earth's center and XY plane containing the equator. That is probably the reason why you are getting a limited range of values. – Amey Joshi Dec 25 '15 at 13:22
  • So my values depend on the latitude (or longitude) that I'm at? How do I work around it then (without relocating)? – barak manos Dec 25 '15 at 13:37
  • I guess the only way to realize full range of values is to use the device in presence of an artificially generated magnetic field. (I am assuming that you are checking if the device works for all possible values.) – Amey Joshi Dec 25 '15 at 14:10
  • Thanks. Your answer and formulas look pretty "convincing" and well explained, as well as coinciding with my preliminary investigation of this issue. So I've up-voted it, but I cannot accept it until I make sure that I am using the device correctly, and then verify the correctness of these formulas. Thanks again for the effort and high quality of your answer :) – barak manos Dec 25 '15 at 14:31