upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bno055.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016-2017 Intel Corporation.
4  *
5  * The MIT License
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <vector>
29 #include "bno055.h"
30 
31 namespace upm {
32 
103  class BNO055 {
104 
105  public:
122  BNO055(int bus=BNO055_DEFAULT_I2C_BUS,
123  uint8_t addr=BNO055_DEFAULT_ADDR);
124 
128  virtual ~BNO055();
129 
135  void update();
136 
142  uint8_t getChipID();
143 
149  uint8_t getACCID();
150 
156  uint8_t getMAGID();
157 
163  uint8_t getGYRID();
164 
170  uint16_t getSWRevID();
171 
177  uint8_t getBootLoaderID();
178 
186  void setClockExternal(bool extClock);
187 
195  void setTemperatureSource(BNO055_TEMP_SOURCES_T src);
196 
206  void setOperationMode(BNO055_OPERATION_MODES_T mode);
207 
213  void resetSystem();
214 
224  void getCalibrationStatus(int *mag, int *acc, int *gyr, int *sys);
225 
234  std::vector<int> getCalibrationStatus();
235 
244  bool isFullyCalibrated();
245 
258  std::vector<uint8_t> readCalibrationData();
259 
270  void writeCalibrationData(std::vector<uint8_t> calibrationData);
271 
282  float getTemperature(bool fahrenheit=false);
283 
296  void getEulerAngles(float *heading, float *roll, float *pitch);
297 
307  std::vector<float> getEulerAngles();
308 
323  void getQuaternions(float *w, float *x, float *y, float *z);
324 
333  std::vector<float> getQuaternions();
334 
348  void getLinearAcceleration(float *x, float *y, float *z);
349 
358  std::vector<float> getLinearAcceleration();
359 
373  void getGravityVectors(float *x, float *y, float *z);
374 
383  std::vector<float> getGravityVectors();
384 
398  void getAccelerometer(float *x, float *y, float *z);
399 
409  std::vector<float> getAccelerometer();
410 
424  void getMagnetometer(float *x, float *y, float *z);
425 
435  std::vector<float> getMagnetometer();
436 
450  void getGyroscope(float *x, float *y, float *z);
451 
461  std::vector<float> getGyroscope();
462 
471  void setAccelerationConfig(BNO055_ACC_RANGE_T range,
472  BNO055_ACC_BW_T bw,
473  BNO055_ACC_PWR_MODE_T pwr);
474 
483  void setMagnetometerConfig(BNO055_MAG_ODR_T odr,
484  BNO055_MAG_OPR_T opr,
485  BNO055_MAG_POWER_T pwr);
486 
495  void setGyroscopeConfig(BNO055_GYR_RANGE_T range,
496  BNO055_GYR_BW_T bw,
497  BNO055_GYR_POWER_MODE_T pwr);
498 
506  void setAccelerometerUnits(bool mg=false);
507 
515  void setGyroscopeUnits(bool radians=false);
516 
524  void setEulerUnits(bool radians=false);
525 
529  void resetInterruptStatus();
530 
537  uint8_t getInterruptStatus();
538 
546  uint8_t getInterruptEnable();
547 
554  void setInterruptEnable(uint8_t enables);
555 
566  uint8_t getInterruptMask();
567 
578  void setInterruptMask(uint8_t mask);
579 
586  BNO055_SYS_STATUS_T getSystemStatus();
587 
595  BNO055_SYS_ERR_T getSystemError();
596 
597 
598 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
599  void installISR(int gpio, mraa_gpio_edge_t level, jobject runnable)
600  {
601  installISR(gpio, level, mraa_java_isr_callback, runnable);
602  }
603 #else
604 
615  void installISR(int gpio, mraa_gpio_edge_t level,
616  void (*isr)(void *), void *arg);
617 #endif
618 
623  void uninstallISR();
624 
625  protected:
626  bno055_context m_bno055;
627 
639  void setPage(uint8_t page, bool force=false);
640 
647  uint8_t readReg(uint8_t reg);
648 
656  void readRegs(uint8_t reg, uint8_t *buffer, int len);
657 
665  void writeReg(uint8_t reg, uint8_t val);
666 
675  void writeRegs(uint8_t reg, uint8_t *buffer, int len);
676 
677  private:
678  // Adding a private function definition for java bindings
679 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
680  void installISR(int gpio, mraa_gpio_edge_t level,
681  void (*isr)(void *), void *arg);
682 #endif
683  };
684 }
void resetSystem()
Definition: bno055.cxx:173
uint8_t getInterruptStatus()
Definition: bno055.cxx:183
void setAccelerationConfig(BNO055_ACC_RANGE_T range, BNO055_ACC_BW_T bw, BNO055_ACC_PWR_MODE_T pwr)
Definition: bno055.cxx:333
void setMagnetometerConfig(BNO055_MAG_ODR_T odr, BNO055_MAG_OPR_T opr, BNO055_MAG_POWER_T pwr)
Definition: bno055.cxx:340
void writeRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bno055.cxx:81
void writeCalibrationData(std::vector< uint8_t > calibrationData)
Definition: bno055.cxx:231
void writeReg(uint8_t reg, uint8_t val)
Definition: bno055.cxx:74
uint8_t getInterruptEnable()
Definition: bno055.cxx:188
std::vector< float > getQuaternions()
Definition: bno055.cxx:266
BNO055_SYS_STATUS_T getSystemStatus()
Definition: bno055.cxx:208
uint8_t readReg(uint8_t reg)
Definition: bno055.cxx:62
void setClockExternal(bool extClock)
Definition: bno055.cxx:125
void readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bno055.cxx:67
BNO055_SYS_ERR_T getSystemError()
Definition: bno055.cxx:213
uint8_t getACCID()
Definition: bno055.cxx:93
std::vector< float > getGravityVectors()
Definition: bno055.cxx:290
void setGyroscopeConfig(BNO055_GYR_RANGE_T range, BNO055_GYR_BW_T bw, BNO055_GYR_POWER_MODE_T pwr)
Definition: bno055.cxx:347
std::vector< uint8_t > readCalibrationData()
Definition: bno055.cxx:218
uint8_t getInterruptMask()
Definition: bno055.cxx:198
uint8_t getGYRID()
Definition: bno055.cxx:103
uint16_t getSWRevID()
Definition: bno055.cxx:108
std::vector< float > getGyroscope()
Definition: bno055.cxx:326
void uninstallISR()
Definition: bno055.cxx:362
std::vector< float > getLinearAcceleration()
Definition: bno055.cxx:278
bool isFullyCalibrated()
Definition: bno055.cxx:168
void setPage(uint8_t page, bool force=false)
Definition: bno055.cxx:118
void setInterruptEnable(uint8_t enables)
Definition: bno055.cxx:193
BNO055(int bus=BNO055_DEFAULT_I2C_BUS, uint8_t addr=BNO055_DEFAULT_ADDR)
Definition: bno055.cxx:42
void setInterruptMask(uint8_t mask)
Definition: bno055.cxx:203
Definition: bno055.h:53
uint8_t getBootLoaderID()
Definition: bno055.cxx:113
void setTemperatureSource(BNO055_TEMP_SOURCES_T src)
Definition: bno055.cxx:130
void resetInterruptStatus()
Definition: bno055.cxx:178
std::vector< float > getMagnetometer()
Definition: bno055.cxx:314
void setEulerUnits(bool radians=false)
Definition: bno055.cxx:145
void setAccelerometerUnits(bool mg=false)
Definition: bno055.cxx:135
uint8_t getChipID()
Definition: bno055.cxx:88
API for the BNO055 Absolute Orientation 9DOF Fusion Hub.
Definition: bno055.hpp:103
void setOperationMode(BNO055_OPERATION_MODES_T mode)
Definition: bno055.cxx:150
void setGyroscopeUnits(bool radians=false)
Definition: bno055.cxx:140
void update()
Definition: bno055.cxx:55
std::vector< int > getCalibrationStatus()
Definition: bno055.cxx:160
float getTemperature(bool fahrenheit=false)
Definition: bno055.cxx:239
void installISR(int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: bno055.cxx:354
std::vector< float > getEulerAngles()
Definition: bno055.cxx:254
C API for the bno055 driver.
virtual ~BNO055()
Definition: bno055.cxx:50
std::vector< float > getAccelerometer()
Definition: bno055.cxx:302
uint8_t getMAGID()
Definition: bno055.cxx:98