简体   繁体   English

消除加速度计读数中的重力影响

[英]Removing gravity effect from accelerometer readings

I am developing an application, in which I have used Accelerometer for sensing linear accelerations , but after some time I get to know that Accelerometer does not show linear accelerations ( also have gravity effect on it ). 我正在开发一个应用程序,其中使用了Accelerometer来感测线性加速度 ,但是一段时间后,我知道Accelerometer不会显示线性加速度( 也对其产生重力影响 )。

So for removing gravity I have tried some method and reached the conclusion that I must have to design a filter. 因此,为了消除重力,我尝试了一些方法,并得出结论,必须设计一个过滤器。

And for designing filter I have tried the following code. 为了设计过滤器,我尝试了以下代码。

public void onSensorChanged(SensorEvent event)
 {
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter's time-constant
      // and dT, the event delivery rate

      final float alpha = 0.8;

      gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      linear_acceleration[0] = event.values[0] - gravity[0];
      linear_acceleration[1] = event.values[1] - gravity[1];
      linear_acceleration[2] = event.values[2] - gravity[2];
 }

which is taken from Android Developers . 摘自Android Developers

Now I have some problem in the code above: 现在,我在上面的代码中遇到了一些问题:

  1. What are alpha, t and dt? 什么是alpha,t和dt?
  2. How to get the value of t and dt and how to calculate them? 如何获得t和dt的值以及如何计算它们?
  3. Also let me know that the code i am using for getting linear accelerations will work or not? 还让我知道我用于获得线性加速度的代码是否有效?

This method is 'damping' the variation of the sensor values. 这种方法可以“抑制”传感器值的变化。 It's called "exponential smoothing" . 这就是所谓的“指数平滑” In a fast-changing variable, you can find an estimation of the average by taking the latest value, and letting it count for a fraction (alpha). 在快速变化的变量中,您可以通过获取最新值并将其计算为分数(alpha)来找到平均值的估计值。

This algorithm uses this filter to find the constant, which 'must' be gravity. 该算法使用此过滤器来找到常数,“必须”为重力。 Total acceleration = gravity + instantaneous acceleration, so the instantaneous acceleration can be calculated by event.values - gravity . 总加速度=重力+瞬时加速度,因此可以通过event.values - gravity计算瞬时加速度。

This works unless you're eg constantly accelerating (rocket launch, speeding up on highway, ...). 除非您不断加速(火箭发射,在高速公路上加速...),否则此方法有效。 The factor alpha tells you how fast the 'average' can change, and needs to be bigger when you want to measure faster-changing accelerations. 因子α告诉您“平均值”的变化速度,当您想测量变化更快的加速度时,该值需要更大。 This is reflected by the term dt : when smaller (higher event rate) with respect to the filter time constant, alpha becomes bigger. 这由术语dt反映:当相对于过滤器时间常数较小(较高的事件发生率)时,alpha会变大。 The time-constant tells you how fast the effect of a ripple is decaying in the average. 时间常数告诉您平均而言,纹波效应衰减的速度有多快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM