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。
Diff: ITG3200.cpp
- Revision:
- 6:a7ad6046824c
- Parent:
- 5:0a0315f0f34e
- Child:
- 7:43b936a53b64
--- 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; } }