Use of a magnetic field vector outside of the sensor’s own referential

Hey all,

This is our Firestone ever post on this forum. Glad to be here!
We are a team of three students from France, and as part of a project, we need to acquire a device’s position thanks to a magnetometer. The idea is to establish a map of the magnetic field in a building, with fix orientation (« base » referential, or B).
To do that, we are reading from the HMC 5883L magnetometer the X, Y and Z components of the field vector. The obvious problem is that the HMC has its own (x,y,z) coordinate system (which we will later call « navigation » referential, or N), which is variable depending on the sensor’s own orientation.

Attached to this post is a graphic representation of the problem.

For now, we are only treating the problem as plane (parallel to the ground, if considered level).

This is the data we think we need:
-The angular difference between the navigation referential and the base referential
-The x and y components of the magnetic field vector.

This is what we do:

  1. We read the x and y components from the HMC
  2. We compute the angular difference between the 2 referentials (no problem there..)
  3. The x and y components originating from the coordinate systems’ origins, we materialize them as 2 points: A for x, which has type coordinates A(x;0); and B (for y); which has type coordinates B(0;y).
  4. We use the attached rotation matrix to calculate the new coordinates in the base referential.
  5. We calculate the new coordinates of the vector, which has type coordinates
    m( x(A)+x(B); y(A)+y(B) )
    And we project these new coordinates on our base (x;y) plane.

Theoretically, at a given point in space, considering that we are level, we should get at the end of this algorithm the same vector no matter the orientation of the sensor, right?
The problem is that it doesn’t work.. programming aside, do you see any issues with the algorithm?

You need to know the orientation of the magnetometer, with respect to the fixed coordinate system.

I see nothing in your post that suggests how you can obtain that information.

We maybe weren’t clear enough. The fixed coordinate system has a known orientation (for now, heading north) . The information you’re talking about is calculated at what I called step 2.
Thanks for your help!

Sorry, you are making no sense at all.

Please explain clearly how you know or calculate the orientation of the magnetometer with respect to the fixed coordinate system.

It is required to know that transformation, in order to use the magnetometer to map the local magnetic field, in terms of the fixed reference system. In general, that transformation will be a 3x3 matrix, requiring at least 3 independent parameters (for example, Euler angles) to specify.

@jremington, sorry for this -very- late reply. We’ve had lots of other stuff to do regarding school that didn’t leave us with any time for the project.

We use atan2(Y;X) to retrieve the (vector x; any northbound vector) oriented angle (No idea as to how to post a vector on the boards here..)
The angular difference between the navigation referential and the base one can then be deducted from this value (that of the angle between the base referential and a northbound vector).

By simply using a serial print command, we can accurately track this angle. So we’re pretty sure the problem isn’t coming from there..

The angular difference between the navigation referential and the base one can then be deducted from this value (that of the angle between the base referential and a northbound vector).

For the third time, how do you know that angular difference?

The point is there's a circularity here if all you have is the compass - you can't use the compass to
determine local<->global transform if the compass is being used to map out an unknown varying
vector field!

So how do you determine the local<->global frame mapping? Is this just a case of a single rotation angle?
If so you just have to rotate the compass heading value by that amount to get it in the global frame.