![](/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@9:ef46e12b4560, 2017-08-14 (annotated)
- Committer:
- mbedoguz
- Date:
- Mon Aug 14 14:09:50 2017 +0000
- Revision:
- 9:ef46e12b4560
- Parent:
- 8:b9206956f396
- Child:
- 10:e7fffe32c12c
This is a bluepill(stm32f103) version of MPU9250-dmp library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedoguz | 0:c6daf7016b8c | 1 | #include "SparkFunMPU9250-DMP.h" |
mbedoguz | 2:7be1ac6eb8cb | 2 | #include "mdcompat.h" |
mbedoguz | 9:ef46e12b4560 | 3 | #include "stm32f103c8t6.h" |
mbedoguz | 9:ef46e12b4560 | 4 | //In order to compile, you should define MPU9250 in build macros |
mbedoguz | 8:b9206956f396 | 5 | |
mbedoguz | 9:ef46e12b4560 | 6 | Serial pc(SERIAL_TX,SERIAL_RX); |
mbedoguz | 0:c6daf7016b8c | 7 | DigitalOut led(LED1); |
mbedoguz | 0:c6daf7016b8c | 8 | MPU9250_DMP imu; |
mbedoguz | 4:9d706f783b5a | 9 | unsigned char whoami[1]={0}; |
mbedoguz | 4:9d706f783b5a | 10 | unsigned char fifo_count[2]={32,32}; |
mbedoguz | 4:9d706f783b5a | 11 | unsigned char temp[1]={32}; |
mbedoguz | 4:9d706f783b5a | 12 | unsigned char outbuff[4]; |
mbedoguz | 5:3a9280cea2ff | 13 | unsigned char inbuff[4]; |
mbedoguz | 4:9d706f783b5a | 14 | unsigned char regadd; |
mbedoguz | 5:3a9280cea2ff | 15 | char registeradress[5]; |
mbedoguz | 4:9d706f783b5a | 16 | unsigned char registerdata[]={33}; |
mbedoguz | 4:9d706f783b5a | 17 | void printIMUData(void); |
mbedoguz | 0:c6daf7016b8c | 18 | int main() |
mbedoguz | 0:c6daf7016b8c | 19 | { |
mbedoguz | 0:c6daf7016b8c | 20 | pc.baud(115200); |
mbedoguz | 0:c6daf7016b8c | 21 | pc.printf("Hello World\n"); |
mbedoguz | 4:9d706f783b5a | 22 | imu_init(); |
mbedoguz | 4:9d706f783b5a | 23 | stamper_init(); |
mbedoguz | 5:3a9280cea2ff | 24 | #if 1//Regular program |
mbedoguz | 0:c6daf7016b8c | 25 | // Call imu.begin() to verify communication and initialize |
mbedoguz | 0:c6daf7016b8c | 26 | if (imu.begin() != INV_SUCCESS){ |
mbedoguz | 0:c6daf7016b8c | 27 | while (1){ |
mbedoguz | 0:c6daf7016b8c | 28 | pc.printf("Unable to communicate with MPU-9250"); |
mbedoguz | 0:c6daf7016b8c | 29 | pc.printf("Check connections, and try again.\n"); |
mbedoguz | 0:c6daf7016b8c | 30 | wait_ms(5000); |
mbedoguz | 0:c6daf7016b8c | 31 | } |
mbedoguz | 0:c6daf7016b8c | 32 | } |
mbedoguz | 5:3a9280cea2ff | 33 | pc.printf("imu.begin() suceeded\n"); |
mbedoguz | 4:9d706f783b5a | 34 | |
mbedoguz | 4:9d706f783b5a | 35 | if(imu.dmpBegin(DMP_FEATURE_6X_LP_QUAT | // Enable 6-axis quat |
mbedoguz | 0:c6daf7016b8c | 36 | DMP_FEATURE_GYRO_CAL, // Use gyro calibration |
mbedoguz | 9:ef46e12b4560 | 37 | 10)==INV_ERROR){ // Set DMP FIFO rate to 150 Hz |
mbedoguz | 4:9d706f783b5a | 38 | pc.printf("imu.dmpBegin have failed\n");//dmpLoad function under it fails which is caused by memcmp(firmware+ii, cur, this_write) (it is located at row 2871 of inv_mpu.c) |
mbedoguz | 4:9d706f783b5a | 39 | } |
mbedoguz | 4:9d706f783b5a | 40 | else{ |
mbedoguz | 4:9d706f783b5a | 41 | pc.printf("imu.dmpBegin() suceeded\n"); |
mbedoguz | 4:9d706f783b5a | 42 | } |
mbedoguz | 8:b9206956f396 | 43 | pc.printf("$GETEU,*\n"); |
mbedoguz | 4:9d706f783b5a | 44 | #endif |
mbedoguz | 5:3a9280cea2ff | 45 | #if 0//this scope is only for debugging purposes of mbed_i2c_read and write functions |
mbedoguz | 4:9d706f783b5a | 46 | mbed_i2c_read(0x68,0x75,1,whoami); |
mbedoguz | 4:9d706f783b5a | 47 | pc.printf("whoami=%d\n",whoami[0]); |
mbedoguz | 5:3a9280cea2ff | 48 | mbed_i2c_read(0x68,0x23,2,inbuff); |
mbedoguz | 5:3a9280cea2ff | 49 | pc.printf("Buffer=%d-%d\n",inbuff[0],inbuff[1]); |
mbedoguz | 5:3a9280cea2ff | 50 | outbuff[0]=inbuff[0]&0x01; |
mbedoguz | 5:3a9280cea2ff | 51 | outbuff[1]=inbuff[1]&0x02; |
mbedoguz | 5:3a9280cea2ff | 52 | pc.printf("updated buffer=%d-%d\n",outbuff[0],outbuff[1]); |
mbedoguz | 4:9d706f783b5a | 53 | mbed_i2c_write(0x68,0x23,2,outbuff); |
mbedoguz | 5:3a9280cea2ff | 54 | mbed_i2c_read(0x68,0x23,2,inbuff); |
mbedoguz | 5:3a9280cea2ff | 55 | pc.printf("new out buffer=%d-%d(if zero, write function still needs to be fixed)\n",inbuff[0],inbuff[1]); |
mbedoguz | 4:9d706f783b5a | 56 | #endif |
mbedoguz | 0:c6daf7016b8c | 57 | while(1){ |
mbedoguz | 4:9d706f783b5a | 58 | if(pc.readable()){ |
mbedoguz | 4:9d706f783b5a | 59 | pc.scanf("%s",®isteradress); |
mbedoguz | 4:9d706f783b5a | 60 | regadd=(registeradress[0]-48)*100+(registeradress[1]-48)*10+(registeradress[2]-48); |
mbedoguz | 4:9d706f783b5a | 61 | mbed_i2c_read(0x68,(unsigned)regadd,1,registerdata); |
mbedoguz | 4:9d706f783b5a | 62 | pc.printf("%d is gotten from serial port, data at that register is %d\n",regadd,registerdata[0]); |
mbedoguz | 4:9d706f783b5a | 63 | } |
mbedoguz | 9:ef46e12b4560 | 64 | // Check for new data in the FIFO |
mbedoguz | 9:ef46e12b4560 | 65 | if (imu.fifoAvailable()){//fifo is not being available |
mbedoguz | 9:ef46e12b4560 | 66 | led=0; |
mbedoguz | 9:ef46e12b4560 | 67 | wait_ms(1); |
mbedoguz | 9:ef46e12b4560 | 68 | led=1; |
mbedoguz | 9:ef46e12b4560 | 69 | wait_ms(1); |
mbedoguz | 9:ef46e12b4560 | 70 | // Use dmpUpdateFifo to update the ax, gx, mx, etc. values |
mbedoguz | 9:ef46e12b4560 | 71 | if ( imu.dmpUpdateFifo() == INV_SUCCESS){ |
mbedoguz | 9:ef46e12b4560 | 72 | // computeEulerAngles can be used -- after updating the |
mbedoguz | 9:ef46e12b4560 | 73 | // quaternion values -- to estimate roll, pitch, and yaw |
mbedoguz | 9:ef46e12b4560 | 74 | imu.computeEulerAngles(); |
mbedoguz | 9:ef46e12b4560 | 75 | printIMUData(); |
mbedoguz | 9:ef46e12b4560 | 76 | } |
mbedoguz | 9:ef46e12b4560 | 77 | } |
mbedoguz | 5:3a9280cea2ff | 78 | else{ |
mbedoguz | 9:ef46e12b4560 | 79 | led=0; |
mbedoguz | 0:c6daf7016b8c | 80 | } |
mbedoguz | 0:c6daf7016b8c | 81 | } |
mbedoguz | 0:c6daf7016b8c | 82 | return 0; |
mbedoguz | 0:c6daf7016b8c | 83 | } |
mbedoguz | 0:c6daf7016b8c | 84 | |
mbedoguz | 0:c6daf7016b8c | 85 | void printIMUData(void) |
mbedoguz | 0:c6daf7016b8c | 86 | { |
mbedoguz | 0:c6daf7016b8c | 87 | // After calling dmpUpdateFifo() the ax, gx, mx, etc. values |
mbedoguz | 0:c6daf7016b8c | 88 | // are all updated. |
mbedoguz | 0:c6daf7016b8c | 89 | // Quaternion values are, by default, stored in Q30 long |
mbedoguz | 0:c6daf7016b8c | 90 | // format. calcQuat turns them into a float between -1 and 1 |
mbedoguz | 0:c6daf7016b8c | 91 | float q0 = imu.calcQuat(imu.qw); |
mbedoguz | 0:c6daf7016b8c | 92 | float q1 = imu.calcQuat(imu.qx); |
mbedoguz | 0:c6daf7016b8c | 93 | float q2 = imu.calcQuat(imu.qy); |
mbedoguz | 0:c6daf7016b8c | 94 | float q3 = imu.calcQuat(imu.qz); |
mbedoguz | 0:c6daf7016b8c | 95 | |
mbedoguz | 8:b9206956f396 | 96 | pc.printf("$,%.4lf,%.4lf,%.4lf,*\n", imu.yaw,imu.pitch,imu.roll); |
mbedoguz | 0:c6daf7016b8c | 97 | } |