Forked from Aaron Berk's ITG3200 driver class library, customized for my specific application using 9DoF-Stick by Sparkfun.

Dependents:   HARP

Fork of ITG3200 by Aaron Berk

ITG-3200 is triple axis, digital interface, gyro sensor.

This library is forked from Aaron Berk's work.

This library is for specific application using 9DoF-Stick.

Datasheet:

http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf

This library has a feature to correct thermal drift of the device. For details, see Thermal Drift.

ITG-3200は3軸のデジタルインターフェースを備えたジャイロセンサです。

このライブラリは 9DoF-Stick を使用した特定の企画のために保守しています。

mbed IDEが日本語をサポートするまでは英語でコメントを書いていきますが、サポートした後もきっと英語で書いていくでしょう。

このライブラリはデバイスの熱ドリフトを補正する機能を持っています。詳しくは Thermal Drift

Files at this revision

API Documentation at this revision

Comitter:
gltest26
Date:
Sat Sep 29 14:34:17 2012 +0000
Parent:
6:a7ad6046824c
Child:
8:ac0365ab3cef
Commit message:
Added a new constructor to accept an external I2C interface object.; Added options to return values not zero adjusted.;

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	Thu Sep 13 14:36:13 2012 +0000
+++ b/ITG3200.cpp	Sat Sep 29 14:34:17 2012 +0000
@@ -35,12 +35,16 @@
 
 #include "ITG3200.h"
 
-ITG3200::ITG3200(PinName sda, PinName scl) : calibSamples(0), i2c_(sda, scl){
+ITG3200::ITG3200(PinName sda, PinName scl, bool fastmode) : calibSamples(0), i2c_(sda, scl){
 
     offset[0] = offset[1] = offset[2] = 0;
 
-    //400kHz, fast mode.
-    i2c_.frequency(400000);
+    if(fastmode){
+        //400kHz, fast mode.
+        i2c_.frequency(400000);
+    }
+    else
+        i2c_.frequency(100000);
     
     //Set FS_SEL to 0x03 for proper operation.
     //See datasheet for details.
--- a/ITG3200.h	Thu Sep 13 14:36:13 2012 +0000
+++ b/ITG3200.h	Sat Sep 29 14:34:17 2012 +0000
@@ -103,8 +103,9 @@
      *
      * @param sda - mbed pin to use for the SDA I2C line.
      * @param scl - mbed pin to use for the SCL I2C line.
+     * @param fastmode Sets the internal I2C interface to use 400kHz clock.
      */
-    ITG3200(PinName sda, PinName scl);
+    ITG3200(PinName sda, PinName scl, bool fastmode = false);
 
     /**
      * Get the identity of the device.
@@ -284,8 +285,9 @@
      * Typical sensitivity is 14.375 LSB/(degrees/sec).
      * 
      * @param readings The output buffer array that has at least 3 length.
+     * @param subtractOffset Make the returned values subtracted of zero offset.
      */
-    void getGyroXYZ(int readings[3]);
+    void getGyroXYZ(int readings[3], bool subtractOffset = true);
 
     /**
      * Burst read the outputs on the x,y,z-axis gyroscope and convert them into degrees per second.
@@ -298,8 +300,9 @@
      * Burst read the outputs on the x,y,z-axis gyroscope and convert them into degrees per second.
      *
      * @param readings The output buffer array that has at least 3 length.
+     * @param subtractOffset Make the returned values subtracted of zero offset.
      */
-    void getGyroXYZRadians(double readings[3]);
+    void getGyroXYZRadians(double readings[3], bool subtractOffset = true);
 
     /**
      * Get the power management configuration.
@@ -396,6 +399,20 @@
         return calibSamples;
     }
 
+    /**
+     * Returns the I2C object that this object is using for communication.
+     */
+    I2C &getI2C(){
+        return i2c_;
+    }
+    
+    /**
+     * Returns internal offset values for zero adjusting. Returned pointer is pointing an array of 3 elements.
+     */
+    const int *getOffset()const{
+        return offset;
+    }
+
 protected:
 
     /**
@@ -426,7 +443,7 @@
     int offset[3];
     
     long calibSamples;
-
+    
 private:
 
     I2C i2c_;
@@ -450,10 +467,12 @@
 };
 
 
-inline void ITG3200::getGyroXYZ(int readings[3]){
+inline void ITG3200::getGyroXYZ(int readings[3], bool subtractOffset){
     getRawGyroXYZ(readings);
-    for(int i = 0; i < 3; i++)
-        readings[i] -= offset[i];
+    if(subtractOffset){
+        for(int i = 0; i < 3; i++)
+            readings[i] -= offset[i];
+    }
 }
 
 inline void ITG3200::getGyroXYZDegrees(double readings[3]){
@@ -463,9 +482,9 @@
         readings[i] = intData[i] * 2000. / 32767.;
 }
 
-inline void ITG3200::getGyroXYZRadians(double readings[3]){
+inline void ITG3200::getGyroXYZRadians(double readings[3], bool subtractOffset){
     int intData[3];
-    getGyroXYZ(intData);
+    getGyroXYZ(intData, subtractOffset);
     for(int i = 0; i < 3; i++)
         readings[i] = intData[i] * 2000. / 32767. * 2. * M_PI / 360.;
 }