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