# L3G4200D angle calculation

Question asked by benedetto.salvatore on May 24, 2012
Hi there,

I'm using an L3G4200D sensor for calculating the angle displacement
with the code below. However from the computation I get half of the real rotation
the sensor make, that is, if I rotate it of 90 degree, I measure a 45 degree rotation.

The output data rate is set a 100hz, resolution is 250dps and the BW is set at 12,5Hz.
I realized that I might loose some samples (I don't use interrupts),
but that should not be a problem when rotating at constant speed,
as I always calculate the delta from the last sample.

Any suggestion would be appreciated.

117 `while (1) {` `        gyroscope.readGyroscopeData(x, y, z);` `// Data rate is 100Hz, thus T = 0.01s` `        uint64_t currentValue = util::currentCounterValue();` `        uint32_t delta = currentValue - previousValue;` `        timeElapsed = (float)delta / 1000000;` `        previousValue = currentValue;` `/* Convert data to dps */` `if ((x - x0) > kThreshold || (x - x0) < -kThreshold)` `          wxz = (x - x0) * 0.00875;` `else` `          wxz = 0;` `if ((y - y0) > kThreshold || (y - y0) < -kThreshold)` `          wyz = (y - y0) * 0.00875;` `else` `          wyz = 0;` `if ((z - z0) > kThreshold || (z - z0) < -kThreshold)` `          wxy = (z - z0) * 0.00875;` `else` `          wxy = 0;` `        xz += (wxz * timeElapsed);` `        yz += (wyz * timeElapsed);` `        xy += (wxy * timeElapsed);` `        sprintf(bufferOut, "#wxz=%+f wyz=%+f wxy=%+f xz=%+f yz=%+f xy=%+f\n",` `                wxz, wyz, wxy, xz, yz, xy);` `        trace(bufferOut);` `        gpioPortC.toggle(GPIO::ePin12);` `/* Sensor data rate is set at 100Hz. */` `//util::delayms(1);` `      }`