I looked at this post but it seems to be outdated: Swift gyroscope yaw, pitch, roll
I am trying to use CoreMotion to calculate the rotation around the Y axis and return it as a double in a Swift Playground on iOS. I am currently trying to work out how to get the yaw because from the Apple documentation for Swift it seems to be returned as a double, and save the value as a variable. This is what OI have done so far:
let yaw = 0.0
if motionManager.isGyroAvailable {
motionManager.deviceMotionUpdateInterval = 0.2;
motionManager.startDeviceMotionUpdates()
motionManager.gyroUpdateInterval = 0.2
motionManager.startGyroUpdatesToQueue(OperationQueue.currentQueue ?? ) {
[weak self] (gyroData: CMGyroData!, error: NSError!) in
self?.outputRotationData(gyroData.rotationRate)
if error != nil {
println("\(error)")
}
}
} else {
print("gyroscope not working")
}
I am trying to use this on Swift Playgrounds on iOS 12 for the iPad with the most up to date versions of swift and XCode.