Skip to content

Commit

Permalink
bno055: Initial implementation
Browse files Browse the repository at this point in the history
This driver implements support for the Bosch BNO055 Absolute
Orientation 9DOF Fusion Hub.   It was implemented on the Adafruit
variant at https://www.adafruit.com/products/2472.

The BNO055 is a System in Package (SiP), integrating a triaxial 14-bit
accelerometer, a triaxial 16-bit gyroscope with a range of ±2000
degrees per second, a triaxial geomagnetic sensor and a 32-bit cortex
M0+ microcontroller running Bosch Sensortec sensor fusion software, in
a single package.

This sensor handles the hard problem of combining various sensor
information into a reliable measurement of sensor orientation (refered
to as 'sensor fusion').  The onboard MCU runs this software and can
provide fusion output in the form of Euler Angles, Quaternions, Linear
Acceleration, and Gravity Vectors in 3 axes.

The focus on this driver has been on supporting the fusion components.
Less support is available for use of this device as a generic
accelerometer, gyroscope and magnetometer, however enough
infrastructure is available to add any missing functionality.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Noel Eck <noel.eck@intel.com>
  • Loading branch information
jontrulson authored and noel-eck committed May 9, 2016
1 parent d045dde commit 456bde0
Show file tree
Hide file tree
Showing 12 changed files with 2,901 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/c++/CMakeLists.txt
Expand Up @@ -267,6 +267,7 @@ add_example (vcap)
add_example (ds2413)
add_example (ds18b20)
add_example (bmp280)
add_example (bno055)

# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
Expand Down
129 changes: 129 additions & 0 deletions examples/c++/bno055.cxx
@@ -0,0 +1,129 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "bno055.hpp"

using namespace std;

int shouldRun = true;

void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}


int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]

// Instantiate an BNO055 using default parameters (bus 0, addr
// 0x28). The default running mode is NDOF absolute orientation
// mode.
upm::BNO055 *sensor = new upm::BNO055();

// First we need to calibrate....
cout << "First we need to calibrate. 4 numbers will be output every"
<< endl;
cout << "second for each sensor. 0 means uncalibrated, and 3 means"
<< endl;
cout << "fully calibrated."
<< endl;
cout << "See the UPM documentation on this sensor for instructions on"
<< endl;
cout << "what actions are required to calibrate."
<< endl;
cout << endl;

// do the calibration...
while (shouldRun && !sensor->isFullyCalibrated())
{
int mag, acc, gyr, sys;
sensor->getCalibrationStatus(&mag, &acc, &gyr, &sys);

cout << "Magnetometer: " << mag
<< " Accelerometer: " << acc
<< " Gyroscope: " << gyr
<< " System: " << sys
<< endl;

sleep(1);
}

cout << endl;
cout << "Calibration complete." << endl;
cout << endl;

// now output various fusion data every 250 milliseconds
while (shouldRun)
{
float w, x, y, z;

sensor->update();

sensor->getEulerAngles(&x, &y, &z);
cout << "Euler: Heading: " << x
<< " Roll: " << y
<< " Pitch: " << z
<< " degrees"
<< endl;

sensor->getQuaternions(&w, &x, &y, &z);
cout << "Quaternion: W: " << w
<< " X: " << x
<< " Y: " << y
<< " Z: " << z
<< endl;

sensor->getLinearAcceleration(&x, &y, &z);
cout << "Linear Acceleration: X: " << x
<< " Y: " << y
<< " Z: " << z
<< " m/s^2"
<< endl;

sensor->getGravityVectors(&x, &y, &z);
cout << "Gravity Vector: X: " << x
<< " Y: " << y
<< " Z: " << z
<< " m/s^2"
<< endl;

cout << endl;
usleep(250000);
}

//! [Interesting]

cout << "Exiting..." << endl;

delete sensor;

return 0;
}
99 changes: 99 additions & 0 deletions examples/java/BNO055_Example.java
@@ -0,0 +1,99 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import upm_bno055.BNO055;

public class BNO055_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
System.out.println("Initializing...");

// Instantiate an BNO055 using default parameters (bus 0, addr
// 0x28). The default running mode is NDOF absolute orientation
// mode.
BNO055 sensor = new BNO055();

System.out.println("First we need to calibrate. 4 numbers will be output every");
System.out.println("second for each sensor. 0 means uncalibrated, and 3 means");
System.out.println("fully calibrated.");
System.out.println("See the UPM documentation on this sensor for instructions on");
System.out.println("what actions are required to calibrate.");
System.out.println("");

while (!sensor.isFullyCalibrated())
{
int calData[] = sensor.getCalibrationStatus();

System.out.println("Magnetometer: " + calData[0]
+ " Accelerometer: " + calData[1]
+ " Gyroscope: " + calData[2]
+ " System: " + calData[3]);

Thread.sleep(1000);

}

System.out.println("");
System.out.println("Calibration complete.");
System.out.println("");

while (true)
{
// update our values from the sensor
sensor.update();

float dataE[] = sensor.getEulerAngles();
System.out.println("Euler: Heading: " + dataE[0] +
" Roll: " + dataE[1] +
" Pitch: " + dataE[2] +
" degrees");

float dataQ[] = sensor.getQuaternions();
System.out.println("Quaternion: W: " + dataQ[0] +
" X:" + dataQ[1] +
" Y: " + dataQ[2] +
" Z: " + dataQ[3]);

float dataL[] = sensor.getLinearAcceleration();
System.out.println("Linear Acceleration: X: " + dataL[0] +
" Y: " + dataL[1] +
" Z: " + dataL[2] +
" m/s^2");

float dataG[] = sensor.getGravityVectors();
System.out.println("Gravity Vector: X: " + dataG[0] +
" Y: " + dataG[1] +
" Z: " + dataG[2] +
" m/s^2");


System.out.println();
Thread.sleep(250);
}

// ! [Interesting]
}
}
1 change: 1 addition & 0 deletions examples/java/CMakeLists.txt
Expand Up @@ -127,6 +127,7 @@ if (BACNET_FOUND)
endif()
add_example(VCAP_Example vcap)
add_example(BMP280_Example bmp280)
add_example(BNO055_Example bno055)

add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
Expand Down
117 changes: 117 additions & 0 deletions examples/javascript/bno055.js
@@ -0,0 +1,117 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


var sensorObj = require('jsupm_bno055');

// Instantiate an BNO055 using default parameters (bus 0, addr
// 0x28). The default running mode is NDOF absolute orientation
// mode.
var sensor = new sensorObj.BNO055();

var mag = new sensorObj.new_intp();
var acc = new sensorObj.new_intp();
var gyr = new sensorObj.new_intp();
var syst = new sensorObj.new_intp();

var w = new sensorObj.new_floatp();
var x = new sensorObj.new_floatp();
var y = new sensorObj.new_floatp();
var z = new sensorObj.new_floatp();

console.log("First we need to calibrate. 4 numbers will be output every");
console.log("second for each sensor. 0 means uncalibrated, and 3 means");
console.log("fully calibrated.");
console.log("See the UPM documentation on this sensor for instructions on");
console.log("what actions are required to calibrate.");
console.log("");

// do the calibration...
var calInterval = setInterval(function()
{
if (sensor.isFullyCalibrated())
{
clearInterval(calInterval);
console.log("");
console.log("Calibration complete.");
console.log("");

setInterval(outputData, 250)
}
else
{
sensor.getCalibrationStatus(mag, acc, gyr, syst);
console.log("Magnetometer: " + sensorObj.intp_value(mag) +
" Accelerometer: " + sensorObj.intp_value(acc) +
" Gyroscope: " + sensorObj.intp_value(gyr) +
" System: " + sensorObj.intp_value(syst));
}

}, 1000);


// now output various fusion data every 250 milliseconds
function outputData()
{
sensor.update();

sensor.getEulerAngles(x, y, z);
console.log("Euler: Heading: " + sensorObj.floatp_value(x) +
" Roll: " + sensorObj.floatp_value(y) +
" Pitch: " + sensorObj.floatp_value(z) +
" degrees");

sensor.getQuaternions(w, x, y, z);
console.log("Quaternion: W: " + sensorObj.floatp_value(w) +
" X:" + sensorObj.floatp_value(x) +
" Y: " + sensorObj.floatp_value(y) +
" Z: " + sensorObj.floatp_value(z));

sensor.getLinearAcceleration(x, y, z);
console.log("Linear Acceleration: X: " + sensorObj.floatp_value(x) +
" Y: " + sensorObj.floatp_value(y) +
" Z: " + sensorObj.floatp_value(z) +
" m/s^2");

sensor.getGravityVectors(x, y, z);
console.log("Gravity Vector: X: " + sensorObj.floatp_value(x) +
" Y: " + sensorObj.floatp_value(y) +
" Z: " + sensorObj.floatp_value(z) +
" m/s^2");

console.log("");
};

// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

0 comments on commit 456bde0

Please sign in to comment.