2013-04-30 64 views
3

我正在嘗試爲我正在處理的項目製作一個指南針應用程序,該應用程序可以在崎嶇地形上工作。我已經使用標準TYPE_ACCELEROMETERTYPE_MAGNETIC_FIELD傳感器,它似乎給出了相當準確的讀數。但是,當我圍繞其y軸和z軸傾斜手機時,即使手機指向相同方向(恆定z軸),標題讀數也會改變。Android傾斜補償指南針

有誰知道如何彌補這個?示例代碼將不勝感激。

這是我目前使用的代碼:

private void updateDirection() { 
    float[] R = new float[16]; 
     float[] orientationValues = new float[3]; 

     if(SensorManager.getRotationMatrix (R, null, accelerometerValues, magneticValues)){ 

     SensorManager.getOrientation (R, orientationValues); 

     orientationValues[0] = (float)Math.toDegrees (orientationValues[0]); 
     orientationValues[1] = (float)Math.toDegrees (orientationValues[1]); 
     orientationValues[2] = (float)Math.toDegrees (orientationValues[2]); 

     if(orientationValues[0] < 0){ 
      orientationValues[0] = 360 + orientationValues[0]; 
     } 

     final int trueNorthHeading = NavigationUtils.getTrueNorthBearing(currentLocation, orientationValues[0]); 
     if(trueNorthHeading == currentHeading) { 
     return; 
    } 

     int accuracy = 3; 
     if(NavigationUtils.isSignificantHeadingChange(currentHeading, trueNorthHeading, accuracy, SIGNIFICANT_CHANGE_LIMIT)){ 

      int headingChangeDegrees = NavigationUtils.getStearageDegree(currentHeading, trueNorthHeading); 
     currentHeading = trueNorthHeading;  

     navigationManager.headingUpdate(trueNorthHeading, Math.round(orientationValues[0]), headingChangeDegrees); 

      Log.d("COMPASS", "North: values[0]: " + (int)orientationValues[0]); 
     } 
     } 
} 

感謝您的幫助,

亞當

+0

您的意思是說,它在旋轉時被某種設備固定在適當位置時會稍微變化?或者它比微小的漂移更明顯? – 2013-04-30 18:21:44

+0

當圍繞y軸旋轉時,即使手機指向相同方向,返回的值也會從160 *到200 *。除了輕微的漂移,Defo更重要。 – 2013-04-30 18:32:03

+0

手機是平躺還是垂直? – 2013-04-30 19:59:54

回答

2

使用TYPE_GRAVITY代替或在未使用過濾器的低通濾波器的加速度計或卡爾曼濾波器。 TYPE_GRAVITY提高了低通濾波器的精度,最高可達10度。

+0

沒有工作。事實上它使情況更糟。你會認爲Google的聰明人會爲做這種事情做一個簡單的API,考慮他們在增強現實中付出了多少努力。 – 2013-04-30 20:50:05

+0

我不太明白你帖子中的問題。有關方位角的錯誤?你的手機的位置是什麼? – 2013-04-30 20:52:19

+0

手機的位置平放在桌子上,遠離所有的磁場干擾。假設我圍繞y軸旋轉它的方向[0]爲150 *,例如向左或向右旋轉約60 *,則方向[0]的讀數變化多達40 *,即使圍繞z軸。 – 2013-04-30 21:07:26