![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluepill version of mpu9250-dmp library of sparkfun
Dependencies: MotionDriver_6_1 SparkFunMPU9250-DMP mbed-STM32F103C8T6 mbed
Fork of MPU9250-dmp by
main.cpp@0:c6daf7016b8c, 2017-08-07 (annotated)
- Committer:
- mbedoguz
- Date:
- Mon Aug 07 13:50:51 2017 +0000
- Revision:
- 0:c6daf7016b8c
- Child:
- 2:7be1ac6eb8cb
It compiles and dmu begins but no data comes, (fifo is not being available)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedoguz | 0:c6daf7016b8c | 1 | /*#include "mbed.h" |
mbedoguz | 0:c6daf7016b8c | 2 | #include "inv_mpu.h" |
mbedoguz | 0:c6daf7016b8c | 3 | #include "mdcompat.h" |
mbedoguz | 0:c6daf7016b8c | 4 | Serial pc(USBTX,USBRX); |
mbedoguz | 0:c6daf7016b8c | 5 | DigitalOut led(LED1); |
mbedoguz | 0:c6daf7016b8c | 6 | int main() |
mbedoguz | 0:c6daf7016b8c | 7 | { |
mbedoguz | 0:c6daf7016b8c | 8 | imu_init(); |
mbedoguz | 0:c6daf7016b8c | 9 | |
mbedoguz | 0:c6daf7016b8c | 10 | while(1){ |
mbedoguz | 0:c6daf7016b8c | 11 | led=1; |
mbedoguz | 0:c6daf7016b8c | 12 | wait_ms(100); |
mbedoguz | 0:c6daf7016b8c | 13 | led=0; |
mbedoguz | 0:c6daf7016b8c | 14 | wait_ms(100); |
mbedoguz | 0:c6daf7016b8c | 15 | } |
mbedoguz | 0:c6daf7016b8c | 16 | }*/ |
mbedoguz | 0:c6daf7016b8c | 17 | |
mbedoguz | 0:c6daf7016b8c | 18 | #include "SparkFunMPU9250-DMP.h" |
mbedoguz | 0:c6daf7016b8c | 19 | |
mbedoguz | 0:c6daf7016b8c | 20 | Serial pc(USBTX,USBRX); |
mbedoguz | 0:c6daf7016b8c | 21 | DigitalOut led(LED1); |
mbedoguz | 0:c6daf7016b8c | 22 | MPU9250_DMP imu; |
mbedoguz | 0:c6daf7016b8c | 23 | long DEBUG[]={2,2,2,2}; |
mbedoguz | 0:c6daf7016b8c | 24 | int main() |
mbedoguz | 0:c6daf7016b8c | 25 | { |
mbedoguz | 0:c6daf7016b8c | 26 | pc.baud(115200); |
mbedoguz | 0:c6daf7016b8c | 27 | pc.printf("Hello World\n"); |
mbedoguz | 0:c6daf7016b8c | 28 | // Call imu.begin() to verify communication and initialize |
mbedoguz | 0:c6daf7016b8c | 29 | pc.printf("imu.begin()is being run\n"); |
mbedoguz | 0:c6daf7016b8c | 30 | if (imu.begin() != INV_SUCCESS){ |
mbedoguz | 0:c6daf7016b8c | 31 | pc.printf("imu.begin() have failed"); |
mbedoguz | 0:c6daf7016b8c | 32 | while (1){ |
mbedoguz | 0:c6daf7016b8c | 33 | pc.printf("Unable to communicate with MPU-9250"); |
mbedoguz | 0:c6daf7016b8c | 34 | pc.printf("Check connections, and try again.\n"); |
mbedoguz | 0:c6daf7016b8c | 35 | wait_ms(5000); |
mbedoguz | 0:c6daf7016b8c | 36 | } |
mbedoguz | 0:c6daf7016b8c | 37 | } |
mbedoguz | 0:c6daf7016b8c | 38 | pc.printf("imu.begin() suceeded\n"); |
mbedoguz | 0:c6daf7016b8c | 39 | imu.dmpBegin(DMP_FEATURE_6X_LP_QUAT | // Enable 6-axis quat |
mbedoguz | 0:c6daf7016b8c | 40 | DMP_FEATURE_GYRO_CAL, // Use gyro calibration |
mbedoguz | 0:c6daf7016b8c | 41 | 20); // Set DMP FIFO rate to 20 Hz |
mbedoguz | 0:c6daf7016b8c | 42 | // DMP_FEATURE_LP_QUAT can also be used. It uses the |
mbedoguz | 0:c6daf7016b8c | 43 | // accelerometer in low-power mode to estimate quat's. |
mbedoguz | 0:c6daf7016b8c | 44 | // DMP_FEATURE_LP_QUAT and 6X_LP_QUAT are mutually exclusive |
mbedoguz | 0:c6daf7016b8c | 45 | pc.printf("imu.dmpBegin() suceeded\n"); |
mbedoguz | 0:c6daf7016b8c | 46 | |
mbedoguz | 0:c6daf7016b8c | 47 | while(1){ |
mbedoguz | 0:c6daf7016b8c | 48 | // Check for new data in the FIFO |
mbedoguz | 0:c6daf7016b8c | 49 | led=1; |
mbedoguz | 0:c6daf7016b8c | 50 | wait_ms(500); |
mbedoguz | 0:c6daf7016b8c | 51 | led=0; |
mbedoguz | 0:c6daf7016b8c | 52 | wait_ms(500); |
mbedoguz | 0:c6daf7016b8c | 53 | if ( imu.fifoAvailable() ){//fifo is not being available |
mbedoguz | 0:c6daf7016b8c | 54 | led=0; |
mbedoguz | 0:c6daf7016b8c | 55 | wait_ms(100); |
mbedoguz | 0:c6daf7016b8c | 56 | led=1; |
mbedoguz | 0:c6daf7016b8c | 57 | wait_ms(100); |
mbedoguz | 0:c6daf7016b8c | 58 | // Use dmpUpdateFifo to update the ax, gx, mx, etc. values |
mbedoguz | 0:c6daf7016b8c | 59 | if ( imu.dmpUpdateFifo(DEBUG) == INV_SUCCESS){ |
mbedoguz | 0:c6daf7016b8c | 60 | // computeEulerAngles can be used -- after updating the |
mbedoguz | 0:c6daf7016b8c | 61 | // quaternion values -- to estimate roll, pitch, and yaw |
mbedoguz | 0:c6daf7016b8c | 62 | imu.computeEulerAngles(); |
mbedoguz | 0:c6daf7016b8c | 63 | //printIMUData(); |
mbedoguz | 0:c6daf7016b8c | 64 | #if 1 |
mbedoguz | 0:c6daf7016b8c | 65 | pc.printf("%lf",DEBUG[0]); |
mbedoguz | 0:c6daf7016b8c | 66 | pc.printf("\t"); |
mbedoguz | 0:c6daf7016b8c | 67 | pc.printf("%lf",DEBUG[1]); |
mbedoguz | 0:c6daf7016b8c | 68 | pc.printf("\t"); |
mbedoguz | 0:c6daf7016b8c | 69 | pc.printf("%lf",DEBUG[2]); |
mbedoguz | 0:c6daf7016b8c | 70 | pc.printf("\t"); |
mbedoguz | 0:c6daf7016b8c | 71 | pc.printf("%lf\n ",DEBUG[3]); |
mbedoguz | 0:c6daf7016b8c | 72 | #endif |
mbedoguz | 0:c6daf7016b8c | 73 | } |
mbedoguz | 0:c6daf7016b8c | 74 | } |
mbedoguz | 0:c6daf7016b8c | 75 | } |
mbedoguz | 0:c6daf7016b8c | 76 | return 0; |
mbedoguz | 0:c6daf7016b8c | 77 | } |
mbedoguz | 0:c6daf7016b8c | 78 | |
mbedoguz | 0:c6daf7016b8c | 79 | void printIMUData(void) |
mbedoguz | 0:c6daf7016b8c | 80 | { |
mbedoguz | 0:c6daf7016b8c | 81 | // After calling dmpUpdateFifo() the ax, gx, mx, etc. values |
mbedoguz | 0:c6daf7016b8c | 82 | // are all updated. |
mbedoguz | 0:c6daf7016b8c | 83 | // Quaternion values are, by default, stored in Q30 long |
mbedoguz | 0:c6daf7016b8c | 84 | // format. calcQuat turns them into a float between -1 and 1 |
mbedoguz | 0:c6daf7016b8c | 85 | float q0 = imu.calcQuat(imu.qw); |
mbedoguz | 0:c6daf7016b8c | 86 | float q1 = imu.calcQuat(imu.qx); |
mbedoguz | 0:c6daf7016b8c | 87 | float q2 = imu.calcQuat(imu.qy); |
mbedoguz | 0:c6daf7016b8c | 88 | float q3 = imu.calcQuat(imu.qz); |
mbedoguz | 0:c6daf7016b8c | 89 | |
mbedoguz | 0:c6daf7016b8c | 90 | pc.printf("R:%lf P:%lf Y:%lf \n", imu.roll,imu.pitch,imu.yaw); |
mbedoguz | 0:c6daf7016b8c | 91 | } |