A basic eCompass using mbed-RTOS
Dependencies: C12832 FXOS8700Q eCompass_FPU_Lib mbed-rtos mbed
Revision 1:2d2270d1a5f5, committed 2014-05-07
- Comitter:
- JimCarver
- Date:
- Wed May 07 18:09:44 2014 +0000
- Parent:
- 0:2126a25ea273
- Commit message:
- Improved version which requires no modification to RTOS
Changed in this revision
diff -r 2126a25ea273 -r 2d2270d1a5f5 FXOS8700Q.lib --- a/FXOS8700Q.lib Mon May 05 17:46:15 2014 +0000 +++ b/FXOS8700Q.lib Wed May 07 18:09:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/JimCarver/code/FXOS8700Q/#52116f8fb3da +http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
diff -r 2126a25ea273 -r 2d2270d1a5f5 main.cpp --- a/main.cpp Mon May 05 17:46:15 2014 +0000 +++ b/main.cpp Wed May 07 18:09:44 2014 +0000 @@ -4,16 +4,7 @@ #include "rtos.h" #include "C12832.h" -/* - * - * Changes which must be made to default rtos settings: - * Default scheduler stack size changed to 2048 for target K64F (RTX_Conf_CM.h, line 66) - * Default stack size changed to 1024 words for ARMCC Compiler (cmsis_os.h, line 121) - * The Timer Thread must run at Real Time priority (RTX_Conf_CM.c, line 182) - * - */ -extern Thread osTimerThread; FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); eCompass compass; @@ -39,24 +30,24 @@ Thread *(calibrate); Thread *(lcdp); +// This HAL map is for the FXOS8700Q on the K64F Freedom board. void hal_map( MotionSensorDataCounts * acc_raw, MotionSensorDataCounts * mag_raw) { int16_t t; -// swap and negate X & Y axis +// swap and negate accelerometer X & Y axis t = acc_raw->x; acc_raw->x = acc_raw->y * -1; acc_raw->y = t * -1; -// swap mag X & Y axis +// swap magnetometer X & Y axis t = mag_raw->x; mag_raw->x = mag_raw->y; mag_raw->y = t; -// negate mag Z axis +// negate magnetometer Z axis mag_raw->z *= -1; } void compass_thread(void const *argument) { - //osTimerThread.set_priority(osPriorityRealtime); // get raw data from the sensors green = 0; acc.getAxis( acc_raw); @@ -72,19 +63,18 @@ } tcount++; green = 1; - //osTimerThread.set_priority(osPriorityNormal); } void debug_print(void) { // Some useful printf statements for debug printf("roll=%d, pitch=%d, yaw=%d\r\n", axis6.roll, axis6.pitch, axis6.yaw); - //printf("Acc: X= %d Y= %d Z= %d ", acc_raw.x, acc_raw.y, acc_raw.z); - //printf("Mag: X= %d Y= %d Z= %d\r\n", mag_raw.x, mag_raw.y, mag_raw.z); + printf("Acc: X= %d Y= %d Z= %d ", acc_raw.x, acc_raw.y, acc_raw.z); + printf("Mag: X= %d Y= %d Z= %d\r\n", mag_raw.x, mag_raw.y, mag_raw.z); 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\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("Tcount= %d\r\n", tcount); + printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3); + printf("Tcount= %d\r\n\n\n", tcount); } void calibrate_thread(void const *argument) { @@ -111,13 +101,13 @@ while (true) { // Signal flags that are reported as event are automatically cleared. Thread::signal_wait(0x4); - red = 0; + //red = 0; h = seconds / 3600; m = (seconds % 3600) / 60; s = seconds % 60; lcd.locate(0,1); lcd.printf("K64F eCompass\nRunTime %02d:%02d:%02d\nRoll: %03d Pitch: %02d Yaw: %03d ", h, m, s, axis6.roll, axis6.pitch, axis6.yaw); - red = 1; + //red = 1; } } @@ -144,15 +134,15 @@ compass_timer.start(20); /* * Thread Priorities - * Compass THread, Real Time (Highest) - * Compass calibration, High Priority - * LED Update, Above Normal - * Pprintf to console, Normal + * Compass Thread, High Priority + * Compass calibration, Above Normal + * LED Update, Normal + * printf to console, Below Normal * main(), Normal */ - debugp->set_priority(osPriorityNormal); - lcdp->set_priority(osPriorityAboveNormal); - calibrate->set_priority(osPriorityHigh); + debugp->set_priority(osPriorityBelowNormal); + lcdp->set_priority(osPriorityNormal); + calibrate->set_priority(osPriorityAboveNormal); green = 1; while (true) { Thread::wait(osWaitForever);
diff -r 2126a25ea273 -r 2d2270d1a5f5 mbed.bld --- a/mbed.bld Mon May 05 17:46:15 2014 +0000 +++ b/mbed.bld Wed May 07 18:09:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776 \ No newline at end of file