How to use an accelerometer to detect vibrators above 1Gs?

I am making an Android application, which is something like a black box for cars, which records the process of moving a car.

But now I am faced with the problem of how I am going to integrate an accelerometer capable of detecting slight movement (possibly> 1Gs) when an accident occurs, this can stop the video recording and save it until the archive file, thus without losing the file as a result accident. Does anyone know how to accomplish the above task to track any form of vibration?

I'm new to android / java, can anyone help me out? Thanks in advance...

This is part of the video section, but now, how am I going to turn on the accelerometer for Auto Archive purposes?

+3
source share
1 answer

You need to use onSensorChanged(SensorEvent event)interface callbackSensorEventListener

Get class information SensorEventhere: http://developer.android.com/reference/android/hardware/SensorEvent.html

Here's an example on the IBM developerWorks page: http://www.ibm.com/developerworks/opensource/library/os-android-sensor/index.html


Android Help Pages:

public final float []

Values: API: Level 3

The length and content of the array values ​​depends on the type of sensor (see also SensorEvent to determine the coordinate of the system used). Sensor.TYPE_ACCELEROMETER: all values ​​are in SI units (m / s ^ 2)

values[0]: Acceleration minus Gx on the x axis

values[1]: Acceleration minus Gy along the y axis

values[2]: Acceleration minus Gz on the z axis

, (). , (Fs), : Ad = - ΣFs/mass

, : Ad = -g - ΣF/mass

, (, , ), g = 9,81 / ^ 2

, 9,81 m/s ^ 2, 0 / ^ 2.

, , , . . , .

 public void onSensorChanged(SensorEvent event)
 {
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter time-constant
      // and dT, the event delivery rate

      final float alpha = 0.8;

      gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      linear_acceleration[0] = event.values[0] - gravity[0];
      linear_acceleration[1] = event.values[1] - gravity[1];
      linear_acceleration[2] = event.values[2] - gravity[2];
 }
+1

All Articles