Will Church / BNO055_fusion_tom

Fork of BNO055_fusion by Tom Rasmussen

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Fri Apr 10 11:18:12 2015 +0000
Parent:
2:0f225b686cd5
Child:
4:9e6fead1e93e
Commit message:
improved select_page() function.

Changed in this revision

BNO055.cpp Show annotated file Show diff for this revision Revisions of this file
BNO055.h Show annotated file Show diff for this revision Revisions of this file
--- a/BNO055.cpp	Wed Apr 08 11:27:57 2015 +0000
+++ b/BNO055.cpp	Fri Apr 10 11:18:12 2015 +0000
@@ -7,7 +7,7 @@
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
  *      Created: March     30th, 2015
- *      Revised: April      8th, 2015
+ *      Revised: April     10th, 2015
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
@@ -204,6 +204,8 @@
 #else
     _i2c.frequency(400000);
 #endif
+    page_flag = 0xff;
+    select_page(0);
     // Check Acc & Mag & Gyro are available of not
     check_id();
     // Set initial data
@@ -224,17 +226,20 @@
 
 uint8_t BNO055::select_page(uint8_t page)
 {
-    dt[0] = BNO055_PAGE_ID;
-    if (page == 1) {
-        dt[1] = 1;  // select page 1
-    } else {
-        dt[1] = 0;  // select page 0
+    if (page != page_flag){
+        dt[0] = BNO055_PAGE_ID;
+        if (page == 1) {
+            dt[1] = 1;  // select page 1
+        } else {
+            dt[1] = 0;  // select page 0
+        }
+        _i2c.write(chip_addr, dt, 2, false);
+        dt[0] = BNO055_PAGE_ID;
+        _i2c.write(chip_addr, dt, 1, true);
+        _i2c.read(chip_addr, dt, 1, false);
+        page_flag = dt[0];
     }
-    _i2c.write(chip_addr, dt, 2, false);
-    dt[0] = BNO055_PAGE_ID;
-    _i2c.write(chip_addr, dt, 1, true);
-    _i2c.read(chip_addr, dt, 1, false);
-    return dt[0];
+    return page_flag;
 }
 
 uint8_t BNO055::reset(void)
@@ -249,6 +254,8 @@
     _i2c.frequency(400000);
 #endif
     _i2c.stop();
+    page_flag = 0xff;
+    select_page(0);
     check_id();
     if (chip_id != I_AM_BNO055_CHIP){
         return 1;
@@ -275,21 +282,21 @@
     _i2c.read(chip_addr, dt, 7, false);
     chip_id = dt[0];
     if (chip_id == I_AM_BNO055_CHIP) {
-        ready_flg = 1;
+        ready_flag = 1;
     } else {
-        ready_flg = 0;
+        ready_flag = 0;
     }
     acc_id = dt[1];
     if (acc_id == I_AM_BNO055_ACC) {
-        ready_flg |= 2;
+        ready_flag |= 2;
     }
     mag_id = dt[2];
     if (mag_id == I_AM_BNO055_MAG) {
-        ready_flg |= 4;
+        ready_flag |= 4;
     }
     gyr_id = dt[3];
     if (mag_id == I_AM_BNO055_MAG) {
-        ready_flg |= 8;
+        ready_flag |= 8;
     }
     bootldr_rev_id = dt[5]<< 8 | dt[4];
     sw_rev_id = dt[6];
@@ -308,7 +315,7 @@
 /////////////// Check chip ready or not  //////////////////
 uint8_t BNO055::chip_ready(void)
 {
-    if (ready_flg == 0x0f) {
+    if (ready_flag == 0x0f) {
         return 1;
     }
     return 0;
--- a/BNO055.h	Wed Apr 08 11:27:57 2015 +0000
+++ b/BNO055.h	Fri Apr 10 11:18:12 2015 +0000
@@ -7,7 +7,7 @@
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
  *      Created: March     30th, 2015
- *      Revised: April      8th, 2015
+ *      Revised: April     10th, 2015
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
@@ -223,7 +223,7 @@
 
     /** Reset
       * @param none
-      * @return 0 = sucess, 1 = Not avirable chip
+      * @return 0 = sucess, 1 = Not available chip
       */
     uint8_t reset(void);
 
@@ -274,7 +274,8 @@
     char     dt[10];      // working buffer
     uint8_t  chip_addr;
     uint8_t  chip_mode;
-    uint8_t  ready_flg;
+    uint8_t  ready_flag;
+    uint8_t  page_flag;
 
     uint8_t  chip_id;
     uint8_t  acc_id;
@@ -464,4 +465,74 @@
 #define GYRO_ANY_MOTION_THRES   0x1e
 #define GYRO_ANY_MOTION_SET     0x1f
 
+//---------------------------------------------------------
+//----- Calibration example -------------------------------
+//---------------------------------------------------------
+#if 0
+// Calibration
+//  Please refer BNO055 Data sheet 3.10 Calibration & 3.6.4 Sensor calibration data
+void bno055_calbration(void){
+    uint8_t d;
+
+    pc.printf("------ Enter BNO055 Manual Calibration Mode ------\r\n");
+    //---------- Gyroscope Caliblation ------------------------------------------------------------
+    // (a) Place the device in a single stable position for a period of few seconds to allow the
+    //     gyroscope to calibrate
+    pc.printf("Step1) Please wait few seconds\r\n");
+    t.start();
+    while (t.read() < 10){
+        d = imu.read_calib_status();
+        pc.printf("Calb dat = 0x%x target  = 0x30(at least)\r\n", d);
+        if ((d & 0x30) == 0x30){
+            break;
+        }
+        wait(1.0);
+    }
+    pc.printf("-> Step1) is done\r\n\r\n");
+    //---------- Magnetometer Caliblation ---------------------------------------------------------
+    // (a) Make some random movements (for example: writing the number ‘8’ on air) until the
+    //     CALIB_STAT register indicates fully calibrated.
+    // (b) It takes more calibration movements to get the magnetometer calibrated than in the
+    //     NDOF mode.
+    pc.printf("Step2) random moving (try to change the BNO055 axis)\r\n");
+    t.start();
+    while (t.read() < 30){
+        d = imu.read_calib_status();
+        pc.printf("Calb dat = 0x%x target  = 0x33(at least)\r\n", d);
+        if ((d & 0x03) == 0x03){
+            break;
+        }
+        wait(1.0);   
+    }
+    pc.printf("-> Step2) is done\r\n\r\n");
+    //---------- Magnetometer Caliblation ---------------------------------------------------------
+    // a) Place the device in 6 different stable positions for a period of few seconds
+    //    to allow the accelerometer to calibrate.
+    // b) Make sure that there is slow movement between 2 stable positions
+    //    The 6 stable positions could be in any direction, but make sure that the device is
+    //    lying at least once perpendicular to the x, y and z axis.
+    pc.printf("Step3) Change rotation each X,Y,Z axis KEEP SLOWLY!!");
+    pc.printf(" Each 90deg stay a 5 sec and set at least 6 position.\r\n");
+    pc.printf(" e.g. (1)ACC:X0,Y0,Z-9,(2)ACC:X9,Y0,Z0,(3)ACC:X0,Y0,Z9,");
+    pc.printf("(4)ACC:X-9,Y0,Z0,(5)ACC:X0,Y-9,Z0,(6)ACC:X0,Y9,Z0,\r\n");
+    pc.printf(" If you will give up, hit any key.\r\n", d);
+    t.stop();
+    while (true){
+        d = imu.read_calib_status();
+        imu.get_gravity(&gravity);
+        pc.printf("Calb dat = 0x%x target  = 0xff ACC:X %3.0f, Y %3.0f, Z %3.0f\r\n",
+                   d, gravity.x, gravity.y, gravity.z);
+        if (d == 0xff){     break;}
+        if (pc.readable()){ break;}
+        wait(1.0);
+    }
+    if (imu.read_calib_status() == 0xff){
+        pc.printf("-> All of Calibration steps are done successfully!\r\n\r\n");
+    } else {
+        pc.printf("-> Calibration steps are suspended!\r\n\r\n");
+    }
+    t.stop();
+}
+#endif
+
 #endif      // BNO055_H