microsoft / HoloLens2ForCV

Sample code and documentation for using the Microsoft HoloLens 2 for Computer Vision research.
MIT License
480 stars 145 forks source link

Interpreting magnetometer data #30

Open max-krichenbauer opened 3 years ago

max-krichenbauer commented 3 years ago

Hello!

I'm reading the magnetometer values from the Hololens 2, but I can't figure out what they are supposed to mean or if my readings are erroneous. The documentation doesn't state any unit of measurement or meaning for these values.

When I tested it, the values where [464, -198, 483] and after turning 180 degrees they were [456, -223, 463]. What do these values mean an how are they to be processed.

Thank you!

Best regards, Max

ozgunkaratas commented 3 years ago

Hey Max, have you had any update regarding data extraction from the IMU sensor?

max-krichenbauer commented 3 years ago

Hi @ozgunkaratas Through other channels, I received the following explanation:

They *think* the units for the returned values are micro-teslas.
[...]
I'm guessing that the HL2 only uses the magnetometer to sense relative heading.
So it's probably not calibrated to do more than that. 
For example, the research API does not give any extrinsic calibration data on how the magnetometer is precisely oriented to the coordinate frames of the other sensors or cameras. 
This would also explain why they aren't 100% sure of the units – because they might only be looking at how the direction of the magnetic field changes with HL2 orientation (and not using the absolute field strength).
ozgunkaratas commented 3 years ago

Hi @max-krichenbauer thank you for your update, i was able to compare HL magnetometer data with my external IMU sensor which outputs field strength information in 3 axes in units of Tesla and the HL and the IMU do not match with each other whatsoever. I think you are right in the sense that this is used for sensing relative heading.

made3 commented 3 years ago

Hey @max-krichenbauer Did you find a way to get a degree value or something like that from the magnetometer outputs? It is hard to find anything on the internet about using the magnetometer values of the HoloLens...

Edit: So, I received values like x: 400 y: 400 z: -200 +/- around 40 depending on what direction I looked at. I had to remove the hard iron distortion by getting the max and min value of each axis and removing the mean value of those from the incoming values. Example: When rotating the headset I gathered a max-X value of 420 and a min-X value of 380. So now I remove the mean value (400) from all incoming x-values. That way the values I get are centered around 0 and not around 400 anymore. Same goes for the y and z axis.

Then I used the atan to get degree values from my Y and Z:

if (magValueZ > 0) magDegrees = 90. - ((double)atan(magValueY / magValueZ) * 180. / (atan(1) * 4));
if (magValueZ < 0) magDegrees = 270. - ((double)atan(magValueY / magValueZ) * 180. / (atan(1) * 4));
if (magValueZ == 0 && magValueY < 0) magDegrees = 180;
if (magValueZ == 0 && magValueY > 0) magDegrees = 0;

X is not needed. Might be different in your case because @max-krichenbauer apparently received my z values on his y. No idea how that works though. (atan(1) * 4) is just Pi.

So in the end I received the clockwise degrees starting at north. 0 is north, 90 is east, 180 sout and 270 west.

ilyassebel commented 2 years ago

Hi

Hello!

I'm reading the magnetometer values from the Hololens 2, but I can't figure out what they are supposed to mean or if my readings are erroneous. The documentation doesn't state any unit of measurement or meaning for these values.

When I tested it, the values where [464, -198, 483] and after turning 180 degrees they were [456, -223, 463]. What do these values mean an how are they to be processed.

Thank you!

Best regards, Max

Hi Max,

Please how did you get the magnetometer values ?

Best regards