[android-developers] Re: gyro trouble
package com.gyro_test;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.
SensorEventListener; public class Gyro_Listener implements SensorEventListener {
final float nanosecondsPerSecond = 1.0f / 100000000.0f;
private long lastTime = 0;
final float[] angle = new float[3];
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (lastTime != 0) {
final float dT = (sensorEvent.timestamp - lastTime)
* nanosecondsPerSecond;
angle[0] += sensorEvent.values[0] * dT;
angle[1] += sensorEvent.values[1] * dT;
angle[2] += sensorEvent.values[2] * dT;
}
lastTime = sensorEvent.timestamp;
System.out.println("angle0 = " + angle[0] + ", angle1 = " + angle[1] + ", angle2 = " + angle[2]);
}
}
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home