Modified getOffset for calibrating Thermal Drift coefficients.

Dependents:   9Dof_unit_testing

Fork of ITG3200 by James Watanabe

Modified to make getOffset() function easier to use.

Files at this revision

API Documentation at this revision

Comitter:
gltest26
Date:
Thu Sep 13 14:36:13 2012 +0000
Parent:
5:0a0315f0f34e
Child:
7:43b936a53b64
Commit message:
Made ITG3200::calibrate precisely measures time for calibration. Also added calibSamples variable that indicate number of samples for the last calibration.

Changed in this revision

ITG3200.cpp Show annotated file Show diff for this revision Revisions of this file
ITG3200.h Show annotated file Show diff for this revision Revisions of this file
--- a/ITG3200.cpp	Wed Sep 12 22:56:04 2012 +0000
+++ b/ITG3200.cpp	Thu Sep 13 14:36:13 2012 +0000
@@ -35,7 +35,7 @@
 
 #include "ITG3200.h"
 
-ITG3200::ITG3200(PinName sda, PinName scl) : i2c_(sda, scl) {
+ITG3200::ITG3200(PinName sda, PinName scl) : calibSamples(0), i2c_(sda, scl){
 
     offset[0] = offset[1] = offset[2] = 0;
 
@@ -251,20 +251,24 @@
 }
 
 void ITG3200::calibrate(double time){
-    static const double deltaTime = 0.002;
     long sum[3] = {0};
     int sumCount = 0;
-    for(; 0 < time; time -= deltaTime){
+    Timer t;
+    t.start();
+    while(t.read() < time){
         int gyro[3];
-        getGyroXYZ(gyro);
+        getRawGyroXYZ(gyro);
         for(int i = 0; i < 3; i++)
             sum[i] += gyro[i];
         sumCount++;
     }
-    
+    t.stop();
+
     // Avoid zero division
     if(0 < sumCount){
         for(int i = 0; i < 3; i++)
             offset[i] = sum[i] / sumCount;
+        // Update member variable only if successful
+        calibSamples = sumCount;
     }
 }
--- a/ITG3200.h	Wed Sep 12 22:56:04 2012 +0000
+++ b/ITG3200.h	Thu Sep 13 14:36:13 2012 +0000
@@ -391,6 +391,10 @@
      *             correction quality.
      */
     void calibrate(double time);
+    
+    long getCalibrationSamples()const{
+        return calibSamples;
+    }
 
 protected:
 
@@ -420,6 +424,8 @@
      * TODO: temperature drift calibration
      */
     int offset[3];
+    
+    long calibSamples;
 
 private: