Arduino ADK and pololu sensor board problem

Hi guys,
I have a Arduino mega ADK board and a sensor board Minimu-9 i connected the arduino and the sensors together,but the values weren't true ,so i searched for filters and I make some kind of filter for the gyro and it was working properly until i notised that when i move the board to fast or long or both the values don't return back to zero instantly when I put the board down. Its someting like this :

G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
G X: 0 Y: 0 Z: 0
...(start shaking)
G X: -926 Y: 799 Z: 317
G X: -2715 Y: 381 Z: -835
G X: -2949 Y: 93 Z: -863
G X: -1535 Y: 457 Z: 433
G X: 721 Y: 2167 Z: 2219
G X: -932 Y: 810 Z: 2834
G X: -657 Y: 411 Z: 3841
.....(shaking and shaking)
G X: -2586 Y: -2026 Z: 5495
G X: -2604 Y: -1567 Z: 5064
G X: -2984 Y: -884 Z: 5559
G X: -1352 Y: -1045 Z: 4524
G X: -1533 Y: -927 Z: 4628
....(stop shaking)
G X: -1482 Y: -891 Z: 4582
G X: -1425 Y: -891 Z: 4581
G X: -1362 Y: -890 Z: 4580
G X: -1284 Y: -889 Z: 4579
G X: -1190 Y: -889 Z: 4578
G X: -1105 Y: -889 Z: 4577
G X: -1023 Y: -888 Z: 4576
G X: -933 Y: -887 Z: 4575
G X: -847 Y: -886 Z: 4574
G X: -762 Y: -885 Z: 4573
G X: -677 Y: -884 Z: 4572
G X: -590 Y: -884 Z: 4571
G X: -500 Y: -883 Z: 4570
G X: -400 Y: -882 Z: 4569
G X: -304 Y: -881 Z: 4568
G X: -214 Y: -880 Z: 4567
G X: -123 Y: -879 Z: 4566
G X: -33 Y: -878 Z: 4565
G X: 0 Y: -877 Z: 4564
G X: 0 Y: -876 Z: 4563
G X: 0 Y: -875 Z: 4562
G X: 0 Y: -874 Z: 4561
G X: 0 Y: -873 Z: 4560
G X: 0 Y: -872 Z: 4559
G X: 0 Y: -871 Z: 4558
G X: 0 Y: -871 Z: 4557
.....(until all 3 axis goes to 0)

and here is my source :

#include <Wire.h>
#include <L3G.h>

L3G gyro;
 int gyroX[99];
 int gyroY[99];
 int gyroZ[99];
 int filtergyroX=0;
 int filtergyroY=0;
 int filtergyroZ=0;
 int BufX=0;
 int BufY=0;
 int BufZ=0;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  
  if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();
}

void loop() 
{
 for(int i=0;i<=99; i++)
 {
   gyro.read();
   gyroX[i]=((int)gyro.g.x);
   gyroY[i]=((int)gyro.g.y);
   gyroZ[i]=((int)gyro.g.z);
   delay(1);
  }
  for(int q=0;q<=99;q++)
  {
   float Kgyro=0.001;
   filtergyroX= BufX+(Kgyro*gyroX[q]);
      BufX=filtergyroX;
   filtergyroY= BufY+(Kgyro*gyroY[q]);
      BufY=filtergyroY;
   filtergyroZ= BufZ+(Kgyro*gyroZ[q]);
      BufZ=filtergyroZ;
  }
  
Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)filtergyroX);
  Serial.print(" Y: ");
  Serial.print((int)filtergyroY);
  Serial.print(" Z: ");
  Serial.println((int)filtergyroZ);
  
}

Does someone have an explanation for those results?
I want to thank you all in advance for your time. :slight_smile: :slight_smile:

That is what they do.
The MEMS sensors are a great invention, but far from ideal.

You need the accelerometer and the compass to keep the orientation.
This is about Kalman filtering, http://arduino.cc/forum/index.php/topic,58048.0.html

Thank you for your answer,Erdin . I will take a look at that topic.