13

Lots of posts talk about the gyro drift problem. Some guys say that the gyro reading has drift, however others say the integration has drift.

  1. The raw gyro reading has drift[link].
  2. The integration has drift[link](Answer1).

So, I conduct one experiment. The next two figures are what I got. The following figure shows that gyro reading doesn't drift at all, but has the offset. Because of the offset, the integration is horrible. So it seems that the integration is the drift, is it? enter image description here

The next figure shows that when the offset is reduced the integration doesn't drift at all. enter image description here

In addition, I conducted another experiment. First, I put the mobile phone stationary on the desk for about 10s. Then rotated it to the left then restore to back. Then right and back. The following figure tells the angle quite well. What I used is only reducing the offset then take the integration.

enter image description here

So, my big problem here is that maybe the offset is the essence of the gyro drift(integration drift)? Can complimentary filter or kalman filter be applied to remove the gyro drift in this condition?

Any help is appreciated.

Community
  • 1
  • 1
Allen Jee
  • 719
  • 2
  • 7
  • 14

4 Answers4

17

If the gyro reading has "drift", it is called bias and not drift.

The drift is due to the integration and it occurs even if the bias is exactly zero. The drift is because you are accumulating the white noise of the reading by integration.

For drift cancellation, I highly recommend the Direction Cosine Matrix IMU: Theory manuscript, I have implemented sensor fusion for Shimmer 2 devices based on it.

(Edit: The document is from the MatrixPilot project, which has since moved to Github, and can be found in the Downloads section of the wiki there.)

If you insist on the Kalman filter then see https://stackoverflow.com/q/5478881/341970.

By why are you implementing your own sensor fusion algorithm?

Both Android (SensorManager under Sensor.TYPE_ROTATION_VECTOR) and iPhone (Core Motion) offers its own.

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • Really helpful, thanks! Actually, I'm know little about the white noise, I seems that the white noise has minor effect on the integration from the third diagram, is it? So is the drift really a serious issue? – Allen Jee Jan 08 '13 at 11:44
  • Yes, the error can become arbirarily large due to the white noise. Of cource, if you have bias, the situation is even worse :( Anyway, upvoted your question! – Ali Jan 08 '13 at 11:55
  • Appreciated :) I really want to see the the error due to the white noise to get some sense of how to calibrate it. Should I collect the gyro data in 1 hour or others? – Allen Jee Jan 08 '13 at 12:09
  • @AllenJee If you collect the data for an 1 hour, you will see that the bias is fluctuating. Otherwise, I recommend the Direction Cosine Matrix IMU: Theory manuscript, it will give you a clear understanding of the issue. It's basically a tutorial. Good luck! – Ali Jan 08 '13 at 12:21
  • 1
    For Android, `Sensor.TYPE_ROTATION_VECTOR` does not seem to be implemented on all devices (on the OnePlus One running Cyanogenmod I never got any events). There's also the deprecated `Sensor.TYPE_ORIENTATION` as well as API functions to calculate roll, pitch and yaw from accelerometer and magnetometer readings. However, my experience after trying to get yaw values from both sensors on two different devices is that accuracy is somewhere between mediocre and horrible, depending on the device. – user149408 Feb 27 '16 at 17:59
  • 1
    @Ali, I've been trying to understand your statement on drift because of white noise. By drift, I mean gyro integrated output monotonically increasing or increasing when gyro is at rest. If the noise in the gyro output (due to thermo vibrations) is true white noise, then by definition it was zero mean. When you integrate this, you get random walk noise, which also has zero mean. So the gyro integrated output has time-increasing variance, but can't really drift when at rest - am I missing anything? – Ezequiel Garcia Jan 15 '17 at 16:13
  • @EzequielGarcia I am afraid I do not follow. *"When you integrate this, you get random walk noise, which also has zero mean."* No, the expected value of the translation distance is monotonically increasing, see [Gaussian random walk on Wikipedia](https://en.wikipedia.org/wiki/Random_walk#Gaussian_random_walk). Does that answer your question? – Ali Jan 15 '17 at 16:52
  • @Ali, see my reply below. – Ezequiel Garcia Jan 15 '17 at 19:18
  • Does android sensor manager and ios core motion also somehow actively use magnetometer data? – lolelo May 09 '19 at 14:39
  • @lolelo In theory, they could *if* the device has a magnetometer, and that may help to reduce the drift. However, don't expect a miracle from the magnetometer readings. I cannot tell you what the sensor manager or the core motion internally does, sorry. – Ali May 09 '19 at 14:50
  • @Ali So `CMAttitude` (the class that you linked above) for iPhone is actually offering a fusion of acc and gyro sensors? – Bendemann Jan 17 '22 at 08:49
  • 1
    @Bendemann Yes, that is the case. You don't have to do the sensor fusion yourself. – Ali Jan 17 '22 at 08:53
1

The dear Ali wrote something that is really questionable and imprecise (wrong).

The drift is the integration of the bias. It is the visible "effect" of bias when you integrate. The noise - any kind of stationary noise - that has mean zero, consequently has integral zero (I am not talking of the integral of PSD, but of the additive noise of the signal integrated in time).

The bias changes in time, as a function of voltage and exercise temperature. E.g. if voltage changes (and it changes), bias changes. The bias it is not fixed nor "predictable". That is why you can not eliminate bias using the proposed subtraction of the estimated bias by the signal. Also any estimate has an error. This error cumulates in time. If the error is lower, the effects of cumulation (the drifting) become visible in a longer interval, but it still exists.

Theory says that a total elimination of bias it is not possible, at the present days. At the state of the art, no one has still found a way to eliminate the bias - based only gyroscopes and accelerometers magnetometers - that could filter all the bias out.

Android and iPhone have limited implementations of bias elimination algorithms. They are not totally free by bias effects (e.g. in small intervals). For some applications this can cause severe problems and unpredictable results.

stefano
  • 27
  • 2
  • 3
    "The noise - any kind of stationary noise - that has mean zero, consequently has integral zero." Are you familiar with the concept of [random walk](http://en.wikipedia.org/wiki/Random_walk)? Or to put it in another way, if you toss a coin 100 times, according to your logic, I get exactly 50 heads and 50 tails. Do you see the problem? I suggest you revise your answer. – Ali Jul 24 '13 at 08:09
  • He probably meant that the mean value of the integral is zero, too. Drift is a systematic tendency in a process. I am no expert in this, but I do not see any way to compensate for the integrated noise. The integrated bias, on the other hand, could be cancelled by on-the-fly recalibration based on detection of prolonged periods of near-zero angular acceleration. – Pavel Bazant Dec 03 '13 at 12:36
1

In this discussion both Ali and Stefano have raised two fundamental aspects of drifts due to ideal integration.

Basically zero mean white noise is an idealized concept and even for such ideal noise integration offer higher gain over lower frequency component of noise, which introduces a low frequency drift in the integrated signal. By theory the zero mean noise should not cause any drift iff observed over significantly long time but practically ideal integration never works.

On the other hand, even a minor dc-offset in the reading (input signal) can cause a significant drift over a time, if an ideal integration (loss-less summation) is performed on it. It can ramp up a very small dc-offsets in the system, as ideal integration has infinite gain on DC component of an input signal. Therefore for the practical purpose we substitute ideal integration by a low pass filter whose cut-off can be as low as required but can not be zero or too low for practical purpose.

abhijit
  • 79
  • 3
  • 1
    *"By theory the zero mean noise should not cause any drift iff observed over significantly long time"* Are you familiar with the concept of [random walk](https://en.wikipedia.org/wiki/Random_walk)? I suggest you revise your answer. – Ali Oct 30 '15 at 21:10
  • I agree there will be a fluctuation like random walk but if the noise is "really" a zero mean noise and if we observe for long enough time duration ideally till infinity the integrated signal should show equal amount fluctuation over zero. However, no simulated random noise is ideal zero mean noise, so in practice or even in simulation I can expect some drift (Liked Ezequiel's simulation). Over a short time scale we can see the signal drifting but over long enough time scale obviously it will fluctuate across zero rather being drifting away from zero continuously. – abhijit Jan 31 '17 at 04:52
1

Motivated by Ali reply (thanks Ali!), I did some reading and some numerical experiments and decided to post my own reply about the nature of gyro drift.

I've written a simple octave online script plotting white noise and integrated white noise:

enter image description here

The angle plot with reduced offset that is shown in the question seems to resemble a typical random walk. Mathematical random walks has zero mean value, so that cannot be accounted as drift. However, I believe numerical integration of white noise leads to non-zero mean (as can be seen in the histogram plot for random walk below). This, together with linearly increasing variance could be associated to the so-called gyro drift.

There is a great introduction to errors arising from gyroscopes and accelerometers here. In any case, I still have much to learn, so I could be wrong.

Regarding the complimentary filter, there's some discussion here, showing how the gyro drift is reduced by it. The article is very informal, but I found it interesting.

David Lechner
  • 1,433
  • 17
  • 29
Ezequiel Garcia
  • 1,037
  • 8
  • 20