Code to demo/test out my IMU board
Dependencies: mbed ITG3200_lib HMC5843_lib
main.cpp@0:57375160cf48, 2011-02-22 (annotated)
- Committer:
- atommota
- Date:
- Tue Feb 22 23:50:00 2011 +0000
- Revision:
- 0:57375160cf48
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
atommota | 0:57375160cf48 | 1 | #include "mbed.h" |
atommota | 0:57375160cf48 | 2 | #include "LIS331.h" |
atommota | 0:57375160cf48 | 3 | #include "ITG3200.h" |
atommota | 0:57375160cf48 | 4 | #include "HMC5843.h" |
atommota | 0:57375160cf48 | 5 | //#include "SDHCFileSystem.h" |
atommota | 0:57375160cf48 | 6 | |
atommota | 0:57375160cf48 | 7 | // Define binary expansions if needed |
atommota | 0:57375160cf48 | 8 | //#define Ob(x) ((unsigned)Ob_(0 ## x ## uL)) |
atommota | 0:57375160cf48 | 9 | //#define Ob_(x) (x & 1 | x >> 2 & 2 | x >> 4 & 4 | x >> 6 & 8 | \ |
atommota | 0:57375160cf48 | 10 | // x >> 8 & 16 | x >> 10 & 32 | x >> 12 & 64 | x >> 14 & 128) |
atommota | 0:57375160cf48 | 11 | |
atommota | 0:57375160cf48 | 12 | |
atommota | 0:57375160cf48 | 13 | |
atommota | 0:57375160cf48 | 14 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); |
atommota | 0:57375160cf48 | 15 | Serial pc(USBTX, USBRX); |
atommota | 0:57375160cf48 | 16 | LIS331 accel(p9, p10); |
atommota | 0:57375160cf48 | 17 | ITG3200 gyro(p9, p10); |
atommota | 0:57375160cf48 | 18 | HMC5843 compass(p9, p10); |
atommota | 0:57375160cf48 | 19 | Timer t; |
atommota | 0:57375160cf48 | 20 | DigitalOut success_led(LED4); |
atommota | 0:57375160cf48 | 21 | DigitalOut progress_led(LED3); |
atommota | 0:57375160cf48 | 22 | DigitalOut error_led(LED1); |
atommota | 0:57375160cf48 | 23 | |
atommota | 0:57375160cf48 | 24 | int readings[3]; |
atommota | 0:57375160cf48 | 25 | |
atommota | 0:57375160cf48 | 26 | int main() { |
atommota | 0:57375160cf48 | 27 | success_led = 0; |
atommota | 0:57375160cf48 | 28 | error_led = 0; |
atommota | 0:57375160cf48 | 29 | pc.printf("Now starting LIS331/ITG-3200 acceptance test...\n\r"); |
atommota | 0:57375160cf48 | 30 | |
atommota | 0:57375160cf48 | 31 | // Set Highest Gyro Bandwidth |
atommota | 0:57375160cf48 | 32 | gyro.setLpBandwidth(LPFBW_256HZ); |
atommota | 0:57375160cf48 | 33 | |
atommota | 0:57375160cf48 | 34 | // Set 8g range on accel |
atommota | 0:57375160cf48 | 35 | accel.setFullScaleRange8g(); |
atommota | 0:57375160cf48 | 36 | |
atommota | 0:57375160cf48 | 37 | //Continuous mode, , 10Hz measurement rate. |
atommota | 0:57375160cf48 | 38 | // HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA |
atommota | 0:57375160cf48 | 39 | compass.setDefault(); |
atommota | 0:57375160cf48 | 40 | |
atommota | 0:57375160cf48 | 41 | //FILE *fp = fopen("/sd/data.txt", "w"); |
atommota | 0:57375160cf48 | 42 | //if(fp == NULL) { |
atommota | 0:57375160cf48 | 43 | // error_led = 1; // crap something went wrong |
atommota | 0:57375160cf48 | 44 | // error("Could not open file for write\n"); |
atommota | 0:57375160cf48 | 45 | //} |
atommota | 0:57375160cf48 | 46 | //success_led = 1; // file is open for writing! |
atommota | 0:57375160cf48 | 47 | |
atommota | 0:57375160cf48 | 48 | |
atommota | 0:57375160cf48 | 49 | pc.printf("Accel Address:%x\n\r",accel.getWhoAmI()); |
atommota | 0:57375160cf48 | 50 | pc.printf("Gyro Address:%x\n\r",gyro.getWhoAmI()); |
atommota | 0:57375160cf48 | 51 | pc.printf("Temp(C):%f\n\r",gyro.getTemperature()); |
atommota | 0:57375160cf48 | 52 | |
atommota | 0:57375160cf48 | 53 | wait(0.9); |
atommota | 0:57375160cf48 | 54 | |
atommota | 0:57375160cf48 | 55 | |
atommota | 0:57375160cf48 | 56 | |
atommota | 0:57375160cf48 | 57 | |
atommota | 0:57375160cf48 | 58 | t.start(); // Start our timer |
atommota | 0:57375160cf48 | 59 | while (1) { |
atommota | 0:57375160cf48 | 60 | progress_led = 1; |
atommota | 0:57375160cf48 | 61 | //Arbitrary wait for printf clarity. |
atommota | 0:57375160cf48 | 62 | wait(0.3); |
atommota | 0:57375160cf48 | 63 | compass.readData(readings); |
atommota | 0:57375160cf48 | 64 | |
atommota | 0:57375160cf48 | 65 | |
atommota | 0:57375160cf48 | 66 | pc.printf("\n\r%f,", t.read()); // get current time in seconds |
atommota | 0:57375160cf48 | 67 | pc.printf("%f,%f,%f,", (float)accel.getAccelX(), (float)accel.getAccelY(), (float)accel.getAccelZ()); |
atommota | 0:57375160cf48 | 68 | pc.printf("%f,%f,%f", (float)gyro.getGyroX() / 14.375, (float)gyro.getGyroY() / 14.375, (float)gyro.getGyroZ() / 14.375); |
atommota | 0:57375160cf48 | 69 | |
atommota | 0:57375160cf48 | 70 | // uncomment next line to enable output of mag values |
atommota | 0:57375160cf48 | 71 | //pc.printf(",%i,%i,%i", (int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2]); |
atommota | 0:57375160cf48 | 72 | |
atommota | 0:57375160cf48 | 73 | progress_led = 0; |
atommota | 0:57375160cf48 | 74 | if (t.read() > 240) { // quit after 240 seconds, change it to however long you want to record for |
atommota | 0:57375160cf48 | 75 | break; // LED3 will remain off when done writing to card |
atommota | 0:57375160cf48 | 76 | } |
atommota | 0:57375160cf48 | 77 | } |
atommota | 0:57375160cf48 | 78 | |
atommota | 0:57375160cf48 | 79 | wait(0.5); |
atommota | 0:57375160cf48 | 80 | |
atommota | 0:57375160cf48 | 81 | // fclose(fp); // Need to add Physical_Switch --> DigitalIn --> Int --> fclose() |
atommota | 0:57375160cf48 | 82 | } |