4

I am working on an application that uses the iPhone's magnetometer and accelerometer together. I problem I have noted is that when the device is tilted back, it hits a critical point at which the heading values are reversed (iOS seems to think that the device has been rotated around). At first I thought it would be simple as checking when the device's orientation changed ([UIDevice currentDevice].orientation), but *the heading values reverse significantly before (at least 15 degrees of tilt) the device orientation change notification is sent.

I apologize if this description is confusing, but you can easily see my issue with the following experiment:

Open the compass app on an iPhone and calibrate the compass. Once calibrated, hold the iPhone straight up and down, in portrait mode, with the home bottom below the screen. Now slowly tilt the phone backward (so the camera is facing more directly upward). You will hit a point where the compass suddenly reverses its direction. Unfortunately, this point is not correlated with the point where the OS recognizes a device orientation change.

My problem is that I need to continue to register the heading in the original direction, as I haven't actually turned the device around and it is clearly still pointing forwards (in the original direction). I have tested for the angle of the device at this critical point and had some success correcting for it this way, but I get very jittery results around the critical angle due to the noise from the accelerometer. I have also experimented with the location manager's headingOrientation property with no success. If anyone has found a solution to this situation, it would be much appreciated!

Cheers.

Marco
  • 6,692
  • 2
  • 27
  • 38
eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
  • 1
    Have you solved the issue? – Valentin Shamardin Mar 04 '18 at 14:53
  • 1
    I am just looking into the same issue. I am seeing the compass reverse direction when starting with a heading North or South, but when I am heading East or west there is a small jump but the compass does not reverse. – tagy22 Jun 09 '18 at 16:58

1 Answers1

0

A bit more background on why you need this would be helpful to provide better answers. When doing the move you describe, the top of the device is actually pointing into the opposite direction.
To compensate for this, you will need to add a filter and determine the new state of the device angles and heading based on the previous state of the device angles and heading. Knowing that the device angles are approaching the critical phase and knowing that the heading suddenly reversed by 180° should enable you to distinguish this case. You could add gyro information to the filter to use device rotation rates and determine that the device is being moved over the critical angle.

user3071962
  • 320
  • 3
  • 8
  • I have determined what the critical angle is and am currently filtering it based on that assumption, but unfortunately due to the inaccuracy of the accelerometer when the device is held very near the critical angle for an extended period of time, the heading oscillates back and forth. I was wondering if there is a way to receive a notification for when the location manager is doing this 180 degree correction. – eric.mitchell Feb 28 '14 at 15:24