Joel von Rotz / BNO055
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bno055.h Source File

bno055.h

Go to the documentation of this file.
00001 /**
00002  * @brief Declaration of the BNO055 class 
00003  * 
00004  * @file bno055.h
00005  * @author Joel von Rotz
00006  * @date 18.07.2018
00007  */
00008 #ifndef BNO055_H
00009 #define BNO055_H
00010 
00011 #include "mbed.h"
00012 #include "bno055_config.h"
00013 #include "bno055_registermap.h "
00014 #include "bno055_definitions.h "
00015 #include "i2c_master.h"
00016 
00017 
00018 /**
00019  * @brief This is a library for the sensor BNO055, a 9 axis sensor by <a href="https://www.bosch-sensortec.com/">Bosch Sensortec</a>, written by <a href="https://os.mbed.com/users/joelvonrotz/">Joel von Rotz</a>
00020  * <img src="https://ae01.alicdn.com/kf/HTB1n3aPNpXXXXaFXVXXq6xXFXXXi/BNO055-gyroscope-Absolute-Orientation-9-Axis-Sensor.jpg_640x640.jpg" alt="Image of a flying Potato here!">
00021  * Currently, this library is compatible with the mbed LPC1768 only and probably won't change in the future, unless somebody takes their time to port the library to other microcontroller (would very much appreciate it though).
00022  * \n\n             
00023  * <center><a href="https://os.mbed.com/users/joelvonrotz/code/I2C-Master/">This Library requires The <strong>TWI_Master</strong> Library to work</a></center>
00024  * \n\n
00025  * <h2>Example Programm Without Debug</h2>
00026  * @code
00027  * #include "mbed.h"
00028  * #include "i2c_master.h"
00029  * #include "bno055.h"
00030  * 
00031  * Serial  pc(USBTX,USBRX,115200);
00032  * 
00033  * I2C_Master i2c_master(p9, p10);
00034  * DigitalOut bno055_reset(p11);
00035  * BNO055     bno055(0x28,         //7-bit slave address
00036  *                   i2c_master,   //reference of the i2c-master object
00037  *                   bno055_reset, //reference of the reset-pin connected with the mbed
00038  *                   true);        //enable external 32kHz oscillator
00039  * 
00040  * 
00041  * int main() {
00042  *   bno055.setOperationMode(OPERATION_MODE_NDOF);
00043  *   
00044  *   while(1) {
00045  *     bno055.getEulerDegrees();
00046  *     pc.printf("x: %4.3f y: %4.3f z: %4.3f\n\r", bno055.euler.x,bno055.euler.y,bno055.euler.z);
00047  *     wait_ms(100);
00048  *   }
00049  * }
00050  * @endcode
00051  * \n
00052  * <h2>Example Programm With Debug</h2>
00053  * @code
00054  * #define DEBUGGING_ENABLED
00055  * 
00056  * #include "mbed.h"
00057  * #include "i2c_master.h"
00058  * #include "bno055.h"
00059  * 
00060  * Serial  pc(USBTX,USBRX,115200);
00061  * 
00062  * I2C_Master i2c_master(p9, p10);
00063  * DigitalOut bno055_reset(p11);
00064  * BNO055     bno055(0x28,         //7-bit slave address
00065  *                   i2c_master,   //reference of the i2c-master object
00066  *                   bno055_reset, //reference of the reset-pin connected with the mbed
00067  *                   true,         //enable external 32kHz oscillator
00068  *                   pc);          //debugging Serial object
00069  * 
00070  * int main() {
00071  *   bno055.setOperationMode(OPERATION_MODE_NDOF);
00072  *   
00073  *   while(1) {
00074  *     bno055.getEulerDegrees();
00075  *     pc.printf("x: %4.3f y: %4.3f z: %4.3f\n\r", bno055.euler.x,bno055.euler.y,bno055.euler.z);
00076  *     wait_ms(100);
00077  *   }
00078  * }
00079  * @endcode
00080  * 
00081  * During the execution of the programm, open your terminal. Everything should now be printed.
00082  * 
00083  */
00084 class BNO055
00085 {
00086 public:
00087     #ifdef DEBUGGING_ENABLED
00088         BNO055(uint8_t slave_address, I2C_Master& i2c_master, DigitalOut& ResetPin, bool external_clk, Serial& DEBUG_SERIAL);
00089     #else
00090         BNO055(uint8_t slave_address, I2C_Master& i2c_master, DigitalOut& ResetPin, bool external_clk);
00091     #endif
00092 //=---------------------------------------
00093     struct bno055_format_s
00094     {
00095         uint8_t                 units;
00096         bno055_orientation_t    orientation;
00097         bno055_temperature_t    temperature;
00098         bno055_euler_t          euler;
00099         bno055_gyro_t           gyroscope;
00100         bno055_acceleration_t   acceleration;
00101     };
00102 
00103     struct bno055_id_s
00104     {
00105         uint8_t     chip;
00106         uint8_t     accel;
00107         uint8_t     gyro;
00108         uint8_t     magneto;
00109         uint8_t     bl_rev;
00110         uint16_t    sw_rev;
00111     };
00112     
00113     struct bno055_mode_s
00114     {
00115         uint8_t     power;
00116         uint8_t     operation;
00117     };
00118 
00119     struct bno055_system_s
00120     {
00121         uint8_t     status;
00122         uint8_t     error;
00123     };
00124 
00125     struct bno055_axis_s
00126     {
00127         uint8_t     map;
00128         uint8_t     sign;
00129     };
00130 
00131     struct bno055_interrupt_s
00132     {
00133         uint8_t     status;
00134         struct bno055_gyro_interrupt_s
00135         {
00136             bool    high_rate;
00137             bool    any_motion;
00138         }gyroscope;
00139 
00140         struct bno055_accel_interrupt_s
00141         {
00142             bool    no_motion;
00143             bool    any_motion;
00144             bool    high_g;
00145         }acceleration;
00146     };
00147 
00148     struct bno055_quaternion_s
00149     {
00150         float w;
00151         float x;
00152         float y;
00153         float z;
00154     };
00155 
00156     struct bno055_data_s
00157     {
00158         float x;
00159         float y;
00160         float z;
00161     };
00162 
00163     struct bno055_calibration_s
00164     {
00165         uint8_t system;
00166         uint8_t gyro;
00167         uint8_t acceleration;
00168         uint8_t magneto;
00169         uint8_t status;
00170     };
00171 
00172 //=---------------------------------------
00173 
00174     
00175     float          temperature;
00176     uint16_t        orientation;
00177 
00178     bno055_format_s     format;
00179     bno055_id_s         id;
00180     bno055_mode_s       mode;
00181     bno055_system_s     system;
00182     bno055_axis_s       axis;
00183 
00184     bno055_data_s       gravity_vector;
00185     bno055_data_s       linear_accel;
00186     bno055_data_s       accel;
00187     bno055_data_s       magneto;
00188     bno055_data_s       gyro;
00189     bno055_data_s       euler;
00190 
00191     bno055_quaternion_s     quaternion;
00192     bno055_calibration_s    calibration;
00193 
00194     bno055_interrupt_s  interrupt;
00195     
00196 //=---------------------------------------
00197 
00198     void        setUnitFormat(bno055_orientation_t  new_orientation_format  = WINDOWS,
00199                               bno055_temperature_t  new_temperature_format  = CELSIUS,
00200                               bno055_euler_t        new_euler_format        = DEGREES,
00201                               bno055_gyro_t         new_gyroscope_format    = DEGREE_PER_SEC,
00202                               bno055_acceleration_t new_acceleration_format = ACCELERATION 
00203                               );
00204 
00205     void        getUnitFormat(void);
00206     void        getIDs(void);
00207     void        setPowerMode(bno055_powermode_t new_power_mode  = POWER_NORMAL);
00208     uint8_t     getPowerMode(void);
00209     void        setOperationMode(bno055_opr_mode_t new_opr_mode = OPERATION_MODE_CONFIGMODE);
00210     uint8_t     getOperationMode(void);
00211     void        setPage(bno055_page_t new_page = PAGE_0);
00212     uint8_t     getPage(void);
00213     uint8_t     getSystemStatus(void);
00214     uint8_t     getSystemError(void);
00215     void        useExternalOscillator(bool enabled);
00216     void        resetSW(void);
00217     void        resetHW(void);
00218     void        assignAxis( bno055_axis_t x_axis = X_AXIS,
00219                             bno055_axis_t y_axis = Y_AXIS,
00220                             bno055_axis_t z_axis = Z_AXIS);
00221     void        setAxisSign(bno055_axis_sign_t x_sign = POSITIVE,
00222                             bno055_axis_sign_t y_sign = POSITIVE,
00223                             bno055_axis_sign_t z_sign = POSITIVE);
00224     void        setOrientation(bno055_remap_options_t orientation_placement = REMAP_OPTION_P1);
00225     void        getOrientation(void);
00226     void        getCalibrationStatus(void);
00227 
00228     void        getInterruptFlag(void);
00229     void        setEnableInterrupts(bno055_enable_t accel_no_motion,
00230                                     bno055_enable_t accel_any_motion,
00231                                     bno055_enable_t accel_high_g,
00232                                     bno055_enable_t gyro_high_rate,
00233                                     bno055_enable_t gyro_any_motion
00234                                     );
00235     uint8_t     getEnabledInterrupts(void);
00236     
00237     void        setInterruptMask(bno055_enable_t accel_no_motion,
00238                                  bno055_enable_t accel_any_motion,
00239                                  bno055_enable_t accel_high_g,
00240                                  bno055_enable_t gyro_high_rate,
00241                                  bno055_enable_t gyro_any_motion
00242                                  );
00243     uint8_t     getInterruptMask(void);
00244     
00245     void        configAccelerationInterrupt(bno055_config_int_axis_t    high_axis,
00246                                             bno055_config_int_axis_t    am_nm_axis,
00247                                             bno055_any_motion_sample_t  am_dur
00248                                             );
00249     void        configGyroscopeInterrupt(bno055_config_int_axis_t hg_z_axis,
00250                                          bno055_config_int_axis_t hg_y_axis,
00251                                          bool   high_rate_unfilt,
00252                                          bool   any_motion_unfilt
00253                                          );
00254 
00255     void        getAcceleration(void);
00256     void        getMagnetometer(void);
00257     void        getGyroscope(void);
00258     void        getEulerDegrees(void);
00259     void        getQuaternion(void);
00260     void        getLinearAcceleration(void);
00261     void        getGravityVector(void);
00262     void        getTemperature(void);
00263 
00264 private:
00265     I2C_Master&     m_i2c_master;
00266     DigitalOut&     m_ResetPin;
00267     
00268     //DEBUG SERIAL
00269     #ifdef DEBUGGING_ENABLED
00270         Serial&     m_DEBUG_SERIAL;
00271     #endif
00272 
00273     uint8_t     m_bno055_address;
00274 
00275     uint8_t     page;
00276     uint8_t     arrayIndex;
00277     float       sensor_data_converted;
00278     uint8_t     register_data[8];
00279     int16_t     sensor_data[4];
00280 
00281     void        get(bno055_reg_t  address, bno055_data_s& data, const float format, bool is_euler);
00282     void        get(bno055_reg_t  address, bno055_quaternion_s& data, const float format);
00283 
00284     
00285 };
00286 
00287 #endif /* BNO055_H */
00288 
00289