Hi Mark,

Well.. no... I'm not thinking the phone is constantly accelerating... That's the point of looking for a fairly high acceleration, and then a low acceleration to count as one shake, but I have played with many different values.. and still don't seem to get absolutely consistent results... and the big problem.. I have no way to know how well it will work on other phones, even if I get it working on my phone (it's a G1).

BUT... you did make me rethink about what constitutes a shake.. and I think I have come up with a better definition than what I had. Let me know if this makes sense to you..

A half shake is the act of moving your phone from one position to another (and probably more or less about 4 inches or more). A full shake would be the act of moving the phone to another position and back again.

Now... in a half shake the following would happen.. A high acceleration when you start moving the phone.. followed by a low acceleration when you reach full speed.. then a high negative acceleration when you begin stopping and a low acceleration when you are close to stopping, and from the first high acceleration to the last low acceleration the phone should have moved at least a couple of inches. A full shake would just be two half shakes in a row in less than a second or at most two.

Does that make sense?

Looking at your code, it's pretty similar to mine (organized much better .. but functionally about the same).. except that you are using the GRAVITY_EARTH constant, and I've hard coded most of my variables in my declaration. I hadn't thought of using the GRAVITY_EARTH constant.. but it makes a lot of sense. .because it should help adjust for the difference between different acceleromators.. I'll try adding that to my code and see if my results improve..

Oh.. and you are using SENSOR_DELAY_UI and I was using SENSOR_DELAY_GAME when I registered the Listener. Any idea of what the real difference is between the two? I've googled it a few times, and haven't come up with any really useful comparisons, except that DELAY_UI is the slowest rate :). "rate suitable for the user interface" just doesn't mean much to me :).

One question though... What is the rationale for squaring the GRAVITY_EARTH constant to calculate your threshold? Is that just your interpretation of what force a Shake would be, and then adjust from there, or is there something more scientific behind it?



On 11/07/2010 6:49 PM, Mark Murphy wrote:
On Sun, Jul 11, 2010 at 9:43 PM, Brad Gies<[email protected]>  wrote:
Has anyone implemented an Android Shake Detector that works well on most
phones?
http://github.com/commonsguy/cw-advandroid/tree/master/Sensor/Shaker/

I thought it would be fairly simple to implement but I keep getting false
results. Basically, what I'm doing is setting up a sensor Listener, checking
to make sure it is a SensorManager.SENSOR_ACCELEROMETER event, then only
checking the event if the last event I received was more than 50
milliseconds ago (to try to reduce the amount of checking I do)... Then I
look for 3 "Shakes" within 4 seconds... A "Shake" to me being a speed
reading of over 1000 followed by a speed reading of less than 400 within 1
second.
If you are holding the phone in your hand, and are shaking it, you
might think that the phone is constantly accelerating. It's not. As
you swing your hand back and forth, the phone accelerates,
decelerates, stops, accelerates in the opposite direction,
decelerates, stops, etc. Hence, any single reading of the
accelerometer may be low, even if you think you are actually shaking
the phone.

The algorithm I use allows you to define a ratio over gravity (e.g.,
1.25f means 25% more than the force of Earth's gravity
[implementations for non-Earth locations, such as the surface of the
original Death Star, are left as an exercise for the reader]). It also
allows you to define the "quiet time" (sub-threshold acceleration)
necessary to consider a shake to have stopped (e.g., 500ms).


--
Sincerely,

Brad Gies
-----------------------------------------------------------------------
Bistro Bot - Bistro Blurb
http://www.bgies.com
http://www.bistroblurb.com
http://www.ihottonight.com
-----------------------------------------------------------------------

Never doubt that a small group of thoughtful, committed people can
change the world. Indeed. It is the only thing that ever has - Margaret Mead

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to