AHRS

Dependencies:   Eigen

Dependents:   IndNav_QK3_T265

Revision:
7:bfde7bd5fe31
Parent:
4:3c21fb0c9e84
Child:
12:1070a10a4624
--- a/LSM9DS1_i2c.cpp	Fri Jun 14 07:05:20 2019 +0000
+++ b/LSM9DS1_i2c.cpp	Wed Jun 26 14:19:01 2019 +0000
@@ -68,12 +68,12 @@
     settings.gyro.enableY = true;
     settings.gyro.enableZ = true;
     // gyro scale can be 245, 500, or 2000
-    settings.gyro.scale = 245;
+    settings.gyro.scale = 500;
     // gyro sample rate: value between 1-6
     // 1 = 14.9    4 = 238
     // 2 = 59.5    5 = 476
     // 3 = 119     6 = 952
-    settings.gyro.sampleRate = 6;
+    settings.gyro.sampleRate = 5;
     // gyro cutoff frequency: value between 0-3
     // Actual value of cutoff frequency depends
     // on sample rate.
@@ -100,7 +100,7 @@
     // 1 = 10 Hz    4 = 238 Hz
     // 2 = 50 Hz    5 = 476 Hz
     // 3 = 119 Hz   6 = 952 Hz
-    settings.accel.sampleRate = 6;
+    settings.accel.sampleRate = 5;
     // Accel cutoff freqeuncy can be any value between -1 - 3. 
     // -1 = bandwidth determined by sample rate
     // 0 = 408 Hz   2 = 105 Hz
@@ -121,7 +121,7 @@
     // 1 = 1.25 Hz   5 = 20 Hz
     // 2 = 2.5 Hz    6 = 40 Hz
     // 3 = 5 Hz      7 = 80 Hz
-    settings.mag.sampleRate = 7;
+    settings.mag.sampleRate = 4;
     settings.mag.tempCompensationEnable = false;
     // magPerformance can be any value between 0-3
     // 0 = Low power mode      2 = high performance
@@ -345,7 +345,7 @@
     // Turn on FIFO and set threshold to 32 samples
     enableFIFO(true);
     setFIFO(FIFO_THS, 0x1F);
-    while (samples < 0x1F)
+    while (samples < 0x7F)
     {
         samples = (xgReadByte(FIFO_SRC) & 0x3F); // Read number of stored samples
     }
@@ -584,9 +584,9 @@
         gy -= gBiasRaw[Y_AXIS];
         gz -= gBiasRaw[Z_AXIS];
     }
-    gyroX = static_cast<float>(gx)/32768.0f*245.0f*3.14159265358979323846f/180.0f;
-    gyroY = static_cast<float>(gy)/32768.0f*245.0f*3.14159265358979323846f/180.0f;
-    gyroZ = static_cast<float>(gz)/32768.0f*245.0f*3.14159265358979323846f/180.0f;
+    gyroX = static_cast<float>(gx)/32768.0f*(float)settings.gyro.scale*3.14159265358979323846f/180.0f;
+    gyroY = static_cast<float>(gy)/32768.0f*(float)settings.gyro.scale*3.14159265358979323846f/180.0f;
+    gyroZ = static_cast<float>(gz)/32768.0f*(float)settings.gyro.scale*3.14159265358979323846f/180.0f;
 }
 
 int16_t LSM9DS1::readGyro(lsm9ds1_axis axis)