Unit testing and development for 9DOF sparkfun sensor stick
Dependencies: ADXL345 HMC5883L ITG3200 mbed
main.cpp@0:ac2f55940442, 2012-10-30 (annotated)
- Committer:
- tylerjw
- Date:
- Tue Oct 30 17:30:03 2012 +0000
- Revision:
- 0:ac2f55940442
- Child:
- 1:dc730a26cdc2
0.1 ITG3200 Thermal Drift Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerjw | 0:ac2f55940442 | 1 | /** |
tylerjw | 0:ac2f55940442 | 2 | 10 second 9-dof data log |
tylerjw | 0:ac2f55940442 | 3 | |
tylerjw | 0:ac2f55940442 | 4 | The purpose of this program is to demonstrate and calibrate the three |
tylerjw | 0:ac2f55940442 | 5 | sensors on teh 9-doft board. |
tylerjw | 0:ac2f55940442 | 6 | |
tylerjw | 0:ac2f55940442 | 7 | The first version of this software will test the ITG3200 gyro to find |
tylerjw | 0:ac2f55940442 | 8 | the temperature drift line. Data will be logged to help determine the |
tylerjw | 0:ac2f55940442 | 9 | thermal drift line. |
tylerjw | 0:ac2f55940442 | 10 | See: http://mbed.org/users/gltest26/code/ITG3200/wiki/Thermal-Drift |
tylerjw | 0:ac2f55940442 | 11 | */ |
tylerjw | 0:ac2f55940442 | 12 | |
tylerjw | 0:ac2f55940442 | 13 | #include "mbed.h" |
tylerjw | 0:ac2f55940442 | 14 | #include "ITG3200.h" |
tylerjw | 0:ac2f55940442 | 15 | |
tylerjw | 0:ac2f55940442 | 16 | int main() |
tylerjw | 0:ac2f55940442 | 17 | { |
tylerjw | 0:ac2f55940442 | 18 | DigitalOut myled(p24); |
tylerjw | 0:ac2f55940442 | 19 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
tylerjw | 0:ac2f55940442 | 20 | ITG3200 gyro(p28, p27); // sda, scl - gyro |
tylerjw | 0:ac2f55940442 | 21 | //const float offset[3] = {99.53, -45.26, -29.53}; // taken from itg3200_05.xls curve fit |
tylerjw | 0:ac2f55940442 | 22 | //const float slope[3] = {-0.95, 0.95, 0.47}; |
tylerjw | 0:ac2f55940442 | 23 | |
tylerjw | 0:ac2f55940442 | 24 | //gyro.setCalibrationCurve(offset, slope); |
tylerjw | 0:ac2f55940442 | 25 | //gyro.calibrate(1.0); |
tylerjw | 0:ac2f55940442 | 26 | gyro.setLpBandwidth(LPFBW_5HZ); |
tylerjw | 0:ac2f55940442 | 27 | |
tylerjw | 0:ac2f55940442 | 28 | Serial pc(USBTX, USBRX); |
tylerjw | 0:ac2f55940442 | 29 | |
tylerjw | 0:ac2f55940442 | 30 | pc.baud(9600); |
tylerjw | 0:ac2f55940442 | 31 | |
tylerjw | 0:ac2f55940442 | 32 | myled = 0; |
tylerjw | 0:ac2f55940442 | 33 | FILE *fp = fopen("/local/itg3200.csv", "w"); // Open "itg3200.csv" for writing |
tylerjw | 0:ac2f55940442 | 34 | fputs("Temp, X, Y, Z\r\n", fp); // place the header at the top |
tylerjw | 0:ac2f55940442 | 35 | |
tylerjw | 0:ac2f55940442 | 36 | float temperature = 0.0; |
tylerjw | 0:ac2f55940442 | 37 | int gyro_readings[3]; |
tylerjw | 0:ac2f55940442 | 38 | |
tylerjw | 0:ac2f55940442 | 39 | for(int i = 0; i < 120; i++) { // 120 seconds - 600 samples |
tylerjw | 0:ac2f55940442 | 40 | myled = 1; |
tylerjw | 0:ac2f55940442 | 41 | gyro.calibrate(1.0); |
tylerjw | 0:ac2f55940442 | 42 | //wait(0.5); |
tylerjw | 0:ac2f55940442 | 43 | myled = 0; |
tylerjw | 0:ac2f55940442 | 44 | //gyro.getGyroXYZ(gyro_readings, ITG3200::Calibration); |
tylerjw | 0:ac2f55940442 | 45 | gyro.getOffset(gyro_readings); |
tylerjw | 0:ac2f55940442 | 46 | temperature = gyro.getTemperature(); |
tylerjw | 0:ac2f55940442 | 47 | pc.printf("%3d,%f,%d,%d,%d\r\n",i,temperature,gyro_readings[0],gyro_readings[1],gyro_readings[2]); |
tylerjw | 0:ac2f55940442 | 48 | fprintf(fp, "%f,%d,%d,%d\r\n",temperature,gyro_readings[0],gyro_readings[1],gyro_readings[2]); |
tylerjw | 0:ac2f55940442 | 49 | } |
tylerjw | 0:ac2f55940442 | 50 | fclose(fp); |
tylerjw | 0:ac2f55940442 | 51 | myled = 0; |
tylerjw | 0:ac2f55940442 | 52 | } |