This program uses the MMA8451 & MAG3110 on a KL-46 freedom board to implement a tilt compensated eCompass with the heading displayed on the LCD. This program uses the mbed RTOS to manage the hard real time requirements of the eCompass algorithm
Dependencies: MAG3110 MMA8451Q SLCD eCompass_Lib mbed-rtos mbed
Diff: main.cpp
- Revision:
- 4:ba1dbfb683fb
- Parent:
- 3:0770c275e6e8
diff -r 0770c275e6e8 -r ba1dbfb683fb main.cpp --- a/main.cpp Fri May 16 18:23:32 2014 +0000 +++ b/main.cpp Sun May 18 15:59:34 2014 +0000 @@ -36,11 +36,16 @@ // void debug_print(void) { + int h, m, s; + h = seconds / 3600; + m = (seconds % 3600) / 60; + s = seconds % 60; // Some useful printf statements for debug + printf("Runtime= %d:%02d:%02d\r\n", h, m, s); printf("roll=%d, pitch=%d, yaw=%d\r\n", axis6.roll, axis6.pitch, axis6.yaw); printf("Acc: X= %2.3f Y= %2.3f Z= %2.3f ", axis6.fGax, axis6.fGay, axis6.fGaz); printf("Mag: X= %4.1f Y= %4.1f Z= %4.1f\r\n", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz); - printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n\r\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3); + printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3); } // HAL Map for KL46 Freedom board MMA8451Q & MAG3110 sensors // @@ -86,7 +91,9 @@ void calibrate_thread(void const *argument) { while(true) { Thread::signal_wait(0x2); + red = 0; compass.calibrate(); + red = 1; } } @@ -125,9 +132,7 @@ lcdp = &t3; mag.enable(); acc.enable(); - // make sure our sensors are talking to us - // Only available when multi-sensor shield is installed - //printf("\r\nFXOS8700 ID= %X\r\n", combo0.getWhoAmI()); + // Say hello to our sensors // Native KL46-FRDM sensors printf("\r\nMMA8451Q ID= %X\r\n", acc.whoAmI()); printf("MAG3110 ID= %X\r\n", mag.whoAmI()); @@ -146,7 +151,7 @@ debugp->set_priority(osPriorityBelowNormal); lcdp->set_priority(osPriorityLow); calibrate->set_priority(osPriorityAboveNormal); - compass_timer.start(20); // Run the Compass every 20ms + Thread::wait(osWaitForever); }