Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Project Campus_Safety_Bot
Fork of BNO055 by
Revision 1:2c3322a8d417, committed 2015-05-30
- Comitter:
- StressedDave
- Date:
- Sat May 30 18:36:36 2015 +0000
- Parent:
- 0:24f23c36dd24
- Child:
- 2:695c6e5d239a
- Commit message:
- Added device orientation changes as per p25 of datasheet
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 Thu May 28 19:22:25 2015 +0000
+++ b/BNO055.cpp Sat May 30 18:36:36 2015 +0000
@@ -8,7 +8,7 @@
accel_scale = 1.0f;
rate_scale = 1.0f/16.0f;
angle_scale = 1.0f/16.0f;
- temp_scale = 1.0f;
+ temp_scale = 1;
}
void BNO055::reset(){
@@ -93,16 +93,23 @@
void BNO055::set_temp_units(char units){
readchar(BNO055_UNIT_SEL_ADDR);
if (units == CENTIGRADE){
- rx = rx & 0x7F;
- temp_scale = 1.0f;
+ rx = rx & 0xEF;
+ temp_scale = 1;
}
else {
rx = rx | units;
- temp_scale = 2.0f;
+ temp_scale = 2;
}
writechar(BNO055_UNIT_SEL_ADDR,rx);
}
+void BNO055::set_orientation(char units){
+ readchar(BNO055_UNIT_SEL_ADDR);
+ if (units == WINDOWS) rx = rx &0x7F;
+ else rx = rx | units;
+ writechar(BNO055_UNIT_SEL_ADDR,rx);
+}
+
void BNO055::setmode(char omode){
writechar(BNO055_OPR_MODE_ADDR,omode);
op_mode = omode;
@@ -173,7 +180,88 @@
gravity.z = float(gravity.rawz)*accel_scale;
}
+void BNO055::get_quat(void){
+ tx[0] = BNO055_QUATERNION_DATA_W_LSB_ADDR;
+ _i2c.write(address,tx,1,true);
+ _i2c.read(address+1,rawdata,8,0);
+ quat.raww = (rawdata[1] << 8 | rawdata[0]);
+ quat.rawx = (rawdata[3] << 8 | rawdata[2]);
+ quat.rawy = (rawdata[5] << 8 | rawdata[4]);
+ quat.rawz = (rawdata[7] << 8 | rawdata[6]);
+ quat.w = float(quat.raww)/16384.0f;
+ quat.x = float(quat.rawx)/16384.0f;
+ quat.y = float(quat.rawy)/16384.0f;
+ quat.z = float(quat.rawz)/16384.0f;
+}
+
+void BNO055::get_temp(void){
+ readchar(BNO055_TEMP_ADDR);
+ temperature = rx / temp_scale;
+}
+
void BNO055::get_calib(void){
readchar(BNO055_CALIB_STAT_ADDR);
calib = rx;
+}
+
+void BNO055::read_calibration_data(void){
+ char tempmode = op_mode;
+ setmode(OPERATION_MODE_CONFIG);
+ wait_ms(20);
+ tx[0] = ACCEL_OFFSET_X_LSB_ADDR;
+ _i2c.write(address,tx,1,true);
+ _i2c.read(address,calibration,22,false);
+ setmode(tempmode);
+ wait_ms(10);
+}
+
+void BNO055::write_calibration_data(void){
+ char tempmode = op_mode;
+ setmode(OPERATION_MODE_CONFIG);
+ wait_ms(20);
+ tx[0] = ACCEL_OFFSET_X_LSB_ADDR;
+ _i2c.write(address,tx,1,true);
+ _i2c.write(address,calibration,22,false);
+ setmode(tempmode);
+ wait_ms(10);
+}
+
+void BNO055::set_mapping(char orient){
+ switch (orient){
+ case 0:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x04);
+ break;
+ case 1:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+ break;
+ case 2:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+ break;
+ case 3:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x02);
+ break;
+ case 4:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x03);
+ break;
+ case 5:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x01);
+ break;
+ case 6:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x07);
+ break;
+ case 7:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x05);
+ break;
+ default:
+ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+ writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+ }
}
\ No newline at end of file
--- a/BNO055.h Thu May 28 19:22:25 2015 +0000
+++ b/BNO055.h Sat May 30 18:36:36 2015 +0000
@@ -122,9 +122,11 @@
#define DEG_PER_SEC 0x00
#define RAD_PER_SEC 0x02
#define DEGREES 0x00
-#define RADIANS 0x40
+#define RADIANS 0x04
#define CENTIGRADE 0x00
-#define FAHRENHEIT 0x80
+#define FAHRENHEIT 0x10
+#define WINDOWS 0x00
+#define ANDROID 0x80
//Definitions for power mode
#define POWER_MODE_NORMAL 0x00
@@ -132,7 +134,7 @@
#define POWER_MODE_SUSPEND 0x02
//Definitions for operating mode
-#define OPERATION_MODE_CONFIG 0x00
+#define OPERATION_MODE_CONFIG 0x00
#define OPERATION_MODE_ACCONLY 0x01
#define OPERATION_MODE_MAGONLY 0x02
#define OPERATION_MODE_GYRONLY 0x03
@@ -170,7 +172,6 @@
char bootload;
char serial[16];
}chip;
-
class BNO055
{
@@ -188,13 +189,20 @@
void set_anglerate_units(char units);
void set_angle_units(char units);
void set_temp_units(char units);
+ void set_orientation(char units);
+ void set_mapping(char orient);
+
void get_accel(void);
void get_gyro(void);
void get_mag(void);
void get_lia(void);
void get_grv(void);
void get_quat(void);
+ void get_temp(void);
+
void get_calib(void);
+ void read_calibration_data(void);
+ void write_calibration_data(void);
values accel,gyro,mag,lia,gravity;
angles euler;
@@ -203,14 +211,17 @@
char status;
char calibration[22];
chip ID;
+ int temperature;
+
private:
I2C _i2c;
char rx,tx[2],address; //I2C variables
- char rawdata[16]; //Temporary array for input data values
+ char rawdata[22]; //Temporary array for input data values
char op_mode;
char pwr_mode;
- float accel_scale,rate_scale,angle_scale,temp_scale;
+ float accel_scale,rate_scale,angle_scale;
+ int temp_scale;
void readchar(char location){
tx[0] = location;
