Unit testing and development for 9DOF sparkfun sensor stick

Dependencies:   ADXL345 HMC5883L ITG3200 mbed

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Tue Nov 06 19:06:58 2012 +0000
Parent:
3:5e21a352e236
Child:
5:63b115f85aa7
Commit message:
sample time test

Changed in this revision

ADXL345.lib Show annotated file Show diff for this revision Revisions of this file
HMC5883L.lib Show annotated file Show diff for this revision Revisions of this file
ITG3200.lib Show annotated file Show diff for this revision Revisions of this file
adxl345unit.cpp Show annotated file Show diff for this revision Revisions of this file
adxl345unit.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ADXL345.lib	Mon Nov 05 18:35:42 2012 +0000
+++ b/ADXL345.lib	Tue Nov 06 19:06:58 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/tylerjw/code/ADXL345/#4cdd4315189f
+http://mbed.org/users/tylerjw/code/ADXL345/#d81793e01ec4
--- a/HMC5883L.lib	Mon Nov 05 18:35:42 2012 +0000
+++ b/HMC5883L.lib	Tue Nov 06 19:06:58 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/tylerjw/code/HMC5883L/#8eb755577f83
+http://mbed.org/users/tylerjw/code/HMC5883L/#bc4e1201e092
--- a/ITG3200.lib	Mon Nov 05 18:35:42 2012 +0000
+++ b/ITG3200.lib	Tue Nov 06 19:06:58 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/tylerjw/code/ITG3200/#9a354f34d8e3
+http://mbed.org/users/tylerjw/code/ITG3200/#e886466d7d67
--- a/adxl345unit.cpp	Mon Nov 05 18:35:42 2012 +0000
+++ b/adxl345unit.cpp	Tue Nov 06 19:06:58 2012 +0000
@@ -188,14 +188,14 @@
     open_file_ = 0;
 }
 
-bool ADXL345UNIT::methodTest()
-{
+//void ADXL345UNIT::sampleTimeTest()
+//{
     // constructors and size of obj tests
     // destructor test
     // get device id [0xE5]
     // set power mode > get bw rate
     //
-}
+//}
 
 int16_t ADXL345UNIT::arr_avg(int16_t* arr,int16_t length)
 {
@@ -212,7 +212,7 @@
     for(int sample = 0; sample < 100; sample++) {
         start_time = t->read();
 
-        adxl345_.getOutput(buffer[sample]);
+        adxl345_.getXYZ(buffer[sample]);
 
         wait(period - (start_time - t->read()));
     }
--- a/adxl345unit.h	Mon Nov 05 18:35:42 2012 +0000
+++ b/adxl345unit.h	Tue Nov 06 19:06:58 2012 +0000
@@ -51,7 +51,7 @@
         * Perform built in self test and print results to BIST.csv
         * Raw data is printed to BIST_RAW.csv
         *
-        * NOT YET TESTED
+        * Working
         *
         * @param store_raw true to store raw data
         * @returns test result: true if passed, false if failed
@@ -61,23 +61,14 @@
         /**
         * Performs the offset callibration test and prints to OFF_CAL.csv
         *
-        * NOT YET TESTED
+        * Working
         *
-        * TODO: implement into ADXL345 class.
+        * Implemented in ADXL345 class
         *
         * @param store_raw true to store raw data
         */
         void offsetCalibration(bool);
         
-        /**
-        * Tests the method of ADXL345 library
-        * 
-        * Results stored in method.txt
-        *
-        * @returns test result, true if passed, false if not
-        */
-        bool methodTest();
-        
     private:
         ADXL345 adxl345_;
         Serial pc_;
--- a/main.cpp	Mon Nov 05 18:35:42 2012 +0000
+++ b/main.cpp	Tue Nov 06 19:06:58 2012 +0000
@@ -15,28 +15,67 @@
 */
 
 #include "mbed.h"
-//#include "ITG3200.h"
-//#include "HMC5883L.h"
-#include "adxl345unit.h"
+#include "ITG3200.h"
+#include "HMC5883L.h"
+#include "ADXL345.h"
+//#include "adxl345unit.h"
 
 I2C i2c_bus(p28, p27);
 ADXL345 accel(i2c_bus);
+HMC5883L magno(i2c_bus);
+ITG3200 gyro(i2c_bus);
 Timer t;
 Serial pc(USBTX, USBRX);
 //ADXL345UNIT accel_test(i2c_bus, t);
 
+void sample_time_test();
+
 int main()
 {
+    sample_time_test();
+}
+
+void sample_time_test()
+{
+    int16_t accel_sample[3];
+    int16_t magno_sample[3];
+    int16_t gyro_sample[3];
+    double temperature;
+    double heading_rad, heading_deg;
+    wait(0.5); // enough time for everything to prepare a sample
     t.start();
+    double accel_time, magno_time, gyro_time, temp_time, head_rad_time, head_deg_time;
     pc.baud(9600);
-    accel.calibrate(&t, true);
-    //accel_test.builtInSelfTest(true);
-    //accel_test.offsetCalibration(true);
-/*
-    int sample[3];
+    
+    pc.printf("accel,magno,gyro,temp,head_rad,head_deg\r\n");
+    for(int i = 0; i < 100; i++)
+    {
+        t.reset();
+        accel.getXYZ(accel_sample);
+        accel_time = t.read();
+        magno.getXYZ(magno_sample);
+        magno_time = t.read();
+        gyro.getXYZ(gyro_sample, ITG3200::Calibration);
+        gyro_time = t.read();
+        temperature = gyro.getTemperature();
+        temp_time = t.read();
+        heading_rad = magno.getHeadingXY();
+        head_rad_time = t.read();
+        heading_deg = magno.getHeadingXYDeg();
+        head_deg_time = t.read();
+        
+        pc.printf("%f,%f,%f,%f,%f,%f\r\n",accel_time,magno_time,gyro_time,temp_time,head_rad_time,head_deg_time);
+        
+        wait(0.2 - t.read());
+    }
+}
+
+void ADXL345_test()
+{
+    int16_t sample[3];
     float elapsed_time;
     float time_stamp[100];
-    int samples[100][3];
+    int16_t samples[100][3];
 
     Timer t;
     Serial pc(USBTX, USBRX);
@@ -49,7 +88,7 @@
     wait(0.001);
 
     t.start();
-    accel.getOutput(sample);
+    accel.getXYZ(sample);
     elapsed_time = t.read();
 
     pc.printf("Sample took %f seconds.\r\n", elapsed_time);
@@ -57,17 +96,15 @@
 
     for(int i = 0; i < 100; i++) {
         t.reset();
-        accel.getOutput(samples[i]);
+        accel.getXYZ(samples[i]);
         time_stamp[i] = t.read();
     }
     for(int i = 0; i < 100; i++) {
         pc.printf("Sample took %f seconds.\r\n", time_stamp[i]);
         pc.printf("x: %d, y: %d, z: %d\r\n", samples[i][0],samples[i][1],samples[i][2]);
     }
-    */
 }
 
-/*
 void hmc5883l_test()
 {
     Serial pc(USBTX, USBRX);
@@ -76,7 +113,7 @@
 
     HMC5883L compass(i2c_bus);
 
-    int data[3];
+    int16_t data[3];
 
     while(1) {
         compass.getXYZ(data);
@@ -84,9 +121,8 @@
         wait(0.067);
     }
 }
-*/
-/*
-void itg3200_test()
+
+void itg3200_curve_test()
 {
     DigitalOut myled(LED1);
     LocalFileSystem local("local");               // Create the local filesystem under the name "local"
@@ -106,14 +142,14 @@
     fputs("Temp, X, Y, Z\r\n", fp);               // place the header at the top
 
     float temperature = 0.0;
-    int gyro_readings[3];
+    int16_t gyro_readings[3];
 
     for(int i = 0; i < 120; i++) { // 120 seconds - 600 samples
         myled = 1;
         //gyro.calibrate(1.0);
         wait(0.5);
         myled = 0;
-        gyro.getGyroXYZ(gyro_readings, ITG3200::Calibration);
+        gyro.getXYZ(gyro_readings, ITG3200::Calibration);
         //gyro.getOffset(gyro_readings);
         temperature = gyro.getTemperature();
         pc.printf("%3d,%f,%d,%d,%d\r\n",i,temperature,gyro_readings[0],gyro_readings[1],gyro_readings[2]);
@@ -122,4 +158,3 @@
     fclose(fp);
     myled = 0;
 }
-*/
\ No newline at end of file