DroidForums.net is the original Verizon Android Forum! Registered Users do not see these ads. Please Register - It's Free!
Results 1 to 1 of 1

Thread: Magnetic Sensor Droid X development issues

  1. Droid Newbie
    ocv808's Avatar
    Member #
    203258
    Join Date
    Jun 2011
    Posts
    1
    Phone
    droid 1 and Nexus S
    #1

    Magnetic Sensor Droid X development issues

    Hello all,
    I have been trying to create a simple compass functionality in an application. I created the simple application doing testing on my Motorola droid 1 (2.22) and nexus S(2.34) and they seemed to work correctly (accuracy was not the best how-ever they work similar to other apps on the same phone so any differences i assumed to be hardware error).

    However i then tested the app on a droid X (2.33) and the results were completely different (and completely wrong). When the phone is rolled around 45 degrees (rotated around z axis a computer coordinate system) the compass heading returned can change over 180 degrees. The heading value even goes in the opposite direction of the other phones (nexus s and droid 1) when spun in the same direction. This is the only phone that produces this result even after calibrating in the settings and doing the normal figure 8 motion. Also when i test against another compass app on the droid x it doesnt seem to have the same issue, but my compass app on the other phones lines up with the 3rd party compass app. So I would assume there would be something i can do in software to avoid this but there is nothing i can find and most people say my code looks correct. Also what would be the difference between these phones to cause this do i have to have special cases for phones that have issues like this?

    Here is my code to perform the orientation calculations

    Code:
    public void onSensorChanged(SensorEvent event)
        {
            // If the sensor data is unreliable return
            if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE)
            {
                Toast.makeText(main.this, "Sensor Status Unreliable",Toast.LENGTH_SHORT).show();
            }
    
    
    
    
    
            // Gets the value of the sensor that has been changed
            switch (event.sensor.getType())
            {
            case Sensor.TYPE_ACCELEROMETER:
                m_vfgravity = event.values.clone();
                break;
            case Sensor.TYPE_MAGNETIC_FIELD:
                m_vfgeomag = event.values.clone();
                break;
            }
    
            if (m_vfgravity != null && m_vfgeomag != null)
            {
                if(SensorManager.getRotationMatrix(m_vfinR, m_vfI, m_vfgravity, m_vfgeomag))
                {
                    SensorManager.getOrientation(m_vfinR, m_vforientVals);
    
                    m_fCompBearing = (float) Math.round((Math.toDegrees(m_vforientVals[0])) *2)/2;
    
                    //convert to 0-360 from -180-180
                    if(m_fCompBearing < 0.0)
                    {
                        m_fCompBearing = 360 + m_fCompBearing;
                    }
    
    
                    mCompHead.setText("" + (int)m_fCompBearing);
                }
    
                calcOffset();   
                rotateCmp();
            }
        }

    and my initialization code

    Code:
    mSMngr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSListener = new cSensorListener();
    
        mSMngr.registerListener(mSListener,
                mSMngr.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_UI);
        mSMngr.registerListener(mSListener,
                mSMngr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                SensorManager.SENSOR_DELAY_UI);
    Any insight and or advice would be greatly appreciated. This bug has been haunting me for almost a week now with no solution in sight. I still cant even identify the root of the problem.

    Thanks in advance !!
  2.  
     
     
     

Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. in pocket detection & other sensor issues
    By yellowbarber in forum Android Tech Support
    Replies: 0
    Last Post: 03-08-2011, 04:03 PM
  2. Orientation and Magnetic Issues
    By DarkNet in forum Cyanogenmod
    Replies: 1
    Last Post: 01-26-2011, 10:24 PM
  3. Anyone else having issues with proximity sensor?
    By razorseal in forum Project Elite
    Replies: 8
    Last Post: 01-01-2011, 10:24 AM
  4. Magnetic field sensor dead
    By PaulC in forum Droid 2 Tech Issues
    Replies: 0
    Last Post: 10-04-2010, 07:05 PM
  5. Will magnetic damage the Droid?
    By nomad in forum Android General Discussions
    Replies: 23
    Last Post: 01-26-2010, 01:51 PM

Search tags for this page

android 2.33 droid x
,
android magnetic
,

android magnetic sensor

,
android magnetic sensor calibration
,

android magnetic sensor error

,
droid x 2.33
,
droid x magnetic case
,
droid x magnetic sensor
,

magnetic sensor error

,

magnetic sensor error android

Click on a term to search our site for related topics.

Tags for this Thread

Find us on Google+