最近我做了一些研究,使用加速度计陀螺仪来使用那些传感器在没有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;
}
}
在这里,我试图从我的加速度计(音调)角度(仅用于测试),从陀螺仪_X的集成通过时间过滤它与互补滤波器
filtered_angle [0] =(0.98f)(filtered_angle [0] gyro_x * dT)(0.02f)(音高)
with dT begin more or less 0.009 secondes
但我不知道为什么,但我的角度不是很准确......当设备平放在 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共享相同的方法....因此,当我计算滤波后的角度时,我会在之前的几秒钟内采取加速度测量的间距,不是吗?这可能是我问题的根源吗?
谢谢 !
4 回答
我只能repeat myself.
通过两次积分线性加速度得到位置,但是 the error is horrible. It is useless in practice. 换句话说,你正试图解决不可能的问题 .
你实际上可以做的是跟踪方向 .
滚动,俯仰和偏航是邪恶的,不要使用它们 . 入住时间为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?
我写了一个关于使用补充滤波器进行轨道跟踪的陀螺仪和加速度计的教程:http://www.pieter-jan.com/node/11也许它可以帮到你 .
我测试你的代码,发现可能比例因子不一致 . 将音高转换为0-pi可获得更好的效果 . 在我的测试中,过滤结果是~90度 .
我试过,这会给你角度90 ...