V
V
Vlad Antonov2020-05-19 14:52:18
iOS
Vlad Antonov, 2020-05-19 14:52:18

How to detect jump with Core Motion?

I'm trying to make an application for counting jump rope, I just can't figure out how to implement the definition of a jump. Couldn't find any tutorials or any hint how to do it.
Please help!

final class WorkoutViewController: UIViewController {
    private var motionManager = CMMotionManager()
    private var jumpCounter = 0

    func jump() {
        let xAxis = motionManager.deviceMotion!.userAcceleration.x
        let yAxis = motionManager.deviceMotion!.userAcceleration.y
        let zAxis = motionManager.deviceMotion!.userAcceleration.z
        let xGravity = motionManager.deviceMotion!.gravity.x
        let yGravity = motionManager.deviceMotion!.gravity.y
        let zGravity = motionManager.deviceMotion!.gravity.z
        // I don't know how to detect a jump here
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        motionManager.deviceMotionUpdateInterval = self.updateDataInterval
        motionManager.startDeviceMotionUpdates(to: .main) { (_, _) in
            self.jump()
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question