I gather from your followup that you found your answer, so I will indulge
in a mini-code review for you.
bob wrote:
>
> package com.gyro_test;
>
> By long-standing and official convention, don't use underscores in Java
package names or other identifiers,
except for constant variable names.
> import android.hardware.Sensor;
>
import android.hardware.SensorEvent;
>
> import android.hardware.SensorEventListener;
>
> public class Gyro_Listener implements SensorEventListener {
>
> No underscore.
> 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)
>
You need indentation. Your lack of indentation is very disturbing.
Why 'float' and not 'double'? Ordinarily you'd want 'double'. You'll lose
precision in this calculation.
Well, you might lose precision with 'double', too, but not as much.
* 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]);
>
> }
>
> }
>
--
Lew
--
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