九軸の制御

Dependencies:   mbed

Fork of MPU9250AHRS by Kris Winer

Revision:
3:51217f251b8d
Parent:
1:71c319f03fda
--- 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();