Bosch BNO055 IMU library fork
Dependents: Orion_newPCB_test_LV Orion_PCB_test_Faulhaber_gr41_wptcmd_V1
Fork of BNO055 by
BNO055.h@7:14cdbe8c68af, 2016-01-20 (annotated)
- Committer:
- akashvibhute
- Date:
- Wed Jan 20 02:40:21 2016 +0000
- Revision:
- 7:14cdbe8c68af
- Parent:
- 3:1db1628eb8b2
modified i2c frequency to 40kHz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
StressedDave | 0:24f23c36dd24 | 1 | #ifndef BNO055_H |
StressedDave | 0:24f23c36dd24 | 2 | #define BNO055_H |
StressedDave | 0:24f23c36dd24 | 3 | |
StressedDave | 0:24f23c36dd24 | 4 | #include "mbed.h" |
StressedDave | 0:24f23c36dd24 | 5 | // |
akashvibhute | 7:14cdbe8c68af | 6 | //#define BNOAddress (0x28 << 1) |
akashvibhute | 7:14cdbe8c68af | 7 | #define BNOAddress (0x29 << 1) |
StressedDave | 0:24f23c36dd24 | 8 | //Register definitions |
StressedDave | 0:24f23c36dd24 | 9 | /* Page id register definition */ |
StressedDave | 0:24f23c36dd24 | 10 | #define BNO055_PAGE_ID_ADDR 0x07 |
StressedDave | 0:24f23c36dd24 | 11 | /* PAGE0 REGISTER DEFINITION START*/ |
StressedDave | 0:24f23c36dd24 | 12 | #define BNO055_CHIP_ID_ADDR 0x00 |
StressedDave | 0:24f23c36dd24 | 13 | #define BNO055_ACCEL_REV_ID_ADDR 0x01 |
StressedDave | 0:24f23c36dd24 | 14 | #define BNO055_MAG_REV_ID_ADDR 0x02 |
StressedDave | 0:24f23c36dd24 | 15 | #define BNO055_GYRO_REV_ID_ADDR 0x03 |
StressedDave | 0:24f23c36dd24 | 16 | #define BNO055_SW_REV_ID_LSB_ADDR 0x04 |
StressedDave | 0:24f23c36dd24 | 17 | #define BNO055_SW_REV_ID_MSB_ADDR 0x05 |
StressedDave | 0:24f23c36dd24 | 18 | #define BNO055_BL_REV_ID_ADDR 0x06 |
StressedDave | 0:24f23c36dd24 | 19 | /* Accel data register */ |
StressedDave | 0:24f23c36dd24 | 20 | #define BNO055_ACCEL_DATA_X_LSB_ADDR 0x08 |
StressedDave | 0:24f23c36dd24 | 21 | #define BNO055_ACCEL_DATA_X_MSB_ADDR 0x09 |
StressedDave | 0:24f23c36dd24 | 22 | #define BNO055_ACCEL_DATA_Y_LSB_ADDR 0x0A |
StressedDave | 0:24f23c36dd24 | 23 | #define BNO055_ACCEL_DATA_Y_MSB_ADDR 0x0B |
StressedDave | 0:24f23c36dd24 | 24 | #define BNO055_ACCEL_DATA_Z_LSB_ADDR 0x0C |
StressedDave | 0:24f23c36dd24 | 25 | #define BNO055_ACCEL_DATA_Z_MSB_ADDR 0x0D |
StressedDave | 0:24f23c36dd24 | 26 | /* Mag data register */ |
StressedDave | 0:24f23c36dd24 | 27 | #define BNO055_MAG_DATA_X_LSB_ADDR 0x0E |
StressedDave | 0:24f23c36dd24 | 28 | #define BNO055_MAG_DATA_X_MSB_ADDR 0x0F |
StressedDave | 0:24f23c36dd24 | 29 | #define BNO055_MAG_DATA_Y_LSB_ADDR 0x10 |
StressedDave | 0:24f23c36dd24 | 30 | #define BNO055_MAG_DATA_Y_MSB_ADDR 0x11 |
StressedDave | 0:24f23c36dd24 | 31 | #define BNO055_MAG_DATA_Z_LSB_ADDR 0x12 |
StressedDave | 0:24f23c36dd24 | 32 | #define BNO055_MAG_DATA_Z_MSB_ADDR 0x13 |
StressedDave | 0:24f23c36dd24 | 33 | /* Gyro data registers */ |
StressedDave | 0:24f23c36dd24 | 34 | #define BNO055_GYRO_DATA_X_LSB_ADDR 0x14 |
StressedDave | 0:24f23c36dd24 | 35 | #define BNO055_GYRO_DATA_X_MSB_ADDR 0x15 |
StressedDave | 0:24f23c36dd24 | 36 | #define BNO055_GYRO_DATA_Y_LSB_ADDR 0x16 |
StressedDave | 0:24f23c36dd24 | 37 | #define BNO055_GYRO_DATA_Y_MSB_ADDR 0x17 |
StressedDave | 0:24f23c36dd24 | 38 | #define BNO055_GYRO_DATA_Z_LSB_ADDR 0x18 |
StressedDave | 0:24f23c36dd24 | 39 | #define BNO055_GYRO_DATA_Z_MSB_ADDR 0x19 |
StressedDave | 0:24f23c36dd24 | 40 | /* Euler data registers */ |
StressedDave | 0:24f23c36dd24 | 41 | #define BNO055_EULER_H_LSB_ADDR 0x1A |
StressedDave | 0:24f23c36dd24 | 42 | #define BNO055_EULER_H_MSB_ADDR 0x1B |
StressedDave | 0:24f23c36dd24 | 43 | #define BNO055_EULER_R_LSB_ADDR 0x1C |
StressedDave | 0:24f23c36dd24 | 44 | #define BNO055_EULER_R_MSB_ADDR 0x1D |
StressedDave | 0:24f23c36dd24 | 45 | #define BNO055_EULER_P_LSB_ADDR 0x1E |
StressedDave | 0:24f23c36dd24 | 46 | #define BNO055_EULER_P_MSB_ADDR 0x1F |
StressedDave | 0:24f23c36dd24 | 47 | /* Quaternion data registers */ |
StressedDave | 0:24f23c36dd24 | 48 | #define BNO055_QUATERNION_DATA_W_LSB_ADDR 0x20 |
StressedDave | 0:24f23c36dd24 | 49 | #define BNO055_QUATERNION_DATA_W_MSB_ADDR 0x21 |
StressedDave | 0:24f23c36dd24 | 50 | #define BNO055_QUATERNION_DATA_X_LSB_ADDR 0x22 |
StressedDave | 0:24f23c36dd24 | 51 | #define BNO055_QUATERNION_DATA_X_MSB_ADDR 0x23 |
StressedDave | 0:24f23c36dd24 | 52 | #define BNO055_QUATERNION_DATA_Y_LSB_ADDR 0x24 |
StressedDave | 0:24f23c36dd24 | 53 | #define BNO055_QUATERNION_DATA_Y_MSB_ADDR 0x25 |
StressedDave | 0:24f23c36dd24 | 54 | #define BNO055_QUATERNION_DATA_Z_LSB_ADDR 0x26 |
StressedDave | 0:24f23c36dd24 | 55 | #define BNO055_QUATERNION_DATA_Z_MSB_ADDR 0x27 |
StressedDave | 0:24f23c36dd24 | 56 | /* Linear acceleration data registers */ |
StressedDave | 0:24f23c36dd24 | 57 | #define BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR 0x28 |
StressedDave | 0:24f23c36dd24 | 58 | #define BNO055_LINEAR_ACCEL_DATA_X_MSB_ADDR 0x29 |
StressedDave | 0:24f23c36dd24 | 59 | #define BNO055_LINEAR_ACCEL_DATA_Y_LSB_ADDR 0x2A |
StressedDave | 0:24f23c36dd24 | 60 | #define BNO055_LINEAR_ACCEL_DATA_Y_MSB_ADDR 0x2B |
StressedDave | 0:24f23c36dd24 | 61 | #define BNO055_LINEAR_ACCEL_DATA_Z_LSB_ADDR 0x2C |
StressedDave | 0:24f23c36dd24 | 62 | #define BNO055_LINEAR_ACCEL_DATA_Z_MSB_ADDR 0x2D |
StressedDave | 0:24f23c36dd24 | 63 | /* Gravity data registers */ |
StressedDave | 0:24f23c36dd24 | 64 | #define BNO055_GRAVITY_DATA_X_LSB_ADDR 0x2E |
StressedDave | 0:24f23c36dd24 | 65 | #define BNO055_GRAVITY_DATA_X_MSB_ADDR 0x2F |
StressedDave | 0:24f23c36dd24 | 66 | #define BNO055_GRAVITY_DATA_Y_LSB_ADDR 0x30 |
StressedDave | 0:24f23c36dd24 | 67 | #define BNO055_GRAVITY_DATA_Y_MSB_ADDR 0x31 |
StressedDave | 0:24f23c36dd24 | 68 | #define BNO055_GRAVITY_DATA_Z_LSB_ADDR 0x32 |
StressedDave | 0:24f23c36dd24 | 69 | #define BNO055_GRAVITY_DATA_Z_MSB_ADDR 0x33 |
StressedDave | 0:24f23c36dd24 | 70 | /* Temperature data register */ |
StressedDave | 0:24f23c36dd24 | 71 | #define BNO055_TEMP_ADDR 0x34 |
StressedDave | 0:24f23c36dd24 | 72 | /* Status registers */ |
StressedDave | 0:24f23c36dd24 | 73 | #define BNO055_CALIB_STAT_ADDR 0x35 |
StressedDave | 0:24f23c36dd24 | 74 | #define BNO055_SELFTEST_RESULT_ADDR 0x36 |
StressedDave | 0:24f23c36dd24 | 75 | #define BNO055_INTR_STAT_ADDR 0x37 |
StressedDave | 0:24f23c36dd24 | 76 | #define BNO055_SYS_CLK_STAT_ADDR 0x38 |
StressedDave | 0:24f23c36dd24 | 77 | #define BNO055_SYS_STAT_ADDR 0x39 |
StressedDave | 0:24f23c36dd24 | 78 | #define BNO055_SYS_ERR_ADDR 0x3A |
StressedDave | 0:24f23c36dd24 | 79 | /* Unit selection register */ |
StressedDave | 0:24f23c36dd24 | 80 | #define BNO055_UNIT_SEL_ADDR 0x3B |
StressedDave | 0:24f23c36dd24 | 81 | #define BNO055_DATA_SELECT_ADDR 0x3C |
StressedDave | 0:24f23c36dd24 | 82 | /* Mode registers */ |
StressedDave | 0:24f23c36dd24 | 83 | #define BNO055_OPR_MODE_ADDR 0x3D |
StressedDave | 0:24f23c36dd24 | 84 | #define BNO055_PWR_MODE_ADDR 0x3E |
StressedDave | 0:24f23c36dd24 | 85 | #define BNO055_SYS_TRIGGER_ADDR 0x3F |
StressedDave | 0:24f23c36dd24 | 86 | #define BNO055_TEMP_SOURCE_ADDR 0x40 |
StressedDave | 0:24f23c36dd24 | 87 | /* Axis remap registers */ |
StressedDave | 0:24f23c36dd24 | 88 | #define BNO055_AXIS_MAP_CONFIG_ADDR 0x41 |
StressedDave | 0:24f23c36dd24 | 89 | #define BNO055_AXIS_MAP_SIGN_ADDR 0x42 |
StressedDave | 0:24f23c36dd24 | 90 | /* Accelerometer Offset registers */ |
StressedDave | 0:24f23c36dd24 | 91 | #define ACCEL_OFFSET_X_LSB_ADDR 0x55 |
StressedDave | 0:24f23c36dd24 | 92 | #define ACCEL_OFFSET_X_MSB_ADDR 0x56 |
StressedDave | 0:24f23c36dd24 | 93 | #define ACCEL_OFFSET_Y_LSB_ADDR 0x57 |
StressedDave | 0:24f23c36dd24 | 94 | #define ACCEL_OFFSET_Y_MSB_ADDR 0x58 |
StressedDave | 0:24f23c36dd24 | 95 | #define ACCEL_OFFSET_Z_LSB_ADDR 0x59 |
StressedDave | 0:24f23c36dd24 | 96 | #define ACCEL_OFFSET_Z_MSB_ADDR 0x5A |
StressedDave | 0:24f23c36dd24 | 97 | /* Magnetometer Offset registers */ |
StressedDave | 0:24f23c36dd24 | 98 | #define MAG_OFFSET_X_LSB_ADDR 0x5B |
StressedDave | 0:24f23c36dd24 | 99 | #define MAG_OFFSET_X_MSB_ADDR 0x5C |
StressedDave | 0:24f23c36dd24 | 100 | #define MAG_OFFSET_Y_LSB_ADDR 0x5D |
StressedDave | 0:24f23c36dd24 | 101 | #define MAG_OFFSET_Y_MSB_ADDR 0x5E |
StressedDave | 0:24f23c36dd24 | 102 | #define MAG_OFFSET_Z_LSB_ADDR 0x5F |
StressedDave | 0:24f23c36dd24 | 103 | #define MAG_OFFSET_Z_MSB_ADDR 0x60 |
StressedDave | 0:24f23c36dd24 | 104 | /* Gyroscope Offset registers*/ |
StressedDave | 0:24f23c36dd24 | 105 | #define GYRO_OFFSET_X_LSB_ADDR 0x61 |
StressedDave | 0:24f23c36dd24 | 106 | #define GYRO_OFFSET_X_MSB_ADDR 0x62 |
StressedDave | 0:24f23c36dd24 | 107 | #define GYRO_OFFSET_Y_LSB_ADDR 0x63 |
StressedDave | 0:24f23c36dd24 | 108 | #define GYRO_OFFSET_Y_MSB_ADDR 0x64 |
StressedDave | 0:24f23c36dd24 | 109 | #define GYRO_OFFSET_Z_LSB_ADDR 0x65 |
StressedDave | 0:24f23c36dd24 | 110 | #define GYRO_OFFSET_Z_MSB_ADDR 0x66 |
StressedDave | 0:24f23c36dd24 | 111 | /* Radius registers */ |
StressedDave | 0:24f23c36dd24 | 112 | #define ACCEL_RADIUS_LSB_ADDR 0x67 |
StressedDave | 0:24f23c36dd24 | 113 | #define ACCEL_RADIUS_MSB_ADDR 0x68 |
StressedDave | 0:24f23c36dd24 | 114 | #define MAG_RADIUS_LSB_ADDR 0x69 |
StressedDave | 0:24f23c36dd24 | 115 | #define MAG_RADIUS_MSB_ADDR 0x6A |
StressedDave | 0:24f23c36dd24 | 116 | |
StressedDave | 0:24f23c36dd24 | 117 | /* Page 1 registers */ |
StressedDave | 0:24f23c36dd24 | 118 | #define BNO055_UNIQUE_ID_ADDR 0x50 |
StressedDave | 0:24f23c36dd24 | 119 | |
StressedDave | 0:24f23c36dd24 | 120 | //Definitions for unit selection |
StressedDave | 0:24f23c36dd24 | 121 | #define MPERSPERS 0x00 |
StressedDave | 0:24f23c36dd24 | 122 | #define MILLIG 0x01 |
StressedDave | 0:24f23c36dd24 | 123 | #define DEG_PER_SEC 0x00 |
StressedDave | 0:24f23c36dd24 | 124 | #define RAD_PER_SEC 0x02 |
StressedDave | 0:24f23c36dd24 | 125 | #define DEGREES 0x00 |
StressedDave | 1:2c3322a8d417 | 126 | #define RADIANS 0x04 |
StressedDave | 0:24f23c36dd24 | 127 | #define CENTIGRADE 0x00 |
StressedDave | 1:2c3322a8d417 | 128 | #define FAHRENHEIT 0x10 |
StressedDave | 1:2c3322a8d417 | 129 | #define WINDOWS 0x00 |
StressedDave | 1:2c3322a8d417 | 130 | #define ANDROID 0x80 |
StressedDave | 0:24f23c36dd24 | 131 | |
StressedDave | 0:24f23c36dd24 | 132 | //Definitions for power mode |
StressedDave | 0:24f23c36dd24 | 133 | #define POWER_MODE_NORMAL 0x00 |
StressedDave | 0:24f23c36dd24 | 134 | #define POWER_MODE_LOWPOWER 0x01 |
StressedDave | 0:24f23c36dd24 | 135 | #define POWER_MODE_SUSPEND 0x02 |
StressedDave | 0:24f23c36dd24 | 136 | |
StressedDave | 0:24f23c36dd24 | 137 | //Definitions for operating mode |
StressedDave | 1:2c3322a8d417 | 138 | #define OPERATION_MODE_CONFIG 0x00 |
StressedDave | 0:24f23c36dd24 | 139 | #define OPERATION_MODE_ACCONLY 0x01 |
StressedDave | 0:24f23c36dd24 | 140 | #define OPERATION_MODE_MAGONLY 0x02 |
StressedDave | 0:24f23c36dd24 | 141 | #define OPERATION_MODE_GYRONLY 0x03 |
StressedDave | 0:24f23c36dd24 | 142 | #define OPERATION_MODE_ACCMAG 0x04 |
StressedDave | 0:24f23c36dd24 | 143 | #define OPERATION_MODE_ACCGYRO 0x05 |
StressedDave | 0:24f23c36dd24 | 144 | #define OPERATION_MODE_MAGGYRO 0x06 |
StressedDave | 0:24f23c36dd24 | 145 | #define OPERATION_MODE_AMG 0x07 |
StressedDave | 0:24f23c36dd24 | 146 | #define OPERATION_MODE_IMUPLUS 0x08 |
StressedDave | 0:24f23c36dd24 | 147 | #define OPERATION_MODE_COMPASS 0x09 |
StressedDave | 0:24f23c36dd24 | 148 | #define OPERATION_MODE_M4G 0x0A |
StressedDave | 0:24f23c36dd24 | 149 | #define OPERATION_MODE_NDOF_FMC_OFF 0x0B |
StressedDave | 0:24f23c36dd24 | 150 | #define OPERATION_MODE_NDOF 0x0C |
StressedDave | 0:24f23c36dd24 | 151 | |
StressedDave | 0:24f23c36dd24 | 152 | typedef struct values{ |
StressedDave | 0:24f23c36dd24 | 153 | int16_t rawx,rawy,rawz; |
StressedDave | 0:24f23c36dd24 | 154 | float x,y,z; |
StressedDave | 0:24f23c36dd24 | 155 | }values; |
StressedDave | 0:24f23c36dd24 | 156 | |
StressedDave | 0:24f23c36dd24 | 157 | typedef struct angles{ |
StressedDave | 0:24f23c36dd24 | 158 | int16_t rawroll,rawpitch,rawyaw; |
StressedDave | 0:24f23c36dd24 | 159 | float roll, pitch, yaw; |
StressedDave | 0:24f23c36dd24 | 160 | } angles; |
StressedDave | 0:24f23c36dd24 | 161 | |
StressedDave | 0:24f23c36dd24 | 162 | typedef struct quaternion{ |
StressedDave | 0:24f23c36dd24 | 163 | int16_t raww,rawx,rawy,rawz; |
StressedDave | 0:24f23c36dd24 | 164 | float w,x,y,z; |
StressedDave | 0:24f23c36dd24 | 165 | }quaternion; |
StressedDave | 0:24f23c36dd24 | 166 | |
StressedDave | 0:24f23c36dd24 | 167 | typedef struct chip{ |
StressedDave | 0:24f23c36dd24 | 168 | char id; |
StressedDave | 0:24f23c36dd24 | 169 | char accel; |
StressedDave | 0:24f23c36dd24 | 170 | char gyro; |
StressedDave | 0:24f23c36dd24 | 171 | char mag; |
StressedDave | 0:24f23c36dd24 | 172 | char sw[2]; |
StressedDave | 0:24f23c36dd24 | 173 | char bootload; |
StressedDave | 0:24f23c36dd24 | 174 | char serial[16]; |
StressedDave | 0:24f23c36dd24 | 175 | }chip; |
StressedDave | 0:24f23c36dd24 | 176 | |
StressedDave | 2:695c6e5d239a | 177 | /** Class for operating Bosch BNO055 sensor over I2C **/ |
StressedDave | 0:24f23c36dd24 | 178 | class BNO055 |
StressedDave | 0:24f23c36dd24 | 179 | { |
StressedDave | 0:24f23c36dd24 | 180 | public: |
StressedDave | 0:24f23c36dd24 | 181 | |
StressedDave | 2:695c6e5d239a | 182 | /** Create BNO055 instance **/ |
StressedDave | 0:24f23c36dd24 | 183 | BNO055(PinName SDA, PinName SCL); |
StressedDave | 2:695c6e5d239a | 184 | |
StressedDave | 2:695c6e5d239a | 185 | /** Perform a power-on reset of the BNO055 **/ |
StressedDave | 0:24f23c36dd24 | 186 | void reset(); |
StressedDave | 2:695c6e5d239a | 187 | /** Check that the BNO055 is connected and download the software details |
StressedDave | 2:695c6e5d239a | 188 | and serial number of chip and store in ID structure **/ |
StressedDave | 0:24f23c36dd24 | 189 | bool check(); |
StressedDave | 2:695c6e5d239a | 190 | /** Turn the external timing crystal on/off **/ |
StressedDave | 0:24f23c36dd24 | 191 | void SetExternalCrystal(bool yn); |
StressedDave | 2:695c6e5d239a | 192 | /** Set the operation mode of the sensor **/ |
StressedDave | 0:24f23c36dd24 | 193 | void setmode(char mode); |
StressedDave | 2:695c6e5d239a | 194 | /** Set the power mode of the sensor **/ |
StressedDave | 0:24f23c36dd24 | 195 | void setpowermode(char mode); |
StressedDave | 0:24f23c36dd24 | 196 | |
StressedDave | 2:695c6e5d239a | 197 | /** Set the output units from the accelerometer, either MPERSPERS or MILLIG **/ |
StressedDave | 0:24f23c36dd24 | 198 | void set_accel_units(char units); |
StressedDave | 2:695c6e5d239a | 199 | /** Set the output units from the gyroscope, either DEG_PER_SEC or RAD_PER_SEC **/ |
StressedDave | 0:24f23c36dd24 | 200 | void set_anglerate_units(char units); |
StressedDave | 2:695c6e5d239a | 201 | /** Set the output units from the IMU, either DEGREES or RADIANS **/ |
StressedDave | 0:24f23c36dd24 | 202 | void set_angle_units(char units); |
StressedDave | 2:695c6e5d239a | 203 | /** Set the output units from the temperature sensor, either CENTIGRADE or FAHRENHEIT **/ |
StressedDave | 0:24f23c36dd24 | 204 | void set_temp_units(char units); |
StressedDave | 2:695c6e5d239a | 205 | /** Set the data output format to either WINDOWS or ANDROID **/ |
StressedDave | 1:2c3322a8d417 | 206 | void set_orientation(char units); |
StressedDave | 2:695c6e5d239a | 207 | /** Set the mapping of the exes/directions as per page 25 of datasheet |
StressedDave | 2:695c6e5d239a | 208 | range 0-7, any value outside this will set the orientation to P1 (default at power up) **/ |
StressedDave | 1:2c3322a8d417 | 209 | void set_mapping(char orient); |
StressedDave | 1:2c3322a8d417 | 210 | |
StressedDave | 2:695c6e5d239a | 211 | /** Get the current values from the accelerometer **/ |
StressedDave | 0:24f23c36dd24 | 212 | void get_accel(void); |
StressedDave | 2:695c6e5d239a | 213 | /** Get the current values from the gyroscope **/ |
StressedDave | 0:24f23c36dd24 | 214 | void get_gyro(void); |
StressedDave | 2:695c6e5d239a | 215 | /** Get the current values from the magnetometer **/ |
StressedDave | 0:24f23c36dd24 | 216 | void get_mag(void); |
StressedDave | 2:695c6e5d239a | 217 | /** Get the corrected linear acceleration **/ |
StressedDave | 0:24f23c36dd24 | 218 | void get_lia(void); |
StressedDave | 2:695c6e5d239a | 219 | /** Get the current gravity vector **/ |
StressedDave | 0:24f23c36dd24 | 220 | void get_grv(void); |
StressedDave | 2:695c6e5d239a | 221 | /** Get the output quaternion **/ |
StressedDave | 0:24f23c36dd24 | 222 | void get_quat(void); |
StressedDave | 2:695c6e5d239a | 223 | /** Get the current Euler angles **/ |
StressedDave | 2:695c6e5d239a | 224 | void get_angles(void); |
StressedDave | 2:695c6e5d239a | 225 | /** Get the current temperature **/ |
StressedDave | 1:2c3322a8d417 | 226 | void get_temp(void); |
StressedDave | 1:2c3322a8d417 | 227 | |
StressedDave | 2:695c6e5d239a | 228 | /** Read the calibration status register and store the result in the calib variable **/ |
StressedDave | 0:24f23c36dd24 | 229 | void get_calib(void); |
StressedDave | 2:695c6e5d239a | 230 | /** Read the offset and radius values into the calibration array**/ |
StressedDave | 1:2c3322a8d417 | 231 | void read_calibration_data(void); |
StressedDave | 2:695c6e5d239a | 232 | /** Write the contents of the calibration array into the registers **/ |
StressedDave | 1:2c3322a8d417 | 233 | void write_calibration_data(void); |
StressedDave | 0:24f23c36dd24 | 234 | |
StressedDave | 2:695c6e5d239a | 235 | /** Structures containing 3-axis data for acceleration, rate of turn and magnetic field. |
StressedDave | 2:695c6e5d239a | 236 | x,y,z are the scale floating point values and |
StressedDave | 2:695c6e5d239a | 237 | rawx, rawy, rawz are the int16_t values read from the sensors **/ |
StressedDave | 0:24f23c36dd24 | 238 | values accel,gyro,mag,lia,gravity; |
StressedDave | 2:695c6e5d239a | 239 | /** Stucture containing the Euler angles as yaw, pitch, roll as scaled floating point |
StressedDave | 2:695c6e5d239a | 240 | and rawyaw, rawroll & rollpitch as the int16_t values loaded from the registers **/ |
StressedDave | 0:24f23c36dd24 | 241 | angles euler; |
StressedDave | 2:695c6e5d239a | 242 | /** Quaternion values as w,x,y,z (scaled floating point) and raww etc... as int16_t loaded from the |
StressedDave | 2:695c6e5d239a | 243 | registers **/ |
StressedDave | 0:24f23c36dd24 | 244 | quaternion quat; |
StressedDave | 2:695c6e5d239a | 245 | |
StressedDave | 2:695c6e5d239a | 246 | /** Current contents of calibration status register **/ |
StressedDave | 0:24f23c36dd24 | 247 | char calib; |
StressedDave | 2:695c6e5d239a | 248 | /** Contents of the 22 registers containing offset and radius values used as calibration by the sensor **/ |
StressedDave | 0:24f23c36dd24 | 249 | char calibration[22]; |
StressedDave | 3:1db1628eb8b2 | 250 | /** Structure containing sensor numbers, software version and chip UID **/ |
StressedDave | 0:24f23c36dd24 | 251 | chip ID; |
StressedDave | 2:695c6e5d239a | 252 | /** Current temperature **/ |
StressedDave | 1:2c3322a8d417 | 253 | int temperature; |
StressedDave | 1:2c3322a8d417 | 254 | |
StressedDave | 0:24f23c36dd24 | 255 | private: |
StressedDave | 0:24f23c36dd24 | 256 | |
StressedDave | 0:24f23c36dd24 | 257 | I2C _i2c; |
StressedDave | 0:24f23c36dd24 | 258 | char rx,tx[2],address; //I2C variables |
StressedDave | 1:2c3322a8d417 | 259 | char rawdata[22]; //Temporary array for input data values |
StressedDave | 0:24f23c36dd24 | 260 | char op_mode; |
StressedDave | 0:24f23c36dd24 | 261 | char pwr_mode; |
StressedDave | 1:2c3322a8d417 | 262 | float accel_scale,rate_scale,angle_scale; |
StressedDave | 1:2c3322a8d417 | 263 | int temp_scale; |
StressedDave | 0:24f23c36dd24 | 264 | |
StressedDave | 0:24f23c36dd24 | 265 | void readchar(char location){ |
StressedDave | 0:24f23c36dd24 | 266 | tx[0] = location; |
StressedDave | 0:24f23c36dd24 | 267 | _i2c.write(address,tx,1,true); |
StressedDave | 0:24f23c36dd24 | 268 | _i2c.read(address,&rx,1,false); |
StressedDave | 0:24f23c36dd24 | 269 | } |
StressedDave | 0:24f23c36dd24 | 270 | |
StressedDave | 0:24f23c36dd24 | 271 | void writechar(char location, char value){ |
StressedDave | 0:24f23c36dd24 | 272 | tx[0] = location; |
StressedDave | 0:24f23c36dd24 | 273 | tx[1] = value; |
StressedDave | 0:24f23c36dd24 | 274 | _i2c.write(address,tx,2); |
StressedDave | 0:24f23c36dd24 | 275 | } |
StressedDave | 0:24f23c36dd24 | 276 | |
StressedDave | 0:24f23c36dd24 | 277 | void setpage(char value){ |
StressedDave | 0:24f23c36dd24 | 278 | writechar(BNO055_PAGE_ID_ADDR,value); |
StressedDave | 0:24f23c36dd24 | 279 | } |
StressedDave | 0:24f23c36dd24 | 280 | }; |
StressedDave | 0:24f23c36dd24 | 281 | #endif |