Here is my CM code:
func checkMotion(_ myMotionManager:CMMotionManager) -> Bool {
//check to see if core motion is available
var isCoreMotionAvailable = myMotionManager.isAccelerometerAvailable
isCoreMotionAvailable = myMotionManager.isGyroAvailable
isCoreMotionAvailable = myMotionManager.isMagnetometerAvailable
isCoreMotionAvailable = myMotionManager.isDeviceMotionAvailable
if isCoreMotionAvailable {
myMotionManager.deviceMotionUpdateInterval = 0.25
myMotionManager.startDeviceMotionUpdates(to: OperationQueue.current!, withHandler: checkMotionUpdate)
}
return false
}
and to check the data:
func checkMotionUpdate(data: CMDeviceMotion?, error:Error?) {
if error != nil {
print(error!.localizedDescription)
} else {
if let motionData = data {
//check to see if we have a base point and if not store one
if !bHasBasePoint {
basePoint = motionData
bHasBasePoint = true
print("Basepoint:\(basePoint!)")
}
print("Acceleration X: \(motionData.userAcceleration.x)")
print("Acceleration Y: \(motionData.userAcceleration.y)")
print("Acceleration Z: \(motionData.userAcceleration.z)")
print()
}
}
}
and some results:
Basepoint:
Basepoint:QuaternionX 0.011783 QuaternionY -0.461725 QuaternionZ 0.000044 QuaternionW 0.886945 UserAccelX 0.006458 UserAccelY 0.000324 UserAccelZ 0.002740 RotationRateX 0.000997 RotationRateY -0.001316 RotationRateZ -0.001370 MagneticFieldX 0.000000 MagneticFieldY 0.000000 MagneticFieldZ 0.000000 MagneticFieldAccuracy -1 Heading -1.000000 @ 73807.821537
Some acceleration checks:
Acceleration X: 0.00645828247070312
Acceleration Y: 0.0003238245844841
Acceleration Z: 0.00274038314819336
Acceleration X: 0.00522691011428833
Acceleration Y: 0.000595645979046822
Acceleration Z: 0.00370562076568604
Acceleration X: 0.00506830215454102
Acceleration Y: 0.000180358067154884
Acceleration Z: 0.0017169713973999
Acceleration X: 0.00555837154388428
Acceleration Y: -0.00128581002354622
Acceleration Z: 0.00320953130722046
Acceleration X: 0.00509798526763916
Acceleration Y: -4.2034313082695e-05
Acceleration Z: 0.00197714567184448
So I am very new at CM coding (day 2) and am a bit confused on why I am seeing acceleration changes for x, y and z when the iPhone is sitting landscape in a cradle right now? Is this expected behavior and is there a range of acceleration that I should ignore as kind of a false positive?
So, maybe you found other infos about it right now. But since it is not answered yet:
Generally it is normal to have some motion recordings as the device is still. There are two reasons for that: One is, that the sensor itself is producing some error noise, the other is, that the sensor really would always have a value of 1 in one axes (or more realistically split between axes) towards the gravitation of the planet we live. Now this gravitational part get's split off with a filter, but that also introduces some errors.
Errors from the sensor itself should produce negative and positive errors randomly and a moving average should remove the impact of those therefor (f.e. your Y axis seems to not be infected by the splitting of the gravitational force and linear acceleration, and I guess it would almost completely cancel out over some values). So you should already getting better values by averaging over some past values.
From the readings you get there were usually 2 axes with a bit higher values. I would guess they appear from the gravitation splitting, and your phone was still, but maybe a bit tilted because in the gradle.
Now while 0.00something is not low, it is also not the highest error. You can get some feeling of what the values mean by looking up some references like Wikipedia Magnitude or maybe this side for earthquakes where they show what acceleration is needed to have it felt by a human ;) Wikipedia Ground Acceleration.
I do not know what apple uses for the splitting of gravitational force, but I remember that it at least a while ago was not the best filter, but fast and useful enough for UI stuff. But that could have changed with ARKit. So if you need more accurate splitting maybe implementing another filter based on the raw gravitation could make sense.
I hope that helped a bit.