Normal resting values for Y-axis on L3G gyro

I’m working on a project that uses the AltIMU-10 v3 to provide orientation data for an AHRS. I’ve put together a very basic sketch that outputs the various values from the sensor and I’ve noticed that the gyro settles at 0 on the X and Z axis, but the Y axis always shows a large negative value. Here’s short section of the output:

{“heading”: 178.44, “magX”: -2533, “maxY”: 77, “magZ”: -2420, “accX”: -438, “accY”: -54, “accZ”: 16829, “gyroX”: 0, “gyroY”: -15602, “gyroZ”: 0}
{“heading”: 178.29, “magX”: -2528, “maxY”: 84, “magZ”: -2410, “accX”: -473, “accY”: -54, “accZ”: 16811, “gyroX”: 0, “gyroY”: -15595, “gyroZ”: 0}
{“heading”: 178.45, “magX”: -2536, “maxY”: 84, “magZ”: -2420, “accX”: -470, “accY”: -102, “accZ”: 16816, “gyroX”: 0, “gyroY”: -15591, “gyroZ”: 0}
{“heading”: 178.38, “magX”: -2534, “maxY”: 78, “magZ”: -2417, “accX”: -406, “accY”: -40, “accZ”: 16790, “gyroX”: 0, “gyroY”: -15602, “gyroZ”: 0}
{“heading”: 178.52, “magX”: -2522, “maxY”: 79, “magZ”: -2419, “accX”: -462, “accY”: -94, “accZ”: 16929, “gyroX”: 0, “gyroY”: -15597, “gyroZ”: 0}
{“heading”: 178.59, “magX”: -2538, “maxY”: 72, “magZ”: -2424, “accX”: -405, “accY”: -64, “accZ”: 16786, “gyroX”: 0, “gyroY”: -15590, “gyroZ”: 0}
{“heading”: 178.46, “magX”: -2531, “maxY”: 79, “magZ”: -2431, “accX”: -367, “accY”: -75, “accZ”: 16844, “gyroX”: 0, “gyroY”: -15605, “gyroZ”: 0}
{“heading”: 178.42, “magX”: -2531, “maxY”: 79, “magZ”: -2410, “accX”: -437, “accY”: -61, “accZ”: 16844, “gyroX”: 0, “gyroY”: -15590, “gyroZ”: 0}
{“heading”: 178.91, “magX”: -2538, “maxY”: 68, “magZ”: -2423, “accX”: -443, “accY”: -136, “accZ”: 16826, “gyroX”: 0, “gyroY”: -15589, “gyroZ”: 0}
{“heading”: 178.39, “magX”: -2530, “maxY”: 80, “magZ”: -2421, “accX”: -407, “accY”: -60, “accZ”: 16836, “gyroX”: 0, “gyroY”: -15605, “gyroZ”: 0}
{“heading”: 178.52, “magX”: -2529, “maxY”: 79, “magZ”: -2416, “accX”: -414, “accY”: -95, “accZ”: 16851, “gyroX”: 0, “gyroY”: -15599, “gyroZ”: 0}

I’m expect the accelerometer to show a constant gravitational acceleration, but I’m curious what the constant value on the gyro’s Y axis means. I’ve tried this on both of the AltiIMU-10 v3s and also on a MinIMU-9 v2 that I had and it seems to be consistent. If this is something obvious, please forgive my ignorance.

Cheers,

Steve

Hello, Steve.

I am sorry you are having trouble with your AltIMU-10. Since you have the same problem occurring on three different devices, I suspect that the issue is with your code. Can you post the simplest version of your code that you think should work, but doesn’t?

-Jon

Jonathan,

Here’s a very simple sketch that is exhibiting the behavior:

// Very Simple AltIMU-10 v3 Demo App
#include <Wire.h>
#include <LSM303.h>
#include <L3G.h>

// compass object
LSM303 compass;
LSM303::vector<int16_t> running_min = {32767, 32767, 32767}, running_max = {-32768, -32768, -32768};
L3G gyro;

int timer = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Starting up AHRS module");
 
  Wire.begin();
  Serial.println("Wire library initialized");
  
  compass.init();
  compass.enableDefault();
  Serial.println("Compass initialized");
  
  while (!gyro.init());
  gyro.enableDefault();
  Serial.println("Gyro initialized");  
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(50);
  compass.read();
  
  delay(50);
  gyro.read();
  
    if((millis()-timer)>=20)  // Main loop runs at 50Hz
    {
      timer=millis();
      float heading = compass.heading();
      char dat[250];

      // convert float to int due to arduino weirdness
      long val = (heading * 100);
      
      sprintf(dat, "{\"heading\": %ld, \"magX\": %d, \"maxY\": %d, \"magZ\": %d, \"accX\": %d, \"accY\": %d, \"accZ\": %d, \"gyroX\": %d, \"gyroY\": %d, \"gyroZ\": %d}\n", val, compass.m.x, compass.m.y, compass.m.z, compass.a.x, compass.a.y, compass.a.z, gyro.g.x, gyro.g.y, gyro.g.z);
      Serial.println(dat);
    }
}

And here’s what that’s generating using either the AltIMU-10 v3 or the MinIMU-9 v2:

{"heading": 3529, "magX": 341, "maxY": -491, "magZ": -363, "accX": 80, "accY": 288, "accZ": 15696, "gyroX": 0, "gyroY": 16656, "gyroZ": 0}
{"heading": 3558, "magX": 344, "maxY": -485, "magZ": -365, "accX": 144, "accY": -16, "accZ": 15584, "gyroX": 0, "gyroY": 16656, "gyroZ": 0}
{"heading": 3539, "magX": 341, "maxY": -488, "magZ": -361, "accX": 32, "accY": 304, "accZ": 15712, "gyroX": 0, "gyroY": -16128, "gyroZ": 0}
{"heading": 3530, "magX": 341, "maxY": -488, "magZ": -366, "accX": 96, "accY": 144, "accZ": 15584, "gyroX": 0, "gyroY": -16032, "gyroZ": 0}
{"heading": 3481, "magX": 337, "maxY": -488, "magZ": -363, "accX": 32, "accY": 96, "accZ": 15632, "gyroX": 0, "gyroY": -16224, "gyroZ": 0}
{"heading": 3551, "magX": 343, "maxY": -491, "magZ": -364, "accX": 192, "accY": 176, "accZ": 15440, "gyroX": 0, "gyroY": -16192, "gyroZ": 0}
{"heading": 3537, "magX": 344, "maxY": -491, "magZ": -365, "accX": 96, "accY": 144, "accZ": 15840, "gyroX": 0, "gyroY": 16384, "gyroZ": 0}
{"heading": 3516, "magX": 339, "maxY": -487, "magZ": -367, "accX": 160, "accY": 16, "accZ": 15296, "gyroX": 0, "gyroY": 16656, "gyroZ": 0}
{"heading": 3580, "magX": 344, "maxY": -487, "magZ": -365, "accX": 0, "accY": 432, "accZ": 15872, "gyroX": 0, "gyroY": 16752, "gyroZ": 0}
{"heading": 3626, "magX": 347, "maxY": -485, "magZ": -361, "accX": 176, "accY": 272, "accZ": 15296, "gyroX": 0, "gyroY": -16384, "gyroZ": 0}
{"heading": 3627, "magX": 356, "maxY": -483, "magZ": -366, "accX": -368, "accY": 400, "accZ": 16160, "gyroX": 0, "gyroY": -15984, "gyroZ": 0}
{"heading": 3701, "magX": 352, "maxY": -477, "magZ": -367, "accX": 272, "accY": 64, "accZ": 15232, "gyroX": 0, "gyroY": 16800, "gyroZ": 0}
{"heading": 3740, "magX": 355, "maxY": -477, "magZ": -365, "accX": 256, "accY": 208, "accZ": 15456, "gyroX": 0, "gyroY": 16256, "gyroZ": 0}

All the values seem reasonable (note that the heading is being scaled up by 100 to return an integer rather than a float) except for the gyroY which you can see bounces between -16000 and +17000.

Anything obvious in my code?

Thanks,

Steve

Hi, Steve.

We looked into this a bit and Jon was able to reproduce the problem while running your program (thanks for posting it). In short, the problem is that the gyro readings (gyro.g.x, etc.) provided by the L3G library are floats, and when you try to sprintf them as ints, weird things happen. The fix is simple; just cast the readings to ints:

This isn’t a problem with the compass readings because the LSM303 library provides those readings as ints. I’ve been meaning to update the L3G library to make it more like the LSM303 library, and this is an example of something that could be improved/made more consistent.

- Kevin

Brilliant! Thank you very much. I thought I was losing my mind.

Cheers,

Steve