CoreMotion Official Document(번역) - juniverse1103/ARKitStudy GitHub Wiki
Core Motion
Overview
Core Motion은 motion-과 environment- related 한 데이터를 가속도 센서(accelerometer)와 자이로스코프(gyroscope), 만보계(pedometer), 자기계(magnetometer), 기압계(barometer)와 같은 iOS 장비에 내장된 하드웨어로부터 가져옵니다. 이 프레임워크를 사용해서 앱 내에서 사용가능한 hardware-generated data 에 접근할 수 있습니다.
이 프레임워크의 많은 기능들은 하드웨어에 기록된 raw value와 처리된 버전의 값들에 접근할 수 있도록 해 줍니다. 처리된 값들은 그 데이터를 사용하는데 있어 불리하게 작용할 수 있는 편향된 정보들을 포함하지 않습니다. 예를 들어 처리된 가속도계 값은 유저로부터의 가속도만 반영하고, 중력가속도는 반영하지 않습니다.
CMMotionManager
모션 서비스를 시작하고 관리하는 객체입니다.
Overview
CMMotionManager 객체를 사용해서 다음과 같은 네가지 종류의 모션 데이터를 받아올 수 있습니다.
- Accelerometer data, 3차원 공간 상에서 디바이스의 즉각적인 가속을 판별합니다.
- Gyroscope data, 장비의 3개의 축에 대해서 즉각적인 회전을 판별합니다.
- Magnetometer data, 지구의 자기장에 상대적인 장비의 방향을 판별합니다.
- Device - motion data, 사용자로부터의 가속, 고도, 회전률, 지구 자기장에 상대적으로 정렬된 방향, 중력에 상대적인 방향 등의 모션과 관련된 요소들을 판별합니다. 이 데이터는 Core motion의 센서 융합 알고리즘으로부터 제공됩니다.
중요
앱 내에 단 하나의 CMMotionManager 객체만을 생성하십시오. 이 클래스에 대한 다수의 인스턴스는 가속도계와 자이로스코프로 부터 받아오는 데이터에 영향을 줄 수 있습니다.
Handling Motion Updates at Specified Intervals
특정 시간 간격으로 모션 데이터를 받아오기 위해서, 앱은 operation queue(OperationQueue 인스턴스)와 처리되는 업데이트들에 대한 특정 타입의 블록 핸들러를 받는 "start" 메서드를 호출합니다. 모션 데이터는 블록 핸들러로 보내집니다. 업데이트의 빈도는 interval 프로퍼티의 값에 의해 결정됩니다.
-
Accelerometer:
- Set Update Interval: Set the
accelerometerUpdateInterval
property to specify an update interval - Call Start Update: Call the
startAccelerometerUpdates(to:withHandler:)
method, passing in a block of typeCMAccelerometerHandler
- **Pass into the block: ** Accelerometer data is passed into the block as
CMAccelerometerData
objects
- Set Update Interval: Set the
-
Gyroscope:
- Set Update Interval: Set the
gyroUpdateInterval
property to specify an update interval - Call Start Update: Call the
startGyroUpdates(to:withHandler:)
method, passing in a block of typeCMGyroHandler
- **Pass into the block: **Rotation-rate data is passed into the block as
CMGyroData
objects
- Set Update Interval: Set the
-
Magnetometer
- Set Update Interval: Set the
magnetometerUpdateInterval
property to specify an update interval - Call Start Update: Call the
startMagnetometerUpdates(to:withHandler:)
method, passing in a block of typeCMMagnetometerHandler
- **Pass into the block: ** Magnetometer data is passed into the block as
CMMagnetometerData
objects
- Set Update Interval: Set the
-
Device Motion
- Set Update Interval: Set the
deviceMotionUpdateInterval
property to specify an update interval - Call Start Update: Call the
startDeviceMotionUpdates(to:withHandler:)
method, passing in a block of typeCMDeviceMotionHandler
- **Pass into the block: ** Device motion data is passed into the block as
CMDeviceMotionData
objects
- Set Update Interval: Set the
CMDeviceMotion
디바이스의 Attitude, Rotation Rate, Acceleration 을 Encapsulate하여 측정하는 클래스 입니다.
Overview
앱이 CMMotionManager 클래스의 startDeviceMotionUpdates()
류 메서드를 호출한 후 CMDeviceMotion 오브젝트를 받아오거나 그 샘플을 만듭니다.
가속도계는 gravity와 userAcceleration 두가지 가속도 벡터의 합을 측정합니다. User Accleration은 유저가 디바이스에 가하는 가속도입니다. Core Motion이 자이로스코프와 가속도계 모두를 사용할 수 있기 때문에, 중력과 사용자 가속도를 구분할 수 있습니다. CMDeviceMotion 객체는 gravity와 userAcceleration 프로퍼티 모두를 제공합니다.
Getting Attitude and Rotation Rate
CMAttitude
CMAttitude 클래스는 세가지 다른 수학적 형태의 회전 정보를 제공합니다: Rotation Matrix, Quaternion, Euler Angles(Roll, Pitch, and Yaw values). CMAttitude 객체에는 CMDevicemotion 객체의 attitude 프로퍼티를 통해 접근합니다.
CMRotationRate
CMRotationRate 구조체는 3개의 축에 대한 디바이스의 회전 비율을 특정하는 데이터를 가지고 있습니다. 이 프로퍼티의 값은 코어 모션 알고리즘에 의해 보정된 자이로스코프 데이터를 포함합니다. CMGyroData의 프로퍼티는 자이로스코프로부터 받아온 raw data를 제공합니다.
Getting Acceleration Data
gravity
중력가속도 값을 계산합니다.
userAcceleration
사용자로부터 유도된 가속도 값을 계산합니다.