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

Revision:
3:eea9733ca427
Parent:
1:9bef044f45ad
Child:
4:155c44407af5
--- a/ITG3200.h	Wed Sep 12 11:36:48 2012 +0000
+++ b/ITG3200.h	Wed Sep 12 14:37:34 2012 +0000
@@ -1,4 +1,5 @@
 /**
+ * @file ITG3200.h
  * @author Aaron Berk
  *
  * @section LICENSE
@@ -26,6 +27,7 @@
  * @section DESCRIPTION
  *
  * ITG-3200 triple axis, digital interface, gyroscope.
+ * Forked from Aaron Berk's work.
  *
  * Datasheet:
  *
@@ -35,12 +37,12 @@
 #ifndef ITG3200_H
 #define ITG3200_H
 
-/**
+/*
  * Includes
  */
 #include "mbed.h"
 
-/**
+/*
  * Defines
  */
 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address.
@@ -86,6 +88,12 @@
 
 public:
 
+    /**
+     * The I2C address that can be passed directly to i2c object (it's already shifted 1 bit left).
+     *
+     * You don't need to manually set or clear the LSB when calling I2C::read() or I2C::write(),
+     * the library takes care of it.  We just always clear the LSB.
+     */
     static const int I2C_ADDRESS = 0xD0;
 
     /**
@@ -366,6 +374,39 @@
      * @param config The configuration byte to write to the PWR_MGM register.
      */
     void setPowerManagement(char config);
+    
+    /**
+     * Calibrate the sensor drift by sampling zero offset.
+     *
+     * Be sure to keep the sensor stationary while sampling offset.
+     *
+     * Once this function is invoked, following getGyroXYZ*() functions return
+     * corrected values.
+     *
+     * If the drift value changes over time, you can call this function once in a while
+     * to follow it. But don't forget to fix the sensor while calibrating!
+     *
+     * @param time The time span to sample and average offset.
+     *             Sampling rate is limited, so giving long time to calibrate will improve
+     *             correction quality.
+     */
+    void calibrate(double time);
+
+protected:
+    /**
+     * An internal method to acquire gyro sensor readings before calibration correction.
+     *
+     * Protected for the time being, although there could be cases that raw values are
+     * appreciated by the user.
+     */
+    void getRawGyroXYZ(int readings[3]);
+
+    /**
+     * Offset values that will be subtracted from output.
+     *
+     * TODO: temperature drift calibration
+     */
+    int offset[3];
 
 private:
 
@@ -374,6 +415,12 @@
 };
 
 
+inline void ITG3200::getGyroXYZ(int readings[3]){
+    getRawGyroXYZ(readings);
+    for(int i = 0; i < 3; i++)
+        readings[i] -= offset[i];
+}
+
 inline void ITG3200::getGyroXYZDegrees(double readings[3]){
     int intData[3];
     getGyroXYZ(intData);