九軸の制御

Dependencies:   mbed

Fork of MPU9250AHRS by Kris Winer

Files at this revision

API Documentation at this revision

Comitter:
kurikuri
Date:
Fri Jul 13 07:55:27 2018 +0000
Parent:
2:4e59a37182df
Commit message:
Kp-9250??;

Changed in this revision

MPU9250.h Show annotated file Show diff for this revision Revisions of this file
N5110.lib Show diff for this revision Revisions of this file
ST_401_84MHZ.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4e59a37182df -r 51217f251b8d MPU9250.h
--- a/MPU9250.h	Tue Aug 05 01:37:23 2014 +0000
+++ b/MPU9250.h	Fri Jul 13 07:55:27 2018 +0000
@@ -190,7 +190,7 @@
 float aRes, gRes, mRes;      // scale resolutions per LSB for the sensors
 
 //Set up I2C, (SDA,SCL)
-I2C i2c(I2C_SDA, I2C_SCL);
+I2C i2c(p28, p27);
 
 DigitalOut myled(LED1);
     
@@ -625,7 +625,7 @@
 // Configure the accelerometer for self-test
    writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, 0xE0); // Enable self test on all three axes and set accelerometer range to +/- 2 g
    writeByte(MPU9250_ADDRESS, GYRO_CONFIG, 0xE0); // Enable self test on all three axes and set gyro range to +/- 250 degrees/s
-   delay(25); // Delay a while to let the device stabilize
+   wait(25); // Delay a while to let the device stabilize
 
   for( int ii = 0; ii < 200; ii++) { // get average self-test values of gyro and acclerometer
   
@@ -648,7 +648,7 @@
  // Configure the gyro and accelerometer for normal operation
    writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, 0x00);
    writeByte(MPU9250_ADDRESS, GYRO_CONFIG, 0x00);
-   delay(25); // Delay a while to let the device stabilize
+   wait(25); // Delay a while to let the device stabilize
    
    // Retrieve accelerometer and gyro factory Self-Test Code from USR_Reg
    selfTest[0] = readByte(MPU9250_ADDRESS, SELF_TEST_X_ACCEL); // X-axis accel self-test results
diff -r 4e59a37182df -r 51217f251b8d N5110.lib
--- a/N5110.lib	Tue Aug 05 01:37:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/onehorse/code/Adfs/#28c629d0b0d0
diff -r 4e59a37182df -r 51217f251b8d ST_401_84MHZ.lib
--- a/ST_401_84MHZ.lib	Tue Aug 05 01:37:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/dreschpe/code/ST_401_84MHZ/#b9343c8b85ec
diff -r 4e59a37182df -r 51217f251b8d main.cpp
--- a/main.cpp	Tue Aug 05 01:37:23 2014 +0000
+++ b/main.cpp	Fri Jul 13 07:55:27 2018 +0000
@@ -1,9 +1,4 @@
-/* MPU9250 Basic Example Code
- by: Kris Winer
- date: April 1, 2014
- license: Beerware - Use this code however you'd like. If you 
- find it useful you can buy me a beer some time.
- 
+/* 
  Demonstrate basic MPU-9250 functionality including parameterizing the register addresses, initializing the sensor, 
  getting properly scaled accelerometer, gyroscope, and magnetometer data out. Added display functions to 
  allow display to on breadboard monitor. Addition of 9 DoF sensor fusion using open source Madgwick and 
@@ -13,11 +8,10 @@
  10k resistors are on the EMSENSR-9250 breakout board.
  
  Hardware setup:
- MPU9250 Breakout --------- Arduino
+ MPU9250 Breakout --------- lpc1768
  VDD ---------------------- 3.3V
- VDDI --------------------- 3.3V
- SDA ----------------------- A4
- SCL ----------------------- A5
+ SDA ----------------------- p28
+ SCL ----------------------- p27
  GND ---------------------- GND
  
  Note: The MPU9250 is an I2C sensor and uses the Arduino Wire library. 
@@ -26,34 +20,15 @@
  We are also using the 400 kHz fast I2C mode by setting the TWI_FREQ  to 400000L /twi.h utility file.
  */
  
-//#include "ST_F401_84MHZ.h" 
-//F401_init84 myinit(0);
 #include "mbed.h"
 #include "MPU9250.h"
-#include "N5110.h"
-
-// Using NOKIA 5110 monochrome 84 x 48 pixel display
-// pin 9 - Serial clock out (SCLK)
-// pin 8 - Serial data out (DIN)
-// pin 7 - Data/Command select (D/C)
-// pin 5 - LCD chip select (CS)
-// pin 6 - LCD reset (RST)
-//Adafruit_PCD8544 display = Adafruit_PCD8544(9, 8, 7, 5, 6);
 
 float sum = 0;
 uint32_t sumCount = 0;
 char buffer[14];
-
    MPU9250 mpu9250;
-   
    Timer t;
-
    Serial pc(USBTX, USBRX); // tx, rx
-
-   //        VCC,   SCE,  RST,  D/C,  MOSI,S CLK, LED
-   N5110 lcd(PA_8, PB_10, PA_9, PA_6, PA_7, PA_5, PC_7);
-   
-
         
 int main()
 {
@@ -65,10 +40,6 @@
   pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);   
   
   t.start();        
-  
-  lcd.init();
-//  lcd.setBrightness(0.05);
-  
     
   // Read the WHO_AM_I register, this is a good test of communication
   uint8_t whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);  // Read WHO_AM_I register for MPU-9250
@@ -78,11 +49,7 @@
   {  
     pc.printf("MPU9250 WHO_AM_I is 0x%x\n\r", whoami);
     pc.printf("MPU9250 is online...\n\r");
-    lcd.clear();
-    lcd.printString("MPU9250 is", 0, 0);
     sprintf(buffer, "0x%x", whoami);
-    lcd.printString(buffer, 0, 1);
-    lcd.printString("shoud be 0x71", 0, 2);  
     wait(1);
     
     mpu9250.resetMPU9250(); // Reset registers to default in preparation for device calibration
@@ -117,13 +84,8 @@
    {
     pc.printf("Could not connect to MPU9250: \n\r");
     pc.printf("%#x \n",  whoami);
- 
-    lcd.clear();
-    lcd.printString("MPU9250", 0, 0);
-    lcd.printString("no connection", 0, 1);
     sprintf(buffer, "WHO_AM_I 0x%x", whoami);
-    lcd.printString(buffer, 0, 2); 
- 
+    
     while(1) ; // Loop forever if communication doesn't happen
     }
 
@@ -190,29 +152,21 @@
     pc.printf(" gy = %f", gy); 
     pc.printf(" gz = %f  deg/s\n\r", gz); 
     
-    pc.printf("gx = %f", mx); 
-    pc.printf(" gy = %f", my); 
-    pc.printf(" gz = %f  mG\n\r", mz); 
+    pc.printf("mx = %f", mx); 
+    pc.printf(" my = %f", my); 
+    pc.printf(" mz = %f  mG\n\r", mz); 
     
+    /*//温度/*
     tempCount = mpu9250.readTempData();  // Read the adc values
     temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade
     pc.printf(" temperature = %f  C\n\r", temperature); 
+    */
     
     pc.printf("q0 = %f\n\r", q[0]);
     pc.printf("q1 = %f\n\r", q[1]);
     pc.printf("q2 = %f\n\r", q[2]);
     pc.printf("q3 = %f\n\r", q[3]);      
     
-/*    lcd.clear();
-    lcd.printString("MPU9250", 0, 0);
-    lcd.printString("x   y   z", 0, 1);
-    sprintf(buffer, "%d %d %d mg", (int)(1000.0f*ax), (int)(1000.0f*ay), (int)(1000.0f*az));
-    lcd.printString(buffer, 0, 2);
-    sprintf(buffer, "%d %d %d deg/s", (int)gx, (int)gy, (int)gz);
-    lcd.printString(buffer, 0, 3);
-    sprintf(buffer, "%d %d %d mG", (int)mx, (int)my, (int)mz);
-    lcd.printString(buffer, 0, 4); 
- */  
   // Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation.
   // In this coordinate system, the positive z-axis is down toward Earth. 
   // Yaw is the angle between Sensor x-axis and Earth magnetic North (or true North if corrected for local declination, looking down on the sensor positive yaw is counterclockwise.
@@ -233,10 +187,8 @@
     pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll);
     pc.printf("average rate = %f\n\r", (float) sumCount/sum);
 //    sprintf(buffer, "YPR: %f %f %f", yaw, pitch, roll);
-//    lcd.printString(buffer, 0, 4);
 //    sprintf(buffer, "rate = %f", (float) sumCount/sum);
-//    lcd.printString(buffer, 0, 5);
-    
+
     myled= !myled;
     count = t.read_ms();