Fixing Sensor Drift - need to come up with a clever set up
Hey guys,
I'm using an Arduino Board with an accelerometer, gyroscope and magnetometer. The problem I’m having is that the x axis is drifting downwards in very small numbers, but for example if I start at 0 after 2 minutes the drift becomes significant and it’s not representing the true location of it.
So my idea to prevent it is that if for example the x axis number starts at 0 and drifts slowly to -1, as soon as it hits -1 it fixes itself to 0. This needs to be applied only to the very small change in value so when I’m actually tilting the board and it quickly changes to -40 for example it won't fix itself obviously because it needs to show that it's tilting.
Initially my idea was to compensate the drift by adding a 1 every time the value changes from 0 to -1, but the problem is that it's not a constant drift in time, so sometimes it takes 1 second to change from 0 to -1 and sometimes it's a 1.4s.
Therefore I need to implement a system that compensates for small changes but when a big change is recorded there will be no compensation.
Sorry if the explanation is not very clear, I hope you guys get it!
Your help would be much appreciated, thanks!
Can you post more about how you're using the sensor? Is it subject to rapid changes?
You could do something like split 0 3 to find low values and then keep track of the running average/median for the last n values in that range and just subtract those.
Is there a ceiling on your drift?
Hi Peter,
The way I’m using at the moment is just a 3D representation of a cube in jitter. Like I said it needs to stay in its place but because of the drift over time it shows a false visualization of the cube's position. The problem is in the gyroscope.
There is no ceiling to the drift, it just keeps on changing over time and drops down a whole number every 0.4-0.8s and this changes randomly.
You could convert the data into a signal (via sig~) and then use a high pass filter to remove what is essentially DC offset. You probably want one with a fairly steep roll off at a very low frequency. I'd look at filterdesign for this.
You could also "highpass filter" it at control rate, by subtracting the long-term smoothed value from the input. (Maybe running average/median, or use slide/line)
Both of these approaches don't need a ceiling, but...they will weed out unchanging signals. (So if your sensor outputs 20, 20, 20....for a long while, that will also get filtered)
It's hard to say without seeing some data, but give this approach a shot.