簡體   English   中英

使用加速度計獲取設備運動方向

[英]Get device motion direction using accelerometer

我正在嘗試使用加速度計檢測android設備的運動方向。 我已經從加速度計的輸出值中刪除了重力分量,並減去了角度。

因此,我既可以獲取運動方向,又可以瞬間獲取任意角度。 就像我停止移動設備時一樣。

有什么建議可以過濾掉這些角度嗎?

編輯:我已經能夠通過采用當前和過去值的平均值來解決此問題。 仍然存在的另一個問題是,在最初的一會兒,加速度計會報告運動方向相反的值。

這是加速度計的典型問題。最初,由於慣性等原因,沒有任何解決方案。但是,您可以嘗試使用某種“整數控制器”。

另一個可能的解決方案是檢測加速度的突然變化,並將其解釋為方向變化,例如,如果您在X邊緣(Ax)上具有加速度,則表示這種變化。

while(1){
Ax = readAx();
if(changeSign(Ax)){  //From + to - or - to +.
      //Do what ever you need, for example if sign is changed and keep on it then is that the mobilephone is been moved in the other direction. Else if it's acceleration is close to 0 it means that the device has stopped
}else{
     //The device keep moving on the same direction.
}
}

隨時發揮創造力。 管理解決方案的方法有很多,具體取決於您的目標。

希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM