Forked from Aaron Berk's ITG3200 driver class library, customized for my specific application using 9DoF-Stick by Sparkfun.
Fork of ITG3200 by
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 9:05396b551a9a, committed 2012-10-02
- Comitter:
- gltest26
- Date:
- Tue Oct 02 18:04:13 2012 +0000
- Parent:
- 8:ac0365ab3cef
- Commit message:
- Added support for calibration curve on chip temperature.
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 |
diff -r ac0365ab3cef -r 05396b551a9a ITG3200.cpp --- a/ITG3200.cpp Tue Oct 02 17:09:20 2012 +0000 +++ b/ITG3200.cpp Tue Oct 02 18:04:13 2012 +0000 @@ -68,6 +68,17 @@ } +void ITG3200::setCalibrationCurve(const float offset[3], const float slope[3]){ + if(offset){ + for(int i = 0; i < 3; i++) + this->foffset[i] = offset[i]; + } + if(slope){ + for(int i = 0; i < 3; i++) + this->slope[i] = slope[i]; + } +} + char ITG3200::getWhoAmI(void){ //WhoAmI Register address. @@ -242,6 +253,24 @@ readings[i] = swapExtend(&rx[i * 2]); } +void ITG3200::getGyroXYZ(int readings[3], Correction corr){ + getRawGyroXYZ(readings); + switch(corr){ + case OffsetCorrection: + for(int i = 0; i < 3; i++) + readings[i] -= offset[i]; + break; + case Calibration: + { + float temp = getTemperature(); + for(int i = 0; i < 3; i++) + readings[i] -= slope[i] * temp + foffset[i]; + } + break; + } +} + + char ITG3200::getPowerManagement(void){ char tx = PWR_MGM_REG;
diff -r ac0365ab3cef -r 05396b551a9a ITG3200.h --- a/ITG3200.h Tue Oct 02 17:09:20 2012 +0000 +++ b/ITG3200.h Tue Oct 02 18:04:13 2012 +0000 @@ -95,6 +95,21 @@ * the library takes care of it. We just always clear the LSB. */ static const int I2C_ADDRESS = 0xD0; + + /** + * @brief Zero offset correction mode that can be specified when calling getGyroXYZ(). + * + * 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 + * must have calibration curves for each axes to do so. + * Here are the options on how to correct the drift. + */ + enum Correction{ + NoCorrection, ///< Do not correct zero offset at all; You would have trouble integrating the values to obtain rotation. + OffsetCorrection, ///< Correct the outputs with single-point zero adjust. + Calibration, ///< Use calibration curve (actually lines) to correct the outputs. You must provide coefficients with setCalibrationCurve(). + Num_Correction + }; /** * Constructor. @@ -119,6 +134,14 @@ ~ITG3200(); void init(); + + /** + * Sets calibration curve parameters. + * + * @param offset An array holding calibration curve offsets (0th-order coefficient) for each axis, must have 3 elements. + * @param slope An array holding calibration curve slopes (1st-order coefficient) for each axis, must have 3 elements. + */ + void setCalibrationCurve(const float offset[3], const float slope[3]); /** * Get the identity of the device. @@ -298,24 +321,25 @@ * 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. + * @param corr Correction method for returned values. */ - void getGyroXYZ(int readings[3], bool subtractOffset = true); + void getGyroXYZ(int readings[3], Correction corr = OffsetCorrection); /** * 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 corr Correction method for returned values. */ - void getGyroXYZDegrees(double readings[3]); + void getGyroXYZDegrees(double readings[3], Correction corr = OffsetCorrection); /** * 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. + * @param corr Correction method for returned values. */ - void getGyroXYZRadians(double readings[3], bool subtractOffset = true); + void getGyroXYZRadians(double readings[3], Correction corr = OffsetCorrection); /** * Get the power management configuration. @@ -455,6 +479,9 @@ */ int offset[3]; + float foffset[3]; + float slope[3]; + long calibSamples; private: @@ -485,24 +512,16 @@ }; -inline void ITG3200::getGyroXYZ(int readings[3], bool subtractOffset){ - getRawGyroXYZ(readings); - if(subtractOffset){ - for(int i = 0; i < 3; i++) - readings[i] -= offset[i]; - } -} - -inline void ITG3200::getGyroXYZDegrees(double readings[3]){ +inline void ITG3200::getGyroXYZDegrees(double readings[3], Correction corr){ int intData[3]; - getGyroXYZ(intData); + getGyroXYZ(intData, corr); for(int i = 0; i < 3; i++) readings[i] = intData[i] * 2000. / 32767.; } -inline void ITG3200::getGyroXYZRadians(double readings[3], bool subtractOffset){ +inline void ITG3200::getGyroXYZRadians(double readings[3], Correction corr){ int intData[3]; - getGyroXYZ(intData, subtractOffset); + getGyroXYZ(intData, corr); for(int i = 0; i < 3; i++) readings[i] = intData[i] * 2000. / 32767. * 2. * M_PI / 360.; }