Looks like Reto forgot a 0 in his nanosecondsPerSecond.
Should be:
final float nanosecondsPerSecond = 1.0f / 1000000000.0f;
On Wednesday, September 26, 2012 1:17:51 PM UTC-5, bob wrote:
>
> I'm trying to learn gyroscopes, so I have this code (partly from a book
>
>
> Meier, Reto (2012-04-05). Professional Android 4 Application Development
> (Wrox Professional Guides) (Kindle Locations 13327-13331). John Wiley and
> Sons. Kindle Edition.
>
>
> , partly from my head)
>
>
>
> 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]);
>
>
> }
>
> }
>
>
>
>
> Anyhow, the issue is that when I rotate the tablet by 90 degrees on the
> table, angle2 increases by about 15.4. I would expect it to increase by
> pi/2.
>
>
> Anyone know why this is?
>
>
>
--
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