Вопрос

I have been experimenting with CMDeviceMotion, and especially with startDeviceMotionUpdatesUsingReferenceFrame. The magneticField values in that don't seem correct to me.

For example, if I do:

CMDeviceMotion *manager = [[CMDeviceMotion alloc] init];
manager.deviceMotionUpdateInterval = 0.1;
[manager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical toQueue:queue withHandler:^(CMDeviceMotion *motion, NSError *error) {
    CMMagneticField fld = motion.magneticField.field;
    NSLog( @"%5.1f %5.1f %5.1f", fld.x, fld.y, fld.z );
    [self handleDeviceMotion:manager.deviceMotion];
}];       

it shows a magneticField vector with a size of about 50, but almost aligned with gravity. That is, when the device is lying flat on a table, x and y are close to zero, and z is close to -50, independent of how I rotate the device.

The 50 would be correct in size for the Earth's magnetic field (according to Wikipedia should be between between 25 and 65 micro Tesla), but the direction of the vector seems all wrong. I was wondering whether:

  • It is something peculiar at my location only (Stockholm, Sweden), or
  • The magneticField property shows remaining magnetic field without the earth's field, or
  • This is bug

Do you have similar experiences with the magneticField property?

Это было полезно?

Решение

OK, the mystery is solved.

I now used a reference frame CMAttitudeReferenceFrameXTrueNorthZVertical, which gives similar results to the ...XArbirtraryCorrectedZVertical that I used before. Then I calculated how the magneticField vector is positioned with respect to gravity, by rotating it back to the referenceFrame using the given attitude.

It turns out the magneticField is pretty stably pointing 5 degrees east of true north, but with an angle of about 73 degrees into the ground. And that is exactly according to expectation for my location in Sweden, according to this map.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top