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:
tylerjw
Date:
Tue Nov 06 17:31:49 2012 +0000
Parent:
11:9a354f34d8e3
Child:
13:e886466d7d67
Commit message:
getGyro commands replaced with get

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 Oct 31 15:42:01 2012 +0000
+++ b/ITG3200.cpp	Tue Nov 06 17:31:49 2012 +0000
@@ -68,7 +68,12 @@
     tx[1] = 0x03 << 3;
 
     i2c_.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, tx, 2);
+    
+    const float offset[3] = {99.5, -45.0, -29.7}; // taken from itg3200.xls curve fit test
+    const float slope[3] = {-1.05, 0.95, 0.47};
 
+    setCalibrationCurve(offset, slope);
+    setLpBandwidth(LPFBW_5HZ); // lowest rate low-pass filter
 }
 
 void ITG3200::setCalibrationCurve(const float offset[3], const float slope[3])
@@ -254,7 +259,7 @@
 
 }
 
-void ITG3200::getRawGyroXYZ(int readings[3])
+void ITG3200::getRawXYZ(int readings[3])
 {
 
     char tx = GYRO_XOUT_H_REG;
@@ -268,9 +273,9 @@
         readings[i] = swapExtend(&rx[i * 2]);
 }
 
-void ITG3200::getGyroXYZ(int readings[3], Correction corr)
+void ITG3200::getXYZ(int16_t readings[3], Correction corr)
 {
-    getRawGyroXYZ(readings);
+    getRawXYZ(readings);
     switch(corr) {
         case OffsetCorrection:
             for(int i = 0; i < 3; i++)
@@ -319,7 +324,7 @@
     t.start();
     while(t.read() < time) {
         int gyro[3];
-        getRawGyroXYZ(gyro);
+        getRawXYZ(gyro);
         for(int i = 0; i < 3; i++)
             sum[i] += gyro[i];
         sumCount++;
--- a/ITG3200.h	Wed Oct 31 15:42:01 2012 +0000
+++ b/ITG3200.h	Tue Nov 06 17:31:49 2012 +0000
@@ -98,7 +98,7 @@
     static const int I2C_ADDRESS = 0xD0;
     
     /**
-     * @brief Zero offset correction mode that can be specified when calling getGyroXYZ().
+     * @brief Zero offset correction mode that can be specified when calling getXYZ().
      *
      * The device has a major drift in readings depending on ambient temperature.
      * You can measure the temperature with built-in thermometer to correct it, but you
@@ -296,7 +296,7 @@
      *
      * @return The output on the x-axis in raw ADC counts.
      */
-    int getGyroX(void){ return getWord(GYRO_XOUT_H_REG); }
+    int getX(void){ return getWord(GYRO_XOUT_H_REG); }
 
     /**
      * Get the output for the y-axis gyroscope.
@@ -305,7 +305,7 @@
      *
      * @return The output on the y-axis in raw ADC counts.
      */
-    int getGyroY(void){ return getWord(GYRO_YOUT_H_REG); }
+    int getY(void){ return getWord(GYRO_YOUT_H_REG); }
 
     /**
      * Get the output on the z-axis gyroscope.
@@ -314,7 +314,7 @@
      * 
      * @return The output on the z-axis in raw ADC counts.
      */
-    int getGyroZ(void){ return getWord(GYRO_ZOUT_H_REG); }
+    int getZ(void){ return getWord(GYRO_ZOUT_H_REG); }
 
     /**
      * Burst read the outputs on the x,y,z-axis gyroscope.
@@ -324,7 +324,7 @@
      * @param readings The output buffer array that has at least 3 length.
      * @param corr Correction method for returned values.
      */
-    void getGyroXYZ(int readings[3], Correction corr = OffsetCorrection);
+    void getXYZ(int16_t readings[3], Correction corr = OffsetCorrection);
 
     /**
      * Burst read the outputs on the x,y,z-axis gyroscope and convert them into degrees per second.
@@ -332,7 +332,7 @@
      * @param readings The output buffer array that has at least 3 length.
      * @param corr Correction method for returned values.
      */
-    void getGyroXYZDegrees(double readings[3], Correction corr = OffsetCorrection);
+    void getXYZDegrees(double readings[3], Correction corr = OffsetCorrection);
 
     /**
      * Burst read the outputs on the x,y,z-axis gyroscope and convert them into degrees per second.
@@ -340,7 +340,7 @@
      * @param readings The output buffer array that has at least 3 length.
      * @param corr Correction method for returned values.
      */
-    void getGyroXYZRadians(double readings[3], Correction corr = OffsetCorrection);
+    void getXYZRadians(double readings[3], Correction corr = OffsetCorrection);
 
     /**
      * Get the power management configuration.
@@ -421,7 +421,7 @@
      *
      * Be sure to keep the sensor stationary while sampling offset.
      *
-     * Once this function is invoked, following getGyroXYZ*() functions return
+     * Once this function is invoked, following getXYZ*() functions return
      * corrected values.
      *
      * If the drift value changes over time, you can call this function once in a while
@@ -461,7 +461,7 @@
      *
      * The queried value is assumed big-endian, 2's complement value.
      *
-     * This protected function is added because we shouldn't write getGyroX(), getGyroY() and getGyroZ()
+     * This protected function is added because we shouldn't write getX(), getY() and getZ()
      * independently, but collect common codes.
      *
      * @param regi Register address to be read.
@@ -474,7 +474,7 @@
      * Protected for the time being, although there could be cases that raw values are
      * appreciated by the user.
      */
-    void getRawGyroXYZ(int readings[3]);
+    void getRawXYZ(int readings[3]);
 
     /**
      * Offset values that will be subtracted from output.
@@ -516,16 +516,16 @@
 };
 
 
-inline void ITG3200::getGyroXYZDegrees(double readings[3], Correction corr){
+inline void ITG3200::getXYZDegrees(double readings[3], Correction corr){
     int intData[3];
-    getGyroXYZ(intData, corr);
+    getXYZ(intData, corr);
     for(int i = 0; i < 3; i++)
         readings[i] = intData[i] * 2000. / 32767.;
 }
 
-inline void ITG3200::getGyroXYZRadians(double readings[3], Correction corr){
+inline void ITG3200::getXYZRadians(double readings[3], Correction corr){
     int intData[3];
-    getGyroXYZ(intData, corr);
+    getXYZ(intData, corr);
     for(int i = 0; i < 3; i++)
         readings[i] = intData[i] * 2000. / 32767. * 2. * M_PI / 360.;
 }