Detect programmatically if iPhone is dropped using CoreMotion/Accelerometer

不想你离开。 提交于 2020-08-01 08:58:06

问题


So I am writing a piece of code where I have to detect different movement gestures using Accelerometer and gyroscope in iOS 4.3 above.

Q1: Is there any existing opensource code which has achieved any movement/gesture detection?

If not

Q2: For now I want to detect if the iPhone is dropped.

What I have achieved so far: CoreMotion API gives userAcceleration, which (afaik) is the acceleration that the user is giving to the device or the acceleration of device in some direction (x, y or z) with out considering the gravity so what I can do is: store, let's say, previous 5-6 values of acceleration parameters and can check where any of them hits large negative value, which basically represents the sudden deceleration.

But this solution is not very optimal, I think I need to somehow detect the freefall/downwards motion of the device too first. Any idea how to approach this problem?

UPDATE: Thanks Misch for sharing your approach. I was not at all thinking about total acceleration. I did exactly what you said:

"You would however have to test yourself, what means "total acceleration corresponds approximately to earth acceleration" and "for some time" in your case."

The acceleration value is actually in G's so I tested the "total acceleration" values with in range of 0.9 - 1.1. And I checked them over some time, initially I checked four consecutive values when updateInterval is set to 1/20.0. For now I have relaxed the condition of consecutiveness a little.

Here's a sample output:

Acceleration = 0.090868
Acceleration = 0.074473
Acceleration = 0.159797
Acceleration = 1.157513
Acceleration = 1.224588
Acceleration = 1.036272
Acceleration = 0.914698
Acceleration = 0.904093
Acceleration = 0.941516
Acceleration = 0.046362
Acceleration = 0.045109
Acceleration = 0.060045

I think, I still have to keep on testing and adjusting values. If you have any optimization in mind kindly do share, I know in order to help you'd need to see the many samples of freefall acceleration values. For now I am thinking to:

  1. round off the values of acceleration to 3 decimal places and play with the acceleration range I am using.
  2. May be check if, after the freefall condition is met, total acceleration value suddenly goes down.
  3. Do you think the acceleration values I have quoted are a bit noisy?

回答1:


To Q2:

Checking for large negative values does not tell you whether the phone is being dropped.

  • First, the user could just move the phone with a rapid gesture, this would also result in a large (maybe negative) value.
  • Secondly, the phone could fall in another direction than you imagine, and therefore, the acceleration could be positive, although the phone is moving towards the ground.

You could just calculate the total acceleration (a = sqrt(ax^2 + ay^2 + az^2)) and check whether this total acceleration corresponds approximately to earth acceleration (9.81). The phone is falling if the acceleration corresponds to earth acceleration for some time.

You would however have to test yourself, what means "total acceleration corresponds approximately to earth acceleration" and "for some time" in your case.


The physics behind this:

Let's assume you drop your phone in a way, that the y axis of the phone shows upwards. Then the x and z accelerations will be 0 and the y acceleration will be like this:

Acceleration in y axis

The acceleration will be 0 in the beginning, will then reach -9.81 the moment, you release your phone. Then it will hit the ground, which you see in the small acceleration peak, and then the acceleration is zero again.

However you can't use only the acceleration in y direction, because your phone may fall in a different angle.

So you have to watch the total acceleration of your phone:

Total acceleration

Here you don't see a negative acceleration anymore. However, here it doesn't matter anymore in which direction your phone is facing, as a free fall will always be characterized by an acceleration of 9.81.

To your edits:
1. Why would you want to round off the values of acceleration to 3 decimal places? If you test 0.9 < x < 1.1, it doesn't matter if x is 0.914698 or 0.915.
2. What if someone drops the phone but then catches it again, so the total acceleration does not necessarily have to go down again. Additionally, there should be a large acceleration value (a sudden deceleration) the moment the phone hits the floor. Maybe the reason one does not see this in your values is that it is so short, that it falls between two consecutive measurements. However this could be measured, so don't suppose that immediately after the free fall, the acceleration should decrease again.



来源:https://stackoverflow.com/questions/14445914/detect-programmatically-if-iphone-is-dropped-using-coremotion-accelerometer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!