Example/test programs for my BNO080 driver.

Dependencies:   BNO080

BNO080 Driver Examples

These examples show how to use some of the functionality on my BNO080 driver. To get started with MBed CLI:

Build Instructions

$ hg clone https://MultipleMonomials@os.mbed.com/users/MultipleMonomials/code/BNO080-Examples/
$ cd BNO080-Examples
$ mbed deploy
$ mbed compile
Revision:
4:85b98cc04a0a
Parent:
3:f72d98d0095e
Child:
5:ee64252765de
--- a/BNOTestSuite.cpp	Mon May 04 03:04:11 2020 -0700
+++ b/BNOTestSuite.cpp	Tue Jul 21 22:00:26 2020 -0700
@@ -26,9 +26,7 @@
 
 	while (true)
 	{
-        // note: for some reason it seems like wait() here waits 10x the time you tell it to
-        // not sure what's causing this behavior, and I don't see it with mbed os 2
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
         if(imu.updateData())
 		{
@@ -56,7 +54,7 @@
 
 	while (true)
 	{
-        ThisThread::sleep_for(1);
+		ThisThread::sleep_for(1ms);
 
 		if(imu.updateData())
 		{
@@ -104,9 +102,7 @@
 
 	while (true)
 	{
-		// note: for some reason it seems like wait() here waits 10x the time you tell it to
-        // not sure what's causing this behavior, and I don't see it with mbed os 2
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
 		if(imu.updateData())
 		{
@@ -136,7 +132,7 @@
 
 	while (true)
 	{
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
 		if(imu.updateData())
 		{
@@ -183,9 +179,7 @@
 
 	while (true)
 	{
-		// note: for some reason it seems like wait() here waits 10x the time you tell it to
-        // not sure what's causing this behavior, and I don't see it with mbed os 2
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
 		if(imu.updateData())
 		{
@@ -214,7 +208,7 @@
 
 	while (true)
 	{
-        ThisThread::sleep_for(1);
+        ThisThread::sleep_for(1ms);
 
 		if(imu.updateData())
 		{
@@ -275,7 +269,7 @@
 
 	while (true)
 	{
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
 		if(imu.updateData())
 		{
@@ -343,7 +337,7 @@
 
 	while (true)
 	{
-        ThisThread::sleep_for(update_rate_ms);
+		ThisThread::sleep_for(1ms * update_rate_ms);
 
 		if(imu.updateData())
 		{
@@ -373,13 +367,61 @@
 	}
 }
 
+void BNOTestSuite::test_accelCalibration()
+{
+	// enable calibration for the magnetometer
+	bool success = imu.enableCalibration(true, false, false);
+
+	const size_t update_rate_ms = 200;
+	imu.enableReport(BNO080::Report::TOTAL_ACCELERATION, update_rate_ms);
+
+	if(success)
+	{
+		pc.printf("Calibration mode was successfully enabled!\r\n");
+	}
+	else
+	{
+		pc.printf("Calibration mode failed to enable!\r\n");
+		while(true){}
+	}
+
+	while (true)
+	{
+		ThisThread::sleep_for(1ms * update_rate_ms);
+
+		if(imu.updateData())
+		{
+			pc.printf("IMU Total Acceleration: [");
+			imu.totalAcceleration.print(pc, true);
+			pc.printf("] m/s^2, Status: %hhu (should be 2-3 when calibration is complete), ", imu.getReportStatus(BNO080::Report::TOTAL_ACCELERATION));
+			pc.printf("]\r\n");
+
+		}
+		else
+		{
+			pc.printf("IMU was not ready with data packet!\r\n");
+		}
+
+		if(serial.readable())
+		{
+			// char typed over serial
+			pc.printf("Saving current calibration...\r\n");
+			imu.saveCalibration();
+
+			// throw out rest of chars in serial buffer
+			while(serial.readable())
+			{
+				pc.getc();
+			}
+		}
+	}
+
+}
+
 int main()
 {
-	pc.baud(115200);
-
 	pc.printf("============================================================\n");
 
-
 	// reset and connect to IMU
 	while(!imu.begin())
 	{
@@ -407,7 +449,7 @@
 	pc.printf("10. Test set orientation\r\n");
 	pc.printf("11. Test set permanent orientation\r\n");
 	pc.printf("12. Test disabling reports\r\n");
-	pc.printf("13. Exit test suite\r\n");
+	pc.printf("13. Test accelerometer calibration\r\n");
 
 	pc.scanf("%d", &test);
 	pc.printf("Running test %d:\r\n\n", test);
@@ -451,9 +493,6 @@
 		case 12:
 			harness.test_disable();
 			break;
-		case 13:
-			pc.printf("Exiting test suite.\r\n");
-			return 0;
 		default:
 			printf("Invalid test number. Please run again.\r\n");
 			return 1;