简体   繁体   English

以编程方式检测iPhone是否掉在地上

[英]programmatically detect if the iPhone fell on the ground

How to detect the iPhone fell on the ground using the UIAccelerometer ? 如何使用UIAccelerometer检测iPhone掉在地上? I am using the following delegate to calculate the falling detection but it's not working correctly. 我正在使用以下委托来计算跌倒检测,但无法正常工作。

Is this calculation correct or not? 这个计算正确与否吗?
Please suggest any other type of detection. 请建议其他任何类型的检测。

Calculation : currentDeviceAcceleration = sqrt(9.81*x*x + 9.81*y*y + 9.81*z*z) 计算方法 :currentDeviceAcceleration = sqrt(9.81 * x * x + 9.81 * y * y + 9.81 * z * z)

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{

    float x = acceleration.x;
    float y = acceleration.y;
    float z = acceleration.z;

    float currentDeviceAcceleration = sqrt(9.81*x*x + 9.81*y*y + 9.81*z*z);
        if (currentDeviceAcceleration > 8.5) {
             //Device felt on ground
        }

}

I suppose, the variables x to z store the acceleration in m/s². 我想,变量x到z将加速度存储为m /s²。

So, the total acceleration in m/s² of the device is sqrt (x*x + y*y + z*z) . 因此,设备的总加速度(m /s²)为sqrt(x * x + y * y + z * z)

The conclusion however, that the device fell to the ground is false. 但是,该设备跌落到地面的结论是错误的。 any acceleration can reach that value. 任何加速度都可以达到该值。

I have 2 ideas how to solve this particular Problem 我有两个想法如何解决这个特定的问题

1) acceleration has to be constant (within a range) for a given time (eg the time of the fall from a hand to the ground which would be about 0.35 seconds.) 1)在给定的时间内(例如,从手到地面跌落的时间大约为0.35秒),加速度必须保持恒定(在一定范围内)。

2) after the free fall, the acceleration goes insanely up, depending on the surface the device is landing on. 2)自由落体后,加速度会急剧上升,具体取决于设备降落的表面。 Maybe you could catch that. 也许你可以抓住。 :) :)

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

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