android - 互补滤波器(陀螺仪+加速器)与安卓

标签 android filter tracking accelerometer gyroscope

最近我做了一些研究,使用加速度计 + 陀螺仪来使用这些传感器在没有 GPS 帮助的情况下跟踪智能手机(见这篇文章) Indoor Positioning System based on Gyroscope and Accelerometer

为此,我将需要我的方向(角度(俯仰、滚动等..))所以这里是我到目前为止所做的:

public void onSensorChanged(SensorEvent arg0) {
    if (arg0.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    {
        accel[0] = arg0.values[0];
         accel[1] = arg0.values[1];
   accel[2] = arg0.values[2];
   pitch = Math.toDegrees(Math.atan2(accel[1], Math.sqrt(Math.pow(accel[2], 2) + Math.pow(accel[0], 2))));

  tv2.setText("Pitch: " + pitch + "\n" + "Roll: " + roll);

   } else if (arg0.sensor.getType() == Sensor.TYPE_GYROSCOPE )
{
  if (timestamp != 0) {
  final float dT = (arg0.timestamp - timestamp) * NS2S;         
  angle[0] += arg0.values[0] * dT;
  filtered_angle[0] = (0.98f) * (filtered_angle[0] + arg0.values[0] * dT) + (0.02f)* (pitch);
   }        
   timestamp = arg0.timestamp;
 }
}

在这里,我试图从我的加速度计(俯仰)角度(仅用于测试),通过集成 gyroscope_X 槽时间用互补滤波器对其进行过滤

filtered_angle[0] = (0.98f) * (filtered_angle[0] + gyro_x * dT) + (0.02f)* (pitch)

dT 开始大约 0.009 秒

但我不知道为什么,但我的角度不是很准确......当设备平放在 table 上时(屏幕朝上)

Pitch (angle fromm accel) = 1.5 (average) 
Integrate gyro = 0 to growing (normal it's drifting) 
filtered gyro angle = 1.2

当我将手机抬起90°时(看到屏幕正对着我面前的墙)

Pitch (angle fromm accel) = 86 (MAXIMUM) 
Integrate gyro = he is out ok its normal 
filtered gyro angle = 83 (MAXIMUM)

所以角度永远不会达到 90???即使我试着把电话拿得再高一点…… 为什么直到 90° 才开始?我的计算错了吗?还是传感器质量差?

我想知道的另一件事是:使用 Android 我不会“读出”传感器的值,但当它们发生变化时我会收到通知。问题是,正如您在代码中看到的,Accel 和 Gyro 共享相同的方法……所以当我计算过滤后的角度时,我将在 0.009 秒之前采用加速度测量的间距,不是吗?这可能是我问题的根源吗?

谢谢!

最佳答案

我只能repeat myself.

您可以通过对线性加速度进行两次积分来获得位置,但是误差非常大。它在实践中没有用。 换句话说,您正在尝试解决不可能的事情。

您实际上可以做的只是跟踪方向。

Roll、pitch 和 yaw 是邪恶的,不要使用它们。打卡the video I already recommended , 在 38:25。

这是一个 excellent tutorial关于如何使用陀螺仪和加速度计跟踪方向。

您可能会发现有帮助的类似问题:

track small movements of iphone with no GPS
What is the real world accuracy of phone accelerometers when used for positioning?
how to calculate phone's movement in the vertical direction from rest?
iOS: Movement Precision in 3D Space
How to use Accelerometer to measure distance for Android Application Development
Distance moved by Accelerometer
How can I find distance traveled with a gyroscope and accelerometer?

关于android - 互补滤波器(陀螺仪+加速器)与安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7553417/

相关文章:

java - 如何把最后一个文档添加到recyclerview的底部?

python : RuntimeWarning: overflow encountered

python - 跟踪红外LED阵列以找到其坐标

python - OpenCV中Lucas-Kanade跟踪器中的错误和状态输出

android onactivityresult data.getData() 在 fragment 中返回 null

android - 如何根据选中的单选按钮将 Spinner 值重置为 "Select by something"

带有游标的Android列表设计问题

angularjs - 如何将过滤按钮添加到 ui-grid 标题

javascript - 检查一个数组是否包含在对象内部的另一个数组中

ruby-on-rails - ActiveAdmin:如何在过滤器中使用多选?