简体   繁体   English

计算 iPhone 移动的短垂直距离

[英]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.目前我正在开发一个应用程序,它需要检测 iPhone 是否开始和停止垂直移动。 I need to be able to detect a pretty short (50-100 cm) vertical distance traveled, ie if a person performs a squat.我需要能够检测到一个非常短(50-100 厘米)的垂直移动距离,即如果一个人执行下蹲。

Is there a way to calculate that the Core Motion framework ?有没有办法计算出Core Motion 框架

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)
            }
         }
     })
}

Is there a way to calculate vertical distance traveled with the Core Motion framework?有没有办法计算使用 Core Motion 框架行进的垂直距离?

Core Motion can detect attitude (how the phone is oriented) and acceleration (how the phone starts or stops moving, speeds up or slows down). Core Motion 可以检测姿态(手机的方向)和加速度(手机如何开始或停止移动、加速或减速)。 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.但这只不过是一个猜测。

Well had to do a bit of similar work for one of the apps I worked on earlier. Well 不得不为我之前开发的其中一个应用程序做一些类似的工作。 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).加速度计、陀螺仪、GPS 和磁力计(可能不是您的情况下的 GPS 和指南针)。 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.好吧,如果你真的想厚颜无耻,你可以做我们所做的,我们将这些传感器数据发送到 ML API/模型。 Over time it became really accurate.随着时间的推移,它变得非常准确。 Now we are more than 90% accurate.现在我们的准确率超过 90%。 However, this might be overkill in your case.但是,这在您的情况下可能有点矫枉过正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM