This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in detecting a shake movement

 
ganesh gupthag
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi group ,
I use OpenIntents SensorSimulator to detect the shake movement
In code i wrote

public float accelerometer_shake_threshold = 1.2f; // what does this 1.2 means to this program
static final int ACCELEROMETER_FLOAT_TO_INT = 1024; // is this a conversion factor
int mACCELEROMETER_SHAKE_THRESHOLD_SQUARE;

public void onSensorChanged(int sensor, float[] values){
if( sensor == SensorManager.SENSOR_ACCELEROMETER){
int t = (int)(ACCELEROMETER_FLOAT_TO_INT * accelerometer_shake_threshold);
mACCELEROMETER_SHAKE_THRESHOLD_SQUARE = t * t;


android.util.Log.i("Answer",String.valueOf(values[0]));
android.util.Log.i("Answer",String.valueOf(values[1]));
android.util.Log.i("Answer",String.valueOf(values[2]));

int ax = (int)(ACCELEROMETER_FLOAT_TO_INT * values[0]);
int ay = (int)(ACCELEROMETER_FLOAT_TO_INT * values[1]);
int az = (int)(ACCELEROMETER_FLOAT_TO_INT * values[2]);

int len2 = ax * ax + ay * ay + az * az;
android.util.Log.i("LEN is",Integer.toString(len2));

if (len2 < mACCELEROMETER_SHAKE_THRESHOLD_SQUARE) {

Log.v(TAG,"Force Detected");
TextView tv=(TextView)findViewById(R.id.found);
tv.setText("ViolentForce Detected");

}
I could not get the desired result ,the value of len2 is seems to be constant for any movement I give through the sensor simulator (Yaw,Roll and Pitch).If the len2 is constant value then what could be the purpose of the if statement .
I just blindly followed the code snippet given under" Detecting "Shake" With The Accelerometer"(http://www.anddev.org/example_detecting_-und-quotshake-und-quot_with_the_accelerometer-t4451.html
) .I don't no where i went wrong
In other few examples which i came across has len2 value compared with cube root of gravity(being a newb its Greek to me ) Help me out to know the concept to detect a violent shake .What kind of physics is used to detect this sense .
Thanks
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Accelerometer gives acceleration(raw data) along X-Y-Z axis in SI units. To detect a shake, you need to define it first and then apply a suitable model(can require good understanding of physics).

The algorithm for detecting a shake could be as simple as:



The way you combine your accelerometer readings and the threshold value will define the "strength" and type of "shake" that your code can sense(Perhaps providing this in API would have been more convenient).

Maybe someone with a physics degree can help here.
 
ganesh gupthag
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tripathi for your post
What do you mean by applying a model ,Can't i use OpenIntents Sensor Simulator to pass a shake movement (by just sliding the Yaw or,Roll or Pitch vigorously )
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By model, I meant -

{formula(designed using accelerometer readings) or
predicates on the readings}
that will describe shake for your algorithm.

For e.g: In you code, you chose sum of squares and compared it with some large value:
[ "X^2 + Y^2+Z^2" > "threshold^2"].
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic