development

iOS에서 Core Location과 Core Motion 프레임 워크의 자기장 값의 차이점은 무엇입니까?

big-blog 2020. 11. 29. 11:58
반응형

iOS에서 Core Location과 Core Motion 프레임 워크의 자기장 값의 차이점은 무엇입니까?


iOS 기기의 자력계를 사용하여 자기장 (강도, x, y, z)을 얻는 두 가지 방법이 있습니다.

1) Core Location
CLHeading from CLLocationManagerDelegate메서드를 사용했습니다 locationManager:didUpdateHeading:. 이는 Apple의 Teslameter 샘플 앱과 유사합니다.

2) 핵심 모션
사용 CMMagneticField에서 CMMotionManager의 ' magnetometerData.magneticField.

질문 :
a) 둘의 차이점은 무엇입니까? 나는 둘 다에서 다른 가치를 얻고 있습니다. 나는 그들이 동일한 값을 반환 할 것이라고 기대했습니다.
그 차이는 내가 쉬는 자세에서 앱을 시작한 다음 (테이블에서 얼굴을 위로) 기기를 공중으로 들어 올릴 때 가장 두드러집니다.
b) 차이가있는 경우 Core Location 제목의 자기장을 언제 사용해야하며 Core Motion의 자기장을 언제 사용해야합니까?

참고 : Core Location 및 Core Motion의 "자기장"이 다른 자기장 개념을 참조하는지도 확실하지 않습니다.
참고 : 두 접근 방식에 대해 강도를 (x ^ 2 + y ^ 2 + z ^ 2)의 제곱근으로 계산했습니다.


이것을 풀기 위해 나는 애플 문서를 파헤치는 데 너무 많은 시간을 보냈다.

자력계 데이터를 얻는 세 가지 방법이 있습니다.

1 / Core Motion 프레임 워크
CMMotionManagers의 CMMagnetometer클래스

2 / Core Motion 프레임 워크
CMDeviceMotion CMCalibratedMagneticField 속성

3 / 핵심 위치 프레임 워크
CLLocationManagerCLHeading

1 / 자력계에서 '원시'데이터를 제공합니다.
2 / 및 3 / '파생'데이터를 반환합니다. 두 경우의 숫자는 비슷합니다 (정확히 같지는 않지만).

Core Motion의 CMM 자 기계와 CMCalibratedMagneticField의 차이점

1 / 및 2 /-둘 다 Core Motion 프레임 워크에서-다음과 같이 다릅니다.

CMDeviceMotion 클래스 참조

@property(readonly, nonatomic) CMCalibratedMagneticField magneticField

토론
이 속성에 의해 반환 된 CMCalibratedMagneticField는 장치 바이어스없이 장치 주변의 총 자기장을 제공합니다. CMMagnetometer 클래스의 자기장 속성과는 달리이 값은 지구 자기장과 주변 필드를 더하고 장치 바이어스를 뺀 값을 반영합니다.

CMMagnetometer는 원시 데이터를 제공하고 CMCalibratedMagneticField는 조정 된 데이터입니다.

Core Motion의 CMCalibratedMagneticField와 Core Location의 CLHeading의 차이점

문서는 2 /와 3 /의 차이점에 대해 즉시 명확하지 않지만 다른 숫자를 생성하므로 파헤쳐 보겠습니다.

핵심 위치 프레임 워크
CLHeading

에서 위치 인식 프로그래밍 안내서

제목 관련 이벤트 받기

헤딩 이벤트는 자력계가 포함 된 기기에서 실행되는 앱에서 사용할 수 있습니다. 자력계는 지구에서 나오는 근처의 자기장을 측정하고이를 사용하여 장치의 정확한 방향을 결정합니다. 자력계는 오디오 스피커, 모터 및 기타 여러 유형의 전자 장치에서 발견되는 고정 자석에서 나오는 것과 같은 로컬 자기장의 영향을받을 수 있지만 Core Location은 장치와 함께 움직이는 필드를 필터링 할 수있을만큼 똑똑합니다.

다음은 관련 CLHeading'원시'속성입니다.

@property(readonly, nonatomic) CLHeadingComponentValue x
@property(readonly, nonatomic) CLHeadingComponentValue y
@property(readonly, nonatomic) CLHeadingComponentValue z

[x | y | z] 축에 대한 지자기 데이터 (마이크로 테슬라로 측정)입니다. (읽기 전용)
이 값은 장치가 추적하는 자기장 선에서 [x | y | z] 축 편차를 나타냅니다. ( 이전 버전의 문서는 다음을 추가합니다. )이 속성이보고하는 값은 -128에서 +128 범위로 정규화됩니다.

마이크로 테슬라 측정이 +/- 128의 범위로 '정규화'(압축? 잘림?) 될 수있는 방법이 명확하지 않고 여전히 측정한다고 주장하는 단위를 나타냅니다. 아마도 그것이 문서에서 문장이 제거 된 이유 일 것입니다. iPad mini의 장치는 이러한 종류의 범위를 따르는 것처럼 보이지만 iPhone4S는 더 높은 범위 (예 : 200-500)에서 CMM 자력계 판독 값을 제공합니다 .

API는 분명히 파생 된 속성을 사용할 것으로 예상합니다.

@property(readonly, nonatomic) CLLocationDirection magneticHeading
@property(readonly, nonatomic) CLLocationDirection trueHeading

안정적인 N / SE / W 나침반 판독 값을도 단위로 제공합니다 (0 = 북쪽, 180 = 남쪽 등). 진북에서 자기 편차를 얻기 위해서는 다른 핵심 위치 서비스 (지리 위치)가 필요합니다.

다음은 CLHeading헤더 파일 의 스 니펫입니다.

/*
 *  CLHeading
 *  
 *  Discussion:
 *    Represents a vector pointing to magnetic North constructed from 
 *    axis component values x, y, and z. An accuracy of the heading 
 *    calculation is also provided along with timestamp information.
 *  
 *  x|y|z
 *  Discussion:
 *    Returns a raw value for the geomagnetism measured in the [x|y|z]-axis.

Core Motion 프레임 워크
CMDeviceMotion CMCalibratedMagneticField

/*
 *  magneticField
 *  
 *  Discussion:
 *          Returns the magnetic field vector with respect to the device for devices with a magnetometer.
 *          Note that this is the total magnetic field in the device's vicinity without device
 *          bias (Earth's magnetic field plus surrounding fields, without device bias),
 *          unlike CMMagnetometerData magneticField.
 */
@property(readonly, nonatomic) CMCalibratedMagneticField magneticField NS_AVAILABLE(NA,5_0);

CMM 자력계

 *  magneticField
 *  
 *  Discussion:
 *    Returns the magnetic field measured by the magnetometer. Note
 *        that this is the total magnetic field observed by the device which
 *        is equal to the Earth's geomagnetic field plus bias introduced
 *        from the device itself and its surroundings.
 */
@property(readonly, nonatomic) CMMagneticField magneticField;  

CMMagneticField
이것은 벡터를 보유하는 구조체입니다. 의 보정 된 자기장과 보정되지 않은 버전
의 경우 동일합니다 .CMDeviceMotionCMMagnetometer

/*  CMMagneticField - used in 
 *  CMDeviceMotion.magneticField.field
 *  CMMagnetometerData.magneticField
 *  
 *  Discussion:
 *    A structure containing 3-axis magnetometer data.
 *
 *  Fields:
 *    x:
 *      X-axis magnetic field in microteslas.
 *    y:
 *      Y-axis magnetic field in microteslas.
 *    z:
 *      Z-axis magnetic field in microteslas.

2 /와 3 /의 차이점은 다음과 같습니다.

핵심 위치 CLHeading

축 구성 요소 값 x, y 및 z로 구성된 자북을 가리키는 벡터를 나타냅니다.

Core Location은 장치와 함께 움직이는 필드필터링 할 수있을만큼 똑똑 합니다.

코어 모션 CMC 보정 자기장

[표시] 장치 바이어스없이 지구 자기장 과 주변 장

그래서-문서에 따르면-우리는 다음을 가지고 있습니다.

1 / CMM
자력계 자력계의 원시 판독 값

2 / CMDeviceMotion (CMCalibratedMagneticField *)
장치 바이어스 (온보드 자기장)에 대해 수정 된 자기장 자 기계 판독 값

3 / CLHeading [x | y | z]
자력계 판독 값은 장치 바이어스에 대해 수정되고 로컬 외부 자기장을 제거하기 위해 필터링됩니다 (장치 이동에 의해 감지 됨-필드가 장치와 함께 이동하는 경우 무시하고 그렇지 않으면 측정).

이론 테스트

enter image description here

I have put a Magnet-O-Meter demo app on gitHub which displays some of these differences. It's quite revealing to wave a magnet around your device when the app is running and watching how the various APIs react:

CMMagnetometer doesn't react much to anything unless you pull a rare earth magnet up close. The onboard magnetic fields seem far more significant than local external fields or the earth's magnetic field. On my iPhone 4S it consistently points to the bottom left of the device; on the iPad mini it points usually to the top right.

CLHeading.[x|y|z] is the most vulnerable (responsive) to local external fields, whether moving or static relative to the device.

(CMDevice)CMCalibratedMagneticField is the most steady in the face of varying external fields, but otherwise tracks it's Core Location counterpart CLHeading.[x|y|z] pretty closely.

CLHeading.magneticHeading - Apple's recommendation for magnetic compass reading - is far more stable than any of these. It is using data from the other sensors to stabilise the magnetometer data. But you don't get a raw breakdown of x,y,z

             influenced by
             onboard fields    local external fields   earth's field
yellow               X                   X                 X
green                _                   X                 X
blue                 _                   _                 X
red                  _                   _                 X           

yellow CMMagnetometer
green CLHeading.[x|y|z]
blue CMCalibratedMagneticField
red CLHeading.magneticHeading

This does seem to contradict the docs, which suggest that CLHeading.[x|y|z] should be less influenced by local external fields than CMCalibratedMagneticField.

What approach should you take? Based on my limited testing, I would suggest…
If you want a compass reading
CLHeading's magneticHeading and trueHeading will give you the most accurate and most stable compass reading.
If you need to avoid Core Location
CMDeviceMotion's CMCalibratedMagneticField seems to be the next most desirable, although considerably less stable and accurate than magneticHeading.
If you are interested in local magnetic fields
CLHeading's 'raw' x y and z properties seem to be more sensitive to local magnetic fields.
If you want all of the data including onboard magnetic fields
Raw magnetometer data from CMMagnetometer. There is really not much point using this unless you are prepared to do tons of filtering, as it is hugely influenced by magnetic fields generated on the device itself.


this answer is based on my interpretation of the documentation links below

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLHeading_Class/Reference/Reference.html#//apple_ref/doc/c_ref/CLHeading

http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMMagnetometerData_Class/Reference/Reference.html#//apple_ref/doc/c_ref/CMMagnetometerData

a) CLHeading is "deviation from the magnetic field lines being tracked by the device" while magnetometerData.magneticField "is the total magnetic field observed by the device which is equal to the Earth’s geomagnetic field plus bias introduced from the device itself and its surroundings".

So CLHeading gives you filtered values with the Frame of Reference being the existing magnetic field of the earth. While magnetometerData gives you unfiltered values with the Frame of reference being the device.

b) if you were doing anything with location where you wanted to know where is magnetic or true north I'd recommend using CLHeading. If you wanted to create an app that responds to magnetic fields in the devices immediate vicinity or you had some specific sensor fusion you wanted to perform maybe try create an AHRS for instance then go with CMMagneticField.


An important thing to remember when using the CLHeading.[x|y|z] values to calculate the local magnetic field strength is that the CLLocationManagerDelegate method

  • (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager

should be set to return YES. I have found that the magnetometer readings are never calibrated if this calibration warning is turned off, and that as a result the calculated field strength is very unstable when the orientation of the device is changed.


I think the magnetometerData.magneticField it telling you the acceleration, not the position (hence why you get large values moving from still to moving) whereas the location manager provides data on the direction the device is pointing in.

참고URL : https://stackoverflow.com/questions/15380632/in-ios-what-is-the-difference-between-the-magnetic-field-values-from-the-core-l

반응형