upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
BMI160 Class Reference

UPM API for the BMI160 3-axis Accelerometer, Gyroscope and Magnetometer. More...

Detailed Description

The Bosch BMI160 is a 3-axis Accelerometer and Gyroscope. Additionally it supports an external Magnetometer, accessed through the BMI160's register interface. This driver was developed with a BMI160 "Shuttle" board, which included a BMM150 Magnetometer.

The device is driven by either 1.8v or 3.3vdc. This driver incorporates the Bosch BMI160 driver code at https://github.com/BoschSensortec/BMI160_driver .

While not all of the functionality of this device is supported initially, the inclusion of the Bosch driver in the source code makes it possible to support whatever features are required that the driver can support.

// Instantiate a BMI160 instance using default i2c bus and address
upm::BMI160 *sensor = new upm::BMI160();
while (shouldRun)
{
// update our values from the sensor
sensor->update();
float dataX, dataY, dataZ;
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
cout << "Accelerometer: ";
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
<< dataZ << endl;
sensor->getGyroscope(&dataX, &dataY, &dataZ);
cout << "Gryoscope: ";
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
<< dataZ << endl;
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
cout << "Magnetometer: ";
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
<< dataZ << endl;
cout << endl;
usleep(500000);
}

Public Types

enum  ACCEL_RANGE_T { ACCEL_RANGE_2G = 0, ACCEL_RANGE_4G, ACCEL_RANGE_8G, ACCEL_RANGE_16G }
 
enum  GYRO_RANGE_T {
  GYRO_RANGE_125 = 0, GYRO_RANGE_250, GYRO_RANGE_500, GYRO_RANGE_1000,
  GYRO_RANGE_2000
}
 

Public Member Functions

 BMI160 (int bus=BMI160_I2C_BUS, uint8_t address=BMI160_DEFAULT_I2C_ADDR)
 
 ~BMI160 ()
 
void update ()
 
void setAccelerometerScale (ACCEL_RANGE_T scale)
 
void setGyroscopeScale (GYRO_RANGE_T scale)
 
float * getAccelerometer ()
 
void getAccelerometer (float *x, float *y, float *z)
 
float * getGyroscope ()
 
void getGyroscope (float *x, float *y, float *z)
 
float * getMagnetometer ()
 
void getMagnetometer (float *x, float *y, float *z)
 
void enableMagnetometer (bool enable)
 
unsigned int getSensorTime ()
 

Protected Member Functions

virtual bool init ()
 

Protected Attributes

float m_accelX
 
float m_accelY
 
float m_accelZ
 
float m_gyroX
 
float m_gyroY
 
float m_gyroZ
 
float m_magX
 
float m_magY
 
float m_magZ
 
unsigned int m_sensorTime
 
float m_accelScale
 
float m_gyroScale
 
bool m_magEnabled
 

Constructor & Destructor Documentation

BMI160 ( int  bus = BMI160_I2C_BUS,
uint8_t  address = BMI160_DEFAULT_I2C_ADDR 
)

bmi160 constructor

Parameters
busi2c bus to use
addressthe address for this device
~BMI160 ( )

BMI160 Destructor

Member Function Documentation

void update ( void  )

Take a measurement and store the current sensor values internally. This function must be called prior to retrieving any sensor values, for example getAccelerometer().

void setAccelerometerScale ( ACCEL_RANGE_T  scale)

set the scaling mode of the accelerometer

Parameters
scaleone of the ACCEL_RANGE_T values
void setGyroscopeScale ( GYRO_RANGE_T  scale)

set the scaling mode of the gyroscope

Parameters
scaleone of the GYRO_RANGE_T values
float * getAccelerometer ( )

Get the Accelerometer values. This function returns a pointer to 3 floating point values: X, Y, and Z, in that order. The values returned are in gravities. update() must have been called prior to calling this method.

The caller is reponsible for freeing the returned pointer.

Returns
Pointer to 3 floating point values: X, Y, and Z in gravities.
void getAccelerometer ( float *  x,
float *  y,
float *  z 
)

Get the Accelerometer values. The values returned are in gravities. update() must have been called prior to calling this method.

Parameters
xA pointer into which the X value will be returned
yA pointer into which the Y value will be returned
zA pointer into which the Z value will be returned
float * getGyroscope ( )

Get the Gyroscope values. This function returns a pointer to 3 floating point values: X, Y, and Z, in that order. The values values returned are in degrees per second. update() must have been called prior to calling this method.

The caller is reponsible for freeing the returned pointer.

Returns
Pointer to 3 floating point values: X, Y, and Z in degrees per second.
void getGyroscope ( float *  x,
float *  y,
float *  z 
)

Get the Gyroscope values. The values returned are in degrees per second. update() must have been called prior to calling this method.

Parameters
xA pointer into which the X value will be returned
yA pointer into which the Y value will be returned
zA pointer into which the Z value will be returned
float * getMagnetometer ( )

Get the Magnetometer values. This function returns a pointer to 3 floating point values: X, Y, and Z, in that order. The values values returned are in micro Teslas. update() must have been called prior to calling this method. If the Magnetometer has been disabled, the return values will always be 0, 0, and 0.

The caller is reponsible for freeing the returned pointer.

Returns
Pointer to 3 floating point values: X, Y, and Z in micro Teslas.
void getMagnetometer ( float *  x,
float *  y,
float *  z 
)

Get the Magnetometer values. The values returned are in micro Teslas. update() must have been called prior to calling this method.

Parameters
xA pointer into which the X value will be returned
yA pointer into which the Y value will be returned
zA pointer into which the Z value will be returned
void enableMagnetometer ( bool  enable)

Enable or disable the Magnetometer. By default, the magnetometer is enabled.

Parameters
enabletrue to enable the magnetometer, false to disable.
unsigned int getSensorTime ( )

Return the sensor time. This is a 24bit value that increments every 39us. It will wrap around once the 24b resolution is exceeded.

Returns
The current sensor time.
bool init ( )
protectedvirtual

set up initial values and start operation

Returns
true if successful

The documentation for this class was generated from the following files: