I'm really sorry to hijack your thread but I'm having problems with this new
method of getting orientation.
Here's my relevant code:
    // Sensor stuff
    private SensorManager mSensorManager;
    private Sensor mGravitySensor;
    private Sensor mAccelerometer;
    private Sensor mOrientationSensor;
    private Object mSensorsSync;
    private float mGravity[];
    private float mGeomagneticField[];
    private float mOrientation[];

   @Override
    public void onSensorChanged(SensorEvent event) {
        synchronized (mSensorsSync) {
            // If the sensor data is unreliable return
            if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE)
                return;

            switch (event.sensor.getType()) {
                case Sensor.TYPE_ACCELEROMETER: {
                    mGravity = event.values.clone();
                    break;
                }
                case Sensor.TYPE_GRAVITY: {
                    mGeomagneticField = event.values.clone();
                    break;
                }
                case Sensor.TYPE_ORIENTATION: {
                    mOrientation = event.values.clone();
                    break;
                }
            }
        }
    }

    public float getOrientation() {
        float azimuth = 0;

        synchronized (mSensorsSync) {
            if (mGravity != null && mGeomagneticField != null) {
                float rotationMatrix[] = new float[16];
                float orientation[] = new float[3];
                SensorManager.getRotationMatrix(rotationMatrix, null,
mGravity, mGeomagneticField);
                SensorManager.getOrientation(rotationMatrix, orientation);
                azimuth = orientation[0] * (180 / (float) Math.PI);
            } else if (mOrientation != null) {
                azimuth = mOrientation[0];
            }
        }

        // If we already have a location, we can adjust from Magnetic North
to True North
        if (mLastLocation != null) {
            GeomagneticField geomagneticField;
            geomagneticField = new GeomagneticField(new
Double(mLastLocation.getLatitude()).floatValue(),
                                                    new
Double(mLastLocation.getLongitude()).floatValue(),
                                                    new
Double(mLastLocation.getAltitude()).floatValue(),

System.currentTimeMillis());
            azimuth += geomagneticField.getDeclination();
        }

        return azimuth;
    }


Now, the "funny" thing is that running this last function every second,
yields this results:
D/r3pek   (27225): Orientation: -124.224174
D/r3pek   (27225): Orientation: -72.60516
D/r3pek   (27225): Orientation: 143.30765
D/r3pek   (27225): Orientation: -170.44586
D/r3pek   (27225): Orientation: 22.947144
D/r3pek   (27225): Orientation: 57.386185
D/r3pek   (27225): Orientation: 11.841694
D/r3pek   (27225): Orientation: -9.966194
D/r3pek   (27225): Orientation: 101.79189
D/r3pek   (27225): Orientation: 98.999954
D/r3pek   (27225): Orientation: 76.45832
D/r3pek   (27225): Orientation: 32.002098
D/r3pek   (27225): Orientation: 10.2068405
D/r3pek   (27225): Orientation: -59.222923

with the phone still on my desk (It's a Nexus One).
Now, if I use the deprecated Orientation sensor, the values are OK but not
with this method.
Can you guys see something that I'm not seeing?

Thanks in advance,
Carlos Silva

On Wed, Jul 20, 2011 at 00:48, Nathan <critter...@crittermap.com> wrote:

>
> On Jul 19, 4:14 pm, Adam Ratana <adam.rat...@gmail.com> wrote:
> > Hello Nathan, I actually use raw Accelerometer + Magnetometer data as
> > well as the deprecated Orientation sensor in my apps (they support
> > 2.1+) and I have yet to receive anything stating that the orientation
> > sensor was not available, perhaps I have been lucky.
>
> Well, I may have gotten lucky too, but I can't say there are no error
> reports.
>
> ANR
>
> DALVIK THREADS:
> (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
> "main" prio=5 tid=1 NATIVE
>  | group="main" sCount=1 dsCount=0 obj=0x4001f1b8 self=0xcee8
>  | sysTid=6034 nice=0 sched=0/0 cgrp=default handle=-1345006496
>  at android.hardware.SensorManager.sensors_enable_sensor(Native
> Method)
>  at
> android.hardware.SensorManager.enableSensorLocked(SensorManager.java:
> 1048)
>  at
> android.hardware.SensorManager.registerListener(SensorManager.java:
> 1143)
>  at
> android.hardware.SensorManager.registerListener(SensorManager.java:
> 1039)
>
> I can't match it up exactly with reports from users that the app is
> frozen on startup, but I am looking at all possibilities.
>
> This article suggests I capture data from both the accelerometer and
> the magnetic field, neither of which I would otherwise care about, and
> use them to calculate orientation. It's a guy from Google, so it might
> be the closest thing I can find to official.
>
>
> http://www.damonkohler.com/2010/06/better-orientation-readings-in-android.html
>
> Nathan
>
> --
> 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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to