MPU-9250 with Kalman Filter
Dependencies: ADXL362-helloworld MPU9250_SPI mbed
Fork of ADXL362-helloworld by
Revision 7:758a94e02aa7, committed 2016-06-17
- Comitter:
- mfurukawa
- Date:
- Fri Jun 17 05:31:40 2016 +0000
- Parent:
- 6:ea0804dc7cae
- Child:
- 8:03f9b5289083
- Commit message:
- stable (allread)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jun 17 05:16:13 2016 +0000 +++ b/main.cpp Fri Jun 17 05:31:40 2016 +0000 @@ -33,9 +33,13 @@ imu[0] = new mpu9250_spi(spi, p8); imu[1] = new mpu9250_spi(spi, p9); - int i=0; + for(int i=0;i<2;i++){ - if(imu[i]->init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250 + imu[0]->deselect(); + imu[1]->deselect(); + imu[i]->select(); + + if(imu[i]->init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250 printf("\nCouldn't initialize MPU9250 via SPI!"); } printf("\nWHOAMI=0x%2x\n",imu[i]->whoami()); //output the I2C address to know if SPI is working, it should be 104 @@ -47,18 +51,26 @@ printf("AK8963 WHIAM=0x%2x\n",imu[i]->AK8963_whoami()); wait(0.1); imu[i]->AK8963_calib_Magnetometer(); - - while(1) { - //myled = 1; - wait(0.1); - /* - imu[i]->read_temp(); - imu[i]->read_acc(); - imu[i]->read_rot(); - imu[i]->AK8963_read_Magnetometer(); - */ + } + imu[0]->select(); + imu[1]->deselect(); + while(1) { + + + //myled = 1; + wait_us(1); + /* + imu[i]->read_temp(); + imu[i]->read_acc(); + imu[i]->read_rot(); + imu[i]->AK8963_read_Magnetometer(); + */ + for(int i=0;i<2;i++){ + imu[0]->deselect(); + imu[1]->deselect(); + imu[i]->select(); imu[i]->read_all(); - printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n", + printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f ", imu[i]->Temperature, imu[i]->gyroscope_data[0], imu[i]->gyroscope_data[1], @@ -70,34 +82,9 @@ imu[i]->Magnetometer[1], imu[i]->Magnetometer[2] ); - //myled = 0; - //wait(0.5); + //myled = 0; + //wait(0.5); } - - /* - uint64_t xyzt[6]; - short xi[6],yi[6],zi[6]; - - while(1) { - - - for (int i=0; i<6; i++) - xyzt[i] = adxl362[i]->scan(); - - for (int i=0; i<6; i++) { - uint16_t x = static_cast<uint16_t>(0xFFFF&(xyzt[i]>>48)); - uint16_t y = static_cast<uint16_t>(0xFFFF&(xyzt[i]>>32)); - uint16_t z = static_cast<uint16_t>(0xFFFF&(xyzt[i]>>16)); - - if(x & 1<<16) xi[i] = -1 * static_cast<short>(~x) + 1; else xi[i] = x; - if(y & 1<<16) yi[i] = -1 * static_cast<short>(~y) + 1; else yi[i] = y; - if(z & 1<<16) zi[i] = -1 * static_cast<short>(~z) + 1; else zi[i] = z; - } - for (int i=0; i<6; i++) { - printf("%d %d %d ", xi[i], yi[i], zi[i]); - } - printf("\r\n"); - wait_us(1); + printf("\n"); } - */ }