Acelerometro

Solo disponible en BuenasTareas
  • Páginas : 13 (3232 palabras )
  • Descarga(s) : 0
  • Publicado : 21 de marzo de 2011
Leer documento completo
Vista previa del texto
This class represents a Sensor event and holds informations such as the sensor's type, the timestamp, accuracy and of course the sensor's data. Definition of the coordinate system used by the SensorEvent API. The coordinate-system is defined relative to the screen of the phone in its default orientation. The axes are not swapped when the device's screen orientation changes. The X axis ishorizontal and points to the right, the Y axis is vertical and points up and the Z axis points towards the outside of the front face of the screen. In this system, coordinates behind the screen have negative Z values.

Note: This coordinate system is different from the one used in the Android 2D APIs where the origin is in the top-left corner.
See Also

• SensorManager • SensorEvent • SensorSummary
Fields public int accuracy The accuracy of this event. public Sensor sensor The sensor that generated this event. public long timestamp The time in nanosecond at which the event happened The length and contents of the values array depends on which sensor type is being monitored (see also SensorEvent for a public final float[] values definition of the coordinate system used). [Expand] InheritedMethods

From class java.lang.Object clone() Creates and returns a copy Object of this Object. equals(Object o) Compares this instance with boolean the specified object and indicates if they are equal. finalize() Called before the object's void memory is reclaimed by the VM. getClass() Returns the unique instance final Class of Class that represents this object's class. hashCode() Returns anint integer hash code for this object. notify() Causes a thread which is waiting on this object's monitor final void (by means of calling one of the wait() methods) to be woken up. notifyAll() Causes all threads which are waiting on this object's monitor (by final void means of calling one of the wait()

Fields
public int accuracy Since: API Level 3 The accuracy of this event. See SensorManagerfor details. public Sensor sensor Since: API Level 3 The sensor that generated this event. See SensorManager for details. public long timestamp Since: API Level 3 The time in nanosecond at which the event happened public final float[] values Since: API Level 3 The length and contents of the values array depends on which sensor type is being monitored (see also SensorEvent for a definition of thecoordinate 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 on the y-axis values[2]: Acceleration minus Gz on the z-axis A sensor of this type measures the acceleration applied to the device (Ad). Conceptually, it does so by measuring forces applied to the sensor itself (Fs) using therelation: Ad = - ∑Fs / mass In particular, the force of gravity is always influencing the measured acceleration: Ad = -g - ∑F / mass For this reason, when the device is sitting on a table (and obviously not accelerating), the accelerometer reads a magnitude of g = 9.81 m/s^2 Similarly, when the device is in free-fall and therefore dangerously accelerating towards to ground at 9.81 m/s^2, itsaccelerometer reads a magnitude of 0 m/s^2. It should be apparent that in order to measure the real acceleration of the device, the contribution of the force of gravity must be eliminated. This can be achieved by applying a high-pass filter. Conversely, a low-pass filter can be used to isolate the force of gravity.
public void onSensorChanged(SensorEvent event) { // alpha is calculated as t / (t + dT) //with t, the low-pass filter's 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] -...
tracking img