Detect programmatically if iPhone is dropped using CoreMotion / Accelerometer

So I am writing a piece of code where I have to detect different movements using the accelerometer and gyroscope in iOS 4.3 above.

Q1: Is there any existing open source code that has achieved any motion / gesture detection?

If not

Q2: For now, I want to determine if the iPhone is being discarded.

What I have achieved so far: The CoreMotion API provides userAcceleration , which (afaik) is the acceleration that the user gives to the device, or the acceleration of the device in some direction (x, y, or z) disregarding gravity, so I can: store, let's say the previous 5-6 acceleration parameter values ​​and check where any of them fall into a large negative value, which is basically a sudden deceleration.

But this solution is not very optimal, I think that I need to somehow first detect the movement of the device down or down. Any idea how to approach this issue?

UPDATE: Thanks to Misch for sharing your approach. I didn't think about full acceleration at all. I did exactly what you said:

"You will, however, have to test yourself, which means" full acceleration "to roughly Earth acceleration" and "for some time" in your case.

The acceleration value is actually in G, so I checked the "full acceleration" values ​​between 0.9 and 1.1. And I checked them for some time, I checked four consecutive values ​​first when updateInterval is set to 1 / 20.0. I have softened the sequence state a bit for now.

Here's an example of the 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.045600

I think I still need to keep testing and adjusting the values. If you have any optimization, kindly share, I know to help you see many samples of gravity acceleration values. While I think:

  • round up the acceleration values ​​to three decimal places and play with the acceleration range I'm using.
  • It can be checked if, after reaching the free fall condition, the overall acceleration value suddenly drops.
  • Do you think the acceleration values ​​I quoted are a little noisy?
+3


source to share


1 answer


To Q2 :

Checking for large negative values ​​does not tell if the phone is being deleted.

  • First, the user can simply move the phone with a quick gesture, this will also result in a large (possibly negative) value.
  • Secondly, the phone may fall in a different direction than you imagine, and therefore the acceleration can be positive, although the phone is moving towards the ground.

You can simply calculate the total acceleration ( a = sqrt(ax^2 + ay^2 + az^2)

) and check if this total acceleration corresponds roughly to the ground acceleration ( 9.81

). The phone crashes if the acceleration matches the acceleration of the earth for some time.

You will, however, have to test yourself, which means that in your case, "full acceleration corresponds approximately to the acceleration of the earth" and " for some time ."


The physics behind this:

Suppose you have lowered your phone so that the y-axis of the phone is displayed upward. Then the accelerations x and z will be 0, and the acceleration y will look like this:



Acceleration in y axis

The acceleration will be 0 at the beginning, then it will reach -9.81 the moment you release your phone. It will then hit the ground, which you will see in a small peak of acceleration, and then the acceleration will return to zero.

However, you cannot only use acceleration in the y direction because your phone may fall at a different angle.

So, you need to see the full acceleration of your phone:

Total acceleration

Here you no longer see negative acceleration. However, it doesn't matter which direction your phone is in, as a free fall will always have an acceleration of 9.81.

For your changes:
 1. Why do you want to round the acceleration values ​​to 3 decimal places? If you check 0.9 < x < 1.1

, it doesn't matter if x

- 0.914698

or 0.915

.
 2. What to do if someone drops the phone and then catches it again, so full acceleration doesn't have to go down again. Also, the moment the phone hits the floor, there must be a large acceleration value (sudden deceleration). Perhaps the reason you don't see this in your values ​​is because it is so short that it falls between two successive dimensions. However, it is measurable, so do not allow acceleration to decrease again immediately after free fall.

+19


source







All Articles