Android的指南针,可补偿倾斜和俯仰 [英] Android Compass that can Compensate for Tilt and Pitch

查看:198
本文介绍了Android的指南针,可补偿倾斜和俯仰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个应用程序在我的Andr​​oid手机(Nexus的4),这将在一个模型船使用。我已经添加了低通滤波器来滤除来自传感器的小胶质。

不过,指南针是唯一稳定的当手机平放在它的后面。如果我倾斜起来,(例如打开一本书的页面),然后罗盘航向去路要走 - 高达50 *

我试图与Sensor.TYPE_MAGNETIC_FIELD有任何Sensor.TYPE_GRAVITY和Sensor.TYPE_ACCELEROMETER和效果是一样的。

我用提到的解决方案<一href="http://stackoverflow.com/questions/10192057/android-getorientation-method-returns-bad-results">here,和许多其他地方。我的数学是不是很大,但是这必须是一个普遍的问题,我觉得很沮丧,有没有一个API来处理它。

我一直对这个问题的3天,仍然没有找到任何解决办法,但是当我使用的从抓指南针,他们保持稳定,无论多少电话是倾斜的。所以我知道它一定是可行的。

我想要做的就是创建一个指南针,如果手机指向说北方话指南针会读北,而不是跳舞,当手机通过任何其他轴(卷或俯仰)移动。

任何人都可以请帮助之前,我不得不放弃我的项目。

谢谢, 亚当

解决方案

通过共同的发病率,我一直在思考这个问题了几个星期,因为

  1. 作为一个数学家,我还没有得到满足任何我见过其他地方提出的答案;和
  2. 我需要一个应用程序,我工作的一个很好的答案。
所以,在过去的几天,我拿出我自己的计算方式在罗盘方位的使用价值。

我已经把那我使用数学<一href="http://math.stackexchange.com/questions/381649/whats-the-best-3d-angular-co-ordinate-system-for-working-with-smartfone-apps/382048#382048">here在math.stackexchange.com ,我已经贴了code,我下面使用。在code计算从原始的 TYPE_GRAVITY TYPE_MAGNETIC_FIELD 传感器数据方位和俯仰,没有任何的API调用例如 SensorManager.getRotationMatrix(...) SensorManager.getOrientation(...)。在code可能可以例如改善通过使用低通滤波器,如果输入变成是有点不稳定。请注意,code通过方法记录了传感器的精度 onAccuracyChanged(传感器传感器,INT精度),所以如果方位好像不稳定的另一件事是检查如何准确的每一个传感器。在任何情况下,与所有的计算在本code明确可见,如果有不稳定性问题(当传感器精度合理),那么他们可以通过查看在输入或在所述方向矢量的不稳定性<加以处理code> m_NormGravityVector [] , m_NormEastVector [] m_NormNorthVector []

我会很感兴趣的任何反馈,任何人都为我的这个方法。我发现,它的工作原理是在我自己的应用程序中的梦想,只要该设备是平的正面向上,垂直,或介于两者之间。然而,正如我提到的math.stackexchange.com的文章,也有出现的设备获得接近被完全颠倒的问题。在这种情况下,人们需要认真确定自己想要的东西的行为。

 进口android.app.Activity;
    进口android.hardware.Sensor;
    进口android.hardware.SensorEvent;
    进口android.hardware.SensorEventListener;
    进口android.hardware.SensorManager;
    进口android.view.Surface;

    公共静态类OrientationSensor实现SensorEventListener {

    公共最后静态INT SENSOR_UNAVAILABLE = -1;

    //其他对象的引用
    的SensorManager m_sm;
    SensorEventListener m_parent; //非空,如果这个类应该调用onSensorChanged(...)和onAccuracyChanged(...)的通知后,其父
    活动m_activity; //为调用getWindowManager()当前的活动。getDefaultDisplay()。getRotation()

    //从Android电子传感器的原始投入
    浮动m_Norm_Gravity; //原料重力矢量的长度在onSensorChanged接收(...)。注:应为约10
    浮动[] m_NormGravityVector; //正常化重力矢量,(即该矢量的长度为1时),这点直线上升到空间
    浮动m_Norm_MagField;生磁场矢量的长度//在onSensorChanged接收(...)。
    浮动[] m_NormMagFieldValues​​; //正常化磁场矢量(即该向量的长度为1)

    //精度规格。 SENSOR_UNAVAILABLE如有不明,否则SensorManager.SENSOR_STATUS_UNRELIABLE,SENSOR_STATUS_ACCURACY_LOW,SENSOR_STATUS_ACCURACY_MEDIUM或SENSOR_STATUS_ACCURACY_HIGH
    INT m_GravityAccuracy; //重力传感器的精度
    INT m_MagneticFieldAccuracy; //磁场传感器的精度

    可一次计算重力和磁场矢量//值
    浮动[] m_NormEastVector; //与磁场值原料重力矢量的标准化叉积,分东
    浮动[] m_NormNorthVector; //归一化矢量指向磁北
    布尔m_OrientationOK; //设置为true,如果m_azimuth_radians和m_pitch_radians已成功地计算下一个调用onSensorChanged(...)
    浮动m_azimuth_radians; //将设备从磁北的角度
    浮动m_pitch_radians; //从水平的设备的倾斜角。 m_pitch_radians = 0如果要是平,m_pitch_radians = Math.PI / 2是指设备的设备是直立的。
    浮动m_pitch_axis_radians; //角度限定的轴的旋转m_pitch_radians

    公共OrientationSensor(SM的SensorManager,SensorEventListener父){
        m_sm = SM;
        m_parent =父母;
        m_activity = NULL;
        m_NormGravityVector = m_NormMagFieldValues​​ = NULL;
        m_NormEastVector =新的浮动[3];
        m_NormNorthVector =新的浮动[3];
        m_OrientationOK = FALSE;
    }

    公众诠释寄存器(活动活动,诠释sensorSpeed​​){
        m_activity =活动; //需要调用getWindowManager()当前的活动。getDefaultDisplay()。getRotation()
        m_NormGravityVector =新的浮动[3];
        m_NormMagFieldValues​​ =新的浮动[3];
        m_OrientationOK = FALSE;
        诠释计数= 0;
        传感器SensorGravity = m_sm.getDefaultSensor(Sensor.TYPE_GRAVITY);
        如果(SensorGravity!= NULL){
            m_sm.registerListener(这一点,SensorGravity,sensorSpeed​​);
            m_GravityAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
            算上++;
        } 其他 {
            m_GravityAccuracy = SENSOR_UNAVAILABLE;
        }
        传感器SensorMagField = m_sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        如果(SensorMagField!= NULL){
            m_sm.registerListener(这一点,SensorMagField,sensorSpeed​​);
            m_MagneticFieldAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
            算上++;
        } 其他 {
            m_MagneticFieldAccuracy = SENSOR_UNAVAILABLE;
        }
        返回计数;
    }

    公共无效注销(){
        m_activity = NULL;
        m_NormGravityVector = m_NormMagFieldValues​​ = NULL;
        m_OrientationOK = FALSE;
        m_sm.unregisterListener(本);
    }

    @覆盖
    公共无效onSensorChanged(SensorEvent EVNT){
        INT SensorType = evnt.sensor.getType();
        开关(SensorType){
            案例Sensor.TYPE_GRAVITY:
                如果(m_NormGravityVector == NULL)m_NormGravityVector =新的浮动[3];
                System.arraycopy(evnt.values​​,0,m_NormGravityVector,0,m_NormGravityVector.length);
                m_Norm_Gravity =(浮点)的Math.sqrt(m_NormGravityVector [0] * m_NormGravityVector [0] + m_NormGravityVector [1] * m_NormGravityVector [1] + m_NormGravityVector [2] * m_NormGravityVector [2]);
                的for(int i = 0; I&LT; m_NormGravityVector.length;我++)m_NormGravityVector [I] / = m_Norm_Gravity;
                打破;
            案例Sensor.TYPE_MAGNETIC_FIELD:
                如果(m_NormMagFieldValues​​ == NULL)m_NormMagFieldValues​​ =新的浮动[3];
                System.arraycopy(evnt.values​​,0,m_NormMagFieldValues​​,0,m_NormMagFieldValues​​.length);
                m_Norm_MagField =(浮点)的Math.sqrt(m_NormMagFieldValues​​ [0] * m_NormMagFieldValues​​ [0] + m_NormMagFieldValues​​ [1] * m_NormMagFieldValues​​ [1] + m_NormMagFieldValues​​ [2] * m_NormMagFieldValues​​ [2]);
                的for(int i = 0; I&LT; m_NormMagFieldValues​​.length;我++)m_NormMagFieldValues​​ [I] / = m_Norm_MagField;
                打破;
        }
        如果(m_NormGravityVector = NULL和放大器;!&安培;!m_NormMagFieldValues​​ = NULL){
            //首先计算水平矢量指向正东方向
            浮East_x = m_NormMagFieldValues​​ [1] * m_NormGravityVector [2]  -  m_NormMagFieldValues​​ [2] * m_NormGravityVector [1];
            浮East_y = m_NormMagFieldValues​​ [2] * m_NormGravityVector [0]  -  m_NormMagFieldValues​​ [0] * m_NormGravityVector [2];
            浮East_z = m_NormMagFieldValues​​ [0] * m_NormGravityVector [1]  -  m_NormMagFieldValues​​ [1] * m_NormGravityVector [0];
            浮动norm_East =(浮动)的Math.sqrt(East_x * East_x + East_y * East_y + East_z * East_z);
            如果(m_Norm_Gravity * m_Norm_MagField * norm_East&LT; 0.1F){//典型值是&GT; 100。
                m_OrientationOK = FALSE; //设备是接近自由下落(或空间),或接近北磁极。
            } 其他 {
                m_NormEastVector [0] = East_x / norm_East; m_NormEastVector [1] = East_y / norm_East; m_NormEastVector [2] = East_z / norm_East;

                //下一个计算水平矢量指向正北
                浮M_dot_G =(m_NormGravityVector [0] * m_NormMagFieldValues​​ [0] + m_NormGravityVector [1] * m_NormMagFieldValues​​ [1] + m_NormGravityVector [2] * m_NormMagFieldValues​​ [2]);
                浮North_x = m_NormMagFieldValues​​ [0]  -  m_NormGravityVector [0] * M_dot_G;
                浮North_y = m_NormMagFieldValues​​ [1]  -  m_NormGravityVector [1] * M_dot_G;
                浮North_z = m_NormMagFieldValues​​ [2]  -  m_NormGravityVector [2] * M_dot_G;
                浮动norm_North =(浮动)的Math.sqrt(North_x * North_x + North_y * North_y + North_z * North_z);
                m_NormNorthVector [0] = North_x / norm_North; m_NormNorthVector [1] = North_y / norm_North; m_NormNorthVector [2] = North_z / norm_North;

                //考虑屏幕旋转远离它的自然旋转
                INT旋转= m_activity.getWindowManager()getDefaultDisplay()getRotation()。
                浮screen_adjustment = 0;
                开关(旋转){
                    案Surface.ROTATION_0:screen_adjustment = 0;打破;
                    案例Surface.ROTATION_90:screen_adjustment =(浮点)Math.PI / 2;打破;
                    案例Surface.ROTATION_180:screen_adjustment =(浮点)Math.PI;打破;
                    案例Surface.ROTATION_270:screen_adjustment = 3 *(浮点)Math.PI / 2;打破;
                }
                //注意:旋转矩阵现在有效地被计算出来。它由三个矢量m_NormEastVector [],m_NormNorthVector []和m_NormGravityVector的[]

                //计算从旋转矩阵所有需要的角
                //注:见http://math.stackexchange.com/questions/381649/whats-the-best-3d-angular-co-ordinate-system-for-working-with-smartfone-apps
                浮罪= m_NormEastVector [1]  -  m_NormNorthVector [0],余弦= m_NormEastVector [0] + m_NormNorthVector [1];
                m_azimuth_radians =(浮点)(SIN = 0&功放;&安培; COS = 0 Math.atan2(SIN,COS):!?0);
                m_pitch_radians =(浮点)Math.acos(m_NormGravityVector [2]);
                罪= -m_NormEastVector [1]  -  m_NormNorthVector [0];余弦= m_NormEastVector [0]  -  m_NormNorthVector [1];
                浮动aximuth_plus_two_pitch_axis_radians =(浮点)(SIN = 0&功放;&安培; COS = 0 Math.atan2(SIN,COS):!?0);
                m_pitch_axis_radians =(浮点)(aximuth_plus_two_pitch_axis_radians  -  m_azimuth_radians)/ 2;
                m_azimuth_radians + = screen_adjustment;
                m_pitch_axis_radians + = screen_adjustment;
                m_OrientationOK = TRUE;
            }
        }
        如果(m_parent!= NULL)m_parent.onSensorChanged(EVNT);
    }

    @覆盖
    公共无效onAccuracyChanged(传感器传感器,诠释精度){
        INT SensorType = sensor.getType();
        开关(SensorType){
            案例Sensor.TYPE_GRAVITY:m_GravityAccuracy =准确性;打破;
            案例Sensor.TYPE_MAGNETIC_FIELD:m_MagneticFieldAccuracy =准确性;打破;
        }
        如果(m_parent!= NULL)m_parent.onAccuracyChanged(传感器,精度);
    }
}
 

I'm trying to make a application on my Android phone (Nexus 4), which will be used in a model boat. I've added low pass filters to filter out the gitter from the sensors.

However, the compass is only stable when the phone is flat on its back. If I tilt it up, (such as turning a page of a booK), then the compass heading goes way off - as much as 50*.

I've tried this with Sensor.TYPE_MAGNETIC_FIELD with either Sensor.TYPE_GRAVITY and Sensor.TYPE_ACCELEROMETER and the effect is the same.

I've used the solution mentioned here, and many other places. My maths is not great but this must be a common problem and I find it frustrating that there is not an API to deal with it.

I've been working on this problem for 3 days and have still not found any solution, but when I use the Compass from Catch, theirs stays stable no matter how much the phone is inclined. So I know it must be possible.

All I want to do is create a compass that if the phone is pointing say north, then the compass will read north, and not jump around when the phone is moved through any other axis (roll or pitch).

Can anyone please help before I have to abandon my project.

Thanks, Adam

解决方案

By co-incidence I've been thinking about this problem for several weeks, because

  1. As a mathematician, I haven't been satisfied by any of the answers that I've seen suggested elsewhere; and
  2. I need a good answer for an app that I'm working on.

So over the last couple of days I've come up with my own way of calculating the azimuth value for use in a compass.

I've put that maths that I'm using here on math.stackexchange.com, and I've pasted the code I've used below. The code calculates the azimuth and pitch from the raw TYPE_GRAVITY and TYPE_MAGNETIC_FIELD sensor data, without any API calls to e.g. SensorManager.getRotationMatrix(...) or SensorManager.getOrientation(...). The code could probably be improved e.g. by using a low pass filter if the inputs turn out to be a bit erratic. Note that the code records the accuracy of the sensors via the method onAccuracyChanged(Sensor sensor, int accuracy), so if the azimuth seems unstable another thing to check is how accurate each sensor is. In any case, with all the calculations explicitly visible in this code, if there are instability problems (when the sensor accuracy is reasonable) then they could be tackled by looking at the instabilities in the inputs or in the direction vectors m_NormGravityVector[], m_NormEastVector[] or m_NormNorthVector[].

I'd be very interested in any feedback that anyone has for me on this method. I find that it works like a dream in my own app, as long as the device is flat face up, vertical, or somewhere in between. However, as I mention in the math.stackexchange.com article, there are issues that arise as the device gets close to being turned upside down. In that situation, one would need to define carefully what behaviour one wants.

    import android.app.Activity;
    import android.hardware.Sensor;
    import android.hardware.SensorEvent;
    import android.hardware.SensorEventListener;
    import android.hardware.SensorManager;
    import android.view.Surface;

    public static class OrientationSensor implements  SensorEventListener {

    public final static int SENSOR_UNAVAILABLE = -1;

    // references to other objects
    SensorManager m_sm;
    SensorEventListener m_parent;   // non-null if this class should call its parent after onSensorChanged(...) and onAccuracyChanged(...) notifications
    Activity m_activity;            // current activity for call to getWindowManager().getDefaultDisplay().getRotation()

    // raw inputs from Android sensors
    float m_Norm_Gravity;           // length of raw gravity vector received in onSensorChanged(...).  NB: should be about 10
    float[] m_NormGravityVector;    // Normalised gravity vector, (i.e. length of this vector is 1), which points straight up into space
    float m_Norm_MagField;          // length of raw magnetic field vector received in onSensorChanged(...). 
    float[] m_NormMagFieldValues;   // Normalised magnetic field vector, (i.e. length of this vector is 1)

    // accuracy specifications. SENSOR_UNAVAILABLE if unknown, otherwise SensorManager.SENSOR_STATUS_UNRELIABLE, SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_MEDIUM or SENSOR_STATUS_ACCURACY_HIGH
    int m_GravityAccuracy;          // accuracy of gravity sensor
    int m_MagneticFieldAccuracy;    // accuracy of magnetic field sensor

    // values calculated once gravity and magnetic field vectors are available
    float[] m_NormEastVector;       // normalised cross product of raw gravity vector with magnetic field values, points east
    float[] m_NormNorthVector;      // Normalised vector pointing to magnetic north
    boolean m_OrientationOK;        // set true if m_azimuth_radians and m_pitch_radians have successfully been calculated following a call to onSensorChanged(...)
    float m_azimuth_radians;        // angle of the device from magnetic north
    float m_pitch_radians;          // tilt angle of the device from the horizontal.  m_pitch_radians = 0 if the device if flat, m_pitch_radians = Math.PI/2 means the device is upright.
    float m_pitch_axis_radians;     // angle which defines the axis for the rotation m_pitch_radians

    public OrientationSensor(SensorManager sm, SensorEventListener parent) {
        m_sm = sm;
        m_parent = parent;
        m_activity = null;
        m_NormGravityVector = m_NormMagFieldValues = null;
        m_NormEastVector = new float[3];
        m_NormNorthVector = new float[3];
        m_OrientationOK = false;
    }

    public int Register(Activity activity, int sensorSpeed) {
        m_activity = activity;  // current activity required for call to getWindowManager().getDefaultDisplay().getRotation()
        m_NormGravityVector = new float[3];
        m_NormMagFieldValues = new float[3];
        m_OrientationOK = false;
        int count = 0;
        Sensor SensorGravity = m_sm.getDefaultSensor(Sensor.TYPE_GRAVITY);
        if (SensorGravity != null) {
            m_sm.registerListener(this, SensorGravity, sensorSpeed);
            m_GravityAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
            count++;
        } else {
            m_GravityAccuracy = SENSOR_UNAVAILABLE;
        }
        Sensor SensorMagField = m_sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        if (SensorMagField != null) {
            m_sm.registerListener(this, SensorMagField, sensorSpeed);
            m_MagneticFieldAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;     
            count++;
        } else {
            m_MagneticFieldAccuracy = SENSOR_UNAVAILABLE;
        }
        return count;
    }

    public void Unregister() {
        m_activity = null;
        m_NormGravityVector = m_NormMagFieldValues = null;
        m_OrientationOK = false;
        m_sm.unregisterListener(this);
    }

    @Override
    public void onSensorChanged(SensorEvent evnt) {
        int SensorType = evnt.sensor.getType();
        switch(SensorType) {
            case Sensor.TYPE_GRAVITY:
                if (m_NormGravityVector == null) m_NormGravityVector = new float[3];
                System.arraycopy(evnt.values, 0, m_NormGravityVector, 0, m_NormGravityVector.length);                   
                m_Norm_Gravity = (float)Math.sqrt(m_NormGravityVector[0]*m_NormGravityVector[0] + m_NormGravityVector[1]*m_NormGravityVector[1] + m_NormGravityVector[2]*m_NormGravityVector[2]);
                for(int i=0; i < m_NormGravityVector.length; i++) m_NormGravityVector[i] /= m_Norm_Gravity;
                break;
            case Sensor.TYPE_MAGNETIC_FIELD:
                if (m_NormMagFieldValues == null) m_NormMagFieldValues = new float[3];
                System.arraycopy(evnt.values, 0, m_NormMagFieldValues, 0, m_NormMagFieldValues.length);
                m_Norm_MagField = (float)Math.sqrt(m_NormMagFieldValues[0]*m_NormMagFieldValues[0] + m_NormMagFieldValues[1]*m_NormMagFieldValues[1] + m_NormMagFieldValues[2]*m_NormMagFieldValues[2]);
                for(int i=0; i < m_NormMagFieldValues.length; i++) m_NormMagFieldValues[i] /= m_Norm_MagField;  
                break;
        }
        if (m_NormGravityVector != null && m_NormMagFieldValues != null) {
            // first calculate the horizontal vector that points due east
            float East_x = m_NormMagFieldValues[1]*m_NormGravityVector[2] - m_NormMagFieldValues[2]*m_NormGravityVector[1];
            float East_y = m_NormMagFieldValues[2]*m_NormGravityVector[0] - m_NormMagFieldValues[0]*m_NormGravityVector[2];
            float East_z = m_NormMagFieldValues[0]*m_NormGravityVector[1] - m_NormMagFieldValues[1]*m_NormGravityVector[0];
            float norm_East = (float)Math.sqrt(East_x * East_x + East_y * East_y + East_z * East_z);
            if (m_Norm_Gravity * m_Norm_MagField * norm_East < 0.1f) {  // Typical values are  > 100.
                m_OrientationOK = false; // device is close to free fall (or in space?), or close to magnetic north pole.
            } else {
                m_NormEastVector[0] = East_x / norm_East; m_NormEastVector[1] = East_y / norm_East; m_NormEastVector[2] = East_z / norm_East;

                // next calculate the horizontal vector that points due north                   
                float M_dot_G = (m_NormGravityVector[0] *m_NormMagFieldValues[0] + m_NormGravityVector[1]*m_NormMagFieldValues[1] + m_NormGravityVector[2]*m_NormMagFieldValues[2]);
                float North_x = m_NormMagFieldValues[0] - m_NormGravityVector[0] * M_dot_G;
                float North_y = m_NormMagFieldValues[1] - m_NormGravityVector[1] * M_dot_G;
                float North_z = m_NormMagFieldValues[2] - m_NormGravityVector[2] * M_dot_G;
                float norm_North = (float)Math.sqrt(North_x * North_x + North_y * North_y + North_z * North_z);
                m_NormNorthVector[0] = North_x / norm_North; m_NormNorthVector[1] = North_y / norm_North; m_NormNorthVector[2] = North_z / norm_North;

                // take account of screen rotation away from its natural rotation
                int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation();
                float screen_adjustment = 0;
                switch(rotation) {
                    case Surface.ROTATION_0:   screen_adjustment =          0;         break;
                    case Surface.ROTATION_90:  screen_adjustment =   (float)Math.PI/2; break;
                    case Surface.ROTATION_180: screen_adjustment =   (float)Math.PI;   break;
                    case Surface.ROTATION_270: screen_adjustment = 3*(float)Math.PI/2; break;
                }
                // NB: the rotation matrix has now effectively been calculated. It consists of the three vectors m_NormEastVector[], m_NormNorthVector[] and m_NormGravityVector[]

                // calculate all the required angles from the rotation matrix
                // NB: see http://math.stackexchange.com/questions/381649/whats-the-best-3d-angular-co-ordinate-system-for-working-with-smartfone-apps
                float sin = m_NormEastVector[1] -  m_NormNorthVector[0], cos = m_NormEastVector[0] +  m_NormNorthVector[1];
                m_azimuth_radians = (float) (sin != 0 && cos != 0 ? Math.atan2(sin, cos) : 0);
                m_pitch_radians = (float) Math.acos(m_NormGravityVector[2]);
                sin = -m_NormEastVector[1] -  m_NormNorthVector[0]; cos = m_NormEastVector[0] -  m_NormNorthVector[1];
                float aximuth_plus_two_pitch_axis_radians = (float)(sin != 0 && cos != 0 ? Math.atan2(sin, cos) : 0);
                m_pitch_axis_radians = (float)(aximuth_plus_two_pitch_axis_radians - m_azimuth_radians) / 2;
                m_azimuth_radians += screen_adjustment;
                m_pitch_axis_radians += screen_adjustment;
                m_OrientationOK = true;                                 
            }
        }
        if (m_parent != null) m_parent.onSensorChanged(evnt);
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        int SensorType = sensor.getType();
        switch(SensorType) {
            case Sensor.TYPE_GRAVITY: m_GravityAccuracy = accuracy; break;
            case Sensor.TYPE_MAGNETIC_FIELD: m_MagneticFieldAccuracy = accuracy; break;
        }
        if (m_parent != null) m_parent.onAccuracyChanged(sensor, accuracy);
    }
}

这篇关于Android的指南针,可补偿倾斜和俯仰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆