Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate a short vertical distance traveled by iPhone

Currently I'm working on an app which needs to detect if the iPhone starts and stops moving vertically. I need to be able to detect a pretty short (50-100 cm) vertical distance traveled, i.e. if a person performs a squat.

Is there a way to calculate that the Core Motion framework?

let motion = CMMotionManager()

if motion.isDeviceMotionAvailable {
    self.motion.deviceMotionUpdateInterval = 1.0 / 60.0
    self.motion.showsDeviceMovementDisplay = true

    self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: .main, withHandler: { (data, error) in
        if let validData = data {
            // Just a random minimum acceleration threshold                    
            if validData.userAcceleration.y > 3 {
               print(validData.userAcceleration.y)
            }
         }
     })
}
like image 613
Michael Samoylov Avatar asked Oct 15 '22 07:10

Michael Samoylov


2 Answers

Is there a way to calculate vertical distance traveled with the Core Motion framework?

Core Motion can detect attitude (how the phone is oriented) and acceleration (how the phone starts or stops moving, speeds up or slows down). A smooth vertical movement would not register at all. You might know that the movement started and ended, but not how far apart those events occurred. You might guess something about that based on the initial acceleration (which could let you calculate how fast we got going) and the time before deceleration. But it wouldn’t be very much more than a guess.

like image 86
matt Avatar answered Oct 18 '22 14:10

matt


Well had to do a bit of similar work for one of the apps I worked on earlier. So the key is to use all the sensors you can access. Accelerometer, gyroscope, GPS, and magnetometer (Probably not the GPS and compass in your case). Then the next step is to perform a few full squats(Hopefully Your office is ok with this :-) as you expect your user to while getting a baseline on the data. Then you can build up a model on this.

Well if you want to be really cheeky, You can do what we did, we sent these sensor data to a ML API/Model. Over time it became really accurate. Now we are more than 90% accurate. However, this might be overkill in your case.

like image 21
rMili Avatar answered Oct 18 '22 14:10

rMili