如何从 Android 3 轴加速度计的加速度计读数中删除重力因子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3377288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove Gravity factor from Accelerometer readings in Android 3-axis accelerometer
提问by Pritam
Can anyone help on removing the g factor from accelerometer readings?
任何人都可以帮助从加速度计读数中去除 g 因子吗?
I am using SensorEventListener with onSensorChanged()
method for getting Sensor.TYPE_ACCELEROMETER data. I need only pure acceleration values in all directions. So at any state if the device is stable (or in constant speed), it should give (0.0,0.0,0.0) roughly.
我正在使用 SensorEventListener 和onSensorChanged()
获取 Sensor.TYPE_ACCELEROMETER 数据的方法。我只需要所有方向上的纯加速度值。因此,在任何状态下,如果设备稳定(或以恒定速度),它应该大致给出 (0.0,0.0,0.0)。
Currently, depending on its pitch and roll, it gives me variable output depending on the g forces acting on each axis.
目前,根据它的俯仰和滚转,它根据作用在每个轴上的 g 力为我提供可变的输出。
I hope there is some formula to remove this, as I also get orientation values (pitch and roll) from Sensor.TYPE_ORIENTATION listener. I have used some but it didn't work.
我希望有一些公式可以消除它,因为我还从 Sensor.TYPE_ORIENTATION 侦听器中获取方向值(俯仰和滚转)。我用过一些,但没有用。
回答by Matthias Braun
You can use a low-pass filter.
您可以使用低通滤波器。
Do this for each of your sensor values:
对每个传感器值执行此操作:
g = 0.9 * g + 0.1 * v
Where v
is your current sensor value and g
is a global variable initially set to zero. Mind that you'll need as many g variables as you have axes.
v
您当前的传感器值在哪里,是g
初始设置为零的全局变量。请注意,您将需要与轴一样多的 g 变量。
With v = v - g
you can eliminate the gravity factor from your sensor value.
随着v = v - g
您可以消除您的传感器值的重力因素。
回答by Rathore
Use Sensor.TYPE_LINEAR_ACCELERATION instead of Sensor.TYPE_ACCELEROMETER
使用 Sensor.TYPE_LINEAR_ACCELERATION 而不是 Sensor.TYPE_ACCELEROMETER
回答by Johnny
Take a look of the following link.
看看下面的链接。
http://developer.android.com/reference/android/hardware/SensorEvent.html
http://developer.android.com/reference/android/hardware/SensorEvent.html
回答by Theodore Sternberg
Just subtract out g (~9.8m/s^2) times the z direction of the rotation matrix. Or to be more explicit about it, let
只需减去 g (~9.8m/s^2) 乘以旋转矩阵的 z 方向。或者更明确地说,让
a = your accelerometer reading,
R = your rotation matrix (as a 9-long vector).
Then what you want is
那么你想要的是
(a[0]-g*R[6], a[1]-g*R[7], a[2]-g*R[8]).
回答by cxnull
Differentiating with respect to time a function of time rids you of the constants.
对时间进行微分,时间的函数使您摆脱了常数。
So by taking the derivative of the accelerometer's signal you'll get the "Jerk", which you can then re-integrate in order to get the non-constant part of the acceleration you're looking for.
因此,通过获取加速度计信号的导数,您将获得“Jerk”,然后您可以重新积分以获得您正在寻找的加速度的非恒定部分。
In Layman's terms, take a sample from the accelerometer every 1 second, and subtract it from the previous sample. If the answer is (very close to) zero, you're not accelerating relatively to earth. If the result is non-zero, integrate it (in this case, multiply by one second), you have your acceleration.
用外行的话来说,每 1 秒从加速度计中取一个样本,然后从前一个样本中减去它。如果答案是(非常接近)零,则您没有相对于地球加速。如果结果不为零,将其积分(在这种情况下,乘以一秒),您就有了加速度。
Two things, though : -Look out for noise in the signal, round off your input. -Don't expect hyper-accurate results from on-chip accelerometers. You can use them to detect shaking, changes in orientation, but not really for knowing how many G's you're experiencing while making sharp turns in your car.
不过有两件事: - 留意信号中的噪音,完善您的输入。- 不要指望片上加速度计的超准确结果。您可以使用它们来检测摇晃、方向变化,但不能真正了解您在汽车急转弯时经历了多少 G。
回答by Pritam
One way (for devices only with accelerometer) is to remove gravity vector from accelerometer data by subtracting the values that would come in static case for same orientation. But as orientation is again calculated by taking acceleration readings and not independently, its not very accurate.
一种方法(仅适用于带有加速度计的设备)是通过减去相同方向静态情况下的值来从加速度计数据中去除重力矢量。但是由于方向是通过获取加速度读数而不是独立来计算的,所以它不是很准确。
Gyroscope may help in this case. But few androids still have a true gyroscope. And using its raw readings is not so simple.
在这种情况下,陀螺仪可能会有所帮助。但是很少有机器人仍然拥有真正的陀螺仪。使用它的原始读数并不是那么简单。
回答by user9802405
you need to assume two coordinate systems: 1- fixed global system. 2- moving coordinate system in which the origin moves & rotates as sensor does. in global system, g is always parallel to z axis but in moving system it is not. so all you have to do is to compute 3*3 rotation matrix from orientation angles or yaw, pitch & roll. (you can find formulas everywhere). then multiply this rotation matrix by 3*1 acceleration vector measured by sensor. this will transform coordinates and declare the values in fixed global system. the only thing afterward is to simply subtract g from z value.
您需要假设两个坐标系:1- 固定的全局系统。2- 移动坐标系,其中原点像传感器一样移动和旋转。在全局系统中,g 总是平行于 z 轴,但在移动系统中则不是。所以你所要做的就是从方向角或偏航、俯仰和滚转计算 3*3 旋转矩阵。(你可以在任何地方找到公式)。然后将此旋转矩阵乘以传感器测量的 3*1 加速度矢量。这将转换坐标并声明固定全局系统中的值。之后唯一的事情就是简单地从 z 值中减去 g。